Codeforces Round 861 (Div. 2)


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

Examples
Input
5
59 63
42 49
15 15
53 57
1 100
Output
60
49
15
57
90
----------------------------------------------------------------------------------------------------
B. Playing in a Casino
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3
3 5
1 4 2 8 5
7 9 2 1 4
3 8 5 3 1
1 4
4 15 1 10
4 3
1 2 3
3 2 1
1 2 1
4 2 7
Output
50
0
31
----------------------------------------------------------------------------------------------------
C. Unlucky Numbers
time limit per test: 2 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
5
59 63
42 49
48 53
90 90
1 100
Output
63
44
53
90
1
----------------------------------------------------------------------------------------------------
D. Petya, Petya, Petr, and Palindromes
time limit per test: 1.5 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
8 5
1 2 8 2 5 2 8 6
Output
4
Input
9 9
1 2 3 4 5 4 3 2 1
Output
0
----------------------------------------------------------------------------------------------------
E1. Minibuses on Venus (easy version)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2 1000000007
Output
4
Input
3 4 1000000007
Output
28
----------------------------------------------------------------------------------------------------
E2. Minibuses on Venus (medium version)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2 1000000007
Output
4
Input
3 4 1000000007
Output
28
----------------------------------------------------------------------------------------------------
E3. Minibuses on Venus (hard version)
time limit per test: 3 seconds
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
3 2 1000000007
Output
4
Input
3 4 1000000007
Output
28
----------------------------------------------------------------------------------------------------
