Round 2 2013


  Submissions
Ticket Swapping
8pt
Not attempted
1580/2016 users correct (78%)
11pt
Not attempted
821/1451 users correct (57%)
Many Prizes
7pt
Not attempted
1150/1389 users correct (83%)
13pt
Not attempted
939/1094 users correct (86%)
Erdős–Szekeres
9pt
Not attempted
365/791 users correct (46%)
15pt
Not attempted
182/271 users correct (67%)
Multiplayer Pong
12pt
Not attempted
1/14 users correct (7%)
25pt
Not attempted
1/1 users correct (100%)
  Top Scores
bmerry89
hos.lyric63
Gennady.Korotkevich63
fanhqme63
dzhulgakov63
komaki63
EgorKulikov63
vepifanov63
Myth563
iwi63
Practice Mode

Problem B. Many Prizes

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
13 points

Problem

We're going to run a tournament with 2N teams, and give out P identical prizes to the teams with ranks 0..P-1.

The teams are numbered 0 through 2N-1. When team i and team j play against each other in a game, team i will win iff i<j.

The teams for a tournament are organized in some order, called the tournament's tournament list, which contains all 2N teams in the tournament. The tournament list will affect which teams play each other, and in what order.

Your job will be to find the largest-numbered team that is guaranteed to win a prize, independent of how the tournament list is ordered; and to find the largest-numbered team that could win a prize, depending on how the tournament list is ordered.

Tournament Resolution

The tournament is conducted in N rounds.

Each team has a record: the list of the results of the games it has played so far. For example, if a team has played three games, and won the first, lost the second and won the third, its record is [W, L, W]. If a team has played zero games, its record is [].

In each round, every team plays a game against a team with the same record. The first team in the tournament list with a particular record will play against the second team with that record; the third team with the same record will play against the fourth; and so on.

After N rounds, each team has a different record. The teams are ranked in reverse lexicographical order of their records; so [W, W, W] > [W, W, L] > [W, L, W] ... > [L, L, L].

Here is an example of a tournament with N=3, and the tournament list [2, 4, 5, 3, 6, 7, 1, 0], where the columns represent different rounds, and the teams are grouped by their records. The winner of each game in the example has been marked with a *.

Round 1    Round 2    Round 3    Final Result
                                 (best rank at top)
[]         [W]        [W,W]
2  *       2  *       2          0  [W,W,W]
4          3          0  *       2  [W,W,L]
                      [W,L]
5          6          3  *       3  [W,L,W]
3  *       0  *       6          6  [W,L,L]
           [L]        [L,W]
6  *       4  *       4          1  [L,W,W]
7          5          1  *       4  [L,W,L]
                      [L,L]
1          7          5  *       5  [L,L,W]
0  *       1  *       7          7  [L,L,L]

If we give out 4 prizes (N=3, P=4), the prizes will go to teams 0, 2, 3 and 6.

The largest-numbered team that was guaranteed to win a prize with N=3, P=4, independent of the order of the tournament list, was team 0: this tournament list demonstrated that it's possible for team 1 not to win a prize, and it turns out that team 0 will always win one, regardless of the order of the tournament list.

The largest-numbered team that could win a prize with N=3, P=4, depending on how the tournament list was ordered, was team 6: this tournament list demonstrated that it's possible for team 6 to win a prize, and it turns out that team 7 will never win one, regardless of the order of the tournament list.

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of two space-separated integers: N, which indicates the tournament has 2N teams, and P, the number of prizes.

Output

For each test case, output one line containing "Case #x: y z", where x is the case number (starting from 1), y is the largest-numbered team that is guaranteed to win a prize, independent of how the tournament list is ordered; and z is the largest-numbered team that could win a prize, depending on how the tournament list is ordered.

Limits

1 ≤ T ≤ 100.
1 ≤ P ≤ 2N.

Small dataset

1 ≤ N ≤ 10.

Large dataset

1 ≤ N ≤ 50.

Sample


Input
 

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

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
15 points

Problem

Given a list X, consisting of the numbers (1, 2, ..., N), an increasing subsequence is a subset of these numbers which appears in increasing order, and a decreasing subsequence is a subset of those numbers which appears in decreasing order. For example, (5, 7, 8) is an increasing subsequence of (4, 5, 3, 7, 6, 2, 8, 1).

