VK Cup 2015 - Qualification Round 1


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

Examples
Input
5
tourist reposted Polycarp
Petr reposted Tourist
WJMZBMR reposted Petr
sdya reposted wjmzbmr
vepifanov reposted sdya
Output
6
Input
6
Mike reposted Polycarp
Max reposted Polycarp
EveryOne reposted Polycarp
111 reposted Polycarp
VkCup reposted Polycarp
Codeforces reposted Polycarp
Output
2
Input
1
SoMeStRaNgEgUe reposted PoLyCaRp
Output
2
----------------------------------------------------------------------------------------------------
B. Photo to Remember
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 10
5 5
10 1
Output
75 110 60 
Input
3
2 1
1 2
2 1
Output
6 4 6 
----------------------------------------------------------------------------------------------------
C. Chicken or Fish?
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
3 4
2 3 2 1
1 0
0 0
5 5
1 2 1 3 1
3 0
0 0
2 1
4 0
Output
YNNY
YYYNY
----------------------------------------------------------------------------------------------------
D. Closest Equals
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
1 1 2 3 2
1 5
2 4
3 5
Output
1
-1
2
Input
6 5
1 2 1 3 2 3
4 6
1 3
2 5
2 4
1 6
Output
2
2
3
-1
2
----------------------------------------------------------------------------------------------------
