ABBYY Cup 3.0


A1. Special Task
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
AJ
Output
81
Input
1?AA
Output
100
----------------------------------------------------------------------------------------------------
A2. Special Task
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
AJ
Output
81
Input
1?AA
Output
100
----------------------------------------------------------------------------------------------------
B1. EKG
time limit per test: 0.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 1
2 0 4 0 6 0
Output
2
4
6
Input
6 2
2 3 0 5 6 0
Output
2
5
Input
4 1
0 0 0 0
Output
1
2
3
4
Input
6 2
0 0 1 0 4 5
Output
1
3
4
6
----------------------------------------------------------------------------------------------------
B2. EKG
time limit per test: 0.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 1
2 0 4 0 6 0
Output
2
4
6
Input
6 2
2 3 0 5 6 0
Output
2
5
Input
4 1
0 0 0 0
Output
1
2
3
4
Input
6 2
0 0 1 0 4 5
Output
1
3
4
6
----------------------------------------------------------------------------------------------------
C1. Tidying Up
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
1 1 2
2 3 3
Output
2
Input
3 4
1 3 2 6
2 1 5 6
4 4 5 3
Output
4
----------------------------------------------------------------------------------------------------
C2. Tidying Up
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 3
1 1 2
2 3 3
Output
2
Input
3 4
1 3 2 6
2 1 5 6
4 4 5 3
Output
4
----------------------------------------------------------------------------------------------------
D1. PE Lesson
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 2 1 2
Output
120
Input
8
1 2 2 1 2 1 1 2
Output
16800
----------------------------------------------------------------------------------------------------
D2. PE Lesson
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 2 1 2
Output
120
Input
8
1 2 2 1 2 1 1 2
Output
16800
----------------------------------------------------------------------------------------------------
D3. PE Lesson
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 2 1 2
Output
120
Input
8
1 2 2 1 2 1 1 2
Output
16800
----------------------------------------------------------------------------------------------------
E1. Summer Homework
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
1 3 1 2 4
2 1 4
2 1 5
2 2 4
1 3 10
2 1 5
Output
12
32
8
50
Input
5 4
1 3 1 2 4
3 1 4 1
2 2 4
1 2 10
2 1 5
Output
12
45
----------------------------------------------------------------------------------------------------
E2. Summer Homework
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
1 3 1 2 4
2 1 4
2 1 5
2 2 4
1 3 10
2 1 5
Output
12
32
8
50
Input
5 4
1 3 1 2 4
3 1 4 1
2 2 4
1 2 10
2 1 5
Output
12
45
----------------------------------------------------------------------------------------------------
E3. Summer Homework
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 5
1 3 1 2 4
2 1 4
2 1 5
2 2 4
1 3 10
2 1 5
Output
12
32
8
50
Input
5 4
1 3 1 2 4
3 1 4 1
2 2 4
1 2 10
2 1 5
Output
12
45
----------------------------------------------------------------------------------------------------
F1. Suns and Rays
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

No test samples are available for this problem
----------------------------------------------------------------------------------------------------
F2. Suns and Rays
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

No test samples are available for this problem
----------------------------------------------------------------------------------------------------
F3. Suns and Rays
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

No test samples are available for this problem
----------------------------------------------------------------------------------------------------
G1. Good Substrings
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
aaab
2
aa 0 0
aab 1 1
Output
3
Input
ltntlnen
3
n 0 0
ttlneenl 1 4
lelllt 1 1
Output
2
Input
a
0
Output
1
----------------------------------------------------------------------------------------------------
G2. Good Substrings
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
aaab
2
aa 0 0
aab 1 1
Output
3
Input
ltntlnen
3
n 0 0
ttlneenl 1 4
lelllt 1 1
Output
2
Input
a
0
Output
1
----------------------------------------------------------------------------------------------------
G3. Good Substrings
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
aaab
2
aa 0 0
aab 1 1
Output
3
Input
ltntlnen
3
n 0 0
ttlneenl 1 4
lelllt 1 1
Output
2
Input
a
0
Output
1
----------------------------------------------------------------------------------------------------
