World Finals 2013


  Submissions
Graduation Requirements
7pt
Not attempted
18/20 users correct (90%)
18pt
Not attempted
5/9 users correct (56%)
Drummer
9pt
Not attempted
24/24 users correct (100%)
20pt
Not attempted
15/23 users correct (65%)
X Marks the Spot
10pt
Not attempted
6/11 users correct (55%)
29pt
Not attempted
1/4 users correct (25%)
Can't Stop
11pt
Not attempted
20/22 users correct (91%)
32pt
Not attempted
12/18 users correct (67%)
Let Me Tell You a Story
14pt
Not attempted
9/10 users correct (90%)
50pt
Not attempted
  Top Scores
mystic121
Vasyl111
winger111
sdya103
pieguy97
mikhailOK93
jpaulson93
EgorKulikov89
Lovro79
staniek79
Practice Mode

Problem A. Graduation Requirements

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
7 points
Large input
18 points

Problem

Before graduating from Awesome Programmer University, students traditionally perform certain "graduation requirements". One of these is driving around a traffic circle backwards. For most people, this is crazy enough, but as an extra challenge, you want to see if you can go backwards around the traffic circle multiple times without stopping.

The traffic circle consists of N intersections, spaced evenly around the circle. A car would normally enter the traffic circle at one intersection, and then every second, it will move to the next counter-clockwise intersection, until eventually it reaches its destination and leaves.

You have been watching cars enter and leave the traffic circle for X seconds. For each car, you record the time it enters the circle, as well as the intersections it enters and leaves at. All cars are moving counter-clockwise at the rate of 1 intersection per second. Each car you watched exited the circle before coming back to the intersection it entered at. There are multiple lanes on the traffic circle, so multiple cars can occupy the same position at the same time.

If you had planned it just right, how long could you have driven clockwise in the traffic circle during this time? You must enter the circle at some integer time >= 0, leave at time <= X, and once you leave, you are not allowed to come back. When in the traffic circle, you must travel clockwise at the rate of 1 intersection per second. You want to play it safe (well, as safe as driving backwards on a traffic circle can be), so you must never touch or pass by another car. In particular, you cannot leave the circle at an intersection at which another car is entering at the same moment, and you cannot enter the circle at an intersection at which another car is leaving at the same moment. You can choose when and where to enter and leave the circle.

Input

The first line of the input gives the number of test cases, T. T test cases follow. The first line of any test case describes the number C of cars you observed. The second line contains two integers, X and N — the time (in seconds) for which you observed the circle, and the number of intersections on the circle. Next C lines describe the cars you have seen. Each of those lines contains three integers si, ei and ti — the intersection at which the car entered the circle, the intersection on which it left and the time at which it entered. The intersections are numbered from 1 to N, counterclockwise (that is, the intersection number 2 is the next intersection counterclockwise from number 1).

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the maximum number of seconds you can travel on the circle. Note that y can be zero both in the case where you cannot enter the circle at all and in the case when you can enter it, but can't travel even one intersection.

Remember that you are required to enter the circle at a time expressed as an integer number of seconds — you must enter at an integer time, and thus arrive at each intersection at an integer time.

Limits

1 ≤ T ≤ 100
1 ≤ si, eiN
siei
0 ≤ ti
Each observed car leaves the circle at time X or earlier.

Small dataset

3 ≤ N ≤ 10
1 ≤ X ≤ 10
0 ≤ C ≤ 10

Large dataset

3 ≤ N ≤ 1010
1 ≤ X ≤ 1010
0 ≤ C ≤ 1000

Sample


Input
 

Output
 
5
1
3 4
1 4 0
6
3 5
5 2 0
5 1 2
1 3 0
1 2 2
2 3 0
3 4 0
3
2 3
1 3 0
2 1 0
3 2 0
0
6 4
1
2 3
1 3 0
Case #1: 1
Case #2: 2
Case #3: 0
Case #4: 6
Case #5: 0

In the first sample case, we have one car, going as in the picture in the statement. There are a number of ways allowing us to travel backwards for one second — for instance, we can enter at intersection 1 at time 1 (we can't enter at time zero, because the other car is there), and travel to intersection 4 (we can't go on to intersection 3, as we would pass the other car which will be going from 3 to 4). Another option is to enter at intersection 4 at time 0, and travel to intersection 3 (and then exit).

In the second sample case, we can travel for two seconds by entering at intersection 5 at time 1, and traveling backwards to intersection 3. In the third sample case, we can't even enter the circle - there are cars at all intersections at every full second. In the fourth case there are no cars, so we can just enter the circle at any point at time 0 and travel round and round till time 6. In the fifth case we can enter the circle, but since there are only three intersections, we will always collide with the other car if we try to move to the next one.

