Codeforces Round 606 (Div. 1, based on Technocup 2020 Elimination Round 4)


A. As Simple as One and Two
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
onetwone
testme
oneoneone
twotwo
Output
2
6 3
0
3
4 1 7 
2
1 4
Input
10
onetwonetwooneooonetwooo
two
one
twooooo
ttttwo
ttwwoo
ooone
onnne
oneeeee
oneeeeeeetwooooo
Output
6
18 11 12 1 6 21 
1
1 
1
3 
1
2 
1
6 
0
1
4 
0
1
1 
2
1 11 
----------------------------------------------------------------------------------------------------
B. Two Fairs
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
7 7 3 5
1 2
2 3
3 4
4 5
5 6
6 7
7 5
4 5 2 3
1 2
2 3
3 4
4 1
4 2
4 3 2 1
1 2
2 3
4 1
Output
4
0
1
----------------------------------------------------------------------------------------------------
C. Beautiful Rectangle
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

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

Examples
Input
5
1 2
1 3
1 4
1 5
Output
5
Input
7
7 2
7 6
1 2
7 5
4 7
3 5
Output
10
----------------------------------------------------------------------------------------------------
E. Four Stones
time limit per test: 1 second
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
0 1 2 3
3 5 6 8
Output
3
1 3
2 5
0 3
Input
0 0 0 0
1 1 1 1
Output
-1
Input
0 0 0 1
0 1 0 1
Output
-1
----------------------------------------------------------------------------------------------------
F. Asterisk Substrings
time limit per test: 5 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
abc
Output
15
----------------------------------------------------------------------------------------------------
