Codeforces Round 443 (Div. 1)


A. Short Program
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
| 3
^ 2
| 1
Output
2
| 3
^ 2
Input
3
& 1
& 3
& 5
Output
1
& 1
Input
3
^ 1
^ 2
^ 3
Output
0
----------------------------------------------------------------------------------------------------
B. Teams Formation
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2 5
1 2 3 1
Output
12
Input
1 9 10
1
Output
1
Input
3 2 10
1 2 1
Output
0
----------------------------------------------------------------------------------------------------
C. Tournament
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
1 5
5 1
10 10
Output
1
2
1
Input
3 2
2 2
3 3
1 10
Output
1
1
3
Input
3 2
2 3
1 1
3 2
Output
1
1
2
----------------------------------------------------------------------------------------------------
D. Magic Breeding
time limit per test: 4 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
2 2 4
1 2
2 1
1 1 2
2 1 2
3 3 1
3 4 2
Output
2
1
Input
5 3 8
1 2 3 4 5
5 1 2 3 4
4 5 1 2 3
1 1 2
1 2 3
2 4 5
3 6 1
3 6 2
3 6 3
3 6 4
3 6 5
Output
5
2
2
3
4
----------------------------------------------------------------------------------------------------
E. Numbers on the blackboard
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 3
1 2 3
1 3
1 2
2 3
Output
17
5
8
Input
3 1
1 2 -3
1 3
Output
1000000006
Input
4 2
1 1 1 -1
1 4
3 4
Output
5
1000000006
----------------------------------------------------------------------------------------------------
