Codeforces Round 162 (Div. 2)


A. Colorful Stones (Simplified Edition)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
RGB
RRR
Output
2
Input
RRRBGBRBBB
BBBRR
Output
3
Input
BRRBGBRGRBGRGRRGGBGBGBRGBRGRGGGRBRRRBRBBBGRRRGGBBB
BBRBGGRGRGBBBRBGRBRBBBBRBRRRBGBBGBBRRBBGGRBRRBRGRB
Output
15
----------------------------------------------------------------------------------------------------
B. Roadside Trees (Simplified Edition)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
1
2
Output
5
Input
5
2
1
2
1
1
Output
14
----------------------------------------------------------------------------------------------------
C. Escape from Stones
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
llrlr
Output
3
5
4
2
1
Input
rrlll
Output
1
2
5
4
3
Input
lrlrr
Output
2
4
5
3
1
----------------------------------------------------------------------------------------------------
D. Good Sequences
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
2 3 4 6 9
Output
4
Input
9
1 2 3 5 6 7 8 9 10
Output
4
----------------------------------------------------------------------------------------------------
E. Choosing Balls
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 3
1 -2 3 4 0 -1
1 2 1 2 1 1
5 1
-2 1
1 0
Output
20
9
4
Input
4 1
-3 6 -1 2
1 2 3 1
1 -1
Output
5
----------------------------------------------------------------------------------------------------
