think-cell Round 1


A. Maximise The Score
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
1
2 3
2
1 1 2 1
3
1 1 1 1 1 1
Output
2
2
3
----------------------------------------------------------------------------------------------------
B. Permutation Printing
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
4
3
Output
4 1 2 3
1 2 3
----------------------------------------------------------------------------------------------------
C. Lexicographically Largest
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2
2 1
5
1 100 1000 1000000 1000000000
3
6 4 8
Output
3 2 
1000000005 1000004 1003 102 2 
11 7 6 
----------------------------------------------------------------------------------------------------
D1. Sum over all Substrings (Easy Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
1
2
10
5
00000
20
11110110000000111111
Output
1
2
0
346
----------------------------------------------------------------------------------------------------
D2. Sum over all Substrings (Hard Version)
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1
1
2
10
5
00000
20
11110110000000111111
Output
1
2
0
346
----------------------------------------------------------------------------------------------------
E. 2..3...4.... Wonderful! Wonderful!
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
3
4
5
10
Output
2 
4 
10 2 
487 162 85 10 
----------------------------------------------------------------------------------------------------
F. Maximize the Difference
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
5 2
1 2
7 4
3 1 5 2
Output
0 2
0 2 3 5
----------------------------------------------------------------------------------------------------
G. Prefix Max Set Counting
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
6
1
2
1 2
3
1 2
1 3
3
1 2
2 3
5
1 2
1 3
1 4
1 5
10
1 2
2 3
1 4
2 5
2 6
4 7
5 8
4 9
9 10
Output
1
1
2
1
8
6
----------------------------------------------------------------------------------------------------
H. Interactive Mex Tree
time limit per test: 5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
3 1
1 2
2 3
2 3
1
0
1
Output
1 2 3
2 1 3
? 1 2 3
? 2 1 3
! 0
----------------------------------------------------------------------------------------------------
I. Counting Is Fun
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1
0
Output
1
Input
3
111
Output
5
Input
4
1011
Output
9
Input
6
110001
Output
36
Input
12
111010001111
Output
2441
----------------------------------------------------------------------------------------------------
