Codeforces Round 316 (Div. 2)


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

Examples
Input
3 3
1 2 3
2 3 1
1 2 1
Output
2
Input
3 4
10 10 3
5 1 6
2 2 2
1 5 7
Output
1
----------------------------------------------------------------------------------------------------
B. Simple Game
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 1
Output
2
Input
4 3
Output
2
----------------------------------------------------------------------------------------------------
C. Replacement
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10 3
.b..bz....
1 h
3 c
9 f
Output
4
3
1
Input
4 4
.cc.
2 .
3 .
2 a
1 a
Output
1
3
1
1
----------------------------------------------------------------------------------------------------
D. Tree Requests
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 5
1 1 1 3 3
zacccd
1 1
3 3
4 1
6 1
1 2
Output
Yes
No
Yes
Yes
Yes
----------------------------------------------------------------------------------------------------
E. Pig and Palindromes
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4
aaab
baaa
abba
Output
3
----------------------------------------------------------------------------------------------------
