Codeforces Round 947 (Div. 1 + Div. 2)


A. Bazoka and Mocha's Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
6
1 1 4 5 1 4
5
7 9 2 2 3
3
1 2 3
Output
No
Yes
Yes
----------------------------------------------------------------------------------------------------
B. 378QAQ and Mocha's Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
7 3 8
5
7 1 9 3 5
5
4 12 2 6 3
5
7 49 9 3 1000000000
Output
No
Yes
Yes
No
----------------------------------------------------------------------------------------------------
C. Chamo and Mocha's Array
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2
1 2
5
1 2 3 4 5
Output
1
4
----------------------------------------------------------------------------------------------------
D. Paint the Tree
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
1 2
1 2
5
1 2
1 2
1 3
1 4
1 5
8
5 4
7 1
1 5
1 8
8 3
7 2
8 6
3 4
Output
2
8
13
----------------------------------------------------------------------------------------------------
E. Chain Queries
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
2 1
1 0
1 2
1
5 4
1 0 0 0 0
1 2
1 3
1 5
3 4
4
3
2
5
Output
No
No
Yes
Yes
No
Input
4
5 3
1 1 1 1 1
3 5
2 5
3 4
1 5
1
1
1
4 4
0 0 0 0
1 2
2 3
1 4
1
2
3
2
1 1
1
1
1 1
0
1
Output
Yes
No
Yes
Yes
Yes
Yes
No
No
Yes
----------------------------------------------------------------------------------------------------
F. Set
time limit per test: 2 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
15 15 15 15 15 15 12
Output
4
3
5
6
7
Input
5
63 63 63 63 6 63 63 63 63 63 63 5 63 63 63 63 63 63 8 63 63 63 63 2 63 63 63 63 63 63 63
Output
1
19
----------------------------------------------------------------------------------------------------
G. Zimpha Fan Club
time limit per test: 12 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
10 10
justmonika
j-stsayori
Output
No
Input
7 8
ttk-wxx
*tt-l-xx
Output
Yes
Input
13 11
asoulwangziji
-soulg*z-y-
Output
No
Input
7 3
abc*cba
a*c
Output
No
Input
20 18
bulijiojio-dibuliduo
*li*ji-*ox*i*-du*-
Output
Yes
----------------------------------------------------------------------------------------------------
H. 378QAQ and Core
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
3
qaq
4
cccc
6
bazoka
6
zazzzz
7
ababbbb
7
ccbabcc
Output
qaq
cccc
z
zzz
bbababb
cbcacbc
----------------------------------------------------------------------------------------------------
I. Mind Bloom
time limit per test: 5 seconds
memory limit per test: 1024 megabytes
input: standard input
output: standard output

Examples
Input
4
5
0 1 1 1 2
00100
3
2 3 3
000
10
0 0 0 0 0 0 0 1 1 1
1111011111
20
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 2 3 3 4
00000000001000101010
Output
500000004
0
0
675898154
----------------------------------------------------------------------------------------------------
