ICM Technex 2018 and Codeforces Round 463 (Div. 1 + Div. 2, combined)


A. Palindromic Supersequence
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
aba
Output
aba
Input
ab
Output
aabaa
----------------------------------------------------------------------------------------------------
B. Recursive Queries
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
22 73 9
45 64 6
47 55 7
2 62 4
Output
1
4
0
8
Input
4
82 94 6
56 67 4
28 59 9
39 74 4
Output
3
1
1
5
----------------------------------------------------------------------------------------------------
C. Permutation Cycle
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
6
1 1 1
2 2 0
2 2 1
1 3 0
2 2 0
2 2 2
Output
0
1
1
2
Input
6
1 1 0
2 2 0
2 0 3
1 0 2
2 1 3
2 1 6
Output
2
2
3
2
Input
7
1 1 2
1 2 3
2 3 3
1 0 0
1 5 1
2 5 0
2 4 0
Output
1
1
2
Input
7
1 1 3
1 2 3
2 3 4
1 2 0
1 5 3
2 5 5
2 7 22
Output
1
2
3
----------------------------------------------------------------------------------------------------
E. Team Work
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
1 1
Output
1
Input
3 2
Output
24
----------------------------------------------------------------------------------------------------
F. Escape Through Leaf
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
2 10 -1
7 -7 5
2 3
2 1
Output
10 50 0 
Input
4
5 -10 5 7
-8 -80 -3 -10
2 1
2 4
1 3
Output
-300 100 0 0 
----------------------------------------------------------------------------------------------------
G. Palindrome Partition
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
abcdcdab
Output
1
Input
abbababababbab
Output
3
----------------------------------------------------------------------------------------------------
