Codeforces Round 556 (Div. 1)


A. Prefix Sum Primes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 1 2 1
Output
1 1 1 2 2
Input
9
1 1 2 1 1 1 2 1 1
Output
1 1 1 2 1 1 1 2 1
----------------------------------------------------------------------------------------------------
B. Three Religions
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 8
abdabc
+ 1 a
+ 1 d
+ 2 b
+ 2 c
+ 3 a
+ 3 b
+ 1 c
- 2
Output
YES
YES
YES
YES
YES
YES
NO
YES
Input
6 8
abbaab
+ 1 a
+ 2 a
+ 3 a
+ 1 b
+ 2 b
+ 3 b
- 1
+ 2 z
Output
YES
YES
YES
YES
YES
NO
YES
NO
----------------------------------------------------------------------------------------------------
C. Tree Generator™
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
(((())))
4 5
3 4
5 6
3 6
2 5
Output
4
3
3
2
4
4
Input
6 4
(((())()))
6 7
5 4
6 4
7 4
Output
4
4
4
5
3
----------------------------------------------------------------------------------------------------
D. Abandoning Roads
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5 5 20 25
1 2 25
2 3 25
3 4 20
4 5 20
5 1 20
Output
0 25 60 40 20
Input
6 7 13 22
1 2 13
2 3 13
1 4 22
3 4 13
4 5 13
5 6 13
6 1 13
Output
0 13 26 39 26 13
----------------------------------------------------------------------------------------------------
E. Election Promises
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2
2 1 1 5
1 2
3 4
Output
WIN
1 5 1 5 
Input
4 2
1 5 1 5
1 2
3 4
Output
LOSE
Input
3 3
314 159 265
1 2
1 3
3 2
Output
WIN
0 0 0 
Input
6 4
2 2 5 5 6 6
1 3
2 4
3 5
4 6
Output
LOSE
----------------------------------------------------------------------------------------------------
