Codeforces Global Round 14


A. Phoenix and Gold
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3 2
3 2 1
5 3
1 2 3 4 8
1 5
5
Output
YES
3 2 1
YES
8 1 2 3 4
NO
----------------------------------------------------------------------------------------------------
B. Phoenix and Puzzle
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
4
6
Output
YES
YES
NO
----------------------------------------------------------------------------------------------------
C. Phoenix and Towers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
5 2 3
1 2 3 1 2
4 3 3
1 1 2 3
Output
YES
1 1 1 2 2
YES
1 2 2 3
----------------------------------------------------------------------------------------------------
D. Phoenix and Socks
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
6 3 3
1 2 3 2 2 2
6 2 4
1 1 2 2 2 2
6 5 1
6 5 4 3 2 1
4 0 4
4 4 4 3
Output
2
3
5
3
----------------------------------------------------------------------------------------------------
E. Phoenix and Computers
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 100000007
Output
6
Input
4 100000007
Output
20
Input
400 234567899
Output
20914007
----------------------------------------------------------------------------------------------------
F. Phoenix and Earthquake
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 4 1
0 0 0 4 0
1 2
2 3
3 4
4 5
Output
YES
3
2
1
4
Input
2 1 2
1 1
1 2
Output
YES
1
Input
2 1 2
0 1
1 2
Output
NO
Input
5 6 5
0 9 4 0 10
1 2
1 3
2 3
3 4
1 4
4 5
Output
YES
6
4
1
2
----------------------------------------------------------------------------------------------------
G. Phoenix and Odometers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
1 2 1
2 3 1
3 1 2
1 4 3
3
1 1 3
1 2 4
4 0 1
Output
YES
NO
YES
Input
4 5
1 2 1
2 3 1
3 1 2
1 4 1
4 3 2
2
1 2 4
4 3 5
Output
YES
YES
----------------------------------------------------------------------------------------------------
H. Phoenix and Bits
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 6
5 4 3 2 1
1 2 3 2
4 2 5
3 2 5 3
4 1 6
2 1 1 8
4 8 10
Output
3
2
1
Input
6 7
6 0 2 3 2 7
1 0 4 3
2 6 8 4
4 0 7
3 2 5 3
1 0 1 2
4 0 3
4 2 7
Output
5
1
2
----------------------------------------------------------------------------------------------------
I. Phoenix and Diamonds
time limit per test: 5 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
3 5
2 3 4
1 5 1
0 2 4
3 6
1 3 3
3 10
2 2 3
3 30
Output
8
16
13
----------------------------------------------------------------------------------------------------