Note: Driving against the direction of the traffic on a traffic circle is typically not a wise thing to do and may cause harm to you or other people. Google (and Google Code Jam in particular) encourages you not to try this.

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
9 points
Large input
20 points

Problem

The drummer has a very important role in any band -- keeping the rhythm. If the drummer's rhythm is uneven, it can ruin the entire performance.

You are the lead singer of a very popular rock band, and you have a bit of a problem. Your drummer has just quit the band to become a professional video gamer. You need to find a new drummer immediately. Fortunately, there is no shortage of candidates. Everyone wants a chance to join your band. Your task is to find the best drummer among the candidates, and you want the person who can keep the most consistent rhythm.

Your plan is as follows. You will ask each candidate to audition individually. During the audition, the candidate will play one drum by striking it with a drum stick several times. Ideally, the time difference between consecutive strikes should be exactly the same, producing a perfect rhythm. In a perfect rhythm, the drum strikes will have time stamps that follow an arithmetic progression like this: T0, T0 + K, T0 + 2*K, ..., T0 + (N - 1)*K.

In real life, of course, it is nearly impossible for a human to produce a perfect rhythm. Therefore, each candidate drummer will produce a rhythm that has an error E, such that each Ti differs by at most E from some perfect rhythm. Given a candidate's sequence of drum strikes, find the smallest possible E among all perfect rhythms that the candidate might have been trying to play.

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each one consists of two lines and represents the audition of one candidate. The first line contains a single integer -- N. The next line contains N integers separated by spaces -- the time stamps, in milliseconds, of the drum strikes played by the candidate. The time stamps are in increasing order.

Output

For each test case, output one line containing "Case #x: E", where x is the case number (starting from 1) and E is the smallest among all possible numbers that describe the error of the candidate's drum strike sequence.

Your answer will be considered correct if it is within an absolute or relative error of 10-6 of the correct answer. See the FAQ for an explanation of what that means, and what formats of floating-point numbers we accept.

Limits

1 ≤ T ≤ 100.

Small dataset

2 ≤ N ≤ 10.
0 ≤ Ti ≤ 100.

Large dataset

For 90% of the test cases, 2 ≤ N ≤ 1000.
For all test cases, 2 ≤ N ≤ 50000.
0 ≤ Ti ≤ 106.

Sample


Input
 

Output
 
3
2
10 70
4
0 10 19 30
6
2 5 10 15 20 24
Case #1: 0
Case #2: 0.5
Case #3: 0.75
This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
10 points
Large input
29 points

Problem

Fair King Tyrone and his four sons conquered the nation of Carrania. His four sons immediately started to squabble about dividing the land between the four of them. The main point of contention was the gold mines of Carrania - each son wanted to have no fewer gold mines than any other.

Fair King Tyrone soon got tired of the squabbling, especially when he learned the number of mines is 4N, so dividing them should be easy. He gathered his sons, took a map, drew an X on it and declared each son would get one quarter of the nation, with borders defined by the X he drew.

Unfortunately, Fair King Tyrone is a bit shortsighted, and the map he drew on was not a map of Carrania. His first minister quickly hid the map, and now tries to draw an identical X on the map of Carrania so that each son gets the same number of gold mines. Unfortunately all sons saw King Tyrone draw the X, and know the borders should be two perpendicular straight lines - so the minister has to make them so.

Help him! Your task is to draw two perpendicular straight lines such that no gold mine lies on a border, and the borders divide the gold mines equally.

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case begins with a number N, describing the number of gold mines each son should get. 4N lines follow, each containing two integers, being the coordinates xi, yi of one of the gold mines. No three gold mines are co-linear.

Output

For each test case, output one line containing "Case #x: xa ya xb yb", where x is the case number (starting from 1), (xa, ya) are the coordinates of the point where the two borders intersect, and (xb, yb) are the coordinates of some other point on the X.

All coordinates must be between -109 and 109, have at most 9 digits after the decimal point, and not use exponential notation. They must be exact: the resulting X will be drawn exactly at these coordinates. You should output IMPOSSIBLE instead if there is no good placement of borders.

Limits

1 ≤ T ≤ 20
-106 ≤ xi, yi ≤ 106

Small dataset

1 ≤ N ≤ 10

Large dataset

1 ≤ N ≤ 2500

Sample


Input
 

Output
 
