CodeChef is a non-commercial competitive programming community
Login
Username (New User? Signup) Password (Forgot Password?)
Signup
Login or
Signup with
Connect
Note
  • Publicize your achievements on your Facebook Wall.
  • Challenge your friends or ask them for help.

Site Navigation

  • PRACTICE
    • Easy
    • Medium
    • Hard
    • Challenge
    • Peer
  • COMPETE
    • All Contests
    • June Challenge 2013
    • May Cook-Off 2013
    • May Challenge 2013
  • DISCUSS
    • Forums
    • Blog
    • Wiki
    • Facebook
    • Twitter
  • COMMUNITY
    • Campus Chapters
    • Host your Contest
    • Go for Gold
    • All Educational Initiatives
  • HELP
    • Frequently Asked Questions
    • FAQ for problem setters
    • Problem Setting
    • Tutorials
    • Long Contest Ranks
    • Short Contest Ranks
    • Event Calendar
    • Top Contributors on Discuss
  • ABOUT
    • About CodeChef
    • Team CodeChef
    • Press Room
    • CodeChef Financials
    • CodeChef Sponsorships
    • CEO's Corner
    • Contact Us
    • About Directi
Home » Compete » September Challenge 2012 » Three is Crowd

Three is Crowd

Problem code: CROWD

  • All Submissions

All submissions for this problem are available.

Two's company, three's a crowd!

