Facebook Hacker Cup 2015 Round 2
Mr. Fox sure loves his socks! He stores his many indistinguishable socks in a set of
Never being quite satisfied with his sock collection, Mr. Fox would like to perform
- Given integers
, , , and , add socks to bin , add socks to the next bin clockwise of bin , add to the next bin clockwise of that one, and so on until this has been done for bins. Determine the total number of socks added in this process. - Given integers
, , and , remove all of the socks from bin and then add socks to it. Do the same for the next bin clockwise of , and so on until this has been done for bins. Determine the sum of two values: the total number of socks removed in this process, and the total number of socks added in this process. - Given integers
and , count the number of socks in bin (without removing them), the number of socks in the next bin clockwise of , and so on until the socks in bins have been counted. Determine the total number of socks counted in this process. - Given integers
and , check if bin contains an odd number of socks. Do the same for the next bin clockwise of , and so on until this has been done for bins. Determine the total number of these bins that contain an odd number of socks.
Can you help Mr. Fox keep track of his socks?
Note the value calculated during each of the
Input
Input begins with an integer
The first two elements of each sequence of integers (
, for , for , for , for , for , for
Output
For the Case #i:
followed by the sum of all values calculated during each operation, modulo
Constraints
Explanation of Sample
The first collection has 5 bins that all have 0 socks. None of the operations involve any socks at all, so the answer is 0.
The second collection has 5 bins with 1, 2, 3, 4, and 5 socks. Mr. Fox performs the operations 1, 2, 3, and 4 in order. For each operation,
The third collection also has 5 bins with 1, 2, 3, 4, and 5 socks. Mr. Fox performs the same operations, but this time
Sample Input
5
5 4
0 0 0 0 0
1 2 0 1 0
1 1 0 0 0
1 1 0 0 0
0 0 0 0 0
0 0 0 0 0
5 4
1 2 0 1 1
1 2 0 1 0
1 1 0 0 0
5 5 0 1 4
0 0 0 0 0
0 0 0 0 0
5 4
1 2 0 1 1
1 2 0 1 0
1 1 0 0 0
5 5 0 1 4
1 2 0 1 1
1 2 0 1 1
5 2
1 2 0 1 1
4 4 0 0 0
1 1 0 0 0
5 5 0 0 0
0 0 0 0 0
0 0 0 0 0
100 100
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
1 2 3 4 5
Sample Output
Case #1: 0
Case #2: 15
Case #3: 65
Case #4: 6
Case #5: 505274484
Comments