2
1
0 0
1 0
0 1
1 1
1
1 0
0 1
-1 0
0 -1
Case #1: 0.5 0.5 2 0.5
Case #2: 0 0 -3 -3
This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
11 points
Large input
32 points

Problem

This problem was inspired by a board game called Can't Stop, designed by Sid Sackson. This problem has a similar idea, but does not assume you have played Can't Stop.

You're playing a (very large) board game. In this game, you're given a sequence of N roll sets. Each roll set consists of D die rolls. Each die roll is an integer.

To win the game, you have to find the largest totally awesome interval of the sequence. An interval is any consecutive sequence of roll sets. An interval is called totally awesome if there exist k numbers such that every roll set in the interval contains at least one of those k numbers.

For example, suppose D=2 and k=3, and the roll sets are as follows:

Set 0: 10 20
Set 1: 50 60
Set 2: 70 30
Set 3: 40 40
Set 4: 30 30
Set 5: 20 40
The interval from Set 0 to Set 2 is totally awesome because roll sets 0-2 all contain 10, 50 or 70. The interval from Set 1 to Set 5 is totally awesome because roll sets 1-5 all contain 50, 30 or 40. That interval contains 5 roll sets, and it is the largest totally awesome interval.

Your job is to output the indices of the first and last roll set in the longest totally awesome interval. If there are multiple totally awesome intervals of that length, output the indices for the one with the lowest first index. Note that the first roll set has index 0.

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case starts with three space-separated integers: N, D and k, as described above. On the next line, there will be N*D integers. The first D integers will be the rolls from the first roll set; the second D integers will be the rolls from the second roll set; and so on.

Output

For each test case, output one line containing "Case #x: y z", where x is the case number (starting from 1), and y and z are the first and last indices of the longest totally awesome interval (with ties broken using the lowest index), as described above.

Limits

1 ≤ T ≤ 100.
1 ≤ D ≤ 4.
1 ≤ every die roll ≤ 105.
For 6 test cases, 1 ≤ N ≤ 105.
For all the other test cases, 1 ≤ N ≤ 103.

Small dataset

k = 2.

Large dataset

2 ≤ k ≤ 3.

Sample


Input
 

Output
 
4
8 1 2
1 2 3 2 4 5 4 6
4 3 2
1 2 3 4 5 6 7 8 9 10 11 12
6 2 3
10 20 50 60 70 30 40 40 30 30 20 40
10 1 3
2 4 3 1 4 5 3 1 1 2
Case #1: 1 3
Case #2: 0 1
Case #3: 1 5
Case #4: 1 4

The board game Can't Stop was designed by Sid Sackson, and has been published by many publishers. Neither Mr. Sackson nor any of the publishers endorses, or has any involvement with, Google Code Jam.

This contest is open for practice. You can try every problem as many times as you like, though we won't keep track of which problems you solve. Read the Quick-Start Guide to get started.
Small input
14 points
Large input
50 points

Problem

The story goes...