It's been one year since Chef met his brother. Last year, his younger brother came to visit him during this time of the year. This year, the Chef is planning to go visit his brother. Chef's brother has planned to throw a "Welcome Party" for him. He wants to invite people from his neighbourhood (i.e. from the street where he lives). There are N houses on the street in a single line (not considering the brother's house). He wants the party to be fun and he will not like to invite people who might spoil the mood of the party. If people are invited from three consecutive houses on the street, they might create trouble. As they say, three's a crowd! He doesn't want to ruin the Chef's Welcome Party and so he will not want to send invites to any three consecutive houses. He wants you to tell him how many ways are there for him to go wrong. Note that he can play safe by not inviting anyone to avoid a crowd.

Input:

First line of the input contains a single integer T, the number of test cases.
Each test case contains a line containing a single integer N described above.

Output:

For each test case output a single integer denoting the number of ways the brother can go wrong with planning the party.
The answer can get quite large. So output the total number of ways modulo 109+7.

Constraints:

1<=T<=10000
1<=N<=1015

Example:

Input:
2
3
4

Output:
1
3

Explanation: Case 1: The only way he can go wrong is by inviting all the houses.
Case 2: First way of getting wrong is by inviting houses (1,2,3). Second way to get wrong is by inviting houses (2,3,4). Third way of going wrong is by inviting all 4 houses i.e. (1,2,3,4).

Author: vamsi_kavala
Tester: laycurse
Editorial http://discuss.codechef.com/problems/CROWD
Date Added: 5-08-2012
Time Limit: 5 sec
Source Limit: 50000 Bytes
Languages: ADA, ASM, BASH, BF, C, C99 strict, CAML, CLOJ, CLPS, CPP 4.0.0-8, CPP 4.3.2, CS2, D, ERL, FORT, FS, GO, HASK, ICK, ICON, JAR, JAVA, JS, LISP clisp, LISP sbcl, LUA, NEM, NICE, NODEJS, PAS fpc, PAS gpc, PERL, PERL6, PHP, PIKE, PRLG, PYTH, PYTH 3.1.2, RUBY, SCALA, SCM guile, SCM qobi, ST, TCL, TEXT, WSPC


  • Submit

Comments

  • Login or Register to post a comment.

Excuse me ? 1.

mustang28 @ 1 Sep 2012 04:44 PM
Excuse me ? 1. tyamgin time--> 7.89s 2. damians time--> 9.38s I thought the time limit was 5.0 secs

Every question in every

siddharthchan @ 1 Sep 2012 04:58 PM
Every question in every contest has one comment like the aforesaid !! @mustang28 - READ THE FAQ before you post a question . Its 5 sec per test file and there can be lots of it.

@admin for N=5 {1 2 3 4 5}

khadarbasha @ 1 Sep 2012 05:20 PM
@admin for N=5 {1 2 3 4 5} is a valid arrangement for wrong way of inviting the party

IMP : Is the time limit not

tanujrastogi @ 1 Sep 2012 09:24 PM
IMP : Is the time limit not applicble in this contest??Solutions with time exceeded are being accepted and awarded scores. Don't we need to write efficient codes this time??

Contestants are requested NOT

vamsi_adm @ 2 Sep 2012 12:06 AM
Contestants are requested NOT to discuss test cases here. That's against the rules of the contest. Please do NOT ask for hints, answers for your test cases or for more test cases. Necessary information has already been provided in the problem statement. Please stick to the rules.

can any1 tell me Y it is

mido_mavrick @ 2 Sep 2012 04:38 AM
can any1 tell me Y it is telling me ( Time Limit Exceeded ) while submitting the answer?

don't use modulus operator

mohammadmaaz @ 2 Sep 2012 12:19 PM
don't use modulus operator too many times caused me tle !!

my approch is corrent...

imrhk @ 2 Sep 2012 01:58 PM
my approch is corrent... there is some prob with MOD... help me out . thanks in advance

Does first test is equal to

cupidon4uk @ 2 Sep 2012 02:29 PM
Does first test is equal to sample test from statement?

nice ques.....

rishrt629 @ 2 Sep 2012 06:44 PM
nice ques.....

is {1,2,3,5 } a valid

kp25 @ 2 Sep 2012 06:44 PM
is {1,2,3,5 } a valid combination..?

mod is giving some

ka4tik @ 2 Sep 2012 08:01 PM
mod is giving some error.....my code runs in 1.7 seconds on ideone for 10000 test cases........tle on cc...........

@mido_mavrick: time limit

coderfrmhell @ 2 Sep 2012 08:10 PM
@mido_mavrick: time limit exceeded means ur code took more time to produce the output than it was supposed to take...

@ kp25, I think {1,2,3,5 } is

deinier @ 2 Sep 2012 09:02 PM
@ kp25, I think {1,2,3,5 } is a valid wrong way for n = 5.

@deinier, still getting wrong

kp25 @ 2 Sep 2012 09:47 PM
@deinier, still getting wrong answer..!! no idea, wherez the bug is hiding.?

Is the order important? say

shredder @ 2 Sep 2012 10:08 PM
Is the order important? say for n=5 , 12345 12354 are to be treated as different ways or as the same?

plz give correct ans for any

suneetk92 @ 3 Sep 2012 12:12 AM
plz give correct ans for any other test case.. just want to verify my algo..

The best way to verify your

Sumudu @ 3 Sep 2012 08:02 AM
The best way to verify your algo is to code it and submit it, simple! Stop posting I/O in the comments!

my code is running on my

aarifjindani @ 3 Sep 2012 02:21 PM
my code is running on my machine with T=10000 and n=10^15 under 500ms and server gives me time limit exceeded.is there any problem with server?

even my soln is timing out. I

shrknt @ 3 Sep 2012 04:16 PM
even my soln is timing out. I dont know what is wrong..

Is there any problem with the

shrknt @ 3 Sep 2012 08:51 PM
Is there any problem with the server...On my machine, with t = 10000 and n = 10^15, it takes less than 5 secs overall.

@radhika123, rixdi, sidd081:

vamsi_adm @ 4 Sep 2012 12:48 AM
@radhika123, rixdi, sidd081: A warning has already been issued in the comments thread to AVOID DISCUSSION OF TEST CASES during the contest. Please do not continue doing this.

Can someone give me a

buda @ 4 Sep 2012 02:24 AM
Can someone give me a ballpark figure of how many times is the tester computer slower than what you get on ideone? I'm getting 0.56s for T=5000 of what I think is the worst case number for my algorithm (not testing with T=10000 because ideone crops the input, but it's a pretty safe bet that that time would be just a factor of two larger). This information would help me decide should I try to optimize my implementation or try to come up with a better algorithm. For example, if the Codechef judge is 5 times slower, that would mean that my solution is pretty close. If it's more than that, then my algorithm is obviously not going to cut it.

