Codeforces Round 819 (Div. 1 + Div. 2) and Grimoire of Code Annual Contest 2022


A. Mainak and Array
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
6
1 3 9 11 5 7
1
20
3
9 99 999
4
2 1 8 1
3
2 1 5
Output
10
0
990
7
4
----------------------------------------------------------------------------------------------------
B. Mainak and Interesting Sequence
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 3
6 12
2 1
3 6
Output
Yes
3
Yes
1 3 2 2 3 1
No
Yes
2 2 2
----------------------------------------------------------------------------------------------------
C. Jatayu's Balanced Bracket Sequence
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
()
3
()(())
3
((()))
4
(())(())
Output
1
2
3
3
----------------------------------------------------------------------------------------------------
D. Edge Split
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
5 7
1 2
2 3
3 4
4 5
5 1
1 3
3 5
4 4
1 2
2 3
1 4
3 4
6 7
1 2
1 3
3 4
4 5
1 4
5 6
6 2
2 1
1 2
Output
0111010
1001
0001111
0
----------------------------------------------------------------------------------------------------
E. Almost Perfect
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
3
50
Output
2
4
830690567
----------------------------------------------------------------------------------------------------
F. Late For Work (submissions are not allowed)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 10
4 2
7 3
3 6
5 2
8 0
1 2 3 4
Output
11
Input
6 9
5 3
5 5
7 0
5 8
7 7
6 6
0 0 0 0 0
Output
3
----------------------------------------------------------------------------------------------------
G. A Certain Magical Party
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 2 4 4
1 1 0 0
Output
2
Input
4
3 4 3 1
0 1 0 0
Output
0
Input
21
1 2 19 19 19 19 19 19 19 19 19 21 21 21 21 21 21 21 21 21 21
1 1 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 1 1
Output
49439766
----------------------------------------------------------------------------------------------------
H. Mainak and the Bleeding Polygon
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
4 5
4 1
7 1
7 5
Output
1.17809724510
Input
5
-3 3
3 1
4 2
-1 9
-2 9
Output
1.07823651333
----------------------------------------------------------------------------------------------------
