Hello 2019


A. Gennady and a Card Game
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
AS
2H 4C TH JH AD
Output
YES
Input
2H
3D 4C AC KD AS
Output
NO
Input
4D
AS AC AD AH 5H
Output
YES
----------------------------------------------------------------------------------------------------
B. Petr and a Combination Lock
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
10
20
30
Output
YES
Input
3
10
10
10
Output
NO
Input
3
120
120
120
Output
YES
----------------------------------------------------------------------------------------------------
C. Yuhao and a Parenthesis
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
)())
)
((
((
(
)
)
Output
2
Input
4
(
((
(((
(())
Output
0
Input
2
(())
()
Output
1
----------------------------------------------------------------------------------------------------
D. Makoto and a Blackboard
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 1
Output
3
Input
6 2
Output
875000008
Input
60 5
Output
237178099
----------------------------------------------------------------------------------------------------
E. Egor and an RPG game
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4
4 3 1 2
6
4 5 6 1 3 2
10
1 2 3 4 5 6 7 8 9 10
Output
2
3 4 3 1
1 2
3
2 4 1
2 5 6
2 3 2
1
10 1 2 3 4 5 6 7 8 9 10
----------------------------------------------------------------------------------------------------
F. Alex and a TV Show
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 13
1 1 1
1 2 4
1 3 6
4 4 4
1 4 4
2 2 1 2
2 3 3 4
4 4 4
3 2 2 3
4 2 1
4 2 2
4 2 3
4 2 4
Output
010101
----------------------------------------------------------------------------------------------------
G. Vladislav and a Great Legend
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
4 1
1 2
2 3
2 4
Output
21
Input
4 2
1 2
2 3
2 4
Output
45
Input
5 3
1 2
2 3
3 4
4 5
Output
780
----------------------------------------------------------------------------------------------------
H. Mateusz and an Infinite Sequence
time limit per test: 7 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 2
0 1
4
0 1 1 0
2 21
Output
6
Input
3 4
0 1 2
2
0 2
6 11
Output
1
----------------------------------------------------------------------------------------------------
