Codeforces Round 662 (Div. 2)


A. Rainbow Dash, Fluttershy and Chess Coloring
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
3
4
Output
2
3
----------------------------------------------------------------------------------------------------
B. Applejack and Storages
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
1 1 1 2 1 1
6
+ 2
+ 1
- 1
+ 2
- 1
+ 2
Output
NO
YES
NO
NO
NO
YES
----------------------------------------------------------------------------------------------------
C. Pinkie Pie Eats Patty-cakes
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
7
1 7 1 6 4 4 6
8
1 1 4 6 4 6 4 7
3
3 3 3
6
2 5 2 3 1 4
Output
3
2
0
4
----------------------------------------------------------------------------------------------------
D. Rarity and New Dress
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 3
aaa
aaa
aaa
Output
10
Input
3 4
abab
baba
abab
Output
12
Input
5 5
zbacg
baaac
aaaaa
eaaad
weadd
Output
31
----------------------------------------------------------------------------------------------------
E1. Twilight and Ancient Scroll (easier version)
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
abcd
zaza
ataka
Output
4
Input
4
dfs
bfs
sms
mms
Output
8
Input
3
abc
bcd
a
Output
0
Input
6
lapochka
kartyshka
bigbabytape
morgenshtern
ssshhhiiittt
queen
Output
2028
----------------------------------------------------------------------------------------------------
E2. Twilight and Ancient Scroll (harder version)
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
abcd
zaza
ataka
Output
4
Input
4
dfs
bfs
sms
mms
Output
8
Input
3
abc
bcd
a
Output
0
Input
6
lapochka
kartyshka
bigbabytape
morgenshtern
ssshhhiiittt
queen
Output
2028
----------------------------------------------------------------------------------------------------
