Codeforces Round 101 (Div. 2)


A. Amusing Joke
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
SANTACLAUS
DEDMOROZ
SANTAMOROZDEDCLAUS
Output
YES
Input
PAPAINOEL
JOULUPUKKI
JOULNAPAOILELUPUKKI
Output
NO
Input
BABBONATALE
FATHERCHRISTMAS
BABCHRISTMASBONATALLEFATHER
Output
NO
----------------------------------------------------------------------------------------------------
B. Hopscotch
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
4
a 0
b 2
c 0
d 0
Output
a 150
c 170
d 180
b 160
Input
4
vasya 0
petya 1
manya 3
dunay 3
Output
-1
----------------------------------------------------------------------------------------------------
D. Take-off Ramps
time limit per test: 4 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 20
5 10 5 5
4 16 1 7
Output
15
1
1 
Input
2 20
9 8 12 6
15 5 1 1
Output
16
1
2 
----------------------------------------------------------------------------------------------------
E. Clearing Up
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 2
1 1 S
1 1 M
Output
0
Input
3 3
1 2 S
1 3 M
2 3 S
Output
2
2 1 
Input
5 6
1 1 S
1 2 M
1 3 S
1 4 M
1 5 M
2 2 S
Output
-1
----------------------------------------------------------------------------------------------------
