Codeforces Round 310 (Div. 1)


A. Case of Matryoshkas
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
2 1 2
1 3
Output
1
Input
7 3
3 1 3 7
2 2 5
2 4 6
Output
10
----------------------------------------------------------------------------------------------------
B. Case of Fugitive
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4
1 4
7 8
9 10
12 14
4 5 3 8
Output
Yes
2 3 1 
Input
2 2
11 14
17 18
2 9
Output
No
Input
2 1
1 1
1000000000000000000 1000000000000000000
999999999999999999
Output
Yes
1 
----------------------------------------------------------------------------------------------------
C. Case of Chocolate
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 5
3 4 U
6 1 L
2 5 L
1 6 U
4 3 U
Output
4
3
2
1
2
Input
10 6
2 9 U
10 1 U
1 10 U
8 3 L
10 1 L
6 5 U
Output
9
1
10
6
0
2
----------------------------------------------------------------------------------------------------
D. Case of a Top Secret
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2
0 3 5
2 3
1 8
Output
3
2
Input
4 4
1 5 7 15
1 4
2 15
3 16
1 28
Output
2
4
3
1
----------------------------------------------------------------------------------------------------
E. Case of Computer Network
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4 4 2
1 2
1 3
2 3
3 4
1 3
4 2
Output
Yes
Input
3 2 2
1 2
3 2
1 3
2 1
Output
No
Input
3 3 2
1 2
1 2
3 2
1 3
2 1
Output
Yes
----------------------------------------------------------------------------------------------------
