VK Cup 2012 Qualification Round 2


A. Friends or Not
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 1
vasya petya 1
petya vasya 2
anya ivan 2
ivan anya 4
Output
1
petya vasya
Input
1 1000
a b 0
Output
0
----------------------------------------------------------------------------------------------------
B. Matchmaker
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 4
1 2
3 4
2 4
5 4
2 4
1 1
1 2
Output
3 2
Input
2 2
1 2
2 1
3 4
5 1
Output
1 0
----------------------------------------------------------------------------------------------------
C. String Manipulation 1.0
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
bac
3
2 a
1 b
2 c
Output
acb
Input
1
abacaba
4
1 a
1 a
1 c
2 b
Output
baa
----------------------------------------------------------------------------------------------------
D. Palindrome pairs
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
aa
Output
1
Input
aaa
Output
5
Input
abacaba
Output
36
----------------------------------------------------------------------------------------------------
E. Zebra Tower
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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