Codeforces Round 221 (Div. 2)


A. Lever
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
=^==
Output
balance
Input
9===^==1
Output
left
Input
2==^7==
Output
right
Input
41^52==
Output
balance
----------------------------------------------------------------------------------------------------
B. I.O.U.
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
1 2 10
2 3 1
2 4 1
Output
10
Input
3 0
Output
0
Input
4 3
1 2 1
2 3 1
3 1 1
Output
0
----------------------------------------------------------------------------------------------------
C. 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
----------------------------------------------------------------------------------------------------
D. 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
----------------------------------------------------------------------------------------------------
E. 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
----------------------------------------------------------------------------------------------------