Nearly 80 years ago, two mathematicians, Paul Erdős and George Szekeres proved a famous result: X is guaranteed to have either an increasing subsequence of length at least sqrt(N) or a decreasing subsequence of length of at least sqrt(N). For example, (4, 5, 3, 7, 6, 2, 8, 1) has a decreasing subsequence of length 4: (5, 3, 2, 1).

I am teaching a combinatorics class, and I want to "prove" this theorem to my class by example. For every number X[i] in the sequence, I will calculate two values:

  • A[i]: The length of the longest increasing subsequence of X that includes X[i] as its largest number.
  • B[i]: The length of the longest decreasing subsequence of X that includes X[i] as its largest number.
The key part of my proof will be that the pair (A[i], B[i]) is different for every i, and this implies that either A[i] or B[i] must be at least sqrt(N) for some i. For the sequence listed above, here are all the values of A[i] and B[i]:
  i  |  X[i]  |  A[i]  |  B[i] 
-----+--------+--------+--------
  0  |   4    |   1    |   4
  1  |   5    |   2    |   4
  2  |   3    |   1    |   3
  3  |   7    |   3    |   4
  4  |   6    |   3    |   3
  5  |   2    |   1    |   2
  6  |   8    |   4    |   2
  7  |   1    |   1    |   1

I came up with a really interesting sequence to demonstrate this fact with, and I calculated A[i] and B[i] for every i, but then I forgot what my original sequence was. Given A[i] and B[i], can you help me reconstruct X?

X should consist of the numbers (1, 2, ..., N) in some order, and if there are multiple sequences possible, you should choose the one that is lexicographically smallest. This means that X[0] should be as small as possible, and if there are still multiple solutions, then X[1] should be as small as possible, and so on.

Input

The first line of the input gives the number of test cases, T. T test cases follow, each consisting of three lines.

The first line of each test case contains a single integer N. The second line contains N positive integers separated by spaces, representing A[0], A[1], ..., A[N-1]. The third line also contains N positive integers separated by spaces, representing B[0], B[1], ..., B[N-1].

Output

For each test case, output one line containing "Case #x: ", followed by X[0], X[1], ... X[N-1] in order, and separated by spaces.

Limits

1 ≤ T ≤ 30.
It is guaranteed that there is at least one possible solution for X.

Small dataset

1 ≤ N ≤ 20.

Large dataset

1 ≤ N ≤ 2000.

Sample


Input
 

Output
 
2
1
1
1
8
1 2 1 3 3 1 4 1
4 4 3 4 3 2 2 1
Case #1: 1
Case #2: 4 5 3 7 6 2 8 1

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
12 points
Large input
25 points

Problem

Two teams of players play pong. Pong is a simple computer game, where each player controls a paddle (which we assume to be a point), and a little ball bounces back and forth. The players in one team are required to bounce the ball in a fixed cyclic order (so in a three-player team, the first one to touch the ball would be P1, then P2, then P3 and only then P1 again), until one of the players doesn't manage to bounce it, at which point the ball leaves the playing field and this player's team loses.

To be more precise: the playing field is a rectangle of size AxB. On each vertical wall (of length A) there are a number of paddles, one for each player of the team guarding this wall. Each paddle is a point. All the paddles of the players on one team move vertically at the same speed (in units per second), and can pass each other freely. There is also a ball, for which we are given its initial position (horizontal and vertical, counted from the lower-left corner) and initial speed (horizontal and vertical, again in units per second). The players are allowed to choose the initial positioning of their paddles on their vertical walls knowing the initial position of the ball. Whenever the ball reaches a horizontal wall, it bounces off (with the angle of incidence equal to the angle of reflection). Whenever it reaches a vertical end of the field, if the paddle of the player who is supposed to touch the ball now is there, it bounces off, while if there isn't, the team of the player whose paddle was supposed to be there loses.

The game can take quite a long time, with the players bouncing the ball back and forth. Your goal is to determine the final result (assuming all players play optimally).

Input

The first line of the input gives the number of test cases, T. T test cases follow. Each test case consists of four lines. The first line contains two integers, A and B, describing the height and width of the playing field. The second line contains two integers, N and M, describing the sizes of the two teams: N is the number of players on the team with paddles on the X = 0 wall, and M is the number of players on the team with paddles on X = B wall. The third line contains two integers, V and W, describing the speed of the paddles of players in the first and second team, respectively. The fourth line contains four integers: Y, X, VY and VX, describing the initial position (vertical and horizontal) and initial speed of the ball (the ball moves by VY units up and VX to the right each second, until it bounces).

