Codeforces Global Round 6


A. Competitive Programmer
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
603
006
205
228
1053
0000000000000000000000000000000000000000000000
Output
red
red
cyan
cyan
cyan
red
----------------------------------------------------------------------------------------------------
B. Dice Tower
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
29 34 19 38
Output
YES
YES
YES
NO
----------------------------------------------------------------------------------------------------
C. Diverse Matrix
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 2
Output
4 12
2 9
Input
1 1
Output
0
----------------------------------------------------------------------------------------------------
D. Decreasing Debts
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
1 2 10
2 3 5
Output
2
1 2 5
1 3 5
Input
3 3
1 2 10
2 3 15
3 1 10
Output
1
2 3 5
Input
4 2
1 2 12
3 4 8
Output
2
1 2 12
3 4 8
Input
3 4
2 3 1
2 3 2
2 3 4
2 3 8
Output
1
2 3 15
----------------------------------------------------------------------------------------------------
E. Spaceship Solitaire
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2 3
5
2 1 1
2 2 1
1 1 1
2 1 2
2 2 0
Output
4
3
3
2
3
----------------------------------------------------------------------------------------------------
F. Almost Same Distance
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2
1 3
1 4
4 5
Output
4 3 2 1 1
Input
6
1 2
1 3
1 4
4 5
4 6
Output
4 4 2 1 1 1
----------------------------------------------------------------------------------------------------
G. Permutation Concatenation
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
Output
8
Input
10
Output
19210869
----------------------------------------------------------------------------------------------------
H. Red-Blue Graph
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6
2 1
5 5
2 1
6 3
4 3
21
1 BBBBB
1 RBBBB
2 BBBBB
5 BRBBB
3 BRBBR
1 BRRBR
1 RRRBR
2 BRRBR
5 BBRBR
4 BBRBB
3 BBRRB
2 BBBRB
5 BRBRB
3 BRBRR
1 BRRRR
1 RRRRR
2 BRRRR
5 BBRRR
4 BBRRB
2 BRBBB
4 BRBBR
Output
0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
-1
-1
----------------------------------------------------------------------------------------------------
