School Personal Contest #1 (Winter Computer School 2010/11) - Codeforces Beta Round 38 (ACM-ICPC Rules)


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

Examples
Input
3
5 6
1 2
Output
5
Input
3
5 6
1 3
Output
11
----------------------------------------------------------------------------------------------------
B. Chess
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
a1
b2
Output
44
Input
a8
d4
Output
38
----------------------------------------------------------------------------------------------------
C. Blinds
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2
1 2 3 4
Output
8
Input
5 3
5 5 7 3 1
Output
15
Input
2 3
1 2
Output
0
----------------------------------------------------------------------------------------------------
D. Vasya the Architect
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
0 0 3 3
1 0 4 3
Output
2
Input
2
0 0 3 3
2 0 5 3
Output
1
Input
3
0 0 3 3
1 0 4 3
2 0 5 3
Output
3
----------------------------------------------------------------------------------------------------
E. Let's Go Rolling!
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 3
3 4
1 2
Output
5
Input
4
1 7
3 1
5 10
6 1
Output
11
----------------------------------------------------------------------------------------------------
F. Smart Boy
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
aba
abac
Output
Second
29 35
Input
3
artem
nik
max
Output
First
2403 1882
----------------------------------------------------------------------------------------------------
G. Queue
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1 0
2 1
Output
2 1 
Input
3
1 3
2 3
3 3
Output
3 2 1 
Input
5
2 3
1 4
4 3
3 1
5 2
Output
3 1 5 4 2 
----------------------------------------------------------------------------------------------------
H. The Great Marathon
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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