Codeforces Round 739 (Div. 3)


A. Dislike of Threes
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
10
1
2
3
4
5
6
7
8
9
1000
Output
1
2
4
5
7
8
10
11
14
1666
----------------------------------------------------------------------------------------------------
B. Who's Opposite?
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
6 2 4
2 3 1
2 4 10
5 3 4
1 3 2
2 5 4
4 3 2
Output
8
-1
-1
-1
4
1
-1
----------------------------------------------------------------------------------------------------
C. Infinity Table
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
11
14
5
4
1
2
1000000000
Output
2 4
4 3
1 3
2 1
1 1
1 2
31623 14130
----------------------------------------------------------------------------------------------------
D. Make a Power of Two
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
12
1052
8888
6
75
128
1
301
12048
1504
6656
1000000000
687194767
Output
2
3
1
3
0
0
2
1
3
4
9
2
----------------------------------------------------------------------------------------------------
E. Polycarp and String Transformation
time limit per test: 3.0 s
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
7
abacabaaacaac
nowyouknowthat
polycarppoycarppoyarppyarppyrpprppp
isi
everywherevrywhrvryhrvrhrvhv
haaha
qweqeewew
Output
abacaba bac
-1
polycarp lcoayrp
is si
everywhere ewyrhv
-1
-1
----------------------------------------------------------------------------------------------------
F1. Nearest Beautiful Number (easy version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
4
1 1
221 2
177890 2
998244353 1
Output
1
221
181111
999999999
----------------------------------------------------------------------------------------------------
F2. Nearest Beautiful Number (hard version)
time limit per test: 1 second
memory limit per test: 256 megabytes
input: standard input
output: standard output

Examples
Input
6
2021 3
177890 2
34512 3
724533 4
998244353 1
12345678 10
Output
2021
181111
34533
724542
999999999
12345678
----------------------------------------------------------------------------------------------------
