Codeforces Round 402 (Div. 2)


A. Pupils Redistribution
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5 4 4 4
5 5 4 5
Output
1
Input
6
1 1 1 1 1 1
5 5 5 5 5 5
Output
3
Input
1
5
3
Output
-1
Input
9
3 2 5 5 2 3 3 3 2
4 1 4 1 1 2 4 4 1
Output
4
----------------------------------------------------------------------------------------------------
B. Weird Rounding
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
30020 3
Output
1
Input
100 9
Output
2
Input
10203049 2
Output
3
----------------------------------------------------------------------------------------------------
C. Dishonest Sellers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1
5 4 6
3 1 5
Output
10
Input
5 3
3 4 7 10 3
4 5 5 12 5
Output
25
----------------------------------------------------------------------------------------------------
D. String Game
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
ababcba
abb
5 3 4 1 7 6 2
Output
3
Input
bbbabb
bb
1 6 3 4 2 5
Output
4
----------------------------------------------------------------------------------------------------
E. Bitwise Formula
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 3
a := 101
b := 011
c := ? XOR b
Output
011
100
Input
5 1
a := 1
bb := 0
cx := ? OR a
d := ? XOR ?
e := d AND bb
Output
0
0
----------------------------------------------------------------------------------------------------
F. Peterson Polyglot
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 c
2 3 a
3 4 t
2 5 t
Output
3
2
Input
16
1 2 o
2 3 f
1 4 p
4 5 i
5 6 e
6 7 c
7 8 e
4 9 r
9 10 e
10 11 t
11 12 t
12 13 y
10 14 f
14 15 i
15 16 x
Output
12
2
----------------------------------------------------------------------------------------------------
