Codeforces Round 147 (Div. 2)


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

Examples
Input
4
8 0
8 10
8 10
8 45
Output
2
Input
3
0 12
10 11
22 22
Output
1
----------------------------------------------------------------------------------------------------
B. Young Table
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3 2 1
4 3 5
6 1
2
Output
2
1 1 2 2
2 1 3 1
Input
1
4
4 3 2 1
Output
2
1 1 1 4
1 2 1 3
----------------------------------------------------------------------------------------------------
C. Primes on Interval
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 4 2
Output
3
Input
6 13 1
Output
4
Input
1 4 3
Output
-1
----------------------------------------------------------------------------------------------------
D. T-decomposition
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1 2
Output
1
2 1 2
Input
3
1 2
2 3
Output
2
2 1 2
2 2 3
1 2
Input
4
2 1
3 1
4 1
Output
3
2 2 1
2 3 1
2 4 1
1 2
2 3
----------------------------------------------------------------------------------------------------
E. Build String
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
bbaze
3
bzb 2
aeb 3
ba 10
Output
8
Input
abacaba
4
aba 2
bcc 1
caa 2
bbb 5
Output
18
Input
xyz
4
axx 8
za 1
efg 4
t 1
Output
-1
----------------------------------------------------------------------------------------------------
