Codeforces Round 402 (Div. 1)


A. String Game
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
ababcba
abb
5 3 4 1 7 6 2
Output
3
Input
bbbabb
bb
1 6 3 4 2 5
Output
4
----------------------------------------------------------------------------------------------------
B. Bitwise Formula
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3 3
a := 101
b := 011
c := ? XOR b
Output
011
100
Input
5 1
a := 1
bb := 0
cx := ? OR a
d := ? XOR ?
e := d AND bb
Output
0
0
----------------------------------------------------------------------------------------------------
C. Peterson Polyglot
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
1 2 c
2 3 a
3 4 t
2 5 t
Output
3
2
Input
16
1 2 o
2 3 f
1 4 p
4 5 i
5 6 e
6 7 c
7 8 e
4 9 r
9 10 e
10 11 t
11 12 t
12 13 y
10 14 f
14 15 i
15 16 x
Output
12
2
----------------------------------------------------------------------------------------------------
D. Parquet Re-laying
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
2 3
ULR
DLR
LRU
LRD
Output
2
1 2
1 1
Input
4 3
ULR
DLR
LRU
LRD
ULR
DUU
UDD
DLR
Output
3
3 1
3 2
2 2
----------------------------------------------------------------------------------------------------
E. Selling Numbers
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
42
3
89
1
958
0 0 1 1 2 2 3 3 4 4
Output
4
Input
?5?
4
2203
5229
276
6243
2 1 6 1 1 2 5 2 2 3
Output
62
----------------------------------------------------------------------------------------------------