Output

For each test case, output one line containing "Case #x: y", where x is the case number (starting from 1) and y is one of the three possible outputs: "DRAW" (if the game can proceed forever), "LEFT z", if the team with paddles on x = 0 wins, and the opposing team can bounce the ball at most z times, or "RIGHT z" if the team with paddles on X = B wins and the opposing team can bounce the ball at most z times.

Limits

1 ≤ T ≤ 100.
0 < X < B
0 < Y < A

Small dataset

1 ≤ N, M ≤ 106
1 ≤ V, W ≤ 1012
-1012VY ≤ 1012
-106VX ≤ 106
2 ≤ A, B ≤ 106

Large dataset

1 ≤ N, M ≤ 10100
1 ≤ V, W ≤ 10100
-10100VY, VX ≤ 10100
2 ≤ A, B ≤ 10100

Sample


Input
 

Output
 
4
6 4
1 2
3 1
5 1 4 8
12 3
3 1
2 3
1 1 2 4
12 3
1 3
3 1
1 1 2 4
12 2
1 2
10 2
3 1 13 4
Case #1: LEFT 2
Case #2: DRAW
Case #3: LEFT 3
Case #4: RIGHT 11

The picture depicts the gameplay in the first sample case. The ball bounces off the right wall at time 0.375 (the first RIGHT player intercepts it, for instance by beginning with her paddle there and not moving it), then off the left wall at 0.875 (the LEFT player bounces it), again on the right at time 1.375 (the second RIGHT player can position his paddle at the bounce point), again on the left (where the LEFT player gets just in time to catch it — she covers the three units of distance exactly in one second in which she needs to get there) and then hits the right wall too far for the first RIGHT player to get there. Note the second RIGHT player could catch the ball, but is not allowed by the rules to do so. Also note that if RIGHT team had one player more, she could bounce the ball, and then LEFT would lose — the ball would come too far up for the single LEFT player to get there in time.

Overview  |  Problem A  |  Problem B  |  Problem C  |  Problem D

In this round, rng..58 took an early lead by solving problem B while most other contestants were working on A. Soon after, fellow Japanese contestants hos.lyric and komaki jumped to the top with problems B and C solved, also skipping problem A.

One hour into the contest, over 100 contestants had correctly solved problem A or B, with very few solutions for C, and no attempts on D. At that point, it looked as if solving both A and B might be enough to guarantee a ticket to round 3. In another half an hour, there were just over 20 correct solutions for problem C, but still no correct attempts for problem D, not even for D-small.

The top 3 spots remained unchanged for over an hour -- hos.lyric, Gennady.Korotkevich, and fanhqme -- each with problems A, B and C. This remained the case until the very last minute, when bmerry came in with an impressive solution for both parts of problem D, earning him the top spot on the scoreboard. He submitted his D-large solution with only 6 seconds left on the clock!


Cast

Problem A. Ticket Swapping written by Onufry Wojtaszczyk. Prepared by Tomek Czajka.

Problem B. Many Prizes written by Bartholomew Furrow. Prepared by Tomek Czajka.

Problem C. Erdős–Szekeres written and prepared by David Arthur.

Problem D. Multiplayer Pong written and prepared by Onufry Wojtaszczyk.

Contest analysis presented by Onufry Wojtaszczyk. Solutions and other problem preparation by Ahmed Aly, Igor Naverniouk, Tomek Kulczynski, John Dethridge, Tiancheng Lou, Steve Thomas, Jan Kuipers, and Tomek Czajka.

Category  Asked  Question  Answered  Answer
Multiplayer Pong
Announcement
1:51:24What happens if the ball run into the corner of the field? Will it be reflected back? Should there be a paddle in a corner?2:00:03The standard thing happens. You bounce in both axes, meaning you go back the way you came, and yes, you do have to have a paddle. Treat this as two bounces, order irrelevant.
Multiplayer Pong
Announcement
38:56It's described how the ball reflects off horizontal walls, but what direction does it travel in after bouncing off a paddle?2:05:22Angle of incidence equals angle of reflection, as in the case of walls.
You cannot ask questions at this time. Please email us at codejam@google.com.
You have 0 submissions.