Hello 2020


A. New Year and Naming
time limit per test: 1 second
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
10 12
sin im gye gap eul byeong jeong mu gi gyeong
yu sul hae ja chuk in myo jin sa o mi sin
14
1
2
3
4
10
11
12
13
73
2016
2017
2018
2019
2020
Output
sinyu
imsul
gyehae
gapja
gyeongo
sinmi
imsin
gyeyu
gyeyu
byeongsin
jeongyu
musul
gihae
gyeongja
----------------------------------------------------------------------------------------------------
B. New Year and Ascent Sequence
time limit per test: 2 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
5
1 1
1 1
1 2
1 4
1 3
Output
9
Input
3
4 2 0 2 0
6 9 9 8 8 7 7
1 6
Output
7
Input
10
3 62 24 39
1 17
1 99
1 60
1 64
1 30
2 79 29
2 20 73
2 85 37
1 100
Output
72
----------------------------------------------------------------------------------------------------
C. New Year and Permutation
time limit per test: 1 second
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
1 993244853
Output
1
Input
2 993244853
Output
6
Input
3 993244853
Output
32
Input
2019 993244853
Output
923958830
Input
2020 437122297
Output
265955509
----------------------------------------------------------------------------------------------------
D. New Year and Conference
time limit per test: 2 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
2
1 2 3 6
3 4 7 8
Output
YES
Input
3
1 3 2 4
4 5 6 7
3 4 5 5
Output
NO
Input
6
1 5 2 9
2 4 5 8
3 6 7 11
7 10 12 16
8 11 13 17
9 12 14 18
Output
YES
----------------------------------------------------------------------------------------------------
E. New Year and Castle Construction
time limit per test: 3 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
5
-1 0
1 0
-10 -1
10 -1
0 3
Output
2
Input
8
0 1
1 2
2 2
1 3
0 -1
-1 -2
-2 -2
-1 -3
Output
40
Input
10
588634631 265299215
-257682751 342279997
527377039 82412729
145077145 702473706
276067232 912883502
822614418 -514698233
280281434 -41461635
65985059 -827653144
188538640 592896147
-857422304 -529223472
Output
213
----------------------------------------------------------------------------------------------------
F. New Year and Social Network
time limit per test: 4 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2
2 3
4 3
1 3
2 4
1 4
Output
3
3 2 4 2
2 1 1 3
4 3 1 4
Input
5
1 2
2 4
3 4
4 5
1 2
1 3
1 4
1 5
Output
4
2 1 1 2
3 4 1 3
4 2 1 4
5 4 1 5
Input
9
7 9
2 8
2 1
7 5
4 7
2 4
9 6
3 9
1 8
4 8
2 9
9 5
7 6
1 3
4 6
5 3
Output
8
4 2 9 2
9 7 6 7
5 7 5 9
6 9 4 6
8 2 8 4
3 9 3 5
2 1 1 8
7 4 1 3
----------------------------------------------------------------------------------------------------
G. Seollal
time limit per test: 3 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
4
2 2
OO
OO
3 3
OOO
XOO
OOO
4 4
OOOX
XOOX
OOXO
OOOO
5 6
OOOOOO
OOOOOO
OOOOOO
OOOOOO
OOOOOO
Output
YES
OOO
  O
OOO
NO
YES
OOOOO X
  O O  
X O O X
  O    
OOO X O
O O   O
O OOOOO
YES
OOOOOOOOOOO
  O   O   O
OOO OOO OOO
O   O   O  
OOO OOO OOO
  O   O   O
OOO OOO OOO
O   O   O  
OOO OOO OOO
----------------------------------------------------------------------------------------------------
