Технокубок 2018 - Отборочный Раунд 4


A. Masha and Bears
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
50 30 10 10
Output
50
30
10
Input
100 50 10 21
Output
-1
----------------------------------------------------------------------------------------------------
B. Tic-Tac-Toe
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... x.. ...
... ... ...
... ... ...
... ... ...
6 4
Output
... ... ... 
... ... ... 
... ... ... 
... ... ... 
... ... ... 
... x.. ... 
!!! ... ... 
!!! ... ... 
!!! ... ... 
Input
xoo x.. x..
ooo ... ...
ooo ... ...
x.. x.. x..
... ... ...
... ... ...
x.. x.. x..
... ... ...
... ... ...
7 4
Output
xoo x!! x!! 
ooo !!! !!! 
ooo !!! !!! 
x!! x!! x!! 
!!! !!! !!! 
!!! !!! !!! 
x!! x!! x!! 
!!! !!! !!! 
!!! !!! !!! 
Input
o.. ... ...
... ... ...
... ... ...
... xxx ...
... xox ...
... ooo ...
... ... ...
... ... ...
... ... ...
5 5
Output
o!! !!! !!! 
!!! !!! !!! 
!!! !!! !!! 
!!! xxx !!! 
!!! xox !!! 
!!! ooo !!! 
!!! !!! !!! 
!!! !!! !!! 
!!! !!! !!! 
----------------------------------------------------------------------------------------------------
C. Shockers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
! abc
. ad
. b
! cd
? c
Output
1
Input
8
! hello
! codeforces
? c
. o
? d
? h
. l
? e
Output
2
Input
7
! ababahalamaha
? a
? b
? a
? b
? a
? h
Output
0
----------------------------------------------------------------------------------------------------
D. Seating of Students
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2 4
Output
YES
5 4 7 2 
3 6 1 8 
Input
2 1
Output
NO
----------------------------------------------------------------------------------------------------
E. Party
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 6
1 2
1 3
2 3
2 5
3 4
4 5
Output
2
2 3 
Input
4 4
1 2
1 3
1 4
3 4
Output
1
1 
----------------------------------------------------------------------------------------------------
F. Power Tower
time limit per test: 4.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6 1000000000
1 2 2 3 3 3
8
1 1
1 6
2 2
2 3
2 4
4 4
4 5
4 6
Output
1
1
2
4
256
3
27
597484987
----------------------------------------------------------------------------------------------------
