Croc Champ 2012 - Qualification Round


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

Examples
Input
4
00209
00219
00999
00909
Output
2
Input
2
1
2
Output
0
Input
3
77012345678999999999
77012345678901234567
77012345678998765432
Output
12
----------------------------------------------------------------------------------------------------
B. Pseudorandom Sequence Period
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 6 12 11
Output
2
Input
2 3 5 1
Output
4
Input
3 6 81 9
Output
1
----------------------------------------------------------------------------------------------------
C. Bus
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 10
3 5
Output
8
Input
2 1
3 5
4 5
Output
8 19
Input
5 4
3 5
4 5
5 5
6 5
7 1
Output
11 11 11 11 20
Input
20 4
28 13
31 13
35 6
36 4
52 6
53 4
83 2
84 4
87 1
93 6
108 4
113 6
116 1
125 2
130 2
136 13
162 2
166 4
184 1
192 2
Output
51 51 43 40 93 89 86 89 114 121 118 121 137 139 139 152 195 199 193 195
----------------------------------------------------------------------------------------------------
D. Calendar Reform
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
25 3
Output
30
Input
50 5
Output
125
----------------------------------------------------------------------------------------------------
E. BHTML+BCSS
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
<a><b><b></b></b></a><a><b></b><b><v/></b></a><b></b>
4
a
a b b
a b
b a
Output
2
1
4
0
Input
<b><aa/></b><aa><b/><b/></aa>
5
aa b
b
aa
b aa
a
Output
2
3
2
1
0
----------------------------------------------------------------------------------------------------