A long, long time ago, King Tyrone the Fair had 4 ministers. The first minister (the king's top adviser) was paid 7 gold pieces per week. The second minister was paid 4 gold pieces per week. The third and fourth ministers were each paid 6 gold pieces per week. Unfortunately, Tyrone accidentally forgot the Ministerial Compensation List in the photo copier one day, and the List ended up on the front page of the Kingdom Times newspaper. At this point, the second minister requested to speak to the king, upset that his own salary was lower than that of the lower ranked third minister.

His Fairness King Tyrone saw no other solution than to fire the third minister. After all, lowering the third minister's salary, raising the salary of the second minister, or changing job titles were all unfair solutions to the problem, in the king's opinion. And who are we to question King Tyrone? Of course, firing the third minister did not solve the problem. The second minister continued to complain because his salary was still lower than that of the fourth minister. So King Tyrone fired the fourth minister as well. At this point, neither of the two remaining ministers complained, and everyone lived happily ever after.

...wait a minute. I messed that up. I'm sorry. My memory is not what it used to be. One moment please... Right. King Tyrone the Fair. Four ministers. Paid 7, 4, 6, and 6 respectively. Ah, yes. The ending went like this...

When the second minister complained of unfairness, King Tyrone fired the first minister. Some might say this was a bit harsh, as the first minister wasn't involved in any way, but we shouldn't question King Tyrone. Obviously, the second minister still complained, so King Tyrone simply fired him. Of the remaining two ministers, each one was being paid at least as much as any minister below him, so none of them complained. And everyone lived happily ever after.

Much better... I think. Maybe? Now I'm not sure anymore. I know for certain that there were N ministers, and I clearly remember their salaries. I also know that every time a minister's salary was lower than the salary of a minister below him, somebody would complain, and some minister got fired; but that it could have been any minister, regardless of whether that minister had anything at all to do with the problem. Ministers continued to be fired until no one complained because all of the salaries were non-increasing. At that point, the firings stopped. But I do not remember in which order the ministers got fired.

Can you help me fix my story? Or at least please tell me how many different stories I could have told. Two stories are different if the sequences of fired ministers in them are not the same.

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each one consists of two lines. The first line will contain an integer N, and the second line will contain N space-separated integers denoting the ministers' salaries, in order from the first minister to the N'th minister.

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is the number of stories I could tell you, modulo 10007.

Limits

Each salary will be positive and at most 10000.

Small dataset

1 ≤ T ≤ 100.
1 ≤ N ≤ 100.

Large dataset

1 ≤ T ≤ 20.
For 80% of test cases, 1 ≤ N ≤ 2000.
For all test cases, 1 ≤ N ≤ 8000.

Sample


Input
 

Output
 
3
4
7 4 6 6
8
90 80 70 60 50 50 40 30
2
7 8
Case #1: 14
Case #2: 1
Case #3: 2
Overview  |  Problem A  |  Problem B  |  Problem C  |  Problem D  |  Problem E

Ivan Miatselski (mystic) earns the 2013 Champion title.

The problem set for the 2013 finals was nearly impossible to solve in its entirety. This meant that the contestants had to be strategic in deciding which problems they were going to try their hand at if they wanted a chance to win the grand prize. The point values for the problems were 25, 29, 39, 43, 64, making problem E “Let Me Tell You a Story” by far the most important. Strangely enough, it was the high point value that perhaps was the reason problem E went unsolved: many contestants mentioned after the finals that they assumed it to be too difficult because of the high point value, explaining why they didn’t try too hard to crack it.

However, problem C “X Marks the Spot” suddenly took its place as the toughest problem that was still solved. Geometry problems are always hard no matter how easy they look, and only staniek (winner of Round 1C), managed to deal with all its tricks correctly in almost two hours: he spent one hour before trying to submit, submitted an incorrect solution for C-small, then found a bug (he was drawing the border directly through a gold mine) and fixed it in 30 more minutes, and then spent another 20 minutes before getting the large input done. That put him in the prime position to win the grand prize, and the spectators were waiting for him to solve the problems that proved to be quite tractable for other contestants and jump into the first place - but he lost his best shot at victory when the clock ran out on his attempt to solve D-large.

That left the prizes up for grabs for people who were solving problems A, B and D. The eventual top three all managed to solve those three problems completely, and also solve one or two other smalls. In third place was Russia’s winger: but spending almost an hour and a half on D made it difficult for him to challenge the first two contestants. In second place was Ukraine’s Vasyl, who was actually the first to get all of A, B and D solved. The winner was Belarus’s mystic, who overtook Vasyl in the last hour of the contest by solving E-small about 10 minutes earlier than his Ukrainian opponent, and then cementing his first place with C-small. Having placed second in 2011, mystic has finally made the final step - congratulations to him, and to all finalists!

Google Code Jam 2013 is over now, but Google Code Jam 2014 will be here before you know it. We’re looking forward to seeing you all again soon!



Cast

Problem A. Graduation Requirements Written by David Arthur, with Onufry Wojtaszczyk. Prepared by Onufry Wojtaszczyk.

Problem B. Drummer Written by Igor Naverniouk. Prepared by Jan Kuipers.

Problem C. X Marks the Spot Written by Onufry Wojtaszczyk, with Tomek Czajka. Prepared by John Dethridge and Tomek Czajka.

Problem D. Can't Stop Written by David Arthur and Bartholomew Furrow. Prepared by Tomek Kulczyński, with Bartholomew Furrow.

Problem E. Let Me Tell You a Story Written Igor Naverniouk, with Tiancheng Lou. Prepared by Tiancheng Lou.

Contest analysis presented by Topraj Gurung, Tsung-Hsien Lee, Denis Savenkov, Onufry Wojtaszczyk, Jonathan Paulson, Petr Mitrichev and Bartholomew Furrow.

Sample solutions, statement and input verification and other problem preparation by Karim Nosir, Jan Kuipers, Igor Naverniouk, Petr Mitrichev, John Dethridge, David Arthur, Onufry Wojtaszczyk, Bartholomew Furrow, Steve Thomas and Jonathan Wills.

You cannot ask questions at this time. Please email us at codejam@google.com.
You have 0 submissions.