Codeforces Round 553 (Div. 2)


A. Maxim and Biology
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
ZCTH
Output
2
Input
5
ZDATG
Output
5
Input
6
AFBAKC
Output
16
----------------------------------------------------------------------------------------------------
B. Dima and a Bad XOR
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
0 0
0 0
0 0
Output
NIE
Input
2 3
7 7 7
7 7 10
Output
TAK
1 3 
----------------------------------------------------------------------------------------------------
C. Problem for Nazar
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 3
Output
7
Input
5 14
Output
105
Input
88005553535 99999999999
Output
761141116
----------------------------------------------------------------------------------------------------
D. Stas and the Queue at the Buffet
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4 2
2 3
6 1
Output
12
Input
4
2 4
3 3
7 1
2 3
Output
25
Input
10
5 10
12 4
31 45
20 55
30 17
29 30
41 32
7 1
5 5
3 15
Output
1423
----------------------------------------------------------------------------------------------------
E. Number of Components
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 1 3
Output
7
Input
4
2 1 1 3
Output
11
Input
10
1 5 2 5 5 3 10 6 5 1
Output
104
----------------------------------------------------------------------------------------------------
F. Sonya and Informatics
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
0 1 0
Output
333333336
Input
5 1
1 1 1 0 0
Output
0
Input
6 4
1 0 0 1 1 0
Output
968493834
----------------------------------------------------------------------------------------------------