Nevermind, I've come up with

buda @ 4 Sep 2012 02:51 AM
Nevermind, I've come up with a better algorithm to implement tomorrow :). Still, would be useful to know for future reference.

@all Can anyone tell if

kuruma @ 4 Sep 2012 08:22 AM
@all Can anyone tell if permutations are to be used? As, is 12345, different from 12354?

@karuma 12345 is same as

amannith @ 4 Sep 2012 02:35 PM
@karuma 12345 is same as 12354...or else in the input case provided above 4123 would also have been a valid case..

@amannith Yes, I realized it

kuruma @ 4 Sep 2012 02:52 PM
@amannith Yes, I realized it today... But it was really late in the night when I wrote this... Sorry about it... Major problem now is that I don“t see why I get WA :(

@admin: we are not able to

remogoku @ 4 Sep 2012 06:45 PM
@admin: we are not able to verify our algo.. so i suggest you that, atleast from next contest pls provide test case for one large value. so that we can verify it. simply if it shows wrong ans means what can we do..?

I am getting runtime error

squeezethekey @ 4 Sep 2012 08:00 PM
I am getting runtime error but I'm not using any array or making too many functions call; can anybody suggest what could be the reason for SIGSEGV error.

i am getting a wrong answer.

priyanka7610 @ 4 Sep 2012 09:07 PM
i am getting a wrong answer. And I cant figure out what is wrong in my code. It is working on my computer. I agree with remogoku.

@admin A problem is also seen

kuruma @ 4 Sep 2012 10:23 PM
@admin A problem is also seen by it's test cases... There should be about 2,3 simple cases, to allow one to get on the right track for the algorithm development, and an addicional corner case to make sure the algorithm is correct... So, can you provide answer for 1000000000000000, please?

@kuruma I respectfully

Sumudu @ 4 Sep 2012 10:41 PM
@kuruma I respectfully disagree. Sometimes if a problem is ill defined we do need to rely on sample cases to understand it, but it's pretty entitled to demand that the problem setter provide sample input that helps us to verify our algorithm (esp. in a multi-day contest with no penalty for wrong submissions!). IMO the only real requirement on sample input is that it accurately communicate the input/output format (e.g. the numbers may not even be correct). For this problem it's really easy to understand what they're asking for, and you can solve the next few small cases by hand (5, 6, maybe even 7) -- and doing so will probably help tremendously in finding an algorithm that is easy to *prove*.

I am getting runtime error

squeezethekey @ 4 Sep 2012 11:49 PM
I am getting runtime error but I'm not using any array or making too many functions call; can anybody suggest what could be the reason for SIGSEGV error.

@dmdmroy7 read carefully: "

kuruma @ 5 Sep 2012 12:04 AM
@dmdmroy7 read carefully: " to any three consecutive houses."

y runtime error while using

bhaveshr053 @ 5 Sep 2012 01:00 AM
y runtime error while using "malloc " for dynamic storage

It is correct yes!!

kuruma @ 5 Sep 2012 02:09 AM
It is correct yes!!

@kuruma does { 1 2 3 4 } and

kp25 @ 5 Sep 2012 08:07 AM
@kuruma does { 1 2 3 4 } and { 1 2 3 4 5 } are same or different..? for n=5

@kuruma: You're constantly

vamsi_adm @ 5 Sep 2012 10:07 AM
@kuruma: You're constantly posting/asking answers to test cases in spite of being asked twice not to do so. Please do not do it. It's against the rules of the contest. All the information that is necessary to solve the problem has already been provided in the problem statement. Please do not ask for more test cases.

PLEASE DO NOT DISCUSS TEST

vamsi_adm @ 5 Sep 2012 10:07 AM
PLEASE DO NOT DISCUSS TEST CASES HERE.

wa wa wa

honour_00 @ 5 Sep 2012 03:21 PM
wa wa wa

@all who got accepted: "Note

kuruma @ 5 Sep 2012 05:28 PM
@all who got accepted: "Note that he can play safe by not inviting anyone to avoid a crowd." Is this even relevant to the problem? I'm desperate now >.<

6 tyms submit..! wa :( @least

kp25 @ 6 Sep 2012 12:01 AM
6 tyms submit..! wa :( @least aftr a long tym i cud find out the prob, i guess d prob is wit %mod operator. for all d wrong answers, don't use repeatedly mod, it may help u.. btw it not helped me

@kp25 I believe mod is always

kuruma @ 6 Sep 2012 12:54 AM
@kp25 I believe mod is always necessary here and we might be missing something... but since admin won't provide answers for larger test cases, after over 10 wrong submissions I am still clueless

wow finally ac after so many

karan173 @ 6 Sep 2012 02:33 AM
wow finally ac after so many tle's and that 2 with one of the slowest solutions.

TLE.. TLE... TLE... infinite

codersrikant @ 6 Sep 2012 07:51 AM
TLE.. TLE... TLE... infinite looop.... :(

@admin... hey I got my code

ejaj_hassan @ 6 Sep 2012 12:45 PM
@admin... hey I got my code running at .01sec on ideone....n here m getting time limit exceeded...what's the pt.???

If a code is judged and ends

kuruma @ 6 Sep 2012 04:16 PM
If a code is judged and ends after 3 sec and we have WA... Then we modify the algorithm and it gives us wrong answer at 6 sec of execution, does it mean that the second algorithm got more test cases correctly judged?

@admin I had run my code for

ravi_upadhyay @ 6 Sep 2012 08:39 PM
@admin I had run my code for 10^4 test cases with very high values of n(i.e. they are all of order of 10^15) and the program runs in just about 0.8 secs, but i am getting tle on codechef. Please Help.

@admin is there a problem

pytart @ 7 Sep 2012 06:45 PM
@admin is there a problem with the site? i tired submitting for two problems and they dont show in my submissions. Also when I submit they are always stuck in "Running" and never even give TLE

@ admin : same problem. Is

rohit220691 @ 7 Sep 2012 07:03 PM
@ admin : same problem. Is there anything wrong with the server

finally accepted aftr 15

kp25 @ 7 Sep 2012 07:23 PM
finally accepted aftr 15 try's..!! :)

seems like has solution has

hellomoto_35 @ 7 Sep 2012 08:41 PM
seems like has solution has sth to do with fibonacci number.some property we need to use to avoid tle for such a big i/p no as of 10^15.

@admin i am also getting

nitish712 @ 7 Sep 2012 09:58 PM
@admin i am also getting tle!!! I got the answer in less than blink of eye for 10^15....why is that so??

Guys it seems like there was

ravi_upadhyay @ 7 Sep 2012 10:27 PM
Guys it seems like there was a problem with the server. My same program is accepted now. :)

does this type of question is

abhinav1592 @ 7 Sep 2012 10:28 PM
does this type of question is solved using some kind of derivable formula (i mean we have to figure out the formula and then simply put the value)..or this is some standard algorithm based problem...???

@admin please do provide

jaichaudhry @ 8 Sep 2012 01:24 PM
@admin please do provide testcases for larger values,else it's difficult for us to figure out what the problem is .....

@admin: 5 sec is for 1 test

biltharesatyendra @ 8 Sep 2012 01:27 PM
@admin: 5 sec is for 1 test file. I made test file with 10000 test cases with value 10^16. It ran in 3 sec. Why TLE?

@admin: i also checked for

biltharesatyendra @ 8 Sep 2012 02:03 PM
@admin: i also checked for 10000 cases with 2^63-1. It ran in 2.56 sec. Still I am getting TLE. Why?

same old school question with

ridder @ 8 Sep 2012 09:10 PM
same old school question with a li'll twist.............problem setter : take a bow :)

ridder, this is an old school

kuruma @ 8 Sep 2012 11:32 PM
ridder, this is an old school question? D:

It seems to be that my

jeepy @ 9 Sep 2012 02:16 AM
It seems to be that my solution is quite optimal, but I keep getting "RunTime error" (which corresponds to "Time elapsed" in C#). Can anyone have a look at http://www.codechef.com/viewsolution/1336308, and tell me if the problem is due to C# bound checking.

sometimes Modulo hurts really

bsk @ 9 Sep 2012 11:47 AM
sometimes Modulo hurts really bad ;)

I doff my hats for those who

bodmas @ 10 Sep 2012 03:21 AM
I doff my hats for those who have solved this problem, especially those who have solved it efficiently. I arrived at a recurrence formular but couldn't solve it into closed form :( I doubt the recurrence will beat the time.

can anyone please provide a

akshaylambe @ 10 Sep 2012 09:25 AM
can anyone please provide a li'll more clarity with the taste cases! i think my code i fyn.. but it's still showing WA on codechef.

please provide test cases

milrocks13 @ 10 Sep 2012 07:28 PM
please provide test cases with little higher values of n...

finally accepted.... high

jonty7 @ 10 Sep 2012 09:19 PM
finally accepted.... high school problem.....

TLE at least this time 'not

harit @ 11 Sep 2012 03:54 AM
TLE at least this time 'not acceptable.......' admin please check whats wrong,

SUCCESSFUL SUBMISSIONS


Fetching successful submissions

CodeChef is a non-commercial competitive programming community
  • About CodeChef
  • About Directi
  • CEO's Corner
  • C-Programming
  • Programming Languages
  • Contact Us
© 2009 Directi Group. All Rights Reserved. CodeChef uses SPOJ © by Sphere Research Labs
In order to report copyright violations of any kind, send in an email to copyright@codechef.com
CodeChef a product of Directi
The time now is:
CodeChef - A Platform for Aspiring Programmers

CodeChef was created as a platform to help programmers make it big in the world of algorithms, computer programming and programming contests. At CodeChef we work hard to revive the geek in you by hosting a programming contest at the start of the month and another smaller programming challenge in the middle of the month. We also aim to have training sessions and discussions related to algorithms, binary search, technicalities like array size and the likes. Apart from providing a platform for programming competitions, CodeChef also has various algorithm tutorials and forum discussions to help those who are new to the world of computer programming.

Practice Section - A Place to hone your 'Computer Programming Skills'

Try your hand at one of our many practice problems and submit your solution in a language of your choice. Our programming contest judge accepts solutions in over 35+ programming languages. Preparing for coding contests were never this much fun! Receive points, and move up through the CodeChef ranks. Use our practice section to better prepare yourself for the multiple programming challenges that take place through-out the month on CodeChef.

Compete - Monthly Programming Contests and Cook-offs

Here is where you can show off your computer programming skills. Take part in our 10 day long monthly coding contest and the shorter format Cook-off coding contest. Put yourself up for recognition and win great prizes. Our programming contests have prizes worth up to Rs.20,000 and $700lots more CodeChef goodies up for grabs.

Discuss

Are you new to computer programming? Do you need help with algorithms? Then be a part of CodeChef's Forums and interact with all our programmers - they love helping out other programmers and sharing their ideas. Have discussions around binary search, array size, branch-and-bound, Dijkstra's algorithm, Encryption algorithm and more by visiting the CodeChef Forums and Wiki section.

CodeChef Community

As part of our Educational initiative, we give institutes the opportunity to associate with CodeChef in the form of Campus Chapters. Hosting online programming competitions is not the only feature on CodeChef. You can also host a coding contest for your institute on CodeChef, organize an algorithm event and be a guest author on our blog.

Go For Gold

The Go for Gold Initiative was launched about a year after CodeChef was incepted, to help prepare Indian students for the ACM ICPC World Finals competition. In the run up to the ACM ICPC competition, the Go for Gold initiative uses CodeChef as a platform to train students for the ACM ICPC competition via multiple warm up contests. As an added incentive the Go for Gold initiative is also offering over Rs.8 lacs to the Indian team that beats the 29th position at the ACM ICPC world finals. Find out more about the Go for Gold and the ACM ICPC competition here.