Codeforces Round 815 (Div. 2)


A. Burenka Plays with Fractions
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8
2 1 1 1
6 3 2 1
1 2 2 3
0 1 0 100
0 1 228 179
100 3 25 6
999999999 300000000 666666666 100000000
33 15 0 84
Output
1
0
2
0
1
1
1
1
----------------------------------------------------------------------------------------------------
B. Interesting Sum
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
8
1 2 2 3 1 5 6 1
5
1 2 3 100 200
4
3 3 3 3
6
7 8 3 1 1 8
Output
9
297
0
14
----------------------------------------------------------------------------------------------------
C. Corners
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 3
101
111
011
110
3 4
1110
0111
0111
2 2
00
00
2 2
11
11
Output
8
9
0
2
----------------------------------------------------------------------------------------------------
D1. Xor-Subsequence (easy version)
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
2
1 2
5
5 2 4 3 1
10
3 8 8 2 9 1 6 2 8 3
Output
2
3
6
----------------------------------------------------------------------------------------------------
D2. Xor-Subsequence (hard version)
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
2
1 2
5
5 2 4 3 1
10
3 8 8 2 9 1 6 2 8 3
Output
2
3
6
----------------------------------------------------------------------------------------------------
E. Misha and Paintings
time limit per test: 3.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4
1 1 1
1 1 2
3 4 5
Output
1
Input
3 2
2 1 3
2 1 1
3 1 2
Output
2
Input
3 3
1 1 1
1 1 2
2 2 2
Output
1
Input
3 2
1 1 1
1 2 1
2 2 2
Output
0
----------------------------------------------------------------------------------------------------
