Codeforces Round 940 (Div. 2) and CodeCraft-23


A. Stickogon
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
1
2
1 1
6
2 2 3 3 3 3
9
4 2 2 2 2 4 2 4 4
Output
0
0
1
2
----------------------------------------------------------------------------------------------------
B. A BIT of a Construction
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 5
2 3
2 5
6 51
Output
5
1 2
5 0
3 1 1 32 2 12
----------------------------------------------------------------------------------------------------
C. How Does the Rook Move?
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
4 1
1 2
8 1
7 6
1000 4
4 4
952 343
222 333
90 91
Output
3
331
671968183
----------------------------------------------------------------------------------------------------
D. A BIT of an Inequality
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3
6 2 4
1
3
5
7 3 7 2 1
Output
4
0
16
----------------------------------------------------------------------------------------------------
E. Carousel of Combinations
time limit per test: 2.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
3
6
314159
Output
0
4
24
78926217
----------------------------------------------------------------------------------------------------
F1. Frequency Mismatch (Easy Version)
time limit per test: 4 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
5 2 3 4 3
1 2
1 3
2 4
2 5
3
1 4 4 5 1
2 3 2 3 1
5 5 4 3 1
Output
1 5
0
1 2
----------------------------------------------------------------------------------------------------
F2. Frequency Mismatch (Hard Version)
time limit per test: 4.5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
5
5 2 3 4 3
1 2
1 3
2 4
2 5
4
1 4 4 5 3
2 3 2 3 1
1 4 4 5 1
5 5 4 3 10
Output
2 3 5
0
1 5
3 5 2 4
----------------------------------------------------------------------------------------------------
