Codeforces Round 221 (Div. 1)


A. Divisible by Seven
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1689
Output
1869
Input
18906
Output
18690
----------------------------------------------------------------------------------------------------
B. Maximum Submatrix 2
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
1 1
1
Output
1
Input
2 2
10
11
Output
2
Input
4 3
100
011
000
101
Output
2
----------------------------------------------------------------------------------------------------
C. Circling Round Treasures
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
....
.S1.
....
....
10
Output
2
Input
7 7
.......
.1###2.
.#...#.
.#.B.#.
.3...4.
..##...
......S
100
100
100
100
Output
364
Input
7 8
........
........
....1B..
.S......
....2...
3.......
........
100
-100
100
Output
0
Input
1 1
S
Output
0
----------------------------------------------------------------------------------------------------
D. Tree and Queries
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8 5
1 2 2 3 3 2 3 3
1 2
1 5
2 3
2 4
5 6
5 7
5 8
1 2
1 3
1 4
2 3
5 3
Output
2
2
1
0
1
Input
4 1
1 2 3 4
1 2
2 3
3 4
1 1
Output
4
----------------------------------------------------------------------------------------------------
E. Red and Black Tree
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
1 0 0
1 2 2
2 3 2
Output
1
Input
4 2
0 1 0 0
1 2 2
2 3 2
3 4 2
Output
-1
----------------------------------------------------------------------------------------------------
