Codeforces Round 675 (Div. 2)


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

Examples
Input
2
1 2 3
12 34 56
Output
4
42
----------------------------------------------------------------------------------------------------
B. Nice Matrix
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
2
4 2
4 2
2 4
4 2
2 4
3 4
1 2 3 4
5 6 7 8
9 10 11 18
Output
8
42
----------------------------------------------------------------------------------------------------
C. Bargain
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
107
Output
42
Input
100500100500
Output
428101984
----------------------------------------------------------------------------------------------------
D. Returning Home
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5 3
1 1 5 5
1 2
4 1
3 3
Output
5
Input
84 5
67 59 41 2
39 56
7 2
15 3
74 18
22 7
Output
42
----------------------------------------------------------------------------------------------------
E. Minlexes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
abcdd
Output
3 abc
2 bc
1 c
0 
1 d
Input
abbcdddeaaffdfouurtytwoo
Output
18 abbcd...tw
17 bbcdd...tw
16 bcddd...tw
15 cddde...tw
14 dddea...tw
13 ddeaa...tw
12 deaad...tw
11 eaadf...tw
10 aadfortytw
9 adfortytw
8 dfortytw
9 fdfortytw
8 dfortytw
7 fortytw
6 ortytw
5 rtytw
6 urtytw
5 rtytw
4 tytw
3 ytw
2 tw
1 w
0 
1 o
----------------------------------------------------------------------------------------------------
F. Boring Queries
time limit per test: 3 seconds
memory limit per test: 512 megabytes
input: standard input
output: standard output

Examples
Input
3
2 3 5
4
1 3
3 3
2 3
2 3
Output
6
2
15
30
----------------------------------------------------------------------------------------------------
