Manthan, Codefest 17


A. Tom Riddle's Diary
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
tom
lucius
ginny
harry
ginny
harry
Output
NO
NO
NO
NO
YES
YES
Input
3
a
a
a
Output
NO
YES
YES
----------------------------------------------------------------------------------------------------
B. Marvolo Gaunt's Ring
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 1 2 3
1 2 3 4 5
Output
30
Input
5 1 2 -3
-1 -2 -3 -4 -5
Output
12
----------------------------------------------------------------------------------------------------
C. Helga Hufflepuff's Cup
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 2
1 2
2 3
1 4
1 2
Output
1
Input
3 3
1 2
1 3
2 1
Output
13
Input
3 1
1 2
1 3
1 1
Output
0
----------------------------------------------------------------------------------------------------
D. Rowena Ravenclaw's Diadem
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
-1 -1
1 0
2 0
2
1 1 3
2 1 3
Output
YES
NO
Input
3
-1 -1
1 0
1 1
2
2 2 3
2 3 2
Output
YES
NO
----------------------------------------------------------------------------------------------------
E. Salazar Slytherin's Locket
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2 4 9
3 1 10
Output
1
2
Input
2
2 1 100
5 1 100
Output
21
4
----------------------------------------------------------------------------------------------------
F. Nagini
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 1 10 10
1 2 4 -7
2 1 10
Output
34
Input
7
1 2 3 5
1 1 10 10
1 4 5 -5
2 4 8
1 1 10 -10
2 4 8
2 1 10
Output
15
75
170
----------------------------------------------------------------------------------------------------
G. Harry Vs Voldemort
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1 2
2 3
1
2 3
Output
2
4
Input
4
1 2
2 3
2 4
2
1 4
3 4
Output
6
18
24
Input
5
1 2
2 3
3 4
4 5
1
1 5
Output
20
60
----------------------------------------------------------------------------------------------------
