source
stringclasses 1
value | task_type
stringclasses 1
value | in_source_id
stringlengths 1
4
| problem
stringlengths 488
6.07k
| gold_standard_solution
stringlengths 19
30.1k
| verification_info
dict | metadata
dict | problem_id
stringlengths 5
9
|
---|---|---|---|---|---|---|---|
apps | verifiable_code | 2366 | Solve the following coding problem using the programming language python:
Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for $n$ last days: $a_1, a_2, \dots, a_n$, where $a_i$ is the price of berPhone on the day $i$.
Polycarp considers the price on the day $i$ to be bad if later (that is, a day with a greater number) berPhone was sold at a lower price. For example, if $n=6$ and $a=[3, 9, 4, 6, 7, 5]$, then the number of days with a bad price is $3$ — these are days $2$ ($a_2=9$), $4$ ($a_4=6$) and $5$ ($a_5=7$).
Print the number of days with a bad price.
You have to answer $t$ independent data sets.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of sets of input data in the test. Input data sets must be processed independently, one after another.
Each input data set consists of two lines. The first line contains an integer $n$ ($1 \le n \le 150000$) — the number of days. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$), where $a_i$ is the price on the $i$-th day.
It is guaranteed that the sum of $n$ over all data sets in the test does not exceed $150000$.
-----Output-----
Print $t$ integers, the $j$-th of which should be equal to the number of days with a bad price in the $j$-th input data set.
-----Example-----
Input
5
6
3 9 4 6 7 5
1
1000000
2
2 1
10
31 41 59 26 53 58 97 93 23 84
7
3 2 1 2 3 4 5
Output
3
0
1
8
2
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for _ in range(int(input())):
n = int(input())
A = list(map(int, input().split()))
m = 10 ** 9
c = 0
for i in range(n - 1, -1, -1):
if A[i] <= m:
m = A[i]
else:
c += 1
print(c)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n6\n3 9 4 6 7 5\n1\n1000000\n2\n2 1\n10\n31 41 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n",
"output": "3\n0\n1\n8\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1213/B"
} | vfc_7010 |
apps | verifiable_code | 2367 | Solve the following coding problem using the programming language python:
You are given two strings $s$ and $t$ both of length $n$ and both consisting of lowercase Latin letters.
In one move, you can choose any length $len$ from $1$ to $n$ and perform the following operation: Choose any contiguous substring of the string $s$ of length $len$ and reverse it; at the same time choose any contiguous substring of the string $t$ of length $len$ and reverse it as well.
Note that during one move you reverse exactly one substring of the string $s$ and exactly one substring of the string $t$.
Also note that borders of substrings you reverse in $s$ and in $t$ can be different, the only restriction is that you reverse the substrings of equal length. For example, if $len=3$ and $n=5$, you can reverse $s[1 \dots 3]$ and $t[3 \dots 5]$, $s[2 \dots 4]$ and $t[2 \dots 4]$, but not $s[1 \dots 3]$ and $t[1 \dots 2]$.
Your task is to say if it is possible to make strings $s$ and $t$ equal after some (possibly, empty) sequence of moves.
You have to answer $q$ independent test cases.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 10^4$) — the number of test cases. Then $q$ test cases follow.
The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of $s$ and $t$.
The second line of the test case contains one string $s$ consisting of $n$ lowercase Latin letters.
The third line of the test case contains one string $t$ consisting of $n$ lowercase Latin letters.
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer on it — "YES" (without quotes) if it is possible to make strings $s$ and $t$ equal after some (possibly, empty) sequence of moves and "NO" otherwise.
-----Example-----
Input
4
4
abcd
abdc
5
ababa
baaba
4
asdf
asdg
4
abcd
badc
Output
NO
YES
NO
YES
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
q = int(input())
for _ in range(q) :
n = int(input())
s = input()
t = input()
x = set(s)
y = set(t)
if x != y :
print("NO")
continue
if len(x) == n :
a = [0] * n
for i, c in enumerate(t) :
a[i] = s.find(c)
yeet = 0
vis = [False] * n
for i in range(n) :
if vis[i] :
continue
j = i
cyc = 0
while not vis[j] :
cyc += 1
vis[j] = True
j = a[j]
# print('>> ', i, cyc)
yeet += (cyc - 1) % 2
yeet %= 2
if yeet == 0 :
print("YES")
else :
print("NO")
continue
print("YES")
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n4\nabcd\nabdc\n5\nababa\nbaaba\n4\nasdf\nasdg\n4\nabcd\nbadc\n",
"output": "NO\nYES\nNO\nYES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1256/F"
} | vfc_7014 |
apps | verifiable_code | 2369 | Solve the following coding problem using the programming language python:
This problem is a version of problem D from the same contest with some additional constraints and tasks.
There are $n$ candies in a candy box. The type of the $i$-th candy is $a_i$ ($1 \le a_i \le n$).
You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type $1$ and two candies of type $2$ is bad).
It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift.
You really like some of the candies and don't want to include them into the gift, but you want to eat them yourself instead. For each candy, a number $f_i$ is given, which is equal to $0$ if you really want to keep $i$-th candy for yourself, or $1$ if you don't mind including it into your gift. It is possible that two candies of the same type have different values of $f_i$.
You want your gift to be as large as possible, but you don't want to include too many of the candies you want to eat into the gift. So, you want to calculate the maximum possible number of candies that can be included into a gift, and among all ways to choose maximum number of candies, you want to maximize the number of candies having $f_i = 1$ in your gift.
You have to answer $q$ independent queries.
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries.
The first line of each query contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of candies.
Then $n$ lines follow, each containing two integers $a_i$ and $f_i$ ($1 \le a_i \le n$, $0 \le f_i \le 1$), where $a_i$ is the type of the $i$-th candy, and $f_i$ denotes whether you want to keep the $i$-th candy for yourself ($0$ if you want to keep it, $1$ if you don't mind giving it away).
It is guaranteed that the sum of $n$ over all queries does not exceed $2 \cdot 10^5$.
-----Output-----
For each query print two integers:
the maximum number of candies in a gift you can compose, according to the constraints in the statement; the maximum number of candies having $f_i = 1$ in a gift you can compose that contains the maximum possible number of candies.
-----Example-----
Input
3
8
1 0
4 1
2 0
4 1
5 1
6 1
3 0
2 0
4
1 1
1 1
2 1
2 1
9
2 0
2 0
4 1
4 1
4 1
7 0
7 1
7 0
7 1
Output
3 3
3 3
9 5
-----Note-----
In the first query, you can include two candies of type $4$ and one candy of type $5$. All of them have $f_i = 1$ and you don't mind giving them away as part of the gift.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# @author
import sys
class GCandyBoxHardVersion:
def solve(self):
q = int(input())
for _ in range(q):
n = int(input())
a = [0] * n
f = [0] * n
for i in range(n):
a[i], f[i] = [int(_) for _ in input().split()]
d = {key: [0, 0] for key in a}
for i in range(n):
d[a[i]][f[i]] += 1
rev_d = {sum(key): [] for key in list(d.values())}
for x in d:
rev_d[d[x][0] + d[x][1]] += [d[x]]
for x in rev_d:
rev_d[x].sort(key=lambda item:item[1])
# print(rev_d)
cur = max(rev_d)
cnt = max(rev_d)
nb_candies = 0
given_away = 0
while 1:
if cnt == 0 or cur == 0:
break
if cur > cnt:
cur -= 1
continue
if cnt not in rev_d or not rev_d[cnt]:
cnt -= 1
continue
mx_f = -1
v = -1
for max_cnt in range(cur, cnt + 1):
if max_cnt in rev_d and rev_d[max_cnt] and rev_d[max_cnt][-1][1] > mx_f:
v = max_cnt
mx_f = rev_d[max_cnt][-1][1]
to_take = rev_d[v].pop()
# rev_d[cnt] -= 1
nb_candies += cur
given_away += min(to_take[1], cur)
cur -= 1
# rev_d[cnt - cur] += 1
print(nb_candies, given_away)
solver = GCandyBoxHardVersion()
input = sys.stdin.readline
solver.solve()
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n8\n1 0\n4 1\n2 0\n4 1\n5 1\n6 1\n3 0\n2 0\n4\n1 1\n1 1\n2 1\n2 1\n9\n2 0\n2 0\n4 1\n4 1\n4 1\n7 0\n7 1\n7 0\n7 1\n",
"output": "3 3\n3 3\n9 5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1183/G"
} | vfc_7022 |
apps | verifiable_code | 2371 | Solve the following coding problem using the programming language python:
You are given an array $a$ consisting of $n$ integers. You have to find the length of the smallest (shortest) prefix of elements you need to erase from $a$ to make it a good array. Recall that the prefix of the array $a=[a_1, a_2, \dots, a_n]$ is a subarray consisting several first elements: the prefix of the array $a$ of length $k$ is the array $[a_1, a_2, \dots, a_k]$ ($0 \le k \le n$).
The array $b$ of length $m$ is called good, if you can obtain a non-decreasing array $c$ ($c_1 \le c_2 \le \dots \le c_{m}$) from it, repeating the following operation $m$ times (initially, $c$ is empty): select either the first or the last element of $b$, remove it from $b$, and append it to the end of the array $c$.
For example, if we do $4$ operations: take $b_1$, then $b_{m}$, then $b_{m-1}$ and at last $b_2$, then $b$ becomes $[b_3, b_4, \dots, b_{m-3}]$ and $c =[b_1, b_{m}, b_{m-1}, b_2]$.
Consider the following example: $b = [1, 2, 3, 4, 4, 2, 1]$. This array is good because we can obtain non-decreasing array $c$ from it by the following sequence of operations: take the first element of $b$, so $b = [2, 3, 4, 4, 2, 1]$, $c = [1]$; take the last element of $b$, so $b = [2, 3, 4, 4, 2]$, $c = [1, 1]$; take the last element of $b$, so $b = [2, 3, 4, 4]$, $c = [1, 1, 2]$; take the first element of $b$, so $b = [3, 4, 4]$, $c = [1, 1, 2, 2]$; take the first element of $b$, so $b = [4, 4]$, $c = [1, 1, 2, 2, 3]$; take the last element of $b$, so $b = [4]$, $c = [1, 1, 2, 2, 3, 4]$; take the only element of $b$, so $b = []$, $c = [1, 1, 2, 2, 3, 4, 4]$ — $c$ is non-decreasing.
Note that the array consisting of one element is good.
Print the length of the shortest prefix of $a$ to delete (erase), to make $a$ to be a good array. Note that the required length can be $0$.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of $a$. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer: the length of the shortest prefix of elements you need to erase from $a$ to make it a good array.
-----Example-----
Input
5
4
1 2 3 4
7
4 3 3 8 4 5 2
3
1 1 1
7
1 3 1 4 5 3 2
5
5 4 3 2 3
Output
0
4
0
2
3
-----Note-----
In the first test case of the example, the array $a$ is already good, so we don't need to erase any prefix.
In the second test case of the example, the initial array $a$ is not good. Let's erase first $4$ elements of $a$, the result is $[4, 5, 2]$. The resulting array is good. You can prove that if you erase fewer number of first elements, the result will not be good.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for __ in range(int(input())):
n = int(input())
ar = list(map(int, input().split()))
ar.reverse()
ans = n - 1
flag = False
for i in range(1, n):
if ar[i] < ar[i - 1]:
flag = True
if flag:
if ar[i] > ar[i - 1]:
break
ans -= 1
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n4\n1 2 3 4\n7\n4 3 3 8 4 5 2\n3\n1 1 1\n7\n1 3 1 4 5 3 2\n5\n5 4 3 2 3\n",
"output": "0\n4\n0\n2\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1385/C"
} | vfc_7030 |
apps | verifiable_code | 2372 | Solve the following coding problem using the programming language python:
Initially, you have the array $a$ consisting of one element $1$ ($a = [1]$).
In one move, you can do one of the following things:
Increase some (single) element of $a$ by $1$ (choose some $i$ from $1$ to the current length of $a$ and increase $a_i$ by one); Append the copy of some (single) element of $a$ to the end of the array (choose some $i$ from $1$ to the current length of $a$ and append $a_i$ to the end of the array).
For example, consider the sequence of five moves:
You take the first element $a_1$, append its copy to the end of the array and get $a = [1, 1]$. You take the first element $a_1$, increase it by $1$ and get $a = [2, 1]$. You take the second element $a_2$, append its copy to the end of the array and get $a = [2, 1, 1]$. You take the first element $a_1$, append its copy to the end of the array and get $a = [2, 1, 1, 2]$. You take the fourth element $a_4$, increase it by $1$ and get $a = [2, 1, 1, 3]$.
Your task is to find the minimum number of moves required to obtain the array with the sum at least $n$.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow.
The only line of the test case contains one integer $n$ ($1 \le n \le 10^9$) — the lower bound on the sum of the array.
-----Output-----
For each test case, print the answer: the minimum number of moves required to obtain the array with the sum at least $n$.
-----Example-----
Input
5
1
5
42
1337
1000000000
Output
0
3
11
72
63244
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
for _ in range(int(input())):
n=int(input())
if n==1:
print(0)
else:
k=int(n**(0.5))
if k*k<n:
k+=1
# print(n,k)
ans=k-1
if k*(k-1)>=n:
ans+=(k-2)
else:
ans+=(k-1)
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n1\n5\n42\n1337\n1000000000\n",
"output": "0\n3\n11\n72\n63244\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1426/C"
} | vfc_7034 |
apps | verifiable_code | 2373 | Solve the following coding problem using the programming language python:
You are given an array $a$ consisting of $n$ integers (it is guaranteed that $n$ is even, i.e. divisible by $2$). All $a_i$ does not exceed some integer $k$.
Your task is to replace the minimum number of elements (replacement is the following operation: choose some index $i$ from $1$ to $n$ and replace $a_i$ with some integer in range $[1; k]$) to satisfy the following conditions: after all replacements, all $a_i$ are positive integers not greater than $k$; for all $i$ from $1$ to $\frac{n}{2}$ the following equation is true: $a_i + a_{n - i + 1} = x$, where $x$ should be the same for all $\frac{n}{2}$ pairs of elements.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($2 \le n \le 2 \cdot 10^5, 1 \le k \le 2 \cdot 10^5$) — the length of $a$ and the maximum possible value of some $a_i$ correspondingly. It is guratanteed that $n$ is even (i.e. divisible by $2$). The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le k$), where $a_i$ is the $i$-th element of $a$.
It is guaranteed that the sum of $n$ (as well as the sum of $k$) over all test cases does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$, $\sum k \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer — the minimum number of elements you have to replace in $a$ to satisfy the conditions from the problem statement.
-----Example-----
Input
4
4 2
1 2 1 2
4 3
1 2 2 1
8 7
6 1 1 7 6 3 4 6
6 6
5 2 6 1 3 4
Output
0
1
4
2
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
def input():
return sys.stdin.readline()[:-1]
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
cum = [0 for _ in range(2*k+2)]
for i in range(n//2):
x, y = a[i], a[n-i-1]
cum[2] += 2
cum[min(x, y)+1] -= 1
cum[x+y] -= 1
cum[x+y+1] += 1
cum[max(x, y)+k+1] += 1
cum[2*k+1] -= 2
ans = n
for i in range(2, 2*k+1):
cum[i] += cum[i-1]
ans = min(ans, cum[i])
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n4 2\n1 2 1 2\n4 3\n1 2 2 1\n8 7\n6 1 1 7 6 3 4 6\n6 6\n5 2 6 1 3 4\n",
"output": "0\n1\n4\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1343/D"
} | vfc_7038 |
apps | verifiable_code | 2374 | Solve the following coding problem using the programming language python:
You are given a system of pipes. It consists of two rows, each row consists of $n$ pipes. The top left pipe has the coordinates $(1, 1)$ and the bottom right — $(2, n)$.
There are six types of pipes: two types of straight pipes and four types of curved pipes. Here are the examples of all six types:
[Image] Types of pipes
You can turn each of the given pipes $90$ degrees clockwise or counterclockwise arbitrary (possibly, zero) number of times (so the types $1$ and $2$ can become each other and types $3, 4, 5, 6$ can become each other).
You want to turn some pipes in a way that the water flow can start at $(1, 0)$ (to the left of the top left pipe), move to the pipe at $(1, 1)$, flow somehow by connected pipes to the pipe at $(2, n)$ and flow right to $(2, n + 1)$.
Pipes are connected if they are adjacent in the system and their ends are connected. Here are examples of connected pipes:
[Image] Examples of connected pipes
Let's describe the problem using some example:
[Image] The first example input
And its solution is below: [Image] The first example answer
As you can see, the water flow is the poorly drawn blue line. To obtain the answer, we need to turn the pipe at $(1, 2)$ $90$ degrees clockwise, the pipe at $(2, 3)$ $90$ degrees, the pipe at $(1, 6)$ $90$ degrees, the pipe at $(1, 7)$ $180$ degrees and the pipe at $(2, 7)$ $180$ degrees. Then the flow of water can reach $(2, n + 1)$ from $(1, 0)$.
You have to answer $q$ independent queries.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 10^4$) — the number of queries. Then $q$ queries follow.
Each query consists of exactly three lines. The first line of the query contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of pipes in each row. The next two lines contain a description of the first and the second rows correspondingly. Each row description consists of $n$ digits from $1$ to $6$ without any whitespaces between them, each digit corresponds to the type of pipe in the corresponding cell. See the problem statement to understand which digits correspond to which types of pipes.
It is guaranteed that the sum of $n$ over all queries does not exceed $2 \cdot 10^5$.
-----Output-----
For the $i$-th query print the answer for it — "YES" (without quotes) if it is possible to turn some pipes in a way that the water flow can reach $(2, n + 1)$ from $(1, 0)$, and "NO" otherwise.
-----Example-----
Input
6
7
2323216
1615124
1
3
4
2
13
24
2
12
34
3
536
345
2
46
54
Output
YES
YES
YES
NO
YES
NO
-----Note-----
The first query from the example is described in the problem statement.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
ans = []
for _ in range(int(input())):
n = int(input())
s = list(input())
t = list(input())
lvl = 0
X = [s, t]
f = 1
for i in range(n):
if s[i] in '3456' and t[i] in '3456':
lvl = 1 - lvl
elif X[lvl][i] in '3456':
f = 0
ans.append('NO')
break
if f and lvl == 1:
ans.append('YES')
elif f:
ans.append('NO')
print('\n'.join(ans))
``` | {
"language": "python",
"test_cases": [
{
"input": "6\n7\n2323216\n1615124\n1\n3\n4\n2\n13\n24\n2\n12\n34\n3\n536\n345\n2\n46\n54\n",
"output": "YES\nYES\nYES\nNO\nYES\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1234/C"
} | vfc_7042 |
apps | verifiable_code | 2376 | Solve the following coding problem using the programming language python:
You are given a tree (connected graph without cycles) consisting of $n$ vertices. The tree is unrooted — it is just a connected undirected graph without cycles.
In one move, you can choose exactly $k$ leaves (leaf is such a vertex that is connected to only one another vertex) connected to the same vertex and remove them with edges incident to them. I.e. you choose such leaves $u_1, u_2, \dots, u_k$ that there are edges $(u_1, v)$, $(u_2, v)$, $\dots$, $(u_k, v)$ and remove these leaves and these edges.
Your task is to find the maximum number of moves you can perform if you remove leaves optimally.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($2 \le n \le 2 \cdot 10^5$; $1 \le k < n$) — the number of vertices in the tree and the number of leaves you remove in one move, respectively. The next $n-1$ lines describe edges. The $i$-th edge is represented as two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$), where $x_i$ and $y_i$ are vertices the $i$-th edge connects. It is guaranteed that the given set of edges forms a tree.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer — the maximum number of moves you can perform if you remove leaves optimally.
-----Example-----
Input
4
8 3
1 2
1 5
7 6
6 8
3 1
6 4
6 1
10 3
1 2
1 10
2 3
1 5
1 6
2 4
7 10
10 9
8 10
7 2
3 1
4 5
3 6
7 4
1 2
1 4
5 1
1 2
2 3
4 3
5 3
Output
2
3
3
4
-----Note-----
The picture corresponding to the first test case of the example:
[Image]
There you can remove vertices $2$, $5$ and $3$ during the first move and vertices $1$, $7$ and $4$ during the second move.
The picture corresponding to the second test case of the example:
[Image]
There you can remove vertices $7$, $8$ and $9$ during the first move, then vertices $5$, $6$ and $10$ during the second move and vertices $1$, $3$ and $4$ during the third move.
The picture corresponding to the third test case of the example:
$\text{of}$
There you can remove vertices $5$ and $7$ during the first move, then vertices $2$ and $4$ during the second move and vertices $1$ and $6$ during the third move.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush,heappop,heapify
import math
from collections import *
from functools import reduce,cmp_to_key
import sys
input = sys.stdin.readline
M = mod = 998244353
def factors(n):return sorted(set(reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0))))
def inv_mod(n):return pow(n, mod - 2, mod)
def li():return [int(i) for i in input().rstrip('\n').split()]
def st():return input().rstrip('\n')
def val():return int(input().rstrip('\n'))
def li2():return [i for i in input().rstrip('\n')]
def li3():return [int(i) for i in input().rstrip('\n')]
for _ in range(val()):
n, k = li()
d = defaultdict(set)
for i in range(n-1):
a, b = li()
d[a].add(b)
d[b].add(a)
thistime = 1
he = deque()
visited = {}
for i in d:
if len(d[i]) == 1:
visited[i] = 1
he.append(i)
ans = 0
counts = defaultdict(int)
# print(he)
while he:
i = he.popleft()
for j in list(d[i]):
counts[j] += 1
d[i].remove(j)
d[j].remove(i)
if counts[j] == k:
thistime = 1
ans += 1
counts[j] = 0
if len(d[j]) == 1:
if j not in visited:he.append(j)
visited[j] = 1
# print(j, he)
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n8 3\n1 2\n1 5\n7 6\n6 8\n3 1\n6 4\n6 1\n10 3\n1 2\n1 10\n2 3\n1 5\n1 6\n2 4\n7 10\n10 9\n8 10\n7 2\n3 1\n4 5\n3 6\n7 4\n1 2\n1 4\n5 1\n1 2\n2 3\n4 3\n5 3\n",
"output": "2\n3\n3\n4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1385/F"
} | vfc_7050 |
apps | verifiable_code | 2377 | Solve the following coding problem using the programming language python:
This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on $n$ are less than in the hard version of the problem.
You are given an array $a$ of $n$ integers (there are no equals elements in the array). You can perform the following operations on array elements: choose any index $i$ ($1 \le i \le n$) and move the element $a[i]$ to the begin of the array; choose any index $i$ ($1 \le i \le n$) and move the element $a[i]$ to the end of the array.
For example, if $n = 5$, $a = [4, 7, 2, 3, 9]$, then the following sequence of operations can be performed: after performing the operation of the first type to the second element, the array $a$ will become $[7, 4, 2, 3, 9]$; after performing the operation of the second type to the second element, the array $a$ will become $[7, 2, 3, 9, 4]$.
You can perform operations of any type any number of times in any order.
Find the minimum total number of operations of the first and second type that will make the $a$ array sorted in non-decreasing order. In other words, what is the minimum number of operations that must be performed so the array satisfies the inequalities $a[1] \le a[2] \le \ldots \le a[n]$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases in the test. Then $t$ test cases follow.
Each test case starts with a line containing an integer $n$ ($1 \le n \le 3000$) — length of the array $a$.
Then follow $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — an array that needs to be sorted by the given operations. All numbers in the given array are distinct.
The sum of $n$ for all test cases in one test does not exceed $3000$.
-----Output-----
For each test case output one integer — the minimum total number of operations of the first and second type, which will make the array sorted in non-decreasing order.
-----Example-----
Input
4
5
4 7 2 3 9
5
3 5 8 1 7
5
1 4 5 7 12
4
0 2 1 3
Output
2
2
0
2
-----Note-----
In the first test case, you first need to move 3, and then 2 to the beginning of the array. Therefore, the desired sequence of operations: $[4, 7, 2, 3, 9] \rightarrow [3, 4, 7, 2, 9] \rightarrow [2, 3, 4, 7, 9]$.
In the second test case, you need to move the 1 to the beginning of the array, and the 8 — to the end. Therefore, the desired sequence of operations: $[3, 5, 8, 1, 7] \rightarrow [1, 3, 5, 8, 7] \rightarrow [1, 3, 5, 7, 8]$.
In the third test case, the array is already sorted.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = sys.stdin.readline
import bisect
t=int(input())
for tests in range(t):
n=int(input())
A=list(map(int,input().split()))
compression_dict={a: ind for ind, a in enumerate(sorted(set(A)))}
A=[compression_dict[a] for a in A]
Q=[0]*n
for i in range(n):
Q[A[i]]=i
count=1
Ans=0
#print(A,Q)
for i in range(1,n):
if Q[i]>Q[i-1]:
count+=1
else:
Ans=max(count,Ans)
count=1
Ans=max(count,Ans)
print(n-Ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n5\n4 7 2 3 9\n5\n3 5 8 1 7\n5\n1 4 5 7 12\n4\n0 2 1 3\n",
"output": "2\n2\n0\n2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1367/F1"
} | vfc_7054 |
apps | verifiable_code | 2378 | Solve the following coding problem using the programming language python:
Recently you have bought a snow walking robot and brought it home. Suppose your home is a cell $(0, 0)$ on an infinite grid.
You also have the sequence of instructions of this robot. It is written as the string $s$ consisting of characters 'L', 'R', 'U' and 'D'. If the robot is in the cell $(x, y)$ right now, he can move to one of the adjacent cells (depending on the current instruction). If the current instruction is 'L', then the robot can move to the left to $(x - 1, y)$; if the current instruction is 'R', then the robot can move to the right to $(x + 1, y)$; if the current instruction is 'U', then the robot can move to the top to $(x, y + 1)$; if the current instruction is 'D', then the robot can move to the bottom to $(x, y - 1)$.
You've noticed the warning on the last page of the manual: if the robot visits some cell (except $(0, 0)$) twice then it breaks.
So the sequence of instructions is valid if the robot starts in the cell $(0, 0)$, performs the given instructions, visits no cell other than $(0, 0)$ two or more times and ends the path in the cell $(0, 0)$. Also cell $(0, 0)$ should be visited at most two times: at the beginning and at the end (if the path is empty then it is visited only once). For example, the following sequences of instructions are considered valid: "UD", "RL", "UUURULLDDDDLDDRRUU", and the following are considered invalid: "U" (the endpoint is not $(0, 0)$) and "UUDD" (the cell $(0, 1)$ is visited twice).
The initial sequence of instructions, however, might be not valid. You don't want your robot to break so you decided to reprogram it in the following way: you will remove some (possibly, all or none) instructions from the initial sequence of instructions, then rearrange the remaining instructions as you wish and turn on your robot to move.
Your task is to remove as few instructions from the initial sequence as possible and rearrange the remaining ones so that the sequence is valid. Report the valid sequence of the maximum length you can obtain.
Note that you can choose any order of remaining instructions (you don't need to minimize the number of swaps or any other similar metric).
You have to answer $q$ independent test cases.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 2 \cdot 10^4$) — the number of test cases.
The next $q$ lines contain test cases. The $i$-th test case is given as the string $s$ consisting of at least $1$ and no more than $10^5$ characters 'L', 'R', 'U' and 'D' — the initial sequence of instructions.
It is guaranteed that the sum of $|s|$ (where $|s|$ is the length of $s$) does not exceed $10^5$ over all test cases ($\sum |s| \le 10^5$).
-----Output-----
For each test case print the answer on it. In the first line print the maximum number of remaining instructions. In the second line print the valid sequence of remaining instructions $t$ the robot has to perform. The moves are performed from left to right in the order of the printed sequence. If there are several answers, you can print any. If the answer is $0$, you are allowed to print an empty line (but you can don't print it).
-----Example-----
Input
6
LRU
DURLDRUDRULRDURDDL
LRUDDLRUDRUL
LLLLRRRR
URDUR
LLL
Output
2
LR
14
RUURDDDDLLLUUR
12
ULDDDRRRUULL
2
LR
2
UD
0
-----Note-----
There are only two possible answers in the first test case: "LR" and "RL".
The picture corresponding to the second test case: [Image] Note that the direction of traverse does not matter
Another correct answer to the third test case: "URDDLLLUURDR".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
for _ in range(n):
s = input()
l,r,u,d = [s.count(i) for i in 'LRUD']
lr = min(l, r)
ud = min(u, d)
res = ""
if lr == 0 and ud == 0:
res = ""
elif lr == 0:
res = "UD"
elif ud == 0:
res = 'LR'
else:
res = 'R' * lr + 'U' * ud + 'L' * lr + 'D' * ud
print(len(res))
print(res)
``` | {
"language": "python",
"test_cases": [
{
"input": "6\nLRU\nDURLDRUDRULRDURDDL\nLRUDDLRUDRUL\nLLLLRRRR\nURDUR\nLLL\n",
"output": "2\nLR\n14\nLLLUUUURRRDDDD\n12\nLLLUUURRRDDD\n2\nLR\n2\nUD\n0\n\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1272/B"
} | vfc_7058 |
apps | verifiable_code | 2380 | Solve the following coding problem using the programming language python:
You are given a garland consisting of $n$ lamps. States of the lamps are represented by the string $s$ of length $n$. The $i$-th character of the string $s_i$ equals '0' if the $i$-th lamp is turned off or '1' if the $i$-th lamp is turned on. You are also given a positive integer $k$.
In one move, you can choose one lamp and change its state (i.e. turn it on if it is turned off and vice versa).
The garland is called $k$-periodic if the distance between each pair of adjacent turned on lamps is exactly $k$. Consider the case $k=3$. Then garlands "00010010", "1001001", "00010" and "0" are good but garlands "00101001", "1000001" and "01001100" are not. Note that the garland is not cyclic, i.e. the first turned on lamp is not going after the last turned on lamp and vice versa.
Your task is to find the minimum number of moves you need to make to obtain $k$-periodic garland from the given one.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 25~ 000$) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $k$ ($1 \le n \le 10^6; 1 \le k \le n$) — the length of $s$ and the required period. The second line of the test case contains the string $s$ consisting of $n$ characters '0' and '1'.
It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$ ($\sum n \le 10^6$).
-----Output-----
For each test case, print the answer — the minimum number of moves you need to make to obtain $k$-periodic garland from the given one.
-----Example-----
Input
6
9 2
010001010
9 3
111100000
7 4
1111111
10 3
1001110101
1 1
1
1 1
0
Output
1
2
5
4
0
0
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = sys.stdin.readline
rInt = lambda: int(input())
mInt = lambda: map(int, input().split())
rLis = lambda: list(map(int, input().split()))
outs = []
t = rInt()
for _ in range(t):
n, k = mInt()
s = input()
pref = [0]
for c in s:
if c == '1':
pref.append(pref[-1] + 1)
else:
pref.append(pref[-1])
best = pref[-1]
dp = []
for i in range(n):
cost = pref[i]
if i >= k:
case2 = dp[i - k] + pref[i] - pref[i - k + 1]
if case2 < cost:
cost = case2
if s[i] == '0':
cost += 1
dp.append(cost)
actual = cost + pref[-1] - pref[i + 1]
if actual < best:
best = actual
outs.append(best)
print(*outs, sep = '\n')
``` | {
"language": "python",
"test_cases": [
{
"input": "6\n9 2\n010001010\n9 3\n111100000\n7 4\n1111111\n10 3\n1001110101\n1 1\n1\n1 1\n0\n",
"output": "1\n2\n5\n4\n0\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1353/E"
} | vfc_7066 |
apps | verifiable_code | 2381 | Solve the following coding problem using the programming language python:
There is a frog staying to the left of the string $s = s_1 s_2 \ldots s_n$ consisting of $n$ characters (to be more precise, the frog initially stays at the cell $0$). Each character of $s$ is either 'L' or 'R'. It means that if the frog is staying at the $i$-th cell and the $i$-th character is 'L', the frog can jump only to the left. If the frog is staying at the $i$-th cell and the $i$-th character is 'R', the frog can jump only to the right. The frog can jump only to the right from the cell $0$.
Note that the frog can jump into the same cell twice and can perform as many jumps as it needs.
The frog wants to reach the $n+1$-th cell. The frog chooses some positive integer value $d$ before the first jump (and cannot change it later) and jumps by no more than $d$ cells at once. I.e. if the $i$-th character is 'L' then the frog can jump to any cell in a range $[max(0, i - d); i - 1]$, and if the $i$-th character is 'R' then the frog can jump to any cell in a range $[i + 1; min(n + 1; i + d)]$.
The frog doesn't want to jump far, so your task is to find the minimum possible value of $d$ such that the frog can reach the cell $n+1$ from the cell $0$ if it can jump by no more than $d$ cells at once. It is guaranteed that it is always possible to reach $n+1$ from $0$.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The next $t$ lines describe test cases. The $i$-th test case is described as a string $s$ consisting of at least $1$ and at most $2 \cdot 10^5$ characters 'L' and 'R'.
It is guaranteed that the sum of lengths of strings over all test cases does not exceed $2 \cdot 10^5$ ($\sum |s| \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer — the minimum possible value of $d$ such that the frog can reach the cell $n+1$ from the cell $0$ if it jumps by no more than $d$ at once.
-----Example-----
Input
6
LRLRRLL
L
LLR
RRRR
LLLLLL
R
Output
3
2
3
1
7
1
-----Note-----
The picture describing the first test case of the example and one of the possible answers:
[Image]
In the second test case of the example, the frog can only jump directly from $0$ to $n+1$.
In the third test case of the example, the frog can choose $d=3$, jump to the cell $3$ from the cell $0$ and then to the cell $4$ from the cell $3$.
In the fourth test case of the example, the frog can choose $d=1$ and jump $5$ times to the right.
In the fifth test case of the example, the frog can only jump directly from $0$ to $n+1$.
In the sixth test case of the example, the frog can choose $d=1$ and jump $2$ times to the right.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for i in range(int(input())):
s='R' + input() + 'R'
prev=0
ma=-1
for i in range(1,len(s)):
if s[i]=='R':
ma=max(ma,i-prev)
prev=i
print(ma)
``` | {
"language": "python",
"test_cases": [
{
"input": "6\nLRLRRLL\nL\nLLR\nRRRR\nLLLLLL\nR\n",
"output": "3\n2\n3\n1\n7\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1324/C"
} | vfc_7070 |
apps | verifiable_code | 2382 | Solve the following coding problem using the programming language python:
You are given $n$ strings $a_1, a_2, \ldots, a_n$: all of them have the same length $m$. The strings consist of lowercase English letters.
Find any string $s$ of length $m$ such that each of the given $n$ strings differs from $s$ in at most one position. Formally, for each given string $a_i$, there is no more than one position $j$ such that $a_i[j] \ne s[j]$.
Note that the desired string $s$ may be equal to one of the given strings $a_i$, or it may differ from all the given strings.
For example, if you have the strings abac and zbab, then the answer to the problem might be the string abab, which differs from the first only by the last character, and from the second only by the first.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 100$) — the number of test cases. Then $t$ test cases follow.
Each test case starts with a line containing two positive integers $n$ ($1 \le n \le 10$) and $m$ ($1 \le m \le 10$) — the number of strings and their length.
Then follow $n$ strings $a_i$, one per line. Each of them has length $m$ and consists of lowercase English letters.
-----Output-----
Print $t$ answers to the test cases. Each answer (if it exists) is a string of length $m$ consisting of lowercase English letters. If there are several answers, print any of them. If the answer does not exist, print "-1" ("minus one", without quotes).
-----Example-----
Input
5
2 4
abac
zbab
2 4
aaaa
bbbb
3 3
baa
aaa
aab
2 2
ab
bb
3 1
a
b
c
Output
abab
-1
aaa
ab
z
-----Note-----
The first test case was explained in the statement.
In the second test case, the answer does not exist.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def isvalid(s):
nonlocal l
for i in l:
count=0
for j in range(len(i)):
if(s[j]!=i[j]):
count+=1
if(count>1):
return 0
return 1
t=int(input())
for you in range(t):
l=input().split()
n=int(l[0])
m=int(l[1])
l=[]
for i in range(n):
s=input()
l.append(s)
poss=0
ans=0
for i in range(m):
copy=[x for x in l[0]]
for j in range(26):
copy[i]=chr(97+j)
if(isvalid(copy)):
poss=1
ans=copy
break
if(poss==1):
break
if(poss):
for i in ans:
print(i,end="")
print()
else:
print(-1)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n2 4\nabac\nzbab\n2 4\naaaa\nbbbb\n3 3\nbaa\naaa\naab\n2 2\nab\nbb\n3 1\na\nb\nc\n",
"output": "zbac\n-1\naaa\nab\na\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1360/F"
} | vfc_7074 |
apps | verifiable_code | 2383 | Solve the following coding problem using the programming language python:
Find the minimum area of a square land on which you can place two identical rectangular $a \times b$ houses. The sides of the houses should be parallel to the sides of the desired square land.
Formally, You are given two identical rectangles with side lengths $a$ and $b$ ($1 \le a, b \le 100$) — positive integers (you are given just the sizes, but not their positions). Find the square of the minimum area that contains both given rectangles. Rectangles can be rotated (both or just one), moved, but the sides of the rectangles should be parallel to the sides of the desired square.
Two rectangles can touch each other (side or corner), but cannot intersect. Rectangles can also touch the sides of the square but must be completely inside it. You can rotate the rectangles. Take a look at the examples for a better understanding.
[Image] The picture shows a square that contains red and green rectangles.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10\,000$) —the number of test cases in the input. Then $t$ test cases follow.
Each test case is a line containing two integers $a$, $b$ ($1 \le a, b \le 100$) — side lengths of the rectangles.
-----Output-----
Print $t$ answers to the test cases. Each answer must be a single integer — minimal area of square land, that contains two rectangles with dimensions $a \times b$.
-----Example-----
Input
8
3 2
4 2
1 1
3 1
4 7
1 3
7 4
100 100
Output
16
16
4
9
64
9
64
40000
-----Note-----
Below are the answers for the first two test cases: [Image] [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
T = int(input())
for _ in range(T):
a, b = list(map(int, input().split()))
print(max(max(a, b), min(a, b) * 2)**2)
``` | {
"language": "python",
"test_cases": [
{
"input": "8\n3 2\n4 2\n1 1\n3 1\n4 7\n1 3\n7 4\n100 100\n",
"output": "16\n16\n4\n9\n64\n9\n64\n40000\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1360/A"
} | vfc_7078 |
apps | verifiable_code | 2384 | Solve the following coding problem using the programming language python:
This is a hard version of the problem. In this version, the given array can contain equal elements and the constraints on $n$ are greater than in the easy version of the problem.
You are given an array $a$ of $n$ integers (the given array can contain equal elements). You can perform the following operations on array elements: choose any index $i$ ($1 \le i \le n$) and move the element $a[i]$ to the begin of the array; choose any index $i$ ($1 \le i \le n$) and move the element $a[i]$ to the end of the array.
For example, if $n = 5$, $a = [4, 7, 2, 2, 9]$, then the following sequence of operations can be performed: after performing the operation of the first type to the second element, the array $a$ will become $[7, 4, 2, 2, 9]$; after performing the operation of the second type to the second element, the array $a$ will become $[7, 2, 2, 9, 4]$.
You can perform operations of any type any number of times in any order.
Find the minimum total number of operations of the first and second type that will make the $a$ array sorted in non-decreasing order. In other words, what is the minimum number of operations must be performed so the array satisfies the inequalities $a[1] \le a[2] \le \ldots \le a[n]$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases in the test. Then $t$ test cases follow.
Each test case starts with a line containing an integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the size of the array $a$.
Then follow $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$) — an array that needs to be sorted by the given operations. The given array can contain equal elements.
The sum of $n$ for all test cases in one test does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case output one integer — the minimum total number of operations of the first and second type, which will make the array sorted in non-decreasing order.
-----Example-----
Input
9
5
4 7 2 2 9
5
3 5 8 1 7
5
1 2 2 4 5
2
0 1
3
0 1 0
4
0 1 0 0
4
0 1 0 1
4
0 1 0 2
20
16 15 1 10 0 14 0 10 3 9 2 5 4 5 17 9 10 20 0 9
Output
2
2
0
0
1
1
1
1
16
-----Note-----
In the first test case, you first need to move two 2, to the beginning of the array. Therefore, the desired sequence of operations: $[4, 7, 2, 2, 9] \rightarrow [2, 4, 7, 2, 9] \rightarrow [2, 2, 4, 7, 9]$.
In the second test case, you need to move the 1 to the beginning of the array, and the 8 — to the end. Therefore, the desired sequence of operations: $[3, 5, 8, 1, 7] \rightarrow [1, 3, 5, 8, 7] \rightarrow [1, 3, 5, 7, 8]$.
In the third test case, the array is already sorted.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from sys import stdin
for _ in range(int(input())):
n = int(input())
l = list(map(int,input().split()))
id = list(zip(l,list(range(n))))
id.sort()
val, pos = zip(*id)
blok = []
cur = [pos[0]]
for i in range(1,n):
if val[i] == val[i-1]:
cur.append(pos[i])
else:
cur.sort()
blok.append(cur)
cur = [pos[i]]
cur.sort()
blok.append(cur)
best = 0
m = len(blok)
for j in range(m):
best = max(len(blok[j]), best)
i = 0
while True:
if i >= m-2:
break
cyk = min(blok[i+1])
j = -1
while j+1 < len(blok[i]) and blok[i][j+1] < cyk:
j += 1
su = (j+1)
ii = i+2
while ii < m:
if min(blok[ii]) > max(blok[ii-1]):
su += len(blok[ii-1])
ii += 1
else:
break
if ii == m:
su += len(blok[-1])
best = max(best, su)
else:
xxx = max(blok[ii-1])
su += len(blok[ii-1])
inde = len(blok[ii])-1
while inde >= 0 and blok[ii][inde] >= xxx:
su += 1
inde -= 1
best = max(best,su)
i = max(i+1, ii-1)
for i in range(1,m):
b1 = blok[i];b0 = blok[i-1];l0,l1,i1 = len(b0),len(b1),0
for ind in range(l0):
while True:
if i1 < l1 and b1[i1] <= b0[ind]:i1 += 1
else:break
if l1 == i1:break
best = max(best, (ind+1)+(l1-i1))
print(n-best)
``` | {
"language": "python",
"test_cases": [
{
"input": "9\n5\n4 7 2 2 9\n5\n3 5 8 1 7\n5\n1 2 2 4 5\n2\n0 1\n3\n0 1 0\n4\n0 1 0 0\n4\n0 1 0 1\n4\n0 1 0 2\n20\n16 15 1 10 0 14 0 10 3 9 2 5 4 5 17 9 10 20 0 9\n",
"output": "2\n2\n0\n0\n1\n1\n1\n1\n16\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1367/F2"
} | vfc_7082 |
apps | verifiable_code | 2385 | Solve the following coding problem using the programming language python:
There is a rectangular grid of size $n \times m$. Each cell of the grid is colored black ('0') or white ('1'). The color of the cell $(i, j)$ is $c_{i, j}$. You are also given a map of directions: for each cell, there is a direction $s_{i, j}$ which is one of the four characters 'U', 'R', 'D' and 'L'.
If $s_{i, j}$ is 'U' then there is a transition from the cell $(i, j)$ to the cell $(i - 1, j)$; if $s_{i, j}$ is 'R' then there is a transition from the cell $(i, j)$ to the cell $(i, j + 1)$; if $s_{i, j}$ is 'D' then there is a transition from the cell $(i, j)$ to the cell $(i + 1, j)$; if $s_{i, j}$ is 'L' then there is a transition from the cell $(i, j)$ to the cell $(i, j - 1)$.
It is guaranteed that the top row doesn't contain characters 'U', the bottom row doesn't contain characters 'D', the leftmost column doesn't contain characters 'L' and the rightmost column doesn't contain characters 'R'.
You want to place some robots in this field (at most one robot in a cell). The following conditions should be satisfied.
Firstly, each robot should move every time (i.e. it cannot skip the move). During one move each robot goes to the adjacent cell depending on the current direction. Secondly, you have to place robots in such a way that there is no move before which two different robots occupy the same cell (it also means that you cannot place two robots in the same cell). I.e. if the grid is "RL" (one row, two columns, colors does not matter there) then you can place two robots in cells $(1, 1)$ and $(1, 2)$, but if the grid is "RLL" then you cannot place robots in cells $(1, 1)$ and $(1, 3)$ because during the first second both robots will occupy the cell $(1, 2)$.
The robots make an infinite number of moves.
Your task is to place the maximum number of robots to satisfy all the conditions described above and among all such ways, you have to choose one where the number of black cells occupied by robots before all movements is the maximum possible. Note that you can place robots only before all movements.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 5 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $m$ ($1 < nm \le 10^6$) — the number of rows and the number of columns correspondingly.
The next $n$ lines contain $m$ characters each, where the $j$-th character of the $i$-th line is $c_{i, j}$ ($c_{i, j}$ is either '0' if the cell $(i, j)$ is black or '1' if the cell $(i, j)$ is white).
The next $n$ lines also contain $m$ characters each, where the $j$-th character of the $i$-th line is $s_{i, j}$ ($s_{i, j}$ is 'U', 'R', 'D' or 'L' and describes the direction of the cell $(i, j)$).
It is guaranteed that the sum of the sizes of fields does not exceed $10^6$ ($\sum nm \le 10^6$).
-----Output-----
For each test case, print two integers — the maximum number of robots you can place to satisfy all the conditions described in the problem statement and the maximum number of black cells occupied by robots before all movements if the number of robots placed is maximized. Note that you can place robots only before all movements.
-----Example-----
Input
3
1 2
01
RL
3 3
001
101
110
RLL
DLD
ULL
3 3
000
000
000
RRD
RLD
ULL
Output
2 1
4 3
2 2
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = sys.stdin.readline
def search(i,j):
L=[]
c=0
while CHECK[i][j]==1<<30:
L.append((i,j))
CHECK[i][j]=c
if MAP2[i][j]=="U":
i-=1
elif MAP2[i][j]=="D":
i+=1
elif MAP2[i][j]=="R":
j+=1
else:
j-=1
c+=1
if (i,j) in L:
x=CHECK[i][j]
y=CHECK[L[-1][0]][L[-1][1]]
loop=abs(x-y)+1
for x,y in L:
CHECK[x][y]%=loop
LOOP[x][y]=loop
else:
loop=LOOP[i][j]
c=CHECK[i][j]
for x,y in L[::-1]:
c=(c-1)%loop
CHECK[x][y]=c
LOOP[x][y]=loop
def search2(i,j):
Q=[(i,j)]
ANS=[0]*LOOP[i][j]
while Q:
x,y=Q.pop()
if USE[x][y]==1:
continue
USE[x][y]=1
if MAP[x][y]=="0":
ANS[CHECK[x][y]]=1
if MAP2[x][y]=="U":
Q.append((x-1,y))
elif MAP2[x][y]=="D":
Q.append((x+1,y))
elif MAP2[x][y]=="R":
Q.append((x,y+1))
else:
Q.append((x,y-1))
if 0<=x+1<n and 0<=y<m and MAP2[x+1][y]=="U":
Q.append((x+1,y))
if 0<=x-1<n and 0<=y<m and MAP2[x-1][y]=="D":
Q.append((x-1,y))
if 0<=x<n and 0<=y+1<m and MAP2[x][y+1]=="L":
Q.append((x,y+1))
if 0<=x<n and 0<=y-1<m and MAP2[x][y-1]=="R":
Q.append((x,y-1))
return LOOP[i][j],sum(ANS)
t=int(input())
for tests in range(t):
n,m=list(map(int,input().split()))
MAP=[input().strip() for i in range(n)]
MAP2=[input().strip() for i in range(n)]
CHECK=[[1<<30]*m for i in range(n)]
LOOP=[[1<<30]*m for i in range(n)]
for i in range(n):
for j in range(m):
if CHECK[i][j]==1<<30:
search(i,j)
#print(i,j)
#print(CHECK)
#print(LOOP)
USE=[[0]*m for i in range(n)]
ANSM=0
ANSC=0
for i in range(n):
for j in range(m):
if USE[i][j]==0:
x,y=search2(i,j)
ANSM+=x
ANSC+=y
print(ANSM,ANSC)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n1 2\n01\nRL\n3 3\n001\n101\n110\nRLL\nDLD\nULL\n3 3\n000\n000\n000\nRRD\nRLD\nULL\n",
"output": "2 1\n4 3\n2 2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1335/F"
} | vfc_7086 |
apps | verifiable_code | 2386 | Solve the following coding problem using the programming language python:
A permutation of length $n$ is a sequence of integers from $1$ to $n$ of length $n$ containing each number exactly once. For example, $[1]$, $[4, 3, 5, 1, 2]$, $[3, 2, 1]$ are permutations, and $[1, 1]$, $[0, 1]$, $[2, 2, 1, 4]$ are not.
There was a permutation $p[1 \dots n]$. It was merged with itself. In other words, let's take two instances of $p$ and insert elements of the second $p$ into the first maintaining relative order of elements. The result is a sequence of the length $2n$.
For example, if $p=[3, 1, 2]$ some possible results are: $[3, 1, 2, 3, 1, 2]$, $[3, 3, 1, 1, 2, 2]$, $[3, 1, 3, 1, 2, 2]$. The following sequences are not possible results of a merging: $[1, 3, 2, 1, 2, 3$], [$3, 1, 2, 3, 2, 1]$, $[3, 3, 1, 2, 2, 1]$.
For example, if $p=[2, 1]$ the possible results are: $[2, 2, 1, 1]$, $[2, 1, 2, 1]$. The following sequences are not possible results of a merging: $[1, 1, 2, 2$], [$2, 1, 1, 2]$, $[1, 2, 2, 1]$.
Your task is to restore the permutation $p$ by the given resulting sequence $a$. It is guaranteed that the answer exists and is unique.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 400$) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ($1 \le n \le 50$) — the length of permutation. The second line of the test case contains $2n$ integers $a_1, a_2, \dots, a_{2n}$ ($1 \le a_i \le n$), where $a_i$ is the $i$-th element of $a$. It is guaranteed that the array $a$ represents the result of merging of some permutation $p$ with the same permutation $p$.
-----Output-----
For each test case, print the answer: $n$ integers $p_1, p_2, \dots, p_n$ ($1 \le p_i \le n$), representing the initial permutation. It is guaranteed that the answer exists and is unique.
-----Example-----
Input
5
2
1 1 2 2
4
1 3 1 4 3 4 2 2
5
1 2 1 2 3 4 3 5 4 5
3
1 2 3 1 2 3
4
2 3 2 4 1 3 4 1
Output
1 2
1 3 4 2
1 2 3 4 5
1 2 3
2 3 4 1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
print(*set(a))
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n2\n1 1 2 2\n4\n1 3 1 4 3 4 2 2\n5\n1 2 1 2 3 4 3 5 4 5\n3\n1 2 3 1 2 3\n4\n2 3 2 4 1 3 4 1\n",
"output": "1 2 \n1 3 4 2 \n1 2 3 4 5 \n1 2 3 \n2 3 4 1 \n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1385/B"
} | vfc_7090 |
apps | verifiable_code | 2388 | Solve the following coding problem using the programming language python:
You are given an undirected unweighted connected graph consisting of $n$ vertices and $m$ edges. It is guaranteed that there are no self-loops or multiple edges in the given graph.
Your task is to choose at most $\lfloor\frac{n}{2}\rfloor$ vertices in this graph so each unchosen vertex is adjacent (in other words, connected by an edge) to at least one of chosen vertices.
It is guaranteed that the answer exists. If there are multiple answers, you can print any.
You will be given multiple independent queries to answer.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 2 \cdot 10^5$) — the number of queries.
Then $t$ queries follow.
The first line of each query contains two integers $n$ and $m$ ($2 \le n \le 2 \cdot 10^5$, $n - 1 \le m \le min(2 \cdot 10^5, \frac{n(n-1)}{2})$) — the number of vertices and the number of edges, respectively.
The following $m$ lines denote edges: edge $i$ is represented by a pair of integers $v_i$, $u_i$ ($1 \le v_i, u_i \le n$, $u_i \ne v_i$), which are the indices of vertices connected by the edge.
There are no self-loops or multiple edges in the given graph, i. e. for each pair ($v_i, u_i$) there are no other pairs ($v_i, u_i$) or ($u_i, v_i$) in the list of edges, and for each pair ($v_i, u_i$) the condition $v_i \ne u_i$ is satisfied. It is guaranteed that the given graph is connected.
It is guaranteed that $\sum m \le 2 \cdot 10^5$ over all queries.
-----Output-----
For each query print two lines.
In the first line print $k$ ($1 \le \lfloor\frac{n}{2}\rfloor$) — the number of chosen vertices.
In the second line print $k$ distinct integers $c_1, c_2, \dots, c_k$ in any order, where $c_i$ is the index of the $i$-th chosen vertex.
It is guaranteed that the answer exists. If there are multiple answers, you can print any.
-----Example-----
Input
2
4 6
1 2
1 3
1 4
2 3
2 4
3 4
6 8
2 5
5 4
4 3
4 1
1 3
2 3
2 6
5 6
Output
2
1 3
3
4 3 6
-----Note-----
In the first query any vertex or any pair of vertices will suffice.
[Image]
Note that you don't have to minimize the number of chosen vertices. In the second query two vertices can be enough (vertices $2$ and $4$) but three is also ok.
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
N, M = list(map(int, input().split()))
E = [[] for aa in range(N)]
for __ in range(M):
a, b = list(map(int, input().split()))
E[a-1].append(b-1)
E[b-1].append(a-1)
D = [-1] * N
D[0] = 0
d = 0
post = [0]
EVEN = [1]
ODD = []
while post:
d += 1
pre = post
post = []
for i in pre:
for e in E[i]:
if D[e] < 0:
D[e] = d
post.append(e)
if d % 2:
ODD.append(e+1)
else:
EVEN.append(e+1)
if len(ODD) < len(EVEN):
print(len(ODD))
print(*ODD)
else:
print(len(EVEN))
print(*EVEN)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n6 8\n2 5\n5 4\n4 3\n4 1\n1 3\n2 3\n2 6\n5 6\n",
"output": "1\n1 \n3\n3 4 6 \n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1176/E"
} | vfc_7098 |
apps | verifiable_code | 2389 | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is the size of the input.
You are given a string $s$ consisting of $n$ characters, each character is 'R', 'G' or 'B'.
You are also given an integer $k$. Your task is to change the minimum number of characters in the initial string $s$ so that after the changes there will be a string of length $k$ that is a substring of $s$, and is also a substring of the infinite string "RGBRGBRGB ...".
A string $a$ is a substring of string $b$ if there exists a positive integer $i$ such that $a_1 = b_i$, $a_2 = b_{i + 1}$, $a_3 = b_{i + 2}$, ..., $a_{|a|} = b_{i + |a| - 1}$. For example, strings "GBRG", "B", "BR" are substrings of the infinite string "RGBRGBRGB ..." while "GR", "RGR" and "GGG" are not.
You have to answer $q$ independent queries.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries. Then $q$ queries follow.
The first line of the query contains two integers $n$ and $k$ ($1 \le k \le n \le 2 \cdot 10^5$) — the length of the string $s$ and the length of the substring.
The second line of the query contains a string $s$ consisting of $n$ characters 'R', 'G' and 'B'.
It is guaranteed that the sum of $n$ over all queries does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each query print one integer — the minimum number of characters you need to change in the initial string $s$ so that after changing there will be a substring of length $k$ in $s$ that is also a substring of the infinite string "RGBRGBRGB ...".
-----Example-----
Input
3
5 2
BGGGG
5 3
RBRGR
5 5
BBBRR
Output
1
0
3
-----Note-----
In the first example, you can change the first character to 'R' and obtain the substring "RG", or change the second character to 'R' and obtain "BR", or change the third, fourth or fifth character to 'B' and obtain "GB".
In the second example, the substring is "BRG".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from sys import stdin
import math
rgb = 'RGB'
for query in range(int(stdin.readline())):
n, k = list(map(int, stdin.readline().split()))
s = stdin.readline()
ans = math.inf
for start in range(3):
dp = [0 for i in range(n + 1)]
for i in range(n):
cur = rgb[(start + i) % len(rgb)]
dp[i + 1] = dp[i] + int(s[i] != cur)
for i in range(n - k + 1):
ans = min(ans, dp[i + k] - dp[i])
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n5 2\nBGGGG\n5 3\nRBRGR\n5 5\nBBBRR\n",
"output": "1\n0\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1196/D2"
} | vfc_7102 |
apps | verifiable_code | 2390 | Solve the following coding problem using the programming language python:
This problem is actually a subproblem of problem G from the same contest.
There are $n$ candies in a candy box. The type of the $i$-th candy is $a_i$ ($1 \le a_i \le n$).
You have to prepare a gift using some of these candies with the following restriction: the numbers of candies of each type presented in a gift should be all distinct (i. e. for example, a gift having two candies of type $1$ and two candies of type $2$ is bad).
It is possible that multiple types of candies are completely absent from the gift. It is also possible that not all candies of some types will be taken to a gift.
Your task is to find out the maximum possible size of the single gift you can prepare using the candies you have.
You have to answer $q$ independent queries.
If you are Python programmer, consider using PyPy instead of Python when you submit your code.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 2 \cdot 10^5$) — the number of queries. Each query is represented by two lines.
The first line of each query contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of candies.
The second line of each query contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$), where $a_i$ is the type of the $i$-th candy in the box.
It is guaranteed that the sum of $n$ over all queries does not exceed $2 \cdot 10^5$.
-----Output-----
For each query print one integer — the maximum possible size of the single gift you can compose using candies you got in this query with the restriction described in the problem statement.
-----Example-----
Input
3
8
1 4 8 4 5 6 3 8
16
2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1
9
2 2 4 4 4 7 7 7 7
Output
3
10
9
-----Note-----
In the first query, you can prepare a gift with two candies of type $8$ and one candy of type $5$, totalling to $3$ candies.
Note that this is not the only possible solution — taking two candies of type $4$ and one candy of type $6$ is also valid.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = sys.stdin.readline
Q = int(input())
for _ in range(Q):
N = int(input())
A = [int(a) for a in input().split()]
X = {}
for a in A:
if a in X:
X[a] += 1
else:
X[a] = 1
Y = []
for x in X:
Y.append(X[x])
Y = sorted(Y)[::-1]
prev = Y[0] + 1
su = 0
for i in range(len(Y)):
ne = min(prev-1, Y[i])
if ne <= 0:
break
su += ne
prev = ne
print(su)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n8\n1 4 8 4 5 6 3 8\n16\n2 1 3 3 4 3 4 4 1 3 2 2 2 4 1 1\n9\n2 2 4 4 4 7 7 7 7\n",
"output": "3\n10\n9\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1183/D"
} | vfc_7106 |
apps | verifiable_code | 2391 | Solve the following coding problem using the programming language python:
You are given an array $a$ consisting of $n$ integers.
In one move, you can choose some index $i$ ($1 \le i \le n - 2$) and shift the segment $[a_i, a_{i + 1}, a_{i + 2}]$ cyclically to the right (i.e. replace the segment $[a_i, a_{i + 1}, a_{i + 2}]$ with $[a_{i + 2}, a_i, a_{i + 1}]$).
Your task is to sort the initial array by no more than $n^2$ such operations or say that it is impossible to do that.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 100$) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ($3 \le n \le 500$) — the length of $a$. The second line of the test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 500$), where $a_i$ is the $i$-th element $a$.
It is guaranteed that the sum of $n$ does not exceed $500$.
-----Output-----
For each test case, print the answer: -1 on the only line if it is impossible to sort the given array using operations described in the problem statement, or the number of operations $ans$ on the first line and $ans$ integers $idx_1, idx_2, \dots, idx_{ans}$ ($1 \le idx_i \le n - 2$), where $idx_i$ is the index of left border of the segment for the $i$-th operation. You should print indices in order of performing operations.
-----Example-----
Input
5
5
1 2 3 4 5
5
5 4 3 2 1
8
8 4 5 2 3 6 7 3
7
5 2 1 6 4 7 3
6
1 2 3 3 6 4
Output
0
6
3 1 3 2 2 3
13
2 1 1 6 4 2 4 3 3 4 4 6 6
-1
4
3 3 4 4
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t = int(input())
for _ in range(t):
n = int(input())
l = list([int(x)- 1 for x in input().split()])
out = []
ll = [(l[i], i) for i in range(n)]
ll.sort()
swap = (-1,-1)
for i in range(n - 1):
if ll[i][0] == ll[i + 1][0]:
swap = (ll[i][1],ll[i+1][1])
newl = [0]*n
for i in range(n):
newl[ll[i][1]] = i
l = newl
swapN = 0
for i in range(n):
for j in range(i + 1, n):
if l[i] > l[j]:
swapN += 1
#print(l)
if swapN & 1:
l[swap[0]],l[swap[1]] = l[swap[1]],l[swap[0]]
#print(l)
def shift(i):
out.append(i + 1)
l[i],l[i+1],l[i+2] = l[i+2],l[i],l[i+1]
works = True
done = False
while not done:
for i in range(n):
if l[i] != i:
break
else:
done = True
if done:
break
for find in range(i + 1, n):
if l[find] == i:
break
while find - i >= 2:
find -= 2
shift(find)
if find - i == 1:
if find <= n - 2:
shift(find - 1)
shift(find - 1)
else:
works = False
break
#print(l)
if works:
print(len(out))
print(' '.join(map(str,out)))
else:
print(-1)
#print('---')
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n5\n1 2 3 4 5\n5\n5 4 3 2 1\n8\n8 4 5 2 3 6 7 3\n7\n5 2 1 6 4 7 3\n6\n1 2 3 3 6 4\n",
"output": "0\n\n6\n3 1 3 2 2 3 \n13\n2 1 1 6 4 2 4 3 3 4 4 6 6 \n-1\n4\n3 3 4 4 \n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1374/F"
} | vfc_7110 |
apps | verifiable_code | 2392 | Solve the following coding problem using the programming language python:
Polycarp is reading a book consisting of $n$ pages numbered from $1$ to $n$. Every time he finishes the page with the number divisible by $m$, he writes down the last digit of this page number. For example, if $n=15$ and $m=5$, pages divisible by $m$ are $5, 10, 15$. Their last digits are $5, 0, 5$ correspondingly, their sum is $10$.
Your task is to calculate the sum of all digits Polycarp has written down.
You have to answer $q$ independent queries.
-----Input-----
The first line of the input contains one integer $q$ ($1 \le q \le 1000$) — the number of queries.
The following $q$ lines contain queries, one per line. Each query is given as two integers $n$ and $m$ ($1 \le n, m \le 10^{16}$) — the number of pages in the book and required divisor, respectively.
-----Output-----
For each query print the answer for it — the sum of digits written down by Polycarp.
-----Example-----
Input
7
1 1
10 1
100 3
1024 14
998244353 1337
123 144
1234312817382646 13
Output
1
45
153
294
3359835
0
427262129093995
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for _ in range(int(input())):
n, m = list(map(int, input().split()))
A = []
x = 1
while True:
if (m * x) % 10 not in A:
A.append((m * x) % 10)
else:
break
x += 1
s = sum(A)
n //= m
print(s * (n // len(A)) + sum(A[:n % len(A)]))
``` | {
"language": "python",
"test_cases": [
{
"input": "7\n1 1\n10 1\n100 3\n1024 14\n998244353 1337\n123 144\n1234312817382646 13\n",
"output": "1\n45\n153\n294\n3359835\n0\n427262129093995\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1213/C"
} | vfc_7114 |
apps | verifiable_code | 2393 | Solve the following coding problem using the programming language python:
Polygon is not only the best platform for developing problems but also a square matrix with side $n$, initially filled with the character 0.
On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row and a cannon to the left of each cell in the first column. Thus, exactly $2n$ cannons were placed. [Image] Initial polygon for $n=4$.
Cannons shoot character 1. At any moment of time, no more than one cannon is shooting. When a 1 flies out of a cannon, it flies forward (in the direction of the shot) until it collides with a polygon border or another 1. After that, it takes the cell in which it was before the collision and remains there. Take a look at the examples for better understanding.
More formally: if a cannon stands in the row $i$, to the left of the first column, and shoots with a 1, then the 1 starts its flight from the cell ($i, 1$) and ends in some cell ($i, j$); if a cannon stands in the column $j$, above the first row, and shoots with a 1, then the 1 starts its flight from the cell ($1, j$) and ends in some cell ($i, j$).
For example, consider the following sequence of shots: [Image]
1. Shoot the cannon in the row $2$. 2. Shoot the cannon in the row $2$. 3. Shoot the cannon in column $3$.
You have a report from the military training on your desk. This report is a square matrix with side length $n$ consisting of 0 and 1. You wonder if the training actually happened. In other words, is there a sequence of shots such that, after the training, you get the given matrix?
Each cannon can make an arbitrary number of shots. Before the training, each cell of the polygon contains 0.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow.
Each test case starts with a line containing an integer $n$ ($1 \le n \le 50$) — the size of the polygon.
This is followed by $n$ lines of length $n$, consisting of 0 and 1 — the polygon matrix after the training.
The total area of the matrices in all test cases in one test does not exceed $10^5$.
-----Output-----
For each test case print: YES if there is a sequence of shots leading to a given matrix; NO if such a sequence does not exist.
The letters in the words YES and NO can be printed in any case.
-----Example-----
Input
5
4
0010
0011
0000
0000
2
10
01
2
00
00
4
0101
1111
0101
0111
4
0100
1110
0101
0111
Output
YES
NO
YES
YES
NO
-----Note-----
The first test case was explained in the statement.
The answer to the second test case is NO, since a 1 in a cell ($1, 1$) flying out of any cannon would continue its flight further.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def read_int():
return int(input())
def read_ints():
return list(map(int, input().split(' ')))
t = read_int()
for case_num in range(t):
n = read_int()
mat = []
for i in range(n):
mat.append(input())
ok = True
for i in range(n):
for j in range(n):
if mat[i][j] == '0':
continue
cok = j == n - 1 or i == n - 1
if not cok:
cok = mat[i][j + 1] == '1' or mat[i + 1][j] == '1'
if not cok:
ok = False
break
if not ok:
break
print('YES' if ok else 'NO')
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n4\n0010\n0011\n0000\n0000\n2\n10\n01\n2\n00\n00\n4\n0101\n1111\n0101\n0111\n4\n0100\n1110\n0101\n0111\n",
"output": "YES\nNO\nYES\nYES\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1360/E"
} | vfc_7118 |
apps | verifiable_code | 2394 | Solve the following coding problem using the programming language python:
You are given a bracket sequence $s$ of length $n$, where $n$ is even (divisible by two). The string $s$ consists of $\frac{n}{2}$ opening brackets '(' and $\frac{n}{2}$ closing brackets ')'.
In one move, you can choose exactly one bracket and move it to the beginning of the string or to the end of the string (i.e. you choose some index $i$, remove the $i$-th character of $s$ and insert it before or after all remaining characters of $s$).
Your task is to find the minimum number of moves required to obtain regular bracket sequence from $s$. It can be proved that the answer always exists under the given constraints.
Recall what the regular bracket sequence is:
"()" is regular bracket sequence; if $s$ is regular bracket sequence then "(" + $s$ + ")" is regular bracket sequence; if $s$ and $t$ are regular bracket sequences then $s$ + $t$ is regular bracket sequence.
For example, "()()", "(())()", "(())" and "()" are regular bracket sequences, but ")(", "()(" and ")))" are not.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2000$) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ($2 \le n \le 50$) — the length of $s$. It is guaranteed that $n$ is even. The second line of the test case containg the string $s$ consisting of $\frac{n}{2}$ opening and $\frac{n}{2}$ closing brackets.
-----Output-----
For each test case, print the answer — the minimum number of moves required to obtain regular bracket sequence from $s$. It can be proved that the answer always exists under the given constraints.
-----Example-----
Input
4
2
)(
4
()()
8
())()()(
10
)))((((())
Output
1
0
1
3
-----Note-----
In the first test case of the example, it is sufficient to move the first bracket to the end of the string.
In the third test case of the example, it is sufficient to move the last bracket to the beginning of the string.
In the fourth test case of the example, we can choose last three openning brackets, move them to the beginning of the string and obtain "((()))(())".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for _ in range(int(input())):
n = int(input())
s = input()
st = 0
fans = 0
for x in s:
if x == ')':
st -= 1
else:
st += 1
if st < 0:
fans += 1
st = 0
print(fans)
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n2\n)(\n4\n()()\n8\n())()()(\n10\n)))((((())\n",
"output": "1\n0\n1\n3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1374/C"
} | vfc_7122 |
apps | verifiable_code | 2395 | Solve the following coding problem using the programming language python:
A number is ternary if it contains only digits $0$, $1$ and $2$. For example, the following numbers are ternary: $1022$, $11$, $21$, $2002$.
You are given a long ternary number $x$. The first (leftmost) digit of $x$ is guaranteed to be $2$, the other digits of $x$ can be $0$, $1$ or $2$.
Let's define the ternary XOR operation $\odot$ of two ternary numbers $a$ and $b$ (both of length $n$) as a number $c = a \odot b$ of length $n$, where $c_i = (a_i + b_i) \% 3$ (where $\%$ is modulo operation). In other words, add the corresponding digits and take the remainders of the sums when divided by $3$. For example, $10222 \odot 11021 = 21210$.
Your task is to find such ternary numbers $a$ and $b$ both of length $n$ and both without leading zeros that $a \odot b = x$ and $max(a, b)$ is the minimum possible.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 5 \cdot 10^4$) — the length of $x$. The second line of the test case contains ternary number $x$ consisting of $n$ digits $0, 1$ or $2$. It is guaranteed that the first digit of $x$ is $2$. It is guaranteed that the sum of $n$ over all test cases does not exceed $5 \cdot 10^4$ ($\sum n \le 5 \cdot 10^4$).
-----Output-----
For each test case, print the answer — two ternary integers $a$ and $b$ both of length $n$ and both without leading zeros such that $a \odot b = x$ and $max(a, b)$ is the minimum possible. If there are several answers, you can print any.
-----Example-----
Input
4
5
22222
5
21211
1
2
9
220222021
Output
11111
11111
11000
10211
1
1
110111011
110111010
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for _ in range(int(input())):
n=int(input())
s=input()
a=""
b=""
flag=1
for i in s:
if flag:
if i=="2":
a+="1"
b+="1"
elif i=="1":
a+="1"
b+="0"
flag=0
else:
a+="0"
b+="0"
else:
if i=="2":
a+="0"
b+="2"
elif i=="1":
a+="0"
b+="1"
flag=0
else:
a+="0"
b+="0"
print(a)
print(b)
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n5\n22222\n5\n21211\n1\n2\n9\n220222021\n",
"output": "11111\n11111\n11000\n10211\n1\n1\n110111011\n110111010\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1328/C"
} | vfc_7126 |
apps | verifiable_code | 2396 | Solve the following coding problem using the programming language python:
You are given a string $s[1 \dots n]$ consisting of lowercase Latin letters. It is guaranteed that $n = 2^k$ for some integer $k \ge 0$.
The string $s[1 \dots n]$ is called $c$-good if at least one of the following three conditions is satisfied: The length of $s$ is $1$, and it consists of the character $c$ (i.e. $s_1=c$); The length of $s$ is greater than $1$, the first half of the string consists of only the character $c$ (i.e. $s_1=s_2=\dots=s_{\frac{n}{2}}=c$) and the second half of the string (i.e. the string $s_{\frac{n}{2} + 1}s_{\frac{n}{2} + 2} \dots s_n$) is a $(c+1)$-good string; The length of $s$ is greater than $1$, the second half of the string consists of only the character $c$ (i.e. $s_{\frac{n}{2} + 1}=s_{\frac{n}{2} + 2}=\dots=s_n=c$) and the first half of the string (i.e. the string $s_1s_2 \dots s_{\frac{n}{2}}$) is a $(c+1)$-good string.
For example: "aabc" is 'a'-good, "ffgheeee" is 'e'-good.
In one move, you can choose one index $i$ from $1$ to $n$ and replace $s_i$ with any lowercase Latin letter (any character from 'a' to 'z').
Your task is to find the minimum number of moves required to obtain an 'a'-good string from $s$ (i.e. $c$-good string for $c=$ 'a'). It is guaranteed that the answer always exists.
You have to answer $t$ independent test cases.
Another example of an 'a'-good string is as follows. Consider the string $s = $"cdbbaaaa". It is an 'a'-good string, because: the second half of the string ("aaaa") consists of only the character 'a'; the first half of the string ("cdbb") is 'b'-good string, because: the second half of the string ("bb") consists of only the character 'b'; the first half of the string ("cd") is 'c'-good string, because: the first half of the string ("c") consists of only the character 'c'; the second half of the string ("d") is 'd'-good string.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ($1 \le n \le 131~072$) — the length of $s$. It is guaranteed that $n = 2^k$ for some integer $k \ge 0$. The second line of the test case contains the string $s$ consisting of $n$ lowercase Latin letters.
It is guaranteed that the sum of $n$ does not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$).
-----Output-----
For each test case, print the answer — the minimum number of moves required to obtain an 'a'-good string from $s$ (i.e. $c$-good string with $c =$ 'a'). It is guaranteed that the answer exists.
-----Example-----
Input
6
8
bbdcaaaa
8
asdfghjk
8
ceaaaabb
8
bbaaddcc
1
z
2
ac
Output
0
7
4
5
1
1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# coding: utf-8
# Your code here!
def solve(s, c):
if(len(s)==1):
if s[0]==c:
return 0
else:
return 1
ans1 = sum([i!=c for i in s[:len(s)//2]]) + solve(s[len(s)//2:],chr(ord(c)+1))
ans2 = sum([i!=c for i in s[len(s)//2:]]) + solve(s[:len(s)//2],chr(ord(c)+1))
return min(ans1, ans2)
for _ in range(int(input())):
input()
print(solve(input(),'a'))
``` | {
"language": "python",
"test_cases": [
{
"input": "6\n8\nbbdcaaaa\n8\nasdfghjk\n8\nceaaaabb\n8\nbbaaddcc\n1\nz\n2\nac\n",
"output": "0\n7\n4\n5\n1\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1385/D"
} | vfc_7130 |
apps | verifiable_code | 2397 | Solve the following coding problem using the programming language python:
Consider all binary strings of length $m$ ($1 \le m \le 60$). A binary string is a string that consists of the characters 0 and 1 only. For example, 0110 is a binary string, and 012aba is not. Obviously, there are exactly $2^m$ such strings in total.
The string $s$ is lexicographically smaller than the string $t$ (both have the same length $m$) if in the first position $i$ from the left in which they differ, we have $s[i] < t[i]$. This is exactly the way strings are compared in dictionaries and in most modern programming languages when comparing them in a standard way. For example, the string 01011 is lexicographically smaller than the string 01100, because the first two characters are the same, and the third character in the first string is less than that in the second.
We remove from this set $n$ ($1 \le n \le \min(2^m-1, 100)$) distinct binary strings $a_1, a_2, \ldots, a_n$, each of length $m$. Thus, the set will have $k=2^m-n$ strings. Sort all strings of the resulting set in lexicographical ascending order (as in the dictionary).
We number all the strings after sorting from $0$ to $k-1$. Print the string whose index is $\lfloor \frac{k-1}{2} \rfloor$ (such an element is called median), where $\lfloor x \rfloor$ is the rounding of the number down to the nearest integer.
For example, if $n=3$, $m=3$ and $a=[$010, 111, 001$]$, then after removing the strings $a_i$ and sorting, the result will take the form: $[$000, 011, 100, 101, 110$]$. Thus, the desired median is 100.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then, $t$ test cases follow.
The first line of each test case contains integers $n$ ($1 \le n \le \min(2^m-1, 100)$) and $m$ ($1 \le m \le 60$), where $n$ is the number of strings to remove, and $m$ is the length of binary strings. The next $n$ lines contain $a_1, a_2, \ldots, a_n$ — distinct binary strings of length $m$.
The total length of all given binary strings in all test cases in one test does not exceed $10^5$.
-----Output-----
Print $t$ answers to the test cases. For each test case, print a string of length $m$ — the median of the sorted sequence of remaining strings in the corresponding test case.
-----Example-----
Input
5
3 3
010
001
111
4 3
000
111
100
011
1 1
1
1 1
0
3 2
00
01
10
Output
100
010
0
1
11
-----Note-----
The first test case is explained in the statement.
In the second test case, the result after removing strings and sorting is $[$001, 010, 101, 110$]$. Therefore, the desired median is 010.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def read_int():
return int(input())
def read_ints():
return list(map(int, input().split(' ')))
t = read_int()
for case_num in range(t):
n, m = read_ints()
a = []
for i in range(n):
a.append(int(input(), 2))
a.sort()
k = 2 ** m - n
ans = (k - 1) // 2
for ai in a:
if ai <= ans:
ans += 1
binary = '{:b}'.format(ans)
print(binary.rjust(m, '0'))
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n3 3\n010\n001\n111\n4 3\n000\n111\n100\n011\n1 1\n1\n1 1\n0\n3 2\n00\n01\n10\n",
"output": "100\n010\n0\n1\n11\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1360/H"
} | vfc_7134 |
apps | verifiable_code | 2399 | Solve the following coding problem using the programming language python:
You are given a graph consisting of $n$ vertices and $m$ edges. It is not guaranteed that the given graph is connected. Some edges are already directed and you can't change their direction. Other edges are undirected and you have to choose some direction for all these edges.
You have to direct undirected edges in such a way that the resulting graph is directed and acyclic (i.e. the graph with all edges directed and having no directed cycles). Note that you have to direct all undirected edges.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 2 \cdot 10^4$) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains two integers $n$ and $m$ ($2 \le n \le 2 \cdot 10^5$, $1 \le m \le min(2 \cdot 10^5, \frac{n(n-1)}{2})$) — the number of vertices and the number of edges in the graph, respectively.
The next $m$ lines describe edges of the graph. The $i$-th edge is described with three integers $t_i$, $x_i$ and $y_i$ ($t_i \in [0; 1]$, $1 \le x_i, y_i \le n$) — the type of the edge ($t_i = 0$ if the edge is undirected and $t_i = 1$ if the edge is directed) and vertices this edge connects (the undirected edge connects vertices $x_i$ and $y_i$ and directed edge is going from the vertex $x_i$ to the vertex $y_i$). It is guaranteed that the graph do not contain self-loops (i.e. edges from the vertex to itself) and multiple edges (i.e. for each pair ($x_i, y_i$) there are no other pairs ($x_i, y_i$) or ($y_i, x_i$)).
It is guaranteed that both sum $n$ and sum $m$ do not exceed $2 \cdot 10^5$ ($\sum n \le 2 \cdot 10^5$; $\sum m \le 2 \cdot 10^5$).
-----Output-----
For each test case print the answer — "NO" if it is impossible to direct undirected edges in such a way that the resulting graph is directed and acyclic, otherwise print "YES" on the first line and $m$ lines describing edges of the resulted directed acyclic graph (in any order). Note that you cannot change the direction of the already directed edges. If there are several answers, you can print any.
-----Example-----
Input
4
3 1
0 1 3
5 5
0 2 1
1 1 5
1 5 4
0 5 2
1 3 5
4 5
1 1 2
0 4 3
1 3 1
0 2 3
1 2 4
4 5
1 4 1
1 1 3
0 1 2
1 2 4
1 3 2
Output
YES
3 1
YES
2 1
1 5
5 4
2 5
3 5
YES
1 2
3 4
3 1
3 2
2 4
NO
-----Note-----
Explanation of the second test case of the example:
[Image]
Explanation of the third test case of the example:
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from sys import stdin, stdout
import functools
import sys,os,math
#sys.setrecursionlimit(10**6)
T = int(input())
for _ in range(T):
N, M = list(map(int, input().split()))
DS = [0] * (N + 1)
ES = []
g = [[] for _ in range(N + 1)]
for _ in range(M):
t, u, v = list(map(int, input().split()))
ES.append([t ,u ,v])
if t == 1:
DS[u] += 1
g[u].append(len(ES) - 1)
g[v].append(len(ES) - 1)
q = []
for u in range(1, N+1):
if DS[u] == 0:
q.append(u)
while len(q) > 0:
u = q.pop()
if DS[u] > 0:
continue
for e in g[u]:
t, u0, v0 = ES[e]
if t == 1:
if v0 == u:
DS[u0] -= 1
if DS[u0] == 0:
q.append(u0)
elif t == 0:
v = v0 if u0 == u else u0
ES[e] = [1, v, u]
md = max(DS)
if md > 0:
print("NO")
else:
print("YES")
for e in ES:
print(e[1], e[2])
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n3 1\n0 1 3\n5 5\n0 2 1\n1 1 5\n1 5 4\n0 5 2\n1 3 5\n4 5\n1 1 2\n0 4 3\n1 3 1\n0 2 3\n1 2 4\n4 5\n1 4 1\n1 1 3\n0 1 2\n1 2 4\n1 3 2\n",
"output": "YES\n3 1\nYES\n2 1\n1 5\n5 4\n2 5\n3 5\nYES\n1 2\n3 4\n3 1\n3 2\n2 4\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1385/E"
} | vfc_7142 |
apps | verifiable_code | 2400 | Solve the following coding problem using the programming language python:
The round carousel consists of $n$ figures of animals. Figures are numbered from $1$ to $n$ in order of the carousel moving. Thus, after the $n$-th figure the figure with the number $1$ follows. Each figure has its own type — the type of the animal corresponding to this figure (the horse, the tiger and so on). The type of animal of the $i$-th figure equals $t_i$. [Image] The example of the carousel for $n=9$ and $t=[5, 5, 1, 15, 1, 5, 5, 1, 1]$.
You want to color each figure in one of the colors. You think that it's boring if the carousel contains two different figures (with the distinct types of animals) going one right after another and colored in the same color.
Your task is to color the figures in such a way that the number of distinct colors used is the minimum possible and there are no figures of the different types going one right after another and colored in the same color. If you use exactly $k$ distinct colors, then the colors of figures should be denoted with integers from $1$ to $k$.
-----Input-----
The input contains one or more test cases.
The first line contains one integer $q$ ($1 \le q \le 10^4$) — the number of test cases in the test. Then $q$ test cases follow. One test case is given on two lines.
The first line of the test case contains one integer $n$ ($3 \le n \le 2 \cdot 10^5$) — the number of figures in the carousel. Figures are numbered from $1$ to $n$ in order of carousel moving. Assume that after the $n$-th figure the figure $1$ goes.
The second line of the test case contains $n$ integers $t_1, t_2, \dots, t_n$ ($1 \le t_i \le 2 \cdot 10^5$), where $t_i$ is the type of the animal of the $i$-th figure.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
Print $q$ answers, for each test case print two lines.
In the first line print one integer $k$ — the minimum possible number of distinct colors of figures.
In the second line print $n$ integers $c_1, c_2, \dots, c_n$ ($1 \le c_i \le k$), where $c_i$ is the color of the $i$-th figure. If there are several answers, you can print any.
-----Example-----
Input
4
5
1 2 1 2 2
6
1 2 2 1 2 2
5
1 2 1 2 3
3
10 10 10
Output
2
1 2 1 2 2
2
2 1 2 1 2 1
3
2 3 2 3 1
1
1 1 1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = lambda: sys.stdin.readline().rstrip()
T = int(input())
for _ in range(T):
N = int(input())
A = [int(a) for a in input().split()]
if max(A) == min(A):
print(1)
print(*([1] * N))
elif N % 2 == 0:
print(2)
print(*([1, 2] * (N // 2)))
else:
for i in range(N):
if A[i-1] == A[i]:
print(2)
print(*(([1, 2] * N)[:i][::-1] + ([1, 2] * N)[:N-i]))
break
else:
print(3)
print(*([3] + [1, 2] * (N // 2)))
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n5\n1 2 1 2 2\n6\n1 2 2 1 2 2\n5\n1 2 1 2 3\n3\n10 10 10\n",
"output": "2\n2 1 2 1 1 \n2\n1 2 1 2 1 2 \n3\n1 2 1 2 3\n1\n1 1 1 \n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1328/D"
} | vfc_7146 |
apps | verifiable_code | 4757 | Solve the following coding problem using the programming language python:
You are given four positive integers $n$, $m$, $a$, $b$ ($1 \le b \le n \le 50$; $1 \le a \le m \le 50$). Find any such rectangular matrix of size $n \times m$ that satisfies all of the following conditions:
each row of the matrix contains exactly $a$ ones; each column of the matrix contains exactly $b$ ones; all other elements are zeros.
If the desired matrix does not exist, indicate this.
For example, for $n=3$, $m=6$, $a=2$, $b=1$, there exists a matrix satisfying the conditions above:
$$ \begin{vmatrix} 0 & 1 & 0 & 0 & 0 & 1 \\ 1 & 0 & 0 & 1 & 0 & 0 \\ 0 & 0 & 1 & 0 & 1 & 0 \end{vmatrix} $$
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 1000$) — the number of test cases. Then $t$ test cases follow.
Each test case is described by four positive integers $n$, $m$, $a$, $b$ ($1 \le b \le n \le 50$; $1 \le a \le m \le 50$), where $n$ and $m$ are the sizes of the matrix, and $a$ and $b$ are the number of ones for rows and columns, respectively.
-----Output-----
For each test case print:
"YES" (without quotes) and the required matrix (if there are several answers, print any) if it exists, or "NO" (without quotes) if it does not exist.
To print the matrix $n \times m$, print $n$ rows, each of which consists of $m$ numbers $0$ or $1$ describing a row of the matrix. Numbers must be printed without spaces.
-----Example-----
Input
5
3 6 2 1
2 2 2 1
2 2 2 2
4 4 2 2
2 1 1 2
Output
YES
010001
100100
001010
NO
YES
11
11
YES
1100
1100
0011
0011
YES
1
1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for _ in range(int(input())):
n, m, a, b = list(map(int, input().split()))
if a * n != b * m:
print('NO')
else:
ar = []
for i in range(n):
ar.append([0] * m)
x, y = 0, a
for i in range(n):
if x < y:
for j in range(x, y):
ar[i][j] = 1
else:
for j in range(x, m):
ar[i][j] = 1
for j in range(y):
ar[i][j] = 1
x += a
y += a
x %= m
y %= m
print('YES')
for i in range(n):
print(''.join(map(str, ar[i])))
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n3 6 2 1\n2 2 2 1\n2 2 2 2\n4 4 2 2\n2 1 1 2\n",
"output": "YES\n110000\n001100\n000011\nNO\nYES\n11\n11\nYES\n1100\n0110\n0011\n1001\nYES\n1\n1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "introductory",
"problem_url": "https://codeforces.com/problemset/problem/1360/G"
} | vfc_9508 |
apps | verifiable_code | 0 | Solve the following coding problem using the programming language python:
An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code $091$), a colon (ASCII code $058$), some (possibly zero) vertical line characters (ASCII code $124$), another colon, and a closing bracket (ASCII code $093$). The length of the accordion is the number of characters in it.
For example, [::], [:||:] and [:|||:] are accordions having length $4$, $6$ and $7$. (:|:), {:||:}, [:], ]:||:[ are not accordions.
You are given a string $s$. You want to transform it into an accordion by removing some (possibly zero) characters from it. Note that you may not insert new characters or reorder existing ones. Is it possible to obtain an accordion by removing characters from $s$, and if so, what is the maximum possible length of the result?
-----Input-----
The only line contains one string $s$ ($1 \le |s| \le 500000$). It consists of lowercase Latin letters and characters [, ], : and |.
-----Output-----
If it is not possible to obtain an accordion by removing some characters from $s$, print $-1$. Otherwise print maximum possible length of the resulting accordion.
-----Examples-----
Input
|[a:b:|]
Output
4
Input
|]:[|:]
Output
-1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
n = len(s)
ind = -1
f = False
for i in range(n):
if s[i] == '[':
f = True
elif s[i] == ':':
if f:
ind = i
break
bind = -1
f = False
for i in range(n-1,-1,-1):
if s[i] == ']':
f = True
elif s[i] == ':':
if f:
bind = i
break
# print(ind,bind)
if ind == -1 or bind == -1:
print(-1)
elif ind >= bind:
print(-1)
else:
ans = 4
for i in range(ind+1,bind):
if s[i] == '|':
ans += 1
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "|[a:b:|]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "|]:[|:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":][:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":[]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[[:]]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[::]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "]:|:[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":::::]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::::]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::[]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[a|[::]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "dsfdsfds\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":[||]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":::]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[||]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":[[[:]]]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::]::[:]::[::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[:|:]\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "[::]aaaaaaaa\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "[[::]|]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "[::::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "][\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[||]][[]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "][k:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::|[]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "||||\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "||]ekq\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]:|||:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|||[|||:[m[[n[[[xuy|:[[[:|:[:k[qlihm:ty[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "aaaaa[[[[[:[[[[a]]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[hellocodeforces::]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "[::]lolxd\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "sasixyu:[[:||ld[:[dxoe\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[:|||:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "topkek[::]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "[[||]]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|[::||::]]a\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": ":]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]::]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "r|x\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":][:|||\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]]::[[]]::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]f:|efw][jz[|[[z][[g]i|[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]::[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|:[[][:cv|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":y]j]tz:e[p[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "||\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]|[hhf[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "abide\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|c[]][zx]|[[[[j[::nx[|[:ou[u]\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "|:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]:|:][:||:]\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "]:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "d[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "k::]k|iv|]|g[|r[q:|[:[r[cj]||mjm|[|[|[|:[\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": ":|f[|e]e:|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "][:|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|rh]|[|:[v|||||i\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "y:[|[]b[][ug|e[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[:::]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "[:]:[:]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "::]]:::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[:||:|]\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "d]k[[::[||[:tpoc[||[:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]||haha||[:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]||ahaha||[:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[][]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|]:::]]|:|||||]]]:|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "||:][:||\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|:][:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[:::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ss:]]n:w:kzxiwpdoce|d:]][:nmw|b:hs\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::][::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[:tk]v|hd:h:c[s\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "md:o:|r:[uuzcov]wy]|[:[imwc\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":::]w\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "wd[]jcq[[]f|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":aj::pxblo]]]:o|x|:|]y:wn]:[:v:m\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "oeq]pp|i:[tan|][:ncsp::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "m][js]x]a:l\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[asfd:khj]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":i:]f|cau\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ljjjsv:h|]o:]k\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "aaaa\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "qj|]gd:i:::[|ur[e[e:]ay::k:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "qod:|nw]sfr:g|::[]ajs:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]zpgjpy:]:sz|[miz\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]ty:|:cjk::c:[[]tm\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "umfqrr::m]w]g::a|]|::]duhhxmzqs:gbo]br|xz|[g][ou:v[e[u|:y[||k:|[zqd:p:wf:a:gb\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":j:]xp:pnyh\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]|[:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]h:y[u:bg\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":am:trjm|]e[[[vm[:|pv\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":[||||||]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|[:qw[|:yr]c:p][]|n:qql[ulp:ph:|||adcg\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": ":a::[vd|vwq|r:][]:|::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|v]efoi::b|ov]:]|||:vk[q]is|[]|ku|]||wk[[|[q::]g|\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "[w:||j:iiasd]gz||o:yw[::b::[[[m[oe[|oh]jh]:yjwa\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "||::k[is|m|]|::i\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "t]g]ney::]hca]:|]|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]g[:]|u[d]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[:[|][\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]g|||yoj[:[h]]yys]u:iz:|rn|[:oc:|:[a|gns:||:hkr[idkx|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":n:[mb|cb|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[e[]|s:ml:|q[gh[[:anpd[|::[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|f||]:ng[]j:]::gc\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[x|[:l::hc[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "em]]|:tu:cw::d:ralw|[]l:f::c\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|kjw:j:]y\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|[[fu:j\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":b]l]byp]avhswotk:f[r]:k:::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]c|z||]cya:|yny]]q|g]q::h:|ff]q|jx::]:|]c]:||::rfr]o|hbgtb\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|]j:k[su:b|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]]s:|f:ho::s]p:|]]]sd\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "okje|:e:ti]yl|[r[x]|gt]zgzz[:[]:u:i]:ctml[]w[u:f]]:ltc[n:[k:[g:wdh\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "a|xg]:mv]:[:::p\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "y|:]:j[|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":rr]a[m]g:[m[e::[f:my:[[::h:]:]q:h[tf[o]nj[j[c:\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "][:[:[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "aaa:|||:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "cyzha::al:zc:o]s\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::h]go]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "sa:|cas|[::oq[sn]m:::h]e]dbjh:lllafnt|xly[j]:r::euta|fs[hw[h[[[i\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "|:[]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "][reerf][ybn[g]|i:q:]:[|:]b:xt[\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "k[h]|a|t|m]mwba[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[||::]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "b\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|xm:f:b[[|:w]t[[[ht\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "qyx::ti]o]|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "vl::r]i|y:]pi:yicacsqm|:sy|pd:nwu::r|iib]goq\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "af:r:gett|]t:x:f|iqdo]bm]:[w::x|]:pe:[[\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "v[t:[q:tmrwta\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]:v[|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "cl|dyisv::|hn|:fgdm][z[e\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "w]]::|zc\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|trrxb|]|z:t]s|]v|ds]u:|c:z|f|m[]bowp\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":z]gr[|uvm|ngodriz]f[c]|lfxqg|p]bcoxrfv:k:r::[m|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]o[|]]|t::::]w]:[:|:ro|a::ged[slr:kug:::rww:ei:|m::ah|cwk[v\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "yx:tx::dqpl|:::]l|]j[y[t|d[:elr:m\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "d]sp]|d]::|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "q|dlfohjzs]:[jnuxy|[]||::]u[[j:\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "]s]:[co|]m:y:njby\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "fmnu|n:ynz:|::hk::|::]|]l::|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaaaaaaa[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "f|gzg::cl]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]x\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "tc|:]ekb:tu\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]ujn|]|]j|o|:q:|r:a:u:::sv:]ffrzo\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "tuyut]j:[u]|ft||:]houmvj[yh:[::f\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "n:]:][|gpxex|qw[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]gy]]fd|bd::ph::j[]]jc|eqn]|lj]:s|ew:c||:[gksv\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::p:oqv:|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "os::a]un:k||ri:n:d]:who|]urx:yat::]|lm:m]q]iua|:s[g::]|:\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "uy|dzq]dkobuo:c|]]c]j:|]wtssv:|:lkn][sb[dw::|m|z:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "euj|eip:[bgqn[bjmivsxd][j][[[]dsk:y\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]:||k:]sf::[::|yn]:xv]pg[|q[]:[wpv:|y\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "clpy::||:fs||[w]]::||\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "u:ft:]|c]:q\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "rr::m[]|:j:uq[:t|[:trxbtq:|hj[rf\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[h[|k|[hb|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|e|o:]g:[:w\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::]:asl:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "z:::e|r]j|n]|:f]]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":ml|r:qm|:n]b::|:]]trak:ku]:::k]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]zp\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|wu[ehma]]ced]d[f[m][]b]:|:|::|fbz\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "uyme:|oew||mvo[[|e]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|zh]|]dmg|]:rtj:r|]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "kj:t[|[|oph]qt:h[rq[[bu[|]m|:||[hvh[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":[p|vg:[|:nu[:olj::p[o[qr[ltui\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]|pv:|[|d]][:|ddhn::n|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "fud:e:zmci:uh]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "d:x|]:::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "lovs:iq:[][[k\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "xf::osgw:kmft:gvy:::]m\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|hb:qtxa:nx::wnhg]p\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]:]:fcl|]a::::[z|q[|jw\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "np|:]q:xlct[|]hw:tfd|ci:d\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "nl]nz:][tpm:ps[jfx|:tfzekk\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "e:n|al]:i|hss:c:|v|b[u]efg[]k][u||vv:ma:ytgw:fjv|ve\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "pw:m|qu:|[gb[:]liv:an:oj:cavwjk[dxr:|po:ny|hu:mawqxv::[::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|]:i:|[:[q|x|lmetc[|:[|c:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":z::vy[lcyjoq\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::]v]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":wr|ze]d:wt:]]|q:c[::sk:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]::|]:[|dob|]ke:ghk[::uxycp|:fh:pxewxaet[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "jf:]e:i:q]|w:nrk:hvpj|m]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "vhbato:s|:]vhm:o|n[hfj]pgp|bs]d|:cxv\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::b|zltkdkulzx[]ocfqcmu::r[::s\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]fq|m::|[zk][:|::hxy[u::zw|::n|a\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "b:|xjehu]ywpi:|][ye]:[:[:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "q:wdd::i:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "v::mp:l::[x]:w[[ehu\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "g]:kobbxo:[dy]:daz[[|eqe::|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "vz:naw[:d[][f[[wgzdki]|ct[::[yh|w|bgxd[x:q[[zm][i:r[r|[:a[][|yx][r|:\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "s::dul::i[mwln:it::[|g:eh:xs|ew[bp|g]ak|ems:|:gydoq:[dg:]]:qr|[:[p[:q:[i[:]:k\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": ":][]||[|:|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":n[]ncg\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "j:m::|:||]u:[v|z]]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]:svzta[|ey|s|oi[[gmy::ayi]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": ":[|]did:]p:[|::|olz[:albp[[k:|||\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|::|]:|]|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|q|x]zt:]:kw:cs|fn]]jadp|cq\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ka:|u:|omvu:scrjwzt|]e|[[|k:h:we]::ou:]bxq|][dv:\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "mas:]c]a::a:[g:tiejt[rvh:zz::qwufm[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":k:::g|y]b|c]qwva|::v\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "sn::zeno:[ft]l|y|m|[||bz\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "t:nwkx:wg:x|:vr]|uk[[|]x|:gz:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ym:dvmmajd:t]|[hqx]d:l[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::[da][ik]]v:i\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|yyu]:[lj|aa[]vfenav[:ji|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "gt:|]|k]:|[hikmw|hz|a[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "z:::]oqatxzhf:gdpr]:]:ls]art[zq\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":o:]]u:evfw::]:c::gdu[lus:ej:[|:ruam:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]::k]d|:hx[]pop][:::u[s:o[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::sry]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "y:]:[[i]iy:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "||j:]::x|:f:l\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]]:d\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "l]b:][::]]z|ysyifc[:s|ag[hngo|:x:rhqn|ru\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "::q:ghi]:y:gtl:o:|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|j::lq:ot[]]c[|]|y[bxxqgl[]]]l[g:[|dg::hl:c\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "yk:t:ez|b:i:ze:[mt[[[]ochz:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[iy]u|bdr\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|stnr|t:x:oa]|ov[v]::jv[]to:[\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "[a|u\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::|]]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "sv:sxjxf]|::]bij:]:okugd:]qlg::s:c[|:dk\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "pfk[w:ow[|zz:|e::|ovvy:|y:vndh:::i:d]|[[qyn:::[||::]i:|:|]abb:ut]dxva:]ppkymtk|wyg:divb:[[l:c[jy|\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": ":rv::::lybr:|e:e:|iqtzgd::xhw]l]]:[aqa]d]:my[]]uo:d::s[a[:[[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]|rhs:p]:z::t[|vfr]]iu[ktw]j||a[d::ttz|ez[[:::k\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "rw|oe]gq]mv:]]:]:cb:s:z|:]]:g:eri\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|][|]jknnx]f[w|n|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::]t:np]:n]|jkn]:jy:|:c:]]]t||k|sm::c\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|[u]]ncc::[e:|][]l[][]p:un[w:cr:fa]dnud[tx:gz||so|||]j[wpr]b:ik:ulm[nab::u:yoo\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "vu:]|ar|q|mwyl|]tr:qm:k:[|::jc]zzf\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "lvyn]zm:q:vcg[:]n]jzhmdi\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]:l:|]mm\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "z:qqh|]k\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]wsjx:p:hwk:ckjnb]js:w::|:|r:e]r|j]x\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]k:vkb:]]]|]ciljah:bc\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[qf:d]nvex|i|n|z[z]]gsw:pnnc:lw:bofpt\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]y:qc||tg|::y[::[[l]xceg:|j[edpf[j|:bmy:\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "rszfx:pf|h]:e:wi[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "r:::xez:y]nrt:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "d::fftr::u:kug][ea:tu:ari][\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "|bvff||:m]:|i|::p|[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "a:]a[:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]|]|]:::[]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":::[||]|[]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|:][::|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[||::||]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "]||:::]]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::i|hack|myself::[]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "m|:::|:z:n:]cepp\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::n::itzc:]:abfjlmlhubk[|::[hm:x[fg|b|:axss:r[c\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "c:m:xbw]m|[hm:oofub\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]wvihpdy::vn:]]:|hqiaigj[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "omi]cb:s]kxzrjhi]:o\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "o|utkq|:j:]w:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "abc\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "xil]x]:hhtlz|:k:t:[pdv|ne]jyy|:sbd::jt:::|jgau:|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]:|:]|]:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]]|[fxy\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "q:t:|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":cu:lrcc[a|mij][o]]:x:ej\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "sn:c:d]]|s]::e\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[gp[]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "||]tzs:|:]ta|jhvpdk\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":os|:hj:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[|h::]]]qqw:dpp::jrq:v:[:z:[b:\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": ":c]:k:ugqzk:z::[]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "gn]wmt]lck]::|yk]lbwbxw]:az:|:ln::|b\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":lmn:gs|muauf[[p]:xjoo:|x:lsdps:go[d|l|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "sw|]:|::x]ff\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "t:b:[d:vzei[||e|uo]]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":l:::ha]]:g||t:]:ky||dbl]:]:q:m||g:]ta\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::::[|:|::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]]|[k:f]||t]wg:b]]:[o[|e]hroomwxdph]|u]::[j[h:b|[mr:dn[|n[[yxoh:tf:[a[||[:::|dz\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "[p||yi::u:::r|m:[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":kew:u]blgozxp:::]a]tp|g\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "wsn]:ig::||:fc]v|t:yn:uaurphuj|]r|uut]:::]n]:e:pg]]]wb:]]:o||:d:p[::|:]g:k:wxcg|c[:k|w|||]mcy\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "]up::]dcte]|ldnz|t:|]|iao:r:|v]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":[nt]|::q:ant|xijg\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "r]:kxu[][qe[:y:x\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":z]|[[w]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "og|:]vxfpmq]]ax]zvx:::hm:htnicv|:hs:]ptpc[j|t]d\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]g]sl:pqsqy:b::]rj:jl]]|n:y]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ejwmbu:fqkp]eb:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "xq]|mnn:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "gsl:]o:|f[e][wxmg[nlbn[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "dt:]y:jta:zu]dwxq|ki\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "zr:s]ocaf:|ruqd:::|lbek[:y[gb::k|y:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "n:]m]e|]:wr:iny:s]or]o:o]|:]]w|g]pp|ff\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::y:qjf:am]]]n]xrghkm|::|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":||l]::||:son|::]pq|]]w|:y|]n:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]j]pons\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "qks]b]wtqjih:d]]jjz:|]:|i:[]b::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "l:vw|v|s|:ei[]jc\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "jyflberp:et]q:x]:n|ww:f:d||c||:aq|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":s]::]p|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":w:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|i|:]:p\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "t]c:[[qt]t::v:x:|[::vaiejt|h\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":eiiup]tldk\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "v:j]pajb\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":x|b:i[d]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[d:eest:t|w|cy\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":ff[::[|lsfp|k]a[x:f\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "bk[kl:|tybma:vb::k:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[:pu::[dgl[z[g||e:t:e:o|:mhxn\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":jg|ift[mp|[:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "x::vv|d|knrx::[h:]hi[]co:ukn[[|[|:ezb\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":c:ojn[[|[p]lr\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|fu]s:]:uvra:x:wu|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]u]gam|y:hdql]x][ap[hae[lb[bi[czzd:fmdho\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "hdc:ytu|b]]:t:qms|gkwc:zf|:[kf\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]pmz[x:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ty||gbbe:fnga::]|m]z:][c:a[:|ijl:orl::b[t\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "f]mbz]mvz[[sb:j:qi[hhp:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|ryv:[c:::[t:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "yi|ycel:]]]iybr|spac[]:k\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "j::]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "gugw|:q\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":uve:jp|n|:]]:g::]:ciygwdj::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "khr:vri]n]m|]vn:rn\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "m::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::[[l|[nv]q\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ezz]:||sdv]:ucb[:[|oh|bm::::cgzl\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ek|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":p|:rpv::r:h|]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "kfcw::]]::f]mx]ecmc|:o:]||k:]jghys|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "c[:mke:::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "gofpok]]]w|[][v:h[ya|:ocm|q:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "az:]:d]|:|:|o|:::::|j[q]]tid|pb]nxi:c|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|:a:ypw|v:jovg[u:hb\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]|m|:|:w:|k|bi:ex]o]][mtz|ciy[]u[|[|][]o]lmy::|sde]sl|:|:dufv:le\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "]fv:w::mfi:::q]::[|d]dao::|i]|cnt[u]:\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "g|t:]l]w]]]x|q]jf[[[div::it:t\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "cbk]i::bk|mo:][[|]]x\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "fpxbk::se|fz:z:t:|]p]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[v:vv[ds|pz|:|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "am|::s|q|]x\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":fiv|qz|xl::mjbt][i\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::|o::r[x|o][lmt[wo\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "t:]iu:fo:e:w:]okrh][[vu|de]:::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "d:s||||z:sp|:oq[iq[rx|uj[n]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|]ezv:szl]pg|:||ao\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|jq]mf\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "z::[:rm|t:l::yotu]a|se[]:::y::[t\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "|]bg]]::vwre::fgz:dnf:cemye|tw|]:p]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "g:]c:[]f|yuz|r|:if:lf:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "kl:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|qe]|p|tcjp::m\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "||b]h::x|]p\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "j::r:my|qml\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "z::]|vy:||:hs::]vm\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "nf:ve:ri:riubcmfx]ib]j:qqa\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ne|s:jsa:pvl|sj[::]u]xbtr:|u:\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "|o]:s||:y::g:rans::d]]|p\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "krm|l::|]asp]r:b:::[]qbq::p|:mi[:yrrwoa[zt\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]mz|::|sxnk:::z|:bp]ajueqi|ogkql]z:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[:r:::bpz\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[fkvy|f:zd::k:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]u::t:b:sp|zlq]:h::|::ad|:q]f::]::n]m:::::[el|]kb][|dcdtfqs|]o:[:af::l:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::]nd[[|][zac|x[|::l\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]|agd:[|]dds|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]::m:::::b:q[]tz\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "lsvs]qe]|ao]nzqojo::r]nl:w:gu\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "a[|]z|ec[e:l[i:yf[[:se:yy|i[toc|:[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|][x]:rl::rl[f::l:::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "w:c:foghy:n:|]:b::ud|rs[][ua:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "kr|z:bd:h:]oa:y:|t]:vsx|]uo:|||\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":o:r\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "bx]y:xwo:::|]i:lz:]:pyp|sm:|]s\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "v][][f[f]y[kvlewloh|tdg:a|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "da:z::::f:|:oj]|t:p]:]yxnlnyk:[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":goep]s:]nwm]:qt::r|::x\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[cm|nu:k]f]:qkjz|[k|b:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]]:o::|:hj||:k]g:pgtq:eooo:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "tx::k]:f]pf|x:a:n:w:h]:youw:fajc:vcmi|dx\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "kmfk:teu[|dh]nvwx|]:mg::[d::uco:l[nqp\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "oh[i]fz[][:np:ea[y\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "jie::q]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "w|exua:x:mgr[::zt\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|a:xqjra|]tyl:wpk|nav[:u:[nq\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":l::f:u]wmt:[rqjb|m::][[:[opi\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": ":|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|p\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "sqsmoyj:l:|nze|:|r]qb::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":z]:|znp::as:n:bk|:qsu:wm|[wm[hkh:ju[:y|::|||je|wyu[hi\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":rd\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "w:s:yg]::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "w:]ca|i|ot\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "jb[n]:g[::s[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|]aw[id:s]k:y|b\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[njo::|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]]:u|::m::huhe:s::[ubrq::wa]ttp][]hwik\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "]amqhe::r:xvu:i]|:o]j|gkf:hgf]wah\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":|[m:::[u::r[c\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ri]qag:luidt:w]:g|j|hjua:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "c\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]m::i:::n|ga]m|ai|kc||]:|x|tjjmr:f\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "s|:[|j|[oouk:::h:|[x[:w|l:[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "vv:::[|f:y:|ke::vz:[:y[an|[b:::r:mdzl|:j:h]|s|ldmex\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "v:bkn:dwa[]::cv\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "o:y|:b|:|::]f:yyqg:oy]ezc:ggv::j:iyj:bqa]:|]r:k[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "u:g:gt]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "qgb:ym:]z|og]|:hu\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":[[|j]|yqdc[[f|]yv:thdmaw\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "n:yq:[|w|t[st:fg]d:uv[[bw:wgpy[:gnri:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "kisy:s:vg:yc]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "w:l[|:|tggqs\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":o:y||f[[no]:a:ge|[v|:gw|f:u[[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "g|]uj\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "pm]e:h:|j]dts]][sl[ekt]xt|zmx:k::x:d[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]twgo[mu:xf:[||e|:l|a|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "h:q::|zyh:b:]hpv[yf]pp|v]:y:j\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]::[u:[w|v|:qu[[[n:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "p]j:]n:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "wa\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "lu|v|fs:gow]:ct[ppm]pii::[z|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":e]h:]]::|]::]j|[s]]:[my::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[x:[r:b[|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":[sy[b|[|]]|]n|a[]tpa:::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ntp]y|w:]v]|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "z]w:dc[dq][[]l[|||p]]ealr[m[evn:o\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "hxl:|c|]omqt:jeey|kjyz:nphi::[v[c[::dunu]lf\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "]pbs|::g:tvu]|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "r::t:|:oezsfj:|]sjn]k|][][]t\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "t:::c:oyh:]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|d]|v\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "p|:[w|[t]||]|[y|x|as:q|o|zbn|zkyr|q:|eu[ll::mq:[j\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "d]w|g:bt:k:]tzzija[]:t\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":::drl:|fv::rn:q[]nq\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "y|::f:]]:p\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "u:ypnp:a::h:yqtome|kjsa:]|:rsotcg:]xcq[vvx|]]e\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::l:g\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "wl\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":r:]z:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "e|v|gh:::d]|d|]d:fs]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":l|kj|:sli::r:]g:yt|]:h[:::tl|hb:r\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "n:::[::[gwy\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::qa|v]|m|::|[nu]:||:fy::[p:af:e:qj|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "f|c\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "qq:|:f|o:g:ra[||]q\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "l[b:|[toa[g]qn\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "p:]dr]kt]t:]f:f|::s]ic]mzz:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "jp::l:[pyv]t:a][]::j[k:dmdc|:e]bjzp|pl[:[[::f|jo:nzu:pu|ndvpte:||\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": ":wt:nt|la:p|]:k[acxydv[][]|]e::|v|i:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]|[|zja::|g|]d:t::gawk|j|rfcada|qfkg:hi\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "][mm:mqraj:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]|l:dgb::::]:]wrt\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::k:c:tjg|h]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "vpl:::]owzt[:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "djt:::bfkl:q:ls::[]kfgpgit[k[|c:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "r::uh]][j]bfqsn[:[|s|:kqz:|p[bl::x|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "y:::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]lx:rjzff\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ptbb|]d\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "b|::b:g]]||:]nm[yrpf:t][]tzjy|:xm:q:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]::::uk:l:l:cl|]|:mbmqn\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":x::]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]uwfhq[uz[y::fi[:[egg:p\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "aa|:]w:lzf:zgw]:]|:ek|bq||d]h:]aq:n:o:]s]m]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|::]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "pky::t]zyx:||stu]tjt|:|v:[axhm[:ny|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "ld]]ngmi:c|tqo:v:]|]h:l\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[|::[aqj]]cz:l[||::\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "]d]ph:pm]||ytyw:[t[|wgx:tbagh:v[l:kpsuo|pcp\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "do]|]c[]ad|[adzbqjz]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]qrt:]no]|::][]d:p]:iwl::[ud[|s:r\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "mg|[]:[kla[[a|[z\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|:g[jv]ep]ln:|xnbaf\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "eeps]|rizigx:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::j]]]t|s:j]:bdzikd|zi|[kx]][:[lw:||mdnlw\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "zuf::z::w]pkf]fu]vz\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "icpw::k:x:wu|t:kq:ln]:|bdhiwu\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":[zie]|avb[qvl\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "fur|z][[][w:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::cy::::iry]|m:coi[]o|[bi:z[:s:p[:gcwh::::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]jpb::]|[ifu|yb]::l:|kt\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "b][[[hk[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|x:]::ultgj|e:t:]z\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "fh]]||:medq:]:|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|:zwi|i:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::dd:qj[g|s[:::]yemb]lo::\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "]:p]b|s]e\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "fa:]|:qzhby:l]wazenq]de|x::::td[]|:s\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "m:wpuz:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "dwx::::g:pi|r|bf[fxtvwk|z]|x|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "pcn|]t|]|y:rl]]:|u|y]y:h:g|x\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "hfdm]]w:ldlrp|t:|:wje::]fw|k:|[snyj\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "e|:b]][]u|cv[rpypk:g[:gb:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|zb|nd:|v\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "fuip:pvl:c[]::t::[x::f|f:urz\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "lr]b:]:]:|]|x|yiac\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]:]ty]l|c]]rkk\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "g]:c]etg\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "icx:q:]:|k|a]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]:|j|ehb]d|kqro|gdc:f:jbc|||v:gocskgf:|a::kmhv:ffwu:|qo:]v:y:igkm]:i|v|i|on\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "xx:|o[vu]yp[]ew[l|::::x[t::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[[[[[:|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "rmcq]w[wu\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "k|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "c:hn:|:|qiyse:o::[pp]fn:b\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|]l|gj]:p:u[]hv:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "r:xa::::fc:|]v|n|:axl\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "[]|ccgd:mn|:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":[::]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "]lj]vz:::y:::t]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]:un]v]]]cuy:w[|vms]hbnh]z[y:eru|el[[::iw[f[[:r:[w[][fezx\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": ":e:vvq:]u]]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "s\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":e||:|::[|:[|l\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "f]|g:lxm]:|[[:[:whcklc|cdan|[|oi[me[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "::ew:]]::d[][::c:[:ox:jv::b:b:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]|tue][rs]|x::u|]t:t:|vo|[ax[:|yomhn::bne\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "z\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "i::fd\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":sv:iro|]:zfvpwa:|ug]||v:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":]:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "n|]:w:bl|:j]:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "z]]]r]goiqy|x]h:|s]:tof|tm|rdd::x:]l:hg:gt::]|mru]tn|:h|\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "oenfnemfddbhhmig]gcd:]:mnnbj::f|ichec:|dkfnjbfjkdgoge]lfihgd[hooegj||g|gc]omkbggn:in::[dim[oie:nbkk]lfkddm:]cmjkf\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "[lqd]v::|e\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "][i::[][gq:::|:g|n:gt:\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "::]z]:|:x|:b:|[][w||]j[|oxjf[oo::urc]\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "]w:q]a]n:p:hb:rt:|pqe|]ze:]z:::b]::c[::jj[r::dw|kbe\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "bb:]ranrc:s:qmrcw:atzl:]im|eg:du::j::::b|]]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":[:]::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "u|::kepn]pr]a\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "n|:f||f:|xabqx]zj:nd|]vl\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "pwnseq[::[ajk]y:e:\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "aeo:wg|t:]s|:][[f]iczvk:boe||plg:::::::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "a]::]:nk]:cppyut]wb[g]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|g|jwpdzh:s:]::qp|r\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "yj|:du|mg:c]jn\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":||:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "]a]:pt]]iid:g:]:rfl\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "t::u]|]::]:]d:]|wf|r:|:[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|a|:r:]]:m]:|a\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "w::||[\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "o|:]]|d:y:x|jmvonbz:|:|]icol\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":[]f:\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "|:[]a\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":::]|||[:::\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "aa::]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "||::]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "||:]\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": ":||||||:]\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1101/B"
} | vfc_9754 |
apps | verifiable_code | 1 | Solve the following coding problem using the programming language python:
Anton has the integer x. He is interested what positive integer, which doesn't exceed x, has the maximum sum of digits.
Your task is to help Anton and to find the integer that interests him. If there are several such integers, determine the biggest of them.
-----Input-----
The first line contains the positive integer x (1 ≤ x ≤ 10^18) — the integer which Anton has.
-----Output-----
Print the positive integer which doesn't exceed x and has the maximum sum of digits. If there are several such integers, print the biggest of them. Printed integer must not contain leading zeros.
-----Examples-----
Input
100
Output
99
Input
48
Output
48
Input
521
Output
499
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
num = list(map(int, input()))
best = num[:]
for i in range(-1, -len(num) - 1, -1):
if num[i] == 0:
continue
num[i] -= 1
for j in range(i + 1, 0):
num[j] = 9
if sum(num) > sum(best):
best = num[:]
s = ''.join(map(str, best)).lstrip('0')
print(s)
``` | {
"language": "python",
"test_cases": [
{
"input": "100\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "48\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"input": "521\n",
"output": "499\n",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "39188\n",
"output": "38999\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "59999154\n",
"output": "59998999\n",
"type": "stdin_stdout"
},
{
"input": "1000\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "10000\n",
"output": "9999\n",
"type": "stdin_stdout"
},
{
"input": "100000\n",
"output": "99999\n",
"type": "stdin_stdout"
},
{
"input": "1000000\n",
"output": "999999\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n",
"output": "9999999\n",
"type": "stdin_stdout"
},
{
"input": "100000000\n",
"output": "99999999\n",
"type": "stdin_stdout"
},
{
"input": "1000000000\n",
"output": "999999999\n",
"type": "stdin_stdout"
},
{
"input": "10000000000\n",
"output": "9999999999\n",
"type": "stdin_stdout"
},
{
"input": "100000000000\n",
"output": "99999999999\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000\n",
"output": "999999999999\n",
"type": "stdin_stdout"
},
{
"input": "10000000000000\n",
"output": "9999999999999\n",
"type": "stdin_stdout"
},
{
"input": "100000000000000\n",
"output": "99999999999999\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000\n",
"output": "999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "10000000000000000\n",
"output": "9999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "100000000000000000\n",
"output": "99999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000\n",
"output": "999999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "999999990\n",
"output": "999999989\n",
"type": "stdin_stdout"
},
{
"input": "666666899789879\n",
"output": "599999999999999\n",
"type": "stdin_stdout"
},
{
"input": "65499992294999000\n",
"output": "59999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "9879100000000099\n",
"output": "8999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "9991919190909919\n",
"output": "9989999999999999\n",
"type": "stdin_stdout"
},
{
"input": "978916546899999999\n",
"output": "899999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "5684945999999999\n",
"output": "4999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999\n",
"output": "999999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "999999999999990999\n",
"output": "999999999999989999\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999990\n",
"output": "999999999999999989\n",
"type": "stdin_stdout"
},
{
"input": "909999999999999999\n",
"output": "899999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "199999999999999999\n",
"output": "199999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "299999999999999999\n",
"output": "299999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "999999990009999999\n",
"output": "999999989999999999\n",
"type": "stdin_stdout"
},
{
"input": "999000000001999999\n",
"output": "998999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "999999999991\n",
"output": "999999999989\n",
"type": "stdin_stdout"
},
{
"input": "999999999992\n",
"output": "999999999989\n",
"type": "stdin_stdout"
},
{
"input": "79320\n",
"output": "78999\n",
"type": "stdin_stdout"
},
{
"input": "99004\n",
"output": "98999\n",
"type": "stdin_stdout"
},
{
"input": "99088\n",
"output": "98999\n",
"type": "stdin_stdout"
},
{
"input": "99737\n",
"output": "98999\n",
"type": "stdin_stdout"
},
{
"input": "29652\n",
"output": "28999\n",
"type": "stdin_stdout"
},
{
"input": "59195\n",
"output": "58999\n",
"type": "stdin_stdout"
},
{
"input": "19930\n",
"output": "19899\n",
"type": "stdin_stdout"
},
{
"input": "49533\n",
"output": "48999\n",
"type": "stdin_stdout"
},
{
"input": "69291\n",
"output": "68999\n",
"type": "stdin_stdout"
},
{
"input": "59452\n",
"output": "58999\n",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "110\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "111\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "119\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "118\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "1100\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1199\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1109\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1190\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "12\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "120\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "121\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "129\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "128\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "1200\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1299\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1209\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1290\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "13\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "130\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "131\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "139\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "138\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "1300\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1399\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1309\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1390\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "14\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "140\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "141\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "149\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "148\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "1400\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1499\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1409\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1490\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "15\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "150\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "151\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "159\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "158\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "1500\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1599\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1509\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1590\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "16\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "160\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "161\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "169\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "168\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "1600\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1699\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1609\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1690\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "17\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "170\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "171\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "179\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "178\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "1700\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1799\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1709\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1790\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "18\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "180\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "181\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "189\n",
"output": "189\n",
"type": "stdin_stdout"
},
{
"input": "188\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "1800\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1899\n",
"output": "1899\n",
"type": "stdin_stdout"
},
{
"input": "1809\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1890\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "19\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "190\n",
"output": "189\n",
"type": "stdin_stdout"
},
{
"input": "191\n",
"output": "189\n",
"type": "stdin_stdout"
},
{
"input": "199\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "198\n",
"output": "198\n",
"type": "stdin_stdout"
},
{
"input": "1900\n",
"output": "1899\n",
"type": "stdin_stdout"
},
{
"input": "1999\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "1909\n",
"output": "1899\n",
"type": "stdin_stdout"
},
{
"input": "1990\n",
"output": "1989\n",
"type": "stdin_stdout"
},
{
"input": "20\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "200\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "201\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "209\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "208\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "2000\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2099\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2009\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2090\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "210\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "211\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "219\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "218\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "2100\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2199\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2109\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2190\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "22\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "220\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "221\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "229\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "228\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "2200\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2299\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2209\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2290\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "23\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "230\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "231\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "239\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "238\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "2300\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2399\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2309\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2390\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "24\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "240\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "241\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "249\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "248\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "2400\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2499\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2409\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2490\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "25\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "250\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "251\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "259\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "258\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "2500\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2599\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2509\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2590\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "26\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "260\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "261\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "269\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "268\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "2600\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2699\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2609\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2690\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "27\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "270\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "271\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "279\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "278\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "2700\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2799\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2709\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2790\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "28\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "280\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "281\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "289\n",
"output": "289\n",
"type": "stdin_stdout"
},
{
"input": "288\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "2800\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2899\n",
"output": "2899\n",
"type": "stdin_stdout"
},
{
"input": "2809\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "2890\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "29\n",
"output": "29\n",
"type": "stdin_stdout"
},
{
"input": "290\n",
"output": "289\n",
"type": "stdin_stdout"
},
{
"input": "291\n",
"output": "289\n",
"type": "stdin_stdout"
},
{
"input": "299\n",
"output": "299\n",
"type": "stdin_stdout"
},
{
"input": "298\n",
"output": "298\n",
"type": "stdin_stdout"
},
{
"input": "2900\n",
"output": "2899\n",
"type": "stdin_stdout"
},
{
"input": "2999\n",
"output": "2999\n",
"type": "stdin_stdout"
},
{
"input": "2909\n",
"output": "2899\n",
"type": "stdin_stdout"
},
{
"input": "2990\n",
"output": "2989\n",
"type": "stdin_stdout"
},
{
"input": "999\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "999\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "890\n",
"output": "889\n",
"type": "stdin_stdout"
},
{
"input": "995\n",
"output": "989\n",
"type": "stdin_stdout"
},
{
"input": "999\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "989\n",
"output": "989\n",
"type": "stdin_stdout"
},
{
"input": "999\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "999\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "991\n",
"output": "989\n",
"type": "stdin_stdout"
},
{
"input": "999\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "9929\n",
"output": "9899\n",
"type": "stdin_stdout"
},
{
"input": "4999\n",
"output": "4999\n",
"type": "stdin_stdout"
},
{
"input": "9690\n",
"output": "8999\n",
"type": "stdin_stdout"
},
{
"input": "8990\n",
"output": "8989\n",
"type": "stdin_stdout"
},
{
"input": "9982\n",
"output": "9899\n",
"type": "stdin_stdout"
},
{
"input": "9999\n",
"output": "9999\n",
"type": "stdin_stdout"
},
{
"input": "1993\n",
"output": "1989\n",
"type": "stdin_stdout"
},
{
"input": "9367\n",
"output": "8999\n",
"type": "stdin_stdout"
},
{
"input": "8939\n",
"output": "8899\n",
"type": "stdin_stdout"
},
{
"input": "9899\n",
"output": "9899\n",
"type": "stdin_stdout"
},
{
"input": "99999\n",
"output": "99999\n",
"type": "stdin_stdout"
},
{
"input": "93929\n",
"output": "89999\n",
"type": "stdin_stdout"
},
{
"input": "99999\n",
"output": "99999\n",
"type": "stdin_stdout"
},
{
"input": "38579\n",
"output": "29999\n",
"type": "stdin_stdout"
},
{
"input": "79096\n",
"output": "78999\n",
"type": "stdin_stdout"
},
{
"input": "72694\n",
"output": "69999\n",
"type": "stdin_stdout"
},
{
"input": "99999\n",
"output": "99999\n",
"type": "stdin_stdout"
},
{
"input": "99999\n",
"output": "99999\n",
"type": "stdin_stdout"
},
{
"input": "99992\n",
"output": "99989\n",
"type": "stdin_stdout"
},
{
"input": "27998\n",
"output": "19999\n",
"type": "stdin_stdout"
},
{
"input": "460999\n",
"output": "399999\n",
"type": "stdin_stdout"
},
{
"input": "999999\n",
"output": "999999\n",
"type": "stdin_stdout"
},
{
"input": "999999\n",
"output": "999999\n",
"type": "stdin_stdout"
},
{
"input": "998999\n",
"output": "998999\n",
"type": "stdin_stdout"
},
{
"input": "999999\n",
"output": "999999\n",
"type": "stdin_stdout"
},
{
"input": "999929\n",
"output": "999899\n",
"type": "stdin_stdout"
},
{
"input": "999999\n",
"output": "999999\n",
"type": "stdin_stdout"
},
{
"input": "999999\n",
"output": "999999\n",
"type": "stdin_stdout"
},
{
"input": "979199\n",
"output": "899999\n",
"type": "stdin_stdout"
},
{
"input": "999999\n",
"output": "999999\n",
"type": "stdin_stdout"
},
{
"input": "9899999\n",
"output": "9899999\n",
"type": "stdin_stdout"
},
{
"input": "9699959\n",
"output": "8999999\n",
"type": "stdin_stdout"
},
{
"input": "9999999\n",
"output": "9999999\n",
"type": "stdin_stdout"
},
{
"input": "9997099\n",
"output": "9989999\n",
"type": "stdin_stdout"
},
{
"input": "8992091\n",
"output": "8989999\n",
"type": "stdin_stdout"
},
{
"input": "9599295\n",
"output": "8999999\n",
"type": "stdin_stdout"
},
{
"input": "2999902\n",
"output": "2999899\n",
"type": "stdin_stdout"
},
{
"input": "9999953\n",
"output": "9999899\n",
"type": "stdin_stdout"
},
{
"input": "9999999\n",
"output": "9999999\n",
"type": "stdin_stdout"
},
{
"input": "9590999\n",
"output": "8999999\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/770/B"
} | vfc_9758 |
apps | verifiable_code | 2 | Solve the following coding problem using the programming language python:
Apart from having lots of holidays throughout the year, residents of Berland also have whole lucky years. Year is considered lucky if it has no more than 1 non-zero digit in its number. So years 100, 40000, 5 are lucky and 12, 3001 and 12345 are not.
You are given current year in Berland. Your task is to find how long will residents of Berland wait till the next lucky year.
-----Input-----
The first line contains integer number n (1 ≤ n ≤ 10^9) — current year in Berland.
-----Output-----
Output amount of years from the current year to the next lucky one.
-----Examples-----
Input
4
Output
1
Input
201
Output
99
Input
4000
Output
1000
-----Note-----
In the first example next lucky year is 5. In the second one — 300. In the third — 5000.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
s = input()
n = len(s)
t = int(str(int(s[0]) + 1) + '0' * (n - 1))
print(t - int(s))
main()
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "201\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "4000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100000000\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "900000000\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "999999999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "9999999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100000001\n",
"output": "99999999\n",
"type": "stdin_stdout"
},
{
"input": "3660\n",
"output": "340\n",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "900000001\n",
"output": "99999999\n",
"type": "stdin_stdout"
},
{
"input": "62911\n",
"output": "7089\n",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "940302010\n",
"output": "59697990\n",
"type": "stdin_stdout"
},
{
"input": "91\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "101\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "1090\n",
"output": "910\n",
"type": "stdin_stdout"
},
{
"input": "987654321\n",
"output": "12345679\n",
"type": "stdin_stdout"
},
{
"input": "703450474\n",
"output": "96549526\n",
"type": "stdin_stdout"
},
{
"input": "1091\n",
"output": "909\n",
"type": "stdin_stdout"
},
{
"input": "89\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "109\n",
"output": "91\n",
"type": "stdin_stdout"
},
{
"input": "190\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "19\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "482\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "12\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "13\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "14\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "15\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "16\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "17\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "18\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "19\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "20\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "22\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "23\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "24\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "25\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "26\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "27\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "28\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "29\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "30\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "31\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "32\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "33\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "34\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "35\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "36\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "37\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "38\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "39\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "40\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "41\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "42\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "43\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "44\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "45\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "46\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "47\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "48\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "49\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "50\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "51\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "52\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "53\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "54\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "55\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "56\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "57\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "58\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "59\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "60\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "61\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "62\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "63\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "64\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "65\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "66\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "67\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "68\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "69\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "70\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "71\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "72\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "73\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "74\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "75\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "76\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "77\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "78\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "79\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "80\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "81\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "82\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "83\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "84\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "85\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "86\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "87\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "88\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "89\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "90\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "91\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "92\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "93\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "94\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "95\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "96\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "97\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "98\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "99\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "1000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "1000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "10000\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "10000\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "101\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "110\n",
"output": "90\n",
"type": "stdin_stdout"
},
{
"input": "1001\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1100\n",
"output": "900\n",
"type": "stdin_stdout"
},
{
"input": "1010\n",
"output": "990\n",
"type": "stdin_stdout"
},
{
"input": "10010\n",
"output": "9990\n",
"type": "stdin_stdout"
},
{
"input": "10100\n",
"output": "9900\n",
"type": "stdin_stdout"
},
{
"input": "102\n",
"output": "98\n",
"type": "stdin_stdout"
},
{
"input": "120\n",
"output": "80\n",
"type": "stdin_stdout"
},
{
"input": "1002\n",
"output": "998\n",
"type": "stdin_stdout"
},
{
"input": "1200\n",
"output": "800\n",
"type": "stdin_stdout"
},
{
"input": "1020\n",
"output": "980\n",
"type": "stdin_stdout"
},
{
"input": "10020\n",
"output": "9980\n",
"type": "stdin_stdout"
},
{
"input": "10200\n",
"output": "9800\n",
"type": "stdin_stdout"
},
{
"input": "108\n",
"output": "92\n",
"type": "stdin_stdout"
},
{
"input": "180\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "1008\n",
"output": "992\n",
"type": "stdin_stdout"
},
{
"input": "1800\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "1080\n",
"output": "920\n",
"type": "stdin_stdout"
},
{
"input": "10080\n",
"output": "9920\n",
"type": "stdin_stdout"
},
{
"input": "10800\n",
"output": "9200\n",
"type": "stdin_stdout"
},
{
"input": "109\n",
"output": "91\n",
"type": "stdin_stdout"
},
{
"input": "190\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1009\n",
"output": "991\n",
"type": "stdin_stdout"
},
{
"input": "1900\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1090\n",
"output": "910\n",
"type": "stdin_stdout"
},
{
"input": "10090\n",
"output": "9910\n",
"type": "stdin_stdout"
},
{
"input": "10900\n",
"output": "9100\n",
"type": "stdin_stdout"
},
{
"input": "200\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "200\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "2000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "2000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "2000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "20000\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "20000\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "201\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "210\n",
"output": "90\n",
"type": "stdin_stdout"
},
{
"input": "2001\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "2100\n",
"output": "900\n",
"type": "stdin_stdout"
},
{
"input": "2010\n",
"output": "990\n",
"type": "stdin_stdout"
},
{
"input": "20010\n",
"output": "9990\n",
"type": "stdin_stdout"
},
{
"input": "20100\n",
"output": "9900\n",
"type": "stdin_stdout"
},
{
"input": "202\n",
"output": "98\n",
"type": "stdin_stdout"
},
{
"input": "220\n",
"output": "80\n",
"type": "stdin_stdout"
},
{
"input": "2002\n",
"output": "998\n",
"type": "stdin_stdout"
},
{
"input": "2200\n",
"output": "800\n",
"type": "stdin_stdout"
},
{
"input": "2020\n",
"output": "980\n",
"type": "stdin_stdout"
},
{
"input": "20020\n",
"output": "9980\n",
"type": "stdin_stdout"
},
{
"input": "20200\n",
"output": "9800\n",
"type": "stdin_stdout"
},
{
"input": "208\n",
"output": "92\n",
"type": "stdin_stdout"
},
{
"input": "280\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "2008\n",
"output": "992\n",
"type": "stdin_stdout"
},
{
"input": "2800\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "2080\n",
"output": "920\n",
"type": "stdin_stdout"
},
{
"input": "20080\n",
"output": "9920\n",
"type": "stdin_stdout"
},
{
"input": "20800\n",
"output": "9200\n",
"type": "stdin_stdout"
},
{
"input": "209\n",
"output": "91\n",
"type": "stdin_stdout"
},
{
"input": "290\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "2009\n",
"output": "991\n",
"type": "stdin_stdout"
},
{
"input": "2900\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "2090\n",
"output": "910\n",
"type": "stdin_stdout"
},
{
"input": "20090\n",
"output": "9910\n",
"type": "stdin_stdout"
},
{
"input": "20900\n",
"output": "9100\n",
"type": "stdin_stdout"
},
{
"input": "800\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "800\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "8000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "8000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "8000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "80000\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "80000\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "801\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "810\n",
"output": "90\n",
"type": "stdin_stdout"
},
{
"input": "8001\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "8100\n",
"output": "900\n",
"type": "stdin_stdout"
},
{
"input": "8010\n",
"output": "990\n",
"type": "stdin_stdout"
},
{
"input": "80010\n",
"output": "9990\n",
"type": "stdin_stdout"
},
{
"input": "80100\n",
"output": "9900\n",
"type": "stdin_stdout"
},
{
"input": "802\n",
"output": "98\n",
"type": "stdin_stdout"
},
{
"input": "820\n",
"output": "80\n",
"type": "stdin_stdout"
},
{
"input": "8002\n",
"output": "998\n",
"type": "stdin_stdout"
},
{
"input": "8200\n",
"output": "800\n",
"type": "stdin_stdout"
},
{
"input": "8020\n",
"output": "980\n",
"type": "stdin_stdout"
},
{
"input": "80020\n",
"output": "9980\n",
"type": "stdin_stdout"
},
{
"input": "80200\n",
"output": "9800\n",
"type": "stdin_stdout"
},
{
"input": "808\n",
"output": "92\n",
"type": "stdin_stdout"
},
{
"input": "880\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "8008\n",
"output": "992\n",
"type": "stdin_stdout"
},
{
"input": "8800\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "8080\n",
"output": "920\n",
"type": "stdin_stdout"
},
{
"input": "80080\n",
"output": "9920\n",
"type": "stdin_stdout"
},
{
"input": "80800\n",
"output": "9200\n",
"type": "stdin_stdout"
},
{
"input": "809\n",
"output": "91\n",
"type": "stdin_stdout"
},
{
"input": "890\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "8009\n",
"output": "991\n",
"type": "stdin_stdout"
},
{
"input": "8900\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "8090\n",
"output": "910\n",
"type": "stdin_stdout"
},
{
"input": "80090\n",
"output": "9910\n",
"type": "stdin_stdout"
},
{
"input": "80900\n",
"output": "9100\n",
"type": "stdin_stdout"
},
{
"input": "900\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "900\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "9000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "9000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "9000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "90000\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "90000\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "901\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "910\n",
"output": "90\n",
"type": "stdin_stdout"
},
{
"input": "9001\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "9100\n",
"output": "900\n",
"type": "stdin_stdout"
},
{
"input": "9010\n",
"output": "990\n",
"type": "stdin_stdout"
},
{
"input": "90010\n",
"output": "9990\n",
"type": "stdin_stdout"
},
{
"input": "90100\n",
"output": "9900\n",
"type": "stdin_stdout"
},
{
"input": "902\n",
"output": "98\n",
"type": "stdin_stdout"
},
{
"input": "920\n",
"output": "80\n",
"type": "stdin_stdout"
},
{
"input": "9002\n",
"output": "998\n",
"type": "stdin_stdout"
},
{
"input": "9200\n",
"output": "800\n",
"type": "stdin_stdout"
},
{
"input": "9020\n",
"output": "980\n",
"type": "stdin_stdout"
},
{
"input": "90020\n",
"output": "9980\n",
"type": "stdin_stdout"
},
{
"input": "90200\n",
"output": "9800\n",
"type": "stdin_stdout"
},
{
"input": "908\n",
"output": "92\n",
"type": "stdin_stdout"
},
{
"input": "980\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "9008\n",
"output": "992\n",
"type": "stdin_stdout"
},
{
"input": "9800\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "9080\n",
"output": "920\n",
"type": "stdin_stdout"
},
{
"input": "90080\n",
"output": "9920\n",
"type": "stdin_stdout"
},
{
"input": "90800\n",
"output": "9200\n",
"type": "stdin_stdout"
},
{
"input": "909\n",
"output": "91\n",
"type": "stdin_stdout"
},
{
"input": "990\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "9009\n",
"output": "991\n",
"type": "stdin_stdout"
},
{
"input": "9900\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "9090\n",
"output": "910\n",
"type": "stdin_stdout"
},
{
"input": "90090\n",
"output": "9910\n",
"type": "stdin_stdout"
},
{
"input": "90900\n",
"output": "9100\n",
"type": "stdin_stdout"
},
{
"input": "92651241\n",
"output": "7348759\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/808/A"
} | vfc_9762 |
apps | verifiable_code | 3 | Solve the following coding problem using the programming language python:
You have a long fence which consists of $n$ sections. Unfortunately, it is not painted, so you decided to hire $q$ painters to paint it. $i$-th painter will paint all sections $x$ such that $l_i \le x \le r_i$.
Unfortunately, you are on a tight budget, so you may hire only $q - 2$ painters. Obviously, only painters you hire will do their work.
You want to maximize the number of painted sections if you choose $q - 2$ painters optimally. A section is considered painted if at least one painter paints it.
-----Input-----
The first line contains two integers $n$ and $q$ ($3 \le n, q \le 5000$) — the number of sections and the number of painters availible for hire, respectively.
Then $q$ lines follow, each describing one of the painters: $i$-th line contains two integers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$).
-----Output-----
Print one integer — maximum number of painted sections if you hire $q - 2$ painters.
-----Examples-----
Input
7 5
1 4
4 5
5 6
6 7
3 5
Output
7
Input
4 3
1 1
2 2
3 4
Output
2
Input
4 4
1 1
2 2
2 3
3 4
Output
3
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from collections import defaultdict as dd
import math
def nn():
return int(input())
def li():
return list(input())
def mi():
return list(map(int, input().split()))
def lm():
return list(map(int, input().split()))
n, q=mi()
ints=[]
for _ in range(q):
st, end=mi()
ints.append((st,end))
coverage=[10]+[0]*n
for st, end in ints:
for i in range(st,end+1):
coverage[i]+=1
total=-1
for val in coverage:
if not val==0:
total+=1
singlecount=0
doublecount=0
singles=[0]*(n+1)
#print(total)
doubles=[0]*(n+1)
for i in range(len(coverage)):
#print(i,singles)
if coverage[i]==1:
singlecount+=1
if coverage[i]==2:
doublecount+=1
singles[i]=singlecount
doubles[i]=doublecount
maxtotal=0
for i in range(len(ints)):
for j in range(i+1, len(ints)):
st1=min(ints[i][0],ints[j][0])
end1=min(ints[i][1],ints[j][1])
st2, end2=max(ints[i][0],ints[j][0]), max(ints[i][1],ints[j][1])
#assume st1<=st2
if end1<st2:
curtotal=total-(singles[end1]-singles[st1-1])-(singles[end2]-singles[st2-1])
elif end1<end2:
curtotal=total-(singles[st2-1]-singles[st1-1])-(doubles[end1]-doubles[st2-1])-(singles[end2]-singles[end1])
else:
curtotal=total-(singles[st2-1]-singles[st1-1])-(doubles[end2]-doubles[st2-1])-(singles[end1]-singles[end2])
maxtotal=max(maxtotal,curtotal)
print(maxtotal)
``` | {
"language": "python",
"test_cases": [
{
"input": "7 5\n1 4\n4 5\n5 6\n6 7\n3 5\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n1 1\n2 2\n3 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n1 1\n2 2\n2 3\n3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 3\n1 1\n2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6 3\n1 6\n1 3\n4 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 1\n2 3\n2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n1 3\n1 1\n2 2\n3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "233 3\n1 2\n2 3\n3 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n5 5\n1 3\n3 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n1 4\n1 1\n2 2\n3 3\n4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 5\n5 10\n2 8\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "8 4\n1 5\n1 5\n6 8\n6 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "5000 4\n1 100\n2 100\n1000 1010\n1009 1012\n",
"output": "111\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 3\n1 2\n2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 2\n2 4\n5 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "30 3\n27 27\n25 27\n15 17\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 10\n1 10\n2 9\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "100 5\n20 25\n17 21\n24 28\n1 2\n30 33\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n1 5\n2 6\n3 7\n4 8\n5 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n1 5\n1 1\n2 2\n3 3\n4 4\n5 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "12 6\n1 3\n4 6\n2 5\n7 9\n10 12\n8 11\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "889 3\n1 777\n555 777\n88 888\n",
"output": "801\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 5\n2 3\n4 10\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 2\n1 2\n3 10\n3 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n1 5\n2 5\n3 5\n4 5\n5 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1000 3\n1 1\n1 1\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 10\n1 5\n6 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n1 3\n2 3\n4 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5000 4\n1 1\n2 2\n3 5000\n3 5000\n",
"output": "4999\n",
"type": "stdin_stdout"
},
{
"input": "6 4\n1 6\n1 2\n3 4\n5 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5000 10\n4782 4804\n2909 3096\n3527 3650\n2076 2478\n3775 3877\n149 2710\n4394 4622\n3598 4420\n419 469\n3090 3341\n",
"output": "4114\n",
"type": "stdin_stdout"
},
{
"input": "20 3\n1 20\n1 10\n11 20\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 3\n2 3\n3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "30 4\n1 10\n12 13\n13 14\n20 30\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n1 4\n3 5\n4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n1 1\n2 2\n3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n4 4\n3 3\n2 5\n1 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n1 4\n1 3\n4 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "287 4\n98 203\n119 212\n227 245\n67 124\n",
"output": "146\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n3 4\n1 2\n3 3\n4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "19 4\n3 10\n4 11\n13 15\n15 17\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n4 5\n2 4\n5 5\n1 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "16 3\n7 10\n2 12\n4 14\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "9 5\n5 8\n2 4\n9 9\n6 7\n3 6\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "16 5\n3 9\n11 15\n1 5\n3 7\n8 10\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n9 10\n6 7\n8 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "41 3\n12 23\n21 37\n15 16\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 1\n1 1\n2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "50 4\n13 46\n11 39\n25 39\n2 11\n",
"output": "44\n",
"type": "stdin_stdout"
},
{
"input": "7 4\n5 6\n1 5\n4 5\n1 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "28 4\n4 24\n18 27\n4 13\n14 18\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "33 3\n21 31\n11 24\n19 25\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "48 47\n34 44\n24 45\n21 36\n29 38\n17 29\n20 29\n30 32\n23 40\n47 48\n36 43\n2 37\n27 42\n11 17\n26 47\n4 16\n24 35\n32 47\n8 22\n28 46\n17 26\n36 43\n1 26\n26 40\n26 47\n5 38\n20 33\n6 27\n9 33\n2 7\n17 35\n12 18\n20 36\n20 43\n22 45\n13 44\n3 7\n1 33\n7 45\n20 36\n33 41\n10 11\n29 35\n17 21\n10 24\n39 41\n2 6\n45 46\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"input": "100 6\n20 25\n17 21\n24 28\n5 7\n31 34\n99 100\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "15 4\n14 15\n11 15\n8 14\n1 12\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "16 5\n7 10\n15 15\n12 14\n7 10\n9 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "100 10\n20 25\n17 21\n24 28\n5 7\n31 35\n99 100\n89 90\n50 52\n1 3\n10 10\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n1 3\n2 3\n4 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 3\n5 7\n6 6\n4 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "9 3\n2 2\n1 6\n3 9\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5000 4\n2 4998\n3 4999\n1 2500\n2501 5000\n",
"output": "5000\n",
"type": "stdin_stdout"
},
{
"input": "20 3\n1 20\n11 20\n1 10\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "43 4\n23 33\n15 36\n3 31\n39 41\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n1 4\n1 2\n3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6 4\n1 2\n4 5\n6 6\n1 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n1 3\n1 1\n2 2\n3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "84 6\n1 4\n1 4\n2 4\n2 4\n3 5\n4 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "210 4\n2 8\n1 1\n1 5\n6 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 7\n9 10\n9 9\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "14 4\n1 6\n3 5\n10 11\n2 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "33 3\n2 3\n3 3\n2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "11 3\n1 7\n1 3\n4 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "13 3\n2 3\n2 2\n3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 6\n1 2\n2 3\n1 2\n5 6\n5 8\n10 10\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "14 3\n1 3\n1 2\n3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1011 4\n9 11\n6 11\n2 5\n5 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n1 4\n2 3\n3 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "18 3\n9 18\n5 15\n1 2\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "79 3\n1 4\n2 3\n1 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n6 6\n3 6\n7 9\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "15 3\n2 6\n4 11\n8 13\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "103 3\n1 3\n3 3\n1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "12 3\n2 11\n3 12\n4 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "6 5\n1 5\n3 5\n5 5\n4 6\n2 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "9 4\n3 6\n2 9\n5 6\n1 6\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "100 3\n1 4\n1 2\n3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "19 3\n4 6\n3 5\n3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 4\n5 7\n3 3\n1 4\n1 5\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "87 3\n2 5\n4 7\n2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6 3\n1 4\n1 3\n1 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "94 3\n3 3\n4 4\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8 6\n4 7\n4 8\n1 8\n2 7\n4 7\n3 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "68 3\n4 8\n3 8\n1 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "312 3\n6 6\n2 7\n3 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 6\n1 6\n8 10\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "103 7\n3 3\n2 3\n1 2\n1 1\n2 3\n3 3\n2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n4 6\n1 3\n1 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "12 3\n2 2\n6 9\n4 8\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n1 1\n2 2\n3 3\n1 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "411 4\n4 11\n11 11\n2 10\n1 8\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "9 4\n1 4\n5 8\n8 9\n5 7\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "50 3\n9 26\n16 34\n25 39\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "39 3\n2 3\n7 9\n2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 5\n1 5\n8 8\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9 5\n1 2\n4 6\n1 1\n8 9\n1 3\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "88 3\n1 3\n1 5\n3 8\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "8 3\n1 4\n5 8\n2 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "811 4\n4 4\n6 11\n6 9\n7 11\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "510 5\n10 10\n5 7\n2 6\n3 6\n1 3\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "77 5\n3 6\n1 2\n2 5\n7 7\n1 2\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "22 4\n9 19\n14 17\n7 18\n6 12\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "73 3\n2 3\n2 3\n3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "96 4\n2 5\n2 4\n1 4\n4 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "93 3\n3 3\n3 3\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "12 3\n3 11\n9 12\n2 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "312 4\n4 9\n6 6\n11 12\n1 8\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1010 3\n1 6\n5 10\n3 9\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "17 3\n6 7\n2 3\n3 6\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "19 5\n9 9\n2 3\n5 7\n1 2\n3 4\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 3\n2 5\n4 6\n7 9\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "94 5\n1 1\n3 4\n2 2\n4 4\n3 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "49 3\n6 8\n2 7\n1 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "17 3\n4 7\n1 6\n1 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "511 4\n4 10\n5 11\n5 6\n3 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "6 3\n1 3\n4 5\n5 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5000 14\n1847 3022\n2661 3933\n3410 4340\n4239 4645\n4553 4695\n4814 4847\n4840 4895\n4873 4949\n4937 4963\n4961 4984\n4975 4991\n4989 4996\n4993 4999\n4998 5000\n",
"output": "3034\n",
"type": "stdin_stdout"
},
{
"input": "3072 11\n1217 1281\n1749 2045\n1935 2137\n2298 2570\n2618 2920\n2873 3015\n2967 3050\n3053 3060\n3061 3065\n3064 3070\n3068 3072\n",
"output": "1175\n",
"type": "stdin_stdout"
},
{
"input": "96 5\n46 66\n60 80\n74 90\n88 94\n93 96\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "13 3\n2 2\n5 12\n1 2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n1 2\n2 3\n3 4\n5 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "13 3\n5 13\n6 13\n7 12\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "13 4\n6 12\n2 11\n2 7\n1 7\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "13 4\n1 9\n9 10\n8 11\n4 11\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "233 4\n1 5\n2 4\n7 9\n3 3\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n9 9\n5 7\n3 8\n1 5\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 5\n2 7\n7 9\n1 2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n7 10\n9 10\n3 3\n3 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 4\n2 10\n7 7\n2 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 9\n4 6\n7 10\n2 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n8 9\n1 7\n5 6\n3 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "8 4\n1 4\n2 3\n2 6\n5 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "17 3\n5 16\n4 10\n11 17\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n7 10\n1 7\n2 9\n1 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 2\n1 7\n1 8\n4 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n6 6\n1 5\n5 8\n4 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n7 10\n1 9\n3 7\n2 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n6 9\n3 7\n5 6\n4 9\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n5 5\n3 9\n3 10\n2 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 5\n2 6\n9 9\n1 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n7 9\n9 9\n2 2\n3 10\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "8 3\n1 2\n2 4\n4 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n5 6\n3 6\n4 10\n4 7\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 6\n1 4\n6 10\n9 10\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 5\n4 6\n9 10\n3 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 10\n8 10\n5 9\n1 4\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 6\n3 7\n8 10\n1 6\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 6\n6 9\n5 8\n8 9\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 6\n4 8\n5 9\n1 2\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 7\n7 8\n8 10\n5 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 7\n1 5\n8 9\n4 5\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n6 8\n2 6\n5 6\n3 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n5 6\n8 10\n5 5\n4 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 6\n2 6\n4 9\n1 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 5\n3 4\n1 4\n1 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 3\n1 4\n2 6\n5 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n6 10\n1 6\n1 3\n2 8\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 4\n8 10\n3 5\n1 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 8\n1 10\n7 8\n6 7\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 4\n6 7\n1 4\n3 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 8\n1 5\n4 7\n2 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 7\n5 9\n2 4\n6 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 3\n5 9\n9 10\n6 10\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 8\n7 8\n3 7\n1 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 9\n6 10\n8 10\n5 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 10\n1 2\n5 6\n4 7\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n7 7\n1 3\n3 7\n6 10\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n9 10\n1 6\n2 7\n4 6\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "9 4\n1 4\n8 9\n5 7\n5 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n5 7\n5 8\n4 4\n3 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n7 9\n1 4\n3 8\n7 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n5 8\n5 5\n2 3\n4 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 4\n4 7\n5 5\n5 8\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n7 8\n2 4\n1 7\n1 7\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 9\n7 8\n1 1\n2 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n6 9\n7 10\n2 6\n7 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 9\n5 7\n1 7\n10 10\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n6 7\n4 4\n1 3\n6 10\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 7\n4 9\n6 7\n1 2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 3\n4 5\n4 8\n2 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 10\n1 5\n8 10\n2 7\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 6\n7 8\n8 9\n6 10\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 6\n6 10\n8 8\n7 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 7\n1 7\n3 7\n2 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 9\n4 8\n1 5\n4 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n9 10\n4 5\n3 7\n1 4\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 10\n1 7\n5 8\n5 7\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 5\n5 9\n4 9\n5 7\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 8\n6 7\n2 7\n4 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 9\n8 10\n5 9\n3 5\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 5\n2 3\n8 10\n1 9\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 3\n8 8\n3 9\n3 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n7 10\n4 7\n4 5\n1 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n8 10\n2 9\n1 6\n6 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 9\n1 2\n6 7\n4 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n8 9\n1 8\n3 6\n5 5\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n8 10\n1 9\n2 8\n1 4\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 8\n3 6\n8 10\n5 6\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 10\n1 8\n4 10\n9 9\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n5 8\n4 6\n8 10\n6 9\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n5 10\n2 10\n7 9\n1 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n6 6\n1 7\n1 9\n10 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 5\n7 10\n3 10\n6 8\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n7 10\n2 9\n1 6\n10 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 4\n1 4\n3 6\n4 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n6 9\n3 8\n3 5\n1 6\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n7 10\n1 5\n5 7\n1 4\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 9\n1 6\n2 8\n3 5\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 5\n1 3\n6 9\n4 5\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n6 8\n5 6\n3 5\n1 4\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 3\n4 4\n3 7\n9 10\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 2\n1 3\n4 7\n2 6\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 10\n1 1\n4 5\n3 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n5 10\n2 7\n3 4\n1 1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 8\n1 6\n3 7\n3 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 10\n1 2\n2 8\n1 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 5\n6 10\n10 10\n4 7\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 9\n3 5\n6 10\n2 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 2\n4 8\n5 9\n7 8\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 7\n3 9\n8 10\n5 9\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n5 10\n5 5\n6 8\n9 10\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 4\n9 10\n1 7\n2 6\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 9\n1 5\n6 10\n3 6\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 7\n1 3\n7 8\n1 6\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 7\n5 6\n3 6\n5 9\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 8\n5 9\n2 5\n6 7\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "9 4\n4 5\n1 4\n5 9\n2 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 4\n3 5\n4 4\n8 9\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 9\n2 7\n7 10\n6 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 5\n4 7\n9 10\n1 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 9\n3 6\n7 10\n7 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 8\n3 7\n6 6\n1 2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 9\n3 8\n2 2\n6 10\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 4\n2 5\n1 2\n3 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "9 4\n5 9\n2 7\n4 5\n1 4\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "5000 19\n645 651\n282 291\n4850 4861\n1053 1065\n4949 4952\n2942 2962\n316 319\n2060 2067\n271 278\n2315 2327\n4774 4779\n779 792\n4814 4817\n3836 3840\n3044 3055\n1187 1205\n3835 3842\n4139 4154\n3931 3945\n",
"output": "190\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 4\n5 8\n6 7\n3 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 6\n6 6\n8 8\n3 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 4\n4 9\n4 9\n8 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n5 7\n4 6\n8 10\n5 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 7\n6 10\n3 3\n2 6\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 4\n4 7\n6 7\n4 6\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n9 9\n4 7\n8 10\n1 1\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 7\n5 9\n5 5\n2 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 4\n7 9\n7 8\n5 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 5\n9 10\n6 8\n2 3\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 6\n1 4\n8 10\n6 7\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 5\n3 8\n6 9\n4 5\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 6\n1 2\n2 7\n2 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 8\n2 9\n8 10\n1 5\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1132/C"
} | vfc_9766 |
apps | verifiable_code | 4 | Solve the following coding problem using the programming language python:
Jamie loves sleeping. One day, he decides that he needs to wake up at exactly hh: mm. However, he hates waking up, so he wants to make waking up less painful by setting the alarm at a lucky time. He will then press the snooze button every x minutes until hh: mm is reached, and only then he will wake up. He wants to know what is the smallest number of times he needs to press the snooze button.
A time is considered lucky if it contains a digit '7'. For example, 13: 07 and 17: 27 are lucky, while 00: 48 and 21: 34 are not lucky.
Note that it is not necessary that the time set for the alarm and the wake-up time are on the same day. It is guaranteed that there is a lucky time Jamie can set so that he can wake at hh: mm.
Formally, find the smallest possible non-negative integer y such that the time representation of the time x·y minutes before hh: mm contains the digit '7'.
Jamie uses 24-hours clock, so after 23: 59 comes 00: 00.
-----Input-----
The first line contains a single integer x (1 ≤ x ≤ 60).
The second line contains two two-digit integers, hh and mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59).
-----Output-----
Print the minimum number of times he needs to press the button.
-----Examples-----
Input
3
11 23
Output
2
Input
5
01 07
Output
0
-----Note-----
In the first sample, Jamie needs to wake up at 11:23. So, he can set his alarm at 11:17. He would press the snooze button when the alarm rings at 11:17 and at 11:20.
In the second sample, Jamie can set his alarm at exactly at 01:07 which is lucky.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x=int(input())
h,m=list(map(int,input().split()))
def ok(mm):
while mm<0: mm+=1440
hh=mm//60
mm=mm%60
return hh%10==7 or hh//10==7 or mm%10==7 or mm//10==7
for y in range(999):
if ok(h*60+m-y*x):
print(y)
return
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n11 23\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n01 07\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "34\n09 24\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2\n14 37\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "14\n19 54\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "42\n15 44\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "46\n02 43\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "14\n06 41\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "26\n04 58\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "54\n16 47\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "38\n20 01\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "11\n02 05\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "55\n22 10\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "23\n10 08\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "23\n23 14\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "51\n03 27\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "35\n15 25\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "3\n12 15\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "47\n00 28\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "31\n13 34\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "59\n17 32\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "25\n11 03\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "9\n16 53\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "53\n04 06\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "37\n00 12\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5\n13 10\n",
"output": "63\n",
"type": "stdin_stdout"
},
{
"input": "50\n01 59\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "34\n06 13\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "2\n18 19\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "46\n06 16\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "14\n03 30\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "40\n13 37\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "24\n17 51\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8\n14 57\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "52\n18 54\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "20\n15 52\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "20\n03 58\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "48\n07 11\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "32\n04 01\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "60\n08 15\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "44\n20 20\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "55\n15 35\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "55\n03 49\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "23\n16 39\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "7\n20 36\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "35\n16 42\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "35\n05 56\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "3\n17 45\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "47\n05 59\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "15\n10 13\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "59\n06 18\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "34\n17 18\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "18\n05 23\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "46\n17 21\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "30\n06 27\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "14\n18 40\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "58\n22 54\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "26\n19 44\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10\n15 57\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "54\n20 47\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "22\n08 45\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "48\n18 08\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "32\n07 06\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "60\n19 19\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "45\n07 25\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "29\n12 39\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "13\n08 28\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "41\n21 42\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "41\n09 32\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "9\n21 45\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "37\n10 43\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3\n20 50\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "47\n00 04\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "15\n13 10\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "15\n17 23\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "43\n22 13\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "27\n10 26\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "55\n22 24\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "55\n03 30\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "24\n23 27\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "52\n11 33\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "18\n22 48\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "1\n12 55\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1\n04 27\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n12 52\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1\n20 16\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1\n04 41\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1\n20 21\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1\n04 45\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1\n12 18\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n04 42\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1\n02 59\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n18 24\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "1\n02 04\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "1\n18 28\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n18 01\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n10 25\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1\n02 49\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n02 30\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n18 54\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "1\n02 19\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n05 25\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "60\n23 55\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "60\n08 19\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "60\n00 00\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "60\n08 24\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "60\n16 13\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "60\n08 21\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "60\n16 45\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "60\n08 26\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "60\n08 50\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "60\n05 21\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "60\n13 29\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "60\n05 18\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "60\n13 42\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "60\n05 07\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "60\n05 47\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "60\n21 55\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "60\n05 36\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "60\n21 08\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "60\n21 32\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "60\n16 31\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "5\n00 00\n",
"output": "73\n",
"type": "stdin_stdout"
},
{
"input": "2\n06 58\n",
"output": "390\n",
"type": "stdin_stdout"
},
{
"input": "60\n00 00\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "2\n00 00\n",
"output": "181\n",
"type": "stdin_stdout"
},
{
"input": "10\n00 00\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "60\n01 00\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "12\n00 06\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"input": "1\n00 01\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5\n00 05\n",
"output": "74\n",
"type": "stdin_stdout"
},
{
"input": "60\n01 01\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "11\n18 11\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "60\n01 15\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10\n00 16\n",
"output": "38\n",
"type": "stdin_stdout"
},
{
"input": "60\n00 59\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "30\n00 00\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "60\n01 05\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "4\n00 03\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n00 00\n",
"output": "91\n",
"type": "stdin_stdout"
},
{
"input": "60\n00 01\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "6\n00 03\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "13\n00 00\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n18 01\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n06 00\n",
"output": "145\n",
"type": "stdin_stdout"
},
{
"input": "60\n04 08\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "5\n01 55\n",
"output": "96\n",
"type": "stdin_stdout"
},
{
"input": "8\n00 08\n",
"output": "47\n",
"type": "stdin_stdout"
},
{
"input": "23\n18 23\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\n00 06\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "59\n18 59\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "11\n00 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10\n00 01\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "59\n00 00\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10\n18 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n00 01\n",
"output": "73\n",
"type": "stdin_stdout"
},
{
"input": "1\n00 00\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8\n00 14\n",
"output": "47\n",
"type": "stdin_stdout"
},
{
"input": "60\n03 00\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "60\n00 10\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5\n01 13\n",
"output": "87\n",
"type": "stdin_stdout"
},
{
"input": "30\n02 43\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "17\n00 08\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n00 00\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "60\n00 05\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5\n18 05\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "30\n00 30\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "1\n00 06\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "55\n00 00\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "8\n02 08\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "7\n00 00\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "6\n08 06\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "48\n06 24\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "8\n06 58\n",
"output": "98\n",
"type": "stdin_stdout"
},
{
"input": "3\n12 00\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n01 06\n",
"output": "86\n",
"type": "stdin_stdout"
},
{
"input": "2\n00 08\n",
"output": "185\n",
"type": "stdin_stdout"
},
{
"input": "3\n18 03\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n17 00\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "59\n00 48\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5\n12 01\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "55\n01 25\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2\n07 23\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10\n01 10\n",
"output": "44\n",
"type": "stdin_stdout"
},
{
"input": "2\n00 01\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "59\n00 01\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5\n00 02\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n01 02\n",
"output": "106\n",
"type": "stdin_stdout"
},
{
"input": "5\n00 06\n",
"output": "74\n",
"type": "stdin_stdout"
},
{
"input": "42\n00 08\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "60\n01 20\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "3\n06 00\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n00 01\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n00 06\n",
"output": "184\n",
"type": "stdin_stdout"
},
{
"input": "1\n00 57\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6\n00 00\n",
"output": "61\n",
"type": "stdin_stdout"
},
{
"input": "5\n08 40\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "58\n00 55\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n00 02\n",
"output": "182\n",
"type": "stdin_stdout"
},
{
"input": "1\n08 01\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\n10 10\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "60\n01 11\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "2\n07 00\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15\n00 03\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "6\n04 34\n",
"output": "106\n",
"type": "stdin_stdout"
},
{
"input": "16\n00 16\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "2\n00 59\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "59\n00 08\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10\n03 10\n",
"output": "56\n",
"type": "stdin_stdout"
},
{
"input": "3\n08 03\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "20\n06 11\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "4\n01 00\n",
"output": "106\n",
"type": "stdin_stdout"
},
{
"input": "38\n01 08\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "60\n00 06\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5\n12 00\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "6\n01 42\n",
"output": "78\n",
"type": "stdin_stdout"
},
{
"input": "4\n00 04\n",
"output": "92\n",
"type": "stdin_stdout"
},
{
"input": "60\n04 05\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "1\n00 53\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5\n08 05\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "60\n18 45\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "60\n06 23\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "6\n00 15\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "58\n00 06\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "2\n06 44\n",
"output": "383\n",
"type": "stdin_stdout"
},
{
"input": "1\n08 00\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10\n06 58\n",
"output": "78\n",
"type": "stdin_stdout"
},
{
"input": "59\n00 58\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1\n18 00\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "50\n00 42\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "30\n18 30\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "60\n21 59\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "2\n10 52\n",
"output": "87\n",
"type": "stdin_stdout"
},
{
"input": "56\n00 00\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "16\n18 16\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n01 05\n",
"output": "86\n",
"type": "stdin_stdout"
},
{
"input": "5\n05 00\n",
"output": "133\n",
"type": "stdin_stdout"
},
{
"input": "5\n23 59\n",
"output": "72\n",
"type": "stdin_stdout"
},
{
"input": "7\n17 13\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "58\n00 00\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "15\n00 07\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "59\n08 00\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "46\n00 00\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "59\n01 05\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n01 00\n",
"output": "211\n",
"type": "stdin_stdout"
},
{
"input": "60\n00 24\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10\n00 08\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "10\n00 06\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "60\n01 24\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "50\n00 10\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "2\n03 00\n",
"output": "271\n",
"type": "stdin_stdout"
},
{
"input": "4\n19 04\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "25\n00 23\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "10\n01 01\n",
"output": "43\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/916/A"
} | vfc_9770 |
apps | verifiable_code | 5 | Solve the following coding problem using the programming language python:
Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for her studies, and she wants to close all the tabs that don't belong to this segment as fast as possible.
Each second Luba can either try moving the cursor to the left or to the right (if the cursor is currently at the tab i, then she can move it to the tab max(i - 1, a) or to the tab min(i + 1, b)) or try closing all the tabs to the left or to the right of the cursor (if the cursor is currently at the tab i, she can close all the tabs with indices from segment [a, i - 1] or from segment [i + 1, b]). In the aforementioned expressions a and b denote the minimum and maximum index of an unclosed tab, respectively. For example, if there were 7 tabs initially and tabs 1, 2 and 7 are closed, then a = 3, b = 6.
What is the minimum number of seconds Luba has to spend in order to leave only the tabs with initial indices from l to r inclusive opened?
-----Input-----
The only line of input contains four integer numbers n, pos, l, r (1 ≤ n ≤ 100, 1 ≤ pos ≤ n, 1 ≤ l ≤ r ≤ n) — the number of the tabs, the cursor position and the segment which Luba needs to leave opened.
-----Output-----
Print one integer equal to the minimum number of seconds required to close all the tabs outside the segment [l, r].
-----Examples-----
Input
6 3 2 4
Output
5
Input
6 3 1 3
Output
1
Input
5 2 1 5
Output
0
-----Note-----
In the first test Luba can do the following operations: shift the mouse cursor to the tab 2, close all the tabs to the left of it, shift the mouse cursor to the tab 3, then to the tab 4, and then close all the tabs to the right of it.
In the second test she only needs to close all the tabs to the right of the current position of the cursor.
In the third test Luba doesn't need to do anything.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, pos, l, r = map(int, input().split())
if l > 1 and r < n:
if l <= pos and pos <= r:
if pos - l < r - pos:
print(pos - l + 1 + r - l + 1)
else:
print(r - pos + 1 + r - l + 1)
elif pos > r:
print(pos - r + 1 + r - l + 1)
else:
print(l - pos + 1 + r - l + 1)
elif l == 1 and r < n:
print(int(abs(pos - r)) + 1)
elif l > 1 and r == n:
print(int(abs(pos - l)) + 1)
else:
print(0)
``` | {
"language": "python",
"test_cases": [
{
"input": "6 3 2 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6 3 1 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 2 1 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 1 1 99\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "100 50 1 99\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "100 99 1 99\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 100 1 99\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100 50 2 100\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "100 1 100 100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 50 50 50\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6 4 2 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "100 5 2 50\n",
"output": "53\n",
"type": "stdin_stdout"
},
{
"input": "10 7 3 9\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "7 4 2 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "43 16 2 18\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "100 50 2 51\n",
"output": "52\n",
"type": "stdin_stdout"
},
{
"input": "6 5 2 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 5 2 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 10 2 9\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 7 3 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "64 64 8 44\n",
"output": "58\n",
"type": "stdin_stdout"
},
{
"input": "5 4 2 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6 6 3 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 6 2 7\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "8 6 2 7\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "7 5 2 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7 5 2 6\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "100 50 49 99\n",
"output": "53\n",
"type": "stdin_stdout"
},
{
"input": "100 50 2 99\n",
"output": "147\n",
"type": "stdin_stdout"
},
{
"input": "10 9 2 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 10 7 9\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8 4 2 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "100 50 2 2\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "10 4 3 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "6 3 2 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "53 17 13 18\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 6 3 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9 8 2 5\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "100 50 2 3\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "10 7 2 9\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "6 1 2 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7 6 2 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "26 12 2 4\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "10 8 3 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "100 97 3 98\n",
"output": "98\n",
"type": "stdin_stdout"
},
{
"input": "6 2 2 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "9 2 4 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "6 6 2 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "50 2 25 49\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "5 5 2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "49 11 2 17\n",
"output": "23\n",
"type": "stdin_stdout"
},
{
"input": "10 3 2 9\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 6 3 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "6 1 5 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5 5 3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10 2 5 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7 7 3 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7 3 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5 1 2 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "100 53 2 99\n",
"output": "145\n",
"type": "stdin_stdout"
},
{
"input": "10 2 4 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5 2 1 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100 65 41 84\n",
"output": "64\n",
"type": "stdin_stdout"
},
{
"input": "33 20 7 17\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "7 2 3 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "77 64 10 65\n",
"output": "58\n",
"type": "stdin_stdout"
},
{
"input": "6 1 3 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6 4 2 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "11 8 2 10\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "7 1 3 6\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "100 50 2 50\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "50 49 5 8\n",
"output": "46\n",
"type": "stdin_stdout"
},
{
"input": "15 1 10 13\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "13 9 5 11\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "20 3 5 8\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 5 2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7 1 3 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7 2 3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10 5 2 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8 5 2 6\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "8 5 3 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "9 6 3 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "50 46 34 37\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "10 7 2 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "8 3 1 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100 3 10 20\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "6 2 1 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "12 11 5 10\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "98 97 72 83\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "100 5 3 98\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "8 5 2 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 10 4 6\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 4 2 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 3 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "75 30 6 33\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"input": "4 3 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20 9 7 17\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "10 2 3 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "100 40 30 80\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "10 6 2 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7 3 2 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 6 2 9\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "23 20 19 22\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "100 100 1 1\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "10 2 5 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "9 7 2 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "100 50 50 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 1 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "16 13 2 15\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "9 8 2 6\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "43 22 9 24\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "5 4 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "82 72 66 75\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "7 4 5 6\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "100 50 51 51\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6 5 2 6\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4 4 2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4 3 2 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6 1 2 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 2 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 4 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100 100 2 99\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "10 6 3 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "100 74 30 60\n",
"output": "46\n",
"type": "stdin_stdout"
},
{
"input": "4 1 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "100 50 3 79\n",
"output": "107\n",
"type": "stdin_stdout"
},
{
"input": "10 6 2 8\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "100 51 23 33\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "3 1 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "29 13 14 23\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "6 5 2 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 2 3 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9 3 1 6\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "45 33 23 37\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "100 99 1 98\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100 79 29 68\n",
"output": "52\n",
"type": "stdin_stdout"
},
{
"input": "7 7 6 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100 4 30 60\n",
"output": "58\n",
"type": "stdin_stdout"
},
{
"input": "100 33 50 50\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "50 2 34 37\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "100 70 2 99\n",
"output": "128\n",
"type": "stdin_stdout"
},
{
"input": "6 6 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "41 24 14 19\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "100 54 52 55\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 5 3 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "6 5 4 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 9 2 3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "6 4 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "100 68 5 49\n",
"output": "65\n",
"type": "stdin_stdout"
},
{
"input": "8 4 3 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "9 3 2 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "100 50 1 1\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "10 9 5 9\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "62 54 2 54\n",
"output": "54\n",
"type": "stdin_stdout"
},
{
"input": "100 54 30 60\n",
"output": "38\n",
"type": "stdin_stdout"
},
{
"input": "6 6 6 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 2 2 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "50 3 23 25\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "24 1 5 18\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "43 35 23 34\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "50 46 23 26\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "10 8 5 9\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "6 2 2 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "43 1 13 41\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "13 2 1 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6 3 3 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "14 10 4 12\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "5 1 4 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 3 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "17 17 12 14\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "20 15 6 7\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "86 36 8 70\n",
"output": "92\n",
"type": "stdin_stdout"
},
{
"input": "100 69 39 58\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"input": "3 3 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 2 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9 7 3 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "4 4 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "100 4 2 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "100 65 5 13\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "3 2 2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "44 38 20 28\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "100 65 58 60\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "16 12 8 13\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "11 8 4 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "20 9 2 10\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "5 5 4 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100 99 1 50\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "6 5 3 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "50 29 7 48\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "26 11 1 24\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "5 2 3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "100 1 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "100 60 27 56\n",
"output": "35\n",
"type": "stdin_stdout"
},
{
"input": "6 4 2 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8 7 3 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "4 1 3 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "12 9 2 10\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "100 25 9 19\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "10 7 3 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "7 3 2 6\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "100 39 4 40\n",
"output": "39\n",
"type": "stdin_stdout"
},
{
"input": "100 51 2 99\n",
"output": "147\n",
"type": "stdin_stdout"
},
{
"input": "15 6 4 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4 4 9\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "6 4 3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "14 7 4 12\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "4 4 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6 5 2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "12 12 5 5\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 5 3 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8 6 2 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "8 7 2 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "100 33 5 60\n",
"output": "84\n",
"type": "stdin_stdout"
},
{
"input": "100 32 5 60\n",
"output": "84\n",
"type": "stdin_stdout"
},
{
"input": "79 5 3 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "85 85 85 85\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "69 69 69 69\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7 5 3 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7 4 2 6\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "2 1 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100 2 1 90\n",
"output": "89\n",
"type": "stdin_stdout"
},
{
"input": "100 89 11 90\n",
"output": "82\n",
"type": "stdin_stdout"
},
{
"input": "10 1 2 8\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/915/B"
} | vfc_9774 |
apps | verifiable_code | 6 | Solve the following coding problem using the programming language python:
You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads!
$m$
Initially Zmei Gorynich has $x$ heads. You can deal $n$ types of blows. If you deal a blow of the $i$-th type, you decrease the number of Gorynich's heads by $min(d_i, curX)$, there $curX$ is the current number of heads. But if after this blow Zmei Gorynich has at least one head, he grows $h_i$ new heads. If $curX = 0$ then Gorynich is defeated.
You can deal each blow any number of times, in any order.
For example, if $curX = 10$, $d = 7$, $h = 10$ then the number of heads changes to $13$ (you cut $7$ heads off, but then Zmei grows $10$ new ones), but if $curX = 10$, $d = 11$, $h = 100$ then number of heads changes to $0$ and Zmei Gorynich is considered defeated.
Calculate the minimum number of blows to defeat Zmei Gorynich!
You have to answer $t$ independent queries.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) – the number of queries.
The first line of each query contains two integers $n$ and $x$ ($1 \le n \le 100$, $1 \le x \le 10^9$) — the number of possible types of blows and the number of heads Zmei initially has, respectively.
The following $n$ lines of each query contain the descriptions of types of blows you can deal. The $i$-th line contains two integers $d_i$ and $h_i$ ($1 \le d_i, h_i \le 10^9$) — the description of the $i$-th blow.
-----Output-----
For each query print the minimum number of blows you have to deal to defeat Zmei Gorynich.
If Zmei Gorynuch cannot be defeated print $-1$.
-----Example-----
Input
3
3 10
6 3
8 2
1 4
4 10
4 1
3 2
2 6
1 100
2 15
10 11
14 100
Output
2
3
-1
-----Note-----
In the first query you can deal the first blow (after that the number of heads changes to $10 - 6 + 3 = 7$), and then deal the second blow.
In the second query you just deal the first blow three times, and Zmei is defeated.
In third query you can not defeat Zmei Gorynich. Maybe it's better to convince it to stop fighting?
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
for _ in range(int(input())):
n, x = list(map(int, input().split()))
A = []
for _1 in range(n):
d, h = list(map(int, input().split()))
A.append([d, h])
A.sort(reverse=True)
if A[0][0] >= x:
print(1)
else:
x -= A[0][0]
mz = 0
for d, h in A:
mz = max(mz, d - h)
if mz:
print((x + mz - 1) // mz + 1)
else:
print(-1)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n3 10\n6 3\n8 2\n1 4\n4 10\n4 1\n3 2\n2 6\n1 100\n2 15\n10 11\n14 100\n",
"output": "2\n3\n-1\n",
"type": "stdin_stdout"
},
{
"input": "7\n5 1000000000\n2 1\n1 10\n1 1\n4 1000000000\n3 3\n1 1000000000\n5 1\n2 999999999\n3 1\n2 10000000\n4 10000000\n10000000 999999999\n9999900 12\n9999999 55\n9999999 1\n2 1000000\n1000000 1000000\n999999 1\n3 999999911\n3 1\n11 1000000000\n10 9\n3 1000000000\n1231 1200\n1000 800\n1 100\n",
"output": "999999997\n250000000\n499999999\n1\n1\n499999951\n4999995\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n3 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n8 10\n11 14\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n1 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n10 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n11 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n6 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 8\n10 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n10 11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 10\n1 2\n2 3\n3 4\n4 5\n999 9999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 100\n100 101\n1 101\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n20 25\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n11 12\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n5 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n20 10000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n10 120\n8 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 5\n10 100\n2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 5\n1 2\n2 3\n3 4\n4 5\n5 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 1\n1 1\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n5 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n10 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 10\n11 11\n12 12\n13 13\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n100 1000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n101 110\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 10\n2 1\n3 2\n4 3\n5 4\n999 999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n101 102\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 3\n1 2\n2 3\n3 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n5 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n11 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 6\n7 8\n10 11\n2 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n15 100\n50 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n6 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n5 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n100 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n100 1000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n100 500\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 2\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n5 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 17\n17 17\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 287724084\n410622275 558519327\n460165364 773440538\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n15 100\n20 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n15 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n10000 10000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 100\n1 2\n100 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n7 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n10 20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 5\n6 10\n7 8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n3 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 10\n51 52\n53 54\n55 56\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n4 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n7 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 3\n7 9\n7 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n15 20\n2 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 5\n3 3\n6 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n1000 2000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n3 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n11 20\n10 20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n2 5\n11 15\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 1\n13 13\n5 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 7\n1 2\n2 3\n7 8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10000\n10002 20000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n15 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 1\n1 1\n1 1\n4 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n100 200\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n3 5\n11 15\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7\n2 10\n5 3\n5 4\n2 10\n2 2\n2 5\n2 2\n2 2\n2 5\n3 3\n1 1\n2 2\n3 3\n3 3\n3 1\n3 2\n3 3\n3 5\n3 1\n3 2\n3 3\n4 40\n39 40\n5 2\n11 1\n18 8\n",
"output": "4\n-1\n1\n1\n1\n2\n2\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n11 123\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 4\n1 3\n2 2\n9 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 9\n9 10\n1 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 491766614\n580887809 696119733\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n99 654\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 1000\n9 8\n1002 1001\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n100 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n10 15\n10 15\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n10 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n1000000000 999999999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 2\n1 2\n2 3\n3 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 1\n555 777\n7 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n10 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 10\n8 10\n11 1\n5 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 4\n1 3\n2 6\n5 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 10\n100 1022\n2 3\n4 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 10\n12 13\n14 15\n16 17\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 9\n10 11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 1\n2 2\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 2\n10 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n2 3\n10 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 2\n2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n100 101\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 11\n11 11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n9 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n10 15\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n10 20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 10\n11 12\n1 1\n1 10\n3 2\n",
"output": "1\n8\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 5\n3 2\n4 3\n5 4\n6 5\n7 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n100 99\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n10 13\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 4\n4 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n10 19\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n12 15\n15 17\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n11 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 209810534\n506067088 741292314\n137757052 779663018\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 20\n20 25\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 4\n5 8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 1\n1 1\n1 1\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n10 20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 100\n100 101\n6 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n101 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 2\n3 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n11 80\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n23 54\n69 69\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n12 15\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 89811704\n189906434 633748930\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n12 14\n2 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 1000\n9 8\n1002 1000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 5\n100 1\n4 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n100 99\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 5\n10 10\n2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n11 20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 2\n4 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n5 10000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 5\n10 10\n10 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 10\n500 502\n7 6\n4 5\n6 8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n5 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 5\n5 5\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 4\n1 3\n2 2\n4 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n1 1000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 5\n6 7\n4 8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 10\n1 2\n2 3\n11 15\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 6\n7 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 1\n1 2\n1 6\n13 15\n3 7\n5 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n1 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 1\n2 2\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 2\n3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n1 10000\n10 10000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 6\n4 8\n5 9\n6 99\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 20\n21 23\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 6\n10 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 5\n3 4\n4 5\n5 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 10\n10 15\n1 10\n10 10\n",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 9\n10 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n4 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n10 11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n101 3000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 1\n20 10\n100 101\n1 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n2 1\n1 1\n2 1\n",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 9\n100 100\n1 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n20 30\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 5\n2 1\n3 2\n4 3\n5 4\n6 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 30\n100 99\n10 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 9\n9 100\n1 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n11 13\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 10\n10 1\n10 1\n10 1\n10 1\n10 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 5\n30 1\n5 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 100806436\n842674389 898363387\n210544824 952928428\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 10\n6000 300000\n8 2\n1 4\n4 10\n4 1\n3 2\n2 6\n1 100\n2 15\n10 11\n14 100\n",
"output": "1\n3\n-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 10\n6 3\n8 2\n1 4\n3 10\n12 13\n14 15\n16 17\n",
"output": "2\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 4\n5 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n10000 9999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n20 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 10\n11 20\n12 20\n13 20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 2\n4 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n1 1\n1 5\n4 3\n",
"output": "1\n2\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n10 11\n11 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n5 666\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 1000\n500 8\n1002 1000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n3 4567\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n100 1000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n10 12\n6 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n101 3455\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 2\n2 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 8\n9 3\n2 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 12\n1 1\n12 13\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 4\n5 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 10\n1 2\n2 3\n10 15\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 4\n5 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 6\n8 9\n4 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n5 3\n1 1\n5 7\n",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n8 10\n11 15\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 3\n9 7\n9 7\n2 20\n8 5\n3 1\n2 21\n8 5\n3 1\n",
"output": "1\n5\n6\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1000\n9999 9998\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n11 15\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n11 236954583\n902012977 320763974\n795972796 981875810\n849039459 256297310\n782811205 953973488\n262492899 708681326\n833903408 988437142\n830999367 921787976\n909531471 330119840\n672682916 669593112\n307978155 979351913\n758319968 46137816\n5 875387866\n950231414 197254148\n854504122 480138329\n319447758 525876673\n777901059 142050710\n67202045 969307738\n",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 15\n15 16\n3 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n10 12\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n7 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n100 95\n10 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n12 790047110\n714642478 7205470\n381215384 839029596\n191781258 384578253\n167922554 359020009\n12430721 23222566\n45051351 597654656\n128899497 204770156\n514457749 198042762\n967258595 333421841\n503721720 888792850\n662475029 195770292\n316890699 632578367\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n1000 999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 5\n5 6\n4 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n3 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 1\n2 1\n9 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n21 20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n100 1\n3 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n6 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 6\n6 6\n2 6\n8 9\n4 5\n",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 2\n2 5\n3 5\n4 5\n5 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 398083007\n686447318 668381376\n422715566 612018694\n5 648145615\n229660856 653591442\n12444108 167654072\n639943528 197810896\n964979355 258904556\n874646832 700273338\n4 731014817\n214843599 471451702\n602930121 250804331\n567630290 666424069\n888754797 421013037\n",
"output": "1\n1\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n1000 1000\n9 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 11456887\n997675914 458860071\n264651355 659381898\n539251720 829968843\n463998465 202892606\n170824635 110122375\n354836349 313752791\n3 566100868\n125389553 456048140\n43407260 34704081\n682940726 758773192\n11 483018644\n924702809 255692722\n312155389 379172890\n530348500 666383977\n664288622 460695848\n149388464 374322915\n183579194 1485347\n90522297 239403951\n686084898 544011746\n319167381 235062727\n490344138 599696655\n103868854 345455072\n",
"output": "1\n1\n1\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 334943905\n691877845 590800271\n852210365 891315257\n695598357 697313782\n123985514 104901799\n887775079 636754439\n1 69138927\n789294172 133464854\n13 122804187\n221740911 622365596\n327188939 257834630\n595296972 991905886\n257013641 634041041\n315692825 153629258\n578226816 391573613\n314822377 156131049\n737573444 178961145\n38293225 662681012\n382876028 755818411\n233026832 609858818\n957378758 491249603\n523943413 881360575\n",
"output": "1\n1\n1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 5\n999 999\n1 3\n7 7\n",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n2 1\n100 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 745132167\n928769069 893298383\n653090177 337257634\n815624998 996403895\n224663197 845554094\n663417903 312894963\n27048664 603602031\n292571325 286821960\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 40\n1000 1000\n9 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n1000 1000\n4 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n14 53717421\n865217515 137858932\n466658902 21520184\n145652745 913062876\n641765012 966392701\n71291526 265158769\n76450464 956645142\n883239294 975007070\n691295831 225929568\n577001921 532543299\n572467945 507218178\n48561331 764461747\n254137352 63844123\n81777574 607109424\n940294572 422353762\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n11 11\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 9\n10 20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n12 51427082\n313775771 974893234\n486055065 680686555\n891079673 827082888\n392061048 844818093\n587844063 506386243\n259101840 755677625\n583100762 11654427\n933805977 303701130\n417576054 848789361\n863727087 16520322\n157119826 312307878\n889171810 218188458\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 940859392\n532160257 888437166\n254656628 301382706\n720470406 114473575\n257681807 169501880\n454443505 726025264\n441443506 832262185\n1 294652649\n424623279 556935750\n14 937457215\n497461770 437660432\n842140049 954111728\n303451744 161202041\n140140704 680926056\n662206981 584859677\n55811681 989390067\n914639886 36410416\n753079752 341478459\n959054519 419745532\n692812350 765020627\n888209199 650682241\n831705070 194177867\n599440034 113913651\n851642438 445728719\n",
"output": "2\n1\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 27\n8 44\n44 65\n17 74\n12 96\n9 92\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n4 807989196\n770312657 78181451\n624192034 690910298\n754831733 354913874\n519577171 400120478\n4 491297333\n546432637 76258441\n312107971 75446008\n767483254 958677299\n84044330 577526244\n2 177840791\n197738084 143071228\n23274563 597315796\n7 610054060\n858529462 646280969\n644068190 462783596\n820658202 845877177\n192491527 719512716\n21905484 960718976\n548261425 971882256\n284893133 42507015\n3 358535210\n56376506 490101521\n465816877 732253365\n339502648 781257233\n",
"output": "2\n1\n1\n1\n1\n",
"type": "stdin_stdout"
},
{
"input": "3\n11 104209236\n949583781 458761573\n780497863 492414882\n838499633 565322864\n817039132 348022228\n723527488 152186300\n467396274 271801504\n91422826 344258169\n268689377 248424263\n179726899 346924948\n785270416 609191471\n941418243 609381696\n1 209888207\n719297361 955556943\n9 15177110\n841587884 597751827\n390527478 254837828\n846003355 65835769\n78243798 718907088\n34621371 919537262\n519930567 569304342\n973078604 63126305\n209417213 366621677\n642152661 965392467\n",
"output": "1\n1\n1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 5\n10 100\n2 1\n1 100\n100 500\n",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 4\n5 5\n3 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 2\n2 1000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 100\n3 2\n105 10000\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1217/B"
} | vfc_9778 |
apps | verifiable_code | 7 | Solve the following coding problem using the programming language python:
Anton likes to listen to fairy tales, especially when Danik, Anton's best friend, tells them. Right now Danik tells Anton a fairy tale:
"Once upon a time, there lived an emperor. He was very rich and had much grain. One day he ordered to build a huge barn to put there all his grain. Best builders were building that barn for three days and three nights. But they overlooked and there remained a little hole in the barn, from which every day sparrows came through. Here flew a sparrow, took a grain and flew away..."
More formally, the following takes place in the fairy tale. At the beginning of the first day the barn with the capacity of n grains was full. Then, every day (starting with the first day) the following happens: m grains are brought to the barn. If m grains doesn't fit to the barn, the barn becomes full and the grains that doesn't fit are brought back (in this problem we can assume that the grains that doesn't fit to the barn are not taken into account). Sparrows come and eat grain. In the i-th day i sparrows come, that is on the first day one sparrow come, on the second day two sparrows come and so on. Every sparrow eats one grain. If the barn is empty, a sparrow eats nothing.
Anton is tired of listening how Danik describes every sparrow that eats grain from the barn. Anton doesn't know when the fairy tale ends, so he asked you to determine, by the end of which day the barn will become empty for the first time. Help Anton and write a program that will determine the number of that day!
-----Input-----
The only line of the input contains two integers n and m (1 ≤ n, m ≤ 10^18) — the capacity of the barn and the number of grains that are brought every day.
-----Output-----
Output one integer — the number of the day when the barn will become empty for the first time. Days are numbered starting with one.
-----Examples-----
Input
5 2
Output
4
Input
8 1
Output
5
-----Note-----
In the first sample the capacity of the barn is five grains and two grains are brought every day. The following happens: At the beginning of the first day grain is brought to the barn. It's full, so nothing happens. At the end of the first day one sparrow comes and eats one grain, so 5 - 1 = 4 grains remain. At the beginning of the second day two grains are brought. The barn becomes full and one grain doesn't fit to it. At the end of the second day two sparrows come. 5 - 2 = 3 grains remain. At the beginning of the third day two grains are brought. The barn becomes full again. At the end of the third day three sparrows come and eat grain. 5 - 3 = 2 grains remain. At the beginning of the fourth day grain is brought again. 2 + 2 = 4 grains remain. At the end of the fourth day four sparrows come and eat grain. 4 - 4 = 0 grains remain. The barn is empty.
So the answer is 4, because by the end of the fourth day the barn becomes empty.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m = map(int, input().split())
if (m >= n): print(n)
else:
c = n - m
l = 0
r = 10 ** 18
while r - l > 1:
md = (r + l) // 2
if (1 + md) * md // 2 < c:
l = md
else:
r = md
print(r + m)
``` | {
"language": "python",
"test_cases": [
{
"input": "5 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "32 5\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "1024 1024\n",
"output": "1024\n",
"type": "stdin_stdout"
},
{
"input": "58044 52909\n",
"output": "53010\n",
"type": "stdin_stdout"
},
{
"input": "996478063 658866858\n",
"output": "658892843\n",
"type": "stdin_stdout"
},
{
"input": "570441179141911871 511467058318039545\n",
"output": "511467058661475480\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000000000000\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 999999999999997145\n",
"output": "999999999999997221\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1\n",
"output": "1414213563\n",
"type": "stdin_stdout"
},
{
"input": "999999998765257149 10\n",
"output": "1414213571\n",
"type": "stdin_stdout"
},
{
"input": "999999998765257150 10\n",
"output": "1414213571\n",
"type": "stdin_stdout"
},
{
"input": "999999998765257151 10\n",
"output": "1414213571\n",
"type": "stdin_stdout"
},
{
"input": "999999998765257152 10\n",
"output": "1414213572\n",
"type": "stdin_stdout"
},
{
"input": "999999998765257153 10\n",
"output": "1414213572\n",
"type": "stdin_stdout"
},
{
"input": "762078938126917521 107528\n",
"output": "1234675418\n",
"type": "stdin_stdout"
},
{
"input": "762078938126917522 107528\n",
"output": "1234675418\n",
"type": "stdin_stdout"
},
{
"input": "762078938126917523 107528\n",
"output": "1234675418\n",
"type": "stdin_stdout"
},
{
"input": "762078938126917524 107528\n",
"output": "1234675419\n",
"type": "stdin_stdout"
},
{
"input": "762078938126917525 107528\n",
"output": "1234675419\n",
"type": "stdin_stdout"
},
{
"input": "443233170968441395 1048576\n",
"output": "942571991\n",
"type": "stdin_stdout"
},
{
"input": "443233170968441396 1048576\n",
"output": "942571991\n",
"type": "stdin_stdout"
},
{
"input": "443233170968441397 1048576\n",
"output": "942571992\n",
"type": "stdin_stdout"
},
{
"input": "1833551251625340 1359260576251\n",
"output": "1359321110406\n",
"type": "stdin_stdout"
},
{
"input": "1835002539467264 2810548418174\n",
"output": "2810608952329\n",
"type": "stdin_stdout"
},
{
"input": "1840276176082280 8084185033189\n",
"output": "8084245567345\n",
"type": "stdin_stdout"
},
{
"input": "262133107905 256256256256\n",
"output": "256256364670\n",
"type": "stdin_stdout"
},
{
"input": "262133108160 256256256256\n",
"output": "256256364670\n",
"type": "stdin_stdout"
},
{
"input": "262133108161 256256256256\n",
"output": "256256364670\n",
"type": "stdin_stdout"
},
{
"input": "262133108162 256256256256\n",
"output": "256256364671\n",
"type": "stdin_stdout"
},
{
"input": "399823373917798976 326385530977846185\n",
"output": "326385531361089823\n",
"type": "stdin_stdout"
},
{
"input": "836052329491347820 327211774155929609\n",
"output": "327211775164731428\n",
"type": "stdin_stdout"
},
{
"input": "870979176282270170 16\n",
"output": "1319832715\n",
"type": "stdin_stdout"
},
{
"input": "930580173005562081 4\n",
"output": "1364243511\n",
"type": "stdin_stdout"
},
{
"input": "831613653237860272 154\n",
"output": "1289661856\n",
"type": "stdin_stdout"
},
{
"input": "867842613106376421 178\n",
"output": "1317454248\n",
"type": "stdin_stdout"
},
{
"input": "939156247712499033 1902\n",
"output": "1370517314\n",
"type": "stdin_stdout"
},
{
"input": "975385203286047886 1326\n",
"output": "1396701153\n",
"type": "stdin_stdout"
},
{
"input": "953065701826839766 4023\n",
"output": "1380631201\n",
"type": "stdin_stdout"
},
{
"input": "989294657400388618 7447\n",
"output": "1406630820\n",
"type": "stdin_stdout"
},
{
"input": "885695753008586140 42775\n",
"output": "1330979102\n",
"type": "stdin_stdout"
},
{
"input": "921924708582134992 158903\n",
"output": "1358043072\n",
"type": "stdin_stdout"
},
{
"input": "802352815201515314 183504\n",
"output": "1266953266\n",
"type": "stdin_stdout"
},
{
"input": "861953807629839929 1299632\n",
"output": "1314276256\n",
"type": "stdin_stdout"
},
{
"input": "925155772916259712 1929889\n",
"output": "1362191462\n",
"type": "stdin_stdout"
},
{
"input": "961384732784775860 5046017\n",
"output": "1391685648\n",
"type": "stdin_stdout"
},
{
"input": "910494856396204496 39891744\n",
"output": "1389332262\n",
"type": "stdin_stdout"
},
{
"input": "946723811969753348 17975168\n",
"output": "1394001194\n",
"type": "stdin_stdout"
},
{
"input": "992316381103677158 1849603453\n",
"output": "3258373398\n",
"type": "stdin_stdout"
},
{
"input": "828545340972193305 1027686877\n",
"output": "2314967219\n",
"type": "stdin_stdout"
},
{
"input": "946697532222325132 16179805162\n",
"output": "17555812078\n",
"type": "stdin_stdout"
},
{
"input": "982926487795873985 19357888587\n",
"output": "20759977363\n",
"type": "stdin_stdout"
},
{
"input": "892753091050063317 2037020896\n",
"output": "3373249237\n",
"type": "stdin_stdout"
},
{
"input": "928982046623612170 45215104320\n",
"output": "46578175853\n",
"type": "stdin_stdout"
},
{
"input": "845950022554437217 1553155668877\n",
"output": "1554456398264\n",
"type": "stdin_stdout"
},
{
"input": "882178982422953366 1792038785005\n",
"output": "1793367075026\n",
"type": "stdin_stdout"
},
{
"input": "847407611288100389 9111983407070\n",
"output": "9113285250762\n",
"type": "stdin_stdout"
},
{
"input": "883636566861649242 15350866523198\n",
"output": "15352195899906\n",
"type": "stdin_stdout"
},
{
"input": "988545172809612094 126043487780965\n",
"output": "126044893781768\n",
"type": "stdin_stdout"
},
{
"input": "824774128383160945 152286665864389\n",
"output": "152287950093217\n",
"type": "stdin_stdout"
},
{
"input": "889067279135046636 783632221444127\n",
"output": "783633554323452\n",
"type": "stdin_stdout"
},
{
"input": "925296230413628192 1609871104560255\n",
"output": "1609872463741155\n",
"type": "stdin_stdout"
},
{
"input": "892888041747308306 15921193742955831\n",
"output": "15921195067317449\n",
"type": "stdin_stdout"
},
{
"input": "929116997320857159 16747432626071959\n",
"output": "16747433976901012\n",
"type": "stdin_stdout"
},
{
"input": "810365749050428005 176443295773423092\n",
"output": "176443296899409285\n",
"type": "stdin_stdout"
},
{
"input": "846594708918944153 177269538951506516\n",
"output": "177269540108507095\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "256 20\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "78520 8\n",
"output": "404\n",
"type": "stdin_stdout"
},
{
"input": "1367064836 777314907868410435\n",
"output": "1367064836\n",
"type": "stdin_stdout"
},
{
"input": "658866858 996478063\n",
"output": "658866858\n",
"type": "stdin_stdout"
},
{
"input": "10 648271718824741275\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "326385530977846185 399823373917798976\n",
"output": "326385530977846185\n",
"type": "stdin_stdout"
},
{
"input": "327211774155929609 836052329491347820\n",
"output": "327211774155929609\n",
"type": "stdin_stdout"
},
{
"input": "2570 566042149577952145\n",
"output": "2570\n",
"type": "stdin_stdout"
},
{
"input": "512486308421983105 512486308421983105\n",
"output": "512486308421983105\n",
"type": "stdin_stdout"
},
{
"input": "262144 262144\n",
"output": "262144\n",
"type": "stdin_stdout"
},
{
"input": "314159265358979323 314159265358979323\n",
"output": "314159265358979323\n",
"type": "stdin_stdout"
},
{
"input": "16 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "29 16\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "24 14\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "28 18\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "8 11\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "500000000500004239 4242\n",
"output": "1000004242\n",
"type": "stdin_stdout"
},
{
"input": "500000000500004240 4242\n",
"output": "1000004242\n",
"type": "stdin_stdout"
},
{
"input": "500000000500004241 4242\n",
"output": "1000004242\n",
"type": "stdin_stdout"
},
{
"input": "500000000500004242 4242\n",
"output": "1000004242\n",
"type": "stdin_stdout"
},
{
"input": "500000000500004243 4242\n",
"output": "1000004243\n",
"type": "stdin_stdout"
},
{
"input": "500000000500004244 4242\n",
"output": "1000004243\n",
"type": "stdin_stdout"
},
{
"input": "500000000500004245 4242\n",
"output": "1000004243\n",
"type": "stdin_stdout"
},
{
"input": "163162808800191208 163162808800191206\n",
"output": "163162808800191208\n",
"type": "stdin_stdout"
},
{
"input": "328584130811799021 328584130811799020\n",
"output": "328584130811799021\n",
"type": "stdin_stdout"
},
{
"input": "89633000579612779 89633000579612778\n",
"output": "89633000579612779\n",
"type": "stdin_stdout"
},
{
"input": "924211674273037668 924211674273037666\n",
"output": "924211674273037668\n",
"type": "stdin_stdout"
},
{
"input": "758790352261429854 758790352261429851\n",
"output": "758790352261429853\n",
"type": "stdin_stdout"
},
{
"input": "39154349371830603 39154349371830597\n",
"output": "39154349371830600\n",
"type": "stdin_stdout"
},
{
"input": "313727604417502165 313727604417502155\n",
"output": "313727604417502159\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 999999999999999999\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 999999999999999998\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 999999999999999997\n",
"output": "999999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 999999999999999996\n",
"output": "999999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 999999999999999995\n",
"output": "999999999999999998\n",
"type": "stdin_stdout"
},
{
"input": "1 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6 9\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 2\n",
"output": "1414213564\n",
"type": "stdin_stdout"
},
{
"input": "1 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 15\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "12 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 100000000000000000\n",
"output": "100000001341640786\n",
"type": "stdin_stdout"
},
{
"input": "100 200\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100000000000000000 1\n",
"output": "447213596\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000000000\n",
"output": "1000001413506279\n",
"type": "stdin_stdout"
},
{
"input": "1 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 4\n",
"output": "1414213566\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 10000000000000\n",
"output": "1000000000000\n",
"type": "stdin_stdout"
},
{
"input": "1 100000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1 8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 10\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 11\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 100\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5 16\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10836 16097\n",
"output": "10836\n",
"type": "stdin_stdout"
},
{
"input": "16808 75250\n",
"output": "16808\n",
"type": "stdin_stdout"
},
{
"input": "900000000000169293 1\n",
"output": "1341640788\n",
"type": "stdin_stdout"
},
{
"input": "1 10000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 100\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 20\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 10000\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 5\n",
"output": "1414213567\n",
"type": "stdin_stdout"
},
{
"input": "2 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "999999998765257147 1\n",
"output": "1414213563\n",
"type": "stdin_stdout"
},
{
"input": "3 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "997270248313594436 707405570208615798\n",
"output": "707405570970015402\n",
"type": "stdin_stdout"
},
{
"input": "1 100000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6 1000000\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "16808 282475250\n",
"output": "16808\n",
"type": "stdin_stdout"
},
{
"input": "1000000007 100000000000007\n",
"output": "1000000007\n",
"type": "stdin_stdout"
},
{
"input": "1 1000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000 10000000000000000\n",
"output": "1000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 100\n",
"output": "1414213662\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 9\n",
"output": "1414213571\n",
"type": "stdin_stdout"
},
{
"input": "900000000000169293 171\n",
"output": "1341640957\n",
"type": "stdin_stdout"
},
{
"input": "1 999999999999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10000 10000000000000\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "1 9999999999999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "695968090125646936 429718492544794353\n",
"output": "429718493274519777\n",
"type": "stdin_stdout"
},
{
"input": "2 5000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8 100\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "2 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999 1\n",
"output": "1414213563\n",
"type": "stdin_stdout"
},
{
"input": "5 8\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 99999999999999999\n",
"output": "100000001341640785\n",
"type": "stdin_stdout"
},
{
"input": "100000000000000000 100000000000000000\n",
"output": "100000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000\n",
"output": "2414213562\n",
"type": "stdin_stdout"
},
{
"input": "1 10000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "22 11\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "10 10000000\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "3 8\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 123123\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 10\n",
"output": "1414213572\n",
"type": "stdin_stdout"
},
{
"input": "10000000000000 45687987897897\n",
"output": "10000000000000\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5000 123456789\n",
"output": "5000\n",
"type": "stdin_stdout"
},
{
"input": "7 100\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 500000000000\n",
"output": "501414213209\n",
"type": "stdin_stdout"
},
{
"input": "8 7\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1 10000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 15\n",
"output": "1414213577\n",
"type": "stdin_stdout"
},
{
"input": "1 123456789\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 1000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 11\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 499999999999999999\n",
"output": "500000000999999999\n",
"type": "stdin_stdout"
},
{
"input": "1 100000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "619768314833382029 108339531052386197\n",
"output": "108339532063750408\n",
"type": "stdin_stdout"
},
{
"input": "5 100\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 10000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 500000000000000000\n",
"output": "500000001000000000\n",
"type": "stdin_stdout"
},
{
"input": "143 3\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "2 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100 1000000000\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "2 100000000000000000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100000000000000000 1000000000000000000\n",
"output": "100000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999 123456789\n",
"output": "1537670351\n",
"type": "stdin_stdout"
},
{
"input": "1 99999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 9999999999\n",
"output": "11414213554\n",
"type": "stdin_stdout"
},
{
"input": "5 100000000000000000\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6 999999\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "100 10000000\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "4 100\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000000000\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5 15555555\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 155555\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "200 9999999999\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "3 200\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 490000000000000000\n",
"output": "490000001009950494\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 15555\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10040 200000\n",
"output": "10040\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 60000000000000000\n",
"output": "60000001371130920\n",
"type": "stdin_stdout"
},
{
"input": "10 1000000000000\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 45\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/785/C"
} | vfc_9782 |
apps | verifiable_code | 8 | Solve the following coding problem using the programming language python:
Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from $1$ to $9$). In this problem, we use one digit and one lowercase letter, which is the first character of the suit, to represent a suited tile. All possible suited tiles are represented as 1m, 2m, $\ldots$, 9m, 1p, 2p, $\ldots$, 9p, 1s, 2s, $\ldots$, 9s.
In order to win the game, she must have at least one mentsu (described below) in her hand, so sometimes she should draw extra suited tiles. After drawing a tile, the number of her tiles increases by one. She can draw any tiles she wants, including those already in her hand.
Do you know the minimum number of extra suited tiles she needs to draw so that she can win?
Here are some useful definitions in this game: A mentsu, also known as meld, is formed by a koutsu or a shuntsu; A koutsu, also known as triplet, is made of three identical tiles, such as [1m, 1m, 1m], however, [1m, 1p, 1s] or [1m, 4m, 7m] is NOT a koutsu; A shuntsu, also known as sequence, is made of three sequential numbered tiles in the same suit, such as [1m, 2m, 3m] and [5s, 7s, 6s], however, [9m, 1m, 2m] or [1m, 2p, 3s] is NOT a shuntsu.
Some examples: [2m, 3p, 2s, 4m, 1s, 2s, 4s] — it contains no koutsu or shuntsu, so it includes no mentsu; [4s, 3m, 3p, 4s, 5p, 4s, 5p] — it contains a koutsu, [4s, 4s, 4s], but no shuntsu, so it includes a mentsu; [5p, 5s, 9m, 4p, 1s, 7p, 7m, 6p] — it contains no koutsu but a shuntsu, [5p, 4p, 6p] or [5p, 7p, 6p], so it includes a mentsu.
Note that the order of tiles is unnecessary and you can assume the number of each type of suited tiles she can draw is infinite.
-----Input-----
The only line contains three strings — the tiles in Tokitsukaze's hand. For each string, the first character is a digit ranged from $1$ to $9$ and the second character is m, p or s.
-----Output-----
Print a single integer — the minimum number of extra suited tiles she needs to draw.
-----Examples-----
Input
1s 2s 3s
Output
0
Input
9m 9m 9m
Output
0
Input
3p 9m 2p
Output
1
-----Note-----
In the first example, Tokitsukaze already has a shuntsu.
In the second example, Tokitsukaze already has a koutsu.
In the third example, Tokitsukaze can get a shuntsu by drawing one suited tile — 1p or 4p. The resulting tiles will be [3p, 9m, 2p, 1p] or [3p, 9m, 2p, 4p].
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
cards=list(input().split())
lm=[0]*9
lp=[0]*9
ls=[0]*9
for item in cards:
if item[1]=='m':
lm[int(item[0])-1]+=1
elif item[1]=='p':
lp[int(item[0])-1]+=1
else :
ls[int(item[0])-1]+=1
if max(lm)==3 or max(lp)==3 or max(ls)==3:
print(0)
else :
flag=0
def seq_checker(li):
flag=0
for i in range(9):
if flag==0:
if lm[i]==1:
flag=1
else :
if lm[i]==1:
flag+=1
else :
break
return flag
if seq_checker(lm)==3 or seq_checker(lp)==3 or seq_checker(ls)==3:
print(0)
elif max(lm)==2 or max(lp)==2 or max(ls)==2:
print(1)
else :
m=0
for i in range(0,7):
m=max(sum(lm[i:i+3]),sum(lp[i:i+3]),sum(ls[i:i+3]),m)
print(3-m)
``` | {
"language": "python",
"test_cases": [
{
"input": "1s 2s 3s\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "9m 9m 9m\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3p 9m 2p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8p 2s 9m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5s 8m 5s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9s 4s 3m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4p 8m 9s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8s 5s 7p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4p 7p 2p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3p 2p 3p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5s 9p 5s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9m 6s 1p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4m 2p 8m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8p 6s 4p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9s 6m 7p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4m 1p 3m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8s 8m 1p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5m 3p 8m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9m 7p 4s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4p 4s 2m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8p 8m 7s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5p 4s 5p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9s 1m 1s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4s 5s 8p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2p 8p 8p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7m 3m 6m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8p 5m 9m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3p 9p 5s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7s 6s 3m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4s 1p 8s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8m 5s 6p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3m 3p 4s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7m 7m 9p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5p 1s 1m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9p 5m 8s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6s 9s 4p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1s 6m 2s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5m 2p 7p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2m 6p 5m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6p 3s 1p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1m 7p 8m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5m 4s 6s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2p 9m 2m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7s 2s 3m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4m 7p 1s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8m 2m 6p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3p 8p 4s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7p 3m 9p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4p 7p 7m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8p 5s 5p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3p 9p 1m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7s 6s 8s\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4s 1p 4m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3p 2m 4m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7p 8s 2s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2p 4m 7p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6s 1s 5s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3s 5m 1p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7s 9p 8m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2s 6m 6s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6m 2s 2m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3m 6p 9s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7m 3s 5p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5s 4p 6m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9s 1s 4p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4m 5s 9m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8s 3m 7s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5m 7p 5m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9m 2m 1s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4m 8p 8p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1p 3m 4s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5p 8p 2p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9s 5s 7m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7m 6s 8m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2p 3m 6p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6m 7s 2m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3m 2m 9s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7p 9s 7m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3p 4m 3s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7s 1p 1p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4s 5m 6s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8m 9s 4p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3m 7p 9m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1p 8s 9m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5p 5p 7s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2p 9s 5m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6s 4p 1s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1s 1m 8p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5s 6p 4s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2m 1m 2p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6m 7p 7m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1p 2m 5p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5m 8p 3m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3s 9p 2s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7s 7s 9p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4s 2p 7s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8m 6s 3p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3m 3m 1m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9p 7s 6p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4p 3m 4m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8p 9s 9s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3p 4m 7m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9p 1p 5s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9p 2p 1p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2p 2p 2p\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6s 6s 6s\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2p 4p 3p\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "7p 8p 6p\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3m 5m 4m\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "9s 7s 8s\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3p 9p 4m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7m 2m 3m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3p 5p 9p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2p 5p 9p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4s 5s 2s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8s 9s 5s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9p 6p 1p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1s 4s 3s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3p 9p 2p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9s 1s 3s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4p 7p 7p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5m 3m 5m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5m 5m 8m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5p 6p 5p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8m 8m 6m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9p 2p 9p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8s 9s 8s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9m 1m 1m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7m 4m 9p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7p 5p 5m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5m 3m 9p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6p 8p 6s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2p 4m 2m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8s 2m 6s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6s 1p 8s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7m 7s 1s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2p 8s 2s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4s 1m 1s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2s 3m 3s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2s 2p 3s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2s 8p 3s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3m 3p 1p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3p 1p 2m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7s 9m 9s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1p 9s 7s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1m 2p 8m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8p 1m 1p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9m 8m 2p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9m 8s 9s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2m 9s 1m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1m 8s 9m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7p 7p 7m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2s 2p 2p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2s 8p 2s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8p 8p 1m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9p 9m 9m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1p 9m 1p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7p 7m 7s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8m 2s 7p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2m 2s 2p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2s 8p 2m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1p 1m 1s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1p 1m 9s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4m 7m 6m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 2s 3p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9s 9s 9s\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1s 3s 9m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 1s 7s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5m 6m 7s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 2s 5s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 2p 3s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2s 4s 6s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 4s 7s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1m 5m 9m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9m 1m 2m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1p 2s 4s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3m 4p 5s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1m 3m 1s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 3s 2p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2p 3s 4p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7s 8s 9s\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1m 4m 7m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1s 2s 4s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3s 4m 4s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 2m 3p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1s 2p 4p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1p 8s 9s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1m 1m 2m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 2s 3m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 3s 5s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3m 6m 7m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 2p 3m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8m 7s 9s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 3s 2s\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3s 5s 7s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6s 4s 3s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4m 7s 5s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 3s 4s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3s 5s 1s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1p 5p 9p\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1p 2p 4p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 1p 1p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1m 1s 2m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1p 2s 3m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1m 3m 5m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1m 1p 1s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5m 5p 6m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6p 8s 9s\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9s 1s 2m\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1s 3s 5p\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1s 8m 9m\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1m 2p 3s\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1p 8m 9m\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1191/B"
} | vfc_9786 |
apps | verifiable_code | 9 | Solve the following coding problem using the programming language python:
Yet another round on DecoForces is coming! Grandpa Maks wanted to participate in it but someone has stolen his precious sofa! And how can one perform well with such a major loss?
Fortunately, the thief had left a note for Grandpa Maks. This note got Maks to the sofa storehouse. Still he had no idea which sofa belongs to him as they all looked the same!
The storehouse is represented as matrix n × m. Every sofa takes two neighbouring by some side cells. No cell is covered by more than one sofa. There can be empty cells.
Sofa A is standing to the left of sofa B if there exist two such cells a and b that x_{a} < x_{b}, a is covered by A and b is covered by B. Sofa A is standing to the top of sofa B if there exist two such cells a and b that y_{a} < y_{b}, a is covered by A and b is covered by B. Right and bottom conditions are declared the same way.
Note that in all conditions A ≠ B. Also some sofa A can be both to the top of another sofa B and to the bottom of it. The same is for left and right conditions.
The note also stated that there are cnt_{l} sofas to the left of Grandpa Maks's sofa, cnt_{r} — to the right, cnt_{t} — to the top and cnt_{b} — to the bottom.
Grandpa Maks asks you to help him to identify his sofa. It is guaranteed that there is no more than one sofa of given conditions.
Output the number of Grandpa Maks's sofa. If there is no such sofa that all the conditions are met for it then output -1.
-----Input-----
The first line contains one integer number d (1 ≤ d ≤ 10^5) — the number of sofas in the storehouse.
The second line contains two integer numbers n, m (1 ≤ n, m ≤ 10^5) — the size of the storehouse.
Next d lines contains four integer numbers x_1, y_1, x_2, y_2 (1 ≤ x_1, x_2 ≤ n, 1 ≤ y_1, y_2 ≤ m) — coordinates of the i-th sofa. It is guaranteed that cells (x_1, y_1) and (x_2, y_2) have common side, (x_1, y_1) ≠ (x_2, y_2) and no cell is covered by more than one sofa.
The last line contains four integer numbers cnt_{l}, cnt_{r}, cnt_{t}, cnt_{b} (0 ≤ cnt_{l}, cnt_{r}, cnt_{t}, cnt_{b} ≤ d - 1).
-----Output-----
Print the number of the sofa for which all the conditions are met. Sofas are numbered 1 through d as given in input. If there is no such sofa then print -1.
-----Examples-----
Input
2
3 2
3 1 3 2
1 2 2 2
1 0 0 1
Output
1
Input
3
10 10
1 2 1 1
5 5 6 5
6 4 5 4
2 1 2 0
Output
2
Input
2
2 2
2 1 1 1
1 2 2 2
1 0 0 0
Output
-1
-----Note-----
Let's consider the second example. The first sofa has 0 to its left, 2 sofas to its right ((1, 1) is to the left of both (5, 5) and (5, 4)), 0 to its top and 2 to its bottom (both 2nd and 3rd sofas are below). The second sofa has cnt_{l} = 2, cnt_{r} = 1, cnt_{t} = 2 and cnt_{b} = 0. The third sofa has cnt_{l} = 2, cnt_{r} = 1, cnt_{t} = 1 and cnt_{b} = 1.
So the second one corresponds to the given conditions.
In the third example The first sofa has cnt_{l} = 1, cnt_{r} = 1, cnt_{t} = 0 and cnt_{b} = 1. The second sofa has cnt_{l} = 1, cnt_{r} = 1, cnt_{t} = 1 and cnt_{b} = 0.
And there is no sofa with the set (1, 0, 0, 0) so the answer is -1.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from sys import stdin, stdout
k = int(stdin.readline())
n, m = map(int, stdin.readline().split())
left, right, down, up = [], [], [], []
coordinates = []
for i in range(k):
x1, y1, x2, y2 = map(int, stdin.readline().split())
if x1 == x2:
if y1 < y2:
coordinates.append((x1, y1, x2, y2, i))
else:
coordinates.append((x2, y2, x1, y1, i))
else:
if x1 < x2:
coordinates.append((x1, y1, x2, y2, i))
else:
coordinates.append((x2, y2, x1, y1, i))
left.append(coordinates[-1])
right.append(coordinates[-1])
up.append(coordinates[-1])
down.append(coordinates[-1])
left.sort(key = lambda x: (x[0], x[2]))
down.sort(key = lambda x: (x[1], x[3]))
challengers = [[], [], [], []]
cntl, cntr, cntd, cntu = map(int, stdin.readline().split())
label = 1
if cntl or not cntl:
for i in range(cntl, -1, -1):
if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]):
challengers[0].append(left[i][-1])
else:
break
for i in range(cntl + 1, k):
if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]) and left[i][2] > left[i][0]:
label = 0
if (left[i][0], left[i][2]) == (left[cntl][0], left[cntl][2]):
challengers[0].append(left[i][-1])
else:
break
if cntr or not cntr:
for i in range(k - 1 - cntr, k):
if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]):
challengers[1].append(left[i][-1])
else:
break
for i in range(k - 2 - cntr, -1, -1):
if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]) and left[i][2] > left[i][0]:
label = 0
if (left[i][0], left[i][2]) == (left[k - 1 - cntr][0], left[k - 1 - cntr][2]):
challengers[1].append(left[i][-1])
else:
break
#!!!!!!!!!!!
if cntd or not cntd:
for i in range(cntd, -1, -1):
if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]):
challengers[2].append(down[i][-1])
else:
break
for i in range(cntd + 1, k):
if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]) and down[i][3] > down[i][1]:
label = 0
if (down[i][1], down[i][3]) == (down[cntd][1], down[cntd][3]):
challengers[2].append(down[i][-1])
else:
break
if cntu or not cntu:
for i in range(k - 1 - cntu, k):
if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]):
challengers[3].append(down[i][-1])
else:
break
for i in range(k - 2 - cntu, -1, -1):
if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]) and down[i][3] > down[i][1]:
label = 0
if (down[i][1], down[i][3]) == (down[k - 1 - cntu][1], down[k - 1 - cntu][3]):
challengers[3].append(down[i][-1])
else:
break
ans = set(challengers[0]) & set(challengers[1]) & set(challengers[2]) & set(challengers[3])
if not len(ans) or not label:
stdout.write('-1')
else:
stdout.write(str(list(ans)[0] + 1))
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n3 2\n3 1 3 2\n1 2 2 2\n1 0 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n10 10\n1 2 1 1\n5 5 6 5\n6 4 5 4\n2 1 2 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 2\n2 1 1 1\n1 2 2 2\n1 0 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 2\n1 1 1 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 1\n2 1 1 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1000 1000\n63 902 63 901\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6\n10 10\n3 6 3 7\n4 9 5 9\n5 4 5 3\n7 1 8 1\n9 10 8 10\n7 7 7 8\n0 5 2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 4\n3 1 3 2\n2 2 2 1\n0 0 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 2\n1 1 1 2\n2 1 2 2\n0 1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 2\n1 1 1 2\n2 1 2 2\n1 0 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 2\n1 1 1 2\n2 1 2 2\n0 1 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 2\n1 2 1 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n1 2 1 3\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 4\n1 2 1 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n1 4 1 3\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 6\n1 6 1 5\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 7\n1 6 1 7\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 1\n2 1 1 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n2 2 2 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 3\n1 2 1 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 4\n2 3 2 4\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 5\n2 4 1 4\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 6\n2 1 1 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 7\n2 7 2 6\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 1\n2 1 3 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 2\n1 1 2 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 3\n3 2 3 3\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 4\n2 1 2 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 5\n2 2 2 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 6\n1 4 2 4\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 7\n2 2 1 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 1\n1 1 2 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 2\n1 1 1 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 3\n4 3 4 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 4\n3 2 3 3\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 5\n1 2 2 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 6\n4 3 4 4\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 7\n3 6 4 6\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 1\n2 1 1 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 2\n5 1 4 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 3\n4 2 3 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 4\n2 4 3 4\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 5\n4 1 3 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 6\n3 3 3 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 7\n1 6 1 7\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 1\n6 1 5 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 2\n4 2 5 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 3\n1 2 1 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 4\n2 2 3 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 5\n6 1 6 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 6\n4 1 3 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 7\n6 7 6 6\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 1\n6 1 7 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 2\n4 2 4 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 3\n7 1 7 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 4\n3 3 3 4\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 5\n6 4 7 4\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 6\n2 2 2 3\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 7\n1 3 2 3\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 4\n1 4 1 3\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 5\n1 5 1 4\n1 1 1 2\n0 0 1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 6\n1 2 1 3\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 7\n1 7 1 6\n1 4 1 5\n0 0 1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n2 1 2 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 3\n2 3 1 3\n1 2 2 2\n0 0 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 4\n2 2 2 1\n2 4 1 4\n0 1 1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 5\n2 2 2 1\n1 3 1 4\n1 0 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 6\n1 2 1 1\n2 1 2 2\n1 0 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 7\n2 4 2 5\n2 7 1 7\n0 0 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 2\n1 2 2 2\n1 1 2 1\n0 0 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 3\n2 1 1 1\n1 2 2 2\n0 0 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 4\n1 3 1 4\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 5\n1 2 1 1\n3 1 2 1\n0 1 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 6\n3 2 3 1\n3 6 2 6\n0 0 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 7\n3 6 3 5\n2 4 2 3\n0 1 0 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 1\n3 1 4 1\n1 1 2 1\n0 1 0 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 2\n4 1 3 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 3\n3 1 2 1\n1 2 1 1\n1 0 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 4\n4 1 3 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 5\n3 1 4 1\n4 2 4 3\n0 1 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 6\n2 3 2 4\n2 6 2 5\n0 0 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 7\n1 7 2 7\n4 1 3 1\n1 0 0 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 1\n2 1 1 1\n5 1 4 1\n1 0 0 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 2\n1 1 1 2\n2 2 3 2\n1 0 1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 3\n1 1 1 2\n5 2 5 3\n0 1 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 4\n4 4 4 3\n4 2 5 2\n0 0 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 5\n3 4 3 5\n4 1 3 1\n1 0 0 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 6\n2 4 3 4\n5 2 5 1\n0 1 1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 7\n2 7 1 7\n2 4 3 4\n0 0 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 1\n3 1 4 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 2\n5 1 6 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 3\n2 2 2 1\n3 2 3 1\n0 1 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 4\n6 4 5 4\n4 3 4 2\n1 0 1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 5\n2 4 2 3\n5 4 4 4\n1 0 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 6\n6 6 5 6\n1 3 1 2\n1 0 1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 7\n1 3 1 4\n5 2 5 1\n0 1 1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 1\n6 1 7 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n7 2\n5 2 4 2\n2 1 2 2\n0 1 0 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n7 3\n7 2 6 2\n1 2 2 2\n0 1 0 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n7 4\n6 1 6 2\n2 3 1 3\n1 0 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n7 5\n2 3 1 3\n4 3 3 3\n1 0 0 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n7 6\n5 1 6 1\n2 5 3 5\n0 1 1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n7 7\n2 3 2 4\n5 4 5 5\n0 1 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 6\n1 4 1 5\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 7\n1 1 1 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 3\n1 1 2 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 4\n1 3 1 4\n2 4 2 3\n2 2 1 2\n0 0 0 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 5\n2 5 1 5\n2 3 2 2\n1 1 2 1\n0 0 1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 6\n1 3 1 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 7\n2 6 2 7\n1 4 1 5\n2 2 2 3\n1 0 0 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 2\n3 2 2 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 3\n2 3 3 3\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 4\n3 1 3 2\n3 4 2 4\n0 1 1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 5\n3 4 3 5\n3 2 3 1\n1 3 2 3\n1 0 0 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 6\n1 1 2 1\n1 3 2 3\n0 0 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 7\n2 1 3 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 2\n1 2 2 2\n3 1 4 1\n3 2 4 2\n0 2 1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 3\n4 3 3 3\n2 2 2 1\n1 0 1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 4\n2 3 2 4\n4 4 4 3\n2 2 1 2\n0 2 0 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 5\n2 4 1 4\n1 3 1 2\n2 1 1 1\n2 1 2 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 6\n3 3 4 3\n4 6 3 6\n0 0 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 7\n2 7 3 7\n4 4 4 5\n3 4 3 3\n2 0 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 2\n1 1 1 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 3\n1 2 1 3\n5 2 5 3\n1 1 2 1\n1 1 0 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 4\n4 1 4 2\n1 1 1 2\n5 1 5 2\n0 2 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 5\n3 3 4 3\n5 2 4 2\n0 0 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 6\n5 2 4 2\n1 1 1 2\n5 1 4 1\n2 1 2 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 7\n5 4 4 4\n1 2 1 1\n2 5 2 4\n0 2 0 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 1\n3 1 2 1\n4 1 5 1\n1 0 0 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 2\n5 2 5 1\n6 1 6 2\n3 2 2 2\n2 0 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 3\n2 1 2 2\n6 2 6 1\n1 2 1 1\n1 1 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 4\n1 2 2 2\n3 1 3 2\n2 3 2 4\n0 2 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 5\n2 2 2 1\n5 4 6 4\n4 4 4 3\n2 0 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 6\n4 4 4 5\n2 3 1 3\n3 4 3 3\n0 2 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 7\n3 4 3 5\n5 4 6 4\n4 5 4 4\n1 1 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n7 1\n4 1 5 1\n3 1 2 1\n6 1 7 1\n2 0 0 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n7 2\n7 1 7 2\n5 1 4 1\n3 1 3 2\n0 2 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n7 3\n2 3 3 3\n5 1 6 1\n7 2 7 1\n0 2 2 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n7 4\n5 4 6 4\n6 1 6 2\n5 1 4 1\n0 2 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n7 5\n2 2 2 3\n7 1 7 2\n1 4 1 3\n2 0 0 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n7 6\n2 6 2 5\n2 2 1 2\n4 4 3 4\n0 1 0 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 7\n5 4 6 4\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 4\n1 1 1 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 5\n2 4 2 5\n2 1 1 1\n2 2 1 2\n0 1 1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 6\n1 3 1 2\n2 2 2 1\n2 5 2 6\n1 0 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 7\n2 1 1 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 3\n3 1 2 1\n3 3 2 3\n1 3 1 2\n3 2 2 2\n0 3 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 4\n2 4 3 4\n3 3 3 2\n1 2 2 2\n3 1 2 1\n0 3 1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 5\n2 3 1 3\n1 5 1 4\n2 5 2 4\n2 2 1 2\n1 0 3 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 6\n1 5 1 6\n3 5 3 4\n1 0 0 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 7\n1 2 1 1\n3 3 3 4\n2 1 3 1\n2 6 3 6\n1 1 3 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 2\n2 2 3 2\n1 1 1 2\n4 2 4 1\n2 0 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 3\n1 2 1 1\n3 1 3 2\n0 1 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 4\n3 1 4 1\n3 4 4 4\n0 0 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 5\n3 1 3 2\n2 1 2 2\n1 0 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 6\n1 5 2 5\n3 4 3 5\n1 1 1 2\n4 1 4 2\n2 1 2 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 7\n4 2 4 3\n1 4 1 3\n1 2 1 1\n0 1 0 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 2\n1 1 2 1\n3 1 4 1\n3 2 2 2\n1 1 2 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 3\n2 1 1 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 4\n1 2 1 3\n5 4 5 3\n1 0 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n5 5\n5 1 4 1\n3 3 3 4\n1 3 2 3\n2 1 2 2\n0 2 0 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 6\n4 6 4 5\n1 5 1 6\n5 5 5 4\n0 2 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 7\n1 5 1 4\n2 5 3 5\n4 4 3 4\n2 0 0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 2\n1 1 2 1\n6 1 5 1\n0 1 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 3\n3 3 4 3\n5 3 6 3\n1 0 0 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n6 4\n3 2 3 1\n4 1 5 1\n6 1 6 2\n2 2 1 2\n2 1 0 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 5\n5 4 5 3\n1 3 1 2\n2 1 1 1\n1 1 0 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 6\n1 2 2 2\n1 5 1 6\n6 6 6 5\n0 1 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n6 7\n5 4 5 5\n4 4 3 4\n2 1 1 1\n6 3 6 2\n1 2 2 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n7 2\n5 1 6 1\n2 2 3 2\n2 1 1 1\n2 0 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n7 3\n6 1 7 1\n3 1 4 1\n6 2 5 2\n2 1 1 1\n2 1 3 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n7 4\n4 2 3 2\n5 2 5 3\n3 4 2 4\n6 2 6 1\n3 0 0 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 5\n6 5 7 5\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n7 6\n2 6 1 6\n2 4 2 5\n3 2 2 2\n1 0 0 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n7 7\n4 6 5 6\n7 4 7 5\n7 1 7 2\n2 6 2 5\n1 2 2 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 5\n1 3 2 3\n1 5 1 4\n1 2 2 2\n1 1 2 1\n0 0 3 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 6\n2 1 2 2\n1 2 1 1\n1 0 0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 7\n1 2 2 2\n2 6 2 5\n2 3 1 3\n1 5 1 4\n0 3 2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 4\n2 2 3 2\n1 2 1 3\n3 1 2 1\n1 0 0 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 5\n3 1 3 2\n2 3 2 2\n2 5 1 5\n3 4 3 3\n2 0 2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 6\n3 1 2 1\n1 2 2 2\n2 3 3 3\n1 5 1 4\n0 2 3 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 7\n3 2 2 2\n3 5 2 5\n3 7 2 7\n0 0 1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 3\n3 2 3 3\n4 2 4 1\n1 2 1 3\n3 1 2 1\n0 3 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 4\n2 4 1 4\n1 2 1 3\n4 3 4 4\n3 3 3 2\n0 2 0 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 5\n4 5 3 5\n4 2 3 2\n2 1 3 1\n0 1 0 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5\n4 6\n4 3 3 3\n4 2 4 1\n3 6 2 6\n2 4 2 3\n1 1 1 2\n1 2 2 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 7\n2 6 2 7\n2 5 2 4\n0 0 1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 2\n2 2 2 1\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 3\n4 2 3 2\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 4\n3 1 2 1\n3 4 3 3\n0 0 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 5\n3 4 2 4\n0 0 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n5 6\n5 3 5 2\n4 5 3 5\n1 2 1 3\n1 1 2 1\n3 0 1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 7\n5 5 5 6\n2 4 2 5\n2 3 1 3\n4 7 3 7\n4 1 5 1\n0 3 2 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 2\n5 2 5 1\n4 2 4 1\n1 0 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 3\n2 2 2 3\n3 3 4 3\n4 2 4 1\n1 1 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n6 4\n2 3 1 3\n4 4 3 4\n5 4 6 4\n1 4 2 4\n0 2 1 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5\n6 5\n1 5 1 4\n4 2 4 3\n2 2 1 2\n2 3 1 3\n3 2 3 3\n0 2 0 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n6 6\n4 3 4 2\n2 3 2 4\n4 4 5 4\n5 2 5 3\n0 3 2 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5\n6 7\n1 6 1 5\n3 6 2 6\n5 1 4 1\n2 5 3 5\n5 3 5 2\n3 0 0 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n7 2\n3 1 4 1\n7 1 7 2\n0 1 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n7 3\n6 3 7 3\n4 1 3 1\n0 1 0 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n7 4\n3 1 2 1\n5 2 5 1\n4 2 3 2\n7 3 6 3\n4 3 5 3\n1 2 2 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5\n7 5\n5 3 5 2\n3 5 2 5\n1 3 1 4\n3 3 3 4\n4 1 3 1\n1 2 4 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5\n7 6\n5 5 5 4\n6 1 7 1\n5 2 5 1\n1 1 2 1\n4 6 3 6\n1 3 4 0\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3\n7 7\n2 6 1 6\n7 2 6 2\n3 1 3 2\n2 0 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/818/C"
} | vfc_9790 |
apps | verifiable_code | 10 | Solve the following coding problem using the programming language python:
On the planet Mars a year lasts exactly n days (there are no leap years on Mars). But Martians have the same weeks as earthlings — 5 work days and then 2 days off. Your task is to determine the minimum possible and the maximum possible number of days off per year on Mars.
-----Input-----
The first line of the input contains a positive integer n (1 ≤ n ≤ 1 000 000) — the number of days in a year on Mars.
-----Output-----
Print two integers — the minimum possible and the maximum possible number of days off per year on Mars.
-----Examples-----
Input
14
Output
4 4
Input
2
Output
0 2
-----Note-----
In the first sample there are 14 days in a year on Mars, and therefore independently of the day a year starts with there will be exactly 4 days off .
In the second sample there are only 2 days in a year on Mars, and they can both be either work days or days off.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n=int(input())
r=n%7
d=n//7
print(2*d+max(0,r-5),2*d+min(r,2))
``` | {
"language": "python",
"test_cases": [
{
"input": "14\n",
"output": "4 4\n",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "0 2\n",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "0 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "0 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n",
"output": "0 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "0 2\n",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "2 2\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "2 4\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "2 4\n",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "2 4\n",
"type": "stdin_stdout"
},
{
"input": "12\n",
"output": "2 4\n",
"type": "stdin_stdout"
},
{
"input": "13\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "1000000\n",
"output": "285714 285715\n",
"type": "stdin_stdout"
},
{
"input": "16\n",
"output": "4 6\n",
"type": "stdin_stdout"
},
{
"input": "17\n",
"output": "4 6\n",
"type": "stdin_stdout"
},
{
"input": "18\n",
"output": "4 6\n",
"type": "stdin_stdout"
},
{
"input": "19\n",
"output": "4 6\n",
"type": "stdin_stdout"
},
{
"input": "20\n",
"output": "5 6\n",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "6 6\n",
"type": "stdin_stdout"
},
{
"input": "22\n",
"output": "6 7\n",
"type": "stdin_stdout"
},
{
"input": "23\n",
"output": "6 8\n",
"type": "stdin_stdout"
},
{
"input": "24\n",
"output": "6 8\n",
"type": "stdin_stdout"
},
{
"input": "25\n",
"output": "6 8\n",
"type": "stdin_stdout"
},
{
"input": "26\n",
"output": "6 8\n",
"type": "stdin_stdout"
},
{
"input": "27\n",
"output": "7 8\n",
"type": "stdin_stdout"
},
{
"input": "28\n",
"output": "8 8\n",
"type": "stdin_stdout"
},
{
"input": "29\n",
"output": "8 9\n",
"type": "stdin_stdout"
},
{
"input": "30\n",
"output": "8 10\n",
"type": "stdin_stdout"
},
{
"input": "100\n",
"output": "28 30\n",
"type": "stdin_stdout"
},
{
"input": "99\n",
"output": "28 29\n",
"type": "stdin_stdout"
},
{
"input": "98\n",
"output": "28 28\n",
"type": "stdin_stdout"
},
{
"input": "97\n",
"output": "27 28\n",
"type": "stdin_stdout"
},
{
"input": "96\n",
"output": "26 28\n",
"type": "stdin_stdout"
},
{
"input": "95\n",
"output": "26 28\n",
"type": "stdin_stdout"
},
{
"input": "94\n",
"output": "26 28\n",
"type": "stdin_stdout"
},
{
"input": "93\n",
"output": "26 28\n",
"type": "stdin_stdout"
},
{
"input": "92\n",
"output": "26 27\n",
"type": "stdin_stdout"
},
{
"input": "91\n",
"output": "26 26\n",
"type": "stdin_stdout"
},
{
"input": "90\n",
"output": "25 26\n",
"type": "stdin_stdout"
},
{
"input": "89\n",
"output": "24 26\n",
"type": "stdin_stdout"
},
{
"input": "88\n",
"output": "24 26\n",
"type": "stdin_stdout"
},
{
"input": "87\n",
"output": "24 26\n",
"type": "stdin_stdout"
},
{
"input": "86\n",
"output": "24 26\n",
"type": "stdin_stdout"
},
{
"input": "85\n",
"output": "24 25\n",
"type": "stdin_stdout"
},
{
"input": "84\n",
"output": "24 24\n",
"type": "stdin_stdout"
},
{
"input": "83\n",
"output": "23 24\n",
"type": "stdin_stdout"
},
{
"input": "82\n",
"output": "22 24\n",
"type": "stdin_stdout"
},
{
"input": "81\n",
"output": "22 24\n",
"type": "stdin_stdout"
},
{
"input": "80\n",
"output": "22 24\n",
"type": "stdin_stdout"
},
{
"input": "1000\n",
"output": "285 286\n",
"type": "stdin_stdout"
},
{
"input": "999\n",
"output": "284 286\n",
"type": "stdin_stdout"
},
{
"input": "998\n",
"output": "284 286\n",
"type": "stdin_stdout"
},
{
"input": "997\n",
"output": "284 286\n",
"type": "stdin_stdout"
},
{
"input": "996\n",
"output": "284 286\n",
"type": "stdin_stdout"
},
{
"input": "995\n",
"output": "284 285\n",
"type": "stdin_stdout"
},
{
"input": "994\n",
"output": "284 284\n",
"type": "stdin_stdout"
},
{
"input": "993\n",
"output": "283 284\n",
"type": "stdin_stdout"
},
{
"input": "992\n",
"output": "282 284\n",
"type": "stdin_stdout"
},
{
"input": "991\n",
"output": "282 284\n",
"type": "stdin_stdout"
},
{
"input": "990\n",
"output": "282 284\n",
"type": "stdin_stdout"
},
{
"input": "989\n",
"output": "282 284\n",
"type": "stdin_stdout"
},
{
"input": "988\n",
"output": "282 283\n",
"type": "stdin_stdout"
},
{
"input": "987\n",
"output": "282 282\n",
"type": "stdin_stdout"
},
{
"input": "986\n",
"output": "281 282\n",
"type": "stdin_stdout"
},
{
"input": "985\n",
"output": "280 282\n",
"type": "stdin_stdout"
},
{
"input": "984\n",
"output": "280 282\n",
"type": "stdin_stdout"
},
{
"input": "983\n",
"output": "280 282\n",
"type": "stdin_stdout"
},
{
"input": "982\n",
"output": "280 282\n",
"type": "stdin_stdout"
},
{
"input": "981\n",
"output": "280 281\n",
"type": "stdin_stdout"
},
{
"input": "980\n",
"output": "280 280\n",
"type": "stdin_stdout"
},
{
"input": "10000\n",
"output": "2856 2858\n",
"type": "stdin_stdout"
},
{
"input": "9999\n",
"output": "2856 2858\n",
"type": "stdin_stdout"
},
{
"input": "9998\n",
"output": "2856 2858\n",
"type": "stdin_stdout"
},
{
"input": "9997\n",
"output": "2856 2857\n",
"type": "stdin_stdout"
},
{
"input": "9996\n",
"output": "2856 2856\n",
"type": "stdin_stdout"
},
{
"input": "9995\n",
"output": "2855 2856\n",
"type": "stdin_stdout"
},
{
"input": "9994\n",
"output": "2854 2856\n",
"type": "stdin_stdout"
},
{
"input": "9993\n",
"output": "2854 2856\n",
"type": "stdin_stdout"
},
{
"input": "9992\n",
"output": "2854 2856\n",
"type": "stdin_stdout"
},
{
"input": "9991\n",
"output": "2854 2856\n",
"type": "stdin_stdout"
},
{
"input": "9990\n",
"output": "2854 2855\n",
"type": "stdin_stdout"
},
{
"input": "9989\n",
"output": "2854 2854\n",
"type": "stdin_stdout"
},
{
"input": "9988\n",
"output": "2853 2854\n",
"type": "stdin_stdout"
},
{
"input": "9987\n",
"output": "2852 2854\n",
"type": "stdin_stdout"
},
{
"input": "9986\n",
"output": "2852 2854\n",
"type": "stdin_stdout"
},
{
"input": "9985\n",
"output": "2852 2854\n",
"type": "stdin_stdout"
},
{
"input": "9984\n",
"output": "2852 2854\n",
"type": "stdin_stdout"
},
{
"input": "9983\n",
"output": "2852 2853\n",
"type": "stdin_stdout"
},
{
"input": "9982\n",
"output": "2852 2852\n",
"type": "stdin_stdout"
},
{
"input": "9981\n",
"output": "2851 2852\n",
"type": "stdin_stdout"
},
{
"input": "9980\n",
"output": "2850 2852\n",
"type": "stdin_stdout"
},
{
"input": "100000\n",
"output": "28570 28572\n",
"type": "stdin_stdout"
},
{
"input": "99999\n",
"output": "28570 28572\n",
"type": "stdin_stdout"
},
{
"input": "99998\n",
"output": "28570 28572\n",
"type": "stdin_stdout"
},
{
"input": "99997\n",
"output": "28570 28572\n",
"type": "stdin_stdout"
},
{
"input": "99996\n",
"output": "28570 28571\n",
"type": "stdin_stdout"
},
{
"input": "99995\n",
"output": "28570 28570\n",
"type": "stdin_stdout"
},
{
"input": "99994\n",
"output": "28569 28570\n",
"type": "stdin_stdout"
},
{
"input": "99993\n",
"output": "28568 28570\n",
"type": "stdin_stdout"
},
{
"input": "99992\n",
"output": "28568 28570\n",
"type": "stdin_stdout"
},
{
"input": "99991\n",
"output": "28568 28570\n",
"type": "stdin_stdout"
},
{
"input": "99990\n",
"output": "28568 28570\n",
"type": "stdin_stdout"
},
{
"input": "99989\n",
"output": "28568 28569\n",
"type": "stdin_stdout"
},
{
"input": "99988\n",
"output": "28568 28568\n",
"type": "stdin_stdout"
},
{
"input": "99987\n",
"output": "28567 28568\n",
"type": "stdin_stdout"
},
{
"input": "99986\n",
"output": "28566 28568\n",
"type": "stdin_stdout"
},
{
"input": "99985\n",
"output": "28566 28568\n",
"type": "stdin_stdout"
},
{
"input": "99984\n",
"output": "28566 28568\n",
"type": "stdin_stdout"
},
{
"input": "99983\n",
"output": "28566 28568\n",
"type": "stdin_stdout"
},
{
"input": "99982\n",
"output": "28566 28567\n",
"type": "stdin_stdout"
},
{
"input": "99981\n",
"output": "28566 28566\n",
"type": "stdin_stdout"
},
{
"input": "99980\n",
"output": "28565 28566\n",
"type": "stdin_stdout"
},
{
"input": "999999\n",
"output": "285714 285714\n",
"type": "stdin_stdout"
},
{
"input": "999998\n",
"output": "285713 285714\n",
"type": "stdin_stdout"
},
{
"input": "999997\n",
"output": "285712 285714\n",
"type": "stdin_stdout"
},
{
"input": "999996\n",
"output": "285712 285714\n",
"type": "stdin_stdout"
},
{
"input": "999995\n",
"output": "285712 285714\n",
"type": "stdin_stdout"
},
{
"input": "999994\n",
"output": "285712 285714\n",
"type": "stdin_stdout"
},
{
"input": "999993\n",
"output": "285712 285713\n",
"type": "stdin_stdout"
},
{
"input": "999992\n",
"output": "285712 285712\n",
"type": "stdin_stdout"
},
{
"input": "999991\n",
"output": "285711 285712\n",
"type": "stdin_stdout"
},
{
"input": "999990\n",
"output": "285710 285712\n",
"type": "stdin_stdout"
},
{
"input": "999989\n",
"output": "285710 285712\n",
"type": "stdin_stdout"
},
{
"input": "999988\n",
"output": "285710 285712\n",
"type": "stdin_stdout"
},
{
"input": "999987\n",
"output": "285710 285712\n",
"type": "stdin_stdout"
},
{
"input": "999986\n",
"output": "285710 285711\n",
"type": "stdin_stdout"
},
{
"input": "999985\n",
"output": "285710 285710\n",
"type": "stdin_stdout"
},
{
"input": "999984\n",
"output": "285709 285710\n",
"type": "stdin_stdout"
},
{
"input": "999983\n",
"output": "285708 285710\n",
"type": "stdin_stdout"
},
{
"input": "999982\n",
"output": "285708 285710\n",
"type": "stdin_stdout"
},
{
"input": "999981\n",
"output": "285708 285710\n",
"type": "stdin_stdout"
},
{
"input": "999980\n",
"output": "285708 285710\n",
"type": "stdin_stdout"
},
{
"input": "234123\n",
"output": "66892 66893\n",
"type": "stdin_stdout"
},
{
"input": "234122\n",
"output": "66892 66892\n",
"type": "stdin_stdout"
},
{
"input": "234121\n",
"output": "66891 66892\n",
"type": "stdin_stdout"
},
{
"input": "234120\n",
"output": "66890 66892\n",
"type": "stdin_stdout"
},
{
"input": "234119\n",
"output": "66890 66892\n",
"type": "stdin_stdout"
},
{
"input": "234118\n",
"output": "66890 66892\n",
"type": "stdin_stdout"
},
{
"input": "234117\n",
"output": "66890 66892\n",
"type": "stdin_stdout"
},
{
"input": "234116\n",
"output": "66890 66891\n",
"type": "stdin_stdout"
},
{
"input": "234115\n",
"output": "66890 66890\n",
"type": "stdin_stdout"
},
{
"input": "234114\n",
"output": "66889 66890\n",
"type": "stdin_stdout"
},
{
"input": "234113\n",
"output": "66888 66890\n",
"type": "stdin_stdout"
},
{
"input": "234112\n",
"output": "66888 66890\n",
"type": "stdin_stdout"
},
{
"input": "234111\n",
"output": "66888 66890\n",
"type": "stdin_stdout"
},
{
"input": "234110\n",
"output": "66888 66890\n",
"type": "stdin_stdout"
},
{
"input": "234109\n",
"output": "66888 66889\n",
"type": "stdin_stdout"
},
{
"input": "234108\n",
"output": "66888 66888\n",
"type": "stdin_stdout"
},
{
"input": "234107\n",
"output": "66887 66888\n",
"type": "stdin_stdout"
},
{
"input": "234106\n",
"output": "66886 66888\n",
"type": "stdin_stdout"
},
{
"input": "234105\n",
"output": "66886 66888\n",
"type": "stdin_stdout"
},
{
"input": "234104\n",
"output": "66886 66888\n",
"type": "stdin_stdout"
},
{
"input": "234103\n",
"output": "66886 66888\n",
"type": "stdin_stdout"
},
{
"input": "868531\n",
"output": "248151 248152\n",
"type": "stdin_stdout"
},
{
"input": "868530\n",
"output": "248150 248152\n",
"type": "stdin_stdout"
},
{
"input": "868529\n",
"output": "248150 248152\n",
"type": "stdin_stdout"
},
{
"input": "868528\n",
"output": "248150 248152\n",
"type": "stdin_stdout"
},
{
"input": "868527\n",
"output": "248150 248152\n",
"type": "stdin_stdout"
},
{
"input": "868526\n",
"output": "248150 248151\n",
"type": "stdin_stdout"
},
{
"input": "868525\n",
"output": "248150 248150\n",
"type": "stdin_stdout"
},
{
"input": "868524\n",
"output": "248149 248150\n",
"type": "stdin_stdout"
},
{
"input": "868523\n",
"output": "248148 248150\n",
"type": "stdin_stdout"
},
{
"input": "868522\n",
"output": "248148 248150\n",
"type": "stdin_stdout"
},
{
"input": "868521\n",
"output": "248148 248150\n",
"type": "stdin_stdout"
},
{
"input": "868520\n",
"output": "248148 248150\n",
"type": "stdin_stdout"
},
{
"input": "868519\n",
"output": "248148 248149\n",
"type": "stdin_stdout"
},
{
"input": "868518\n",
"output": "248148 248148\n",
"type": "stdin_stdout"
},
{
"input": "868517\n",
"output": "248147 248148\n",
"type": "stdin_stdout"
},
{
"input": "868516\n",
"output": "248146 248148\n",
"type": "stdin_stdout"
},
{
"input": "868515\n",
"output": "248146 248148\n",
"type": "stdin_stdout"
},
{
"input": "868514\n",
"output": "248146 248148\n",
"type": "stdin_stdout"
},
{
"input": "868513\n",
"output": "248146 248148\n",
"type": "stdin_stdout"
},
{
"input": "868512\n",
"output": "248146 248147\n",
"type": "stdin_stdout"
},
{
"input": "868511\n",
"output": "248146 248146\n",
"type": "stdin_stdout"
},
{
"input": "123413\n",
"output": "35260 35262\n",
"type": "stdin_stdout"
},
{
"input": "123412\n",
"output": "35260 35262\n",
"type": "stdin_stdout"
},
{
"input": "123411\n",
"output": "35260 35261\n",
"type": "stdin_stdout"
},
{
"input": "123410\n",
"output": "35260 35260\n",
"type": "stdin_stdout"
},
{
"input": "123409\n",
"output": "35259 35260\n",
"type": "stdin_stdout"
},
{
"input": "123408\n",
"output": "35258 35260\n",
"type": "stdin_stdout"
},
{
"input": "123407\n",
"output": "35258 35260\n",
"type": "stdin_stdout"
},
{
"input": "123406\n",
"output": "35258 35260\n",
"type": "stdin_stdout"
},
{
"input": "123405\n",
"output": "35258 35260\n",
"type": "stdin_stdout"
},
{
"input": "123404\n",
"output": "35258 35259\n",
"type": "stdin_stdout"
},
{
"input": "123403\n",
"output": "35258 35258\n",
"type": "stdin_stdout"
},
{
"input": "123402\n",
"output": "35257 35258\n",
"type": "stdin_stdout"
},
{
"input": "123401\n",
"output": "35256 35258\n",
"type": "stdin_stdout"
},
{
"input": "123400\n",
"output": "35256 35258\n",
"type": "stdin_stdout"
},
{
"input": "123399\n",
"output": "35256 35258\n",
"type": "stdin_stdout"
},
{
"input": "123398\n",
"output": "35256 35258\n",
"type": "stdin_stdout"
},
{
"input": "123397\n",
"output": "35256 35257\n",
"type": "stdin_stdout"
},
{
"input": "123396\n",
"output": "35256 35256\n",
"type": "stdin_stdout"
},
{
"input": "123395\n",
"output": "35255 35256\n",
"type": "stdin_stdout"
},
{
"input": "123394\n",
"output": "35254 35256\n",
"type": "stdin_stdout"
},
{
"input": "123393\n",
"output": "35254 35256\n",
"type": "stdin_stdout"
},
{
"input": "15\n",
"output": "4 5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/670/A"
} | vfc_9794 |
apps | verifiable_code | 11 | Solve the following coding problem using the programming language python:
Little Joty has got a task to do. She has a line of n tiles indexed from 1 to n. She has to paint them in a strange pattern.
An unpainted tile should be painted Red if it's index is divisible by a and an unpainted tile should be painted Blue if it's index is divisible by b. So the tile with the number divisible by a and b can be either painted Red or Blue.
After her painting is done, she will get p chocolates for each tile that is painted Red and q chocolates for each tile that is painted Blue.
Note that she can paint tiles in any order she wants.
Given the required information, find the maximum number of chocolates Joty can get.
-----Input-----
The only line contains five integers n, a, b, p and q (1 ≤ n, a, b, p, q ≤ 10^9).
-----Output-----
Print the only integer s — the maximum number of chocolates Joty can get.
Note that the answer can be too large, so you should use 64-bit integer type to store it. In C++ you can use the long long integer type and in Java you can use long integer type.
-----Examples-----
Input
5 2 3 12 15
Output
39
Input
20 2 3 3 5
Output
51
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from fractions import gcd
def lcm(a, b):
return a*b//gcd(a, b)
n, a, b, p, q = list(map(int, input().split(' ')))
red = n//a
blue = n//b
if (p<q):
red -= n//lcm(a, b)
else:
blue -= n//lcm(a, b)
print(p*red+q*blue)
``` | {
"language": "python",
"test_cases": [
{
"input": "5 2 3 12 15\n",
"output": "39\n",
"type": "stdin_stdout"
},
{
"input": "20 2 3 3 5\n",
"output": "51\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 2 2 2 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 1 3 3 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 1 1 3 3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "4 1 5 4 3\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "8 8 1 1 1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "15 14 32 65 28\n",
"output": "65\n",
"type": "stdin_stdout"
},
{
"input": "894 197 325 232 902\n",
"output": "2732\n",
"type": "stdin_stdout"
},
{
"input": "8581 6058 3019 2151 4140\n",
"output": "10431\n",
"type": "stdin_stdout"
},
{
"input": "41764 97259 54586 18013 75415\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "333625 453145 800800 907251 446081\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4394826 2233224 609367 3364334 898489\n",
"output": "9653757\n",
"type": "stdin_stdout"
},
{
"input": "13350712 76770926 61331309 8735000 9057368\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "142098087 687355301 987788392 75187408 868856364\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 3 1000000000 999999999\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "6 6 2 8 2\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "500 8 4 4 5\n",
"output": "625\n",
"type": "stdin_stdout"
},
{
"input": "20 4 6 2 3\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "10 3 9 1 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "120 18 6 3 5\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "30 4 6 2 2\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 7171 2727 191 272\n",
"output": "125391842\n",
"type": "stdin_stdout"
},
{
"input": "5 2 2 4 1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 2 2 3 3\n",
"output": "1500000000\n",
"type": "stdin_stdout"
},
{
"input": "24 4 6 5 7\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"input": "216 6 36 10 100\n",
"output": "900\n",
"type": "stdin_stdout"
},
{
"input": "100 12 6 1 10\n",
"output": "160\n",
"type": "stdin_stdout"
},
{
"input": "1000 4 8 3 5\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "10 2 4 3 6\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "10 5 10 2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "100000 3 9 1 2\n",
"output": "44444\n",
"type": "stdin_stdout"
},
{
"input": "10 2 4 1 100\n",
"output": "203\n",
"type": "stdin_stdout"
},
{
"input": "20 6 4 2 3\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "1200 4 16 2 3\n",
"output": "675\n",
"type": "stdin_stdout"
},
{
"input": "7 2 4 7 9\n",
"output": "23\n",
"type": "stdin_stdout"
},
{
"input": "24 6 4 15 10\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "50 2 8 15 13\n",
"output": "375\n",
"type": "stdin_stdout"
},
{
"input": "100 4 6 12 15\n",
"output": "444\n",
"type": "stdin_stdout"
},
{
"input": "56756 9 18 56 78\n",
"output": "422502\n",
"type": "stdin_stdout"
},
{
"input": "10000 4 6 10 12\n",
"output": "36662\n",
"type": "stdin_stdout"
},
{
"input": "20 2 4 3 5\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "24 4 6 10 100\n",
"output": "440\n",
"type": "stdin_stdout"
},
{
"input": "12 2 4 5 6\n",
"output": "33\n",
"type": "stdin_stdout"
},
{
"input": "100 2 4 1 100\n",
"output": "2525\n",
"type": "stdin_stdout"
},
{
"input": "1000 4 6 50 50\n",
"output": "16650\n",
"type": "stdin_stdout"
},
{
"input": "60 12 6 12 15\n",
"output": "150\n",
"type": "stdin_stdout"
},
{
"input": "1000 2 4 5 6\n",
"output": "2750\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 1 9999 5555\n",
"output": "9999000000000\n",
"type": "stdin_stdout"
},
{
"input": "50 2 2 4 5\n",
"output": "125\n",
"type": "stdin_stdout"
},
{
"input": "14 4 2 2 3\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "100 3 9 1 2\n",
"output": "44\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 4 6 1 1000000000\n",
"output": "166666666166666667\n",
"type": "stdin_stdout"
},
{
"input": "12 3 3 45 4\n",
"output": "180\n",
"type": "stdin_stdout"
},
{
"input": "12 2 4 5 9\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 2 2 1000000000 1000000000\n",
"output": "500000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "50 4 8 5 6\n",
"output": "66\n",
"type": "stdin_stdout"
},
{
"input": "32 4 16 6 3\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"input": "10000 2 4 1 1\n",
"output": "5000\n",
"type": "stdin_stdout"
},
{
"input": "8 2 4 100 1\n",
"output": "400\n",
"type": "stdin_stdout"
},
{
"input": "20 4 2 10 1\n",
"output": "55\n",
"type": "stdin_stdout"
},
{
"input": "5 2 2 12 15\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "20 2 12 5 6\n",
"output": "51\n",
"type": "stdin_stdout"
},
{
"input": "10 2 4 1 2\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "32 4 16 3 6\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "50 2 8 13 15\n",
"output": "337\n",
"type": "stdin_stdout"
},
{
"input": "12 6 4 10 9\n",
"output": "38\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999998 999999999 999999998 999999999\n",
"output": "1999999997\n",
"type": "stdin_stdout"
},
{
"input": "20 2 4 10 20\n",
"output": "150\n",
"type": "stdin_stdout"
},
{
"input": "13 4 6 12 15\n",
"output": "54\n",
"type": "stdin_stdout"
},
{
"input": "30 3 6 5 7\n",
"output": "60\n",
"type": "stdin_stdout"
},
{
"input": "7 2 4 2 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "100000 32 16 2 3\n",
"output": "18750\n",
"type": "stdin_stdout"
},
{
"input": "6 2 6 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "999999999 180 192 46642017 28801397\n",
"output": "399129078526502\n",
"type": "stdin_stdout"
},
{
"input": "12 4 6 1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10 2 4 10 5\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "1000000 4 6 12 14\n",
"output": "4333328\n",
"type": "stdin_stdout"
},
{
"input": "2000 20 30 3 5\n",
"output": "531\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 2 1 1\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "30 3 15 10 3\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1000 2 4 1 100\n",
"output": "25250\n",
"type": "stdin_stdout"
},
{
"input": "6 3 3 12 15\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "24 4 6 1 1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "20 2 12 4 5\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 9 15 10 10\n",
"output": "1555555550\n",
"type": "stdin_stdout"
},
{
"input": "16 2 4 1 2\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "100000 4 6 12 14\n",
"output": "433328\n",
"type": "stdin_stdout"
},
{
"input": "24 6 4 1 1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1000000 4 6 12 15\n",
"output": "4499994\n",
"type": "stdin_stdout"
},
{
"input": "100 2 4 5 6\n",
"output": "275\n",
"type": "stdin_stdout"
},
{
"input": "10 3 9 12 15\n",
"output": "39\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 1 999999999 999999999\n",
"output": "999999999000000000\n",
"type": "stdin_stdout"
},
{
"input": "6 2 4 2 3\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6 6 2 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100 2 4 3 7\n",
"output": "250\n",
"type": "stdin_stdout"
},
{
"input": "1000000 32 16 2 5\n",
"output": "312500\n",
"type": "stdin_stdout"
},
{
"input": "100 20 15 50 25\n",
"output": "375\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 100000007 100000013 10 3\n",
"output": "117\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 9999999 99999998 3 3\n",
"output": "330\n",
"type": "stdin_stdout"
},
{
"input": "10077696 24 36 10 100\n",
"output": "30792960\n",
"type": "stdin_stdout"
},
{
"input": "392852503 148746166 420198270 517065752 906699795\n",
"output": "1034131504\n",
"type": "stdin_stdout"
},
{
"input": "536870912 60000 72000 271828 314159\n",
"output": "4369119072\n",
"type": "stdin_stdout"
},
{
"input": "730114139 21550542 204644733 680083361 11353255\n",
"output": "22476810678\n",
"type": "stdin_stdout"
},
{
"input": "538228881 766493289 791886544 468896052 600136703\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "190 20 50 84 172\n",
"output": "1188\n",
"type": "stdin_stdout"
},
{
"input": "1000 5 10 80 90\n",
"output": "17000\n",
"type": "stdin_stdout"
},
{
"input": "99999999 999999998 1 271828 314159\n",
"output": "31415899685841\n",
"type": "stdin_stdout"
},
{
"input": "22 3 6 1243 1\n",
"output": "8701\n",
"type": "stdin_stdout"
},
{
"input": "15 10 5 2 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 1 1000000000 1000000000\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "62 62 42 78 124\n",
"output": "202\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "864351351 351 313 531 11\n",
"output": "1337898227\n",
"type": "stdin_stdout"
},
{
"input": "26 3 6 1244 1\n",
"output": "9952\n",
"type": "stdin_stdout"
},
{
"input": "1000 4 6 7 3\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "134312 3 6 33333 1\n",
"output": "1492318410\n",
"type": "stdin_stdout"
},
{
"input": "100 4 6 17 18\n",
"output": "577\n",
"type": "stdin_stdout"
},
{
"input": "6 2 4 5 6\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "8 2 4 10 1\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "10 2 4 3 3\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "1000 1000 1000 1000 1000\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "123123 3 6 34312 2\n",
"output": "1408198792\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 25 5 999 999\n",
"output": "199800000000\n",
"type": "stdin_stdout"
},
{
"input": "100 4 2 5 12\n",
"output": "600\n",
"type": "stdin_stdout"
},
{
"input": "50 2 4 4 5\n",
"output": "112\n",
"type": "stdin_stdout"
},
{
"input": "24 4 6 100 333\n",
"output": "1732\n",
"type": "stdin_stdout"
},
{
"input": "216 24 36 10 100\n",
"output": "660\n",
"type": "stdin_stdout"
},
{
"input": "50 6 4 3 8\n",
"output": "108\n",
"type": "stdin_stdout"
},
{
"input": "146 76 2 178 192\n",
"output": "14016\n",
"type": "stdin_stdout"
},
{
"input": "55 8 6 11 20\n",
"output": "224\n",
"type": "stdin_stdout"
},
{
"input": "5 2 4 6 16\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "54 2 52 50 188\n",
"output": "1488\n",
"type": "stdin_stdout"
},
{
"input": "536870912 60000000 72000000 271828 314159\n",
"output": "4101909\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 1 1 100\n",
"output": "100000000000\n",
"type": "stdin_stdout"
},
{
"input": "50 4 2 4 5\n",
"output": "125\n",
"type": "stdin_stdout"
},
{
"input": "198 56 56 122 118\n",
"output": "366\n",
"type": "stdin_stdout"
},
{
"input": "5 1000000000 1 12 15\n",
"output": "75\n",
"type": "stdin_stdout"
},
{
"input": "1000 6 12 5 6\n",
"output": "913\n",
"type": "stdin_stdout"
},
{
"input": "50 3 6 12 15\n",
"output": "216\n",
"type": "stdin_stdout"
},
{
"input": "333 300 300 300 300\n",
"output": "300\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000 1 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "188 110 110 200 78\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "100000 20 10 3 2\n",
"output": "25000\n",
"type": "stdin_stdout"
},
{
"input": "100 2 4 1 10\n",
"output": "275\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 2 1000000000 1 1000000\n",
"output": "500999999\n",
"type": "stdin_stdout"
},
{
"input": "20 3 6 5 7\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "50 4 6 4 5\n",
"output": "72\n",
"type": "stdin_stdout"
},
{
"input": "96 46 4 174 156\n",
"output": "3936\n",
"type": "stdin_stdout"
},
{
"input": "5 2 4 12 15\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "12 3 6 100 1\n",
"output": "400\n",
"type": "stdin_stdout"
},
{
"input": "100 4 2 10 32\n",
"output": "1600\n",
"type": "stdin_stdout"
},
{
"input": "1232 3 6 30000 3\n",
"output": "12300000\n",
"type": "stdin_stdout"
},
{
"input": "20 3 6 5 4\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "100 6 15 11 29\n",
"output": "317\n",
"type": "stdin_stdout"
},
{
"input": "10000000 4 8 100 200\n",
"output": "375000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 12 24 2 4\n",
"output": "249999998\n",
"type": "stdin_stdout"
},
{
"input": "123 3 6 3000 1\n",
"output": "123000\n",
"type": "stdin_stdout"
},
{
"input": "401523968 1536 2664 271828 314159\n",
"output": "117768531682\n",
"type": "stdin_stdout"
},
{
"input": "9 2 4 3 5\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "999999999 724362018 772432019 46201854 20017479\n",
"output": "66219333\n",
"type": "stdin_stdout"
},
{
"input": "100 2 4 1 1000\n",
"output": "25025\n",
"type": "stdin_stdout"
},
{
"input": "50 2 4 1 1000\n",
"output": "12013\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 2 1 2 1\n",
"output": "1500000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 2005034 2005046 15 12\n",
"output": "13446\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999999 1000000000 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "999999999 500000000 1 100 1000\n",
"output": "999999999000\n",
"type": "stdin_stdout"
},
{
"input": "50 8 6 3 4\n",
"output": "44\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 1 1000000000 1000000000\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999862 999999818 15 12\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 10000019 10000019 21 17\n",
"output": "2079\n",
"type": "stdin_stdout"
},
{
"input": "20 6 4 8 2\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 1 1 1\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 12345678 123456789 1000000000 999999999\n",
"output": "88999999992\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 2 999999937 100000000 100000000\n",
"output": "50000000100000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 1 1000000000 999999999\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 50001 100003 10 10\n",
"output": "299980\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 3 1 1\n",
"output": "333333334\n",
"type": "stdin_stdout"
},
{
"input": "10000 44 49 114 514\n",
"output": "130278\n",
"type": "stdin_stdout"
},
{
"input": "30 5 15 2 1\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "20 2 4 1 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "100 8 12 5 6\n",
"output": "88\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/678/C"
} | vfc_9798 |
apps | verifiable_code | 12 | Solve the following coding problem using the programming language python:
Vova has won $n$ trophies in different competitions. Each trophy is either golden or silver. The trophies are arranged in a row.
The beauty of the arrangement is the length of the longest subsegment consisting of golden trophies. Vova wants to swap two trophies (not necessarily adjacent ones) to make the arrangement as beautiful as possible — that means, to maximize the length of the longest such subsegment.
Help Vova! Tell him the maximum possible beauty of the arrangement if he is allowed to do at most one swap.
-----Input-----
The first line contains one integer $n$ ($2 \le n \le 10^5$) — the number of trophies.
The second line contains $n$ characters, each of them is either G or S. If the $i$-th character is G, then the $i$-th trophy is a golden one, otherwise it's a silver trophy.
-----Output-----
Print the maximum possible length of a subsegment of golden trophies, if Vova is allowed to do at most one swap.
-----Examples-----
Input
10
GGGSGGGSGG
Output
7
Input
4
GGGG
Output
4
Input
3
SSS
Output
0
-----Note-----
In the first example Vova has to swap trophies with indices $4$ and $10$. Thus he will obtain the sequence "GGGGGGGSGS", the length of the longest subsegment of golden trophies is $7$.
In the second example Vova can make no swaps at all. The length of the longest subsegment of golden trophies in the sequence is $4$.
In the third example Vova cannot do anything to make the length of the longest subsegment of golden trophies in the sequence greater than $0$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
A = input()
x = A.count('G')
num_1 = 0
num_2 = 0
max_num = 0
flag = 0
for i in range(n):
if A[i] == 'G' and flag == 0:
num_1 += 1
elif A[i] == 'G' and flag == 1:
num_2 += 1
elif A[i] == 'S' and flag == 0:
flag = 1
else:
if num_1 + num_2 + 1 <= x:
if num_1 + num_2 + 1 > max_num:
max_num = num_1 + num_2 + 1
num_1 = num_2
num_2 = 0
flag = 1
else:
if num_2 + num_1 > max_num:
max_num = num_1 + num_2
num_1 = num_2
num_2 = 0
flag = 1
if num_1 + num_2 + 1 <= x:
if num_1 + num_2 + 1 > max_num:
max_num = num_1 + num_2 + 1
else:
if num_2 + num_1 > max_num:
max_num = num_1 + num_2
print(max_num)
``` | {
"language": "python",
"test_cases": [
{
"input": "10\nGGGSGGGSGG\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "4\nGGGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\nSSS\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "11\nSGGGGSGGGGS\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "300\nSSGSGSSSGSGSSSSGGSGSSGGSGSGGSSSGSSGSGGSSGGSGSSGGSGGSSGSSSGSGSGSSGSGGSSSGSSGSSGGGGSSGSSGSSGSGGSSSSGGGGSSGSSSSSSSSGSSSSGSGSSSSSSSSGSGSSSSGSSGGSSGSGSSSSSSGSGSSSGGSSGSGSSGSSSSSSGGGSSSGSGSGSGGSGGGSSGSGSSSGSSGGSSGSSGGGGSGSSGSSSSGGSSSSGGSGSSSSSSGSSSGGGSGSGGSSGSSSSSSGGSSSGSSSSGGGSSGSSSGSGGGSSSSGSSSGSGSGGGGS\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "2\nSS\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\nSG\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\nGS\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\nGG\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\nGGSSGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\nGGSSG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "11\nSGGGGGSSSSG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7\nGGGSSSG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "15\nGGSSGGGGGGGSSGG\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "6\nGSSSGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\nGSSG\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\nGSSGGGGSSG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8\nGSSSGGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8\nSGGSGGGG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "12\nGGGSSGGGGSSG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\nGSGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\nGGGSSGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10\nGGGSSGGGGG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "12\nSSSGGSSSGGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10\nGGSSGGSSGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\nGSSSG\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\nGGGGGGGSSG\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "6\nGSSSSG\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\nGGGGSSSGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6\nGGGSGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6\nGSSGSG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "9\nGGGGSSGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8\nSGSSGGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5\nGSSGS\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\nGGGSSG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "94\nGGSSGGSGGSSSSSGSSSGGSSSSSGSGGGGSGSGSGSGSGSSSSGGGSSGSSSSGSSSSSSSSSGSSSGGSSGGSGSSGSGGGGSGGGSSSSS\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "20\nSGSSGGGSSSSSSGGGGGSS\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10\nGSSGSSSSSS\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\nGSGSGSGSGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "16\nGSGSSGSSGGGSSSGS\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8\nSGSSGSSG\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "26\nGGSSSSGSSSSSSSGSSSSSSGSSGS\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10\nSSGGSSGSSS\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "20\nGGGGSSGGGGSGGGSGGGGG\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "8\nGGGSSSGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "15\nGGSGGGSSGGGGGGG\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "8\nGSGSSGGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8\nGSSGGGGG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10\nSSSSGGSGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "21\nSSSGGGSGGGSSSGGGGGGGG\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10\nGGGGSSGGSG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5\nGSSGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\nGGSSSSG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\nGGGGSSG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "17\nGSGSSGGGSSGGGGSGS\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10\nGGSSGGSSSS\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8\nGSGSGGGG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7\nGSSGSSG\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\nGGSSGSSSGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10\nSSGGSSGGSS\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "20\nGSGGSSGGGSSSGGGGSSSS\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7\nGSGGSGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9\nGGGSSGGSG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\nSGS\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10\nSSGGGSSGGS\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\nGSSS\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7\nGGSSGGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "73\nSGSGGGGSSGSGSGGGSSSSSGGSGGSSSGSGSGSSSSGSGGGSSSSGSSGSGSSSGSGGGSSGGGGGGGSSS\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "9\nGGGSSGGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10\nSGSGGSGGGG\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5\nSSGSS\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\nGGSSS\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\nGGGGSSGGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7\nSGGSSGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\nSGSSG\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\nGSG\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7\nGGSSGGS\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8\nSSSGSSGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\nSSG\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8\nGGGSSGGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "11\nSGSGSGGGSSS\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6\nGGSSSG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\nGSGSGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8\nSSSGGSGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10\nGSSSSGGGGG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7\nGSSGGSG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10\nGSSSSSSSGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\nSSGGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\nSSSSSS\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "7\nGGSGGSG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "20\nSSSSSGGGGSGGGGGGGGGG\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "6\nGSSGGS\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8\nGSSGSSGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\nGSSGGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5\nSGSSS\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\nGGS\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\nSGGGSSGGSS\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\nGSS\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "11\nGSSSGGGGGGG\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10\nSSSGGSGGGG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "6\nSGGSSG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\nSGSSGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "20\nSSGSSGGGGSGGGGGGGGGG\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "8\nSGGGSSSG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "9\nGSGSSGGGS\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "89\nSGGSGSGGSSGGSGGSGGGGSSGSSSSSGGGGGGGGGGSSSSGGGGSSSSSGSSSSSGSGSGSGGGSSSGSGGGSSSGSGSGSSGSSGS\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "9\nGGGGGSSGG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "9\nSGSSGSSGS\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\nGGGSSSGGGS\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "20\nSGSSSGGGGSGGGGGGGGGG\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "7\nGSSGGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "18\nGSGSSSSGSSGGGSSSGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "7\nGSSSSGG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "9\nGSSGGSGGG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "17\nSSSSGSGSGSGSGSGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9\nGGSSGGGGS\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8\nGSSGGSSG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "15\nSGGSSGGSGGSGGGS\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7\nGSSSGSG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10\nGSSSGSSSSG\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8\nSGGSSGGS\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "13\nSSGGSSSSGSSSS\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "19\nGSGGGSSSGGGGGGGGGGG\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "15\nGSGGSGGSSGGGGGG\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "6\nSGSGSS\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "46\nGGGGGGGSSSSGGSGGGSSGSSGSSGGGSGSGGSSGSSSSGGSSSS\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "6\nGGSGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "40\nGSSGGGGGGGSSSGSGSSGGGSSSSGSGSSSSGSSSGSSS\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "8\nGGSSSSSG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "32\nGSGSSGGSGGSGGSGGSGGSGSGGSSSGGGGG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "8\nGSGGSGGS\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8\nGGSSSGGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10\nSGGSGGSGGG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10\nSSSGGGSSSG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "7\nSSGGSSG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "13\nGSGSSSSSSGGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "12\nGGSGGSSGGGGG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "9\nSGGSGGSGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "30\nGGGGGGSSGGSSSGSSGSSGSSSGGSSSGG\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "11\nGSGSGSSSGGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10\nSGGGGGGSSG\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "9\nSSSGGSSGS\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "20\nSGGGSSGGGGSSGSGGSSGS\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5\nSGGSS\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\nGGGS\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "90\nSSGSGGSGSGGGSSSSSGSGSSSGGSSGSGSGSSGGGSGGSGGGSSSSSGSGGGSSSSSGSSSSGGSGGSSSSGGGSSSGSSSGGGSGGG\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "30\nSGGGGSSSGSGSSSSSSGGGGSSGGSSSGS\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11\nGGSGSSGGGGG\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10\nGGGSSGGSGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10\nSGSGGGGSGG\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "4\nSSSS\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "9\nGGSGSSSGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "14\nGSGSSSSGGGSSGS\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\nSGG\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9\nGGGSSGGSS\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8\nGSSSGSGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "9\nSSSSGGSGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\nSSGG\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "38\nGSSSSSGGGSSGGGGSSSSSSGGGSSGSSGGGSSGGSS\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5\nGGSGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\nSGGS\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\nSSGSSSGGGS\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5\nGSGSG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\nSSGSG\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\nGSGGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "11\nSSGSSGGGSSG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "9\nSSGGGSGSS\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\nGGSG\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8\nGGSSSGGS\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\nSGGSGG\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10\nSSGGSSSSSS\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\nGGGSGGGGSS\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "170\nSGSGSGGGGGGSGSSGSGSGGSGGGGGGSSSGSGSGGSGGSGSGGGGSSSSSGSSGSSSSSGSGGGSGGSGSGSSGSSSGGSSGGGSGGGSSGGSGSGGSGGGGSGGGSSSGGGGSSSSSSGGSGSSSGSGGSSGGSGSGSGGGGSSSGGGGGGSGGSGGGGGGSGGGGS\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "10\nSGSGSSGGGG\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "183\nGSSSSGGSSGSGSSGGGGGSGSSGGGSSSSGGGSSSGSGSSSSGSGGSGSGSGGSGGGSSSGSGSGSSSGSGSGSGGSGSGGGGGSSGSGGGGSGGGGSSGGGSSSGSGGGSGGSSSGSGSSSSSSSSSSGSSGSGSSGGSGSSSGGGSGSGSGSGSSSSGGGSGSGGGGGSGSSSSSGGSSG\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "123\nGSSSSGGGSSSGSGGSGGSGGGGGGSGSGGSGSGGGGGGGSSGGSGGGGSGGSGSSSSSSGGGSGGGGGGGSGGGSSGSSSGGGGSGGGSSGSSGSSGSSGGSGGSGSSSSGSSGGGGGGSSS\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "100\nSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "174\nGGGGSSSGGGGSGGSSSGSSSGGGGGGGSSSSSSSSGGSGSSSSGGGSSGSGGSGSSSSSGGGSSGGGGSGSSGSSGSGSSSGGSGSGSGSSSGSGGSGGSSGGSSSSGSSGSSGGSSGSSGGGGSSGSSGGGGGSSSSGGGGSSGSGSGSGGGSGSGGGSGGGSGSGSGGGGG\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "181\nGGGGGGGGGGGSSGGGGGGGSSSGSSSSGSSGSSSGGSGGSGGSSGSSGSSGGSGGGSSGGGSGGGGGSGGGSGSGSGSSGSSGGSGGGGSSGGSGGSGSSSSGSSGGSGGSSSGSSGSSGGGSGSSGGGSGSSGGGSSSSSSGGSSSSGSGSSSSSGGSGSSSGGGGSSGGGSGGGSGSS\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "169\nGSGSGSGGSGSSSGSSGSGGGSGGGSSSGGSGSSSSSGGGGSSSSGGGSSGSGGSGGSGGSSGGGGSSGSSGSSSGSGGSSGGSSGGSSGSGSSGSSSSSSGSGSSGSSSGGSGSGGSSSSGSGGSGSSSSGSGGSSGGGSGGSGGSSSSGSSGSSSSSGGGGGGGSGS\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "33\nGGGGSSSGGSSSGGGGGGGSGGGGSGGGGGGGG\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "134\nGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGSGS\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1082/B"
} | vfc_9802 |
apps | verifiable_code | 13 | Solve the following coding problem using the programming language python:
Now you can take online courses in the Berland State University! Polycarp needs to pass k main online courses of his specialty to get a diploma. In total n courses are availiable for the passage.
The situation is complicated by the dependence of online courses, for each course there is a list of those that must be passed before starting this online course (the list can be empty, it means that there is no limitation).
Help Polycarp to pass the least number of courses in total to get the specialty (it means to pass all main and necessary courses). Write a program which prints the order of courses.
Polycarp passes courses consistently, he starts the next course when he finishes the previous one. Each course can't be passed more than once.
-----Input-----
The first line contains n and k (1 ≤ k ≤ n ≤ 10^5) — the number of online-courses and the number of main courses of Polycarp's specialty.
The second line contains k distinct integers from 1 to n — numbers of main online-courses of Polycarp's specialty.
Then n lines follow, each of them describes the next course: the i-th of them corresponds to the course i. Each line starts from the integer t_{i} (0 ≤ t_{i} ≤ n - 1) — the number of courses on which the i-th depends. Then there follows the sequence of t_{i} distinct integers from 1 to n — numbers of courses in random order, on which the i-th depends. It is guaranteed that no course can depend on itself.
It is guaranteed that the sum of all values t_{i} doesn't exceed 10^5.
-----Output-----
Print -1, if there is no the way to get a specialty.
Otherwise, in the first line print the integer m — the minimum number of online-courses which it is necessary to pass to get a specialty. In the second line print m distinct integers — numbers of courses which it is necessary to pass in the chronological order of their passage. If there are several answers it is allowed to print any of them.
-----Examples-----
Input
6 2
5 3
0
0
0
2 2 1
1 4
1 5
Output
5
1 2 3 4 5
Input
9 3
3 9 5
0
0
3 9 4 5
0
0
1 8
1 6
1 2
2 1 2
Output
6
1 2 9 4 5 3
Input
3 3
1 2 3
1 2
1 3
1 1
Output
-1
-----Note-----
In the first test firstly you can take courses number 1 and 2, after that you can take the course number 4, then you can take the course number 5, which is the main. After that you have to take only the course number 3, which is the last not passed main course.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#This code is dedicated to Vlada S.
class Course:
def __init__(self, reqs, number):
self.reqs = list(map(int, reqs.split()[1:]))
self.available = False
self.in_stack = False
self.number = number
n, k = list(map(int, input().split()))
requirements = list(map(int, input().split()))
courses = {}
answer = ""
for i in range(n):
courses[i + 1]= Course(input(), i + 1)
for i in range(len(requirements)):
requirements[i] = courses[requirements[i]]
while requirements:
data = {}
course = requirements.pop()
if not course.available:
requirements.append(course)
done = True
for c in course.reqs:
c = courses[c]
if not c.available:
requirements.append(c)
done = False
if done:
answer += " " + str(course.number)
course.available = True
else:
if course.in_stack:
print(-1)
break
course.in_stack = True
else:
print(answer.count(" "))
print(answer[1:])
``` | {
"language": "python",
"test_cases": [
{
"input": "6 2\n5 3\n0\n0\n0\n2 2 1\n1 4\n1 5\n",
"output": "5\n1 2 3 4 5 \n",
"type": "stdin_stdout"
},
{
"input": "9 3\n3 9 5\n0\n0\n3 9 4 5\n0\n0\n1 8\n1 6\n1 2\n2 1 2\n",
"output": "6\n1 2 9 4 5 3 \n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 2 3\n1 2\n1 3\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n2 1 4\n0\n0\n1 5\n0\n0\n",
"output": "3\n1 2 4 \n",
"type": "stdin_stdout"
},
{
"input": "5 2\n4 1\n0\n1 4\n1 5\n0\n2 1 2\n",
"output": "2\n1 4 \n",
"type": "stdin_stdout"
},
{
"input": "5 2\n4 5\n2 3 4\n1 4\n1 4\n0\n0\n",
"output": "2\n4 5 \n",
"type": "stdin_stdout"
},
{
"input": "6 6\n5 4 3 2 6 1\n1 4\n0\n2 2 6\n2 3 6\n3 3 4 6\n0\n",
"output": "6\n2 6 3 4 1 5 \n",
"type": "stdin_stdout"
},
{
"input": "6 6\n4 1 6 3 2 5\n2 3 5\n4 1 3 4 5\n1 5\n2 3 5\n0\n2 1 5\n",
"output": "6\n5 3 1 4 2 6 \n",
"type": "stdin_stdout"
},
{
"input": "6 5\n2 4 1 3 5\n0\n0\n0\n1 1\n0\n1 3\n",
"output": "5\n1 2 3 4 5 \n",
"type": "stdin_stdout"
},
{
"input": "7 6\n4 3 2 1 6 5\n0\n2 4 5\n1 6\n1 7\n1 6\n0\n1 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "7 2\n1 5\n5 2 3 4 5 6\n2 1 7\n0\n3 1 2 7\n0\n2 5 7\n0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "7 6\n2 5 3 1 7 6\n1 7\n2 3 7\n0\n0\n0\n1 3\n1 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 3 2\n0\n1 3\n1 1\n",
"output": "3\n1 3 2 \n",
"type": "stdin_stdout"
},
{
"input": "10 1\n1\n1 5\n1 3\n0\n1 10\n0\n1 8\n1 1\n2 7 4\n2 6 2\n0\n",
"output": "2\n5 1 \n",
"type": "stdin_stdout"
},
{
"input": "1 1\n1\n0\n",
"output": "1\n1 \n",
"type": "stdin_stdout"
},
{
"input": "2 2\n1 2\n0\n0\n",
"output": "2\n1 2 \n",
"type": "stdin_stdout"
},
{
"input": "2 2\n2 1\n0\n0\n",
"output": "2\n1 2 \n",
"type": "stdin_stdout"
},
{
"input": "2 1\n1\n1 2\n0\n",
"output": "2\n2 1 \n",
"type": "stdin_stdout"
},
{
"input": "2 1\n1\n0\n0\n",
"output": "1\n1 \n",
"type": "stdin_stdout"
},
{
"input": "2 1\n2\n0\n1 1\n",
"output": "2\n1 2 \n",
"type": "stdin_stdout"
},
{
"input": "2 1\n2\n0\n0\n",
"output": "1\n2 \n",
"type": "stdin_stdout"
},
{
"input": "3 1\n1\n2 2 3\n0\n1 2\n",
"output": "3\n2 3 1 \n",
"type": "stdin_stdout"
},
{
"input": "3 3\n2 1 3\n0\n2 1 3\n1 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n8 4 1\n1 3\n0\n0\n0\n1 1\n2 10 9\n1 4\n3 5 1 2\n2 2 7\n2 8 4\n",
"output": "6\n3 1 2 4 5 8 \n",
"type": "stdin_stdout"
},
{
"input": "6 6\n1 2 3 4 5 6\n2 2 6\n1 3\n2 4 5\n0\n1 4\n1 2\n",
"output": "6\n4 5 3 2 6 1 \n",
"type": "stdin_stdout"
},
{
"input": "3 2\n1 3\n0\n0\n1 1\n",
"output": "2\n1 3 \n",
"type": "stdin_stdout"
},
{
"input": "3 1\n1\n2 2 3\n0\n0\n",
"output": "3\n2 3 1 \n",
"type": "stdin_stdout"
},
{
"input": "3 3\n3 1 2\n0\n0\n0\n",
"output": "3\n1 2 3 \n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 2 3\n0\n0\n0\n",
"output": "3\n1 2 3 \n",
"type": "stdin_stdout"
},
{
"input": "3 2\n2 1\n0\n0\n0\n",
"output": "2\n1 2 \n",
"type": "stdin_stdout"
},
{
"input": "3 3\n3 2 1\n0\n0\n0\n",
"output": "3\n1 2 3 \n",
"type": "stdin_stdout"
},
{
"input": "3 3\n3 2 1\n0\n0\n0\n",
"output": "3\n1 2 3 \n",
"type": "stdin_stdout"
},
{
"input": "3 3\n3 1 2\n0\n0\n0\n",
"output": "3\n1 2 3 \n",
"type": "stdin_stdout"
},
{
"input": "3 2\n3 2\n0\n1 3\n1 1\n",
"output": "3\n1 3 2 \n",
"type": "stdin_stdout"
},
{
"input": "3 3\n2 1 3\n0\n1 1\n0\n",
"output": "3\n1 2 3 \n",
"type": "stdin_stdout"
},
{
"input": "3 2\n3 1\n1 3\n0\n0\n",
"output": "2\n3 1 \n",
"type": "stdin_stdout"
},
{
"input": "3 1\n3\n0\n0\n1 2\n",
"output": "2\n2 3 \n",
"type": "stdin_stdout"
},
{
"input": "3 1\n1\n0\n1 1\n0\n",
"output": "1\n1 \n",
"type": "stdin_stdout"
},
{
"input": "3 2\n3 2\n0\n1 1\n1 2\n",
"output": "3\n1 2 3 \n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 2 3\n0\n1 1\n2 1 2\n",
"output": "3\n1 2 3 \n",
"type": "stdin_stdout"
},
{
"input": "4 2\n2 3\n2 3 4\n1 1\n0\n0\n",
"output": "4\n3 4 1 2 \n",
"type": "stdin_stdout"
},
{
"input": "4 4\n3 2 1 4\n2 2 3\n1 1\n1 2\n1 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n4 3\n0\n0\n0\n0\n",
"output": "2\n3 4 \n",
"type": "stdin_stdout"
},
{
"input": "4 1\n1\n2 2 3\n0\n2 2 4\n0\n",
"output": "4\n2 4 3 1 \n",
"type": "stdin_stdout"
},
{
"input": "4 1\n2\n0\n0\n2 1 4\n2 1 2\n",
"output": "1\n2 \n",
"type": "stdin_stdout"
},
{
"input": "4 4\n3 1 4 2\n1 2\n1 3\n1 2\n0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n1 3 2 4\n1 3\n1 3\n0\n1 2\n",
"output": "4\n3 1 2 4 \n",
"type": "stdin_stdout"
},
{
"input": "4 1\n4\n2 2 4\n0\n1 2\n0\n",
"output": "1\n4 \n",
"type": "stdin_stdout"
},
{
"input": "4 2\n3 1\n0\n0\n0\n0\n",
"output": "2\n1 3 \n",
"type": "stdin_stdout"
},
{
"input": "4 4\n3 1 4 2\n1 4\n0\n0\n0\n",
"output": "4\n4 1 2 3 \n",
"type": "stdin_stdout"
},
{
"input": "4 1\n1\n1 4\n2 1 3\n1 4\n1 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n3 2\n0\n1 4\n1 1\n0\n",
"output": "4\n1 4 2 3 \n",
"type": "stdin_stdout"
},
{
"input": "4 4\n2 3 1 4\n0\n2 1 3\n2 1 4\n0\n",
"output": "4\n1 4 3 2 \n",
"type": "stdin_stdout"
},
{
"input": "4 4\n4 1 2 3\n2 2 4\n0\n0\n0\n",
"output": "4\n2 4 1 3 \n",
"type": "stdin_stdout"
},
{
"input": "4 1\n1\n0\n1 1\n0\n0\n",
"output": "1\n1 \n",
"type": "stdin_stdout"
},
{
"input": "5 1\n5\n0\n1 1\n2 2 5\n0\n0\n",
"output": "1\n5 \n",
"type": "stdin_stdout"
},
{
"input": "5 5\n1 2 4 3 5\n0\n0\n2 1 2\n1 5\n0\n",
"output": "5\n1 2 3 5 4 \n",
"type": "stdin_stdout"
},
{
"input": "5 5\n2 1 5 4 3\n1 4\n0\n0\n0\n1 2\n",
"output": "5\n4 1 2 3 5 \n",
"type": "stdin_stdout"
},
{
"input": "5 2\n2 4\n1 2\n0\n1 2\n1 2\n0\n",
"output": "2\n2 4 \n",
"type": "stdin_stdout"
},
{
"input": "5 2\n2 1\n1 3\n1 3\n1 1\n3 1 2 3\n1 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n5 2 1 3\n2 3 5\n1 3\n0\n0\n2 2 4\n",
"output": "5\n3 2 4 5 1 \n",
"type": "stdin_stdout"
},
{
"input": "5 4\n5 1 4 2\n0\n0\n1 5\n1 1\n0\n",
"output": "4\n1 2 4 5 \n",
"type": "stdin_stdout"
},
{
"input": "5 2\n1 3\n0\n2 4 5\n0\n1 2\n2 1 2\n",
"output": "2\n1 3 \n",
"type": "stdin_stdout"
},
{
"input": "5 1\n5\n1 4\n2 1 4\n2 4 5\n2 2 5\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n3 2 1 4\n1 2\n0\n0\n0\n0\n",
"output": "4\n2 1 3 4 \n",
"type": "stdin_stdout"
},
{
"input": "5 1\n2\n3 2 3 4\n0\n2 2 4\n0\n4 1 2 3 4\n",
"output": "1\n2 \n",
"type": "stdin_stdout"
},
{
"input": "5 3\n5 2 4\n1 4\n0\n0\n0\n0\n",
"output": "3\n2 4 5 \n",
"type": "stdin_stdout"
},
{
"input": "5 1\n3\n2 4 5\n0\n0\n0\n1 3\n",
"output": "1\n3 \n",
"type": "stdin_stdout"
},
{
"input": "5 3\n2 5 1\n1 2\n0\n0\n1 5\n0\n",
"output": "3\n2 1 5 \n",
"type": "stdin_stdout"
},
{
"input": "5 3\n4 2 3\n0\n0\n1 2\n0\n1 4\n",
"output": "3\n2 3 4 \n",
"type": "stdin_stdout"
},
{
"input": "6 4\n2 1 4 3\n3 3 4 5\n1 4\n0\n1 3\n4 2 3 4 6\n1 3\n",
"output": "6\n3 4 2 6 5 1 \n",
"type": "stdin_stdout"
},
{
"input": "6 2\n3 6\n2 2 3\n0\n1 1\n1 6\n0\n0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n2\n0\n0\n1 6\n0\n1 2\n0\n",
"output": "1\n2 \n",
"type": "stdin_stdout"
},
{
"input": "6 3\n6 5 1\n0\n1 1\n0\n1 3\n0\n1 5\n",
"output": "3\n1 5 6 \n",
"type": "stdin_stdout"
},
{
"input": "6 6\n1 3 6 5 4 2\n0\n0\n0\n0\n0\n0\n",
"output": "6\n1 2 3 4 5 6 \n",
"type": "stdin_stdout"
},
{
"input": "6 5\n3 4 1 6 5\n2 2 6\n2 4 5\n1 1\n0\n1 4\n0\n",
"output": "6\n4 5 2 6 1 3 \n",
"type": "stdin_stdout"
},
{
"input": "6 2\n5 2\n1 4\n0\n1 2\n0\n0\n1 5\n",
"output": "2\n2 5 \n",
"type": "stdin_stdout"
},
{
"input": "6 6\n4 5 1 6 3 2\n0\n1 6\n1 1\n2 1 3\n1 1\n2 1 3\n",
"output": "6\n1 3 6 2 4 5 \n",
"type": "stdin_stdout"
},
{
"input": "6 6\n3 2 4 1 5 6\n1 6\n1 1\n0\n1 5\n0\n0\n",
"output": "6\n6 1 2 3 5 4 \n",
"type": "stdin_stdout"
},
{
"input": "6 1\n3\n2 4 6\n2 4 6\n2 1 2\n1 2\n1 2\n1 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 6\n5 1 2 3 6 4\n0\n0\n0\n0\n1 4\n1 1\n",
"output": "6\n1 2 3 4 5 6 \n",
"type": "stdin_stdout"
},
{
"input": "6 5\n3 6 2 4 1\n1 4\n1 3\n0\n0\n0\n2 1 5\n",
"output": "6\n4 1 3 2 5 6 \n",
"type": "stdin_stdout"
},
{
"input": "6 4\n4 3 6 5\n0\n0\n3 1 4 5\n1 6\n1 6\n0\n",
"output": "5\n1 6 4 5 3 \n",
"type": "stdin_stdout"
},
{
"input": "6 1\n1\n0\n0\n1 5\n0\n0\n1 5\n",
"output": "1\n1 \n",
"type": "stdin_stdout"
},
{
"input": "6 6\n4 2 5 6 1 3\n1 3\n0\n2 5 6\n2 2 6\n1 2\n1 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "7 7\n1 7 6 2 5 4 3\n0\n2 5 6\n1 5\n1 2\n0\n1 1\n1 1\n",
"output": "7\n1 5 6 2 3 4 7 \n",
"type": "stdin_stdout"
},
{
"input": "7 6\n6 3 5 1 4 7\n0\n0\n0\n0\n1 1\n1 2\n1 1\n",
"output": "7\n1 2 3 4 5 6 7 \n",
"type": "stdin_stdout"
},
{
"input": "7 2\n2 3\n0\n0\n0\n0\n0\n1 4\n0\n",
"output": "2\n2 3 \n",
"type": "stdin_stdout"
},
{
"input": "7 4\n7 5 4 2\n0\n2 6 7\n0\n1 3\n2 2 6\n0\n2 3 4\n",
"output": "6\n6 3 4 7 2 5 \n",
"type": "stdin_stdout"
},
{
"input": "7 6\n5 4 2 1 6 7\n2 2 7\n1 5\n0\n0\n1 3\n1 2\n0\n",
"output": "7\n3 5 2 7 1 4 6 \n",
"type": "stdin_stdout"
},
{
"input": "7 4\n2 1 6 7\n0\n2 3 6\n1 6\n0\n2 1 3\n1 7\n0\n",
"output": "5\n1 7 6 3 2 \n",
"type": "stdin_stdout"
},
{
"input": "7 2\n5 1\n4 2 5 6 7\n1 5\n5 1 2 5 6 7\n1 2\n0\n0\n4 2 4 5 6\n",
"output": "6\n5 2 6 4 7 1 \n",
"type": "stdin_stdout"
},
{
"input": "7 1\n5\n2 2 5\n0\n2 5 7\n0\n1 6\n0\n0\n",
"output": "2\n6 5 \n",
"type": "stdin_stdout"
},
{
"input": "7 6\n5 7 2 4 3 6\n2 5 7\n0\n3 2 5 7\n2 2 6\n0\n0\n2 2 5\n",
"output": "6\n2 5 7 3 6 4 \n",
"type": "stdin_stdout"
},
{
"input": "7 4\n6 4 7 3\n0\n0\n2 2 5\n1 6\n2 1 7\n2 1 2\n0\n",
"output": "7\n1 2 7 5 3 6 4 \n",
"type": "stdin_stdout"
},
{
"input": "7 5\n1 5 4 7 2\n1 4\n4 1 4 6 7\n2 1 4\n1 6\n3 3 4 7\n0\n0\n",
"output": "7\n6 4 1 7 2 3 5 \n",
"type": "stdin_stdout"
},
{
"input": "2 1\n1\n0\n1 1\n",
"output": "1\n1 \n",
"type": "stdin_stdout"
},
{
"input": "2 1\n1\n1 2\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n2\n1 2\n0\n",
"output": "1\n2 \n",
"type": "stdin_stdout"
},
{
"input": "2 1\n2\n1 2\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n1 2\n1 2\n0\n",
"output": "2\n2 1 \n",
"type": "stdin_stdout"
},
{
"input": "2 2\n2 1\n0\n1 1\n",
"output": "2\n1 2 \n",
"type": "stdin_stdout"
},
{
"input": "2 2\n2 1\n1 2\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "7 1\n4\n0\n6 1 3 4 5 6 7\n4 1 4 6 7\n2 1 7\n4 1 3 6 7\n2 3 4\n0\n",
"output": "3\n1 7 4 \n",
"type": "stdin_stdout"
},
{
"input": "7 2\n1 2\n0\n0\n3 2 4 6\n1 3\n1 6\n1 5\n0\n",
"output": "2\n1 2 \n",
"type": "stdin_stdout"
},
{
"input": "7 4\n1 7 6 2\n1 7\n0\n0\n0\n1 1\n0\n0\n",
"output": "4\n7 1 2 6 \n",
"type": "stdin_stdout"
},
{
"input": "7 6\n3 7 4 1 6 2\n2 4 6\n0\n0\n3 2 3 5\n1 3\n1 2\n3 1 5 6\n",
"output": "7\n2 3 5 4 6 1 7 \n",
"type": "stdin_stdout"
},
{
"input": "8 5\n7 1 2 8 3\n0\n0\n0\n0\n0\n0\n0\n0\n",
"output": "5\n1 2 3 7 8 \n",
"type": "stdin_stdout"
},
{
"input": "8 3\n4 8 7\n0\n1 3\n0\n1 2\n0\n0\n1 1\n0\n",
"output": "6\n1 3 2 4 7 8 \n",
"type": "stdin_stdout"
},
{
"input": "8 2\n2 6\n0\n0\n0\n2 5 7\n0\n2 1 2\n0\n3 1 2 3\n",
"output": "3\n1 2 6 \n",
"type": "stdin_stdout"
},
{
"input": "8 6\n8 3 6 4 7 5\n0\n1 4\n1 4\n1 8\n1 7\n1 4\n0\n0\n",
"output": "6\n8 4 3 7 5 6 \n",
"type": "stdin_stdout"
},
{
"input": "8 7\n2 5 3 6 4 8 1\n3 3 5 6\n1 3\n2 4 5\n4 1 2 5 6\n2 1 2\n2 2 8\n1 2\n2 6 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "8 5\n2 5 8 3 1\n3 2 5 6\n1 5\n1 4\n5 1 5 6 7 8\n0\n2 2 8\n4 1 3 5 6\n1 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "8 5\n6 4 7 5 1\n1 7\n1 6\n1 1\n0\n0\n0\n1 5\n1 7\n",
"output": "5\n5 7 1 4 6 \n",
"type": "stdin_stdout"
},
{
"input": "8 3\n3 1 8\n0\n3 4 6 7\n2 6 7\n2 3 6\n2 4 6\n1 1\n1 1\n1 3\n",
"output": "5\n1 6 7 3 8 \n",
"type": "stdin_stdout"
},
{
"input": "8 8\n6 3 1 2 4 8 5 7\n0\n0\n0\n2 5 7\n0\n1 5\n0\n1 1\n",
"output": "8\n1 2 3 5 7 4 6 8 \n",
"type": "stdin_stdout"
},
{
"input": "8 5\n2 1 5 7 6\n1 8\n3 3 4 6\n0\n0\n1 6\n0\n0\n0\n",
"output": "8\n8 1 3 4 6 2 5 7 \n",
"type": "stdin_stdout"
},
{
"input": "8 8\n3 1 2 7 8 4 5 6\n2 4 8\n2 3 8\n1 6\n0\n2 4 6\n0\n5 2 3 4 5 8\n2 3 4\n",
"output": "8\n4 6 3 8 1 2 5 7 \n",
"type": "stdin_stdout"
},
{
"input": "8 3\n4 3 1\n0\n0\n0\n0\n0\n0\n0\n0\n",
"output": "3\n1 3 4 \n",
"type": "stdin_stdout"
},
{
"input": "8 1\n3\n0\n3 1 3 6\n0\n0\n1 1\n0\n1 6\n1 7\n",
"output": "1\n3 \n",
"type": "stdin_stdout"
},
{
"input": "8 8\n5 8 7 2 1 3 4 6\n1 3\n3 1 3 4\n0\n0\n1 1\n1 5\n0\n2 4 6\n",
"output": "8\n3 1 4 2 5 6 7 8 \n",
"type": "stdin_stdout"
},
{
"input": "8 7\n6 3 7 8 1 5 4\n0\n2 1 5\n0\n2 7 8\n1 4\n0\n0\n0\n",
"output": "7\n1 3 7 8 4 5 6 \n",
"type": "stdin_stdout"
},
{
"input": "9 9\n6 3 1 4 2 9 5 7 8\n0\n0\n0\n0\n0\n0\n0\n0\n0\n",
"output": "9\n1 2 3 4 5 6 7 8 9 \n",
"type": "stdin_stdout"
},
{
"input": "9 3\n5 7 3\n3 3 4 5\n4 4 6 7 9\n2 1 2\n2 3 5\n1 3\n4 4 5 7 8\n3 1 4 5\n3 1 3 4\n7 1 2 4 5 6 7 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9 6\n1 6 7 4 5 3\n2 2 6\n3 5 6 8\n5 2 4 5 6 9\n3 5 6 8\n0\n0\n5 2 3 5 6 9\n4 1 3 5 6\n5 1 2 4 6 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9 8\n4 2 9 1 8 3 7 6\n0\n2 1 8\n0\n0\n1 1\n2 1 8\n2 6 8\n3 4 5 9\n5 1 2 5 7 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9 2\n6 9\n2 3 9\n0\n1 8\n1 6\n3 3 6 7\n1 2\n1 9\n0\n0\n",
"output": "3\n2 6 9 \n",
"type": "stdin_stdout"
},
{
"input": "9 6\n5 4 3 2 6 7\n3 4 5 9\n1 6\n4 1 5 8 9\n3 3 5 6\n0\n0\n2 3 8\n1 3\n0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9 8\n2 8 4 7 3 6 9 5\n0\n1 4\n0\n0\n0\n1 8\n0\n3 2 3 7\n0\n",
"output": "8\n4 2 3 5 7 8 6 9 \n",
"type": "stdin_stdout"
},
{
"input": "9 6\n6 7 1 5 9 2\n0\n0\n0\n0\n1 4\n0\n0\n2 1 3\n1 6\n",
"output": "7\n1 2 4 5 6 7 9 \n",
"type": "stdin_stdout"
},
{
"input": "9 4\n5 1 2 3\n1 7\n0\n1 8\n0\n0\n3 1 5 8\n1 6\n2 5 7\n2 1 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9 8\n4 8 6 9 5 7 2 3\n0\n1 4\n0\n3 2 6 8\n1 6\n1 7\n0\n0\n2 3 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9 3\n8 5 3\n3 3 6 9\n1 5\n1 5\n1 8\n1 2\n1 3\n1 9\n1 5\n0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9 6\n7 3 1 6 4 2\n1 3\n0\n1 7\n1 8\n1 4\n1 7\n1 8\n0\n2 1 7\n",
"output": "7\n8 7 3 1 2 4 6 \n",
"type": "stdin_stdout"
},
{
"input": "9 2\n7 4\n1 2\n0\n1 7\n0\n1 1\n0\n0\n2 2 6\n1 5\n",
"output": "2\n4 7 \n",
"type": "stdin_stdout"
},
{
"input": "9 5\n3 8 2 5 1\n1 5\n3 1 6 7\n3 4 6 8\n3 2 6 9\n2 7 9\n2 5 7\n1 2\n2 4 5\n2 1 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9 4\n6 9 7 8\n3 5 8 9\n1 3\n1 4\n0\n2 4 9\n2 4 9\n5 2 3 4 8 9\n0\n1 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 1\n7\n2 4 10\n1 8\n2 4 8\n0\n1 3\n1 2\n2 3 5\n1 7\n0\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 2\n9 4\n0\n0\n0\n0\n1 7\n0\n0\n1 9\n0\n0\n",
"output": "2\n4 9 \n",
"type": "stdin_stdout"
},
{
"input": "10 3\n7 5 3\n3 3 4 5\n1 10\n1 7\n3 2 6 7\n1 7\n0\n0\n3 1 4 6\n3 2 3 5\n1 6\n",
"output": "3\n7 3 5 \n",
"type": "stdin_stdout"
},
{
"input": "10 1\n1\n1 5\n1 1\n3 4 6 10\n1 1\n0\n4 1 2 5 9\n4 1 6 9 10\n6 1 2 3 6 9 10\n2 2 5\n4 1 2 5 9\n",
"output": "2\n5 1 \n",
"type": "stdin_stdout"
},
{
"input": "10 1\n4\n0\n0\n0\n0\n1 10\n0\n0\n0\n0\n0\n",
"output": "1\n4 \n",
"type": "stdin_stdout"
},
{
"input": "10 10\n6 2 4 5 8 1 9 3 10 7\n4 2 7 8 9\n2 7 9\n5 1 6 8 9 10\n2 7 9\n6 1 4 6 7 8 9\n1 8\n0\n2 4 9\n0\n4 2 4 7 9\n",
"output": "10\n7 9 2 4 8 1 6 10 3 5 \n",
"type": "stdin_stdout"
},
{
"input": "10 5\n2 1 10 4 9\n2 3 6\n5 1 6 7 8 10\n3 4 6 7\n2 1 6\n2 6 7\n1 3\n1 4\n3 5 6 10\n4 1 2 8 10\n4 1 5 6 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n4 8 3 1 6\n0\n1 10\n0\n0\n1 3\n2 3 5\n1 3\n1 10\n2 1 6\n0\n",
"output": "7\n1 3 4 5 6 10 8 \n",
"type": "stdin_stdout"
},
{
"input": "10 8\n1 5 4 10 6 2 3 9\n7 3 4 5 6 7 8 10\n1 5\n4 2 5 7 10\n3 2 5 6\n0\n3 2 5 7\n1 2\n8 1 2 3 5 6 7 9 10\n4 2 4 6 7\n3 4 6 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n6 9 8 5 2\n2 7 9\n4 4 5 6 7\n2 6 7\n2 5 8\n2 6 9\n1 9\n2 2 6\n3 1 2 7\n3 3 5 6\n6 1 2 5 6 8 9\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 7\n7 10 5 1 9 4 3\n4 2 4 9 10\n5 1 4 6 8 9\n7 2 4 5 6 7 8 10\n3 3 5 10\n2 7 10\n3 4 5 9\n6 1 2 3 4 6 8\n4 1 3 4 10\n1 5\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 9\n5 1 3 6 10 8 2 9 7\n0\n0\n2 1 6\n1 3\n1 4\n2 5 7\n1 6\n0\n1 8\n0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 5 10 9\n2 2 4\n5 3 4 6 7 10\n2 7 10\n4 1 3 8 10\n2 6 10\n2 7 10\n1 1\n3 6 7 10\n1 7\n3 1 7 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 8\n6 8 2 1 7 10 3 4\n0\n2 1 4\n2 6 7\n0\n3 1 8 9\n3 1 8 9\n0\n0\n1 6\n1 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 6 3\n1 4\n1 4\n0\n0\n2 3 10\n1 2\n0\n1 4\n0\n1 2\n",
"output": "5\n4 1 2 3 6 \n",
"type": "stdin_stdout"
},
{
"input": "11 2\n10 7\n5 2 3 6 10 11\n0\n1 8\n5 1 3 6 9 10\n4 1 2 3 6\n1 5\n5 2 6 9 10 11\n5 2 3 4 7 11\n3 3 6 8\n6 2 4 5 6 8 9\n3 2 3 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "11 11\n3 2 1 7 8 4 10 11 9 6 5\n3 2 7 11\n0\n0\n1 11\n1 1\n1 8\n2 4 5\n0\n1 4\n0\n0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "11 7\n11 2 1 7 9 8 6\n0\n7 3 4 5 6 8 10 11\n3 1 5 8\n1 11\n3 1 7 8\n7 1 3 4 5 7 8 10\n3 4 6 8\n1 5\n2 8 10\n4 1 4 5 7\n5 1 4 6 8 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "11 6\n7 1 10 3 2 11\n0\n1 11\n0\n0\n1 9\n1 5\n0\n0\n0\n0\n0\n",
"output": "6\n1 11 2 3 7 10 \n",
"type": "stdin_stdout"
},
{
"input": "11 7\n6 9 7 3 4 10 11\n4 3 6 8 11\n3 3 5 9\n2 6 7\n1 6\n1 4\n0\n0\n2 7 9\n0\n2 4 11\n3 6 7 9\n",
"output": "7\n6 7 3 4 9 11 10 \n",
"type": "stdin_stdout"
},
{
"input": "11 5\n10 11 8 2 7\n1 9\n1 3\n0\n1 6\n1 1\n0\n0\n1 2\n2 4 8\n0\n0\n",
"output": "6\n3 2 7 8 10 11 \n",
"type": "stdin_stdout"
},
{
"input": "11 6\n6 3 11 1 9 4\n6 2 3 6 7 8 9\n4 5 6 8 10\n4 1 2 6 8\n7 1 3 5 6 7 9 11\n4 3 6 7 8\n1 8\n2 3 9\n0\n0\n5 1 5 7 8 9\n5 1 2 3 7 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "11 6\n4 2 9 7 3 1\n1 11\n0\n1 10\n1 11\n3 7 8 10\n1 11\n1 11\n1 11\n0\n1 2\n1 2\n",
"output": "8\n2 11 1 10 3 4 7 9 \n",
"type": "stdin_stdout"
},
{
"input": "11 5\n3 2 5 7 6\n4 3 5 7 9\n2 7 9\n3 7 9 11\n5 5 6 7 9 10\n3 7 9 11\n6 2 3 5 7 10 11\n0\n2 7 10\n0\n2 2 11\n2 7 9\n",
"output": "8\n7 9 2 11 3 5 10 6 \n",
"type": "stdin_stdout"
},
{
"input": "11 11\n11 6 4 7 8 5 1 3 2 9 10\n5 3 4 7 9 11\n0\n1 2\n1 3\n2 3 4\n6 1 3 4 8 10 11\n1 3\n2 2 4\n3 2 4 11\n5 4 5 7 9 11\n4 2 3 4 7\n",
"output": "11\n2 3 4 7 11 9 1 5 8 10 6 \n",
"type": "stdin_stdout"
},
{
"input": "11 6\n7 1 6 4 3 8\n0\n0\n1 2\n1 1\n0\n0\n1 8\n0\n0\n1 1\n0\n",
"output": "7\n1 2 3 4 6 8 7 \n",
"type": "stdin_stdout"
},
{
"input": "11 3\n9 11 5\n0\n0\n0\n0\n1 8\n0\n2 1 11\n0\n1 2\n0\n0\n",
"output": "5\n2 8 5 9 11 \n",
"type": "stdin_stdout"
},
{
"input": "11 11\n5 4 2 1 6 10 3 7 11 8 9\n0\n1 3\n0\n0\n0\n2 9 11\n1 9\n0\n0\n0\n0\n",
"output": "11\n1 3 2 4 5 9 11 6 7 8 10 \n",
"type": "stdin_stdout"
},
{
"input": "11 10\n9 6 10 3 2 8 4 7 11 5\n1 2\n0\n5 1 8 9 10 11\n4 1 7 8 11\n3 2 7 11\n3 1 7 10\n0\n2 6 11\n6 1 2 6 7 10 11\n2 1 11\n2 1 7\n",
"output": "11\n2 1 7 11 10 6 8 9 3 4 5 \n",
"type": "stdin_stdout"
},
{
"input": "11 10\n5 8 7 6 1 4 9 3 2 11\n3 3 8 10\n2 4 8\n1 5\n2 1 11\n1 4\n3 4 8 9\n2 3 11\n1 5\n3 1 5 8\n2 3 5\n0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "12 9\n9 2 5 7 6 1 10 12 11\n0\n3 6 7 12\n1 4\n1 7\n1 3\n1 1\n0\n0\n2 1 4\n1 3\n0\n2 2 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "12 10\n2 6 1 5 7 9 10 8 12 3\n1 10\n1 9\n1 11\n0\n1 10\n0\n1 3\n1 7\n1 6\n1 11\n0\n0\n",
"output": "11\n11 10 1 6 9 2 3 5 7 8 12 \n",
"type": "stdin_stdout"
},
{
"input": "12 10\n9 11 3 6 4 12 2 7 10 8\n1 7\n3 7 8 9\n3 1 8 11\n4 1 7 9 10\n1 4\n1 12\n1 2\n1 2\n0\n2 1 9\n1 7\n1 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "12 3\n8 10 11\n4 2 5 6 7\n5 4 7 8 10 11\n6 2 4 5 6 8 10\n2 6 8\n0\n3 5 7 8\n0\n2 3 7\n8 2 4 5 6 8 10 11 12\n2 4 7\n6 2 3 5 6 7 12\n5 1 3 6 7 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "12 1\n8\n2 2 4\n1 9\n1 10\n1 12\n4 6 10 11 12\n0\n0\n1 9\n0\n1 8\n0\n0\n",
"output": "2\n9 8 \n",
"type": "stdin_stdout"
},
{
"input": "12 10\n4 10 9 6 7 2 1 11 3 8\n1 4\n0\n7 2 4 5 6 7 8 11\n3 1 10 11\n3 4 8 12\n6 4 7 8 10 11 12\n2 2 11\n1 11\n6 3 4 8 10 11 12\n1 12\n1 1\n0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "12 3\n4 7 8\n2 11 12\n0\n0\n2 3 9\n3 7 11 12\n5 1 3 7 8 10\n1 3\n0\n2 2 8\n1 11\n0\n2 8 11\n",
"output": "6\n2 3 8 9 4 7 \n",
"type": "stdin_stdout"
},
{
"input": "12 9\n2 10 6 3 4 12 7 1 5\n0\n0\n0\n1 8\n0\n1 8\n0\n1 3\n0\n0\n0\n1 8\n",
"output": "10\n1 2 3 8 4 5 6 7 10 12 \n",
"type": "stdin_stdout"
},
{
"input": "12 1\n10\n0\n1 12\n2 2 9\n0\n2 1 2\n3 1 7 8\n3 8 9 10\n0\n0\n3 5 11 12\n0\n0\n",
"output": "6\n1 12 2 5 11 10 \n",
"type": "stdin_stdout"
},
{
"input": "12 4\n5 1 7 3\n0\n3 4 5 12\n0\n1 10\n1 12\n1 9\n3 3 4 9\n1 1\n1 11\n1 5\n2 1 4\n0\n",
"output": "9\n1 3 12 5 10 4 11 9 7 \n",
"type": "stdin_stdout"
},
{
"input": "12 2\n11 4\n0\n0\n0\n1 5\n0\n0\n0\n0\n1 2\n0\n0\n0\n",
"output": "3\n5 4 11 \n",
"type": "stdin_stdout"
},
{
"input": "12 2\n6 8\n6 2 4 5 7 9 11\n4 8 9 11 12\n0\n2 8 9\n2 8 12\n4 2 3 5 9\n2 9 12\n0\n0\n4 3 4 7 9\n2 7 8\n0\n",
"output": "9\n8 9 12 7 11 2 3 5 6 \n",
"type": "stdin_stdout"
},
{
"input": "12 10\n8 7 9 5 10 6 4 12 3 11\n1 5\n1 10\n1 1\n1 5\n1 7\n1 11\n1 10\n2 1 3\n0\n1 1\n1 8\n0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "12 1\n4\n2 4 11\n1 8\n2 2 5\n0\n0\n1 3\n0\n0\n1 2\n1 9\n2 2 6\n0\n",
"output": "1\n4 \n",
"type": "stdin_stdout"
},
{
"input": "12 2\n10 5\n0\n0\n3 1 5 11\n1 3\n0\n1 1\n2 5 9\n2 5 7\n1 8\n2 6 9\n0\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/770/C"
} | vfc_9806 |
apps | verifiable_code | 14 | Solve the following coding problem using the programming language python:
Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty).
You may perform the following operations until both a and s are empty:
Take the first element of a, push it into s and remove it from a (if a is not empty); Take the top element from s, append it to the end of array b and remove it from s (if s is not empty).
You can perform these operations in arbitrary order.
If there exists a way to perform the operations such that array b is sorted in non-descending order in the end, then array a is called stack-sortable.
For example, [3, 1, 2] is stack-sortable, because b will be sorted if we perform the following operations:
Remove 3 from a and push it into s; Remove 1 from a and push it into s; Remove 1 from s and append it to the end of b; Remove 2 from a and push it into s; Remove 2 from s and append it to the end of b; Remove 3 from s and append it to the end of b.
After all these operations b = [1, 2, 3], so [3, 1, 2] is stack-sortable. [2, 3, 1] is not stack-sortable.
You are given k first elements of some permutation p of size n (recall that a permutation of size n is an array of size n where each integer from 1 to n occurs exactly once). You have to restore the remaining n - k elements of this permutation so it is stack-sortable. If there are multiple answers, choose the answer such that p is lexicographically maximal (an array q is lexicographically greater than an array p iff there exists some integer k such that for every i < k q_{i} = p_{i}, and q_{k} > p_{k}). You may not swap or change any of first k elements of the permutation.
Print the lexicographically maximal permutation p you can obtain.
If there exists no answer then output -1.
-----Input-----
The first line contains two integers n and k (2 ≤ n ≤ 200000, 1 ≤ k < n) — the size of a desired permutation, and the number of elements you are given, respectively.
The second line contains k integers p_1, p_2, ..., p_{k} (1 ≤ p_{i} ≤ n) — the first k elements of p. These integers are pairwise distinct.
-----Output-----
If it is possible to restore a stack-sortable permutation p of size n such that the first k elements of p are equal to elements given in the input, print lexicographically maximal such permutation.
Otherwise print -1.
-----Examples-----
Input
5 3
3 2 1
Output
3 2 1 5 4
Input
5 3
2 3 1
Output
-1
Input
5 1
3
Output
3 2 1 5 4
Input
5 2
3 4
Output
-1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
#f = open('input', 'r')
f = sys.stdin
n,k = list(map(int, f.readline().split()))
a = list(map(int, f.readline().split()))
aset = set(a)
st = []
failed = False
ai = 0
app = []
for p in range(1, n+1):
if p in aset:
while ai < k and (len(st)==0 or st[-1]!=p):
st.append(a[ai])
ai += 1
if len(st) == 0 or st[-1] != p:
failed = True
break
st.pop(-1)
a += app[::-1]
app = []
else:
if ai != k:
st += a[ai:k]
ai = k
app.append(p)
if failed:
print(-1)
else:
print(' '.join(map(str, a + app[::-1])))
``` | {
"language": "python",
"test_cases": [
{
"input": "5 3\n3 2 1\n",
"output": "3 2 1 5 4 ",
"type": "stdin_stdout"
},
{
"input": "5 3\n2 3 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n3\n",
"output": "3 2 1 5 4 ",
"type": "stdin_stdout"
},
{
"input": "5 2\n3 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 19\n2 18 19 11 9 20 15 1 8 14 4 6 5 12 17 16 7 13 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 1\n6\n",
"output": "6 5 4 3 2 1 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "20 18\n8 14 18 10 1 3 7 15 2 12 17 19 5 4 11 13 20 16\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 2\n3 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "100000 3\n43791 91790 34124\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 17\n9 11 19 4 8 16 13 3 1 6 18 2 20 10 17 7 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n2 10 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "100000 4\n8269 53984 47865 42245\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 16\n8 1 5 11 15 14 7 20 16 9 12 13 18 4 6 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 4 1 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "100000 5\n82211 48488 99853 11566 42120\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 15\n6 7 14 13 8 4 15 2 11 9 12 16 5 1 20\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n2 10 5 8 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "100000 6\n98217 55264 24242 71840 2627 67839\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 14\n10 15 4 3 1 5 11 12 13 14 6 2 19 20\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 6\n4 5 2 1 6 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "100000 7\n44943 51099 61988 40497 85738 74092 2771\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 13\n6 16 5 19 8 1 4 18 2 20 10 11 13\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 7\n10 4 3 8 2 5 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "100000 8\n88153 88461 80211 24770 13872 57414 32941 63030\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 12\n20 11 14 7 16 13 9 1 4 18 6 12\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 8\n7 9 3 6 2 4 1 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "40 39\n25 4 26 34 35 11 22 23 21 2 1 28 20 8 36 5 27 15 39 7 24 14 17 19 33 6 38 16 18 3 32 10 30 13 37 31 29 9 12\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 1\n20\n",
"output": "20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 ",
"type": "stdin_stdout"
},
{
"input": "40 38\n32 35 36 4 22 6 15 21 40 13 33 17 5 24 28 9 1 23 25 14 26 3 8 11 37 30 18 16 19 20 27 12 39 2 10 38 29 31\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 2\n1 13\n",
"output": "1 13 12 11 10 9 8 7 6 5 4 3 2 20 19 18 17 16 15 14 ",
"type": "stdin_stdout"
},
{
"input": "200000 3\n60323 163214 48453\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "40 37\n26 16 40 10 9 30 8 33 39 19 4 11 2 3 38 21 22 12 1 27 20 37 24 17 23 14 13 29 7 28 34 31 25 35 6 32 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 3\n16 6 14\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "200000 4\n194118 175603 110154 129526\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "40 36\n27 33 34 40 16 39 1 10 9 12 8 37 17 7 24 30 2 31 13 23 20 18 29 21 4 28 25 35 6 22 36 15 3 11 5 26\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 4\n2 10 4 9\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "200000 5\n53765 19781 63409 69811 120021\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "40 35\n2 1 5 3 11 32 13 16 37 26 6 10 8 35 25 24 7 38 21 17 40 14 9 34 33 20 29 12 22 28 36 31 30 19 27\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 5\n11 19 6 2 12\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "200000 6\n33936 11771 42964 153325 684 8678\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "40 34\n35 31 38 25 29 9 32 23 24 16 3 26 39 2 17 28 14 1 30 34 5 36 33 7 22 13 21 12 27 19 40 10 18 15\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 6\n3 6 9 13 20 14\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "200000 7\n175932 99083 128533 75304 164663 7578 174396\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "40 33\n11 15 22 26 21 6 8 5 32 39 28 29 30 13 2 40 33 27 17 31 7 36 9 19 3 38 37 12 10 16 1 23 35\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 7\n7 5 6 13 16 3 17\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "200000 8\n197281 11492 67218 100058 179300 182264 17781 192818\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "40 32\n22 7 35 31 14 28 9 20 10 3 38 6 15 36 33 16 37 2 11 13 26 23 30 12 40 5 21 1 34 19 27 24\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 8\n1 16 14 11 7 9 2 12\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "30 3\n17 5 3\n",
"output": "17 5 3 2 1 4 16 15 14 13 12 11 10 9 8 7 6 30 29 28 27 26 25 24 23 22 21 20 19 18 ",
"type": "stdin_stdout"
},
{
"input": "30 3\n29 25 21\n",
"output": "29 25 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 24 23 22 28 27 26 30 ",
"type": "stdin_stdout"
},
{
"input": "10 6\n2 1 4 3 6 5\n",
"output": "2 1 4 3 6 5 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "4 3\n2 1 3\n",
"output": "2 1 3 4 ",
"type": "stdin_stdout"
},
{
"input": "6 4\n5 4 3 1\n",
"output": "5 4 3 1 2 6 ",
"type": "stdin_stdout"
},
{
"input": "4 3\n1 2 3\n",
"output": "1 2 3 4 ",
"type": "stdin_stdout"
},
{
"input": "6 4\n1 3 2 6\n",
"output": "1 3 2 6 5 4 ",
"type": "stdin_stdout"
},
{
"input": "5 4\n3 2 1 5\n",
"output": "3 2 1 5 4 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n6 4 1 3\n",
"output": "6 4 1 3 2 5 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "4 3\n3 4 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n3 1 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n2 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n1 4 2\n",
"output": "1 4 2 3 ",
"type": "stdin_stdout"
},
{
"input": "4 3\n3 1 2\n",
"output": "3 1 2 4 ",
"type": "stdin_stdout"
},
{
"input": "2 1\n1\n",
"output": "1 2 ",
"type": "stdin_stdout"
},
{
"input": "3 2\n3 2\n",
"output": "3 2 1 ",
"type": "stdin_stdout"
},
{
"input": "4 3\n4 1 2\n",
"output": "4 1 2 3 ",
"type": "stdin_stdout"
},
{
"input": "3 2\n3 1\n",
"output": "3 1 2 ",
"type": "stdin_stdout"
},
{
"input": "4 3\n2 1 4\n",
"output": "2 1 4 3 ",
"type": "stdin_stdout"
},
{
"input": "8 5\n3 1 4 2 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 4\n2 5 1 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n10 1 8 5 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n6 4 3\n",
"output": "6 4 3 2 1 5 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n2 1 6\n",
"output": "2 1 6 5 4 3 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n8 1 7\n",
"output": "8 1 7 6 5 4 3 2 10 9 ",
"type": "stdin_stdout"
},
{
"input": "10 2\n5 4\n",
"output": "5 4 3 2 1 10 9 8 7 6 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 2 10\n",
"output": "1 2 10 9 8 7 6 5 4 3 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 1 6 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n8 1 5\n",
"output": "8 1 5 4 3 2 7 6 10 9 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 4 9 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n3 1 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 6\n1 2 5 4 3 6\n",
"output": "1 2 5 4 3 6 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 9\n9 8 7 5 4 3 2 1 6\n",
"output": "9 8 7 5 4 3 2 1 6 10 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 7 5 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n8 6 2 1 5\n",
"output": "8 6 2 1 5 4 3 7 10 9 ",
"type": "stdin_stdout"
},
{
"input": "10 7\n7 5 2 1 4 3 6\n",
"output": "7 5 2 1 4 3 6 10 9 8 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 2 10 6\n",
"output": "1 2 10 6 5 4 3 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 6\n1 10 9 5 4 3\n",
"output": "1 10 9 5 4 3 2 8 7 6 ",
"type": "stdin_stdout"
},
{
"input": "10 8\n6 10 4 7 9 8 5 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n6 1 10 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 9\n9 6 1 4 2 3 5 10 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 9\n10 1 9 3 2 4 5 8 6\n",
"output": "10 1 9 3 2 4 5 8 6 7 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n10 8 1 7\n",
"output": "10 8 1 7 6 5 4 3 2 9 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 1 3 6\n",
"output": "2 1 3 6 5 4 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n2 1 4\n",
"output": "2 1 4 3 10 9 8 7 6 5 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n4 1 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n9 8 1 2 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n9 8 3\n",
"output": "9 8 3 2 1 7 6 5 4 10 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n8 2 1 5\n",
"output": "8 2 1 5 4 3 7 6 10 9 ",
"type": "stdin_stdout"
},
{
"input": "10 6\n6 5 3 1 2 4\n",
"output": "6 5 3 1 2 4 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 2\n1 2\n",
"output": "1 2 10 9 8 7 6 5 4 3 ",
"type": "stdin_stdout"
},
{
"input": "10 6\n9 6 5 2 1 4\n",
"output": "9 6 5 2 1 4 3 8 7 10 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 1 7 3\n",
"output": "2 1 7 3 6 5 4 10 9 8 ",
"type": "stdin_stdout"
},
{
"input": "10 2\n6 5\n",
"output": "6 5 4 3 2 1 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n2 1 5\n",
"output": "2 1 5 4 3 10 9 8 7 6 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n3 1 2 4\n",
"output": "3 1 2 4 10 9 8 7 6 5 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n8 5 4\n",
"output": "8 5 4 3 2 1 7 6 10 9 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 1 8 4\n",
"output": "2 1 8 4 3 7 6 5 10 9 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n8 3 2\n",
"output": "8 3 2 1 7 6 5 4 10 9 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n5 4 2\n",
"output": "5 4 2 1 3 10 9 8 7 6 ",
"type": "stdin_stdout"
},
{
"input": "10 9\n10 8 7 5 6 2 1 9 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 1 6 4\n",
"output": "2 1 6 4 3 5 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 1 3 9\n",
"output": "2 1 3 9 8 7 6 5 4 10 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 4 3\n",
"output": "1 4 3 2 10 9 8 7 6 5 ",
"type": "stdin_stdout"
},
{
"input": "10 7\n3 2 1 9 8 6 5\n",
"output": "3 2 1 9 8 6 5 4 7 10 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n10 7 1 5\n",
"output": "10 7 1 5 4 3 2 6 9 8 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n8 7 1 2\n",
"output": "8 7 1 2 6 5 4 3 10 9 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 5 4 2\n",
"output": "1 5 4 2 3 10 9 8 7 6 ",
"type": "stdin_stdout"
},
{
"input": "10 5\n2 1 9 3 7\n",
"output": "2 1 9 3 7 6 5 4 8 10 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 1 5 3\n",
"output": "2 1 5 3 4 10 9 8 7 6 ",
"type": "stdin_stdout"
},
{
"input": "10 5\n9 6 1 8 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 13\n3 2 1 7 4 5 6 11 10 9 8 13 12\n",
"output": "3 2 1 7 4 5 6 11 10 9 8 13 12 20 19 18 17 16 15 14 ",
"type": "stdin_stdout"
},
{
"input": "20 14\n3 2 1 7 4 5 6 14 11 10 9 8 13 12\n",
"output": "3 2 1 7 4 5 6 14 11 10 9 8 13 12 20 19 18 17 16 15 ",
"type": "stdin_stdout"
},
{
"input": "10 5\n9 4 2 1 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n1 5 2 10 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 8\n6 5 3 1 2 4 9 8\n",
"output": "6 5 3 1 2 4 9 8 7 10 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n10 9 3 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 7\n10 8 5 1 2 7 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n3 1 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n1 9 8 4 3\n",
"output": "1 9 8 4 3 2 7 6 5 10 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 8 4\n",
"output": "1 8 4 3 2 7 6 5 10 9 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n6 2 1 4\n",
"output": "6 2 1 4 3 5 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 6 4\n",
"output": "1 6 4 3 2 5 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n10 9 3\n",
"output": "10 9 3 2 1 8 7 6 5 4 ",
"type": "stdin_stdout"
},
{
"input": "10 9\n8 10 4 1 3 2 9 7 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n7 10 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n9 10 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 6\n10 8 1 6 2 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 6\n6 5 1 2 9 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n10 1 8\n",
"output": "10 1 8 7 6 5 4 3 2 9 ",
"type": "stdin_stdout"
},
{
"input": "10 9\n1 9 7 10 5 8 4 6 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n1 9 3 2 5\n",
"output": "1 9 3 2 5 4 8 7 6 10 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n10 1 9 7\n",
"output": "10 1 9 7 6 5 4 3 2 8 ",
"type": "stdin_stdout"
},
{
"input": "10 8\n1 10 3 2 9 4 8 5\n",
"output": "1 10 3 2 9 4 8 5 7 6 ",
"type": "stdin_stdout"
},
{
"input": "10 1\n1\n",
"output": "1 10 9 8 7 6 5 4 3 2 ",
"type": "stdin_stdout"
},
{
"input": "10 7\n9 7 1 6 5 4 2\n",
"output": "9 7 1 6 5 4 2 3 8 10 ",
"type": "stdin_stdout"
},
{
"input": "10 9\n10 2 1 7 8 3 5 6 9\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 1 3 10\n",
"output": "2 1 3 10 9 8 7 6 5 4 ",
"type": "stdin_stdout"
},
{
"input": "10 9\n5 1 4 6 3 9 8 10 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 6\n8 2 1 7 6 5\n",
"output": "8 2 1 7 6 5 4 3 10 9 ",
"type": "stdin_stdout"
},
{
"input": "10 5\n2 9 8 6 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n9 2 1 6\n",
"output": "9 2 1 6 5 4 3 8 7 10 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n2 1 7\n",
"output": "2 1 7 6 5 4 3 10 9 8 ",
"type": "stdin_stdout"
},
{
"input": "10 7\n4 1 2 10 9 6 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 6\n10 2 1 3 9 4\n",
"output": "10 2 1 3 9 4 8 7 6 5 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n9 2 1 4\n",
"output": "9 2 1 4 3 8 7 6 5 10 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n5 1 4\n",
"output": "5 1 4 3 2 10 9 8 7 6 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 1 2 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "8 6\n5 4 3 2 1 8\n",
"output": "5 4 3 2 1 8 7 6 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 6 5 4\n",
"output": "1 6 5 4 3 2 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 2\n10 2\n",
"output": "10 2 1 9 8 7 6 5 4 3 ",
"type": "stdin_stdout"
},
{
"input": "10 5\n1 6 2 10 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 9\n6 1 2 10 9 5 3 4 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n4 1 7 2 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 1 3 4\n",
"output": "2 1 3 4 10 9 8 7 6 5 ",
"type": "stdin_stdout"
},
{
"input": "11 2\n3 2\n",
"output": "3 2 1 11 10 9 8 7 6 5 4 ",
"type": "stdin_stdout"
},
{
"input": "6 5\n3 2 1 4 5\n",
"output": "3 2 1 4 5 6 ",
"type": "stdin_stdout"
},
{
"input": "5 4\n2 1 3 5\n",
"output": "2 1 3 5 4 ",
"type": "stdin_stdout"
},
{
"input": "10 6\n3 2 1 5 4 6\n",
"output": "3 2 1 5 4 6 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "11 5\n1 8 7 6 5\n",
"output": "1 8 7 6 5 4 3 2 11 10 9 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n2 1 3\n",
"output": "2 1 3 10 9 8 7 6 5 4 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n2 1 7 6\n",
"output": "2 1 7 6 5 4 3 10 9 8 ",
"type": "stdin_stdout"
},
{
"input": "10 4\n5 4 1 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n9 1 5 4\n",
"output": "9 1 5 4 3 2 8 7 6 10 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n6 1 4\n",
"output": "6 1 4 3 2 5 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 6\n1 9 3 2 4 6\n",
"output": "1 9 3 2 4 6 5 8 7 10 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n10 1 9\n",
"output": "10 1 9 8 7 6 5 4 3 2 ",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 9 7\n",
"output": "1 9 7 6 5 4 3 2 8 10 ",
"type": "stdin_stdout"
},
{
"input": "10 2\n2 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n9 2 1 4 3\n",
"output": "9 2 1 4 3 8 7 6 5 10 ",
"type": "stdin_stdout"
},
{
"input": "10 6\n1 2 3 6 5 4\n",
"output": "1 2 3 6 5 4 10 9 8 7 ",
"type": "stdin_stdout"
},
{
"input": "10 5\n7 6 5 1 4\n",
"output": "7 6 5 1 4 3 2 10 9 8 ",
"type": "stdin_stdout"
},
{
"input": "10 9\n8 1 3 4 10 5 9 7 2\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/911/E"
} | vfc_9810 |
apps | verifiable_code | 15 | Solve the following coding problem using the programming language python:
Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s_1 = a), and the difference between any two neighbouring elements is equal to c (s_{i} - s_{i} - 1 = c). In particular, Vasya wonders if his favourite integer b appears in this sequence, that is, there exists a positive integer i, such that s_{i} = b. Of course, you are the person he asks for a help.
-----Input-----
The first line of the input contain three integers a, b and c ( - 10^9 ≤ a, b, c ≤ 10^9) — the first element of the sequence, Vasya's favorite number and the difference between any two neighbouring elements of the sequence, respectively.
-----Output-----
If b appears in the sequence s print "YES" (without quotes), otherwise print "NO" (without quotes).
-----Examples-----
Input
1 7 3
Output
YES
Input
10 10 0
Output
YES
Input
1 -4 5
Output
NO
Input
0 60 50
Output
NO
-----Note-----
In the first sample, the sequence starts from integers 1, 4, 7, so 7 is its element.
In the second sample, the favorite integer of Vasya is equal to the first element of the sequence.
In the third sample all elements of the sequence are greater than Vasya's favorite integer.
In the fourth sample, the sequence starts from 0, 50, 100, and all the following elements are greater than Vasya's favorite integer.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
a,b,c=map(int,input().split())
if c==0:
if a==b:
print('YES')
else:
print('NO')
return
if (b-a)%c==0 and (b-a)//c>=0:
print('YES')
else:
print('NO')
``` | {
"language": "python",
"test_cases": [
{
"input": "1 7 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 10 0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 -4 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 60 50\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 -4 -5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 1 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 10 42\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1000000000 1000000000 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 16 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1000000000 1000000000 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 -1000000000 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 -1000000000 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "115078364 -899474523 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-245436499 416383245 992\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-719636354 536952440 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-198350539 963391024 68337739\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-652811055 875986516 1091\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "119057893 -516914539 -39748277\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "989140430 731276607 -36837689\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "677168390 494583489 -985071853\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "58090193 777423708 395693923\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "479823846 -403424770 -653472589\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-52536829 -132023273 -736287999\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-198893776 740026818 -547885271\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 -2 -2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-2 -2 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-2 -2 0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-2 -2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-2 -2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-2 -1 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 -1 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 -1 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 -1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-2 -1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 0 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 0 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 0 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 0 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-2 0 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-2 1 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 1 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 1 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-2 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 2 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 2 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 2 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-2 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-2 2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1 -2 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 -2 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1 -2 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 -2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 -2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 -1 -2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1 -1 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1 -1 0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1 -1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1 -1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1 0 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 0 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 0 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 0 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1 0 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 1 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 1 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 1 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1 1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1 2 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 2 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 2 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "-1 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 -2 -2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 -2 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 -2 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 -2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 -2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 -1 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 -1 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 -1 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 -1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 -1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 0 -2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 0 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 0 0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 0 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 0 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 1 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 1 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 1 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 2 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 2 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 2 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 -2 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 -2 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 -2 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 -2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 -2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 -1 -2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 -1 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 -1 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 -1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 -1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 0 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 0 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 0 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 0 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 0 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 1 -2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 1 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 1 0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 2 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 -2 -2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 -2 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 -2 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 -2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 -2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 -1 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 -1 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 -1 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 -1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 -1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 0 -2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 0 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 0 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 0 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 0 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 1 -2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 1 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 1 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 2 -2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 2 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 2 0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1000000000 1000000000 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1000000000 1000000000 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 -1000000000 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 2 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 1 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 -5 -3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 10 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "15 5 -5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "20 10 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "20 15 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 6 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 0 -1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 1 -5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 6 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-5 -10 -5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 0 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 9 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-2 -1 -1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 13 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 3 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 1 -1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 -10 -5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "-1000000000 1000000000 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/675/A"
} | vfc_9814 |
apps | verifiable_code | 16 | Solve the following coding problem using the programming language python:
A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular if it it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, "", "(())" and "()()" are regular bracket sequences; "))" and ")((" are bracket sequences (but not regular ones), and "(a)" and "(1)+(1)" are not bracket sequences at all.
You have a number of strings; each string is a bracket sequence of length $2$. So, overall you have $cnt_1$ strings "((", $cnt_2$ strings "()", $cnt_3$ strings ")(" and $cnt_4$ strings "))". You want to write all these strings in some order, one after another; after that, you will get a long bracket sequence of length $2(cnt_1 + cnt_2 + cnt_3 + cnt_4)$. You wonder: is it possible to choose some order of the strings you have such that you will get a regular bracket sequence? Note that you may not remove any characters or strings, and you may not add anything either.
-----Input-----
The input consists of four lines, $i$-th of them contains one integer $cnt_i$ ($0 \le cnt_i \le 10^9$).
-----Output-----
Print one integer: $1$ if it is possible to form a regular bracket sequence by choosing the correct order of the given strings, $0$ otherwise.
-----Examples-----
Input
3
1
4
3
Output
1
Input
0
0
0
0
Output
1
Input
1
2
3
4
Output
0
-----Note-----
In the first example it is possible to construct a string "(())()(()((()()()())))", which is a regular bracket sequence.
In the second example it is possible to construct a string "", which is a regular bracket sequence.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
cnt1 = int(input())
cnt2 = int(input())
cnt3 = int(input())
cnt4 = int(input())
if cnt1 != cnt4:
print(0)
return
if (cnt3 != 0 and cnt1 == 0):
print(0)
return
print(1)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n1\n4\n3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n0\n0\n0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n3\n4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000000\n1000000000\n1000000000\n1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000\n1000000000\n1000000000\n999999999\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000000\n999999999\n1000000000\n1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n1000000000\n0\n0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n0\n1\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4\n3\n2\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n2\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n0\n2\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "20123\n1\n1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n40\n2\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "925\n22\n24\n111\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n20\n20\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n1\n1\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n0\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "20123\n2\n3\n4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n0\n0\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n6\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n0\n10\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n3\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2\n6\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n5\n10\n4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n0\n3\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n0\n3\n3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n5\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n0\n10\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n10\n10\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n5\n100\n4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n3\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n100\n100\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n4\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n100\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n100\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n10\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n11\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n0\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n2\n2\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n4\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n7\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n10\n1\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5\n5\n1000\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n0\n5\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n10\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n0\n4\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n3\n1\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n2\n1\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n3\n9\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n0\n2\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n100\n1\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n7\n2\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n1\n0\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n5\n0\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n6\n6\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n100\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0\n7\n3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n500\n500\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n0\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n10000000\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n100000\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n5\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n1\n3\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3\n1\n100\n3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n0\n1\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n2\n0\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n1000000\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n1\n1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n500\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n0\n20\n4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n4\n1\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4\n5\n100000000\n4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n5\n3\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n1\n10\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5\n1\n20\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n0\n100\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n100\n100\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n1\n0\n0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5\n10\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n5\n2\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n10\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2\n9\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1000000000\n1000000000\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n0\n0\n5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n3\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n5\n1000000\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2\n10\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n900\n900\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n0\n0\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2\n7\n3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1\n5\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n6\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n1\n2\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n3\n4\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5\n5\n10000\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n2\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1\n10\n4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n0\n0\n4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n5\n100000\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n3\n0\n3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n0\n200\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n0\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10\n21\n21\n10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n5\n1\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n10\n100\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0\n0\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4\n2\n133\n4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n1\n50\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n1\n0\n10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n0\n7\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n0\n0\n3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4\n0\n10\n4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1\n8\n3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n3\n3\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "7\n1\n0\n7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n2\n3\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n0\n0\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n50\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n10\n10\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n0\n228\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n3\n9\n4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n8\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "666\n666\n666\n666\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n5\n12\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n47\n47\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n1\n100\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n1999\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n5\n5\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n2019\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n3\n5\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n5\n2\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n5\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n200\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100\n100\n1000\n100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n10\n2\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n4\n10\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n0\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n2\n3\n4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n0\n0\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n101\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n50\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n1000\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2\n12\n3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "12\n4\n0\n13\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n6\n1\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n1\n45\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n5\n8\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n2\n0\n3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n0\n0\n4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n1\n69\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5\n0\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n2\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "11\n1\n111\n11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n4\n3\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n1\n5\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n3\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100007\n1\n1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "34\n95\n0\n16\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5\n0\n0\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n3\n5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3\n1\n0\n4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "16\n93\n0\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0\n0\n0\n3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20\n24\n45\n20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "23\n0\n49\n23\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "99\n49\n0\n0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100000\n100000\n100000\n100000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "200000\n200000\n200000\n200000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "0\n5\n0\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n123\n123\n1\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1132/A"
} | vfc_9818 |
apps | verifiable_code | 17 | Solve the following coding problem using the programming language python:
Arpa is researching the Mexican wave.
There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0.
At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-th spectator stands. At time k + 1, the (k + 1)-th spectator stands and the first spectator sits. At time k + 2, the (k + 2)-th spectator stands and the second spectator sits. ... At time n, the n-th spectator stands and the (n - k)-th spectator sits. At time n + 1, the (n + 1 - k)-th spectator sits. ... At time n + k, the n-th spectator sits.
Arpa wants to know how many spectators are standing at time t.
-----Input-----
The first line contains three integers n, k, t (1 ≤ n ≤ 10^9, 1 ≤ k ≤ n, 1 ≤ t < n + k).
-----Output-----
Print single integer: how many spectators are standing at time t.
-----Examples-----
Input
10 5 3
Output
3
Input
10 5 7
Output
5
Input
10 5 12
Output
3
-----Note-----
In the following a sitting spectator is represented as -, a standing spectator is represented as ^.
At t = 0 ---------- $\Rightarrow$ number of standing spectators = 0. At t = 1 ^--------- $\Rightarrow$ number of standing spectators = 1. At t = 2 ^^-------- $\Rightarrow$ number of standing spectators = 2. At t = 3 ^^^------- $\Rightarrow$ number of standing spectators = 3. At t = 4 ^^^^------ $\Rightarrow$ number of standing spectators = 4. At t = 5 ^^^^^----- $\Rightarrow$ number of standing spectators = 5. At t = 6 -^^^^^---- $\Rightarrow$ number of standing spectators = 5. At t = 7 --^^^^^--- $\Rightarrow$ number of standing spectators = 5. At t = 8 ---^^^^^-- $\Rightarrow$ number of standing spectators = 5. At t = 9 ----^^^^^- $\Rightarrow$ number of standing spectators = 5. At t = 10 -----^^^^^ $\Rightarrow$ number of standing spectators = 5. At t = 11 ------^^^^ $\Rightarrow$ number of standing spectators = 4. At t = 12 -------^^^ $\Rightarrow$ number of standing spectators = 3. At t = 13 --------^^ $\Rightarrow$ number of standing spectators = 2. At t = 14 ---------^ $\Rightarrow$ number of standing spectators = 1. At t = 15 ---------- $\Rightarrow$ number of standing spectators = 0.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def read_ints():
return [int(i) for i in input().split()]
n, k, t = read_ints()
if t <= k:
print(t)
elif t > n:
print(k + n - t)
else:
print(k)
``` | {
"language": "python",
"test_cases": [
{
"input": "10 5 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 5 7\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 5 12\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "840585600 770678331 788528791\n",
"output": "770678331\n",
"type": "stdin_stdout"
},
{
"input": "25462281 23343504 8024619\n",
"output": "8024619\n",
"type": "stdin_stdout"
},
{
"input": "723717988 205757169 291917494\n",
"output": "205757169\n",
"type": "stdin_stdout"
},
{
"input": "27462087 20831796 15492397\n",
"output": "15492397\n",
"type": "stdin_stdout"
},
{
"input": "966696824 346707476 1196846860\n",
"output": "116557440\n",
"type": "stdin_stdout"
},
{
"input": "290274403 41153108 327683325\n",
"output": "3744186\n",
"type": "stdin_stdout"
},
{
"input": "170963478 151220598 222269210\n",
"output": "99914866\n",
"type": "stdin_stdout"
},
{
"input": "14264008 309456 11132789\n",
"output": "309456\n",
"type": "stdin_stdout"
},
{
"input": "886869816 281212106 52891064\n",
"output": "52891064\n",
"type": "stdin_stdout"
},
{
"input": "330543750 243917820 205522400\n",
"output": "205522400\n",
"type": "stdin_stdout"
},
{
"input": "457658451 18625039 157624558\n",
"output": "18625039\n",
"type": "stdin_stdout"
},
{
"input": "385908940 143313325 509731380\n",
"output": "19490885\n",
"type": "stdin_stdout"
},
{
"input": "241227633 220621961 10025257\n",
"output": "10025257\n",
"type": "stdin_stdout"
},
{
"input": "474139818 268918981 388282504\n",
"output": "268918981\n",
"type": "stdin_stdout"
},
{
"input": "25963410 3071034 820199\n",
"output": "820199\n",
"type": "stdin_stdout"
},
{
"input": "656346757 647995766 75748423\n",
"output": "75748423\n",
"type": "stdin_stdout"
},
{
"input": "588568132 411878522 521753621\n",
"output": "411878522\n",
"type": "stdin_stdout"
},
{
"input": "735788762 355228487 139602545\n",
"output": "139602545\n",
"type": "stdin_stdout"
},
{
"input": "860798593 463398487 506871376\n",
"output": "463398487\n",
"type": "stdin_stdout"
},
{
"input": "362624055 110824996 194551217\n",
"output": "110824996\n",
"type": "stdin_stdout"
},
{
"input": "211691721 195866131 313244576\n",
"output": "94313276\n",
"type": "stdin_stdout"
},
{
"input": "45661815 26072719 9643822\n",
"output": "9643822\n",
"type": "stdin_stdout"
},
{
"input": "757183104 590795077 709609355\n",
"output": "590795077\n",
"type": "stdin_stdout"
},
{
"input": "418386749 1915035 197248338\n",
"output": "1915035\n",
"type": "stdin_stdout"
},
{
"input": "763782282 297277890 246562421\n",
"output": "246562421\n",
"type": "stdin_stdout"
},
{
"input": "893323188 617630677 607049638\n",
"output": "607049638\n",
"type": "stdin_stdout"
},
{
"input": "506708261 356545583 296093684\n",
"output": "296093684\n",
"type": "stdin_stdout"
},
{
"input": "984295813 427551190 84113823\n",
"output": "84113823\n",
"type": "stdin_stdout"
},
{
"input": "774984967 61373612 96603505\n",
"output": "61373612\n",
"type": "stdin_stdout"
},
{
"input": "774578969 342441237 91492393\n",
"output": "91492393\n",
"type": "stdin_stdout"
},
{
"input": "76495801 8780305 56447339\n",
"output": "8780305\n",
"type": "stdin_stdout"
},
{
"input": "48538385 582843 16805978\n",
"output": "582843\n",
"type": "stdin_stdout"
},
{
"input": "325794610 238970909 553089099\n",
"output": "11676420\n",
"type": "stdin_stdout"
},
{
"input": "834925315 316928679 711068031\n",
"output": "316928679\n",
"type": "stdin_stdout"
},
{
"input": "932182199 454838315 267066713\n",
"output": "267066713\n",
"type": "stdin_stdout"
},
{
"input": "627793782 552043394 67061810\n",
"output": "67061810\n",
"type": "stdin_stdout"
},
{
"input": "24317170 17881607 218412\n",
"output": "218412\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 1000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 100 100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 100 99\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "100 100 101\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "100 100 199\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 1999999999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 5 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 3 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 5 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 2 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 5 14\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6 1 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 10 19\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 4 11\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 5 11\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "600 200 700\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "2000 1000 2001\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1000 1000 1001\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "5 4 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 3 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "15 10 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 5 13\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 5 6\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10 6 12\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "7 5 8\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10 4 9\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "9 2 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 2 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6 2 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 5 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 3 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 2 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 3 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 4 8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 6 11\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 3 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 6 14\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 10 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "20 4 22\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4 3 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "12 8 18\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 5 10\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "100 50 149\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "7 6 9\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "16 10 21\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 2 11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "600 200 500\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "100 30 102\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "10 10 18\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "15 3 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 1000000000\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "5 5 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 3 12\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "747 457 789\n",
"output": "415\n",
"type": "stdin_stdout"
},
{
"input": "5 4 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "15 5 11\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7 6 8\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7 4 8\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 4 13\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 3 9\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "20 2 21\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6 5 9\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 9 18\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "12 4 9\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10 7 15\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "999999999 999999998 1500000000\n",
"output": "499999997\n",
"type": "stdin_stdout"
},
{
"input": "20 5 20\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4745 4574 4757\n",
"output": "4562\n",
"type": "stdin_stdout"
},
{
"input": "10 7 12\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "17 15 18\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "3 1 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 3 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6 2 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8 5 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "9 5 10\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10 6 13\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "13 10 14\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "13 12 15\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "10 4 12\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "41 3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 1400000000\n",
"output": "600000000\n",
"type": "stdin_stdout"
},
{
"input": "10 3 11\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "12 7 18\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "15 3 17\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 2 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000 1000000999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 5 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 3 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100 5 50\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10000 10 10000\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "9979797 555554 10101010\n",
"output": "434341\n",
"type": "stdin_stdout"
},
{
"input": "13 5 12\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9 4 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 5 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100000000 10000000 100005000\n",
"output": "9995000\n",
"type": "stdin_stdout"
},
{
"input": "100000 50000 100001\n",
"output": "49999\n",
"type": "stdin_stdout"
},
{
"input": "15 10 20\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 4 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5 3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "30 5 30\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "200000 10 200005\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 9 12\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 6 15\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 10 1000000000\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "7 5 11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "14 3 15\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 100000000 1000000000\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "40 10 22\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "50 10 51\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "999999997 999999995 1999999991\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "92 79 144\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "8 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/851/A"
} | vfc_9822 |
apps | verifiable_code | 18 | Solve the following coding problem using the programming language python:
Petya recieved a gift of a string s with length up to 10^5 characters for his birthday. He took two more empty strings t and u and decided to play a game. This game has two possible moves: Extract the first character of s and append t with this character. Extract the last character of t and append u with this character.
Petya wants to get strings s and t empty and string u lexicographically minimal.
You should write a program that will help Petya win the game.
-----Input-----
First line contains non-empty string s (1 ≤ |s| ≤ 10^5), consisting of lowercase English letters.
-----Output-----
Print resulting string u.
-----Examples-----
Input
cab
Output
abc
Input
acdb
Output
abdc
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from collections import deque
S = input()
mn = [ 300 for i in range( len( S ) ) ]
for i in range( len( S ) - 1, -1, -1 ):
if i == len( S ) - 1:
mn[ i ] = ord( S[ i ] )
else:
mn[ i ] = min( mn[ i + 1 ], ord( S[ i ] ) )
ans = ""
dq = deque()
for i in range( len( S ) ):
dq.append( ord( S[ i ] ) )
while len( dq ) and ( i + 1 == len( S ) or dq[ len( dq ) - 1 ] <= mn[ i + 1 ] ):
ans += chr( dq[ len( dq ) - 1 ] )
dq.pop()
print( ans )
``` | {
"language": "python",
"test_cases": [
{
"input": "cab\n",
"output": "abc\n",
"type": "stdin_stdout"
},
{
"input": "acdb\n",
"output": "abdc\n",
"type": "stdin_stdout"
},
{
"input": "a\n",
"output": "a\n",
"type": "stdin_stdout"
},
{
"input": "ab\n",
"output": "ab\n",
"type": "stdin_stdout"
},
{
"input": "ba\n",
"output": "ab\n",
"type": "stdin_stdout"
},
{
"input": "dijee\n",
"output": "deeji\n",
"type": "stdin_stdout"
},
{
"input": "bhrmc\n",
"output": "bcmrh\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "bababaaababaabbbbbabbbbbbaaabbabaaaaabbbbbaaaabbbbabaabaabababbbabbabbabaaababbabbababaaaaabaaaabbba\n",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\n",
"type": "stdin_stdout"
},
{
"input": "bccbbcccbccbacacbaccaababcbaababaaaaabcaaabcaacbabcaababaabaccacacccbacbcacbbbaacaaccccabbbbacbcbbba\n",
"output": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbcbcbbbbcccccbbbccbcbccccccbbbcbbccbcbbbbcbbccbccbccbcccbbccb\n",
"type": "stdin_stdout"
},
{
"input": "eejahjfbbcdhbieiigaihidhageiechaadieecaaehcehjbddgcjgagdfgffdaaihbecebdjhjagghecdhbhdfbedhfhfafbjajg\n",
"output": "aaaaaaaaaaaaagjjbffhfhdebfdhbhdcehggjhjdbecebhidffgfdggjcgddbjhecheceeidhceieghdihigiieibhdcbbfjhjee\n",
"type": "stdin_stdout"
},
{
"input": "bnrdfnybkzepmluyrhofwnwvfmkdwolvyzrqhuhztvlwjldqmoyxzytpfmrgouymeupxrvpbesyxixnrfbxnqcwgmgjstknqtwrr\n",
"output": "bbbbcggjknqrrwttsmwqnxfrnxixysepvrxpuemyuogrmfptyzxyomqdljwlvtzhuhqrzyvlowdkmfvwnwfohryulmpezkynfdrn\n",
"type": "stdin_stdout"
},
{
"input": "bcaeaae\n",
"output": "aaaecbe\n",
"type": "stdin_stdout"
},
{
"input": "edcadcbcdd\n",
"output": "abccdcddde\n",
"type": "stdin_stdout"
},
{
"input": "a\n",
"output": "a\n",
"type": "stdin_stdout"
},
{
"input": "a\n",
"output": "a\n",
"type": "stdin_stdout"
},
{
"input": "a\n",
"output": "a\n",
"type": "stdin_stdout"
},
{
"input": "b\n",
"output": "b\n",
"type": "stdin_stdout"
},
{
"input": "b\n",
"output": "b\n",
"type": "stdin_stdout"
},
{
"input": "a\n",
"output": "a\n",
"type": "stdin_stdout"
},
{
"input": "c\n",
"output": "c\n",
"type": "stdin_stdout"
},
{
"input": "a\n",
"output": "a\n",
"type": "stdin_stdout"
},
{
"input": "b\n",
"output": "b\n",
"type": "stdin_stdout"
},
{
"input": "c\n",
"output": "c\n",
"type": "stdin_stdout"
},
{
"input": "b\n",
"output": "b\n",
"type": "stdin_stdout"
},
{
"input": "a\n",
"output": "a\n",
"type": "stdin_stdout"
},
{
"input": "e\n",
"output": "e\n",
"type": "stdin_stdout"
},
{
"input": "b\n",
"output": "b\n",
"type": "stdin_stdout"
},
{
"input": "b\n",
"output": "b\n",
"type": "stdin_stdout"
},
{
"input": "aa\n",
"output": "aa\n",
"type": "stdin_stdout"
},
{
"input": "aa\n",
"output": "aa\n",
"type": "stdin_stdout"
},
{
"input": "aa\n",
"output": "aa\n",
"type": "stdin_stdout"
},
{
"input": "aa\n",
"output": "aa\n",
"type": "stdin_stdout"
},
{
"input": "bb\n",
"output": "bb\n",
"type": "stdin_stdout"
},
{
"input": "bb\n",
"output": "bb\n",
"type": "stdin_stdout"
},
{
"input": "ba\n",
"output": "ab\n",
"type": "stdin_stdout"
},
{
"input": "ca\n",
"output": "ac\n",
"type": "stdin_stdout"
},
{
"input": "ab\n",
"output": "ab\n",
"type": "stdin_stdout"
},
{
"input": "cb\n",
"output": "bc\n",
"type": "stdin_stdout"
},
{
"input": "bb\n",
"output": "bb\n",
"type": "stdin_stdout"
},
{
"input": "aa\n",
"output": "aa\n",
"type": "stdin_stdout"
},
{
"input": "da\n",
"output": "ad\n",
"type": "stdin_stdout"
},
{
"input": "ab\n",
"output": "ab\n",
"type": "stdin_stdout"
},
{
"input": "cd\n",
"output": "cd\n",
"type": "stdin_stdout"
},
{
"input": "aaa\n",
"output": "aaa\n",
"type": "stdin_stdout"
},
{
"input": "aaa\n",
"output": "aaa\n",
"type": "stdin_stdout"
},
{
"input": "aaa\n",
"output": "aaa\n",
"type": "stdin_stdout"
},
{
"input": "aab\n",
"output": "aab\n",
"type": "stdin_stdout"
},
{
"input": "aaa\n",
"output": "aaa\n",
"type": "stdin_stdout"
},
{
"input": "baa\n",
"output": "aab\n",
"type": "stdin_stdout"
},
{
"input": "bab\n",
"output": "abb\n",
"type": "stdin_stdout"
},
{
"input": "baa\n",
"output": "aab\n",
"type": "stdin_stdout"
},
{
"input": "ccc\n",
"output": "ccc\n",
"type": "stdin_stdout"
},
{
"input": "ddd\n",
"output": "ddd\n",
"type": "stdin_stdout"
},
{
"input": "ccd\n",
"output": "ccd\n",
"type": "stdin_stdout"
},
{
"input": "bca\n",
"output": "acb\n",
"type": "stdin_stdout"
},
{
"input": "cde\n",
"output": "cde\n",
"type": "stdin_stdout"
},
{
"input": "ece\n",
"output": "cee\n",
"type": "stdin_stdout"
},
{
"input": "bdd\n",
"output": "bdd\n",
"type": "stdin_stdout"
},
{
"input": "aaaa\n",
"output": "aaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaa\n",
"output": "aaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaa\n",
"output": "aaaa\n",
"type": "stdin_stdout"
},
{
"input": "abaa\n",
"output": "aaab\n",
"type": "stdin_stdout"
},
{
"input": "abab\n",
"output": "aabb\n",
"type": "stdin_stdout"
},
{
"input": "bbbb\n",
"output": "bbbb\n",
"type": "stdin_stdout"
},
{
"input": "bbba\n",
"output": "abbb\n",
"type": "stdin_stdout"
},
{
"input": "caba\n",
"output": "aabc\n",
"type": "stdin_stdout"
},
{
"input": "ccbb\n",
"output": "bbcc\n",
"type": "stdin_stdout"
},
{
"input": "abac\n",
"output": "aabc\n",
"type": "stdin_stdout"
},
{
"input": "daba\n",
"output": "aabd\n",
"type": "stdin_stdout"
},
{
"input": "cdbb\n",
"output": "bbdc\n",
"type": "stdin_stdout"
},
{
"input": "bddd\n",
"output": "bddd\n",
"type": "stdin_stdout"
},
{
"input": "dacb\n",
"output": "abcd\n",
"type": "stdin_stdout"
},
{
"input": "abcc\n",
"output": "abcc\n",
"type": "stdin_stdout"
},
{
"input": "aaaaa\n",
"output": "aaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaaa\n",
"output": "aaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaaa\n",
"output": "aaaaa\n",
"type": "stdin_stdout"
},
{
"input": "baaab\n",
"output": "aaabb\n",
"type": "stdin_stdout"
},
{
"input": "aabbb\n",
"output": "aabbb\n",
"type": "stdin_stdout"
},
{
"input": "aabaa\n",
"output": "aaaab\n",
"type": "stdin_stdout"
},
{
"input": "abcba\n",
"output": "aabcb\n",
"type": "stdin_stdout"
},
{
"input": "bacbc\n",
"output": "abbcc\n",
"type": "stdin_stdout"
},
{
"input": "bacba\n",
"output": "aabcb\n",
"type": "stdin_stdout"
},
{
"input": "bdbda\n",
"output": "adbdb\n",
"type": "stdin_stdout"
},
{
"input": "accbb\n",
"output": "abbcc\n",
"type": "stdin_stdout"
},
{
"input": "dbccc\n",
"output": "bcccd\n",
"type": "stdin_stdout"
},
{
"input": "decca\n",
"output": "acced\n",
"type": "stdin_stdout"
},
{
"input": "dbbdd\n",
"output": "bbddd\n",
"type": "stdin_stdout"
},
{
"input": "accec\n",
"output": "accce\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaa\n",
"output": "aaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaa\n",
"output": "aaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaa\n",
"output": "aaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "bbbbab\n",
"output": "abbbbb\n",
"type": "stdin_stdout"
},
{
"input": "bbbbab\n",
"output": "abbbbb\n",
"type": "stdin_stdout"
},
{
"input": "aaaaba\n",
"output": "aaaaab\n",
"type": "stdin_stdout"
},
{
"input": "cbbbcc\n",
"output": "bbbccc\n",
"type": "stdin_stdout"
},
{
"input": "aaacac\n",
"output": "aaaacc\n",
"type": "stdin_stdout"
},
{
"input": "bacbbc\n",
"output": "abbbcc\n",
"type": "stdin_stdout"
},
{
"input": "cacacc\n",
"output": "aacccc\n",
"type": "stdin_stdout"
},
{
"input": "badbdc\n",
"output": "abbcdd\n",
"type": "stdin_stdout"
},
{
"input": "ddadad\n",
"output": "aadddd\n",
"type": "stdin_stdout"
},
{
"input": "ccdece\n",
"output": "cccede\n",
"type": "stdin_stdout"
},
{
"input": "eecade\n",
"output": "acdeee\n",
"type": "stdin_stdout"
},
{
"input": "eabdcb\n",
"output": "abbcde\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaa\n",
"output": "aaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaa\n",
"output": "aaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaa\n",
"output": "aaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaabbaa\n",
"output": "aaaaabb\n",
"type": "stdin_stdout"
},
{
"input": "baaabab\n",
"output": "aaaabbb\n",
"type": "stdin_stdout"
},
{
"input": "bbababa\n",
"output": "aaabbbb\n",
"type": "stdin_stdout"
},
{
"input": "bcccacc\n",
"output": "acccbcc\n",
"type": "stdin_stdout"
},
{
"input": "cbbcccc\n",
"output": "bbccccc\n",
"type": "stdin_stdout"
},
{
"input": "abacaaa\n",
"output": "aaaaacb\n",
"type": "stdin_stdout"
},
{
"input": "ccdbdac\n",
"output": "acdbdcc\n",
"type": "stdin_stdout"
},
{
"input": "bbacaba\n",
"output": "aaabcbb\n",
"type": "stdin_stdout"
},
{
"input": "abbaccc\n",
"output": "aabbccc\n",
"type": "stdin_stdout"
},
{
"input": "bdcbcab\n",
"output": "abcbcdb\n",
"type": "stdin_stdout"
},
{
"input": "dabcbce\n",
"output": "abbccde\n",
"type": "stdin_stdout"
},
{
"input": "abaaabe\n",
"output": "aaaabbe\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaa\n",
"output": "aaaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaa\n",
"output": "aaaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaa\n",
"output": "aaaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "ababbbba\n",
"output": "aaabbbbb\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaba\n",
"output": "aaaaaaab\n",
"type": "stdin_stdout"
},
{
"input": "babbbaab\n",
"output": "aaabbbbb\n",
"type": "stdin_stdout"
},
{
"input": "bcaccaab\n",
"output": "aaabcccb\n",
"type": "stdin_stdout"
},
{
"input": "bbccaabc\n",
"output": "aabccbbc\n",
"type": "stdin_stdout"
},
{
"input": "cacaaaac\n",
"output": "aaaaaccc\n",
"type": "stdin_stdout"
},
{
"input": "daacbddc\n",
"output": "aabccddd\n",
"type": "stdin_stdout"
},
{
"input": "cdbdcdaa\n",
"output": "aadcdbdc\n",
"type": "stdin_stdout"
},
{
"input": "bccbdacd\n",
"output": "acdbccbd\n",
"type": "stdin_stdout"
},
{
"input": "abbeaade\n",
"output": "aaadebbe\n",
"type": "stdin_stdout"
},
{
"input": "ccabecba\n",
"output": "aabcebcc\n",
"type": "stdin_stdout"
},
{
"input": "ececaead\n",
"output": "aadecece\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaa\n",
"output": "aaaaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaa\n",
"output": "aaaaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaa\n",
"output": "aaaaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aabaaabbb\n",
"output": "aaaaabbbb\n",
"type": "stdin_stdout"
},
{
"input": "abbbbbaab\n",
"output": "aaabbbbbb\n",
"type": "stdin_stdout"
},
{
"input": "bbbaababb\n",
"output": "aaabbbbbb\n",
"type": "stdin_stdout"
},
{
"input": "babcaaccb\n",
"output": "aaabcccbb\n",
"type": "stdin_stdout"
},
{
"input": "ccbcabaac\n",
"output": "aaabcbccc\n",
"type": "stdin_stdout"
},
{
"input": "caaaccccb\n",
"output": "aaabccccc\n",
"type": "stdin_stdout"
},
{
"input": "abbcdbddb\n",
"output": "abbbbdddc\n",
"type": "stdin_stdout"
},
{
"input": "dbcaacbbb\n",
"output": "aabbbccbd\n",
"type": "stdin_stdout"
},
{
"input": "cadcbddac\n",
"output": "aacddbcdc\n",
"type": "stdin_stdout"
},
{
"input": "ecebadadb\n",
"output": "aabddbece\n",
"type": "stdin_stdout"
},
{
"input": "bdbeeccdd\n",
"output": "bbccddeed\n",
"type": "stdin_stdout"
},
{
"input": "daaedecda\n",
"output": "aaadceded\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaaa\n",
"output": "aaaaaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaaa\n",
"output": "aaaaaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaaa\n",
"output": "aaaaaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "abaaaaabbb\n",
"output": "aaaaaabbbb\n",
"type": "stdin_stdout"
},
{
"input": "bbaaaabaaa\n",
"output": "aaaaaaabbb\n",
"type": "stdin_stdout"
},
{
"input": "bbabbaaaaa\n",
"output": "aaaaaabbbb\n",
"type": "stdin_stdout"
},
{
"input": "cbaabcaacc\n",
"output": "aaaacbbccc\n",
"type": "stdin_stdout"
},
{
"input": "aaaaccccab\n",
"output": "aaaaabcccc\n",
"type": "stdin_stdout"
},
{
"input": "bccaccaacc\n",
"output": "aaaccccbcc\n",
"type": "stdin_stdout"
},
{
"input": "dbdccdcacd\n",
"output": "accdccdbdd\n",
"type": "stdin_stdout"
},
{
"input": "caaddaaccb\n",
"output": "aaaabccddc\n",
"type": "stdin_stdout"
},
{
"input": "adbbabcbdc\n",
"output": "aabbbbccdd\n",
"type": "stdin_stdout"
},
{
"input": "cdeabdbbad\n",
"output": "aabbdbdedc\n",
"type": "stdin_stdout"
},
{
"input": "eeddcbeeec\n",
"output": "bcceeeddee\n",
"type": "stdin_stdout"
},
{
"input": "bbcebddeba\n",
"output": "abeddbecbb\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/797/C"
} | vfc_9826 |
apps | verifiable_code | 19 | Solve the following coding problem using the programming language python:
Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.
All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases by $1$. If he manages to finish the level successfully then the number of clears increases by $1$ as well. Note that both of the statistics update at the same time (so if the player finishes the level successfully then the number of plays will increase at the same time as the number of clears).
Polycarp is very excited about his level, so he keeps peeking at the stats to know how hard his level turns out to be.
So he peeked at the stats $n$ times and wrote down $n$ pairs of integers — $(p_1, c_1), (p_2, c_2), \dots, (p_n, c_n)$, where $p_i$ is the number of plays at the $i$-th moment of time and $c_i$ is the number of clears at the same moment of time. The stats are given in chronological order (i.e. the order of given pairs is exactly the same as Polycarp has written down).
Between two consecutive moments of time Polycarp peeked at the stats many players (but possibly zero) could attempt the level.
Finally, Polycarp wonders if he hasn't messed up any records and all the pairs are correct. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then he considers his records correct.
Help him to check the correctness of his records.
For your convenience you have to answer multiple independent test cases.
-----Input-----
The first line contains a single integer $T$ $(1 \le T \le 500)$ — the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \le n \le 100$) — the number of moments of time Polycarp peeked at the stats.
Each of the next $n$ lines contains two integers $p_i$ and $c_i$ ($0 \le p_i, c_i \le 1000$) — the number of plays and the number of clears of the level at the $i$-th moment of time.
Note that the stats are given in chronological order.
-----Output-----
For each test case print a single line.
If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then print "YES".
Otherwise, print "NO".
You can print each letter in any case (upper or lower).
-----Example-----
Input
6
3
0 0
1 1
1 2
2
1 0
1000 3
4
10 1
15 2
10 2
15 2
1
765 432
2
4 4
4 3
5
0 0
1 0
1 0
1 0
1 0
Output
NO
YES
NO
YES
NO
YES
-----Note-----
In the first test case at the third moment of time the number of clears increased but the number of plays did not, that couldn't have happened.
The second test case is a nice example of a Super Expert level.
In the third test case the number of plays decreased, which is impossible.
The fourth test case is probably an auto level with a single jump over the spike.
In the fifth test case the number of clears decreased, which is also impossible.
Nobody wanted to play the sixth test case; Polycarp's mom attempted it to make him feel better, however, she couldn't clear it.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
input = sys.stdin.readline
T = int(input())
for _ in range(T):
n = int(input())
lastP = 0
lastC = 0
works = True
for _ in range(n):
p, c = list(map(int, input().split()))
pDiff = p-lastP
cDiff = c-lastC
if 0 <= cDiff <= pDiff:
pass
else:
works = False
lastP = p
lastC = c
if works:
print('YES')
else:
print('NO')
``` | {
"language": "python",
"test_cases": [
{
"input": "6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n",
"output": "NO\nYES\nNO\nYES\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 1\n11 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 2\n8 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n43 34\n44 35\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n4 1\n5 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n100 0\n101 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n2 1\n4 1\n5 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4\n0 0\n0 0\n2 1\n3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 1\n12 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 3\n13 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 0\n11 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n765 432\n767 436\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n1 0\n2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n99\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n2 1\n5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n3 1\n6 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n2 1\n3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n100 1\n101 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n2 0\n3 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 0\n10 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n3 0\n5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n0 0\n100 0\n101 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 1\n11 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 2\n11 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n3 1\n5 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4\n1 0\n3 2\n13 13\n15 15\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 0\n7 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n10 1\n11 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n0 0\n5 1\n7 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4\n0 0\n1 0\n2 0\n3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n0 0\n2 1\n3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n3 1\n4 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4\n4 2\n7 6\n8 8\n9 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n3\n0 0\n100 0\n104 5\n3\n0 0\n100 0\n104 4\n",
"output": "NO\nYES\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n3 2\n4 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n6 1\n8 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 1\n6 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n4 2\n5 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n4\n1 1\n10 10\n100 10\n1000 920\n4\n1 5\n1000 100\n1000 100\n1000 100\n",
"output": "NO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n4 3\n9 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 2\n12 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n100 50\n101 99\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 0\n4 0\n6 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 1\n6 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 1\n12 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n3 2\n5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n4 3\n7 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n0 0\n10 1\n15 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n401 1\n402 2\n403 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n5 0\n7 4\n10 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n100 1\n101 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n0 0\n4 3\n5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 3\n10 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n500 0\n501 400\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n5\n1 0\n1 0\n5 5\n6 6\n7 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 2\n9 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n4 2\n6 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 1\n6 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n3 2\n4 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 2\n6 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n6 2\n8 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n1 0\n3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n4 1\n5 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n12 10\n15 15\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 1\n11 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n5\n1 1\n2 1\n3 1\n4 1\n5 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n7 3\n8 4\n9 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n4 2\n5 4\n6 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n6 3\n7 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 3\n6 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4\n3 2\n5 4\n8 8\n9 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n100 51\n101 99\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 2\n15 14\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n4 2\n5 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n2\n1 0\n2 2\n1\n0 1\n",
"output": "NO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n1 0\n10 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n5\n42 18\n70 25\n82 28\n96 43\n99 48\n5\n85 49\n90 49\n92 50\n95 50\n99 50\n5\n37 50\n95 50\n100 50\n100 50\n100 50\n5\n59 34\n100 38\n100 38\n100 39\n100 41\n5\n40 39\n97 47\n97 50\n99 50\n100 50\n",
"output": "NO\nYES\nNO\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n10 2\n12 7\n13 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 4\n6 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n1\n1 2\n3\n1 1\n2 2\n3 2\n3\n1 1\n1 1\n1 1\n5\n0 0\n0 0\n1 0\n1 0\n2 2\n",
"output": "NO\nYES\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 0\n7 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n4 2\n6 5\n6 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n30 20\n40 40\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n8 1\n9 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n2\n1 0\n4 4\n1\n1 2\n2\n4 0\n6 3\n",
"output": "NO\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n0 0\n50 20\n55 30\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n0 0\n11 5\n21 20\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n108 1\n110 22\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n100 10\n101 101\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 3\n11 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n4 1\n10 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n7 6\n8 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n30 10\n31 20\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n5 1\n6 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4\n4 1\n5 1\n6 4\n6 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 1\n11 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 5\n11 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n2 1\n3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n10 5\n12 8\n13 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n11 1\n12 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n5 0\n7 5\n8 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n5\n25 10\n26 12\n27 13\n28 14\n29 15\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 2\n6 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n5\n1 0\n1 0\n5 1\n6 3\n7 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 8\n12 11\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 5\n16 12\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n110 2\n115 112\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4\n1 1\n2 1\n5 1\n6 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 1\n101 101\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n2 0\n7 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 0\n6 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 1\n7 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 8\n20 19\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n2\n4 1\n5 3\n2\n100 50\n101 99\n",
"output": "NO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n2 1\n4 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n0 0\n5 3\n6 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n30 10\n31 21\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n100 5\n101 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n0 0\n10 5\n11 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n4 3\n8 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n3\n2 1\n3 2\n4 4\n2\n5 3\n5 6\n2\n2 2\n3 2\n",
"output": "NO\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n100 3\n105 50\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 1\n8 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10\n5\n88 60\n10 3\n48 21\n90 70\n40 88\n5\n20 81\n39 98\n34 87\n100 82\n21 21\n2\n46 91\n89 71\n2\n81 98\n25 36\n3\n84 97\n40 32\n17 29\n2\n56 16\n96 75\n5\n35 24\n82 73\n23 15\n45 95\n79 90\n2\n68 13\n70 100\n3\n94 35\n95 77\n31 86\n5\n99 14\n12 54\n81 60\n80 29\n46 55\n",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n500 1\n501 99\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "11\n5\n85 49\n90 49\n92 50\n95 50\n99 50\n5\n85 49\n90 49\n92 50\n95 50\n99 50\n1\n3 4\n5\n42 18\n70 25\n82 28\n96 43\n99 48\n5\n37 50\n95 50\n100 50\n100 50\n100 50\n5\n59 34\n100 38\n100 38\n100 39\n100 41\n5\n40 39\n97 47\n97 50\n99 50\n100 50\n5\n42 18\n70 25\n82 28\n96 43\n99 48\n5\n37 50\n95 50\n100 50\n100 50\n100 50\n5\n59 34\n100 38\n100 38\n100 39\n100 41\n5\n40 39\n97 47\n97 50\n99 50\n100 50\n",
"output": "YES\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n5 1\n6 3\n7 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 7\n12 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n5 2\n7 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n3\n4 2\n5 5\n6 6\n3\n1 1\n3 3\n4 4\n",
"output": "NO\nYES\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n3 0\n5 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n4 3\n6 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n3 2\n4 2\n5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n99 49\n100 50\n101 99\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n13 10\n16 15\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n3 2\n7 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n5 2\n6 5\n7 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 8\n11 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n2\n2 0\n3 2\n3\n0 0\n3 1\n4 3\n",
"output": "NO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4\n1 0\n2 1\n4 4\n6 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n11 0\n13 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n2 1\n5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n100 3\n105 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n2 0\n3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n10 9\n11 11\n11 11\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n10 6\n15 12\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "19\n1\n1 1\n1\n2 2\n1\n3 3\n1\n4 4\n1\n5 5\n1\n6 6\n1\n7 7\n1\n8 8\n1\n9 9\n1\n10 10\n1\n11 11\n1\n12 12\n1\n13 13\n1\n14 14\n1\n15 15\n1\n16 16\n1\n17 17\n1\n18 18\n1\n19 19\n",
"output": "YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n",
"type": "stdin_stdout"
},
{
"input": "20\n2\n1 0\n1000 3\n3\n4 2\n4 2\n4 2\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n",
"output": "YES\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n5 2\n6 4\n7 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n10 3\n13 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n0 0\n5 3\n6 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n0 0\n3 1\n4 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 1\n10 1\n11 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4\n0 0\n1 1\n10 1\n11 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n3\n2 1\n3 2\n4 4\n2\n5 3\n5 6\n2\n2 2\n3 2\n3\n1 1\n2 2\n145 1\n",
"output": "NO\nNO\nYES\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4\n1 0\n5 4\n10 5\n11 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n11\n1 1\n1 1\n3 1\n20 18\n21 19\n43 41\n43 41\n44 42\n46 44\n47 45\n48 47\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n5\n5 1\n6 3\n7 4\n8 5\n9 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n1 0\n5 1\n6 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n4 3\n5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n2 2\n10 3\n11 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n5 4\n8 8\n9 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10\n2\n1 2\n3 3\n1\n5 3\n2\n3 0\n4 5\n1\n3 5\n1\n0 5\n2\n5 4\n0 4\n2\n0 1\n0 5\n1\n4 3\n2\n5 3\n2 5\n2\n5 4\n5 1\n",
"output": "NO\nYES\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n18 10\n22 15\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1334/A"
} | vfc_9830 |
apps | verifiable_code | 20 | Solve the following coding problem using the programming language python:
Karen is getting ready for a new school day!
[Image]
It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome.
What is the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome?
Remember that a palindrome is a string that reads the same forwards and backwards. For instance, 05:39 is not a palindrome, because 05:39 backwards is 93:50. On the other hand, 05:50 is a palindrome, because 05:50 backwards is 05:50.
-----Input-----
The first and only line of input contains a single string in the format hh:mm (00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59).
-----Output-----
Output a single integer on a line by itself, the minimum number of minutes she should sleep, such that, when she wakes up, the time is a palindrome.
-----Examples-----
Input
05:39
Output
11
Input
13:31
Output
0
Input
23:59
Output
1
-----Note-----
In the first test case, the minimum number of minutes Karen should sleep for is 11. She can wake up at 05:50, when the time is a palindrome.
In the second test case, Karen can wake up immediately, as the current time, 13:31, is already a palindrome.
In the third test case, the minimum number of minutes Karen should sleep for is 1 minute. She can wake up at 00:00, when the time is a palindrome.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
h = int(s[:2])
m = int(s[3:])
def ispalin(h, m):
s = "%02d:%02d"%(h,m)
return s == s[::-1]
for d in range(999999):
if ispalin(h, m):
print(d)
break
m+= 1
if m == 60:
h = (h+1)%24
m = 0
``` | {
"language": "python",
"test_cases": [
{
"input": "05:39\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "13:31\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "23:59\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "13:32\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "14:40\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "14:00\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "05:50\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "12:22\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "12:34\n",
"output": "57\n",
"type": "stdin_stdout"
},
{
"input": "05:30\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "14:14\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "01:10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "02:20\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "03:30\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "04:40\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10:01\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "11:11\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "12:21\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "14:41\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15:51\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20:02\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "21:12\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "22:22\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "23:32\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "01:11\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "02:21\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "03:31\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "04:41\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "05:51\n",
"output": "250\n",
"type": "stdin_stdout"
},
{
"input": "10:02\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "11:12\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "14:42\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "15:52\n",
"output": "250\n",
"type": "stdin_stdout"
},
{
"input": "20:03\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "21:13\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "22:23\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "23:33\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "00:00\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "00:01\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "22:21\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "20:01\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "11:10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "06:59\n",
"output": "182\n",
"type": "stdin_stdout"
},
{
"input": "02:00\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "02:19\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "17:31\n",
"output": "151\n",
"type": "stdin_stdout"
},
{
"input": "19:00\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "13:37\n",
"output": "64\n",
"type": "stdin_stdout"
},
{
"input": "07:59\n",
"output": "122\n",
"type": "stdin_stdout"
},
{
"input": "04:20\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "07:10\n",
"output": "171\n",
"type": "stdin_stdout"
},
{
"input": "06:00\n",
"output": "241\n",
"type": "stdin_stdout"
},
{
"input": "06:01\n",
"output": "240\n",
"type": "stdin_stdout"
},
{
"input": "08:15\n",
"output": "106\n",
"type": "stdin_stdout"
},
{
"input": "06:59\n",
"output": "182\n",
"type": "stdin_stdout"
},
{
"input": "01:00\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "07:00\n",
"output": "181\n",
"type": "stdin_stdout"
},
{
"input": "06:10\n",
"output": "231\n",
"type": "stdin_stdout"
},
{
"input": "18:52\n",
"output": "70\n",
"type": "stdin_stdout"
},
{
"input": "09:59\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "19:00\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "15:52\n",
"output": "250\n",
"type": "stdin_stdout"
},
{
"input": "06:50\n",
"output": "191\n",
"type": "stdin_stdout"
},
{
"input": "00:00\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "19:20\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "05:51\n",
"output": "250\n",
"type": "stdin_stdout"
},
{
"input": "06:16\n",
"output": "225\n",
"type": "stdin_stdout"
},
{
"input": "10:10\n",
"output": "61\n",
"type": "stdin_stdout"
},
{
"input": "17:11\n",
"output": "171\n",
"type": "stdin_stdout"
},
{
"input": "18:00\n",
"output": "122\n",
"type": "stdin_stdout"
},
{
"input": "00:01\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "05:04\n",
"output": "46\n",
"type": "stdin_stdout"
},
{
"input": "16:00\n",
"output": "242\n",
"type": "stdin_stdout"
},
{
"input": "23:31\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "17:25\n",
"output": "157\n",
"type": "stdin_stdout"
},
{
"input": "23:32\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "23:58\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "02:21\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "01:11\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "23:46\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "00:09\n",
"output": "61\n",
"type": "stdin_stdout"
},
{
"input": "09:20\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "05:59\n",
"output": "242\n",
"type": "stdin_stdout"
},
{
"input": "18:59\n",
"output": "63\n",
"type": "stdin_stdout"
},
{
"input": "02:02\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "00:30\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "05:54\n",
"output": "247\n",
"type": "stdin_stdout"
},
{
"input": "19:59\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "16:59\n",
"output": "183\n",
"type": "stdin_stdout"
},
{
"input": "17:51\n",
"output": "131\n",
"type": "stdin_stdout"
},
{
"input": "09:30\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"input": "10:01\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "16:55\n",
"output": "187\n",
"type": "stdin_stdout"
},
{
"input": "20:02\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "16:12\n",
"output": "230\n",
"type": "stdin_stdout"
},
{
"input": "20:00\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "01:01\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "23:01\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"input": "06:05\n",
"output": "236\n",
"type": "stdin_stdout"
},
{
"input": "19:19\n",
"output": "43\n",
"type": "stdin_stdout"
},
{
"input": "17:00\n",
"output": "182\n",
"type": "stdin_stdout"
},
{
"input": "07:50\n",
"output": "131\n",
"type": "stdin_stdout"
},
{
"input": "21:20\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "23:23\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "19:30\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"input": "00:59\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "22:59\n",
"output": "33\n",
"type": "stdin_stdout"
},
{
"input": "18:18\n",
"output": "104\n",
"type": "stdin_stdout"
},
{
"input": "17:46\n",
"output": "136\n",
"type": "stdin_stdout"
},
{
"input": "07:30\n",
"output": "151\n",
"type": "stdin_stdout"
},
{
"input": "17:16\n",
"output": "166\n",
"type": "stdin_stdout"
},
{
"input": "06:06\n",
"output": "235\n",
"type": "stdin_stdout"
},
{
"input": "23:30\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "05:57\n",
"output": "244\n",
"type": "stdin_stdout"
},
{
"input": "19:46\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "11:10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "17:07\n",
"output": "175\n",
"type": "stdin_stdout"
},
{
"input": "18:53\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "07:06\n",
"output": "175\n",
"type": "stdin_stdout"
},
{
"input": "17:50\n",
"output": "132\n",
"type": "stdin_stdout"
},
{
"input": "09:15\n",
"output": "46\n",
"type": "stdin_stdout"
},
{
"input": "09:55\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "20:05\n",
"output": "67\n",
"type": "stdin_stdout"
},
{
"input": "22:55\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "10:00\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "07:55\n",
"output": "126\n",
"type": "stdin_stdout"
},
{
"input": "07:40\n",
"output": "141\n",
"type": "stdin_stdout"
},
{
"input": "19:08\n",
"output": "54\n",
"type": "stdin_stdout"
},
{
"input": "23:24\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "16:15\n",
"output": "227\n",
"type": "stdin_stdout"
},
{
"input": "07:20\n",
"output": "161\n",
"type": "stdin_stdout"
},
{
"input": "23:10\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "06:51\n",
"output": "190\n",
"type": "stdin_stdout"
},
{
"input": "16:30\n",
"output": "212\n",
"type": "stdin_stdout"
},
{
"input": "17:54\n",
"output": "128\n",
"type": "stdin_stdout"
},
{
"input": "07:07\n",
"output": "174\n",
"type": "stdin_stdout"
},
{
"input": "08:01\n",
"output": "120\n",
"type": "stdin_stdout"
},
{
"input": "09:58\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "18:03\n",
"output": "119\n",
"type": "stdin_stdout"
},
{
"input": "07:59\n",
"output": "122\n",
"type": "stdin_stdout"
},
{
"input": "05:55\n",
"output": "246\n",
"type": "stdin_stdout"
},
{
"input": "07:39\n",
"output": "142\n",
"type": "stdin_stdout"
},
{
"input": "05:52\n",
"output": "249\n",
"type": "stdin_stdout"
},
{
"input": "12:02\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "08:59\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "09:21\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "16:04\n",
"output": "238\n",
"type": "stdin_stdout"
},
{
"input": "04:00\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "18:21\n",
"output": "101\n",
"type": "stdin_stdout"
},
{
"input": "09:13\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"input": "17:20\n",
"output": "162\n",
"type": "stdin_stdout"
},
{
"input": "06:15\n",
"output": "226\n",
"type": "stdin_stdout"
},
{
"input": "19:21\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "16:02\n",
"output": "240\n",
"type": "stdin_stdout"
},
{
"input": "15:59\n",
"output": "243\n",
"type": "stdin_stdout"
},
{
"input": "06:07\n",
"output": "234\n",
"type": "stdin_stdout"
},
{
"input": "08:08\n",
"output": "113\n",
"type": "stdin_stdout"
},
{
"input": "09:09\n",
"output": "52\n",
"type": "stdin_stdout"
},
{
"input": "02:19\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "21:59\n",
"output": "23\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/816/A"
} | vfc_9834 |
apps | verifiable_code | 21 | Solve the following coding problem using the programming language python:
Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n.
Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each other. He wants to perform exactly one swap in order to maximize the distance between the minimum and the maximum elements. The distance between two elements is considered to be equal to the absolute difference between their positions.
-----Input-----
The first line of the input contains a single integer n (2 ≤ n ≤ 100) — the size of the permutation.
The second line of the input contains n distinct integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ n), where a_{i} is equal to the element at the i-th position.
-----Output-----
Print a single integer — the maximum possible distance between the minimum and the maximum elements Nicholas can achieve by performing exactly one swap.
-----Examples-----
Input
5
4 5 1 3 2
Output
3
Input
7
1 6 5 3 4 7 2
Output
6
Input
6
6 5 4 3 2 1
Output
5
-----Note-----
In the first sample, one may obtain the optimal answer by swapping elements 1 and 2.
In the second sample, the minimum and the maximum elements will be located in the opposite ends of the array if we swap 7 and 2.
In the third sample, the distance between the minimum and the maximum elements is already maximum possible, so we just perform some unnecessary swap, for example, one can swap 5 and 2.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
read = lambda: list(map(int, input().split()))
n = int(input())
a = list(read())
x, y = a.index(1), a.index(n)
ans = max(x, y, n - x - 1, n - y - 1)
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n4 5 1 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\n1 6 5 3 4 7 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "6\n6 5 4 3 2 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 3 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 1 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 4 5 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6\n4 6 3 5 2 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7\n1 5 3 6 2 4 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "100\n76 70 67 54 40 1 48 63 64 36 42 90 99 27 47 17 93 7 13 84 16 57 74 5 83 61 19 56 52 92 38 91 82 79 34 66 71 28 37 98 35 94 77 53 73 10 26 80 15 32 8 81 3 95 44 46 72 6 33 11 21 85 4 30 24 51 49 96 87 55 14 31 12 60 45 9 29 22 58 18 88 2 50 59 20 86 23 41 100 39 62 68 69 97 78 43 25 89 65 75\n",
"output": "94\n",
"type": "stdin_stdout"
},
{
"input": "8\n4 5 3 8 6 7 1 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "9\n6 8 5 3 4 7 9 2 1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10\n8 7 10 1 2 3 4 6 5 9\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "11\n5 4 6 9 10 11 7 3 1 2 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "12\n3 6 7 8 9 10 12 5 4 2 11 1\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "13\n8 4 3 7 5 11 9 1 10 2 13 12 6\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "14\n6 10 13 9 7 1 12 14 3 2 5 4 11 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "15\n3 14 13 12 7 2 4 11 15 1 8 6 5 10 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "16\n11 6 9 8 7 14 12 13 10 15 2 5 3 1 4 16\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "17\n13 12 5 3 9 16 8 14 2 4 10 1 6 11 7 15 17\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "18\n8 6 14 17 9 11 15 13 5 3 18 1 2 7 12 16 4 10\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "19\n12 19 3 11 15 6 18 14 5 10 2 13 9 7 4 8 17 16 1\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "20\n15 17 10 20 7 2 16 9 13 6 18 5 19 8 11 14 4 12 3 1\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "21\n1 9 14 18 13 12 11 20 16 2 4 19 15 7 6 17 8 5 3 10 21\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "22\n8 3 17 4 16 21 14 11 10 15 6 18 13 12 22 20 5 2 9 7 19 1\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "23\n1 23 11 20 9 3 12 4 7 17 5 15 2 10 18 16 8 22 14 13 19 21 6\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "24\n2 10 23 22 20 19 18 16 11 12 15 17 21 8 24 13 1 5 6 7 14 3 9 4\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "25\n12 13 22 17 1 18 14 5 21 2 10 4 3 23 11 6 20 8 24 16 15 19 9 7 25\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "26\n6 21 20 16 26 17 11 2 24 4 1 12 14 8 25 7 15 10 22 5 13 18 9 23 19 3\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "27\n20 14 18 10 5 3 9 4 24 22 21 27 17 15 26 2 23 7 12 11 6 8 19 25 16 13 1\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "28\n28 13 16 6 1 12 4 27 22 7 18 3 21 26 25 11 5 10 20 24 19 15 14 8 23 17 9 2\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "29\n21 11 10 25 2 5 9 16 29 8 17 4 15 13 6 22 7 24 19 12 18 20 1 3 23 28 27 14 26\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "30\n6 19 14 22 26 17 27 8 25 3 24 30 4 18 23 16 9 13 29 20 15 2 5 11 28 12 1 10 21 7\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "31\n29 13 26 27 9 28 2 16 30 21 12 11 3 31 23 6 22 20 1 5 14 24 19 18 8 4 10 17 15 25 7\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "32\n15 32 11 3 18 23 19 14 5 8 6 21 13 24 25 4 16 9 27 20 17 31 2 22 7 12 30 1 26 10 29 28\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "33\n22 13 10 33 8 25 15 14 21 28 27 19 26 24 1 12 5 11 32 20 30 31 18 4 6 23 7 29 16 2 17 9 3\n",
"output": "29\n",
"type": "stdin_stdout"
},
{
"input": "34\n34 30 7 16 6 1 10 23 29 13 15 25 32 26 18 11 28 3 14 21 19 5 31 33 4 17 8 9 24 20 27 22 2 12\n",
"output": "33\n",
"type": "stdin_stdout"
},
{
"input": "35\n24 33 20 8 34 11 31 25 2 4 18 13 9 35 16 30 23 32 17 1 14 22 19 21 28 26 3 15 5 12 27 29 10 6 7\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "36\n1 32 27 35 22 7 34 15 18 36 31 28 13 2 10 21 20 17 16 4 3 24 19 29 11 12 25 5 33 26 14 6 9 23 30 8\n",
"output": "35\n",
"type": "stdin_stdout"
},
{
"input": "37\n24 1 12 23 11 6 30 15 4 21 13 20 25 17 5 8 36 19 32 26 14 9 7 18 10 29 37 35 16 2 22 34 3 27 31 33 28\n",
"output": "35\n",
"type": "stdin_stdout"
},
{
"input": "38\n9 35 37 28 36 21 10 25 19 4 26 5 22 7 27 18 6 14 15 24 1 17 11 34 20 8 2 16 3 23 32 31 13 12 38 33 30 29\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "39\n16 28 4 33 26 36 25 23 22 30 27 7 12 34 17 6 3 38 10 24 13 31 29 39 14 32 9 20 35 11 18 21 8 2 15 37 5 19 1\n",
"output": "38\n",
"type": "stdin_stdout"
},
{
"input": "40\n35 39 28 11 9 31 36 8 5 32 26 19 38 33 2 22 23 25 6 37 12 7 3 10 17 24 20 16 27 4 34 15 40 14 18 13 29 21 30 1\n",
"output": "39\n",
"type": "stdin_stdout"
},
{
"input": "41\n24 18 7 23 3 15 1 17 25 5 30 10 34 36 2 14 9 21 41 40 20 28 33 35 12 22 11 8 19 16 31 27 26 32 29 4 13 38 37 39 6\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "42\n42 15 24 26 4 34 19 29 38 32 31 33 14 41 21 3 11 39 25 6 5 20 23 10 16 36 18 28 27 1 7 40 22 30 9 2 37 17 8 12 13 35\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "43\n43 24 20 13 22 29 28 4 30 3 32 40 31 8 7 9 35 27 18 5 42 6 17 19 23 12 41 21 16 37 33 34 2 14 36 38 25 10 15 39 26 11 1\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "44\n4 38 6 40 29 3 44 2 30 35 25 36 34 10 11 31 21 7 14 23 37 19 27 18 5 22 1 16 17 9 39 13 15 32 43 8 41 26 42 12 24 33 20 28\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "45\n45 29 24 2 31 5 34 41 26 44 33 43 15 3 4 11 21 37 27 12 14 39 23 42 16 6 13 19 8 38 20 9 25 22 40 17 32 35 18 10 28 7 30 36 1\n",
"output": "44\n",
"type": "stdin_stdout"
},
{
"input": "46\n29 3 12 33 45 40 19 17 25 27 28 1 16 23 24 46 31 8 44 15 5 32 22 11 4 36 34 10 35 26 21 7 14 2 18 9 20 41 6 43 42 37 38 13 39 30\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "47\n7 3 8 12 24 16 29 10 28 38 1 20 37 40 21 5 15 6 45 23 36 44 25 43 41 4 11 42 18 35 32 31 39 33 27 30 22 34 14 13 17 47 19 9 46 26 2\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "48\n29 26 14 18 34 33 13 39 32 1 37 20 35 19 28 48 30 23 46 27 5 22 24 38 12 15 8 36 43 45 16 47 6 9 31 40 44 17 2 41 11 42 25 4 21 3 10 7\n",
"output": "38\n",
"type": "stdin_stdout"
},
{
"input": "49\n16 7 42 32 11 35 15 8 23 41 6 20 47 24 9 45 49 2 37 48 25 28 5 18 3 19 12 4 22 33 13 14 10 36 44 17 40 38 30 26 1 43 29 46 21 34 27 39 31\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "50\n31 45 3 34 13 43 32 4 42 9 7 8 24 14 35 6 19 46 44 17 18 1 25 20 27 41 2 16 12 10 11 47 38 21 28 49 30 15 50 36 29 26 22 39 48 5 23 37 33 40\n",
"output": "38\n",
"type": "stdin_stdout"
},
{
"input": "51\n47 29 2 11 43 44 27 1 39 14 25 30 33 21 38 45 34 51 16 50 42 31 41 46 15 48 13 19 6 37 35 7 22 28 20 4 17 10 5 8 24 40 9 36 18 49 12 26 23 3 32\n",
"output": "43\n",
"type": "stdin_stdout"
},
{
"input": "52\n16 45 23 7 15 19 43 20 4 32 35 36 9 50 5 26 38 46 13 33 12 2 48 37 41 31 10 28 8 42 3 21 11 1 17 27 34 30 44 40 6 51 49 47 25 22 18 24 52 29 14 39\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"input": "53\n53 30 50 22 51 31 32 38 12 7 39 43 1 23 6 8 24 52 2 21 34 13 3 35 5 15 19 11 47 18 9 20 29 4 36 45 27 41 25 48 16 46 44 17 10 14 42 26 40 28 33 37 49\n",
"output": "52\n",
"type": "stdin_stdout"
},
{
"input": "54\n6 39 17 3 45 52 16 21 23 48 42 36 13 37 46 10 43 27 49 7 38 32 31 30 15 25 2 29 8 51 54 19 41 44 24 34 22 5 20 14 12 1 33 40 4 26 9 35 18 28 47 50 11 53\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "55\n26 15 31 21 32 43 34 51 7 12 5 44 17 54 18 25 48 47 20 3 41 24 45 2 11 22 29 39 37 53 35 28 36 9 50 10 30 38 19 13 4 8 27 1 42 6 49 23 55 40 33 16 46 14 52\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"input": "56\n6 20 38 46 10 11 40 19 5 1 47 33 4 18 32 36 37 45 56 49 48 52 12 26 31 14 2 9 24 3 16 51 41 43 23 17 34 7 29 50 55 25 39 44 22 27 54 8 28 35 30 42 13 53 21 15\n",
"output": "46\n",
"type": "stdin_stdout"
},
{
"input": "57\n39 28 53 36 3 6 12 56 55 20 50 19 43 42 18 40 24 52 38 17 33 23 22 41 14 7 26 44 45 16 35 1 8 47 31 5 30 51 32 4 37 25 13 34 54 21 46 10 15 11 2 27 29 48 49 9 57\n",
"output": "56\n",
"type": "stdin_stdout"
},
{
"input": "58\n1 26 28 14 22 33 57 40 9 42 44 37 24 19 58 12 48 3 34 31 49 4 16 47 55 52 27 23 46 18 20 32 56 6 39 36 41 38 13 43 45 21 53 54 29 17 5 10 25 30 2 35 11 7 15 51 8 50\n",
"output": "57\n",
"type": "stdin_stdout"
},
{
"input": "59\n1 27 10 37 53 9 14 49 46 26 50 42 59 11 47 15 24 56 43 45 44 38 5 8 58 30 52 12 23 32 22 3 31 41 2 25 29 6 54 16 35 33 18 55 4 51 57 28 40 19 13 21 7 39 36 48 34 17 20\n",
"output": "58\n",
"type": "stdin_stdout"
},
{
"input": "60\n60 27 34 32 54 55 33 12 40 3 47 44 50 39 38 59 11 25 17 15 16 30 21 31 10 52 5 23 4 48 6 26 36 57 14 22 8 56 58 9 24 7 37 53 42 43 20 49 51 19 2 46 28 18 35 13 29 45 41 1\n",
"output": "59\n",
"type": "stdin_stdout"
},
{
"input": "61\n61 11 26 29 31 40 32 30 35 3 18 52 9 53 42 4 50 54 20 58 28 49 22 12 2 19 16 15 57 34 51 43 7 17 25 41 56 47 55 60 46 14 44 45 24 27 33 1 48 13 59 23 38 39 6 5 36 10 8 37 21\n",
"output": "60\n",
"type": "stdin_stdout"
},
{
"input": "62\n21 23 34 38 11 61 55 30 37 48 54 51 46 47 6 56 36 49 1 35 12 28 29 20 43 42 5 8 22 57 44 4 53 10 58 33 27 25 16 45 50 40 18 15 3 41 39 2 7 60 59 13 32 24 52 31 14 9 19 26 17 62\n",
"output": "61\n",
"type": "stdin_stdout"
},
{
"input": "63\n2 5 29 48 31 26 21 16 47 24 43 22 61 28 6 39 60 27 14 52 37 7 53 8 62 56 63 10 50 18 44 13 4 9 25 11 23 42 45 41 59 12 32 36 40 51 1 35 49 54 57 20 19 34 38 46 33 3 55 15 30 58 17\n",
"output": "46\n",
"type": "stdin_stdout"
},
{
"input": "64\n23 5 51 40 12 46 44 8 64 31 58 55 45 24 54 39 21 19 52 61 30 42 16 18 15 32 53 22 28 26 11 25 48 56 27 9 29 41 35 49 59 38 62 7 34 1 20 33 60 17 2 3 43 37 57 14 6 36 13 10 50 4 63 47\n",
"output": "55\n",
"type": "stdin_stdout"
},
{
"input": "65\n10 11 55 43 53 25 35 26 16 37 41 38 59 21 48 2 65 49 17 23 18 30 62 36 3 4 47 15 28 63 57 54 31 46 44 12 51 7 29 13 56 52 14 22 39 19 8 27 45 5 6 34 32 61 20 50 9 24 33 58 60 40 1 42 64\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "66\n66 39 3 2 55 53 60 54 12 49 10 30 59 26 32 46 50 56 7 13 43 36 24 28 11 8 6 21 35 25 42 57 23 45 64 5 34 61 27 51 52 9 15 1 38 17 63 48 37 20 58 14 47 19 22 41 31 44 33 65 4 62 40 18 16 29\n",
"output": "65\n",
"type": "stdin_stdout"
},
{
"input": "67\n66 16 2 53 35 38 49 28 18 6 36 58 21 47 27 5 50 62 44 12 52 37 11 56 15 31 25 65 17 29 59 41 7 42 4 43 39 10 1 40 24 13 20 54 19 67 46 60 51 45 64 30 8 33 26 9 3 22 34 23 57 48 55 14 63 61 32\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "68\n13 6 27 21 65 23 59 14 62 43 33 31 38 41 67 20 16 25 42 4 28 40 29 9 64 17 2 26 32 58 60 53 46 48 47 54 44 50 39 19 30 57 61 1 11 18 37 24 55 15 63 34 8 52 56 7 10 12 35 66 5 36 45 49 68 22 51 3\n",
"output": "64\n",
"type": "stdin_stdout"
},
{
"input": "69\n29 49 25 51 21 35 11 61 39 54 40 37 60 42 27 33 59 53 34 10 46 2 23 69 8 47 58 36 1 38 19 12 7 48 13 3 6 22 18 5 65 24 50 41 66 44 67 57 4 56 62 43 9 30 14 15 28 31 64 26 16 55 68 17 32 20 45 52 63\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "70\n19 12 15 18 36 16 61 69 24 7 11 13 3 48 55 21 37 17 43 31 41 22 28 32 27 63 38 49 59 56 30 25 67 51 52 45 50 44 66 57 26 60 5 46 33 6 23 34 8 40 2 68 14 39 65 64 62 42 47 54 10 53 9 1 70 58 20 4 29 35\n",
"output": "64\n",
"type": "stdin_stdout"
},
{
"input": "71\n40 6 62 3 41 52 31 66 27 16 35 5 17 60 2 15 51 22 67 61 71 53 1 64 8 45 28 18 50 30 12 69 20 26 10 37 36 49 70 32 33 11 57 14 9 55 4 58 29 25 44 65 39 48 24 47 19 46 56 38 34 42 59 63 54 23 7 68 43 13 21\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "72\n52 64 71 40 32 10 62 21 11 37 38 13 22 70 1 66 41 50 27 20 42 47 25 68 49 12 15 72 44 60 53 5 23 14 43 29 65 36 51 54 35 67 7 19 55 48 58 46 39 24 33 30 61 45 57 2 31 3 18 59 6 9 4 63 8 16 26 34 28 69 17 56\n",
"output": "57\n",
"type": "stdin_stdout"
},
{
"input": "73\n58 38 47 34 39 64 69 66 72 57 9 4 67 22 35 13 61 14 28 52 56 20 31 70 27 24 36 1 62 17 10 5 12 33 16 73 18 49 63 71 44 65 23 30 40 8 50 46 60 25 11 26 37 55 29 68 42 2 3 32 59 7 15 43 41 48 51 53 6 45 54 19 21\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "74\n19 51 59 34 8 40 42 55 65 16 74 26 49 63 64 70 35 72 7 12 43 18 61 27 47 31 13 32 71 22 25 67 9 1 48 50 33 10 21 46 11 45 17 37 28 60 69 66 38 2 30 3 39 15 53 68 57 41 6 36 24 73 4 23 5 62 44 14 20 29 52 54 56 58\n",
"output": "63\n",
"type": "stdin_stdout"
},
{
"input": "75\n75 28 60 19 59 17 65 26 32 23 18 64 8 62 4 11 42 16 47 5 72 46 9 1 25 21 2 50 33 6 36 68 30 12 20 40 53 45 34 7 37 39 38 44 63 61 67 3 66 51 29 73 24 57 70 27 10 56 22 55 13 49 35 15 54 41 14 74 69 48 52 31 71 43 58\n",
"output": "74\n",
"type": "stdin_stdout"
},
{
"input": "76\n1 47 54 17 38 37 12 32 14 48 43 71 60 56 4 13 64 41 52 57 62 24 23 49 20 10 63 3 25 66 59 40 58 33 53 46 70 7 35 61 72 74 73 19 30 5 29 6 15 28 21 27 51 55 50 9 65 8 67 39 76 42 31 34 16 2 36 11 26 44 22 45 75 18 69 68\n",
"output": "75\n",
"type": "stdin_stdout"
},
{
"input": "77\n10 20 57 65 53 69 59 45 58 32 28 72 4 14 1 33 40 47 7 5 51 76 37 16 41 61 42 2 21 26 38 74 35 64 43 77 71 50 39 48 27 63 73 44 52 66 9 18 23 54 25 6 8 56 13 67 36 22 15 46 62 75 55 11 31 17 24 29 60 68 12 30 3 70 49 19 34\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "78\n7 61 69 47 68 42 65 78 70 3 32 59 49 51 23 71 11 63 22 18 43 34 24 13 27 16 19 40 21 46 48 77 28 66 54 67 60 15 75 62 9 26 52 58 4 25 8 37 41 76 1 6 30 50 44 36 5 14 29 53 17 12 2 57 73 35 64 39 56 10 33 20 45 74 31 55 38 72\n",
"output": "70\n",
"type": "stdin_stdout"
},
{
"input": "79\n75 79 43 66 72 52 29 65 74 38 24 1 5 51 13 7 71 33 4 61 2 36 63 47 64 44 34 27 3 21 17 37 54 53 49 20 28 60 39 10 16 76 6 77 73 22 50 48 78 30 67 56 31 26 40 59 41 11 18 45 69 62 15 23 32 70 19 55 68 57 35 25 12 46 14 42 9 8 58\n",
"output": "77\n",
"type": "stdin_stdout"
},
{
"input": "80\n51 20 37 12 68 11 28 52 76 21 7 5 3 16 64 34 25 2 6 40 60 62 75 13 45 17 56 29 32 47 79 73 49 72 15 46 30 54 80 27 43 24 74 18 42 71 14 4 44 63 65 33 1 77 55 57 41 59 58 70 69 35 19 67 10 36 26 23 48 50 39 61 9 66 38 8 31 22 53 78\n",
"output": "52\n",
"type": "stdin_stdout"
},
{
"input": "81\n63 22 4 41 43 74 64 39 10 35 20 81 11 28 70 67 53 79 16 61 68 52 27 37 58 9 50 49 18 30 72 47 7 60 78 51 23 48 73 66 44 13 15 57 56 38 1 76 25 45 36 34 42 8 75 26 59 14 71 21 6 77 5 17 2 32 40 54 46 24 29 3 31 19 65 62 33 69 12 80 55\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "82\n50 24 17 41 49 18 80 11 79 72 57 31 21 35 2 51 36 66 20 65 38 3 45 32 59 81 28 30 70 55 29 76 73 6 33 39 8 7 19 48 63 1 77 43 4 13 78 54 69 9 40 46 74 82 60 71 16 64 12 14 47 26 44 5 10 75 53 25 27 15 56 42 58 34 23 61 67 62 68 22 37 52\n",
"output": "53\n",
"type": "stdin_stdout"
},
{
"input": "83\n64 8 58 17 67 46 3 82 23 70 72 16 53 45 13 20 12 48 40 4 6 47 76 60 19 44 30 78 28 22 75 15 25 29 63 74 55 32 14 51 35 31 62 77 27 42 65 71 56 61 66 41 68 49 7 34 2 83 36 5 33 26 37 80 59 50 1 9 54 21 18 24 38 73 81 52 10 39 43 79 57 11 69\n",
"output": "66\n",
"type": "stdin_stdout"
},
{
"input": "84\n75 8 66 21 61 63 72 51 52 13 59 25 28 58 64 53 79 41 34 7 67 11 39 56 44 24 50 9 49 55 1 80 26 6 73 74 27 69 65 37 18 43 36 17 30 3 47 29 76 78 32 22 12 68 46 5 42 81 57 31 33 83 54 48 14 62 10 16 4 20 71 70 35 15 45 19 60 77 2 23 84 40 82 38\n",
"output": "80\n",
"type": "stdin_stdout"
},
{
"input": "85\n1 18 58 8 22 76 3 61 12 33 54 41 6 24 82 15 10 17 38 64 26 4 62 28 47 14 66 9 84 75 2 71 67 43 37 32 85 21 69 52 55 63 81 51 74 59 65 34 29 36 30 45 27 53 13 79 39 57 5 70 19 40 7 42 68 48 16 80 83 23 46 35 72 31 11 44 73 77 50 56 49 25 60 20 78\n",
"output": "84\n",
"type": "stdin_stdout"
},
{
"input": "86\n64 56 41 10 31 69 47 39 37 36 27 19 9 42 15 6 78 59 52 17 71 45 72 14 2 54 38 79 4 18 16 8 46 75 50 82 44 24 20 55 58 86 61 43 35 32 33 40 63 30 28 60 13 53 12 57 77 81 76 66 73 84 85 62 68 22 51 5 49 7 1 70 80 65 34 48 23 21 83 11 74 26 29 67 25 3\n",
"output": "70\n",
"type": "stdin_stdout"
},
{
"input": "87\n14 20 82 47 39 75 71 45 3 37 63 19 32 68 7 41 48 76 27 46 84 49 4 44 26 69 17 64 1 18 58 33 11 23 21 86 67 52 70 16 77 78 6 74 15 87 10 59 13 34 22 2 65 38 66 61 51 57 35 60 81 40 36 80 31 43 83 56 79 55 29 5 12 8 50 30 53 72 54 9 24 25 42 62 73 28 85\n",
"output": "58\n",
"type": "stdin_stdout"
},
{
"input": "88\n1 83 73 46 61 31 39 86 57 43 16 29 26 80 82 7 36 42 13 20 6 64 19 40 24 12 47 87 8 34 75 9 69 3 11 52 14 25 84 59 27 10 54 51 81 74 65 77 70 17 60 35 23 44 49 2 4 88 5 21 41 32 68 66 15 55 48 58 78 53 22 38 45 33 30 50 85 76 37 79 63 18 28 62 72 56 71 67\n",
"output": "87\n",
"type": "stdin_stdout"
},
{
"input": "89\n68 40 14 58 56 25 8 44 49 55 9 76 66 54 33 81 42 15 59 17 21 30 75 60 4 48 64 6 52 63 61 27 12 57 72 67 23 86 77 80 22 13 43 73 26 78 50 51 18 62 1 29 82 16 74 2 87 24 3 41 11 46 47 69 10 84 65 39 35 79 70 32 34 31 20 19 53 71 36 28 83 88 38 85 7 5 37 45 89\n",
"output": "88\n",
"type": "stdin_stdout"
},
{
"input": "90\n2 67 26 58 9 49 76 22 60 30 77 20 13 7 37 81 47 16 19 12 14 45 41 68 85 54 28 24 46 1 27 43 32 89 53 35 59 75 18 51 17 64 66 80 31 88 87 90 38 72 55 71 42 11 73 69 62 78 23 74 65 79 84 4 86 52 10 6 3 82 56 5 48 33 21 57 40 29 61 63 34 36 83 8 15 44 50 70 39 25\n",
"output": "60\n",
"type": "stdin_stdout"
},
{
"input": "91\n91 69 56 16 73 55 14 82 80 46 57 81 22 71 63 76 43 37 77 75 70 3 26 2 28 17 51 38 30 67 41 47 54 62 34 25 84 11 87 39 32 52 31 36 50 19 21 53 29 24 79 8 74 64 44 7 6 18 10 42 13 9 83 58 4 88 65 60 20 90 66 49 86 89 78 48 5 27 23 59 61 15 72 45 40 33 68 85 35 12 1\n",
"output": "90\n",
"type": "stdin_stdout"
},
{
"input": "92\n67 57 76 78 25 89 6 82 11 16 26 17 59 48 73 10 21 31 27 80 4 5 22 13 92 55 45 85 63 28 75 60 54 88 91 47 29 35 7 87 1 39 43 51 71 84 83 81 46 9 38 56 90 24 37 41 19 86 50 61 79 20 18 14 69 23 62 65 49 52 58 53 36 2 68 64 15 42 30 34 66 32 44 40 8 33 3 77 74 12 70 72\n",
"output": "67\n",
"type": "stdin_stdout"
},
{
"input": "93\n76 35 5 87 7 21 59 71 24 37 2 73 31 74 4 52 28 20 56 27 65 86 16 45 85 67 68 70 47 72 91 88 14 32 62 69 78 41 15 22 57 18 50 13 39 58 17 83 64 51 25 11 38 77 82 90 8 26 29 61 10 43 79 53 48 6 23 55 63 49 81 92 80 44 89 60 66 30 1 9 36 33 19 46 75 93 3 12 42 84 40 54 34\n",
"output": "85\n",
"type": "stdin_stdout"
},
{
"input": "94\n29 85 82 78 61 83 80 63 11 38 50 43 9 24 4 87 79 45 3 17 90 7 34 27 1 76 26 39 84 47 22 41 81 19 44 23 56 92 35 31 72 62 70 53 40 88 13 14 73 2 59 86 46 94 15 12 77 57 89 42 75 48 18 51 32 55 71 30 49 91 20 60 5 93 33 64 21 36 10 28 8 65 66 69 74 58 6 52 25 67 16 37 54 68\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "95\n36 73 18 77 15 71 50 57 79 65 94 88 9 69 52 70 26 66 78 89 55 20 72 83 75 68 32 28 45 74 19 22 54 23 84 90 86 12 42 58 11 81 39 31 85 47 60 44 59 43 21 7 30 41 64 76 93 46 87 48 10 40 3 14 38 49 29 35 2 67 5 34 13 37 27 56 91 17 62 80 8 61 53 95 24 92 6 82 63 33 51 25 4 16 1\n",
"output": "94\n",
"type": "stdin_stdout"
},
{
"input": "96\n64 3 47 83 19 10 72 61 73 95 16 40 54 84 8 86 28 4 37 42 92 48 63 76 67 1 59 66 20 35 93 2 43 7 45 70 34 33 26 91 85 89 13 29 58 68 44 25 87 75 49 71 41 17 55 36 32 31 74 22 52 79 30 88 50 78 38 39 65 27 69 77 81 94 82 53 21 80 57 60 24 46 51 9 18 15 96 62 6 23 11 12 90 5 14 56\n",
"output": "86\n",
"type": "stdin_stdout"
},
{
"input": "97\n40 63 44 64 84 92 38 41 28 91 3 70 76 67 94 96 35 79 29 22 78 88 85 8 21 1 93 54 71 80 37 17 13 26 62 59 75 87 69 33 89 49 77 61 12 39 6 36 58 18 73 50 82 45 74 52 11 34 95 7 23 30 15 32 31 16 55 19 20 83 60 72 10 53 51 14 27 9 68 47 5 2 81 46 57 86 56 43 48 66 24 25 4 42 65 97 90\n",
"output": "95\n",
"type": "stdin_stdout"
},
{
"input": "98\n85 94 69 86 22 52 27 79 53 91 35 55 33 88 8 75 76 95 64 54 67 30 70 49 6 16 2 48 80 32 25 90 98 46 9 96 36 81 10 92 28 11 37 97 15 41 38 40 83 44 29 47 23 3 31 61 87 39 78 20 68 12 17 73 59 18 77 72 43 51 84 24 89 65 26 7 74 93 21 19 5 14 50 42 82 71 60 56 34 62 58 57 45 66 13 63 4 1\n",
"output": "97\n",
"type": "stdin_stdout"
},
{
"input": "99\n33 48 19 41 59 64 16 12 17 13 7 1 9 6 4 92 61 49 60 25 74 65 22 97 30 32 10 62 14 55 80 66 82 78 31 23 87 93 27 98 20 29 88 84 77 34 83 96 79 90 56 89 58 72 52 47 21 76 24 70 44 94 5 39 8 18 57 36 40 68 43 75 3 2 35 99 63 26 67 73 15 11 53 28 42 46 69 50 51 95 38 37 54 85 81 91 45 86 71\n",
"output": "87\n",
"type": "stdin_stdout"
},
{
"input": "100\n28 30 77 4 81 67 31 25 66 56 88 73 83 51 57 34 21 90 38 76 22 99 53 70 91 3 64 54 6 94 8 5 97 80 50 45 61 40 16 95 36 98 9 2 17 44 72 55 18 58 47 12 87 24 7 32 14 23 65 41 63 48 62 39 92 27 43 19 46 13 42 52 96 84 26 69 100 79 93 49 35 60 71 59 68 15 10 29 20 1 78 33 75 86 11 85 74 82 89 37\n",
"output": "89\n",
"type": "stdin_stdout"
},
{
"input": "100\n100 97 35 55 45 3 46 98 77 64 94 85 73 43 49 79 72 9 70 62 80 88 29 58 61 20 89 83 66 86 82 15 6 87 42 96 90 75 63 38 81 40 5 23 4 18 41 19 99 60 8 12 76 51 39 93 53 26 21 50 47 28 13 30 68 59 34 54 24 56 31 27 65 16 32 10 36 52 44 91 22 14 33 25 7 78 67 17 57 37 92 11 2 69 84 95 74 71 48 1\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "100\n83 96 73 70 30 25 7 77 58 89 76 85 49 82 45 51 14 62 50 9 31 32 16 15 97 64 4 37 20 93 24 10 80 71 100 39 75 72 78 74 8 29 53 86 79 48 3 68 90 99 56 87 63 94 36 1 40 65 6 44 43 84 17 52 34 95 38 47 60 57 98 59 33 41 46 81 23 27 19 2 54 91 55 35 26 12 92 18 28 66 69 21 5 67 13 11 22 88 61 42\n",
"output": "65\n",
"type": "stdin_stdout"
},
{
"input": "100\n96 80 47 60 56 9 78 20 37 72 68 15 100 94 51 26 65 38 50 19 4 70 25 63 22 30 13 58 43 69 18 33 5 66 39 73 12 55 95 92 97 1 14 83 10 28 64 31 46 91 32 86 74 54 29 52 89 53 90 44 62 40 16 24 67 81 36 34 7 23 79 87 75 98 84 3 41 77 76 42 71 35 49 61 2 27 59 82 99 85 21 11 45 6 88 48 17 57 8 93\n",
"output": "87\n",
"type": "stdin_stdout"
},
{
"input": "100\n5 6 88 37 97 51 25 81 54 17 57 98 99 44 67 24 30 93 100 36 8 38 84 42 21 4 75 31 85 48 70 77 43 50 65 94 29 32 68 86 56 39 69 47 20 60 52 53 10 34 79 2 95 40 89 64 71 26 22 46 1 62 91 76 83 41 9 78 16 63 13 3 28 92 27 49 7 12 96 72 80 23 14 19 18 66 59 87 90 45 73 82 33 74 35 61 55 15 58 11\n",
"output": "81\n",
"type": "stdin_stdout"
},
{
"input": "100\n100 97 92 12 62 17 19 58 37 26 30 95 31 35 87 10 13 43 98 61 28 89 76 1 23 21 11 22 50 56 91 74 3 24 96 55 64 67 14 4 71 16 18 9 77 68 51 81 32 82 46 88 86 60 29 66 72 85 70 7 53 63 33 45 83 2 25 94 52 93 5 69 20 47 49 54 57 39 34 27 90 80 78 59 40 42 79 6 38 8 48 15 65 73 99 44 41 84 36 75\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "100\n22 47 34 65 69 5 68 78 53 54 41 23 80 51 11 8 2 85 81 75 25 58 29 73 30 49 10 71 17 96 76 89 79 20 12 15 55 7 46 32 19 3 82 35 74 44 38 40 92 14 6 50 97 63 45 93 37 18 62 77 87 36 83 9 90 61 57 28 39 43 52 42 24 56 21 84 26 99 88 59 33 70 4 60 98 95 94 100 13 48 66 72 16 31 64 91 1 86 27 67\n",
"output": "96\n",
"type": "stdin_stdout"
},
{
"input": "100\n41 67 94 18 14 83 59 12 19 54 13 68 75 26 15 65 80 40 23 30 34 78 47 21 63 79 4 70 3 31 86 69 92 10 61 74 97 100 9 99 32 27 91 55 85 52 16 17 28 1 64 29 58 76 98 25 84 7 2 96 20 72 36 46 49 82 93 44 45 6 38 87 57 50 53 35 60 33 8 89 39 42 37 48 62 81 73 43 95 11 66 88 90 22 24 77 71 51 5 56\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "100\n1 88 38 56 62 99 39 80 12 33 57 24 28 84 37 42 10 95 83 58 8 40 20 2 30 78 60 79 36 71 51 31 27 65 22 47 6 19 61 94 75 4 74 35 15 23 92 9 70 13 11 59 90 18 66 81 64 72 16 32 34 67 46 91 21 87 77 97 82 41 7 86 26 43 45 3 93 17 52 96 50 63 48 5 53 44 29 25 98 54 49 14 73 69 89 55 76 85 68 100\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "100\n22 59 25 77 68 79 32 45 20 28 61 60 38 86 33 10 100 15 53 75 78 39 67 13 66 34 96 4 63 23 73 29 31 35 71 55 16 14 72 56 94 97 17 93 47 84 57 8 21 51 54 85 26 76 49 81 2 92 62 44 91 87 11 24 95 69 5 7 99 6 65 48 70 12 41 18 74 27 42 3 80 30 50 98 58 37 82 89 83 36 40 52 19 9 88 46 43 1 90 64\n",
"output": "97\n",
"type": "stdin_stdout"
},
{
"input": "100\n12 1 76 78 97 82 59 80 48 8 91 51 54 74 16 10 89 99 83 63 93 90 55 25 30 33 29 6 9 65 92 79 44 39 15 58 37 46 32 19 27 3 75 49 62 71 98 42 69 50 26 81 96 5 7 61 60 21 20 36 18 34 40 4 47 85 64 38 22 84 2 68 11 56 31 66 17 14 95 43 53 35 23 52 70 13 72 45 41 77 73 87 88 94 28 86 24 67 100 57\n",
"output": "98\n",
"type": "stdin_stdout"
},
{
"input": "100\n66 100 53 88 7 73 54 41 31 42 8 46 65 90 78 14 94 30 79 39 89 5 83 50 38 61 37 86 22 95 60 98 34 57 91 10 75 25 15 43 23 17 96 35 93 48 87 47 56 13 19 9 82 62 67 80 11 55 99 70 18 26 58 85 12 44 16 45 4 49 20 71 92 24 81 2 76 32 6 21 84 36 52 97 59 63 40 51 27 64 68 3 77 72 28 33 29 1 74 69\n",
"output": "98\n",
"type": "stdin_stdout"
},
{
"input": "100\n56 64 1 95 72 39 9 49 87 29 94 7 32 6 30 48 50 25 31 78 90 45 60 44 80 68 17 20 73 15 75 98 83 13 71 22 36 26 96 88 35 3 85 54 16 41 92 99 69 86 93 33 43 62 77 46 47 37 12 10 18 40 27 4 63 55 28 59 23 34 61 53 76 42 51 91 21 70 8 58 38 19 5 66 84 11 52 24 81 82 79 67 97 65 57 74 2 89 100 14\n",
"output": "98\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 3 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 3 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 4 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 3 2 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 3 4 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 4 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 4 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 1 3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 1 4 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 4 1 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 4 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 1 2 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 1 4 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 2 1 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 2 4 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 4 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 4 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 1 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 1 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 2 1 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 2 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 3 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 3 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8\n2 5 6 4 8 3 1 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 3 1 5 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 5 3 6 4 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6\n5 4 2 6 1 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6\n4 2 3 1 6 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6\n5 4 2 1 6 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "9\n7 2 3 4 5 6 1 9 8\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "6\n3 2 1 4 6 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 3 4 1 6 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10\n5 2 3 4 1 6 7 8 10 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "6\n5 2 3 1 6 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10\n2 9 3 4 1 10 5 6 7 8\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10\n2 3 4 5 6 7 1 8 10 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "8\n2 3 4 5 1 6 8 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 1 3 4 5 6\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/676/A"
} | vfc_9838 |
apps | verifiable_code | 22 | Solve the following coding problem using the programming language python:
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
[Image] English alphabet
You are given a string s. Check if the string is "s-palindrome".
-----Input-----
The only line contains the string s (1 ≤ |s| ≤ 1000) which consists of only English letters.
-----Output-----
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
-----Examples-----
Input
oXoxoXo
Output
TAK
Input
bod
Output
TAK
Input
ER
Output
NIE
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys, math
s=input()
pal='AHIMOoTUVvWwXxY'
n=len(s)
l=0
r=n-1
flag=True
fir='pq'
sec='bd'
while l<=r:
if s[l]==s[r] and s[l] in pal:
l+=1
r-=1
continue
elif s[l]==s[r]:
flag=False
break
elif (s[l] in fir) and (s[r] in fir):
l+=1
r-=1
continue
elif (s[l] in sec) and (s[r] in sec):
l+=1
r-=1
continue
else:
flag=False
break
if flag:
print('TAK')
else:
print('NIE')
``` | {
"language": "python",
"test_cases": [
{
"input": "oXoxoXo\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "bod\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "ER\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "o\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "a\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "opo\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "HCMoxkgbNb\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "vMhhXCMWDe\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "iIcamjTRFH\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "WvoWvvWovW\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "WXxAdbAxXW\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "vqMTUUTMpv\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "iii\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "AAWW\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ss\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "i\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ii\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "LJ\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "m\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ioi\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "OA\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "aaaiaaa\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "SS\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "iiii\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ssops\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ssss\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ll\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "s\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "bb\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "uu\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ZoZ\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mom\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "uou\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "u\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "JL\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mOm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "llll\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ouo\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "aa\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "olo\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "S\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "lAl\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "nnnn\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ZzZ\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "bNd\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ZZ\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "oNoNo\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "l\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "zz\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "NON\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "nn\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "NoN\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "sos\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "lol\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mmm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "YAiAY\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ipIqi\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "AAA\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "uoOou\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "SOS\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "NN\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "n\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "h\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "blld\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ipOqi\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "pop\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "BB\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "OuO\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "lxl\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "Z\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "vvivv\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "nnnnnnnnnnnnn\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "AA\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "t\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "z\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mmmAmmm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "qlililp\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mpOqm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "iiiiiiiiii\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "BAAAB\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "UA\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mmmmmmm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "NpOqN\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "uOu\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "uuu\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "NAMAN\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "lllll\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "T\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "mmmmmmmmmmmmmmmm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "AiiA\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "iOi\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "lll\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "N\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "viv\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "oiio\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "AiiiA\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "NNNN\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ixi\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "AuuA\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "AAAANANAAAA\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mmmmm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "oYo\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "dd\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "A\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "ioh\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mmmm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "uuuu\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "puq\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "rrrrrr\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "c\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "AbpA\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "qAq\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "tt\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mnmnm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "sss\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "yy\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "bob\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "NAN\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mAm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "tAt\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "yAy\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "zAz\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "aZ\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "hh\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "bbbb\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "ZAZ\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "Y\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "AAMM\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "lml\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "AZA\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mXm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "bd\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "H\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "uvu\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "dxxd\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "dp\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "vV\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "vMo\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "O\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "vYv\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "fv\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "U\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "iAi\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "I\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "VxrV\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "POP\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "bid\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "bmd\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "AiA\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "mmmmmm\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "XHX\n",
"output": "TAK\n",
"type": "stdin_stdout"
},
{
"input": "llllll\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "aAa\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "Db\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "lOl\n",
"output": "NIE\n",
"type": "stdin_stdout"
},
{
"input": "bzd\n",
"output": "NIE\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/691/B"
} | vfc_9842 |
apps | verifiable_code | 23 | Solve the following coding problem using the programming language python:
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
-----Input-----
The first line contains integer a (1 ≤ a ≤ 10^18). The second line contains integer b (1 ≤ b ≤ 10^18). Numbers don't have leading zeroes. It is guaranteed that answer exists.
-----Output-----
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
-----Examples-----
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a = list(input())
b = int(input())
a.sort()
a = a[::-1]
prefix = ""
while(len(a) > 0):
for i in range(len(a)):
num = prefix + a[i] + "".join(sorted(a[:i] + a[i + 1:]))
if (int(num) <= b):
prefix += a[i]
a = a[:i] + a[i+1:]
break
print(prefix)
``` | {
"language": "python",
"test_cases": [
{
"input": "123\n222\n",
"output": "213\n",
"type": "stdin_stdout"
},
{
"input": "3921\n10000\n",
"output": "9321\n",
"type": "stdin_stdout"
},
{
"input": "4940\n5000\n",
"output": "4940\n",
"type": "stdin_stdout"
},
{
"input": "23923472834\n23589234723\n",
"output": "23498743322\n",
"type": "stdin_stdout"
},
{
"input": "102391019\n491010301\n",
"output": "399211100\n",
"type": "stdin_stdout"
},
{
"input": "123456789123456789\n276193619183618162\n",
"output": "276193618987554432\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000\n1000000000000000000\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "1\n1000000000000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999\n1000000000000000000\n",
"output": "999999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "2475345634895\n3455834583479\n",
"output": "3455834579642\n",
"type": "stdin_stdout"
},
{
"input": "15778899\n98715689\n",
"output": "98598771\n",
"type": "stdin_stdout"
},
{
"input": "4555\n5454\n",
"output": "4555\n",
"type": "stdin_stdout"
},
{
"input": "122112\n221112\n",
"output": "221112\n",
"type": "stdin_stdout"
},
{
"input": "199999999999991\n191000000000000\n",
"output": "119999999999999\n",
"type": "stdin_stdout"
},
{
"input": "13\n31\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"input": "212\n211\n",
"output": "122\n",
"type": "stdin_stdout"
},
{
"input": "222234\n322223\n",
"output": "243222\n",
"type": "stdin_stdout"
},
{
"input": "123456789\n987654311\n",
"output": "987654231\n",
"type": "stdin_stdout"
},
{
"input": "20123\n21022\n",
"output": "20321\n",
"type": "stdin_stdout"
},
{
"input": "10101\n11000\n",
"output": "10110\n",
"type": "stdin_stdout"
},
{
"input": "592\n924\n",
"output": "592\n",
"type": "stdin_stdout"
},
{
"input": "5654456\n5634565\n",
"output": "5566544\n",
"type": "stdin_stdout"
},
{
"input": "655432\n421631\n",
"output": "365542\n",
"type": "stdin_stdout"
},
{
"input": "200\n200\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "123456789987654321\n121111111111111111\n",
"output": "119988776655443322\n",
"type": "stdin_stdout"
},
{
"input": "12345\n21344\n",
"output": "15432\n",
"type": "stdin_stdout"
},
{
"input": "120\n200\n",
"output": "120\n",
"type": "stdin_stdout"
},
{
"input": "123\n212\n",
"output": "132\n",
"type": "stdin_stdout"
},
{
"input": "2184645\n5213118\n",
"output": "5186442\n",
"type": "stdin_stdout"
},
{
"input": "9912346\n9912345\n",
"output": "9694321\n",
"type": "stdin_stdout"
},
{
"input": "5003\n5000\n",
"output": "3500\n",
"type": "stdin_stdout"
},
{
"input": "12345\n31234\n",
"output": "25431\n",
"type": "stdin_stdout"
},
{
"input": "5001\n5000\n",
"output": "1500\n",
"type": "stdin_stdout"
},
{
"input": "53436\n53425\n",
"output": "53364\n",
"type": "stdin_stdout"
},
{
"input": "9329\n3268\n",
"output": "2993\n",
"type": "stdin_stdout"
},
{
"input": "1234567890\n9000000001\n",
"output": "8976543210\n",
"type": "stdin_stdout"
},
{
"input": "321\n212\n",
"output": "132\n",
"type": "stdin_stdout"
},
{
"input": "109823464\n901234467\n",
"output": "896443210\n",
"type": "stdin_stdout"
},
{
"input": "6543\n6542\n",
"output": "6534\n",
"type": "stdin_stdout"
},
{
"input": "555441\n555100\n",
"output": "554541\n",
"type": "stdin_stdout"
},
{
"input": "472389479\n327489423\n",
"output": "327487994\n",
"type": "stdin_stdout"
},
{
"input": "45645643756464352\n53465475637456247\n",
"output": "53465475636654442\n",
"type": "stdin_stdout"
},
{
"input": "254\n599\n",
"output": "542\n",
"type": "stdin_stdout"
},
{
"input": "5232222345652321\n5000000000000000\n",
"output": "4655533322222221\n",
"type": "stdin_stdout"
},
{
"input": "201\n200\n",
"output": "120\n",
"type": "stdin_stdout"
},
{
"input": "14362799391220361\n45160821596433661\n",
"output": "43999766332221110\n",
"type": "stdin_stdout"
},
{
"input": "3453\n5304\n",
"output": "4533\n",
"type": "stdin_stdout"
},
{
"input": "989\n998\n",
"output": "998\n",
"type": "stdin_stdout"
},
{
"input": "5200000000234\n5200000000311\n",
"output": "5200000000243\n",
"type": "stdin_stdout"
},
{
"input": "5555132\n1325442\n",
"output": "1255553\n",
"type": "stdin_stdout"
},
{
"input": "123\n211\n",
"output": "132\n",
"type": "stdin_stdout"
},
{
"input": "65689\n66123\n",
"output": "65986\n",
"type": "stdin_stdout"
},
{
"input": "123451234567890\n123456789012345\n",
"output": "123456789012345\n",
"type": "stdin_stdout"
},
{
"input": "22115\n22015\n",
"output": "21521\n",
"type": "stdin_stdout"
},
{
"input": "123\n311\n",
"output": "231\n",
"type": "stdin_stdout"
},
{
"input": "12222\n21111\n",
"output": "12222\n",
"type": "stdin_stdout"
},
{
"input": "765\n567\n",
"output": "567\n",
"type": "stdin_stdout"
},
{
"input": "9087645\n9087640\n",
"output": "9087564\n",
"type": "stdin_stdout"
},
{
"input": "1111111122222333\n2220000000000000\n",
"output": "2213332221111111\n",
"type": "stdin_stdout"
},
{
"input": "7901\n7108\n",
"output": "7091\n",
"type": "stdin_stdout"
},
{
"input": "215489\n215488\n",
"output": "214985\n",
"type": "stdin_stdout"
},
{
"input": "102\n200\n",
"output": "120\n",
"type": "stdin_stdout"
},
{
"input": "19260817\n20011213\n",
"output": "19876210\n",
"type": "stdin_stdout"
},
{
"input": "12345\n53200\n",
"output": "53142\n",
"type": "stdin_stdout"
},
{
"input": "1040003001\n1040003000\n",
"output": "1040001300\n",
"type": "stdin_stdout"
},
{
"input": "295\n924\n",
"output": "592\n",
"type": "stdin_stdout"
},
{
"input": "20000000000000001\n20000000000000000\n",
"output": "12000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "99988877\n99887766\n",
"output": "99879887\n",
"type": "stdin_stdout"
},
{
"input": "12\n12\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "199999999999999999\n900000000000000000\n",
"output": "199999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "1234\n4310\n",
"output": "4231\n",
"type": "stdin_stdout"
},
{
"input": "100011\n100100\n",
"output": "100011\n",
"type": "stdin_stdout"
},
{
"input": "328899\n328811\n",
"output": "299883\n",
"type": "stdin_stdout"
},
{
"input": "646722972346\n397619201220\n",
"output": "397476664222\n",
"type": "stdin_stdout"
},
{
"input": "1203\n1200\n",
"output": "1032\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1112\n2110\n",
"output": "1211\n",
"type": "stdin_stdout"
},
{
"input": "4545\n5540\n",
"output": "5454\n",
"type": "stdin_stdout"
},
{
"input": "3053\n5004\n",
"output": "3530\n",
"type": "stdin_stdout"
},
{
"input": "3503\n5004\n",
"output": "3530\n",
"type": "stdin_stdout"
},
{
"input": "351731653766064847\n501550303749042658\n",
"output": "501548777666643331\n",
"type": "stdin_stdout"
},
{
"input": "10123456789013451\n26666666666666666\n",
"output": "26598754433111100\n",
"type": "stdin_stdout"
},
{
"input": "1110111\n1100000\n",
"output": "1011111\n",
"type": "stdin_stdout"
},
{
"input": "30478\n32265\n",
"output": "30874\n",
"type": "stdin_stdout"
},
{
"input": "456546546549874615\n441554543131214545\n",
"output": "441554498766665554\n",
"type": "stdin_stdout"
},
{
"input": "214\n213\n",
"output": "142\n",
"type": "stdin_stdout"
},
{
"input": "415335582799619283\n133117803602859310\n",
"output": "132999887655543321\n",
"type": "stdin_stdout"
},
{
"input": "787\n887\n",
"output": "877\n",
"type": "stdin_stdout"
},
{
"input": "3333222288889999\n3333222288881111\n",
"output": "3332999988883222\n",
"type": "stdin_stdout"
},
{
"input": "495779862481416791\n836241745208800994\n",
"output": "829998777665444111\n",
"type": "stdin_stdout"
},
{
"input": "139\n193\n",
"output": "193\n",
"type": "stdin_stdout"
},
{
"input": "9568\n6500\n",
"output": "5986\n",
"type": "stdin_stdout"
},
{
"input": "3208899\n3228811\n",
"output": "3209988\n",
"type": "stdin_stdout"
},
{
"input": "27778\n28710\n",
"output": "27877\n",
"type": "stdin_stdout"
},
{
"input": "62345\n46415\n",
"output": "46352\n",
"type": "stdin_stdout"
},
{
"input": "405739873179209\n596793907108871\n",
"output": "594998777332100\n",
"type": "stdin_stdout"
},
{
"input": "365\n690\n",
"output": "653\n",
"type": "stdin_stdout"
},
{
"input": "8388731334391\n4710766672578\n",
"output": "4398887333311\n",
"type": "stdin_stdout"
},
{
"input": "1230\n1200\n",
"output": "1032\n",
"type": "stdin_stdout"
},
{
"input": "1025\n5000\n",
"output": "2510\n",
"type": "stdin_stdout"
},
{
"input": "4207799\n4027711\n",
"output": "2997740\n",
"type": "stdin_stdout"
},
{
"input": "4444222277779999\n4444222277771111\n",
"output": "4442999977774222\n",
"type": "stdin_stdout"
},
{
"input": "7430\n3047\n",
"output": "3047\n",
"type": "stdin_stdout"
},
{
"input": "649675735\n540577056\n",
"output": "539776654\n",
"type": "stdin_stdout"
},
{
"input": "26\n82\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "241285\n207420\n",
"output": "185422\n",
"type": "stdin_stdout"
},
{
"input": "3\n3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "12\n21\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "481287\n826607\n",
"output": "824871\n",
"type": "stdin_stdout"
},
{
"input": "40572351\n59676984\n",
"output": "57543210\n",
"type": "stdin_stdout"
},
{
"input": "268135787269\n561193454469\n",
"output": "539887766221\n",
"type": "stdin_stdout"
},
{
"input": "4\n9\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5\n6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "60579839\n33370073\n",
"output": "30998765\n",
"type": "stdin_stdout"
},
{
"input": "49939\n39200\n",
"output": "34999\n",
"type": "stdin_stdout"
},
{
"input": "2224\n4220\n",
"output": "2422\n",
"type": "stdin_stdout"
},
{
"input": "427799\n427711\n",
"output": "299774\n",
"type": "stdin_stdout"
},
{
"input": "49\n90\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "93875\n82210\n",
"output": "79853\n",
"type": "stdin_stdout"
},
{
"input": "78831\n7319682\n",
"output": "88731\n",
"type": "stdin_stdout"
},
{
"input": "937177\n7143444\n",
"output": "977731\n",
"type": "stdin_stdout"
},
{
"input": "499380628\n391990337\n",
"output": "390988642\n",
"type": "stdin_stdout"
},
{
"input": "2090909\n2900000\n",
"output": "2099900\n",
"type": "stdin_stdout"
},
{
"input": "112233445566778890\n987654321987654320\n",
"output": "987654321876543210\n",
"type": "stdin_stdout"
},
{
"input": "48257086\n80903384\n",
"output": "80876542\n",
"type": "stdin_stdout"
},
{
"input": "112233445566778890\n900654321987654320\n",
"output": "898776655443322110\n",
"type": "stdin_stdout"
},
{
"input": "112233445566778890\n123456789123456788\n",
"output": "123456789123456780\n",
"type": "stdin_stdout"
},
{
"input": "5207799\n5027711\n",
"output": "2997750\n",
"type": "stdin_stdout"
},
{
"input": "200000000000000001\n200000000000000000\n",
"output": "120000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "597402457\n797455420\n",
"output": "797455420\n",
"type": "stdin_stdout"
},
{
"input": "90\n94\n",
"output": "90\n",
"type": "stdin_stdout"
},
{
"input": "86888\n88683\n",
"output": "86888\n",
"type": "stdin_stdout"
},
{
"input": "419155888\n588151913\n",
"output": "588151894\n",
"type": "stdin_stdout"
},
{
"input": "408919130\n191830070\n",
"output": "191830049\n",
"type": "stdin_stdout"
},
{
"input": "524975\n554924\n",
"output": "554792\n",
"type": "stdin_stdout"
},
{
"input": "53029\n30524\n",
"output": "30295\n",
"type": "stdin_stdout"
},
{
"input": "5549\n5542\n",
"output": "5495\n",
"type": "stdin_stdout"
},
{
"input": "6\n9\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "87\n810\n",
"output": "87\n",
"type": "stdin_stdout"
},
{
"input": "920491855\n281495062\n",
"output": "281495059\n",
"type": "stdin_stdout"
},
{
"input": "6691\n6910\n",
"output": "6691\n",
"type": "stdin_stdout"
},
{
"input": "533\n335\n",
"output": "335\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999998\n999999999999999997\n",
"output": "999999999999999989\n",
"type": "stdin_stdout"
},
{
"input": "21111111111111111\n21111111111111110\n",
"output": "12111111111111111\n",
"type": "stdin_stdout"
},
{
"input": "2\n12\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "76544\n45744\n",
"output": "45674\n",
"type": "stdin_stdout"
},
{
"input": "2000000000000001\n2000000000000000\n",
"output": "1200000000000000\n",
"type": "stdin_stdout"
},
{
"input": "740867\n467701\n",
"output": "467087\n",
"type": "stdin_stdout"
},
{
"input": "2\n6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "103\n130\n",
"output": "130\n",
"type": "stdin_stdout"
},
{
"input": "2423712\n8466235\n",
"output": "7432221\n",
"type": "stdin_stdout"
},
{
"input": "84\n48\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"input": "1210\n12113\n",
"output": "2110\n",
"type": "stdin_stdout"
},
{
"input": "2430\n20786\n",
"output": "4320\n",
"type": "stdin_stdout"
},
{
"input": "100\n999\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "19325\n21903\n",
"output": "21593\n",
"type": "stdin_stdout"
},
{
"input": "1969\n23251\n",
"output": "9961\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/915/C"
} | vfc_9846 |
apps | verifiable_code | 24 | Solve the following coding problem using the programming language python:
Alice and Bob play 5-in-a-row game. They have a playing field of size 10 × 10. In turns they put either crosses or noughts, one at a time. Alice puts crosses and Bob puts noughts.
In current match they have made some turns and now it's Alice's turn. She wonders if she can put cross in such empty cell that she wins immediately.
Alice wins if some crosses in the field form line of length not smaller than 5. This line can be horizontal, vertical and diagonal.
-----Input-----
You are given matrix 10 × 10 (10 lines of 10 characters each) with capital Latin letters 'X' being a cross, letters 'O' being a nought and '.' being an empty cell. The number of 'X' cells is equal to the number of 'O' cells and there is at least one of each type. There is at least one empty cell.
It is guaranteed that in the current arrangement nobody has still won.
-----Output-----
Print 'YES' if it's possible for Alice to win in one turn by putting cross in some empty cell. Otherwise print 'NO'.
-----Examples-----
Input
XX.XX.....
.....OOOO.
..........
..........
..........
..........
..........
..........
..........
..........
Output
YES
Input
XXOXX.....
OO.O......
..........
..........
..........
..........
..........
..........
..........
..........
Output
NO
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = [ [ c for c in input() ] for i in range(10) ]
def win():
for i in range(10):
for j in range(10):
ok = True
for k in range(5):
if j+k>9: ok = False
elif s[i][j+k] != 'X': ok = False
if ok: return True
ok = True
for k in range(5):
if i+k>9: ok = False
elif s[i+k][j] != 'X': ok = False
if ok: return True
ok = True
for k in range(5):
if j+k>9 or i+k>9: ok = False
elif s[i+k][j+k] != 'X': ok = False
if ok: return True
ok = True
for k in range(5):
if i-k<0 or j+k>9: ok = False
elif s[i-k][j+k] != 'X': ok = False
if ok: return True
return False
for i in range(10):
for j in range(10):
if s[i][j]=='.':
s[i][j] = 'X'
if win():
print('YES')
return
s[i][j] = '.'
print('NO')
``` | {
"language": "python",
"test_cases": [
{
"input": "XX.XX.....\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XXOXX.....\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XO........\n.XO.......\n..XO......\n....O.....\n....X.....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..X....XX.\n..........\n..........\nX..O..OO..\n....O.....\nX..O.....O\nO....OX..X\n..X....X.X\nO........O\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "O.......O.\n.....O.X..\n......O...\n....X.O...\n.O.O.....X\n.XO.....XX\n...X...X.O\n........O.\n........O.\n.X.X.....X\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "....OX....\n..........\n.O..X...X.\nXXO..XO..O\nO.......X.\n...XX.....\n..O.O...OX\n.........X\n.....X..OO\n........O.\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..O..X.X..\n.O..X...O.\n........O.\n...O..O...\nX.XX....X.\n..O....O.X\n..X.X....O\n......X..X\nO.........\n..X.O...OO\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..X.......\n..O.......\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n.........X\n..........\n..........\n..........\n..O.......\n..........\n..O...X...\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\n..........\n..........\nX.........\n.........X\n..........\n..O.......\n.O...X...O\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "......X...\n..........\n..X....X..\n....O.....\n..........\nO.........\n.....O...X\n..........\n..........\nO.........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..XOO.OOXO\nXOX.X...O.\n...X.....X\nO.O.......\n.O.X..OO..\n.XXO.....X\n..OXX.X..X\nOO..X..XO.\nX..O.....X\n.O...XO...\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".OXXOOOXXO\nXOX.O.X.O.\nXX.X...OXX\nOOOX......\nX.OX.X.O..\nX.O...O.O.\n.OXOXOO...\nOO.XOOX...\nO..XX...XX\nXX.OXXOOXO\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".OX.XX.OOO\n..OXXOXOO.\nX..XXXOO.X\nXOX.O.OXOX\nO.O.X.XX.O\nOXXXOXXOXX\nO.OOO...XO\nO.X....OXX\nXO...XXO.O\nXOX.OOO.OX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....X.....\n...X.OOOO.\n..X.......\n.X........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n..........\n.....X....\n....X.....\n..........\n..X.......\n.X........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....X.....\n...X......\n..........\n.X........\nX.........\n..........\n..........\n..........\n..........\n......OOOO\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\n.OOO.OOO..\n.XXX.XXX..\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\n..........\n..........\n....X.....\n...X.....O\n.........O\n.X.......O\nX........O\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n........X.\n.......X..\n..........\n.....X....\n....OOOO..\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n..........\n..........\n..........\n..........\n.....X....\n....X.....\n...X......\n..X.......\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "OOOO......\n..........\n..........\n..........\n..........\n..........\n......X...\n.......X..\n........X.\n.........X\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....X.....\n...X......\n..........\n.X........\nX.........\n...OOOO...\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\n..........\n..........\n..........\n......X...\nOOOO...X..\n........X.\n.........X\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.........X\n........X.\n.......X..\n......X...\n..........\n..........\n..........\n..........\n......OOOO\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....X.....\n...X.OOOO.\n..X..OOOO.\n.X........\n..........\n..........\nX.........\nX.........\nX.........\nX.........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n......OOO.\n..........\n..........\n..........\n.....O....\n......X...\n.......X..\n........X.\n.........X\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n....X.....\n...X......\n..X.....O.\n.X......O.\n........O.\n........O.\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\nX.........\n.O........\n..XXX.....\n..XOXO....\nOXOOOO....\nX.........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n........X.\n.......X..\n..........\n.....X....\n........O.\n......O...\n...O....O.\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n........X.\n.......X..\n......X...\n..........\n..........\n..........\n..........\n..........\n......OOOO\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".....OOOO.\n..........\n..........\n..........\n..........\n..........\n........X.\n.......X..\n......X...\n.....X....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\n..........\n..........\nX.........\nX.........\nX.........\nXOOOO.....\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "OOOO.....X\n........X.\n..........\n......X...\n.....X....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\nOOOOX.....\n..........\n..X.......\n.X........\nX.........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n.....OOOO.\nX.........\n.X........\n..X.......\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\n..........\n..........\n..O......X\n..O.....X.\n..O.......\n..O...X...\n.....X....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n........X.\n.......X..\n......X...\n..........\n..........\n..........\n..........\n..........\nOOOO......\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "OOOO.....X\n........X.\n.......X..\n......X...\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\n.....X....\n....X.....\n...X......\n.........O\n.X.......O\n.........O\n.........O\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "OOO.......\n...O....X.\n.......X..\n..........\n.....X....\n....X.....\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n........X.\n.......X..\n......X...\nOOOO......\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".X........\n..........\n...X......\n....X.....\n.....X....\n..........\n..........\n..........\n..........\n......OOOO\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n..........\n..........\n..........\n..........\n.........X\n........X.\n.......X..\n......X...\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..O.......\nOO.O......\n......X...\n..........\n....X.....\n...X......\n..X.......\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....X.....\n...X......\n..X.......\n..........\nX.........\n..........\n..OOOO....\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XXOXXOOO..\n..........\n..........\n..........\n..O..X....\n..O.X.....\n..OXO.....\n..X.......\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n..........\n..........\n...X......\n..X.......\n.X........\nX.........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n.........X\n.........X\n.........X\n..........\n.........O\n.........O\n.........O\n.........O\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "O.........\nOO........\nOOO.......\nOOO.......\n..........\n......O.OO\n.....OXXXX\n.....OXXXX\n.....OXXXX\n.....OXXXX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..O.......\nOO.O......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\nXXX.X.....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".XX.....X.\n.X...O.X..\n.O........\n.....X....\n.X..XO.O..\n.X........\n.X.......O\n.........O\n..O.......\n..O....O.O\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "......OOOO\n..........\n..........\n..........\n..........\n.........X\n........X.\n.......X..\n......X...\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n........X.\n.......X..\n..........\n.....X....\n..........\n..........\n..........\n..........\n......OOOO\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..X.......\n...X......\n....X.....\n.....X....\n......O...\n..........\n..OOO.....\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n..........\n..........\n..........\n..........\n.........X\n.........X\n.........X\n.........X\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".....OOOOX\n.XXX......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "....X.....\n...X......\n..X.......\n.X........\n..........\n..........\nOOOO......\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".OOOO....X\n........X.\n..........\n......X...\n.....X....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n..........\n..........\n....X.....\n...X......\n..X.......\n..........\nX.........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "X..XX.....\n.....OOOO.\n..........\nO.........\n..........\nO........X\n........X.\nO......X..\n......X...\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....X....O\n...X.....O\n..X......O\n.X.......O\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n..........\n..........\n..........\n..........\n......X...\n.......X..\n........X.\n.........X\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XXOXX.....\n.....OOOO.\n..........\n.....X....\n....X.....\n..........\n..X...O...\n.X......O.\nX..O..O...\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "O.....X...\n.....X....\n..........\n...X..OOO.\n..X.......\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "OOOO......\n..........\n..........\n..........\n..........\n.........X\n........X.\n..........\n......X...\n.....X....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".XX.....X.\n.X...O.X.X\n.O........\n.....X....\n.X..XO.O..\n.X........\n.X.......O\nO........O\n..O.......\n..O....O.O\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n........X.\n.......X..\n..........\n.....X....\n..........\n..........\n..........\n..........\nOOOO......\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n...X......\n..X.......\n.X......O.\nX.......OO\n.........O\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n........X.\n.......X..\n......X...\n..........\n..........\n....OOOO..\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\n..........\n..........\n..O......X\n..O......X\n..O.......\n..O......X\n.........X\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "......XXXX\nOOOO......\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..O.......\n...O......\n....O.....\n.....O....\n......X...\n.......X..\n........X.\n.........X\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "OOOOX.....\n..........\n..X.......\n.X........\nX.........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "X.X.X.X...\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n........XO\n.......XO.\n......XO..\n..........\n....XO....\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n......XXXX\n..........\n..........\n..........\n..........\n..OOOO....\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n..........\n..........\n.......X..\n......X...\n.....X....\n....X.....\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "......OOOO\n..........\n..........\n..........\n..........\n..........\n...X......\n..X.......\n.X........\nX.........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\n..........\n..........\nOOOO......\n.........X\n........X.\n.......X..\n......X...\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n......X...\n.......X..\n........X.\n.........X\n..........\n..........\n..........\n.OOOO.....\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n...X...OO.\n..X....OO.\n.X........\nX.........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....X.....\n...X......\n..X.......\n.X........\n......OOOO\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n..........\n..........\n..........\n....X.....\n...X......\n..........\n.X........\nX.........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\n..........\n.XXXXO....\n....OOO...\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "O.O.O.O.O.\n..........\n..........\n..........\n..........\n..........\n.XX.......\nX.........\nX.........\nX.........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".O........\n..X...X...\n...O.X....\n....X.....\n...X.X....\n..O...X...\n..XX...O..\n..OOO.OO..\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "OOO...O...\n.X...X.O..\n...O.XXX.O\n.O..XOX.X.\n..O.XXX.O.\n..X.OO.O..\n.OOXXOXXO.\n.OOX.OX.X.\n.XXX....XX\n.OO...OXO.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.........O\n.........O\n.........O\n.........O\n..........\n.........X\n.........X\n.........X\n.........X\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..XOO.OOXO\nXOX.X...O.\n...X.....X\nO.O.......\n.O.X..OO..\n.XXO.....X\n..OXX.X..X\nOO..X..XO.\nX..O..X..X\nOO...XO...\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".....OXXXX\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n......OOO.\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n........X.\n.......X..\n....OO.OO.\n.....X....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "O.........\n.O........\n..........\n...O......\n....O.....\n.........X\n........X.\n..........\n......X...\n.....X....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n........X.\n.......X..\n......X...\n..........\nOOOO......\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\nX.O.......\nX..O......\nX...O.....\nX....O....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..O......X\n...O.....X\n....O....X\n.....O...X\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n..O......X\n...O.....X\n....O....X\n.........O\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n.......OO.\n..........\n..........\n..........\n..........\n.......X..\n........X.\n......XXXX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\n..O.......\n..O..O....\n...O..X...\n.......X..\n........X.\n.........X\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n...X...O..\n..X...O...\n.X...O....\nX...O.....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n..........\n...OOOO...\n..........\n..........\n.....X....\n.....X....\n.....X....\n.....X....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..O.......\n...O......\n....O.....\n.....O....\n..........\nX.........\nX.........\nX.........\nX.........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XXOXX.....\nOOXOO.....\n....XX....\n....OO....\n...XOOX...\n..XO..OX..\nOX......XO\nXO..XX..OX\n....OO....\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n.........X\n...O....X.\n....O..X..\n.....O....\n.....X....\n....XOOO..\n...X......\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XXXXO.....\n..O.......\n...O......\n....O.....\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.......X..\n.......X..\n.......X..\n.......X..\n.......O..\n..........\n..........\n..........\nOOO.......\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....X....\n....X.....\n...X......\n..X.......\n..........\n...OOOO...\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "X.........\n.OO.......\n..XO......\n...XO.....\n....X.....\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "X.XX..XXXX\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\nOOO.O.O.OO\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "O.........\nX.O.......\nX..O......\nX...O.....\nX.........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".....OXXXX\n..........\n..........\n..........\n..........\n.....O....\nOOO...X...\nOOOO...X..\n........X.\n....X....X\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "X.........\nX.O.......\nX..O......\nX...O.....\nO.........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "....X.....\n...X...O..\n..X...O...\n.....O....\nX...O.....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\n.........X\n...O....X.\n....O..X..\n.....O....\n.....X....\n....XOO...\n...X....O.\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "......XXXX\n..O.......\n...O......\n....O.....\n.....O....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..O...X...\n...O...X..\n....O...X.\n.....O...X\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n......XXXX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..O.......\n...O......\n....O.....\n..........\nO.........\nX.........\nX.........\nX.........\nX.........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "X.........\nO.O.......\nX..O......\nX...O.....\nX.........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "X.........\nX.O.......\nX..O......\nX...O.....\n.....O....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "X.........\n..O.......\nX..O......\nX...O.....\nX....O....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XXOXX.....\nOOXOO.....\n....XX....\n....OO....\n...XOOX...\n..XO.XOXO.\nOX...XO.XO\nXO..OX..OX\n.....O....\n.....X....\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "....O.....\n...X...O..\n..X...O...\n.X...O....\nX.........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n...X.X.X.X\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".....O....\n....X..O.O\n...X.....O\n..X.......\n.X.......O\n..........\n..........\n..........\n..........\n.........X\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".....OXXXX\n..O.......\n...O......\n....O.....\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XXX.XXX...\nOOO.OOO...\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....X.....\n...X......\n..X.......\n..........\nX.........\nOOOO......\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".....O....\n..O...X...\n...O...X..\n....O...X.\n.........X\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XXXXOOOO..\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.....OOOO.\n..........\n..........\n..........\n.........X\n........X.\n.......X..\n......X...\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..O.......\n...O......\n....O.....\n.....O....\n..........\n.X........\n..X.......\n...X......\n....X.....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....X.....\n.......O..\n..X...O...\n.X...O....\nX...O.....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XXOXX.....\nOOXOO.....\n.....X....\n.....O....\n...XOOX...\n..XO.XOXO.\nOX...XO.XO\nXO..OX..OX\n.....O....\n.....X....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....X.....\n...X......\n..X.......\n.X........\n..........\n..........\n..........\n..........\n..........\n......OOOO\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "O.........\n.XO.......\n..XO......\n...XO.....\n....X.....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XOXXX.....\n..O.......\n...O......\n....O.....\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n..O......X\n...O.....X\n....O....X\n.....O....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.......OX.\n......OX..\n.....OX...\n....OX....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "X.........\nX.O.......\nO..O......\nX...O.....\nX.........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..O.......\n...O......\n....O.....\n.....O....\nX.........\n..........\nX.........\nX.........\nX.........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n..O.......\n...O.....X\n....O....X\n.....O...X\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.......O..\n......O...\n.....O....\n..........\n.........O\n........X.\n.......X..\n......X...\n.....X....\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n....OOOO..\n.........X\n.........X\n.........X\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".......XXX\nX.........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n......OOOO\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..O.......\n...O......\n....O.....\n..........\nO.........\n.X........\n..X.......\n...X......\n....X.....\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XXXX......\n..O.......\n...O......\n....O.....\n.....O....\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n.......O..\n......O...\n.....O....\n....O.....\n..........\n........X.\n.......X..\n......X...\n.....X....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "OOO.O.....\n..........\n..........\n..........\n..........\n.......X..\n..........\n.....X....\n....X.....\n...X......\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XX..X.....\n.....OOOOX\n........X.\n.......X..\n......X...\n..........\n..........\n....O.....\n..........\n..O.O.....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..........\n..........\nOXXXXOOOO.\n.........X\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "X.........\nX....OOOO.\n..........\nX.........\nX.........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n......X.X.\n.....OX.O.\n......X...\n.....X....\n....O.....\n...O......\n..O.......\n.O........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".OOOOXXXX.\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XX.XX.....\n..........\n..........\n....O.....\n..........\n......O...\n..........\n......O...\n........O.\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".........X\n........X.\n.......X..\n..........\n.....X....\n.....O....\n......O...\n.......O..\n........O.\n..........\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/825/B"
} | vfc_9850 |
apps | verifiable_code | 26 | Solve the following coding problem using the programming language python:
Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point.
Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to earn a lot of cheese. He will hand the three numbers x, y and z to Rat Kwesh, and Rat Kwesh will pick one of the these twelve options: a_1 = x^{y}^{z}; a_2 = x^{z}^{y}; a_3 = (x^{y})^{z}; a_4 = (x^{z})^{y}; a_5 = y^{x}^{z}; a_6 = y^{z}^{x}; a_7 = (y^{x})^{z}; a_8 = (y^{z})^{x}; a_9 = z^{x}^{y}; a_10 = z^{y}^{x}; a_11 = (z^{x})^{y}; a_12 = (z^{y})^{x}.
Let m be the maximum of all the a_{i}, and c be the smallest index (from 1 to 12) such that a_{c} = m. Rat's goal is to find that c, and he asks you to help him. Rat Kwesh wants to see how much cheese he gets, so he you will have to print the expression corresponding to that a_{c}.
-----Input-----
The only line of the input contains three space-separated real numbers x, y and z (0.1 ≤ x, y, z ≤ 200.0). Each of x, y and z is given with exactly one digit after the decimal point.
-----Output-----
Find the maximum value of expression among x^{y}^{z}, x^{z}^{y}, (x^{y})^{z}, (x^{z})^{y}, y^{x}^{z}, y^{z}^{x}, (y^{x})^{z}, (y^{z})^{x}, z^{x}^{y}, z^{y}^{x}, (z^{x})^{y}, (z^{y})^{x} and print the corresponding expression. If there are many maximums, print the one that comes first in the list.
x^{y}^{z} should be outputted as x^y^z (without brackets), and (x^{y})^{z} should be outputted as (x^y)^z (quotes for clarity).
-----Examples-----
Input
1.1 3.4 2.5
Output
z^y^x
Input
2.0 2.0 2.0
Output
x^y^z
Input
1.9 1.8 1.7
Output
(x^y)^z
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from math import log
from decimal import Decimal
s = ['x^y^z', 'x^z^y', '(x^y)^z', 'y^x^z', 'y^z^x', '(y^x)^z', 'z^x^y', 'z^y^x', '(z^x)^y']
x, y, z = list(map(Decimal, input().split()))
f = []
f += [(Decimal(log(x)) * (y ** z), 0)]
f += [(Decimal(log(x)) * (z ** y), -1)]
f += [(Decimal(log(x)) * (y * z), -2)]
f += [(Decimal(log(y)) * (x ** z), -3)]
f += [(Decimal(log(y)) * (z ** x), -4)]
f += [(Decimal(log(y)) * (x * z), -5)]
f += [(Decimal(log(z)) * (x ** y), -6)]
f += [(Decimal(log(z)) * (y ** x), -7)]
f += [(Decimal(log(z)) * (x * y), -8)]
f.sort()
print(s[-f[-1][1]])
``` | {
"language": "python",
"test_cases": [
{
"input": "1.1 3.4 2.5\n",
"output": "z^y^x\n",
"type": "stdin_stdout"
},
{
"input": "2.0 2.0 2.0\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "1.9 1.8 1.7\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "2.0 2.1 2.2\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "1.5 1.7 2.5\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "1.1 1.1 1.1\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "4.2 1.1 1.2\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "113.9 125.2 88.8\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "185.9 9.6 163.4\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "198.7 23.7 89.1\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "141.1 108.1 14.9\n",
"output": "z^y^x\n",
"type": "stdin_stdout"
},
{
"input": "153.9 122.1 89.5\n",
"output": "z^y^x\n",
"type": "stdin_stdout"
},
{
"input": "25.9 77.0 144.8\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "38.7 142.2 89.8\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "51.5 156.3 145.1\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "193.9 40.7 19.7\n",
"output": "z^y^x\n",
"type": "stdin_stdout"
},
{
"input": "51.8 51.8 7.1\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "64.6 117.1 81.6\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "7.0 131.1 7.4\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "149.4 15.5 82.0\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "91.8 170.4 7.7\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "104.6 184.4 82.3\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "117.4 68.8 137.7\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "189.4 63.7 63.4\n",
"output": "z^y^x\n",
"type": "stdin_stdout"
},
{
"input": "2.2 148.1 138.0\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "144.6 103.0 193.4\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "144.0 70.4 148.1\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "156.9 154.8 73.9\n",
"output": "z^y^x\n",
"type": "stdin_stdout"
},
{
"input": "28.9 39.3 148.4\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "41.7 104.5 74.2\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "184.1 118.5 129.5\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "196.9 3.0 4.1\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "139.3 87.4 129.9\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "81.7 171.9 4.4\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "94.5 56.3 59.8\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "36.9 51.1 4.8\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "55.5 159.4 140.3\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "3.9 0.2 3.8\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "0.9 4.6 3.4\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "3.7 3.7 4.1\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "1.1 3.1 4.9\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "3.9 2.1 4.5\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "0.9 2.0 4.8\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "3.7 2.2 4.8\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "1.5 1.3 0.1\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "3.9 0.7 4.7\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "1.8 1.8 2.1\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "4.6 2.1 1.6\n",
"output": "z^y^x\n",
"type": "stdin_stdout"
},
{
"input": "2.0 1.1 2.4\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "4.4 0.5 2.0\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "1.8 0.4 2.7\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "4.6 4.4 2.3\n",
"output": "z^y^x\n",
"type": "stdin_stdout"
},
{
"input": "2.4 3.8 2.7\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "4.4 3.7 3.4\n",
"output": "z^y^x\n",
"type": "stdin_stdout"
},
{
"input": "2.2 3.1 3.0\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "4.6 3.0 3.4\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "4.0 0.4 3.1\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "1.9 4.8 3.9\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "3.9 4.3 3.4\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "1.7 4.5 4.2\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "4.1 3.5 4.5\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "1.9 3.0 4.1\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "4.3 2.4 4.9\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "1.7 1.9 4.4\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "4.5 1.3 4.8\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "1.9 1.1 4.8\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "0.4 0.2 0.3\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.4 1.1 0.9\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "0.2 0.7 0.6\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.1 0.1 0.4\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "1.4 1.1 1.0\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "1.4 0.5 0.8\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "1.2 0.7 1.3\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "1.0 0.3 1.1\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "0.9 1.2 0.2\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "0.8 0.3 0.6\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.6 0.6 1.1\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "0.5 0.1 0.9\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "0.4 1.0 1.5\n",
"output": "z^y^x\n",
"type": "stdin_stdout"
},
{
"input": "0.3 0.4 1.2\n",
"output": "z^y^x\n",
"type": "stdin_stdout"
},
{
"input": "0.1 1.4 0.3\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "1.4 0.8 0.2\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "1.4 1.2 1.4\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "1.2 0.6 0.5\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "1.1 1.5 0.4\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "1.5 1.4 1.1\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "1.4 0.8 0.9\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "1.4 0.3 1.4\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "1.2 0.5 1.2\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "1.1 1.5 1.0\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "0.9 1.0 0.1\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "0.8 0.4 1.4\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "0.7 1.4 0.4\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "0.5 0.8 0.3\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.4 1.1 0.8\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "0.2 0.1 0.2\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.1 0.2 0.6\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "0.1 0.2 0.6\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "0.5 0.1 0.3\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.1 0.1 0.1\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.5 0.5 0.1\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.5 0.2 0.2\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.3 0.4 0.4\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.1 0.3 0.5\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "0.3 0.3 0.5\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "0.2 0.6 0.3\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.6 0.3 0.2\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.2 0.1 0.6\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "0.4 0.1 0.6\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "0.6 0.4 0.3\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.4 0.2 0.3\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.2 0.2 0.5\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "0.2 0.3 0.2\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.6 0.3 0.2\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.2 0.6 0.4\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.6 0.2 0.5\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.5 0.2 0.3\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.5 0.3 0.2\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.3 0.5 0.6\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "0.5 0.3 0.1\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.3 0.4 0.1\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.5 0.4 0.5\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.1 0.5 0.4\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.5 0.5 0.6\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "0.1 0.5 0.2\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "1.0 2.0 4.0\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "1.0 4.0 2.0\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "2.0 1.0 4.0\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "2.0 4.0 1.0\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "4.0 1.0 2.0\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "4.0 2.0 1.0\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "3.0 3.0 3.1\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "0.1 0.2 0.3\n",
"output": "(z^x)^y\n",
"type": "stdin_stdout"
},
{
"input": "200.0 200.0 200.0\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "1.0 1.0 200.0\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "1.0 200.0 1.0\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "200.0 1.0 1.0\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "200.0 200.0 1.0\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "200.0 1.0 200.0\n",
"output": "x^z^y\n",
"type": "stdin_stdout"
},
{
"input": "1.0 200.0 200.0\n",
"output": "y^z^x\n",
"type": "stdin_stdout"
},
{
"input": "1.0 1.0 1.0\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "200.0 0.1 0.1\n",
"output": "x^y^z\n",
"type": "stdin_stdout"
},
{
"input": "200.0 0.1 200.0\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.1 200.0 200.0\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "200.0 200.0 0.1\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.1 200.0 0.1\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
},
{
"input": "0.1 0.1 200.0\n",
"output": "z^x^y\n",
"type": "stdin_stdout"
},
{
"input": "0.1 0.1 0.1\n",
"output": "(x^y)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.1 0.4 0.2\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.2 0.3 0.1\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "0.1 0.4 0.3\n",
"output": "(y^x)^z\n",
"type": "stdin_stdout"
},
{
"input": "1.0 2.0 1.0\n",
"output": "y^x^z\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/621/D"
} | vfc_9858 |
apps | verifiable_code | 28 | Solve the following coding problem using the programming language python:
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.
Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests.
Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only.
The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command.
Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run: all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests.
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 10^5) — the number of files with tests.
n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct.
-----Output-----
In the first line print the minimum number of lines in Vladimir's script file.
After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6.
-----Examples-----
Input
5
01 0
2 1
2extra 0
3 1
99 0
Output
4
move 3 1
move 01 5
move 2extra 4
move 99 3
Input
2
1 0
2 1
Output
3
move 1 3
move 2 1
move 3 2
Input
5
1 0
11 1
111 0
1111 1
11111 0
Output
5
move 1 5
move 11 1
move 1111 2
move 111 4
move 11111 3
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
t = [1] + [0] * n
b, a = d = [], []
h, s = [], []
for i in range(n):
f, k = input().split()
d[int(k)].append(f)
m = len(a)
for i in a:
if i.isdigit() and i[0] != '0':
j = int(i)
if 0 < j <= m:
t[j] = 1
elif m < j <= n:
t[j] = -1
else:
s.append(i)
else:
s.append(i)
for i in b:
if i.isdigit() and i[0] != '0':
j = int(i)
if m < j <= n:
t[j] = 1
elif 0 < j <= m:
t[j] = -1
else:
s.append(i)
else:
s.append(i)
x = [j for j in range(1, m + 1) if t[j] < 0]
y = [j for j in range(m + 1, n + 1) if t[j] < 0]
u = [j for j in range(1, m + 1) if not t[j]]
v = [j for j in range(m + 1, n + 1) if not t[j]]
if not s and (x or y):
s = ['0']
if y:
i = y.pop()
v.append(i)
else:
i = x.pop()
u.append(i)
h.append(str(i) + ' 0')
t[i] = 0
while x or y:
if v and x:
i = x.pop()
j = v.pop()
t[j] = 1
h.append(str(i) + ' ' + str(j))
u.append(i)
else:
u, v, x, y = v, u, y, x
k = 1
for j in s:
while t[k] == 1: k += 1
h.append(j + ' ' + str(k))
k += 1
d = '\nmove '
print(str(len(h)) + d + d.join(h) if h else 0)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n01 0\n2 1\n2extra 0\n3 1\n99 0\n",
"output": "4\nmove 3 1\nmove 01 5\nmove 2extra 4\nmove 99 3\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 0\n2 1\n",
"output": "3\nmove 1 07x45l\nmove 2 1\nmove 07x45l 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 0\n11 1\n111 0\n1111 1\n11111 0\n",
"output": "5\nmove 1 5\nmove 11 1\nmove 1111 2\nmove 111 4\nmove 11111 3\n",
"type": "stdin_stdout"
},
{
"input": "4\nir7oz8 1\nvj4v5t 1\nkwkahb 1\nj5s8o1 0\n",
"output": "4\nmove ir7oz8 1\nmove vj4v5t 2\nmove kwkahb 3\nmove j5s8o1 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 1\n1o0bp2 0\n9tn379 0\nv04v6j 1\n",
"output": "4\nmove 3 1\nmove v04v6j 2\nmove 1o0bp2 4\nmove 9tn379 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 0\nsc7czx 0\nfr4033 1\n3 0\n",
"output": "3\nmove 1 4\nmove fr4033 1\nmove sc7czx 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 0\n1 0\n2 0\nizfotg 1\n",
"output": "2\nmove 1 3\nmove izfotg 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 0\n3 0\n1 1\n4 1\n",
"output": "3\nmove 2 3b4gxa\nmove 4 2\nmove 3b4gxa 4\n",
"type": "stdin_stdout"
},
{
"input": "5\npuusew 1\npvoy4h 0\nwdzx4r 0\n1z84cx 0\nozsuvd 0\n",
"output": "5\nmove puusew 1\nmove pvoy4h 5\nmove wdzx4r 4\nmove 1z84cx 3\nmove ozsuvd 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n949pnr 1\n9sxhcr 0\n5 1\nx8srx3 1\ncl7ppd 1\n",
"output": "5\nmove 5 1\nmove 949pnr 2\nmove x8srx3 3\nmove cl7ppd 4\nmove 9sxhcr 5\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 0\n1 0\np2gcxf 1\nwfyoiq 1\nzjw3vg 1\n",
"output": "5\nmove 2 5\nmove 1 4\nmove p2gcxf 1\nmove wfyoiq 2\nmove zjw3vg 3\n",
"type": "stdin_stdout"
},
{
"input": "5\nogvgi7 0\n3 1\n4 1\n1 1\nm5nhux 0\n",
"output": "3\nmove 4 2\nmove ogvgi7 5\nmove m5nhux 4\n",
"type": "stdin_stdout"
},
{
"input": "5\nt6kdte 1\n2 1\n4 1\n5 1\n3 1\n",
"output": "1\nmove t6kdte 1\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 0\n3 1\n4 0\n1 1\n5 1\n",
"output": "3\nmove 2 8z9k33\nmove 5 2\nmove 8z9k33 5\n",
"type": "stdin_stdout"
},
{
"input": "1\nsd84r7 1\n",
"output": "1\nmove sd84r7 1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n5xzjm4 0\njoa6mr 1\n",
"output": "2\nmove joa6mr 1\nmove 5xzjm4 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 0\nxdkh5a 1\n",
"output": "2\nmove 1 2\nmove xdkh5a 1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 0\n2 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3\nz1nwrd 1\nt0xrja 0\n106qy1 0\n",
"output": "3\nmove z1nwrd 1\nmove t0xrja 3\nmove 106qy1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\nt4hdos 0\ndhje0g 0\n3 0\n",
"output": "2\nmove t4hdos 2\nmove dhje0g 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 0\n26mp5s 0\n1 1\n",
"output": "1\nmove 26mp5s 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1\n1 0\n3 0\n",
"output": "3\nmove 2 adavev\nmove 1 2\nmove adavev 1\n",
"type": "stdin_stdout"
},
{
"input": "1\nprzvln 0\n",
"output": "1\nmove przvln 1\n",
"type": "stdin_stdout"
},
{
"input": "2\nkfsipl 0\n1jj1ol 0\n",
"output": "2\nmove kfsipl 2\nmove 1jj1ol 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2x7a4g 0\n27lqe6 0\nzfo3sp 0\n",
"output": "3\nmove 2x7a4g 3\nmove 27lqe6 2\nmove zfo3sp 1\n",
"type": "stdin_stdout"
},
{
"input": "1\nxzp9ni 1\n",
"output": "1\nmove xzp9ni 1\n",
"type": "stdin_stdout"
},
{
"input": "1\nabbdf7 1\n",
"output": "1\nmove abbdf7 1\n",
"type": "stdin_stdout"
},
{
"input": "2\ndbif39 1\ne8dkf8 0\n",
"output": "2\nmove dbif39 1\nmove e8dkf8 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 0\njkwekx 1\n",
"output": "1\nmove jkwekx 1\n",
"type": "stdin_stdout"
},
{
"input": "3\nn3pmj8 0\n2alui6 0\ne7lf4u 1\n",
"output": "3\nmove e7lf4u 1\nmove n3pmj8 3\nmove 2alui6 2\n",
"type": "stdin_stdout"
},
{
"input": "3\ndr1lp8 0\n1 0\n6a2egk 1\n",
"output": "3\nmove 1 3\nmove 6a2egk 1\nmove dr1lp8 2\n",
"type": "stdin_stdout"
},
{
"input": "4\nyi9ta0 1\nmeljgm 0\nf7bqon 0\n5bbvun 0\n",
"output": "4\nmove yi9ta0 1\nmove meljgm 4\nmove f7bqon 3\nmove 5bbvun 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n0la3gu 0\nzhrmyb 1\n3iprc0 0\n3 0\n",
"output": "3\nmove zhrmyb 1\nmove 0la3gu 4\nmove 3iprc0 2\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n17dgbb 0\n2 1\n",
"output": "2\nmove 2 1\nmove 17dgbb 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 0\n2 1\n",
"output": "3\nmove 1 94gxxb\nmove 2 1\nmove 94gxxb 2\n",
"type": "stdin_stdout"
},
{
"input": "3\nscrn8k 0\n3 1\nycvm9s 0\n",
"output": "3\nmove 3 1\nmove scrn8k 3\nmove ycvm9s 2\n",
"type": "stdin_stdout"
},
{
"input": "3\nt0dfz3 0\n3 0\n1 1\n",
"output": "1\nmove t0dfz3 2\n",
"type": "stdin_stdout"
},
{
"input": "4\nkgw83p 0\np3p3ch 0\n4 1\n0te9lv 0\n",
"output": "4\nmove 4 1\nmove kgw83p 4\nmove p3p3ch 3\nmove 0te9lv 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 1\nnj94jx 0\n3a5ad1 0\n1 0\n",
"output": "4\nmove 1 4\nmove 3 1\nmove nj94jx 3\nmove 3a5ad1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\no9z069 1\n5hools 1\n",
"output": "2\nmove o9z069 1\nmove 5hools 2\n",
"type": "stdin_stdout"
},
{
"input": "2\nyzzyab 1\n728oq0 1\n",
"output": "2\nmove yzzyab 1\nmove 728oq0 2\n",
"type": "stdin_stdout"
},
{
"input": "2\nqy2kmc 1\nqb4crj 1\n",
"output": "2\nmove qy2kmc 1\nmove qb4crj 2\n",
"type": "stdin_stdout"
},
{
"input": "3\nunw560 1\n0iswxk 0\ndonjp9 1\n",
"output": "3\nmove unw560 1\nmove donjp9 2\nmove 0iswxk 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 0\nuv8c54 1\n508bb0 1\n",
"output": "3\nmove 2 3\nmove uv8c54 1\nmove 508bb0 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n9afh0z 1\n0qcaht 1\n3 0\n",
"output": "2\nmove 9afh0z 1\nmove 0qcaht 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n2kk04q 0\nkdktvk 1\nc4i5k8 1\nawaock 0\n",
"output": "4\nmove kdktvk 1\nmove c4i5k8 2\nmove 2kk04q 4\nmove awaock 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 0\nmqbjos 0\n6mhijg 1\n6wum8y 1\n",
"output": "4\nmove 2 4\nmove 6mhijg 1\nmove 6wum8y 2\nmove mqbjos 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 0\npa613p 1\nuuizq7 1\n2 0\n",
"output": "3\nmove 2 3\nmove pa613p 1\nmove uuizq7 2\n",
"type": "stdin_stdout"
},
{
"input": "5\nw0g96a 1\nv99tdi 0\nmywrle 0\nweh22w 1\n9hywt4 0\n",
"output": "5\nmove w0g96a 1\nmove weh22w 2\nmove v99tdi 5\nmove mywrle 4\nmove 9hywt4 3\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 0\n12qcjd 1\nuthzbz 0\nb3670z 0\nl2u93o 1\n",
"output": "4\nmove 12qcjd 1\nmove l2u93o 2\nmove uthzbz 4\nmove b3670z 3\n",
"type": "stdin_stdout"
},
{
"input": "5\n0jc7xb 1\n2 0\n1m7l9s 0\n9xzkau 1\n1 0\n",
"output": "5\nmove 2 5\nmove 1 4\nmove 0jc7xb 1\nmove 9xzkau 2\nmove 1m7l9s 3\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\nvinxur 1\n",
"output": "1\nmove vinxur 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1qe46n 1\n1 1\n",
"output": "1\nmove 1qe46n 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\ng5jlzp 1\n",
"output": "1\nmove g5jlzp 2\n",
"type": "stdin_stdout"
},
{
"input": "3\nc8p28p 1\n2 1\nvk4gdf 0\n",
"output": "2\nmove c8p28p 1\nmove vk4gdf 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1\n3 0\nhs9j9t 1\n",
"output": "1\nmove hs9j9t 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1\n1 0\nomitxh 1\n",
"output": "2\nmove 1 3\nmove omitxh 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 1\nu9do88 1\n787at9 0\nfcud6k 0\n",
"output": "4\nmove 4 1\nmove u9do88 2\nmove 787at9 4\nmove fcud6k 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 0\nqvw4ow 1\nne0ng9 0\n1 1\n",
"output": "2\nmove qvw4ow 2\nmove ne0ng9 4\n",
"type": "stdin_stdout"
},
{
"input": "4\ng6ugrm 1\n1 1\n3 0\n2 0\n",
"output": "2\nmove 2 4\nmove g6ugrm 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 1\nz9zr7d 0\ne8rwo4 1\nrfpjp6 0\ngz6dhj 0\n",
"output": "5\nmove 5 1\nmove e8rwo4 2\nmove z9zr7d 5\nmove rfpjp6 4\nmove gz6dhj 3\n",
"type": "stdin_stdout"
},
{
"input": "5\n5sn77g 0\nsetddt 1\nbz16cb 0\n4 1\n2 0\n",
"output": "5\nmove 4 1\nmove 2 5\nmove setddt 2\nmove 5sn77g 4\nmove bz16cb 3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1\nx2miqh 1\n3 0\n2 0\n1rq643 0\n",
"output": "3\nmove 2 5\nmove x2miqh 2\nmove 1rq643 4\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 1\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 1\nav5vex 0\n1 1\n",
"output": "2\nmove 3 2\nmove av5vex 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 1\n1 0\n2 1\n",
"output": "3\nmove 3 ger8ob\nmove 1 3\nmove ger8ob 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 1\n1 0\n2 1\n",
"output": "3\nmove 3 7d2teb\nmove 1 3\nmove 7d2teb 1\n",
"type": "stdin_stdout"
},
{
"input": "4\ny9144q 0\n3 1\n2 1\ns0bdnf 0\n",
"output": "3\nmove 3 1\nmove y9144q 4\nmove s0bdnf 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 1\n1 0\n3 1\nmod9zl 0\n",
"output": "4\nmove 4 2\nmove 1 4\nmove 3 1\nmove mod9zl 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 1\n3 1\n1 0\n2 0\n",
"output": "5\nmove 4 ger8ob\nmove 1 4\nmove 3 1\nmove 2 3\nmove ger8ob 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1\nnoidnv 0\n3 1\nx3xiiz 0\n1lfa9v 0\n",
"output": "4\nmove 3 2\nmove noidnv 5\nmove x3xiiz 4\nmove 1lfa9v 3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1\nvsyajx 0\n783b38 0\n4 0\n2 1\n",
"output": "2\nmove vsyajx 5\nmove 783b38 3\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 1\n5 0\ncvfl8i 0\n4 1\n2 0\n",
"output": "4\nmove 3 1\nmove 2 3\nmove 4 2\nmove cvfl8i 4\n",
"type": "stdin_stdout"
},
{
"input": "3\nbxo0pe 1\nbt50pa 1\n2tx68t 1\n",
"output": "3\nmove bxo0pe 1\nmove bt50pa 2\nmove 2tx68t 3\n",
"type": "stdin_stdout"
},
{
"input": "3\nj9rnac 1\noetwfz 1\nd6n3ww 1\n",
"output": "3\nmove j9rnac 1\nmove oetwfz 2\nmove d6n3ww 3\n",
"type": "stdin_stdout"
},
{
"input": "3\naf2f6j 1\nmjni5l 1\njvyxgc 1\n",
"output": "3\nmove af2f6j 1\nmove mjni5l 2\nmove jvyxgc 3\n",
"type": "stdin_stdout"
},
{
"input": "3\nr2qlj2 1\nt8wf1y 1\nigids8 1\n",
"output": "3\nmove r2qlj2 1\nmove t8wf1y 2\nmove igids8 3\n",
"type": "stdin_stdout"
},
{
"input": "4\nuilh9a 0\n4lxxh9 1\nkqdpzy 1\nn1d7hd 1\n",
"output": "4\nmove 4lxxh9 1\nmove kqdpzy 2\nmove n1d7hd 3\nmove uilh9a 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 0\niipymv 1\nvakd5b 1\n2ktczv 1\n",
"output": "4\nmove 3 4\nmove iipymv 1\nmove vakd5b 2\nmove 2ktczv 3\n",
"type": "stdin_stdout"
},
{
"input": "4\nq4b449 1\n3 0\ncjg1x2 1\ne878er 1\n",
"output": "4\nmove 3 4\nmove q4b449 1\nmove cjg1x2 2\nmove e878er 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n9f4aoa 1\n4 0\nf4m1ec 1\nqyr2h6 1\n",
"output": "3\nmove 9f4aoa 1\nmove f4m1ec 2\nmove qyr2h6 3\n",
"type": "stdin_stdout"
},
{
"input": "5\n73s1nt 1\nsbngv2 0\n4n3qri 1\nbyhzp8 1\nadpjs4 0\n",
"output": "5\nmove 73s1nt 1\nmove 4n3qri 2\nmove byhzp8 3\nmove sbngv2 5\nmove adpjs4 4\n",
"type": "stdin_stdout"
},
{
"input": "5\n7ajg8o 1\np7cqxy 1\n3qrp34 0\nh93m07 1\n2 0\n",
"output": "5\nmove 2 5\nmove 7ajg8o 1\nmove p7cqxy 2\nmove h93m07 3\nmove 3qrp34 4\n",
"type": "stdin_stdout"
},
{
"input": "5\ny0wnwz 1\n5 0\n0totai 1\n1 0\nym8xwz 1\n",
"output": "4\nmove 1 4\nmove y0wnwz 1\nmove 0totai 2\nmove ym8xwz 3\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 0\n4 0\n5nvzu4 1\nvkpzzk 1\nzamzcz 1\n",
"output": "3\nmove 5nvzu4 1\nmove vkpzzk 2\nmove zamzcz 3\n",
"type": "stdin_stdout"
},
{
"input": "6\np1wjw9 1\nueksby 0\nu1ixfc 1\nj3lk2e 1\n36iskv 0\n9imqi1 0\n",
"output": "6\nmove p1wjw9 1\nmove u1ixfc 2\nmove j3lk2e 3\nmove ueksby 6\nmove 36iskv 5\nmove 9imqi1 4\n",
"type": "stdin_stdout"
},
{
"input": "6\n6slonw 1\nptk9mc 1\n57a4nq 0\nhiq2f7 1\n2 0\nc0gtv3 0\n",
"output": "6\nmove 2 6\nmove 6slonw 1\nmove ptk9mc 2\nmove hiq2f7 3\nmove 57a4nq 5\nmove c0gtv3 4\n",
"type": "stdin_stdout"
},
{
"input": "6\n5 0\n2 0\ncbhvyf 1\nl1z5mg 0\nwkwhby 1\nx7fdh9 1\n",
"output": "5\nmove 2 6\nmove cbhvyf 1\nmove wkwhby 2\nmove x7fdh9 3\nmove l1z5mg 4\n",
"type": "stdin_stdout"
},
{
"input": "6\n1t68ks 1\npkbj1g 1\n5 0\n5pw8wm 1\n1 0\n4 0\n",
"output": "4\nmove 1 6\nmove 1t68ks 1\nmove pkbj1g 2\nmove 5pw8wm 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n7ph5fw 1\ntfxz1j 1\n",
"output": "2\nmove 7ph5fw 2\nmove tfxz1j 3\n",
"type": "stdin_stdout"
},
{
"input": "3\norwsz0 1\nmbt097 1\n3 1\n",
"output": "2\nmove orwsz0 1\nmove mbt097 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\nzwfnx2 1\n7g8t6z 1\n",
"output": "2\nmove zwfnx2 2\nmove 7g8t6z 3\n",
"type": "stdin_stdout"
},
{
"input": "3\nqmf7iz 1\ndjwdce 1\n1 1\n",
"output": "2\nmove qmf7iz 2\nmove djwdce 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4i2i2a 0\n4 1\npf618n 1\nlx6nmh 1\n",
"output": "4\nmove 4 1\nmove pf618n 2\nmove lx6nmh 3\nmove 4i2i2a 4\n",
"type": "stdin_stdout"
},
{
"input": "4\nxpteku 1\n1 0\n4 1\n73xpqz 1\n",
"output": "4\nmove 4 2\nmove 1 4\nmove xpteku 1\nmove 73xpqz 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1wp56i 1\n2 1\n1 0\n6m76jb 1\n",
"output": "3\nmove 1 4\nmove 1wp56i 1\nmove 6m76jb 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 1\nyumiqt 1\n1 0\nt19jus 1\n",
"output": "3\nmove 1 4\nmove yumiqt 1\nmove t19jus 2\n",
"type": "stdin_stdout"
},
{
"input": "5\nynagvf 1\n3 1\nojz4mm 1\ndovec3 0\nnc1jye 0\n",
"output": "4\nmove ynagvf 1\nmove ojz4mm 2\nmove dovec3 5\nmove nc1jye 4\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 1\nwje9ts 1\nkytn5q 1\n7frk8z 0\n3 0\n",
"output": "5\nmove 5 1\nmove 3 5\nmove wje9ts 2\nmove kytn5q 3\nmove 7frk8z 4\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 0\n4 1\n3 0\nlog9cm 1\nu5m0ls 1\n",
"output": "5\nmove 4 2\nmove 1 5\nmove 3 4\nmove log9cm 1\nmove u5m0ls 3\n",
"type": "stdin_stdout"
},
{
"input": "5\nh015vv 1\n3 1\n1 0\n9w2keb 1\n2 0\n",
"output": "4\nmove 1 5\nmove 2 4\nmove h015vv 1\nmove 9w2keb 2\n",
"type": "stdin_stdout"
},
{
"input": "6\n0zluka 0\nqp7q8l 1\nwglqu8 1\n9i7kta 0\nnwf8m3 0\n3 1\n",
"output": "5\nmove qp7q8l 1\nmove wglqu8 2\nmove 0zluka 6\nmove 9i7kta 5\nmove nwf8m3 4\n",
"type": "stdin_stdout"
},
{
"input": "6\n3 1\n1h3t85 1\n5 0\nrf2ikt 0\n3vhl6e 1\n5l3oka 0\n",
"output": "4\nmove 1h3t85 1\nmove 3vhl6e 2\nmove rf2ikt 6\nmove 5l3oka 4\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 0\n3 0\nw9h0pv 1\n5 1\nq92z4i 0\n6qb4ia 1\n",
"output": "6\nmove 5 1\nmove 2 6\nmove 3 5\nmove w9h0pv 2\nmove 6qb4ia 3\nmove q92z4i 4\n",
"type": "stdin_stdout"
},
{
"input": "6\n4 1\n410jiy 1\n1 0\n6 0\nxc98l2 1\n5 0\n",
"output": "4\nmove 4 2\nmove 1 4\nmove 410jiy 1\nmove xc98l2 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\nc9qyld 1\n3 1\n",
"output": "1\nmove c9qyld 2\n",
"type": "stdin_stdout"
},
{
"input": "3\ngdm5ri 1\n1 1\n2 1\n",
"output": "1\nmove gdm5ri 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 1\n2 1\ni19lnk 1\n",
"output": "1\nmove i19lnk 1\n",
"type": "stdin_stdout"
},
{
"input": "3\ncxbbpd 1\n3 1\n1 1\n",
"output": "1\nmove cxbbpd 2\n",
"type": "stdin_stdout"
},
{
"input": "4\nwy6i6o 0\n1 1\n3 1\niy1dq6 1\n",
"output": "2\nmove iy1dq6 2\nmove wy6i6o 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 1\nwgh8s0 1\n1 0\n2 1\n",
"output": "3\nmove 4 3\nmove 1 4\nmove wgh8s0 1\n",
"type": "stdin_stdout"
},
{
"input": "4\nhex0ur 1\n4 1\n3 0\n2 1\n",
"output": "3\nmove 4 1\nmove 3 4\nmove hex0ur 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 1\n1 1\n3 0\n4soxj3 1\n",
"output": "3\nmove 4 2\nmove 3 4\nmove 4soxj3 3\n",
"type": "stdin_stdout"
},
{
"input": "5\n5sbtul 1\n2 1\n8i2duz 0\n5 1\n4b85z6 0\n",
"output": "4\nmove 5 1\nmove 5sbtul 3\nmove 8i2duz 5\nmove 4b85z6 4\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 1\n4 0\nejo0a4 1\ngqzdbk 0\n1 1\n",
"output": "2\nmove ejo0a4 2\nmove gqzdbk 5\n",
"type": "stdin_stdout"
},
{
"input": "5\n2y4agr 1\n5 0\n3 0\n1 1\n4 1\n",
"output": "3\nmove 4 2\nmove 3 4\nmove 2y4agr 3\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 0\n1 1\nq4hyeg 1\n5 0\n4 1\n",
"output": "3\nmove 4 3\nmove 2 4\nmove q4hyeg 2\n",
"type": "stdin_stdout"
},
{
"input": "6\n5 1\nrdm6fu 0\n4 1\noclx1h 0\n7l3kg1 1\nq25te0 0\n",
"output": "6\nmove 5 1\nmove 4 2\nmove 7l3kg1 3\nmove rdm6fu 6\nmove oclx1h 5\nmove q25te0 4\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 0\np4tuyt 0\n5 1\n2 1\nwrrcmu 1\n3r4wqz 0\n",
"output": "5\nmove 5 3\nmove 1 6\nmove wrrcmu 1\nmove p4tuyt 5\nmove 3r4wqz 4\n",
"type": "stdin_stdout"
},
{
"input": "6\n5 1\n6 0\nxhfzge 0\n3 1\n1 0\n1n9mqv 1\n",
"output": "4\nmove 5 2\nmove 1 5\nmove 1n9mqv 1\nmove xhfzge 4\n",
"type": "stdin_stdout"
},
{
"input": "6\nhmpfsz 1\n6 0\n5 1\n4 0\n1 0\n3 1\n",
"output": "3\nmove 5 2\nmove 1 5\nmove hmpfsz 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n3 1\n2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1\n3 1\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1\n1 1\n3 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n2 1\n3 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 1\n1 1\n4 1\nd1cks2 0\n",
"output": "2\nmove 4 2\nmove d1cks2 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 0\n3 1\n1 1\n2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 1\n4 1\n1 0\n3 1\n",
"output": "3\nmove 4 sm2dpo\nmove 1 4\nmove sm2dpo 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 1\n1 1\n3 1\n2 0\n",
"output": "3\nmove 4 2kxv8f\nmove 2 4\nmove 2kxv8f 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n4 1\nhvshea 0\naio11n 0\n2 1\n3 1\n",
"output": "3\nmove 4 1\nmove hvshea 5\nmove aio11n 4\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 0\nts7a1c 0\n4 1\n1 1\n2 1\n",
"output": "2\nmove 4 3\nmove ts7a1c 4\n",
"type": "stdin_stdout"
},
{
"input": "5\n4 0\n3 1\n5 0\n2 1\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 1\n5 0\n4 1\n1 1\n2 0\n",
"output": "3\nmove 4 9nzu21\nmove 2 4\nmove 9nzu21 2\n",
"type": "stdin_stdout"
},
{
"input": "6\neik3kw 0\n5 1\nzoonoj 0\n2 1\n1 1\nivzfie 0\n",
"output": "4\nmove 5 3\nmove eik3kw 6\nmove zoonoj 5\nmove ivzfie 4\n",
"type": "stdin_stdout"
},
{
"input": "6\n7igwk9 0\n6 1\n5 1\ndx2yu0 0\n2 0\n1 1\n",
"output": "5\nmove 6 3\nmove 2 6\nmove 5 2\nmove 7igwk9 5\nmove dx2yu0 4\n",
"type": "stdin_stdout"
},
{
"input": "6\nc3py3h 0\n2 1\n4 0\n3 0\n1 1\n5 1\n",
"output": "3\nmove 3 6\nmove 5 3\nmove c3py3h 5\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 1\n3 0\n2 1\n6 1\n4 0\n5 0\n",
"output": "3\nmove 3 2kxv8f\nmove 6 3\nmove 2kxv8f 6\n",
"type": "stdin_stdout"
},
{
"input": "20\nphp8vy 1\nkeeona 0\n8 0\nwzf4eb 0\n16 1\n9 0\nf2548d 0\n11 0\nyszsig 0\nyyf4q2 0\n1pon1p 1\njvpwuo 0\nd9stsx 0\ne14bkx 1\n5 0\n17 0\nsbklx4 0\nsfms2u 1\n6 0\n18 1\n",
"output": "16\nmove 16 1\nmove 18 2\nmove 5 20\nmove 6 19\nmove php8vy 3\nmove 1pon1p 4\nmove e14bkx 5\nmove sfms2u 6\nmove keeona 18\nmove wzf4eb 16\nmove f2548d 15\nmove yszsig 14\nmove yyf4q2 13\nmove jvpwuo 12\nmove d9stsx 10\nmove sbklx4 7\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 1\n4 1\n1 0\n2 0\n",
"output": "5\nmove 3 7dcv6s\nmove 1 3\nmove 4 1\nmove 2 4\nmove 7dcv6s 2\n",
"type": "stdin_stdout"
},
{
"input": "1\n01 1\n",
"output": "1\nmove 01 1\n",
"type": "stdin_stdout"
},
{
"input": "2\n01 0\n02 1\n",
"output": "2\nmove 02 1\nmove 01 2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/858/E"
} | vfc_9866 |
apps | verifiable_code | 29 | Solve the following coding problem using the programming language python:
Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.
The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.
-----Input-----
You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.
-----Output-----
Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.
-----Examples-----
Input
000000
Output
0
Input
123456
Output
2
Input
111000
Output
1
-----Note-----
In the first example the ticket is already lucky, so the answer is 0.
In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.
In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x=int(input())
def s(a):
r=0
while a>0:
r+=a%10
a//=10
return r
def d(a,b):
r=0
for i in range(6):
if a%10!=b%10:
r += 1
a//=10
b//=10
return r
c=6
for i in range(1000000):
if s(i%1000)==s(i//1000):
c=min(c,d(x,i))
print(c)
``` | {
"language": "python",
"test_cases": [
{
"input": "000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "123456\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "111000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "120111\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "999999\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "199880\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "899889\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "899888\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "505777\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "999000\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "989010\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "651894\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "858022\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "103452\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "999801\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "999990\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "697742\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "242367\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "099999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "198999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "023680\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "999911\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "000990\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "117099\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "990999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "000111\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "000444\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "202597\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "000333\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "030039\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "000009\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "006456\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "022995\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "999198\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "223456\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "333665\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "123986\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "599257\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "101488\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "111399\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "369009\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "024887\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "314347\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "145892\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "321933\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100172\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "222455\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "317596\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "979245\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "000018\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "101389\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "123985\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "900000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "132069\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "949256\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "123996\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "034988\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "320869\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "089753\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "335667\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "868580\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "958031\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "117999\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "000001\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "213986\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "123987\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "111993\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "642479\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "033788\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "766100\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "012561\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "111695\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "123689\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "944234\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "154999\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "333945\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "371130\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "977330\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "777544\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "111965\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "988430\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "123789\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "111956\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "444776\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "001019\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "011299\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "011389\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "999333\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "126999\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "744438\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "588121\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "698213\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "652858\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "989304\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "888213\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "969503\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "988034\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "889444\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "990900\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "301679\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "434946\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "191578\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "118000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "636915\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "811010\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "822569\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "122669\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "010339\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "213698\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "895130\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "000900\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "191000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "001000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "080189\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "990000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "201984\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "002667\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "877542\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "301697\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "211597\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "420337\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "024768\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "878033\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "788024\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "023869\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "466341\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "696327\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "779114\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "858643\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "011488\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "003669\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "202877\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "738000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "567235\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "887321\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "401779\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "989473\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "004977\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "023778\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "809116\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "042762\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "777445\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "769302\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "023977\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "990131\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/845/B"
} | vfc_9870 |
apps | verifiable_code | 30 | Solve the following coding problem using the programming language python:
The campus has $m$ rooms numbered from $0$ to $m - 1$. Also the $x$-mouse lives in the campus. The $x$-mouse is not just a mouse: each second $x$-mouse moves from room $i$ to the room $i \cdot x \mod{m}$ (in fact, it teleports from one room to another since it doesn't visit any intermediate room). Starting position of the $x$-mouse is unknown.
You are responsible to catch the $x$-mouse in the campus, so you are guessing about minimum possible number of traps (one trap in one room) you need to place. You are sure that if the $x$-mouse enters a trapped room, it immediately gets caught.
And the only observation you made is $\text{GCD} (x, m) = 1$.
-----Input-----
The only line contains two integers $m$ and $x$ ($2 \le m \le 10^{14}$, $1 \le x < m$, $\text{GCD} (x, m) = 1$) — the number of rooms and the parameter of $x$-mouse.
-----Output-----
Print the only integer — minimum number of traps you need to install to catch the $x$-mouse.
-----Examples-----
Input
4 3
Output
3
Input
5 2
Output
2
-----Note-----
In the first example you can, for example, put traps in rooms $0$, $2$, $3$. If the $x$-mouse starts in one of this rooms it will be caught immediately. If $x$-mouse starts in the $1$-st rooms then it will move to the room $3$, where it will be caught.
In the second example you can put one trap in room $0$ and one trap in any other room since $x$-mouse will visit all rooms $1..m-1$ if it will start in any of these rooms.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from math import gcd
def powmod(a,b,m):
a%=m
r=1
while b:
if b&1:r=r*a%m
a=a*a%m
b>>=1
return r
def f(n):
r=[]
if (n&1)==0:
e=0
while (n&1)==0:n>>=1;e+=1
yield (2,e)
p=3
while n>1:
if p*p>n:p=n
if n%p:
p+=2
continue
e=1;n//=p
while n%p==0:n//=p;e+=1
yield (p,e)
p+=2
return r
m,x=map(int,input().split())
p=2
r=[(1,1)]
for p,e in f(m):
assert e>=1
ord=p-1
assert powmod(x,ord,p)==1
for pi,ei in f(p-1):
while ord % pi == 0 and powmod(x,ord//pi,p)==1: ord//=pi
ords=[(1,1),(ord,p-1)]
q=p
for v in range(2,e+1):
q*=p
if powmod(x,ord,q)!=1:ord*=p
assert powmod(x,ord,q)==1
ords.append((ord,q//p*(p-1)))
r=[(a//gcd(a,c)*c,b*d) for a,b in r for c,d in ords]
print(sum(y//x for x,y in r))
``` | {
"language": "python",
"test_cases": [
{
"input": "4 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100000000000000 1\n",
"output": "100000000000000\n",
"type": "stdin_stdout"
},
{
"input": "100000000000000 99999999999999\n",
"output": "50000000000001\n",
"type": "stdin_stdout"
},
{
"input": "12 1\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "12 5\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "12 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "12 11\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "1117 1\n",
"output": "1117\n",
"type": "stdin_stdout"
},
{
"input": "1117 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1117 3\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "1117 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1117 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1117 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1117 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1117 8\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1117 9\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "1260 1259\n",
"output": "631\n",
"type": "stdin_stdout"
},
{
"input": "1260 1249\n",
"output": "240\n",
"type": "stdin_stdout"
},
{
"input": "1260 1247\n",
"output": "217\n",
"type": "stdin_stdout"
},
{
"input": "1260 1243\n",
"output": "189\n",
"type": "stdin_stdout"
},
{
"input": "1260 1241\n",
"output": "300\n",
"type": "stdin_stdout"
},
{
"input": "1260 1237\n",
"output": "148\n",
"type": "stdin_stdout"
},
{
"input": "1260 1231\n",
"output": "375\n",
"type": "stdin_stdout"
},
{
"input": "1260 1229\n",
"output": "236\n",
"type": "stdin_stdout"
},
{
"input": "1260 1223\n",
"output": "163\n",
"type": "stdin_stdout"
},
{
"input": "1260 1219\n",
"output": "385\n",
"type": "stdin_stdout"
},
{
"input": "1260 1159\n",
"output": "253\n",
"type": "stdin_stdout"
},
{
"input": "1260 1157\n",
"output": "144\n",
"type": "stdin_stdout"
},
{
"input": "1260 1153\n",
"output": "180\n",
"type": "stdin_stdout"
},
{
"input": "1260 1151\n",
"output": "275\n",
"type": "stdin_stdout"
},
{
"input": "1260 1147\n",
"output": "215\n",
"type": "stdin_stdout"
},
{
"input": "1260 1139\n",
"output": "231\n",
"type": "stdin_stdout"
},
{
"input": "1260 1133\n",
"output": "380\n",
"type": "stdin_stdout"
},
{
"input": "1260 1129\n",
"output": "276\n",
"type": "stdin_stdout"
},
{
"input": "1260 1123\n",
"output": "143\n",
"type": "stdin_stdout"
},
{
"input": "1260 1121\n",
"output": "420\n",
"type": "stdin_stdout"
},
{
"input": "99999999999973 53\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "99999999999973 59\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "99999999999973 61\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "99999999999973 67\n",
"output": "117\n",
"type": "stdin_stdout"
},
{
"input": "99999999999973 71\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "99999999999971 53\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "99999999999971 59\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "99999999999971 61\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "99999999999971 67\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "99999999999971 71\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "99999999999962 73\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "99999999999962 79\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "99999999999962 83\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "99999999999962 89\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "99999999999962 97\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "99999999999898 73\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "99999999999898 79\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "99999999999898 83\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "99999999999898 89\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "99999999999898 97\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "99999999999894 101\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "99999999999894 103\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "99999999999894 107\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "99999999999894 109\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "99999999999894 113\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "99999999999726 101\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "99999999999726 103\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "99999999999726 107\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "99999999999726 109\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "99999999999726 113\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "99999999999030 127\n",
"output": "162\n",
"type": "stdin_stdout"
},
{
"input": "99999999999030 131\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "99999999999030 137\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "99999999999030 139\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"input": "99999999999030 149\n",
"output": "316\n",
"type": "stdin_stdout"
},
{
"input": "99999999998490 127\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "99999999998490 131\n",
"output": "110\n",
"type": "stdin_stdout"
},
{
"input": "99999999998490 137\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "99999999998490 139\n",
"output": "126\n",
"type": "stdin_stdout"
},
{
"input": "99999999998490 149\n",
"output": "106\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 53\n",
"output": "6386192358\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 59\n",
"output": "5903853669\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 61\n",
"output": "1778524398\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 67\n",
"output": "9386162115\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 71\n",
"output": "3440795217\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 73\n",
"output": "3407682168\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 79\n",
"output": "2275785525\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 83\n",
"output": "4545097955\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 89\n",
"output": "19428828848\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 97\n",
"output": "2191149504\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 101\n",
"output": "1244195550\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 103\n",
"output": "2829289260\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 107\n",
"output": "302443010\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 109\n",
"output": "309268638\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 113\n",
"output": "291128068\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 127\n",
"output": "500231088\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 131\n",
"output": "309172890\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 137\n",
"output": "7972868454\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 139\n",
"output": "2547026670\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 149\n",
"output": "1403838534\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 963761198299\n",
"output": "6174161235\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 963761198297\n",
"output": "10459717320\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 963761198293\n",
"output": "11919509478\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 963761198291\n",
"output": "5810183379\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 963761198287\n",
"output": "2616319665\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 963761198273\n",
"output": "11146618176\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 963761198269\n",
"output": "2985636126\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 963761198263\n",
"output": "48735509439\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 963761198261\n",
"output": "13656285022\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 963761198251\n",
"output": "6049249425\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 97821761637499\n",
"output": "6174161235\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 97821761637497\n",
"output": "8923056792\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 97821761637493\n",
"output": "11943039006\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 97821761637491\n",
"output": "5832233847\n",
"type": "stdin_stdout"
},
{
"input": "97821761637600 97821761637487\n",
"output": "2616319665\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 200560490029\n",
"output": "1128917538\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 200560490027\n",
"output": "1003979340\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 200560490023\n",
"output": "291692304\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 200560490021\n",
"output": "309271050\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 200560490017\n",
"output": "293274234\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 200560490003\n",
"output": "498085450\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 200560489999\n",
"output": "321151644\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 200560489993\n",
"output": "7212515628\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 200560489991\n",
"output": "2135429940\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 200560489981\n",
"output": "1403682750\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 7420738134709\n",
"output": "1244367054\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 7420738134707\n",
"output": "2829284640\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 7420738134703\n",
"output": "302429394\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 7420738134701\n",
"output": "309271050\n",
"type": "stdin_stdout"
},
{
"input": "7420738134810 7420738134697\n",
"output": "291126132\n",
"type": "stdin_stdout"
},
{
"input": "99999640000243 99999640000143\n",
"output": "118\n",
"type": "stdin_stdout"
},
{
"input": "99999640000243 99999640000142\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "99999640000243 99999640000141\n",
"output": "117\n",
"type": "stdin_stdout"
},
{
"input": "99999640000243 99999640000140\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "99999640000243 99999640000139\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "93823365636000 53\n",
"output": "238670450\n",
"type": "stdin_stdout"
},
{
"input": "93823365636000 59\n",
"output": "58923677\n",
"type": "stdin_stdout"
},
{
"input": "93823365636000 61\n",
"output": "31645794\n",
"type": "stdin_stdout"
},
{
"input": "18632716502401 67\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "18632716502401 71\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "18632716502401 73\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "93047965920000 79\n",
"output": "103938875\n",
"type": "stdin_stdout"
},
{
"input": "93047965920000 83\n",
"output": "20177587\n",
"type": "stdin_stdout"
},
{
"input": "93047965920000 89\n",
"output": "517743436\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1027/G"
} | vfc_9874 |
apps | verifiable_code | 31 | Solve the following coding problem using the programming language python:
ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and decides to test this with the inhabitants of Udayland.
In Udayland, there are 2^{n} days in a year. ZS the Coder wants to interview k people from Udayland, each of them has birthday in one of 2^{n} days (each day with equal probability). He is interested in the probability of at least two of them have the birthday at the same day.
ZS the Coder knows that the answer can be written as an irreducible fraction $\frac{A}{B}$. He wants to find the values of A and B (he does not like to deal with floating point numbers). Can you help him?
-----Input-----
The first and only line of the input contains two integers n and k (1 ≤ n ≤ 10^18, 2 ≤ k ≤ 10^18), meaning that there are 2^{n} days in a year and that ZS the Coder wants to interview exactly k people.
-----Output-----
If the probability of at least two k people having the same birthday in 2^{n} days long year equals $\frac{A}{B}$ (A ≥ 0, B ≥ 1, $\operatorname{gcd}(A, B) = 1$), print the A and B in a single line.
Since these numbers may be too large, print them modulo 10^6 + 3. Note that A and B must be coprime before their remainders modulo 10^6 + 3 are taken.
-----Examples-----
Input
3 2
Output
1 8
Input
1 3
Output
1 1
Input
4 3
Output
23 128
-----Note-----
In the first sample case, there are 2^3 = 8 days in Udayland. The probability that 2 people have the same birthday among 2 people is clearly $\frac{1}{8}$, so A = 1, B = 8.
In the second sample case, there are only 2^1 = 2 days in Udayland, but there are 3 people, so it is guaranteed that two of them have the same birthday. Thus, the probability is 1 and A = B = 1.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
m = 10** 6 + 3
n, k = list(map(int, input().split()))
p = 1
for i in range(n):
p *= 2
if p > k:
break
if p < k:
print('1 1')
return
gcd = tmp = k - 1
while tmp:
gcd -= tmp % 2
tmp //= 2
b = pow(2, (k - 1) * n - gcd, m)
a = 1
mem = [-1]*100
for i in range(1, k):
cnt = 0
while i % 2 == 0:
i //= 2
cnt += 1
if mem[cnt] == -1:
mem[cnt] = pow(2, n - cnt, m)
a = a * (mem[cnt] - i + m) % m
if a == 0:
break
print((b - a + m) % m, b)
``` | {
"language": "python",
"test_cases": [
{
"input": "3 2\n",
"output": "1 8",
"type": "stdin_stdout"
},
{
"input": "1 3\n",
"output": "1 1",
"type": "stdin_stdout"
},
{
"input": "4 3\n",
"output": "23 128",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000000000000\n",
"output": "906300 906300",
"type": "stdin_stdout"
},
{
"input": "59 576460752303423489\n",
"output": "1 1",
"type": "stdin_stdout"
},
{
"input": "1234567891234 100005\n",
"output": "173817 722464",
"type": "stdin_stdout"
},
{
"input": "2 4\n",
"output": "29 32",
"type": "stdin_stdout"
},
{
"input": "59 576460752303423488\n",
"output": "840218 840218",
"type": "stdin_stdout"
},
{
"input": "2016 2016\n",
"output": "1564 227035",
"type": "stdin_stdout"
},
{
"input": "2016 2017\n",
"output": "360153 815112",
"type": "stdin_stdout"
},
{
"input": "468804735183774830 244864585447548924\n",
"output": "365451 365451",
"type": "stdin_stdout"
},
{
"input": "172714899512474455 414514930706102803\n",
"output": "626500 626500",
"type": "stdin_stdout"
},
{
"input": "876625063841174080 360793239109880865\n",
"output": "34117 34117",
"type": "stdin_stdout"
},
{
"input": "70181875975239647 504898544415017211\n",
"output": "79176 79176",
"type": "stdin_stdout"
},
{
"input": "364505998666117889 208660487087853057\n",
"output": "83777 83777",
"type": "stdin_stdout"
},
{
"input": "648371335753080490 787441\n",
"output": "228932 228932",
"type": "stdin_stdout"
},
{
"input": "841928147887146057 620004\n",
"output": "151333 51640",
"type": "stdin_stdout"
},
{
"input": "545838312215845682 715670\n",
"output": "156176 156176",
"type": "stdin_stdout"
},
{
"input": "473120513399321115 489435\n",
"output": "57896 535051",
"type": "stdin_stdout"
},
{
"input": "17922687587622540 3728\n",
"output": "478998 792943",
"type": "stdin_stdout"
},
{
"input": "211479504016655403 861717213151744108\n",
"output": "196797 196797",
"type": "stdin_stdout"
},
{
"input": "718716873663426516 872259572564867078\n",
"output": "401470 401470",
"type": "stdin_stdout"
},
{
"input": "422627037992126141 41909917823420958\n",
"output": "268735 268735",
"type": "stdin_stdout"
},
{
"input": "616183854421159004 962643186273781485\n",
"output": "149006 149006",
"type": "stdin_stdout"
},
{
"input": "160986032904427725 153429\n",
"output": "100374 100374",
"type": "stdin_stdout"
},
{
"input": "88268234087903158 290389\n",
"output": "566668 88331",
"type": "stdin_stdout"
},
{
"input": "58453009367192916 164246\n",
"output": "317900 341568",
"type": "stdin_stdout"
},
{
"input": "565690379013964030 914981\n",
"output": "547343 547343",
"type": "stdin_stdout"
},
{
"input": "269600543342663655 10645\n",
"output": "913809 282202",
"type": "stdin_stdout"
},
{
"input": "37774758680708184 156713778825283978\n",
"output": "73122 73122",
"type": "stdin_stdout"
},
{
"input": "231331570814773750 77447051570611803\n",
"output": "578654 578654",
"type": "stdin_stdout"
},
{
"input": "935241735143473375 247097392534198386\n",
"output": "181888 181888",
"type": "stdin_stdout"
},
{
"input": "639151895177205704 416747737792752265\n",
"output": "135045 135045",
"type": "stdin_stdout"
},
{
"input": "412663884364501543 401745061547424998\n",
"output": "228503 228503",
"type": "stdin_stdout"
},
{
"input": "180838095407578776 715935\n",
"output": "378695 378695",
"type": "stdin_stdout"
},
{
"input": "884748259736278401 407112\n",
"output": "25714 811489",
"type": "stdin_stdout"
},
{
"input": "78305076165311264 280970\n",
"output": "293282 624669",
"type": "stdin_stdout"
},
{
"input": "782215240494010889 417929\n",
"output": "665887 270857",
"type": "stdin_stdout"
},
{
"input": "486125404822710514 109107\n",
"output": "832669 164722",
"type": "stdin_stdout"
},
{
"input": "57626821183859235 372443612949184377\n",
"output": "802451 802451",
"type": "stdin_stdout"
},
{
"input": "27811605053083586 516548918254320722\n",
"output": "894732 894732",
"type": "stdin_stdout"
},
{
"input": "955093801941591723 462827230953066080\n",
"output": "999170 999170",
"type": "stdin_stdout"
},
{
"input": "659003966270291348 426245\n",
"output": "795318 278062",
"type": "stdin_stdout"
},
{
"input": "852560778404356914 258808\n",
"output": "775128 775128",
"type": "stdin_stdout"
},
{
"input": "397362961182592931 814397\n",
"output": "155345 155345",
"type": "stdin_stdout"
},
{
"input": "904600330829364045 969618\n",
"output": "245893 245893",
"type": "stdin_stdout"
},
{
"input": "98157142963429612 169605644318211774\n",
"output": "409023 409023",
"type": "stdin_stdout"
},
{
"input": "802067302997161941 115883952721989836\n",
"output": "928705 928705",
"type": "stdin_stdout"
},
{
"input": "505977467325861565 285534302275511011\n",
"output": "782797 782797",
"type": "stdin_stdout"
},
{
"input": "274151686958873391 747281437213482980\n",
"output": "977029 977029",
"type": "stdin_stdout"
},
{
"input": "467708499092938957 59762\n",
"output": "283212 204310",
"type": "stdin_stdout"
},
{
"input": "751573831884934263 851791\n",
"output": "905743 905743",
"type": "stdin_stdout"
},
{
"input": "455483991918666592 947456\n",
"output": "570626 570626",
"type": "stdin_stdout"
},
{
"input": "649040812642666750 821314\n",
"output": "57323 57323",
"type": "stdin_stdout"
},
{
"input": "417215023685743983 376900\n",
"output": "122689 122689",
"type": "stdin_stdout"
},
{
"input": "121125188014443608 400338158982406735\n",
"output": "199488 199488",
"type": "stdin_stdout"
},
{
"input": "314682004443476471 544443468582510377\n",
"output": "279665 279665",
"type": "stdin_stdout"
},
{
"input": "821919374090247584 554985827995633347\n",
"output": "854880 854880",
"type": "stdin_stdout"
},
{
"input": "525829538418947209 501264136399411409\n",
"output": "715564 715564",
"type": "stdin_stdout"
},
{
"input": "426597183791521709 928925\n",
"output": "835709 835709",
"type": "stdin_stdout"
},
{
"input": "620154000220554572 802783\n",
"output": "163153 163153",
"type": "stdin_stdout"
},
{
"input": "324064160254286900 898448\n",
"output": "18338 18338",
"type": "stdin_stdout"
},
{
"input": "831301534196025310 690475\n",
"output": "964028 964028",
"type": "stdin_stdout"
},
{
"input": "24858346330090877 523038\n",
"output": "5846 5846",
"type": "stdin_stdout"
},
{
"input": "569660524813359598 814752357830129986\n",
"output": "780635 780635",
"type": "stdin_stdout"
},
{
"input": "496942725996835031 761030666233908048\n",
"output": "746587 746587",
"type": "stdin_stdout"
},
{
"input": "467127505571092085 905135971539044394\n",
"output": "608084 608084",
"type": "stdin_stdout"
},
{
"input": "394409702459600222 851414284237789752\n",
"output": "419420 419420",
"type": "stdin_stdout"
},
{
"input": "703820075205013062 862025309890418636\n",
"output": "982260 982260",
"type": "stdin_stdout"
},
{
"input": "471994290543057591 972026\n",
"output": "215668 215668",
"type": "stdin_stdout"
},
{
"input": "665551106972090453 845883\n",
"output": "623684 623684",
"type": "stdin_stdout"
},
{
"input": "369461267005822782 537061\n",
"output": "97003 97003",
"type": "stdin_stdout"
},
{
"input": "73371431334522407 674020\n",
"output": "899111 372106",
"type": "stdin_stdout"
},
{
"input": "266928247763555270 547878\n",
"output": "817352 54712",
"type": "stdin_stdout"
},
{
"input": "615057631564895479 807178821338760482\n",
"output": "52078 52078",
"type": "stdin_stdout"
},
{
"input": "318967795893595104 976829166597314361\n",
"output": "750015 750015",
"type": "stdin_stdout"
},
{
"input": "512524612322627967 897562435047674890\n",
"output": "614855 614855",
"type": "stdin_stdout"
},
{
"input": "216434772356360296 67212780306228770\n",
"output": "995572 995572",
"type": "stdin_stdout"
},
{
"input": "13491088710006829 715337619732144903\n",
"output": "719453 719453",
"type": "stdin_stdout"
},
{
"input": "688519152023104450 70486\n",
"output": "476402 371144",
"type": "stdin_stdout"
},
{
"input": "685403173770208801 962607\n",
"output": "135409 135409",
"type": "stdin_stdout"
},
{
"input": "389313338098908426 99564\n",
"output": "205907 386429",
"type": "stdin_stdout"
},
{
"input": "93223502427608051 790744\n",
"output": "983387 983387",
"type": "stdin_stdout"
},
{
"input": "286780314561673617 664601\n",
"output": "654850 654850",
"type": "stdin_stdout"
},
{
"input": "831582488749975043 182016637013124494\n",
"output": "159828 159828",
"type": "stdin_stdout"
},
{
"input": "758864689933450475 128294949711869852\n",
"output": "37325 37325",
"type": "stdin_stdout"
},
{
"input": "532376674825779019 113292273466542585\n",
"output": "36122 36122",
"type": "stdin_stdout"
},
{
"input": "236286839154478644 282942618725096464\n",
"output": "187677 187677",
"type": "stdin_stdout"
},
{
"input": "940197003483178269 77403\n",
"output": "119089 181418",
"type": "stdin_stdout"
},
{
"input": "708371214526255502 632992\n",
"output": "615316 615316",
"type": "stdin_stdout"
},
{
"input": "901928035250255660 465555\n",
"output": "586380 781987",
"type": "stdin_stdout"
},
{
"input": "605838195283987989 198026\n",
"output": "929969 156402",
"type": "stdin_stdout"
},
{
"input": "15266076338626979 913942576088954168\n",
"output": "506165 506165",
"type": "stdin_stdout"
},
{
"input": "83260344505016157 935999340494020219\n",
"output": "138293 138293",
"type": "stdin_stdout"
},
{
"input": "851434559843060686 397746475431992189\n",
"output": "314138 314138",
"type": "stdin_stdout"
},
{
"input": "555344724171760311 567396824985513364\n",
"output": "666610 666610",
"type": "stdin_stdout"
},
{
"input": "748901536305825878 347728\n",
"output": "80599 80599",
"type": "stdin_stdout"
},
{
"input": "452811696339558207 443394\n",
"output": "474530 348263",
"type": "stdin_stdout"
},
{
"input": "960049070281296616 235421\n",
"output": "274784 325200",
"type": "stdin_stdout"
},
{
"input": "728223285619341145 791009\n",
"output": "764528 274644",
"type": "stdin_stdout"
},
{
"input": "698408060898630904 50803201495883240\n",
"output": "750308 750308",
"type": "stdin_stdout"
},
{
"input": "625690262082106337 220453546754437119\n",
"output": "741435 741435",
"type": "stdin_stdout"
},
{
"input": "329600422115838666 166731855158215181\n",
"output": "242921 242921",
"type": "stdin_stdout"
},
{
"input": "523157242839838824 310837164758318823\n",
"output": "726051 726051",
"type": "stdin_stdout"
},
{
"input": "871286622346211738 836848346410668404\n",
"output": "530710 530710",
"type": "stdin_stdout"
},
{
"input": "575196786674911363 36374\n",
"output": "88076 806040",
"type": "stdin_stdout"
},
{
"input": "768753603103944226 868940\n",
"output": "118118 118118",
"type": "stdin_stdout"
},
{
"input": "472663767432643850 601411\n",
"output": "203104 203104",
"type": "stdin_stdout"
},
{
"input": "176573931761343475 697077\n",
"output": "389281 749563",
"type": "stdin_stdout"
},
{
"input": "301399940652446487 937011639371661304\n",
"output": "165989 165989",
"type": "stdin_stdout"
},
{
"input": "494956757081479349 760223\n",
"output": "586955 423513",
"type": "stdin_stdout"
},
{
"input": "198866921410178974 492694\n",
"output": "847137 847137",
"type": "stdin_stdout"
},
{
"input": "902777085738878599 348432\n",
"output": "396798 564327",
"type": "stdin_stdout"
},
{
"input": "96333897872944166 462217\n",
"output": "367832 367832",
"type": "stdin_stdout"
},
{
"input": "864508113210988695 17803\n",
"output": "107443 838933",
"type": "stdin_stdout"
},
{
"input": "371745482857759808 590068361140585059\n",
"output": "748215 748215",
"type": "stdin_stdout"
},
{
"input": "341930258137049567 734173670740688701\n",
"output": "21530 21530",
"type": "stdin_stdout"
},
{
"input": "269212459320525000 680451979144466763\n",
"output": "868951 868951",
"type": "stdin_stdout"
},
{
"input": "973122623649224625 850102328697987938\n",
"output": "781676 781676",
"type": "stdin_stdout"
},
{
"input": "517924802132493346 67413\n",
"output": "954073 995488",
"type": "stdin_stdout"
},
{
"input": "711481618561526208 858685\n",
"output": "929035 929035",
"type": "stdin_stdout"
},
{
"input": "218718983913330026 55198\n",
"output": "99469 89622",
"type": "stdin_stdout"
},
{
"input": "922629148242029651 787671\n",
"output": "164442 164442",
"type": "stdin_stdout"
},
{
"input": "116185964671062513 620234\n",
"output": "798435 622171",
"type": "stdin_stdout"
},
{
"input": "884360180009107043 795255840146329784\n",
"output": "541758 541758",
"type": "stdin_stdout"
},
{
"input": "588270344337806667 964906185404883662\n",
"output": "544853 544853",
"type": "stdin_stdout"
},
{
"input": "781827160766839530 885639453855244191\n",
"output": "627074 627074",
"type": "stdin_stdout"
},
{
"input": "91237529217285074 672878442653097259\n",
"output": "988072 988072",
"type": "stdin_stdout"
},
{
"input": "859411744555329603 932262\n",
"output": "859175 859175",
"type": "stdin_stdout"
},
{
"input": "563321908884029228 664734\n",
"output": "883734 883734",
"type": "stdin_stdout"
},
{
"input": "756878725313062090 497297\n",
"output": "641345 641345",
"type": "stdin_stdout"
},
{
"input": "460788885346794419 634257\n",
"output": "660266 660266",
"type": "stdin_stdout"
},
{
"input": "164699049675494044 325434\n",
"output": "170498 994561",
"type": "stdin_stdout"
},
{
"input": "500001 1000002\n",
"output": "998979 999491",
"type": "stdin_stdout"
},
{
"input": "1000003 1000002\n",
"output": "256 256",
"type": "stdin_stdout"
},
{
"input": "1000002 1000003\n",
"output": "256 256",
"type": "stdin_stdout"
},
{
"input": "1000002 1000003\n",
"output": "256 256",
"type": "stdin_stdout"
},
{
"input": "1000002 1000002\n",
"output": "512 512",
"type": "stdin_stdout"
},
{
"input": "500001 1000003\n",
"output": "256 256",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/711/E"
} | vfc_9878 |
apps | verifiable_code | 32 | Solve the following coding problem using the programming language python:
In this problem we assume the Earth to be a completely round ball and its surface a perfect sphere. The length of the equator and any meridian is considered to be exactly 40 000 kilometers. Thus, travelling from North Pole to South Pole or vice versa takes exactly 20 000 kilometers.
Limak, a polar bear, lives on the North Pole. Close to the New Year, he helps somebody with delivering packages all around the world. Instead of coordinates of places to visit, Limak got a description how he should move, assuming that he starts from the North Pole. The description consists of n parts. In the i-th part of his journey, Limak should move t_{i} kilometers in the direction represented by a string dir_{i} that is one of: "North", "South", "West", "East".
Limak isn’t sure whether the description is valid. You must help him to check the following conditions: If at any moment of time (before any of the instructions or while performing one of them) Limak is on the North Pole, he can move only to the South. If at any moment of time (before any of the instructions or while performing one of them) Limak is on the South Pole, he can move only to the North. The journey must end on the North Pole.
Check if the above conditions are satisfied and print "YES" or "NO" on a single line.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 50).
The i-th of next n lines contains an integer t_{i} and a string dir_{i} (1 ≤ t_{i} ≤ 10^6, $\operatorname{dir}_{i} \in \{\text{North, South, West, East} \}$) — the length and the direction of the i-th part of the journey, according to the description Limak got.
-----Output-----
Print "YES" if the description satisfies the three conditions, otherwise print "NO", both without the quotes.
-----Examples-----
Input
5
7500 South
10000 East
3500 North
4444 West
4000 North
Output
YES
Input
2
15000 South
4000 East
Output
NO
Input
5
20000 South
1000 North
1000000 West
9000 North
10000 North
Output
YES
Input
3
20000 South
10 East
20000 North
Output
NO
Input
2
1000 North
1000 South
Output
NO
Input
4
50 South
50 North
15000 South
15000 North
Output
YES
-----Note-----
Drawings below show how Limak's journey would look like in first two samples. In the second sample the answer is "NO" because he doesn't end on the North Pole. [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
"""
Codeforces Good Bye 2016 Contest Problem B
Author : chaotic_iak
Language: Python 3.5.2
"""
################################################### SOLUTION
def main():
latitude = 0
n, = read()
for i in range(n):
l, d = read(str)
l = int(l)
if latitude == 0:
if d != "South":
return "NO"
if latitude == 20000:
if d != "North":
return "NO"
if d == "South":
latitude += l
elif d == "North":
latitude -= l
if not (0 <= latitude <= 20000):
return "NO"
if latitude != 0:
return "NO"
return "YES"
#################################################### HELPERS
def read(callback=int):
return list(map(callback, input().strip().split()))
def write(value, end="\n"):
if value is None: return
try:
if not isinstance(value, str):
value = " ".join(map(str, value))
except:
pass
print(value, end=end)
write(main())
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n7500 South\n10000 East\n3500 North\n4444 West\n4000 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n15000 South\n4000 East\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n20000 South\n1000 North\n1000000 West\n9000 North\n10000 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n20000 South\n10 East\n20000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n1000 North\n1000 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n50 South\n50 North\n15000 South\n15000 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 East\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n1000000 South\n1000000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n149 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n16277 East\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n19701 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3125 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n6549 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2677 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n6101 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n9525 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n5653 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n15072 South\n15072 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n11200 South\n11200 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n14624 South\n14624 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n18048 South\n15452 West\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n1472 West\n4930 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n17600 South\n17600 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n8320 East\n16589 East\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n4448 South\n4448 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n576 South\n576 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n14186 South\n2291 West\n14186 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n10314 South\n15961 North\n5647 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n1035 East\n18143 South\n18143 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n17163 South\n7620 East\n17163 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n587 South\n17098 North\n16511 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n16715 North\n6576 West\n12132 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n7435 South\n245 North\n7190 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n3563 South\n2427 South\n5990 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n6987 South\n11904 East\n19951 East\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n13301 South\n5948 East\n9265 East\n6891 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n16725 South\n8129 South\n19530 West\n24854 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n149 South\n17607 West\n18306 South\n18455 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n16277 South\n19789 North\n4379 South\n867 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n19701 South\n13458 South\n3156 North\n30003 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n3125 South\n15640 East\n6125 East\n19535 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n6549 East\n5118 North\n12198 East\n5118 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n2677 East\n1891 West\n10974 West\n7511 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n6102 South\n8265 East\n13943 South\n20045 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n12416 South\n18116 North\n10553 West\n18435 West\n5700 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n15840 South\n7594 South\n13522 South\n2423 South\n3334 West\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n19264 East\n13968 East\n19595 North\n19115 North\n38710 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n15392 South\n3445 North\n18372 East\n10399 North\n4403 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n18816 South\n5627 West\n14045 East\n7091 East\n18816 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n2240 South\n15104 North\n118 West\n11079 East\n12864 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n5664 South\n1478 South\n18894 South\n2363 West\n26036 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n1792 South\n10956 East\n9159 South\n19055 West\n10951 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n12512 South\n13137 North\n7936 North\n7235 South\n1326 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n14635 North\n14477 South\n17250 North\n14170 East\n15166 South\n2242 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n10763 North\n3954 West\n7515 North\n18158 West\n6644 South\n11634 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n14187 South\n13432 North\n6292 East\n14850 West\n10827 South\n9639 East\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n10315 South\n15614 South\n5069 West\n6134 South\n7713 North\n24350 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n1035 South\n9283 East\n15333 South\n2826 South\n19191 North\n3 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n17163 West\n11465 North\n14110 South\n6814 North\n3373 East\n4169 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n587 South\n942 West\n183 North\n18098 North\n260 East\n17694 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n16715 West\n3124 East\n3152 East\n14790 East\n11738 West\n11461 East\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n7435 South\n12602 South\n1929 East\n6074 East\n15920 West\n20037 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n13750 South\n6645 South\n18539 East\n5713 North\n1580 North\n10012 West\n13102 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n9878 West\n8827 East\n1508 West\n9702 North\n5763 North\n9755 North\n10034 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n13302 West\n2496 North\n284 West\n6394 East\n9945 North\n12603 West\n12275 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n16726 East\n19270 West\n6357 South\n17678 East\n14127 East\n12347 South\n6005 East\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n150 South\n1452 North\n9326 North\n1666 West\n18309 East\n19386 East\n8246 West\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n16278 South\n10929 South\n8103 East\n18358 West\n2492 West\n11834 South\n39041 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n19702 South\n13111 East\n6880 East\n9642 South\n6674 West\n18874 East\n1112 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n3126 South\n6780 North\n9848 West\n6334 North\n10856 West\n14425 West\n10649 East\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n6550 South\n8962 West\n15921 South\n17618 North\n15038 South\n1465 North\n18426 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n12864 South\n3005 West\n16723 West\n17257 West\n12187 East\n12976 South\n1598 North\n24242 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n8992 South\n12483 North\n15500 South\n1245 South\n9073 East\n12719 East\n3839 East\n7130 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n12416 North\n14665 South\n14277 North\n2129 South\n13255 East\n19759 South\n10272 West\n9860 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n15840 South\n4142 East\n17246 North\n13413 North\n4733 West\n15311 North\n12514 South\n17616 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n19264 South\n10516 North\n3319 East\n17401 East\n1620 West\n2350 West\n6243 North\n2505 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8\n15392 South\n7290 West\n2096 West\n14093 East\n5802 South\n2094 North\n8484 East\n19100 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n6113 South\n16767 East\n5064 South\n5377 West\n17280 South\n1838 West\n2213 West\n28457 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n2241 West\n18949 South\n11137 South\n2069 West\n14166 South\n1581 South\n4455 South\n50288 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n5665 South\n8426 East\n9914 North\n13353 South\n18349 North\n4429 East\n18184 North\n27429 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n11979 South\n2470 East\n10716 North\n12992 East\n15497 West\n15940 North\n8107 West\n18934 East\n6993 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n8107 South\n4652 North\n9493 North\n16980 West\n12383 West\n2980 West\n17644 South\n11043 West\n11447 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n18827 South\n18321 West\n8270 East\n968 West\n16565 West\n15427 North\n4077 North\n18960 North\n19006 West\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n14955 West\n503 North\n18535 West\n4956 South\n8044 South\n2467 East\n13615 East\n6877 East\n3460 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n18379 South\n9980 South\n17311 West\n8944 South\n4930 South\n18019 South\n48 West\n14794 South\n75046 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n14507 East\n12162 East\n16088 South\n5636 North\n9112 North\n5058 East\n9585 South\n2712 East\n10925 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n5227 East\n8936 North\n6353 North\n16920 North\n591 North\n4802 South\n8722 North\n3333 West\n36720 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n1355 North\n15309 West\n17834 North\n13612 East\n17477 North\n4546 North\n18260 East\n15442 North\n56654 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n4779 South\n4787 East\n3907 East\n4896 East\n1659 East\n4289 West\n4693 West\n3359 East\n4779 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n80000 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n40000 South\n20000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n40000 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n20001 South\n20001 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n10000 South\n20000 South\n10000 North\n20000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n10 South\n20 North\n10 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n1000 South\n1001 North\n1 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n20000 South\n20000 West\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n10000 South\n20000 South\n10000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 East\n1 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n20000 West\n20000 West\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n80000 South\n20000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n19999 South\n20001 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n500 South\n1000 North\n500 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n400000 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n40000 South\n80000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n100 West\n100 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n40000 South\n40000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n30000 South\n10000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n20000 South\n40000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10\n20000 South\n20000 North\n20000 South\n20000 North\n20000 South\n20000 North\n20000 South\n20000 North\n20000 South\n20000 North\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n40001 South\n40001 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n40001 South\n1 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n50000 South\n50000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n30000 South\n30000 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n10000 South\n50000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n15000 South\n15000 South\n15000 North\n15000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n50 South\n100 North\n50 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n20001 South\n1 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 South\n6 North\n1 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n20000 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 South\n20000 South\n1 North\n20000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n30000 South\n30000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 South\n2 North\n1 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n60000 South\n60000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n50000 South\n10000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n20010 South\n19990 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n20000 South\n1 South\n20000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 South\n2 North\n39999 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n10 South\n20 North\n10 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 South\n2 North\n1 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n2000 South\n19000 South\n19000 South\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n15000 South\n15000 South\n15000 South\n15000 North\n15000 North\n15000 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 South\n1 North\n1 East\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 West\n1 North\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 South\n123456 West\n1 North\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/750/B"
} | vfc_9882 |
apps | verifiable_code | 33 | Solve the following coding problem using the programming language python:
You are given two arithmetic progressions: a_1k + b_1 and a_2l + b_2. Find the number of integers x such that L ≤ x ≤ R and x = a_1k' + b_1 = a_2l' + b_2, for some integers k', l' ≥ 0.
-----Input-----
The only line contains six integers a_1, b_1, a_2, b_2, L, R (0 < a_1, a_2 ≤ 2·10^9, - 2·10^9 ≤ b_1, b_2, L, R ≤ 2·10^9, L ≤ R).
-----Output-----
Print the desired number of integers x.
-----Examples-----
Input
2 0 3 3 5 21
Output
3
Input
2 4 3 0 6 17
Output
2
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys, collections
def gcd(a, b):
if b == 0: return a
return gcd(b, a % b)
def lcm(a, b):
return a // gcd(a, b) * b
def extgcd(a, b):
if b == 0: return 1, 0
x, y = extgcd(b, a % b)
return y, x - a // b * y
def prime_factor(n):
res = collections.defaultdict(int)
i = 2
while i * i <= n:
cnt = 0
while n % i == 0:
n //= i
cnt += 1
if cnt > 0: res[i] = cnt
i += 1
if n != 1: res[n] = 1
return res
def modinv(a, mod):
if a == 0: return -1
if gcd(a, mod) != 1: return -1
return extgcd(a, mod)[0] % mod
def normalize(a1, a2):
p1 = prime_factor(a1)
p2 = prime_factor(a2)
keys = list(set(p1.keys()) | set(p2.keys()))
r1 = 1
r2 = 1
for k in keys:
if p1[k] >= p2[k]:
r1 *= k ** p1[k]
else:
r2 *= k ** p2[k]
return r1, r2
def solve(a1, b1, a2, b2):
g = gcd(a1, a2)
if (b1 - b2) % g != 0: return -1
a1, a2 = normalize(a1, a2)
u = b1 % a1
inv = modinv(a1, a2)
v = (b2 - u) * inv % a2
return u + v * a1
def f(x0, T, v):
ok = 10 ** 36
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2
if x0 + T * mid >= v:
ok = mid
else:
ng = mid
return ok
a1, b1, a2, b2, L, R = map(int, input().split())
T = lcm(a1, a2)
x0 = solve(a1, b1, a2, b2)
if x0 == -1:
print(0)
return
x0 -= T * 10 ** 36
ok = 10 ** 60
ng = -1
while ok - ng > 1:
mid = (ok + ng) // 2
val = x0 + T * mid
k = (val - b1) // a1
l = (val - b2) // a2
if k >= 0 and l >= 0:
ok = mid
else:
ng = mid
x0 += ok * T
# L <= x0 + kT < R + 1
ans = f(x0, T, R + 1) - f(x0, T, L)
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "2 0 3 3 5 21\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 4 3 0 6 17\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 0 4 2 -39 -37\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 9 3 11 49 109\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "3 81 5 72 -1761 501\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "8 -89 20 67 8771 35222\n",
"output": "661\n",
"type": "stdin_stdout"
},
{
"input": "1 -221 894 86403 -687111 141371\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "1 -1074 271 17741 -2062230 1866217\n",
"output": "6821\n",
"type": "stdin_stdout"
},
{
"input": "3 2408 819 119198 -8585197 7878219\n",
"output": "9474\n",
"type": "stdin_stdout"
},
{
"input": "1 341 8581 3946733 -59420141 33253737\n",
"output": "3416\n",
"type": "stdin_stdout"
},
{
"input": "1 10497 19135 2995296 -301164547 -180830773\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8 40306 2753 1809818 254464419 340812028\n",
"output": "3921\n",
"type": "stdin_stdout"
},
{
"input": "2 21697 9076 1042855 -319348358 236269755\n",
"output": "25918\n",
"type": "stdin_stdout"
},
{
"input": "4 2963 394 577593 125523962 628140505\n",
"output": "637839\n",
"type": "stdin_stdout"
},
{
"input": "75 61736 200 200511 160330870 609945842\n",
"output": "749358\n",
"type": "stdin_stdout"
},
{
"input": "34 64314 836 5976 591751179 605203191\n",
"output": "946\n",
"type": "stdin_stdout"
},
{
"input": "1 30929 25249 95822203 -1076436442 705164517\n",
"output": "24134\n",
"type": "stdin_stdout"
},
{
"input": "3 -1208 459 933808 603490653 734283665\n",
"output": "284952\n",
"type": "stdin_stdout"
},
{
"input": "1 35769 16801 47397023 -82531776 1860450454\n",
"output": "107914\n",
"type": "stdin_stdout"
},
{
"input": "1 -3078 36929 51253687 -754589746 -53412627\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 -32720 3649 7805027 408032642 925337350\n",
"output": "141766\n",
"type": "stdin_stdout"
},
{
"input": "1 -2000000000 1 -2000000000 -2000000000 2000000000\n",
"output": "4000000001\n",
"type": "stdin_stdout"
},
{
"input": "1 -2000000000 2 -2000000000 -2000000000 2000000000\n",
"output": "2000000001\n",
"type": "stdin_stdout"
},
{
"input": "3 -2000000000 2 -2000000000 -2000000000 2000000000\n",
"output": "666666667\n",
"type": "stdin_stdout"
},
{
"input": "999999999 999999998 1000000000 999999999 1 10000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 -2000000000 1 2000000000 1 10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 -2000000000 2 2000000000 -2000000000 2000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 0 2 1 0 1000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 0 1 0 0 2000000000\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 0 4 1 5 100\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 999999999 0 1 100000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 30929 1 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1 1 -2000000000 2000000000\n",
"output": "2000000000\n",
"type": "stdin_stdout"
},
{
"input": "4 0 4 1 0 100\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 -2000000000 1 2000000000 5 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "51 -1981067352 71 -414801558 -737219217 1160601982\n",
"output": "435075\n",
"type": "stdin_stdout"
},
{
"input": "2 -1500000000 4 -1499999999 1600000000 1700000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "135 -1526277729 32 1308747737 895574 1593602399\n",
"output": "65938\n",
"type": "stdin_stdout"
},
{
"input": "1098197640 6 994625382 6 -474895292 -101082478\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "12 -696575903 571708420 236073275 2 14\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 -9 2 -10 -10 -9\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 -11 2 -9 -11 -9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "40 54 15 74 -180834723 1373530127\n",
"output": "11446084\n",
"type": "stdin_stdout"
},
{
"input": "2 57 1 56 -1773410854 414679043\n",
"output": "207339494\n",
"type": "stdin_stdout"
},
{
"input": "9 12 1 40 624782492 883541397\n",
"output": "28750990\n",
"type": "stdin_stdout"
},
{
"input": "4 -1000000000 2 4 100 1000\n",
"output": "226\n",
"type": "stdin_stdout"
},
{
"input": "66 90 48 84 -1709970247 1229724777\n",
"output": "2329024\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 2000000000 0 -2000000000 200000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 0 2 1 -1000000000 1000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 -1000000000 2 -999999999 -1000000000 1000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "26 1885082760 30 -1612707510 -1113844607 1168679422\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "76 -19386 86 -6257 164862270 1443198941\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 -2000000000 5 1000000000 1000000000 2000000000\n",
"output": "200000001\n",
"type": "stdin_stdout"
},
{
"input": "505086589 -4 1288924334 -4 -5 -4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "91 -193581878 2 1698062870 -819102473 1893630769\n",
"output": "1074549\n",
"type": "stdin_stdout"
},
{
"input": "8 11047 45 12730 -45077355 1727233357\n",
"output": "4797835\n",
"type": "stdin_stdout"
},
{
"input": "35 8673 6 -19687 -111709844 1321584980\n",
"output": "6293220\n",
"type": "stdin_stdout"
},
{
"input": "71 1212885043 55 1502412287 970234397 1952605611\n",
"output": "115287\n",
"type": "stdin_stdout"
},
{
"input": "274497829 -12 9 -445460655 -5 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1509527550 3 7 -134101853 2 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "43 -1478944506 45 494850401 634267177 1723176461\n",
"output": "562743\n",
"type": "stdin_stdout"
},
{
"input": "25 479638866 50 -874479027 -2000000000 2000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "11 -10 1 -878946597 -11127643 271407906\n",
"output": "24673447\n",
"type": "stdin_stdout"
},
{
"input": "15 -738862158 12 -3 -3 12\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "70 -835526513 23 687193329 -1461506792 1969698938\n",
"output": "796587\n",
"type": "stdin_stdout"
},
{
"input": "124 1413 15321 312133 3424 1443242\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "75 -13580 14 4508 -67634192 1808916097\n",
"output": "1722773\n",
"type": "stdin_stdout"
},
{
"input": "915583842 -15 991339476 -12 -15 -5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "85 -18257 47 -7345 -76967244 1349252598\n",
"output": "337737\n",
"type": "stdin_stdout"
},
{
"input": "178 331734603 162 -73813367 -577552570 1005832995\n",
"output": "46754\n",
"type": "stdin_stdout"
},
{
"input": "8 -17768 34 963 -2000000000 2000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "26 1885082760 30 -1612707510 -2000000000 2000000000\n",
"output": "294660\n",
"type": "stdin_stdout"
},
{
"input": "4 -1999999999 6 -1999999998 -999999999 1999999999\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "121826 1323 1327 304172 -1521910750 860413213\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "36281 170 1917 927519 -1767064448 -177975414\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "37189 -436 464 797102 -1433652908 1847752465\n",
"output": "107\n",
"type": "stdin_stdout"
},
{
"input": "81427 -688 1720 -221771 -77602716 1593447723\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "11 -1609620737 1315657088 -7 -162162918 287749240\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1480269313 -1048624081 1314841531 -8 295288505 358226461\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "13 -15 19 -2 -334847526 1334632952\n",
"output": "5403373\n",
"type": "stdin_stdout"
},
{
"input": "1254161381 -7 821244830 -7 -698761303 941496965\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1269100557 -5 6 -5 -12 -6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "847666888 -6 1327933031 -6 -5 -2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1465846675 1002489474 9 -1250811979 1030017372 1391560043\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8 -1915865359 867648990 9 -5 -4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 -1164702220 906446587 -1868913852 222249893 1493113759\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 -8 17 3 -393290856 231975525\n",
"output": "909708\n",
"type": "stdin_stdout"
},
{
"input": "734963978 0 17 0 -12 -5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1090004357 5 1124063714 -840327001 -448110704 128367602\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "18 -1071025614 1096150070 0 -6 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "451525105 -8 1256335024 -8 -718788747 928640626\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 3 5 -1292190012 -97547955 250011754\n",
"output": "12500588\n",
"type": "stdin_stdout"
},
{
"input": "14 -7 14 -1488383431 -1044342357 842171605\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1384140089 5 16 -1661922737 442287491 1568124284\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "16 -11 14 -1466771835 -1192555694 -2257860\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1676164235 -1589020998 1924931103 1189158232 6 12\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 16 12 -5 11 23\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "16 -16 5 20 -9 7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 -9 1 -2 -13 -1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "18 -17 9 -17 -29 17\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "735463638 620656007 878587644 536507630 -1556948056 1714374073\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1789433851 -633540112 1286318222 -1728151682 1438333624 1538194890\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 -1264610276 1157160166 -336457087 -496892962 759120142\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "831644204 422087925 17 -1288230412 -1090082747 1271113499\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "17 -13 223959272 -1081245422 -1756575771 38924201\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1228969457 -1826233120 11 -1063855654 -819177202 1039858319\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1186536442 -1691684240 17 -1 -702600351 1121394816\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1132421757 -1481846636 515765656 -12 -622203577 552143596\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "18 -1123473160 1826212361 -10 -12 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1197045662 7 15 -1445473718 -1406137199 800415943\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "18 565032929 13 735553852 107748471 1945959489\n",
"output": "5172673\n",
"type": "stdin_stdout"
},
{
"input": "1734271904 1 19 -1826828681 0 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1614979757 -1237127436 12 75067457 -933537920 451911806\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8 -335942902 1179386720 -723257398 -13 -12\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "989432982 2 9 366779468 -1427636085 985664909\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "7 -1390956935 1404528667 -4 -15 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1370475975 841789607 733784598 467967887 -7 15\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6 -7 9 -1 -10 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "960716652 1417038753 1222139305 -4 -1570098546 -931528535\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1744394473 5 1523286739 629247513 -6 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2627 -4960 2627 -4960 -4960 4960\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6 -364562196 7 -803430276 0 11\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1955378240 -837482305 1743607821 -1623988108 -653286850 178227154\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "9 -1642366642 1499382371 -6 -822052389 1405478033\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "9 -1 8 -1 -711474975 237571596\n",
"output": "3299606\n",
"type": "stdin_stdout"
},
{
"input": "1497677869 -1313800455 11 12 -1157529918 1754001465\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "11 -80049925 1600186381 -1454831688 -1384227392 1621203975\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1042015302 -56794440 1727095321 -1037110962 -9 11\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "13 0 1419591662 -1360930956 343359607 1283114457\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "752411560 -6 857048450 -405514986 -5 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "12 2 18 2 -6 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "11 -1 15 -1 -13 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1446642133 -7 9 -1719422944 -916435667 36154654\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1689390799 501112014 13 -1621132473 398367938 709483101\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1932547151 -725726769 782679113 -10 -184530763 498112212\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/710/D"
} | vfc_9886 |
apps | verifiable_code | 34 | Solve the following coding problem using the programming language python:
It's New Year's Eve soon, so Ivan decided it's high time he started setting the table. Ivan has bought two cakes and cut them into pieces: the first cake has been cut into a pieces, and the second one — into b pieces.
Ivan knows that there will be n people at the celebration (including himself), so Ivan has set n plates for the cakes. Now he is thinking about how to distribute the cakes between the plates. Ivan wants to do it in such a way that all following conditions are met: Each piece of each cake is put on some plate; Each plate contains at least one piece of cake; No plate contains pieces of both cakes.
To make his guests happy, Ivan wants to distribute the cakes in such a way that the minimum number of pieces on the plate is maximized. Formally, Ivan wants to know the maximum possible number x such that he can distribute the cakes according to the aforementioned conditions, and each plate will contain at least x pieces of cake.
Help Ivan to calculate this number x!
-----Input-----
The first line contains three integers n, a and b (1 ≤ a, b ≤ 100, 2 ≤ n ≤ a + b) — the number of plates, the number of pieces of the first cake, and the number of pieces of the second cake, respectively.
-----Output-----
Print the maximum possible number x such that Ivan can distribute the cake in such a way that each plate will contain at least x pieces of cake.
-----Examples-----
Input
5 2 3
Output
1
Input
4 7 10
Output
3
-----Note-----
In the first example there is only one way to distribute cakes to plates, all of them will have 1 cake on it.
In the second example you can have two plates with 3 and 4 pieces of the first cake and two plates both with 5 pieces of the second cake. Minimal number of pieces is 3.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, a, b = map(int, input().split())
ans = 0
for i in range(1, n):
ans = max(ans, min(a // i, b // (n - i)))
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "5 2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 7 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100 100 100\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 100 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 9 29\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "4 6 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 70 58\n",
"output": "35\n",
"type": "stdin_stdout"
},
{
"input": "5 7 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5 30 22\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5 5 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 4 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 10 31\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 98 99\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "4 10 16\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11 4 8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 10 14\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6 7 35\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5 6 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 15 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 48 77\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "4 4 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 7 20\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5 2 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "14 95 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "99 82 53\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 71 27\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "5 7 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "11 77 77\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "10 5 28\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 3 12\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 15 17\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 7 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 11 18\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 3 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9 2 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 90 20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "12 45 60\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "3 94 79\n",
"output": "47\n",
"type": "stdin_stdout"
},
{
"input": "41 67 34\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9 3 23\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 20 57\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "55 27 30\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 100 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "20 8 70\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 9 15\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 1 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 94 94\n",
"output": "94\n",
"type": "stdin_stdout"
},
{
"input": "5 3 11\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 3 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "12 12 100\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "6 75 91\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "3 4 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 2 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6 5 15\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 3 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 9 9\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "26 93 76\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "41 34 67\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6 12 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5 20 8\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 1 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "35 66 99\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "30 7 91\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5 22 30\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "8 19 71\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "3 5 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5 3 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 4 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 3 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 20 10\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 100 50\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "6 3 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 90 95\n",
"output": "90\n",
"type": "stdin_stdout"
},
{
"input": "4 8 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6 10 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 3 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 33 33\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "5 5 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "19 24 34\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5 5 12\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8 7 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 56 35\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "4 3 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "18 100 50\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "5 6 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 98 100\n",
"output": "33\n",
"type": "stdin_stdout"
},
{
"input": "6 5 8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 40 80\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "4 8 11\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "66 100 99\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "17 100 79\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "3 2 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "99 100 99\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "21 100 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 10 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 100 63\n",
"output": "33\n",
"type": "stdin_stdout"
},
{
"input": "2 2 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 94 79\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"input": "4 12 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5 5 40\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "99 99 99\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8 97 44\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "11 4 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6 3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7 3 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8 4 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9 4 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "12 6 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 48 89\n",
"output": "29\n",
"type": "stdin_stdout"
},
{
"input": "8 3 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 6 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 5 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "11 6 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 5 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6 6 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 1 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 3 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9 4 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6 5 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 5 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "13 6 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "14 7 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "12 97 13\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "4 2 9\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 20 59\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "12 34 56\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "4 5 9\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 66 41\n",
"output": "22\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/911/B"
} | vfc_9890 |
apps | verifiable_code | 35 | Solve the following coding problem using the programming language python:
The flag of Berland is such rectangular field n × m that satisfies following conditions:
Flag consists of three colors which correspond to letters 'R', 'G' and 'B'. Flag consists of three equal in width and height stripes, parralel to each other and to sides of the flag. Each stripe has exactly one color. Each color should be used in exactly one stripe.
You are given a field n × m, consisting of characters 'R', 'G' and 'B'. Output "YES" (without quotes) if this field corresponds to correct flag of Berland. Otherwise, print "NO" (without quotes).
-----Input-----
The first line contains two integer numbers n and m (1 ≤ n, m ≤ 100) — the sizes of the field.
Each of the following n lines consisting of m characters 'R', 'G' and 'B' — the description of the field.
-----Output-----
Print "YES" (without quotes) if the given field corresponds to correct flag of Berland . Otherwise, print "NO" (without quotes).
-----Examples-----
Input
6 5
RRRRR
RRRRR
BBBBB
BBBBB
GGGGG
GGGGG
Output
YES
Input
4 3
BRG
BRG
BRG
BRG
Output
YES
Input
6 7
RRRGGGG
RRRGGGG
RRRGGGG
RRRBBBB
RRRBBBB
RRRBBBB
Output
NO
Input
4 4
RRRR
RRRR
BBBB
GGGG
Output
NO
-----Note-----
The field in the third example doesn't have three parralel stripes.
Rows of the field in the fourth example are parralel to each other and to borders. But they have different heights — 2, 1 and 1.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n,m=list(map(int,input().split()))
f=[input() for _ in range(n)]
def clr(ss):
cc = None
for s in ss:
for c in s:
if cc is None:
cc = c
elif cc != c:
return None
return cc
if n%3 == 0:
s = set()
for i in range(0,n,n//3):
ret = clr(f[i:i+n//3])
if ret is None:
continue
s.add(ret)
if len(s) == 3:
print('YES')
return
if m%3 == 0:
s = set()
for j in range(0,m,m//3):
ff = []
for i in f:
ff.append(i[j:j+m//3])
ret = clr(ff)
if ret is None:
continue
s.add(ret)
if len(s) == 3:
print('YES')
return
print('NO')
``` | {
"language": "python",
"test_cases": [
{
"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nGGGGG\nGGGGG\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 3\nBRG\nBRG\nBRG\nBRG\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 7\nRRRGGGG\nRRRGGGG\nRRRGGGG\nRRRBBBB\nRRRBBBB\nRRRBBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 4\nRRRR\nRRRR\nBBBB\nGGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nGRB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 1\nR\nG\nB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 3\nRGB\nGRB\nGRB\nGRB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 6\nGGRRBB\nGGRRBB\nGGRRBB\nRRGGBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100 3\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nRGB\nGRB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 100\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 1\nR\nR\nB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 2\nRR\nBB\nRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 2\nRR\nBG\nBG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 2\nBB\nRR\nBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRRR\nRRR\nRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nGGG\nGGG\nGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nRGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 3\nRGR\nRGR\nRGR\nRGR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 4\nRRGG\nRRGG\nBBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nBRG\nBRG\nBRG\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 1\nR\nG\nR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 3\nBBG\nBBG\nBBG\nBBG\nBBG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRRR\nGGG\nRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nRGR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 6\nRRBBGG\nRRBBGG\nRRBBGG\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 6\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG\nRRBBGG\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 3\nRRR\nGGG\nBBB\nBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRRR\nBBB\nRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 1\nB\nR\nB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nBGB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 1\nB\nB\nB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 4\nRRRR\nBBBB\nRRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 6\nRGGGBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9 3\nBBB\nBBB\nBBB\nGGG\nGGG\nGRG\nRGR\nRRR\nRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 4\nRGBB\nRGBB\nRGBB\nRGBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRBR\nRBR\nRBR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 6\nRRRRBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 6\nRRRRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 6\nRRGGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 4\nRRRR\nRRRR\nRRRR\nRRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 1\nB\nG\nB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 1\nR\nR\nR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 9\nRRRGGGBBB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 5\nRRRRR\nBBBBB\nBBBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRRR\nGGG\nGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 1\nR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRGR\nRGR\nRGR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRBG\nGBR\nRGB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRGB\nRGB\nRGB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nBRB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nR\nB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nRBR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 5\nRRGBB\nRRGBB\nRRGBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 3\nBBR\nBBR\nBBR\nBBR\nBBR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRGB\nRBG\nRGB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2\nRB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 3\nBBB\nBBB\nBBB\nBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "36 6\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\nBBRRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 1\nR\nB\nG\nR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "13 12\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\nRRRRGGGGRRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nRR\nRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 6\nRRGGBB\nGRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "70 3\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\nBGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 3\nBBG\nBBG\nBBG\nBBG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 3\nBBB\nGGG\nRRR\nBRG\nBRG\nBRG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 6\nRRBBGG\nRBBBGG\nRBBBGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 6\nGGGGGG\nGGGGGG\nBBBBBB\nBBBBBB\nGGGGGG\nGGGGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 1\nR\nB\nG\nR\nB\nG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 5\nRRRRR\nBBBBB\nGGGGG\nRRRRR\nBBBBB\nGGGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 3\nRRR\nGGG\nBBB\nRRR\nGGG\nBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 5\nRRRRR\nRRRRR\nRRRRR\nGGGGG\nGGGGG\nGGGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "15 28\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nBBBBBBBBBBBBBBBBBBBBBBBBBBBB\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\nGGGGGGGGGGGGGGGGGGGGGGGGGGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "21 10\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nRRRRRRRRRR\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBGBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nBBBBBBBBBB\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\nGGGGGGGGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 2\nRR\nGB\nGB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 2\nRG\nRG\nBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 5\nRRRRR\nRRRRR\nBBBBB\nBBBBB\nRRRRR\nRRRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRGB\nGBR\nBRG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nRBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nBGR\nBGR\nBGR\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 6\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 2\nRR\nGG\nRR\nBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRRR\nRRR\nGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8 6\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 4\nRRRR\nRRRR\nGGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 4\nRRRR\nRRRR\nRRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 1\nR\nR\nR\nR\nR\nR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 6\nRRBBGG\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 6\nRGBRGB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 4\nRRRR\nGGGG\nRRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRRB\nGRG\nGBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 7\nRRGGBBB\nRRGGBBB\nRRGGBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 1\nG\nR\nR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 3\nRGG\nRBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRRG\nGGG\nBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRGB\nRBB\nRGB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRGR\nRGB\nRGB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 1\nB\nR\nR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nGRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 4\nRRRR\nGGGG\nBBBB\nBBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nGGR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRGB\nGGB\nRGB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRGR\nGGG\nBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 6\nRRRRRR\nGGGGGG\nGGGGGG\nGGGGGG\nBBBBBB\nBBBBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nGGGGGG\nBBBBBB\nBBBBBB\nBBBBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 1\nG\nB\nR\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nGGB\nRGB\nRGB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nGRR\nGGG\nBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nGGGGGG\nGGGGGG\nBBBBBB\nRRRRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRRR\nGBG\nBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 8\nRRGGBBBB\nRRGGBBBB\nRRGGBBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nRR\nGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRGB\nRGR\nRGB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nRBG\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 6\nRRGGBB\nGGRRBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 2\nRR\nGG\nBB\nRR\nGG\nBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 5\nRRGGB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2\nRG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 6\nRGBRBG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 6\nRRRGGB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nRGB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 3\nRRR\nBBR\nGBB\nGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 3\nRRR\nBBB\nBBB\nBBB\nGGG\nGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRBG\nRBG\nRBG\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 3\nRRR\nBBB\nGGG\nRRR\nBBB\nGGG\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 4\nRGBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 6\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\nRRRRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 5\nRRRRR\nRRRRR\nGGGGG\nGGGGG\nRRRRR\nRRRRR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nRGB\nBRG\nGBR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 10\nRRRRRRRRRR\nGGGGGGGGGG\nBBBBBBBBBB\nRRRRRRRRRR\nGGGGGGGGGG\nBBBBBBBBBB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "20 6\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\nRRGGBB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 1\nR\nG\nB\nR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 4\nRGBR\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 4\nRGBB\nRRGB\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/837/B"
} | vfc_9894 |
apps | verifiable_code | 36 | Solve the following coding problem using the programming language python:
Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined:
[Image] [Image] Ayrat is searching through the field. He started at point (0, 0) and is moving along the spiral (see second picture). Sometimes he forgets where he is now. Help Ayrat determine his location after n moves.
-----Input-----
The only line of the input contains integer n (0 ≤ n ≤ 10^18) — the number of Ayrat's moves.
-----Output-----
Print two integers x and y — current coordinates of Ayrat coordinates.
-----Examples-----
Input
3
Output
-2 0
Input
7
Output
3 2
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def f(n):
left, right = -1, n + 1
while right - left > 1:
mid = (left + right) // 2
x = 6 * mid * (mid + 1) // 2 + 5 * (mid + 1)
if x > n:
right = mid
else:
left = mid
if left >= 0:
mid = left
x = 6 * mid * (mid + 1) // 2 + 5 * (mid + 1)
n -= x
return (n, left + 1)
def main():
n = int(input())
n, k = f(n)
x = k
y = -2 * k
d = [k + 1] * 6
d[1] -= 1
dx = [1, -1, -2, -1, 1, 2]
dy = [2, 2, 0, -2, -2, 0]
for i in range(6):
x += min(d[i], n) * dx[i]
y += min(d[i], n) * dy[i]
n = max(0, n - d[i])
print(x, y)
main()
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n",
"output": "-2 0\n",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "39\n",
"output": "5 6\n",
"type": "stdin_stdout"
},
{
"input": "14\n",
"output": "-2 -4\n",
"type": "stdin_stdout"
},
{
"input": "94\n",
"output": "8 8\n",
"type": "stdin_stdout"
},
{
"input": "60\n",
"output": "8 0\n",
"type": "stdin_stdout"
},
{
"input": "60\n",
"output": "8 0\n",
"type": "stdin_stdout"
},
{
"input": "59\n",
"output": "7 -2\n",
"type": "stdin_stdout"
},
{
"input": "181994\n",
"output": "154 -492\n",
"type": "stdin_stdout"
},
{
"input": "486639\n",
"output": "-33 806\n",
"type": "stdin_stdout"
},
{
"input": "34514\n",
"output": "13 -214\n",
"type": "stdin_stdout"
},
{
"input": "826594\n",
"output": "-769 562\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000\n",
"output": "-418284973 -1154700538\n",
"type": "stdin_stdout"
},
{
"input": "854460\n",
"output": "414 1068\n",
"type": "stdin_stdout"
},
{
"input": "164960\n",
"output": "458 -20\n",
"type": "stdin_stdout"
},
{
"input": "618459\n",
"output": "-797 -222\n",
"type": "stdin_stdout"
},
{
"input": "496181994\n",
"output": "21108 9228\n",
"type": "stdin_stdout"
},
{
"input": "1000000000\n",
"output": "27596 -17836\n",
"type": "stdin_stdout"
},
{
"input": "228939226\n",
"output": "1516 17472\n",
"type": "stdin_stdout"
},
{
"input": "973034514\n",
"output": "27776 16488\n",
"type": "stdin_stdout"
},
{
"input": "984826594\n",
"output": "22704 -27064\n",
"type": "stdin_stdout"
},
{
"input": "19164960\n",
"output": "4864 384\n",
"type": "stdin_stdout"
},
{
"input": "249781780\n",
"output": "2815 18250\n",
"type": "stdin_stdout"
},
{
"input": "851838979\n",
"output": "8695 33702\n",
"type": "stdin_stdout"
},
{
"input": "978618459\n",
"output": "-15591 -36122\n",
"type": "stdin_stdout"
},
{
"input": "871854460\n",
"output": "31404 5384\n",
"type": "stdin_stdout"
},
{
"input": "302486639\n",
"output": "11555 -17054\n",
"type": "stdin_stdout"
},
{
"input": "0\n",
"output": "0 0\n",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "-1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "-2 0\n",
"type": "stdin_stdout"
},
{
"input": "4\n",
"output": "-1 -2\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "1 -2\n",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "2 0\n",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "2 4\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "0 4\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "-2 4\n",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "-3 2\n",
"type": "stdin_stdout"
},
{
"input": "12\n",
"output": "-4 0\n",
"type": "stdin_stdout"
},
{
"input": "13\n",
"output": "-3 -2\n",
"type": "stdin_stdout"
},
{
"input": "14\n",
"output": "-2 -4\n",
"type": "stdin_stdout"
},
{
"input": "15\n",
"output": "0 -4\n",
"type": "stdin_stdout"
},
{
"input": "16\n",
"output": "2 -4\n",
"type": "stdin_stdout"
},
{
"input": "17\n",
"output": "3 -2\n",
"type": "stdin_stdout"
},
{
"input": "18\n",
"output": "4 0\n",
"type": "stdin_stdout"
},
{
"input": "19\n",
"output": "5 2\n",
"type": "stdin_stdout"
},
{
"input": "20\n",
"output": "4 4\n",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "3 6\n",
"type": "stdin_stdout"
},
{
"input": "22\n",
"output": "1 6\n",
"type": "stdin_stdout"
},
{
"input": "23\n",
"output": "-1 6\n",
"type": "stdin_stdout"
},
{
"input": "24\n",
"output": "-3 6\n",
"type": "stdin_stdout"
},
{
"input": "25\n",
"output": "-4 4\n",
"type": "stdin_stdout"
},
{
"input": "26\n",
"output": "-5 2\n",
"type": "stdin_stdout"
},
{
"input": "27\n",
"output": "-6 0\n",
"type": "stdin_stdout"
},
{
"input": "28\n",
"output": "-5 -2\n",
"type": "stdin_stdout"
},
{
"input": "29\n",
"output": "-4 -4\n",
"type": "stdin_stdout"
},
{
"input": "30\n",
"output": "-3 -6\n",
"type": "stdin_stdout"
},
{
"input": "257947185131120683\n",
"output": "-53995102 -586455096\n",
"type": "stdin_stdout"
},
{
"input": "258773432604171403\n",
"output": "-438664202 297458800\n",
"type": "stdin_stdout"
},
{
"input": "259599671487287531\n",
"output": "-252460838 -588330600\n",
"type": "stdin_stdout"
},
{
"input": "260425914665370955\n",
"output": "-423141322 332249584\n",
"type": "stdin_stdout"
},
{
"input": "261252157843454379\n",
"output": "-164822562 -590200144\n",
"type": "stdin_stdout"
},
{
"input": "262078401021537803\n",
"output": "439863347 302538706\n",
"type": "stdin_stdout"
},
{
"input": "262904639904653932\n",
"output": "-378326148 -427475264\n",
"type": "stdin_stdout"
},
{
"input": "263730878787770060\n",
"output": "200309780 592993400\n",
"type": "stdin_stdout"
},
{
"input": "264557126260820780\n",
"output": "489196540 209450068\n",
"type": "stdin_stdout"
},
{
"input": "775736713043603670\n",
"output": "-794841963 -444342246\n",
"type": "stdin_stdout"
},
{
"input": "776562956221687094\n",
"output": "-623135314 -788838484\n",
"type": "stdin_stdout"
},
{
"input": "777389199399770518\n",
"output": "-328249537 -1018095738\n",
"type": "stdin_stdout"
},
{
"input": "778215438282886646\n",
"output": "-719067659 -599137942\n",
"type": "stdin_stdout"
},
{
"input": "779041681460970070\n",
"output": "-637165825 764022826\n",
"type": "stdin_stdout"
},
{
"input": "779867924639053494\n",
"output": "559082192 -921270732\n",
"type": "stdin_stdout"
},
{
"input": "780694167817136918\n",
"output": "7343027 1020257594\n",
"type": "stdin_stdout"
},
{
"input": "781520406700253046\n",
"output": "-707743686 626107308\n",
"type": "stdin_stdout"
},
{
"input": "782346645583369174\n",
"output": "797020774 -448632052\n",
"type": "stdin_stdout"
},
{
"input": "783172893056419894\n",
"output": "604133660 -835484644\n",
"type": "stdin_stdout"
},
{
"input": "294352484134170081\n",
"output": "-264428508 -626474244\n",
"type": "stdin_stdout"
},
{
"input": "34761473798667069\n",
"output": "-107643660 215287324\n",
"type": "stdin_stdout"
},
{
"input": "247761054921329978\n",
"output": "-287379568 574759144\n",
"type": "stdin_stdout"
},
{
"input": "88904985049714519\n",
"output": "344296355 2\n",
"type": "stdin_stdout"
},
{
"input": "64695994584418558\n",
"output": "146851396 293702780\n",
"type": "stdin_stdout"
},
{
"input": "2999472947040002\n",
"output": "31620002 63239992\n",
"type": "stdin_stdout"
},
{
"input": "134013960807648841\n",
"output": "-422711816 4\n",
"type": "stdin_stdout"
},
{
"input": "27719767248080188\n",
"output": "-96124517 -192249026\n",
"type": "stdin_stdout"
},
{
"input": "228296921967681448\n",
"output": "-275860421 551720850\n",
"type": "stdin_stdout"
},
{
"input": "622704061396296670\n",
"output": "-911192665 10\n",
"type": "stdin_stdout"
},
{
"input": "382830415035226081\n",
"output": "357225613 714451226\n",
"type": "stdin_stdout"
},
{
"input": "175683606088259879\n",
"output": "-483988434 8\n",
"type": "stdin_stdout"
},
{
"input": "533568904697339792\n",
"output": "-421730125 843460258\n",
"type": "stdin_stdout"
},
{
"input": "281824423976299408\n",
"output": "-306498737 -612997466\n",
"type": "stdin_stdout"
},
{
"input": "237223610332609448\n",
"output": "-281201952 -562403896\n",
"type": "stdin_stdout"
},
{
"input": "82638676376847406\n",
"output": "-331941110 4\n",
"type": "stdin_stdout"
},
{
"input": "358538881902627465\n",
"output": "-691412929 6\n",
"type": "stdin_stdout"
},
{
"input": "1941943667672759\n",
"output": "-25442382 -50884744\n",
"type": "stdin_stdout"
},
{
"input": "504819148029580024\n",
"output": "820421960 -4\n",
"type": "stdin_stdout"
},
{
"input": "24271330411219667\n",
"output": "179893783 -2\n",
"type": "stdin_stdout"
},
{
"input": "108364135632524999\n",
"output": "-380112498 8\n",
"type": "stdin_stdout"
},
{
"input": "16796277375911920\n",
"output": "74824856 -149649712\n",
"type": "stdin_stdout"
},
{
"input": "194403552286884865\n",
"output": "-509121532 4\n",
"type": "stdin_stdout"
},
{
"input": "565840809656836956\n",
"output": "868593352 0\n",
"type": "stdin_stdout"
},
{
"input": "39010293491965817\n",
"output": "-114032591 -228065170\n",
"type": "stdin_stdout"
},
{
"input": "746407891412272132\n",
"output": "498801191 -997602386\n",
"type": "stdin_stdout"
},
{
"input": "95626493228268863\n",
"output": "178537107 357074206\n",
"type": "stdin_stdout"
},
{
"input": "385078658398478614\n",
"output": "358273010 -716546028\n",
"type": "stdin_stdout"
},
{
"input": "177207687885798058\n",
"output": "486083238 -4\n",
"type": "stdin_stdout"
},
{
"input": "536222521732590352\n",
"output": "-422777531 845555062\n",
"type": "stdin_stdout"
},
{
"input": "1571429132955632\n",
"output": "45773778 4\n",
"type": "stdin_stdout"
},
{
"input": "498549006180463098\n",
"output": "407655496 -815310984\n",
"type": "stdin_stdout"
},
{
"input": "438594547809157461\n",
"output": "382358709 -764717418\n",
"type": "stdin_stdout"
},
{
"input": "214071008058709620\n",
"output": "534254630 0\n",
"type": "stdin_stdout"
},
{
"input": "599060227806517999\n",
"output": "-446863220 893726452\n",
"type": "stdin_stdout"
},
{
"input": "329939015655396840\n",
"output": "-331631832 663263664\n",
"type": "stdin_stdout"
},
{
"input": "281523482448806534\n",
"output": "306335045 612670094\n",
"type": "stdin_stdout"
},
{
"input": "109561818187625921\n",
"output": "191103653 382207306\n",
"type": "stdin_stdout"
},
{
"input": "412565943716413781\n",
"output": "370839563 741679126\n",
"type": "stdin_stdout"
},
{
"input": "196006607922989510\n",
"output": "-255608161 511216338\n",
"type": "stdin_stdout"
},
{
"input": "379604878823574823\n",
"output": "-355717526 711435056\n",
"type": "stdin_stdout"
},
{
"input": "173500741457825598\n",
"output": "240486136 480972264\n",
"type": "stdin_stdout"
},
{
"input": "138919367769131398\n",
"output": "-430378693 10\n",
"type": "stdin_stdout"
},
{
"input": "29974778103430162\n",
"output": "99957958 199915904\n",
"type": "stdin_stdout"
},
{
"input": "234685974076220810\n",
"output": "-279693865 559387730\n",
"type": "stdin_stdout"
},
{
"input": "633227154929081648\n",
"output": "-459429777 -918859546\n",
"type": "stdin_stdout"
},
{
"input": "58101264340386100\n",
"output": "-139165682 278331372\n",
"type": "stdin_stdout"
},
{
"input": "1718550904886625\n",
"output": "23934291 -47868582\n",
"type": "stdin_stdout"
},
{
"input": "124444652733481603\n",
"output": "203670197 -407340402\n",
"type": "stdin_stdout"
},
{
"input": "441000740540275741\n",
"output": "-383406115 -766812218\n",
"type": "stdin_stdout"
},
{
"input": "545168342596476149\n",
"output": "852579099 -2\n",
"type": "stdin_stdout"
},
{
"input": "138919367769131403\n",
"output": "-430378698 0\n",
"type": "stdin_stdout"
},
{
"input": "138919367984320752\n",
"output": "-215189349 -430378698\n",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "-1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n",
"output": "-1 -2\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "1 -2\n",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "2 0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/615/E"
} | vfc_9898 |
apps | verifiable_code | 37 | Solve the following coding problem using the programming language python:
Dante is engaged in a fight with "The Savior". Before he can fight it with his sword, he needs to break its shields. He has two guns, Ebony and Ivory, each of them is able to perform any non-negative number of shots.
For every bullet that hits the shield, Ebony deals a units of damage while Ivory deals b units of damage. In order to break the shield Dante has to deal exactly c units of damage. Find out if this is possible.
-----Input-----
The first line of the input contains three integers a, b, c (1 ≤ a, b ≤ 100, 1 ≤ c ≤ 10 000) — the number of units of damage dealt by Ebony gun and Ivory gun, and the total number of damage required to break the shield, respectively.
-----Output-----
Print "Yes" (without quotes) if Dante can deal exactly c damage to the shield and "No" (without quotes) otherwise.
-----Examples-----
Input
4 6 15
Output
No
Input
3 2 7
Output
Yes
Input
6 11 6
Output
Yes
-----Note-----
In the second sample, Dante can fire 1 bullet from Ebony and 2 from Ivory to deal exactly 1·3 + 2·2 = 7 damage. In the third sample, Dante can fire 1 bullet from ebony and no bullets from ivory to do 1·6 + 0·11 = 6 damage.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, b, c = list(map(int, input().split()))
p = [0] * 100000
p[0] = 1
p[a] = 1
p[b] = 1
for i in range(c + 1):
if p[i]:
p[i + a] = 1
p[i + b] = 1
if p[c]:
print('Yes')
else:
print('No')
``` | {
"language": "python",
"test_cases": [
{
"input": "4 6 15\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "3 2 7\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6 11 6\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 12 15\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5 5 10\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6 6 7\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1 1 20\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "12 14 19\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "15 12 26\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "2 4 8\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 5 30\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 5 48\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 17 105\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "10 25 282\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "6 34 323\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "2 47 464\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 53 113\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6 64 546\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1 78 725\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1 84 811\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 100 441\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "20 5 57\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "14 19 143\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "17 23 248\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "11 34 383\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "20 47 568\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "16 58 410\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "11 70 1199\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "16 78 712\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "20 84 562\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "19 100 836\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "23 10 58\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "25 17 448\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "22 24 866\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "24 35 67\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "29 47 264\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "23 56 45\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "25 66 1183\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "21 71 657\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "29 81 629\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "23 95 2226\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "32 4 62\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "37 15 789\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "39 24 999\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "38 32 865\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "32 50 205\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "31 57 1362\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "38 68 1870\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "36 76 549\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "35 84 1257\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "39 92 2753\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "44 1 287\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "42 12 830\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "42 27 9\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "49 40 1422\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "44 42 2005\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "50 55 2479\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "48 65 917\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "45 78 152\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "43 90 4096\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "43 94 4316\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "60 7 526\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "53 11 735\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "52 27 609\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "57 32 992\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "52 49 421\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "57 52 2634\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "54 67 3181\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "52 73 638\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "57 84 3470\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "52 100 5582\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "62 1 501\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "63 17 858\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "70 24 1784\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "65 32 1391\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "62 50 2775\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "62 58 88\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "66 68 3112\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "61 71 1643\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "69 81 3880\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "63 100 1960\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "73 6 431\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "75 19 736\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "78 25 247\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "79 36 2854\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "80 43 1864\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "76 55 2196\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "76 69 4122\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "76 76 4905\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "75 89 3056\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "73 100 3111\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "84 9 530\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "82 18 633\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "85 29 2533\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "89 38 2879\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "89 49 2200\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "88 60 4140\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "82 68 1299\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "90 76 2207\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "83 84 4923\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "89 99 7969\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "94 9 168\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "91 20 1009\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "93 23 2872\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "97 31 3761\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "99 46 1341\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "98 51 2845\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "93 66 3412\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "95 76 3724\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "91 87 6237\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "98 97 7886\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "12 17 15\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "93 94 95\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "27 43 27\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "17 43 68\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "44 12 12\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "44 50 150\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1 1 10000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 3 10000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "100 1 10\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 2 1\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "9 9 10000\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "2 3 9995\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 5 4\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "99 98 100\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "6 10 2\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1 6 5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1 4 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 2 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1 7 6\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 3 9871\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "10 5 5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "10 8 2\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/633/A"
} | vfc_9902 |
apps | verifiable_code | 38 | Solve the following coding problem using the programming language python:
Running with barriers on the circle track is very popular in the country where Dasha lives, so no wonder that on her way to classes she saw the following situation:
The track is the circle with length L, in distinct points of which there are n barriers. Athlete always run the track in counterclockwise direction if you look on him from above. All barriers are located at integer distance from each other along the track.
Her friends the parrot Kefa and the leopard Sasha participated in competitions and each of them ran one lap. Each of the friends started from some integral point on the track. Both friends wrote the distance from their start along the track to each of the n barriers. Thus, each of them wrote n integers in the ascending order, each of them was between 0 and L - 1, inclusively. [Image] Consider an example. Let L = 8, blue points are barriers, and green points are Kefa's start (A) and Sasha's start (B). Then Kefa writes down the sequence [2, 4, 6], and Sasha writes down [1, 5, 7].
There are several tracks in the country, all of them have same length and same number of barriers, but the positions of the barriers can differ among different tracks. Now Dasha is interested if it is possible that Kefa and Sasha ran the same track or they participated on different tracks.
Write the program which will check that Kefa's and Sasha's tracks coincide (it means that one can be obtained from the other by changing the start position). Note that they always run the track in one direction — counterclockwise, if you look on a track from above.
-----Input-----
The first line contains two integers n and L (1 ≤ n ≤ 50, n ≤ L ≤ 100) — the number of barriers on a track and its length.
The second line contains n distinct integers in the ascending order — the distance from Kefa's start to each barrier in the order of its appearance. All integers are in the range from 0 to L - 1 inclusively.
The second line contains n distinct integers in the ascending order — the distance from Sasha's start to each barrier in the order of its overcoming. All integers are in the range from 0 to L - 1 inclusively.
-----Output-----
Print "YES" (without quotes), if Kefa and Sasha ran the coinciding tracks (it means that the position of all barriers coincides, if they start running from the same points on the track). Otherwise print "NO" (without quotes).
-----Examples-----
Input
3 8
2 4 6
1 5 7
Output
YES
Input
4 9
2 3 5 8
0 1 3 6
Output
YES
Input
2 4
1 3
1 2
Output
NO
-----Note-----
The first test is analyzed in the statement.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
n, l = map(int, input().split())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
x.append(x[0] + l)
y.append(y[0] + l)
a = [x[i + 1] - x[i] for i in range(n)]
b = [y[i + 1] - y[i] for i in range(n)]
for i in range(n):
if (a == b[i:] + b[:i]):
print("YES")
return
print("NO")
main()
``` | {
"language": "python",
"test_cases": [
{
"input": "3 8\n2 4 6\n1 5 7\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 9\n2 3 5 8\n0 1 3 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n1 3\n1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 9\n0 2 5 6 7\n1 3 6 7 8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 60\n7 26 27 40 59\n14 22 41 42 55\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "20 29\n0 1 2 4 5 8 9 12 14 15 17 19 20 21 22 23 25 26 27 28\n0 2 4 5 6 7 8 10 11 12 13 14 15 16 18 19 22 23 26 28\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "35 41\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 18 19 20 21 22 23 24 25 26 28 30 31 32 33 34 35 36 37 38 39 40\n0 1 2 3 4 5 7 8 9 10 11 12 16 17 18 19 20 21 22 23 24 26 28 29 30 31 32 33 34 35 36 37 38 39 40\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "40 63\n0 2 3 4 5 6 9 10 12 15 17 19 23 25 26 27 28 29 30 31 33 34 36 37 38 39 40 43 45 49 50 52 53 54 55 57 58 60 61 62\n1 2 3 4 5 8 10 14 15 17 18 19 20 22 23 25 26 27 28 30 31 32 33 34 37 38 40 43 46 47 51 53 54 55 56 57 58 59 61 62\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "50 97\n1 2 3 4 6 9 10 11 12 13 14 21 22 23 24 25 28 29 30 31 32 33 34 36 37 40 41 45 53 56 59 64 65 69 70 71 72 73 74 77 81 84 85 86 87 89 91 92 95 96\n0 1 2 3 6 10 13 14 15 16 18 20 21 24 25 27 28 29 30 33 35 36 37 38 39 40 47 48 49 50 51 54 55 56 57 58 59 60 62 63 66 67 71 79 82 85 90 91 95 96\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "50 100\n0 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98\n1 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 39 41 43 45 47 49 51 53 55 57 59 61 63 65 67 69 71 73 75 77 79 81 83 85 87 89 91 93 95 97 99\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n0\n0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n0\n1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n1\n0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n1\n1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n0\n0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 12\n2 3 4 8 10\n2 3 4 8 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 18\n3\n10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 75\n65\n8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 16\n4 13\n2 11\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 95\n45 59\n3 84\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 53\n29 43 50\n29 43 50\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 60\n39 46 51\n43 50 55\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n0 1 2 3\n0 1 2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 93\n45 48 50 90\n20 68 71 73\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 18\n0 3 8 11 15 16\n2 7 10 14 15 17\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 87\n0 1 21 31 34 66\n11 12 32 42 45 77\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 26\n0 3 9 13 14 19 20\n4 7 13 17 18 23 24\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 81\n0 12 19 24 25 35 59\n1 8 13 14 24 48 70\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 20\n0 1 2 3 5 6 14 15\n1 2 10 11 16 17 18 19\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 94\n0 8 11 27 38 54 57 89\n1 33 38 46 49 65 76 92\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9 18\n1 3 6 8 11 12 13 16 17\n0 2 5 6 7 10 11 13 15\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9 90\n10 11 27 33 34 55 63 84 87\n9 12 25 26 42 48 49 70 78\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 42\n4 9 10 14 15 16 19 33 36 40\n0 14 17 21 27 32 33 37 38 39\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 73\n4 5 15 19 20 25 28 42 57 58\n3 4 9 12 26 41 42 61 62 72\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "11 11\n0 1 2 3 4 5 6 7 8 9 10\n0 1 2 3 4 5 6 7 8 9 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "11 57\n1 4 27 30 31 35 37 41 50 52 56\n22 25 26 30 32 36 45 47 51 53 56\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "12 73\n5 9 11 20 25 36 40 41 44 48 56 60\n12 16 18 27 32 43 47 48 51 55 63 67\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "12 95\n1 37 42 46 56 58 59 62 64 71 76 80\n2 18 54 59 63 73 75 76 79 81 88 93\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "13 29\n2 5 6 9 12 17 18 19 20 21 22 24 27\n0 3 6 11 12 13 14 15 16 18 21 25 28\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "13 90\n9 18 23 30 31 36 39 44 58 59 74 82 87\n1 6 18 27 32 39 40 45 48 53 67 68 83\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "14 29\n1 2 3 4 5 7 9 12 13 20 21 22 23 24\n0 3 4 11 12 13 14 15 21 22 23 24 25 27\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "14 94\n7 8 9 21 34 35 36 37 38 43 46 52 84 93\n2 3 4 16 29 30 31 32 33 38 41 47 79 88\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "15 19\n1 2 3 4 5 6 7 8 9 10 11 13 14 16 17\n0 1 2 3 4 5 6 7 8 9 10 12 13 15 16\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "15 27\n2 3 4 5 6 7 8 9 10 11 12 14 17 24 26\n2 3 4 5 6 7 8 9 10 11 12 14 17 24 26\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "16 28\n3 5 6 7 9 10 11 12 13 14 17 19 20 25 26 27\n0 5 6 7 11 13 14 15 17 18 19 20 21 22 25 27\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "16 93\n5 6 10 11 13 14 41 43 46 61 63 70 74 79 83 92\n0 9 15 16 20 21 23 24 51 53 56 71 73 80 84 89\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "17 49\n2 5 11 12 16 18 19 21 22 24 36 37 38 39 40 44 47\n1 7 8 12 14 15 17 18 20 32 33 34 35 36 40 43 47\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "17 86\n16 17 25 33 39 41 50 51 54 56 66 70 72 73 77 80 85\n3 9 11 20 21 24 26 36 40 42 43 47 50 55 72 73 81\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "18 20\n0 1 2 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\n0 1 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "18 82\n0 5 10 13 14 16 21 28 29 30 44 46 61 64 69 71 77 78\n0 5 8 9 11 16 23 24 25 39 41 56 59 64 66 72 73 77\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "19 25\n0 1 2 3 5 7 9 10 12 13 16 17 18 19 20 21 22 23 24\n0 3 4 5 6 7 8 9 10 11 12 13 14 15 17 19 21 22 24\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "19 91\n5 17 18 20 22 25 26 31 32 33 43 47 54 61 62 64 77 80 87\n4 5 6 16 20 27 34 35 37 50 53 60 69 81 82 84 86 89 90\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "20 53\n2 6 8 9 16 17 20 21 22 23 25 26 35 36 38 39 44 46 47 50\n4 5 8 9 10 11 13 14 23 24 26 27 32 34 35 38 43 47 49 50\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "21 44\n0 1 3 4 6 7 8 9 10 11 12 15 17 18 21 22 27 29 34 36 42\n1 7 9 10 12 13 15 16 17 18 19 20 21 24 26 27 30 31 36 38 43\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "21 94\n3 5 6 8 9 15 16 20 28 31 35 39 49 50 53 61 71 82 85 89 90\n6 17 20 24 25 32 34 35 37 38 44 45 49 57 60 64 68 78 79 82 90\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "22 24\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 22 23\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "22 85\n3 5 7 14 18 21 25 32 38 41 53 58 61 62 66 70 71 73 75 76 79 83\n3 6 18 23 26 27 31 35 36 38 40 41 44 48 53 55 57 64 68 71 75 82\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "23 38\n0 2 4 5 7 8 12 13 14 16 17 18 21 22 24 27 28 30 31 32 35 36 37\n0 1 2 3 5 7 8 10 11 15 16 17 19 20 21 24 25 27 30 31 33 34 35\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "23 93\n1 3 5 10 19 22 26 27 30 35 39 53 55 60 66 67 75 76 77 80 82 89 90\n9 11 16 22 23 31 32 33 36 38 45 46 50 52 54 59 68 71 75 76 79 84 88\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "24 37\n1 4 5 6 8 11 12 13 15 16 17 19 20 21 23 26 27 28 30 31 33 34 35 36\n0 3 4 5 7 8 10 11 12 13 15 18 19 20 22 25 26 27 29 30 31 33 34 35\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "24 94\n9 10 13 14 16 18 19 22 24 29 32 35 48 55 57 63 64 69 72 77 78 85 90 92\n1 7 8 13 16 21 22 29 34 36 47 48 51 52 54 56 57 60 62 67 70 73 86 93\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "25 45\n0 1 2 4 6 7 8 9 13 14 17 19 21 22 23 25 28 29 30 31 34 36 38 39 42\n1 3 4 5 7 10 11 12 13 16 18 20 21 24 27 28 29 31 33 34 35 36 40 41 44\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "25 72\n1 2 6 8 9 11 15 18 19 20 26 29 31 33 34 40 41 43 45 48 58 60 68 69 71\n0 6 9 11 13 14 20 21 23 25 28 38 40 48 49 51 53 54 58 60 61 63 67 70 71\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "26 47\n0 2 5 7 8 9 10 12 13 14 20 22 23 25 27 29 31 32 33 35 36 37 38 42 44 45\n0 2 4 6 8 9 10 12 13 14 15 19 21 22 24 26 29 31 32 33 34 36 37 38 44 46\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "26 99\n0 1 13 20 21 22 25 26 27 28 32 39 44 47 56 58 60 62 71 81 83 87 89 93 94 98\n6 8 12 14 18 19 23 24 25 37 44 45 46 49 50 51 52 56 63 68 71 80 82 84 86 95\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "27 35\n0 2 3 4 5 6 7 8 10 11 12 13 14 15 16 17 19 20 21 23 26 27 29 30 31 32 33\n0 1 2 3 5 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 24 25 26 28 31 32 34\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "27 51\n1 2 4 7 8 11 13 17 20 21 23 24 25 28 29 30 34 35 37 38 40 43 45 46 47 48 50\n0 1 2 4 6 7 9 12 13 16 18 22 25 26 28 29 30 33 34 35 39 40 42 43 45 48 50\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "28 38\n1 4 5 7 8 9 10 11 12 14 15 16 18 19 20 21 22 23 24 25 28 29 30 32 33 35 36 37\n0 1 2 3 4 5 6 9 10 11 13 14 16 17 18 20 23 24 26 27 28 29 30 31 33 34 35 37\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "28 67\n0 1 2 3 6 9 10 15 18 22 24 25 30 35 36 38 39 47 48 49 51 53 55 56 58 62 63 64\n4 7 11 13 14 19 24 25 27 28 36 37 38 40 42 44 45 47 51 52 53 56 57 58 59 62 65 66\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "29 29\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "29 93\n1 2 11 13 18 21 27 28 30 38 41 42 46 54 55 56 60 61 63 64 66 69 71 72 77 81 83 89 90\n2 10 11 12 16 17 19 20 22 25 27 28 33 37 39 45 46 50 51 60 62 67 70 76 77 79 87 90 91\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "30 63\n0 2 3 5 6 7 8 10 13 18 19 21 22 23 26 32 35 37 38 39 40 41 43 44 49 51 53 54 58 61\n0 2 3 5 6 7 8 10 13 18 19 21 22 23 26 32 35 37 38 39 40 41 43 44 49 51 53 54 58 61\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "30 91\n1 2 3 7 8 9 13 16 17 19 27 29 38 45 47 52 53 55 61 62 66 77 78 79 80 81 82 84 88 89\n3 4 5 9 12 13 15 23 25 34 41 43 48 49 51 57 58 62 73 74 75 76 77 78 80 84 85 88 89 90\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "31 39\n0 1 2 3 4 5 6 7 8 10 11 13 14 17 18 20 21 23 24 25 27 28 29 30 31 33 34 35 36 37 38\n0 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 18 19 21 22 25 26 28 29 31 32 33 35 36 37 38\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "31 95\n9 12 14 15 21 23 26 28 30 36 37 42 47 51 54 56 59 62 64 65 66 70 72 74 75 79 82 85 87 91 93\n0 2 3 7 10 13 15 19 21 32 35 37 38 44 46 49 51 53 59 60 65 70 74 77 79 82 85 87 88 89 93\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "32 61\n0 2 3 5 7 10 13 14 15 18 19 20 21 22 23 24 26 32 33 34 36 38 43 46 47 51 54 55 56 57 58 59\n1 2 4 6 9 12 13 14 17 18 19 20 21 22 23 25 31 32 33 35 37 42 45 46 50 53 54 55 56 57 58 60\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "32 86\n5 7 9 10 13 17 18 19 25 26 28 32 33 37 38 43 45 47 50 53 57 58 60 69 73 74 75 77 80 82 83 85\n7 11 12 13 15 18 20 21 23 29 31 33 34 37 41 42 43 49 50 52 56 57 61 62 67 69 71 74 77 81 82 84\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "33 44\n0 1 2 3 5 9 10 11 12 13 14 15 17 18 20 21 22 23 24 25 26 27 28 30 31 32 35 36 38 39 41 42 43\n0 2 3 4 7 8 10 11 13 14 15 16 17 18 19 21 25 26 27 28 29 30 31 33 34 36 37 38 39 40 41 42 43\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "33 73\n3 6 7 8 9 10 11 13 14 15 17 19 22 23 26 27 28 31 33 34 35 37 42 44 48 52 54 57 62 63 64 67 68\n2 3 4 7 8 16 19 20 21 22 23 24 26 27 28 30 32 35 36 39 40 41 44 46 47 48 50 55 57 61 65 67 70\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "34 52\n1 2 3 4 5 6 8 9 10 12 13 14 15 16 17 19 21 24 26 27 28 29 31 33 35 36 37 39 40 45 46 49 50 51\n0 1 2 3 4 6 7 8 10 11 12 13 14 15 17 19 22 24 25 26 27 29 31 33 34 35 37 38 43 44 47 48 49 51\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "34 68\n0 7 9 10 11 14 15 16 20 21 22 24 26 32 34 35 37 38 40 41 42 43 44 45 47 50 53 55 57 58 59 62 64 65\n0 1 2 3 5 8 11 13 15 16 17 20 22 23 26 33 35 36 37 40 41 42 46 47 48 50 52 58 60 61 63 64 66 67\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "35 90\n4 5 7 8 10 11 12 13 14 22 27 29 31 33 34 38 46 49 52 53 54 55 56 57 60 61 64 69 77 81 83 86 87 88 89\n4 7 10 11 12 13 14 15 18 19 22 27 35 39 41 44 45 46 47 52 53 55 56 58 59 60 61 62 70 75 77 79 81 82 86\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "36 43\n1 2 3 4 6 7 8 9 10 11 14 16 17 18 19 20 21 22 23 24 25 26 27 29 30 31 32 33 34 35 36 37 38 39 40 42\n0 1 2 3 4 5 6 8 9 10 11 12 13 14 15 16 17 18 19 21 23 24 25 26 28 29 30 31 32 33 36 38 39 40 41 42\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "36 84\n1 3 6 13 15 16 17 18 19 21 23 26 29 33 38 40 42 45 49 50 53 54 57 58 60 61 64 65 67 70 73 76 78 79 81 83\n0 2 5 8 12 17 19 21 24 28 29 32 33 36 37 39 40 43 44 46 49 52 55 57 58 60 62 64 66 69 76 78 79 80 81 82\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "37 46\n0 1 3 6 7 8 9 10 12 13 14 16 17 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 39 40 41 42 43 44\n0 3 4 5 6 7 9 10 11 13 14 16 17 18 19 20 21 22 23 24 25 26 27 28 30 31 32 33 34 36 37 38 39 40 41 43 44\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "37 97\n0 5 10 11 12 15 16 18 19 25 28 29 34 35 36 37 38 40 46 47 48 49 55 58 60 61 62 64 65 70 76 77 80 82 88 94 96\n1 7 13 15 16 21 26 27 28 31 32 34 35 41 44 45 50 51 52 53 54 56 62 63 64 65 71 74 76 77 78 80 81 86 92 93 96\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "38 58\n1 2 3 4 5 8 9 11 12 13 15 16 17 22 23 24 25 26 27 29 30 31 32 33 34 36 37 40 41 43 46 47 48 52 53 55 56 57\n1 2 3 5 6 7 8 9 12 13 15 16 17 19 20 21 26 27 28 29 30 31 33 34 35 36 37 38 40 41 44 45 47 50 51 52 56 57\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "38 92\n1 2 3 5 6 7 12 14 15 16 17 18 20 22 29 31 33 34 38 41 43 49 54 55 57 58 61 63 66 67 69 73 75 76 82 85 88 90\n1 3 4 10 13 16 18 21 22 23 25 26 27 32 34 35 36 37 38 40 42 49 51 53 54 58 61 63 69 74 75 77 78 81 83 86 87 89\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "39 59\n0 1 2 3 5 6 7 8 9 10 11 12 13 15 16 17 19 24 25 28 29 31 32 33 35 37 38 40 41 42 43 45 46 47 49 50 53 55 56\n0 1 3 4 5 6 8 9 10 12 13 16 18 19 22 23 24 25 27 28 29 30 31 32 33 34 35 37 38 39 41 46 47 50 51 53 54 55 57\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "39 67\n1 3 5 7 8 16 18 20 21 23 24 25 27 28 29 31 32 34 36 38 40 43 44 46 47 48 49 50 52 53 54 55 58 59 61 62 63 64 66\n0 1 2 4 6 8 10 12 13 21 23 25 26 28 29 30 32 33 34 36 37 39 41 43 45 48 49 51 52 53 54 55 57 58 59 60 63 64 66\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "40 63\n0 2 3 4 5 6 9 10 12 15 18 19 23 25 26 27 28 29 30 31 33 34 36 37 38 39 40 43 45 49 50 52 53 54 55 57 58 60 61 62\n1 2 3 4 5 8 10 14 15 17 18 19 20 22 23 25 26 27 28 30 31 32 33 34 37 38 40 43 46 47 51 53 54 55 56 57 58 59 61 62\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "40 96\n5 11 12 13 14 16 17 18 19 24 30 31 32 33 37 42 46 50 53 54 55 58 60 61 64 67 68 69 70 72 75 76 77 81 84 85 89 91 92 93\n2 7 11 15 18 19 20 23 25 26 29 32 33 34 35 37 40 41 42 46 49 50 54 56 57 58 66 72 73 74 75 77 78 79 80 85 91 92 93 94\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "41 67\n0 2 3 5 8 10 11 12 13 14 15 19 20 21 22 26 29 30 31 32 34 35 37 38 40 41 44 45 46 47 49 51 52 53 54 56 57 58 59 63 66\n2 3 4 5 9 12 13 14 15 17 18 20 21 23 24 27 28 29 30 32 34 35 36 37 39 40 41 42 46 49 50 52 53 55 58 60 61 62 63 64 65\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "41 72\n0 3 4 6 7 8 9 12 13 14 16 21 23 24 25 26 27 29 31 32 33 34 35 38 40 41 45 47 49 50 51 52 56 57 58 59 61 62 65 66 69\n0 1 4 5 6 8 13 15 16 17 18 19 21 23 24 25 26 27 30 32 33 37 39 41 42 43 44 48 49 50 51 53 54 57 58 61 64 67 68 70 71\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "42 48\n0 1 2 3 4 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 26 27 28 29 30 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47\n0 1 2 3 4 5 6 8 9 10 11 12 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 37 38 39 40 41 42 43 45 46 47\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "42 81\n0 1 3 6 7 8 11 13 17 18 19 21 22 24 29 30 31 32 34 35 38 44 46 48 49 50 51 52 53 55 59 61 62 63 65 66 67 69 70 72 77 80\n0 1 3 4 6 11 12 13 14 16 17 20 26 28 30 31 32 33 34 35 37 41 43 44 45 47 48 49 51 52 54 59 62 63 64 66 69 70 71 74 76 80\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "43 55\n0 1 2 3 4 5 6 7 8 12 14 15 17 18 19 20 21 22 23 26 27 28 29 31 32 33 35 36 37 38 40 42 43 44 45 46 47 48 49 50 51 53 54\n1 2 4 5 6 7 8 9 10 13 14 15 16 18 19 20 22 23 24 25 27 29 30 31 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47 48 49 50 54\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "43 81\n2 3 4 5 6 7 9 10 12 13 18 19 20 21 23 26 27 29 30 32 34 38 39 43 46 47 48 50 51 52 54 55 58 62 64 67 69 70 71 72 73 75 80\n0 3 5 6 7 8 9 11 16 19 20 21 22 23 24 26 27 29 30 35 36 37 38 40 43 44 46 47 49 51 55 56 60 63 64 65 67 68 69 71 72 75 79\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "44 54\n0 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 31 33 34 35 36 37 39 40 41 43 44 47 49 50 52 53\n0 1 2 3 4 5 6 7 8 10 12 13 14 15 16 18 19 20 22 23 26 28 29 31 32 33 34 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "44 93\n1 5 6 7 8 10 14 17 19 21 25 26 27 30 33 34 35 36 38 41 45 48 49 51 53 55 57 60 66 67 69 70 73 76 78 79 80 81 82 83 85 87 88 90\n0 2 4 8 9 10 13 16 17 18 19 21 24 28 31 32 34 36 38 40 43 49 50 52 53 56 59 61 62 63 64 65 66 68 70 71 73 77 81 82 83 84 86 90\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "45 47\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 43 44 45 46\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 41 42 43 44 45 46\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "45 71\n0 2 3 7 8 11 12 13 14 15 16 17 20 21 22 23 24 26 28 30 32 37 39 41 42 43 44 45 47 48 50 52 54 55 56 57 58 59 60 61 62 64 66 68 70\n0 1 2 3 4 7 8 9 10 11 13 15 17 19 24 26 28 29 30 31 32 34 35 37 39 41 42 43 44 45 46 47 48 49 51 53 55 57 58 60 61 65 66 69 70\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "46 46\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "46 93\n0 1 2 6 13 16 17 18 19 21 27 29 32 34 37 38 39 40 41 44 45 49 50 52 54 56 57 61 64 65 66 67 69 71 73 75 77 78 79 83 85 87 88 90 91 92\n0 2 4 5 7 8 9 10 11 12 16 23 26 27 28 29 31 37 39 42 44 47 48 49 50 51 54 55 59 60 62 64 66 67 71 74 75 76 77 79 81 83 85 87 88 89\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "47 49\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48\n0 1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "47 94\n0 1 3 4 5 7 8 9 14 18 19 26 30 33 34 35 37 40 42 45 46 49 50 51 52 53 55 56 60 61 62 63 64 65 66 69 71 73 75 79 84 86 87 88 90 92 93\n1 2 3 4 6 7 8 10 11 12 17 21 22 29 33 36 37 38 40 43 45 48 49 52 53 54 55 56 58 59 63 64 65 66 67 68 69 72 74 76 78 82 87 89 90 91 93\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "48 65\n0 1 2 4 5 6 7 8 9 10 11 12 15 16 17 20 22 24 25 26 27 28 30 32 33 34 35 37 38 39 44 45 46 47 48 50 51 52 53 54 55 56 57 58 59 61 62 63\n0 1 4 6 8 9 10 11 12 14 16 17 18 19 21 22 23 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 45 46 47 49 50 51 53 54 55 56 57 58 59 60 61 64\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "48 90\n1 3 4 5 8 9 11 13 14 15 16 18 20 21 24 26 29 30 31 33 34 36 37 38 39 40 42 43 44 46 47 48 51 52 55 58 59 61 62 63 65 66 68 78 79 81 82 89\n0 3 4 6 8 9 10 11 13 15 16 19 21 24 25 26 28 29 31 32 33 34 35 37 38 39 41 42 43 46 47 50 53 54 56 57 58 60 61 63 73 74 76 77 84 86 88 89\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "49 60\n0 1 2 5 7 8 9 10 11 12 13 14 15 16 17 19 20 21 23 25 26 27 28 29 30 31 32 33 34 36 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 58 59\n0 1 2 3 4 5 6 7 8 10 11 12 14 16 17 18 19 20 21 22 23 24 25 27 29 30 31 32 33 34 35 37 38 39 40 41 42 43 44 45 46 49 50 51 52 53 56 58 59\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "49 97\n0 1 2 3 6 8 11 14 19 23 26 29 32 34 35 37 39 41 43 44 45 46 51 53 63 64 65 66 67 70 71 72 73 76 77 78 79 81 83 84 86 87 90 91 92 93 94 95 96\n0 3 4 5 6 7 8 9 10 11 12 13 16 18 21 24 29 33 36 39 42 44 45 47 49 51 53 54 55 56 61 63 73 74 75 76 77 80 81 82 83 86 87 88 89 91 93 94 96\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "50 58\n0 1 2 3 5 6 7 8 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 49 50 54 55 56 57\n0 1 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 31 32 36 37 38 39 40 41 42 43 45 46 47 48 50 51 52 53 54 55 56 57\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "50 97\n1 2 3 4 7 9 10 11 12 13 14 21 22 23 24 25 28 29 30 31 32 33 34 36 37 40 41 45 53 56 59 64 65 69 70 71 72 73 74 77 81 84 85 86 87 89 91 92 95 96\n0 1 2 3 6 10 13 14 15 16 18 20 21 24 25 27 28 29 30 33 35 36 37 38 39 40 47 48 49 50 51 54 55 56 57 58 59 60 62 63 66 67 71 79 82 85 90 91 95 96\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "40 96\n5 11 12 13 14 16 17 18 19 24 30 31 32 33 37 42 46 50 53 54 55 58 60 61 64 67 68 69 70 72 75 76 77 81 84 85 88 91 92 93\n2 7 11 15 18 19 20 23 25 26 29 32 33 34 35 37 40 41 42 46 49 50 54 56 57 58 66 72 73 74 75 77 78 79 80 85 91 92 93 94\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "41 67\n0 2 3 5 8 10 11 12 13 14 15 19 20 21 22 25 29 30 31 32 34 35 37 38 40 41 44 45 46 47 49 51 52 53 54 56 57 58 59 63 66\n2 3 4 5 9 12 13 14 15 17 18 20 21 23 24 27 28 29 30 32 34 35 36 37 39 40 41 42 46 49 50 52 53 55 58 60 61 62 63 64 65\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "41 72\n0 3 4 6 7 8 9 12 13 14 16 21 23 24 25 26 27 28 31 32 33 34 35 38 40 41 45 47 49 50 51 52 56 57 58 59 61 62 65 66 69\n0 1 4 5 6 8 13 15 16 17 18 19 21 23 24 25 26 27 30 32 33 37 39 41 42 43 44 48 49 50 51 53 54 57 58 61 64 67 68 70 71\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "42 48\n0 1 2 3 4 7 8 9 10 11 12 13 15 16 17 18 19 20 21 22 23 24 25 27 28 29 30 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47\n0 1 2 3 4 5 6 8 9 10 11 12 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 37 38 39 40 41 42 43 45 46 47\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "42 81\n0 1 3 6 7 8 11 13 17 18 19 20 22 24 29 30 31 32 34 35 38 44 46 48 49 50 51 52 53 55 59 61 62 63 65 66 67 69 70 72 77 80\n0 1 3 4 6 11 12 13 14 16 17 20 26 28 30 31 32 33 34 35 37 41 43 44 45 47 48 49 51 52 54 59 62 63 64 66 69 70 71 74 76 80\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "43 55\n0 1 2 3 4 5 6 7 8 12 14 15 17 18 19 20 21 22 23 26 27 28 29 31 32 33 34 36 37 38 40 42 43 44 45 46 47 48 49 50 51 53 54\n1 2 4 5 6 7 8 9 10 13 14 15 16 18 19 20 22 23 24 25 27 29 30 31 32 33 34 35 36 37 38 40 41 42 43 44 45 46 47 48 49 50 54\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "43 81\n2 3 4 5 6 7 9 10 12 13 17 19 20 21 23 26 27 29 30 32 34 38 39 43 46 47 48 50 51 52 54 55 58 62 64 67 69 70 71 72 73 75 80\n0 3 5 6 7 8 9 11 16 19 20 21 22 23 24 26 27 29 30 35 36 37 38 40 43 44 46 47 49 51 55 56 60 63 64 65 67 68 69 71 72 75 79\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "44 54\n0 1 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 26 27 28 29 31 33 34 35 36 37 38 40 41 43 44 47 49 50 52 53\n0 1 2 3 4 5 6 7 8 10 12 13 14 15 16 18 19 20 22 23 26 28 29 31 32 33 34 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "44 93\n1 5 6 7 8 10 14 17 19 21 25 26 27 30 33 34 35 36 38 41 45 48 49 51 53 55 57 60 66 67 69 70 73 76 78 79 80 81 82 83 84 87 88 90\n0 2 4 8 9 10 13 16 17 18 19 21 24 28 31 32 34 36 38 40 43 49 50 52 53 56 59 61 62 63 64 65 66 68 70 71 73 77 81 82 83 84 86 90\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "45 47\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 33 34 35 36 37 38 39 40 41 42 43 44 45 46\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "45 71\n0 2 3 7 8 11 12 13 14 15 16 17 20 21 22 23 24 26 28 30 32 37 39 40 42 43 44 45 47 48 50 52 54 55 56 57 58 59 60 61 62 64 66 68 70\n0 1 2 3 4 7 8 9 10 11 13 15 17 19 24 26 28 29 30 31 32 34 35 37 39 41 42 43 44 45 46 47 48 49 51 53 55 57 58 60 61 65 66 69 70\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "46 46\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "46 93\n0 1 2 6 13 16 17 18 19 21 27 29 32 34 37 38 39 40 41 44 45 49 50 52 54 56 57 61 64 65 66 67 69 71 73 75 77 78 79 83 85 86 88 90 91 92\n0 2 4 5 7 8 9 10 11 12 16 23 26 27 28 29 31 37 39 42 44 47 48 49 50 51 54 55 59 60 62 64 66 67 71 74 75 76 77 79 81 83 85 87 88 89\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "47 49\n0 1 2 3 4 5 6 7 9 10 11 12 13 14 15 16 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48\n0 1 2 3 4 5 6 7 8 9 10 11 13 14 15 16 17 18 19 20 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "47 94\n0 1 3 4 5 7 8 9 14 18 19 26 30 33 34 35 37 40 42 44 46 49 50 51 52 53 55 56 60 61 62 63 64 65 66 69 71 73 75 79 84 86 87 88 90 92 93\n1 2 3 4 6 7 8 10 11 12 17 21 22 29 33 36 37 38 40 43 45 48 49 52 53 54 55 56 58 59 63 64 65 66 67 68 69 72 74 76 78 82 87 89 90 91 93\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "48 65\n0 1 2 4 5 6 7 8 9 10 11 12 15 16 17 20 21 24 25 26 27 28 30 32 33 34 35 37 38 39 44 45 46 47 48 50 51 52 53 54 55 56 57 58 59 61 62 63\n0 1 4 6 8 9 10 11 12 14 16 17 18 19 21 22 23 28 29 30 31 32 34 35 36 37 38 39 40 41 42 43 45 46 47 49 50 51 53 54 55 56 57 58 59 60 61 64\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "48 90\n1 3 4 5 8 9 11 13 14 15 16 17 20 21 24 26 29 30 31 33 34 36 37 38 39 40 42 43 44 46 47 48 51 52 55 58 59 61 62 63 65 66 68 78 79 81 82 89\n0 3 4 6 8 9 10 11 13 15 16 19 21 24 25 26 28 29 31 32 33 34 35 37 38 39 41 42 43 46 47 50 53 54 56 57 58 60 61 63 73 74 76 77 84 86 88 89\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "49 60\n0 1 2 5 7 8 9 10 11 12 13 14 15 16 17 18 20 21 23 25 26 27 28 29 30 31 32 33 34 36 38 39 40 41 42 43 44 46 47 48 49 50 51 52 53 54 55 58 59\n0 1 2 3 4 5 6 7 8 10 11 12 14 16 17 18 19 20 21 22 23 24 25 27 29 30 31 32 33 34 35 37 38 39 40 41 42 43 44 45 46 49 50 51 52 53 56 58 59\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "49 97\n0 1 2 3 5 8 11 14 19 23 26 29 32 34 35 37 39 41 43 44 45 46 51 53 63 64 65 66 67 70 71 72 73 76 77 78 79 81 83 84 86 87 90 91 92 93 94 95 96\n0 3 4 5 6 7 8 9 10 11 12 13 16 18 21 24 29 33 36 39 42 44 45 47 49 51 53 54 55 56 61 63 73 74 75 76 77 80 81 82 83 86 87 88 89 91 93 94 96\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "50 58\n0 1 2 3 5 6 7 8 10 11 12 13 14 15 16 17 18 19 21 22 23 24 25 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 50 54 55 56 57\n0 1 3 4 5 6 7 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 31 32 36 37 38 39 40 41 42 43 45 46 47 48 50 51 52 53 54 55 56 57\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 10\n0 1 3 5 7\n0 1 2 4 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 8\n0 2 4 6 7\n0 2 3 5 7\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/761/B"
} | vfc_9906 |
apps | verifiable_code | 39 | Solve the following coding problem using the programming language python:
A string is a palindrome if it reads the same from the left to the right and from the right to the left. For example, the strings "kek", "abacaba", "r" and "papicipap" are palindromes, while the strings "abb" and "iq" are not.
A substring $s[l \ldots r]$ ($1 \leq l \leq r \leq |s|$) of a string $s = s_{1}s_{2} \ldots s_{|s|}$ is the string $s_{l}s_{l + 1} \ldots s_{r}$.
Anna does not like palindromes, so she makes her friends call her Ann. She also changes all the words she reads in a similar way. Namely, each word $s$ is changed into its longest substring that is not a palindrome. If all the substrings of $s$ are palindromes, she skips the word at all.
Some time ago Ann read the word $s$. What is the word she changed it into?
-----Input-----
The first line contains a non-empty string $s$ with length at most $50$ characters, containing lowercase English letters only.
-----Output-----
If there is such a substring in $s$ that is not a palindrome, print the maximum length of such a substring. Otherwise print $0$.
Note that there can be multiple longest substrings that are not palindromes, but their length is unique.
-----Examples-----
Input
mew
Output
3
Input
wuffuw
Output
5
Input
qqqqqqqq
Output
0
-----Note-----
"mew" is not a palindrome, so the longest substring of it that is not a palindrome, is the string "mew" itself. Thus, the answer for the first example is $3$.
The string "uffuw" is one of the longest non-palindrome substrings (of length $5$) of the string "wuffuw", so the answer for the second example is $5$.
All substrings of the string "qqqqqqqq" consist of equal characters so they are palindromes. This way, there are no non-palindrome substrings. Thus, the answer for the third example is $0$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
mx = 0
n = len(s)
for l in range(n):
for r in range(l, n):
if s[l:r+1] != s[l:r+1][::-1]:
mx = max(mx, r - l + 1)
print(mx)
``` | {
"language": "python",
"test_cases": [
{
"input": "mew\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "wuffuw\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "qqqqqqqq\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "ijvji\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "iiiiiii\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvvgiaahqmtjyuchikvvhvrebow\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "wobervhvvkihcuyjtmqhaaigvahheoqleromusrartldojsjvy\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "ijvxljt\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "fyhcncnchyf\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "ffffffffffff\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "fyhcncfsepqj\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "ybejrrlbcinttnicblrrjeby\n",
"output": "23\n",
"type": "stdin_stdout"
},
{
"input": "yyyyyyyyyyyyyyyyyyyyyyyyy\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "ybejrrlbcintahovgjddrqatv\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "oftmhcmclgyqaojljoaqyglcmchmtfo\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "oooooooooooooooooooooooooooooooo\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "oftmhcmclgyqaojllbotztajglsmcilv\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"input": "gxandbtgpbknxvnkjaajknvxnkbpgtbdnaxg\n",
"output": "35\n",
"type": "stdin_stdout"
},
{
"input": "gggggggggggggggggggggggggggggggggggg\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "gxandbtgpbknxvnkjaygommzqitqzjfalfkk\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "fcliblymyqckxvieotjooojtoeivxkcqymylbilcf\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "fffffffffffffffffffffffffffffffffffffffffff\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "fcliblymyqckxvieotjootiqwtyznhhvuhbaixwqnsy\n",
"output": "43\n",
"type": "stdin_stdout"
},
{
"input": "rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "rajccqwqnqmshmerpvjyfepxwpxyldzpzhctqjnstxyfmlhiy\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "a\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "abca\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "aaaaabaaaaa\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "aba\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "asaa\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "aabaa\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "aabbaa\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "abcdaaa\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "aaholaa\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "abcdefghijka\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "aaadcba\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "aaaabaaaa\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "abaa\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "abcbaa\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "ab\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "l\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "aaaabcaaaa\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "abbaaaaaabba\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "abaaa\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "baa\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaabbba\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "ccbcc\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "bbbaaab\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "abaaaaaaaa\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "abaaba\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "aabsdfaaaa\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "aaaba\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "aaabaaa\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "baaabbb\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "ccbbabbcc\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "cabc\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "aabcd\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "abcdea\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "bbabb\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "aaaaabababaaaaa\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "bbabbb\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "aababd\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "abaaaa\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaabbba\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "aabca\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "aaabccbaaa\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaaaaaaaaaaaaab\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "babb\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "abcaa\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "qwqq\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaaaabbbbbbbbbbbbbbbaaaaaaaaaaaaaaaaaaaaaa\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"input": "aaab\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaabaaaaa\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "wwuww\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "aaaaabcbaaaaa\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "aaabbbaaa\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "aabcbaa\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "abccdefccba\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "aabbcbbaa\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "aaaabbaaaa\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "aabcda\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "abbca\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaabbaaa\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "sssssspssssss\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "sdnmsdcs\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "aaabbbccbbbaaa\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "cbdbdc\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "abb\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "abcdefaaaa\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "abbbaaa\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "v\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "abccbba\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "axyza\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "abcdefgaaaa\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "aaabcdaaa\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "aaaacaaaa\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaa\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "abbbaa\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "abcdee\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "oom\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "aabcaa\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "abba\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "aaca\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "aacbca\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "ababa\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "abcda\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "cccaaccc\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "aaabcda\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "aa\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "aabaaaa\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "abbaaaa\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "aaabcbaaa\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "aabba\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "xyxx\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaaaaabc\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "bbaaaabb\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "aaabaa\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "sssssabsssss\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "bbbaaaabbb\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "abbbbaaaa\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "wwufuww\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "oowoo\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "cccaccc\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "aaa\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "bbbcc\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "abcdef\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "abbba\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "aab\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "aaba\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "azbyaaa\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "oooooiooooo\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "aabbbbbaaaaaa\n",
"output": "13\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/981/A"
} | vfc_9910 |
apps | verifiable_code | 40 | Solve the following coding problem using the programming language python:
Is it rated?
Here it is. The Ultimate Question of Competitive Programming, Codeforces, and Everything. And you are here to answer it.
Another Codeforces round has been conducted. No two participants have the same number of points. For each participant, from the top to the bottom of the standings, their rating before and after the round is known.
It's known that if at least one participant's rating has changed, then the round was rated for sure.
It's also known that if the round was rated and a participant with lower rating took a better place in the standings than a participant with higher rating, then at least one round participant's rating has changed.
In this problem, you should not make any other assumptions about the rating system.
Determine if the current round is rated, unrated, or it's impossible to determine whether it is rated of not.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 1000) — the number of round participants.
Each of the next n lines contains two integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ 4126) — the rating of the i-th participant before and after the round, respectively. The participants are listed in order from the top to the bottom of the standings.
-----Output-----
If the round is rated for sure, print "rated". If the round is unrated for sure, print "unrated". If it's impossible to determine whether the round is rated or not, print "maybe".
-----Examples-----
Input
6
3060 3060
2194 2194
2876 2903
2624 2624
3007 2991
2884 2884
Output
rated
Input
4
1500 1500
1300 1300
1200 1200
1400 1400
Output
unrated
Input
5
3123 3123
2777 2777
2246 2246
2246 2246
1699 1699
Output
maybe
-----Note-----
In the first example, the ratings of the participants in the third and fifth places have changed, therefore, the round was rated.
In the second example, no one's rating has changed, but the participant in the second place has lower rating than the participant in the fourth place. Therefore, if the round was rated, someone's rating would've changed for sure.
In the third example, no one's rating has changed, and the participants took places in non-increasing order of their rating. Therefore, it's impossible to determine whether the round is rated or not.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
'''input
5
3123 3123
2777 2777
2246 2246
2246 2246
1699 1699
'''
n = int(input())
x = []
f = 0
for _ in range(n):
a, b = list(map(int, input().split()))
if a != b:
f = 1
x.append(a)
if f == 1:
print("rated")
elif sorted(x)[::-1] == x:
print("maybe")
else:
print("unrated")
``` | {
"language": "python",
"test_cases": [
{
"input": "6\n3060 3060\n2194 2194\n2876 2903\n2624 2624\n3007 2991\n2884 2884\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "4\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n1 1\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n4126 4126\n4126 4126\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "10\n446 446\n1331 1331\n3594 3594\n1346 1902\n91 91\n3590 3590\n2437 2437\n4007 3871\n2797 699\n1423 1423\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "10\n4078 4078\n2876 2876\n1061 1061\n3721 3721\n143 143\n2992 2992\n3279 3279\n3389 3389\n1702 1702\n1110 1110\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "10\n4078 4078\n3721 3721\n3389 3389\n3279 3279\n2992 2992\n2876 2876\n1702 1702\n1110 1110\n1061 1061\n143 143\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n3936 3936\n2967 2967\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n2 2\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 2\n1 1\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 1\n1 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n2967 2967\n3936 3936\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1200 1200\n1200 1200\n1300 1300\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 3\n2 2\n1 1\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n1 1\n2 2\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 2\n3 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 5\n4 4\n3 4\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n200 200\n200 200\n300 300\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n2 2\n3 3\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2245 2245\n1699 1699\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n10 10\n8 8\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "3\n1500 1500\n1500 1500\n1600 1600\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1500 1500\n1500 1500\n1700 1700\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "4\n100 100\n100 100\n70 70\n80 80\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n2 1\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 5\n4 3\n3 3\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1600 1650\n1500 1550\n1400 1450\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "4\n2000 2000\n1500 1500\n1500 1500\n1700 1700\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "4\n1500 1500\n1400 1400\n1400 1400\n1700 1700\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1600 1600\n1400 1400\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 1\n9 8\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 1\n1 1\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "4\n4123 4123\n4123 4123\n2670 2670\n3670 3670\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 2\n3 3\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n10 11\n5 4\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n15 14\n13 12\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 1\n2 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n2670 2670\n3670 3670\n4106 4106\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 5\n3 3\n2 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n10 9\n10 10\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1011 1011\n1011 999\n2200 2100\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 3\n5 5\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1500 1500\n3000 2000\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 6\n5 5\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n2000 2000\n1500 1501\n500 500\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 3\n2 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 3\n2 2\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n1 1\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "4\n3123 3123\n2777 2777\n2246 2246\n1699 1699\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n15 14\n14 13\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "4\n3000 3000\n2900 2900\n3000 3000\n2900 2900\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "6\n30 3060\n24 2194\n26 2903\n24 2624\n37 2991\n24 2884\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n100 99\n100 100\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2\n1 1\n1 1\n2 2\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n100 101\n100 100\n100 100\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "4\n1000 1001\n900 900\n950 950\n890 890\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 3\n1 1\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 2\n1 1\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 2\n2 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 2\n3 3\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n2 2\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 2\n3 3\n3 3\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "4\n1500 1501\n1300 1300\n1200 1200\n1400 1400\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1000 1000\n500 500\n400 300\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n3000 3000\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n2 3\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 2\n6 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "5\n3123 3123\n1699 1699\n2777 2777\n2246 2246\n2246 2246\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1500 1500\n1600 1600\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2241 2241\n1699 1699\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n20 30\n10 5\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n2 2\n1 1\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n3 3\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 5\n4 4\n3 3\n2 2\n1 1\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 2\n2 1\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n100 100\n90 89\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1000 900\n2000 2000\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n50 10\n10 50\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n200 200\n100 100\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 2\n2 2\n3 3\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1000 1000\n300 300\n100 100\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2\n2 2\n3 3\n4 4\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 3\n6 3\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1200 1100\n1200 1000\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 5\n4 4\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 5\n3 3\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "5\n1500 1500\n1300 1300\n1200 1200\n1400 1400\n1100 1100\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "5\n10 10\n9 9\n8 8\n7 7\n6 6\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "3\n1000 1000\n300 300\n10 10\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "5\n6 6\n5 5\n4 4\n3 3\n2 2\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 3\n1 1\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2\n2 2\n2 2\n3 3\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1000 1000\n700 700\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 3\n5 3\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1000 1000\n1100 1100\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "4\n5 5\n4 4\n3 3\n2 2\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n2 3\n2 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n1 3\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 3\n1 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "4\n1501 1500\n1300 1300\n1200 1200\n1400 1400\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1\n2 2\n3 3\n4 4\n5 5\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n10 10\n1 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "6\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n1699 1699\n1900 1900\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "6\n3123 3123\n2777 2777\n3000 3000\n2246 2246\n2246 2246\n1699 1699\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n100 100\n110 110\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 3\n3 3\n4 4\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 3\n3 2\n4 4\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 2\n4 4\n3 3\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 4\n3 3\n2 2\n1 1\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n3 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "5\n3123 3123\n2777 2777\n2246 2246\n2246 2246\n2699 2699\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 3\n3 3\n3 4\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2\n2 2\n3 3\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2\n1 2\n1 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 1\n2 1\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n3 4\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 2\n2 3\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1500 1500\n1600 1600\n1600 1600\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n3 3\n4 4\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n2 2\n2 2\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n10 12\n8 8\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "5\n1200 1200\n1500 1500\n1500 1500\n1500 1500\n1500 1500\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n2 2\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1500 1400\n1200 1200\n1100 1100\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n10 12\n10 10\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "3\n1500 1500\n1400 1400\n1300 1300\n",
"output": "maybe\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 3\n4 4\n5 5\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 6\n3 5\n4 4\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 6\n4 6\n",
"output": "rated\n",
"type": "stdin_stdout"
},
{
"input": "4\n10 10\n10 10\n7 7\n8 8\n",
"output": "unrated\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 4\n3 3\n",
"output": "maybe\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/807/A"
} | vfc_9914 |
apps | verifiable_code | 41 | Solve the following coding problem using the programming language python:
You are given the array of integer numbers a_0, a_1, ..., a_{n} - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 2·10^5) — length of the array a. The second line contains integer elements of the array separated by single spaces ( - 10^9 ≤ a_{i} ≤ 10^9).
-----Output-----
Print the sequence d_0, d_1, ..., d_{n} - 1, where d_{i} is the difference of indices between i and nearest j such that a_{j} = 0. It is possible that i = j.
-----Examples-----
Input
9
2 1 0 3 0 0 3 2 4
Output
2 1 0 1 0 0 1 2 3
Input
5
0 1 2 3 4
Output
0 1 2 3 4
Input
7
5 6 0 1 -2 3 4
Output
2 1 0 1 2 3 4
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
inf = 10 ** 6
n = int(input())
a = list(map(int, input().split()))
dist = [inf] * n
for i in range(len(a)):
if not a[i]:
dist[i] = 0
cur = 1
i1 = i
while i1 - 1 > - 1 and a[i1 - 1] != 0:
dist[i1 - 1] = min(dist[i1 - 1], cur)
i1 -= 1
cur += 1
i1 = i
cur = 1
while i1 + 1 < n and a[i1 + 1] != 0:
dist[i1 + 1] = min(dist[i1 + 1], cur)
i1 += 1
cur += 1
print(*dist)
``` | {
"language": "python",
"test_cases": [
{
"input": "9\n2 1 0 3 0 0 3 2 4\n",
"output": "2 1 0 1 0 0 1 2 3 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 1 2 3 4\n",
"output": "0 1 2 3 4 ",
"type": "stdin_stdout"
},
{
"input": "7\n5 6 0 1 -2 3 4\n",
"output": "2 1 0 1 2 3 4 ",
"type": "stdin_stdout"
},
{
"input": "1\n0\n",
"output": "0 ",
"type": "stdin_stdout"
},
{
"input": "2\n0 0\n",
"output": "0 0 ",
"type": "stdin_stdout"
},
{
"input": "2\n0 1\n",
"output": "0 1 ",
"type": "stdin_stdout"
},
{
"input": "2\n1 0\n",
"output": "1 0 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 1000000000 1000000000 1000000000 1000000000\n",
"output": "0 1 2 3 4 ",
"type": "stdin_stdout"
},
{
"input": "5\n-1000000000 -1000000000 0 1000000000 1000000000\n",
"output": "2 1 0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "5\n-1000000000 1000000000 1000000000 1000000000 0\n",
"output": "4 3 2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "15\n1000000000 -1000000000 -1000000000 1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 -1000000000 -1000000000 -1000000000 -1000000000 1000000000 0\n",
"output": "14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "15\n0 0 0 0 1000000000 -1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000\n",
"output": "0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 ",
"type": "stdin_stdout"
},
{
"input": "15\n-1000000000 1000000000 1000000000 -1000000000 -1000000000 1000000000 0 -1000000000 -1000000000 0 0 1000000000 -1000000000 0 -1000000000\n",
"output": "6 5 4 3 2 1 0 1 1 0 0 1 1 0 1 ",
"type": "stdin_stdout"
},
{
"input": "15\n-1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000 1000000000 -1000000000 1000000000 1000000000 1000000000 0 0 0 0\n",
"output": "11 10 9 8 7 6 5 4 3 2 1 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "4\n0 0 2 0\n",
"output": "0 0 1 0 ",
"type": "stdin_stdout"
},
{
"input": "15\n1 2 3 4 0 1 2 3 -5 -4 -3 -1 0 5 4\n",
"output": "4 3 2 1 0 1 2 3 4 3 2 1 0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "2\n0 -1\n",
"output": "0 1 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 -1 -1 -1 0\n",
"output": "0 1 2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 0 -1 0\n",
"output": "0 0 0 1 0 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 0 -1\n",
"output": "0 0 1 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 -1 -1\n",
"output": "0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "12\n0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 0\n",
"output": "0 1 2 3 4 5 5 4 3 2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "18\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -1\n",
"output": "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 ",
"type": "stdin_stdout"
},
{
"input": "30\n0 0 0 0 0 0 0 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1\n",
"output": "0 0 0 0 0 0 0 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 ",
"type": "stdin_stdout"
},
{
"input": "1\n0\n",
"output": "0 ",
"type": "stdin_stdout"
},
{
"input": "1\n0\n",
"output": "0 ",
"type": "stdin_stdout"
},
{
"input": "1\n0\n",
"output": "0 ",
"type": "stdin_stdout"
},
{
"input": "2\n0 -1000000000\n",
"output": "0 1 ",
"type": "stdin_stdout"
},
{
"input": "2\n0 1000000000\n",
"output": "0 1 ",
"type": "stdin_stdout"
},
{
"input": "2\n-1000000000 0\n",
"output": "1 0 ",
"type": "stdin_stdout"
},
{
"input": "2\n0 0\n",
"output": "0 0 ",
"type": "stdin_stdout"
},
{
"input": "2\n0 0\n",
"output": "0 0 ",
"type": "stdin_stdout"
},
{
"input": "2\n0 0\n",
"output": "0 0 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 -1000000000 -1000000000\n",
"output": "0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 1000000000 1000000000\n",
"output": "0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "3\n1000000000 1000000000 0\n",
"output": "2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 0 -1000000000\n",
"output": "0 0 1 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 1000000000 0\n",
"output": "0 1 0 ",
"type": "stdin_stdout"
},
{
"input": "3\n-1000000000 0 0\n",
"output": "1 0 0 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 0 0\n",
"output": "0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 0 0\n",
"output": "0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 0 0\n",
"output": "0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "4\n0 -1000000000 -1000000000 -1000000000\n",
"output": "0 1 2 3 ",
"type": "stdin_stdout"
},
{
"input": "4\n1000000000 -1000000000 0 -1000000000\n",
"output": "2 1 0 1 ",
"type": "stdin_stdout"
},
{
"input": "4\n1000000000 -1000000000 1000000000 0\n",
"output": "3 2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "4\n0 0 -1000000000 1000000000\n",
"output": "0 0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "4\n0 0 1000000000 -1000000000\n",
"output": "0 0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "4\n-1000000000 1000000000 0 0\n",
"output": "2 1 0 0 ",
"type": "stdin_stdout"
},
{
"input": "4\n0 0 0 -1000000000\n",
"output": "0 0 0 1 ",
"type": "stdin_stdout"
},
{
"input": "4\n1000000000 0 0 0\n",
"output": "1 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "4\n1000000000 0 0 0\n",
"output": "1 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "4\n0 0 0 0\n",
"output": "0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "4\n0 0 0 0\n",
"output": "0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "4\n0 0 0 0\n",
"output": "0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 1000000000 1000000000 1000000000 1000000000\n",
"output": "0 1 2 3 4 ",
"type": "stdin_stdout"
},
{
"input": "5\n1000000000 -1000000000 -1000000000 1000000000 0\n",
"output": "4 3 2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "5\n1000000000 -1000000000 1000000000 -1000000000 0\n",
"output": "4 3 2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 -1000000000 -1000000000 -1000000000\n",
"output": "0 0 1 2 3 ",
"type": "stdin_stdout"
},
{
"input": "5\n1000000000 0 -1000000000 0 -1000000000\n",
"output": "1 0 1 0 1 ",
"type": "stdin_stdout"
},
{
"input": "5\n1000000000 1000000000 1000000000 0 0\n",
"output": "3 2 1 0 0 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 0 -1000000000 -1000000000\n",
"output": "0 0 0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "5\n-1000000000 1000000000 0 0 0\n",
"output": "2 1 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "5\n1000000000 1000000000 0 0 0\n",
"output": "2 1 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 0 0 -1000000000\n",
"output": "0 0 0 0 1 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 1000000000 0 0\n",
"output": "0 0 1 0 0 ",
"type": "stdin_stdout"
},
{
"input": "5\n1000000000 0 0 0 0\n",
"output": "1 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 0 0 0\n",
"output": "0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 0 0 0\n",
"output": "0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 0 0 0\n",
"output": "0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "6\n0 1000000000 -1000000000 1000000000 -1000000000 1000000000\n",
"output": "0 1 2 3 4 5 ",
"type": "stdin_stdout"
},
{
"input": "6\n-1000000000 -1000000000 1000000000 1000000000 1000000000 0\n",
"output": "5 4 3 2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "6\n-1000000000 1000000000 -1000000000 1000000000 -1000000000 0\n",
"output": "5 4 3 2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "6\n0 0 1000000000 1000000000 -1000000000 -1000000000\n",
"output": "0 0 1 2 3 4 ",
"type": "stdin_stdout"
},
{
"input": "6\n0 0 1000000000 1000000000 -1000000000 -1000000000\n",
"output": "0 0 1 2 3 4 ",
"type": "stdin_stdout"
},
{
"input": "6\n-1000000000 1000000000 -1000000000 -1000000000 0 0\n",
"output": "4 3 2 1 0 0 ",
"type": "stdin_stdout"
},
{
"input": "6\n0 0 0 -1000000000 1000000000 1000000000\n",
"output": "0 0 0 1 2 3 ",
"type": "stdin_stdout"
},
{
"input": "6\n-1000000000 1000000000 -1000000000 0 0 0\n",
"output": "3 2 1 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "6\n-1000000000 -1000000000 1000000000 0 0 0\n",
"output": "3 2 1 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "6\n0 0 0 0 -1000000000 1000000000\n",
"output": "0 0 0 0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "6\n0 0 0 -1000000000 1000000000 0\n",
"output": "0 0 0 1 1 0 ",
"type": "stdin_stdout"
},
{
"input": "6\n1000000000 1000000000 0 0 0 0\n",
"output": "2 1 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "6\n0 0 0 0 0 -1000000000\n",
"output": "0 0 0 0 0 1 ",
"type": "stdin_stdout"
},
{
"input": "6\n0 0 0 1000000000 0 0\n",
"output": "0 0 0 1 0 0 ",
"type": "stdin_stdout"
},
{
"input": "6\n1000000000 0 0 0 0 0\n",
"output": "1 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "6\n0 0 0 0 0 0\n",
"output": "0 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "6\n0 0 0 0 0 0\n",
"output": "0 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "6\n0 0 0 0 0 0\n",
"output": "0 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 -1000000000 1000000000 -1000000000 -1000000000 -1000000000 -1000000000\n",
"output": "0 1 2 3 4 5 6 ",
"type": "stdin_stdout"
},
{
"input": "7\n1000000000 1000000000 -1000000000 0 -1000000000 1000000000 -1000000000\n",
"output": "3 2 1 0 1 2 3 ",
"type": "stdin_stdout"
},
{
"input": "7\n1000000000 1000000000 -1000000000 1000000000 -1000000000 -1000000000 0\n",
"output": "6 5 4 3 2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 0 1000000000 1000000000 1000000000 1000000000 -1000000000\n",
"output": "0 0 1 2 3 4 5 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 1000000000 1000000000 -1000000000 1000000000 1000000000 0\n",
"output": "0 1 2 3 2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "7\n1000000000 -1000000000 -1000000000 1000000000 -1000000000 0 0\n",
"output": "5 4 3 2 1 0 0 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 0 0 1000000000 -1000000000 -1000000000 1000000000\n",
"output": "0 0 0 1 2 3 4 ",
"type": "stdin_stdout"
},
{
"input": "7\n-1000000000 0 0 -1000000000 0 -1000000000 1000000000\n",
"output": "1 0 0 1 0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "7\n1000000000 1000000000 1000000000 -1000000000 0 0 0\n",
"output": "4 3 2 1 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 0 0 0 -1000000000 -1000000000 1000000000\n",
"output": "0 0 0 0 1 2 3 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 -1000000000 0 0 0 -1000000000 1000000000\n",
"output": "0 1 0 0 0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "7\n1000000000 1000000000 1000000000 0 0 0 0\n",
"output": "3 2 1 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 0 0 0 0 -1000000000 1000000000\n",
"output": "0 0 0 0 0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 -1000000000 0 0 0 0 -1000000000\n",
"output": "0 1 0 0 0 0 1 ",
"type": "stdin_stdout"
},
{
"input": "7\n-1000000000 1000000000 0 0 0 0 0\n",
"output": "2 1 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 0 0 0 0 0 -1000000000\n",
"output": "0 0 0 0 0 0 1 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 0 0 0 0 1000000000 0\n",
"output": "0 0 0 0 0 1 0 ",
"type": "stdin_stdout"
},
{
"input": "7\n1000000000 0 0 0 0 0 0\n",
"output": "1 0 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 0 0 0 0 0 0\n",
"output": "0 0 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 0 0 0 0 0 0\n",
"output": "0 0 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "7\n0 0 0 0 0 0 0\n",
"output": "0 0 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 -1000000000 -1000000000 1000000000 1000000000 1000000000 1000000000 -1000000000\n",
"output": "0 1 2 3 4 5 6 7 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 -1000000000 1000000000 1000000000 1000000000 -1000000000 1000000000 1000000000\n",
"output": "0 1 2 3 4 5 6 7 ",
"type": "stdin_stdout"
},
{
"input": "8\n1000000000 -1000000000 -1000000000 -1000000000 1000000000 1000000000 1000000000 0\n",
"output": "7 6 5 4 3 2 1 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 0 -1000000000 -1000000000 1000000000 1000000000 1000000000 -1000000000\n",
"output": "0 0 1 2 3 4 5 6 ",
"type": "stdin_stdout"
},
{
"input": "8\n1000000000 0 0 -1000000000 -1000000000 1000000000 -1000000000 -1000000000\n",
"output": "1 0 0 1 2 3 4 5 ",
"type": "stdin_stdout"
},
{
"input": "8\n1000000000 -1000000000 1000000000 -1000000000 -1000000000 -1000000000 0 0\n",
"output": "6 5 4 3 2 1 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 0 0 1000000000 1000000000 -1000000000 -1000000000 -1000000000\n",
"output": "0 0 0 1 2 3 4 5 ",
"type": "stdin_stdout"
},
{
"input": "8\n-1000000000 0 0 1000000000 1000000000 0 -1000000000 1000000000\n",
"output": "1 0 0 1 1 0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "8\n1000000000 1000000000 1000000000 -1000000000 -1000000000 0 0 0\n",
"output": "5 4 3 2 1 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 0 0 0 1000000000 1000000000 1000000000 -1000000000\n",
"output": "0 0 0 0 1 2 3 4 ",
"type": "stdin_stdout"
},
{
"input": "8\n1000000000 0 1000000000 -1000000000 0 -1000000000 0 0\n",
"output": "1 0 1 1 0 1 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n-1000000000 -1000000000 -1000000000 -1000000000 0 0 0 0\n",
"output": "4 3 2 1 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 0 0 0 0 1000000000 1000000000 -1000000000\n",
"output": "0 0 0 0 0 1 2 3 ",
"type": "stdin_stdout"
},
{
"input": "8\n-1000000000 0 -1000000000 0 0 1000000000 0 0\n",
"output": "1 0 1 0 0 1 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n1000000000 1000000000 1000000000 0 0 0 0 0\n",
"output": "3 2 1 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 0 0 0 0 0 -1000000000 -1000000000\n",
"output": "0 0 0 0 0 0 1 2 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 0 0 1000000000 -1000000000 0 0 0\n",
"output": "0 0 0 1 1 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n1000000000 1000000000 0 0 0 0 0 0\n",
"output": "2 1 0 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 0 0 0 0 0 0 -1000000000\n",
"output": "0 0 0 0 0 0 0 1 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 1000000000 0 0 0 0 0 0\n",
"output": "0 1 0 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n1000000000 0 0 0 0 0 0 0\n",
"output": "1 0 0 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 0 0 0 0 0 0 0\n",
"output": "0 0 0 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 0 0 0 0 0 0 0\n",
"output": "0 0 0 0 0 0 0 0 ",
"type": "stdin_stdout"
},
{
"input": "8\n0 0 0 0 0 0 0 0\n",
"output": "0 0 0 0 0 0 0 0 ",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/803/B"
} | vfc_9918 |
apps | verifiable_code | 42 | Solve the following coding problem using the programming language python:
You are given a binary string $s$.
Find the number of distinct cyclical binary strings of length $n$ which contain $s$ as a substring.
The cyclical string $t$ contains $s$ as a substring if there is some cyclical shift of string $t$, such that $s$ is a substring of this cyclical shift of $t$.
For example, the cyclical string "000111" contains substrings "001", "01110" and "10", but doesn't contain "0110" and "10110".
Two cyclical strings are called different if they differ from each other as strings. For example, two different strings, which differ from each other by a cyclical shift, are still considered different cyclical strings.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 40$) — the length of the target string $t$.
The next line contains the string $s$ ($1 \le |s| \le n$) — the string which must be a substring of cyclical string $t$. String $s$ contains only characters '0' and '1'.
-----Output-----
Print the only integer — the number of distinct cyclical binary strings $t$, which contain $s$ as a substring.
-----Examples-----
Input
2
0
Output
3
Input
4
1010
Output
2
Input
20
10101010101010
Output
962
-----Note-----
In the first example, there are three cyclical strings, which contain "0" — "00", "01" and "10".
In the second example, there are only two such strings — "1010", "0101".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n=int(input())
s=[c=='1' for c in input()]
m=len(s)
z=[[0,0]]
for c in s:
ind = z[-1][c]
z[-1][c] = len(z)
z.append(z[ind][:])
assert(len(z) == m+1)
z[m][0] = z[m][1] = m # make it sticky
# how many things match directly
dp = [0 for _ in range(m+1)]
dp[0] = 1
for i in range(n):
ndp = [0 for _ in range(m+1)]
for i in range(m+1):
ndp[z[i][0]] += dp[i]
ndp[z[i][1]] += dp[i]
dp = ndp
res = dp[m]
for k in range(1, m):
s0 = 0
for c in s[-k:]:
s0 = z[s0][c]
dp = [0 for _ in range(m+1)]
dp[s0] = 1
for i in range(n - k):
ndp = [0 for _ in range(m+1)]
for i in range(m+1):
ndp[z[i][0]] += dp[i]
ndp[z[i][1]] += dp[i]
dp = ndp
for s1 in range(m): # skip m
v = dp[s1]
for c in s[-k:]:
if s1 == m: v = 0
s1 = z[s1][c]
if s1 == m: res += v
print(res)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n0\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "4\n1010\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "20\n10101010101010\n",
"output": "962",
"type": "stdin_stdout"
},
{
"input": "2\n11\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "5\n00101\n",
"output": "5",
"type": "stdin_stdout"
},
{
"input": "10\n100101\n",
"output": "155",
"type": "stdin_stdout"
},
{
"input": "4\n0011\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "7\n1100\n",
"output": "56",
"type": "stdin_stdout"
},
{
"input": "8\n01010001\n",
"output": "8",
"type": "stdin_stdout"
},
{
"input": "6\n10\n",
"output": "62",
"type": "stdin_stdout"
},
{
"input": "17\n011100101100110\n",
"output": "68",
"type": "stdin_stdout"
},
{
"input": "22\n1110011010100111\n",
"output": "1408",
"type": "stdin_stdout"
},
{
"input": "17\n1110110111010101\n",
"output": "34",
"type": "stdin_stdout"
},
{
"input": "11\n10100000100\n",
"output": "11",
"type": "stdin_stdout"
},
{
"input": "20\n10100001011\n",
"output": "10230",
"type": "stdin_stdout"
},
{
"input": "16\n101011\n",
"output": "15248",
"type": "stdin_stdout"
},
{
"input": "33\n0001100010001100110000\n",
"output": "67584",
"type": "stdin_stdout"
},
{
"input": "30\n111001000100\n",
"output": "7857600",
"type": "stdin_stdout"
},
{
"input": "40\n1001\n",
"output": "1029761794578",
"type": "stdin_stdout"
},
{
"input": "31\n101\n",
"output": "2110188507",
"type": "stdin_stdout"
},
{
"input": "18\n001000011010000\n",
"output": "144",
"type": "stdin_stdout"
},
{
"input": "36\n110110010000\n",
"output": "603021324",
"type": "stdin_stdout"
},
{
"input": "40\n00000111111100110111000010000010101001\n",
"output": "160",
"type": "stdin_stdout"
},
{
"input": "39\n000000000000000000000000000000000000001\n",
"output": "39",
"type": "stdin_stdout"
},
{
"input": "37\n0101010101010101010101010101010101010\n",
"output": "37",
"type": "stdin_stdout"
},
{
"input": "31\n11011101110000011100\n",
"output": "63488",
"type": "stdin_stdout"
},
{
"input": "34\n110000100\n",
"output": "1121963008",
"type": "stdin_stdout"
},
{
"input": "35\n111111100100100\n",
"output": "36696800",
"type": "stdin_stdout"
},
{
"input": "20\n100010000\n",
"output": "40840",
"type": "stdin_stdout"
},
{
"input": "21\n01011101001010001\n",
"output": "336",
"type": "stdin_stdout"
},
{
"input": "11\n00010\n",
"output": "638",
"type": "stdin_stdout"
},
{
"input": "16\n10011000100001\n",
"output": "64",
"type": "stdin_stdout"
},
{
"input": "39\n11101001101111001011110111010010111001\n",
"output": "78",
"type": "stdin_stdout"
},
{
"input": "32\n10101100\n",
"output": "519167992",
"type": "stdin_stdout"
},
{
"input": "13\n111\n",
"output": "5435",
"type": "stdin_stdout"
},
{
"input": "4\n01\n",
"output": "14",
"type": "stdin_stdout"
},
{
"input": "8\n100\n",
"output": "208",
"type": "stdin_stdout"
},
{
"input": "9\n1110\n",
"output": "270",
"type": "stdin_stdout"
},
{
"input": "1\n1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "20\n01100111000\n",
"output": "10230",
"type": "stdin_stdout"
},
{
"input": "5\n1\n",
"output": "31",
"type": "stdin_stdout"
},
{
"input": "38\n11111010100111100011\n",
"output": "9961415",
"type": "stdin_stdout"
},
{
"input": "24\n1101110111000111011\n",
"output": "768",
"type": "stdin_stdout"
},
{
"input": "6\n101111\n",
"output": "6",
"type": "stdin_stdout"
},
{
"input": "39\n1010001010100100001\n",
"output": "40894230",
"type": "stdin_stdout"
},
{
"input": "34\n1111001001101011101101101\n",
"output": "17408",
"type": "stdin_stdout"
},
{
"input": "35\n11100110100\n",
"output": "585195800",
"type": "stdin_stdout"
},
{
"input": "7\n1111\n",
"output": "29",
"type": "stdin_stdout"
},
{
"input": "35\n010100010101011110110101000\n",
"output": "8960",
"type": "stdin_stdout"
},
{
"input": "18\n110101110001\n",
"output": "1152",
"type": "stdin_stdout"
},
{
"input": "10\n0110101\n",
"output": "75",
"type": "stdin_stdout"
},
{
"input": "38\n0111110111100000000000100\n",
"output": "311296",
"type": "stdin_stdout"
},
{
"input": "32\n101011001\n",
"output": "263480312",
"type": "stdin_stdout"
},
{
"input": "39\n111011011000100\n",
"output": "654211584",
"type": "stdin_stdout"
},
{
"input": "31\n00101010000\n",
"output": "32331574",
"type": "stdin_stdout"
},
{
"input": "35\n100011111010001011100001\n",
"output": "71680",
"type": "stdin_stdout"
},
{
"input": "39\n1010000110\n",
"output": "20653344998",
"type": "stdin_stdout"
},
{
"input": "34\n1011010111111001100011110111\n",
"output": "2176",
"type": "stdin_stdout"
},
{
"input": "37\n100110110011100100100010110000011\n",
"output": "592",
"type": "stdin_stdout"
},
{
"input": "40\n1010100001001010110011000110001\n",
"output": "20480",
"type": "stdin_stdout"
},
{
"input": "30\n11110010111010001010111\n",
"output": "3840",
"type": "stdin_stdout"
},
{
"input": "36\n100101110110110111100110010011001\n",
"output": "288",
"type": "stdin_stdout"
},
{
"input": "40\n01011011110\n",
"output": "21354424310",
"type": "stdin_stdout"
},
{
"input": "36\n00001010001000010101111010\n",
"output": "36864",
"type": "stdin_stdout"
},
{
"input": "40\n111101001000110000111001110111111110111\n",
"output": "80",
"type": "stdin_stdout"
},
{
"input": "37\n1000101000000000011101011111010011\n",
"output": "296",
"type": "stdin_stdout"
},
{
"input": "31\n0111111101001100\n",
"output": "1015777",
"type": "stdin_stdout"
},
{
"input": "35\n00010000111011\n",
"output": "73382400",
"type": "stdin_stdout"
},
{
"input": "38\n11111111111111111111111111111111100000\n",
"output": "38",
"type": "stdin_stdout"
},
{
"input": "39\n000000000000000111111111111111111111111\n",
"output": "39",
"type": "stdin_stdout"
},
{
"input": "36\n000000000011111111111111111111111111\n",
"output": "36",
"type": "stdin_stdout"
},
{
"input": "37\n1111110000000000000000000000000000000\n",
"output": "37",
"type": "stdin_stdout"
},
{
"input": "37\n0000000000000000011111111111111111111\n",
"output": "37",
"type": "stdin_stdout"
},
{
"input": "39\n101010101010101010101010101010101010101\n",
"output": "39",
"type": "stdin_stdout"
},
{
"input": "38\n10101010101010101010101010101010101010\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "37\n1010101010101010101010101010101010101\n",
"output": "37",
"type": "stdin_stdout"
},
{
"input": "40\n0101010101010101010101010101010101010101\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "38\n00000000000000000000000000000000000000\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "37\n0011111111111011011111110111011111111\n",
"output": "37",
"type": "stdin_stdout"
},
{
"input": "35\n00001000110100100101101111110101111\n",
"output": "35",
"type": "stdin_stdout"
},
{
"input": "40\n0000000000100000100000000000000000000000\n",
"output": "40",
"type": "stdin_stdout"
},
{
"input": "37\n0000110000100100011101000100000001010\n",
"output": "37",
"type": "stdin_stdout"
},
{
"input": "40\n1111111111111011111111101111111111111111\n",
"output": "40",
"type": "stdin_stdout"
},
{
"input": "38\n10100000011100111001100101000100001000\n",
"output": "38",
"type": "stdin_stdout"
},
{
"input": "40\n1111110111111111111111011111111111111110\n",
"output": "40",
"type": "stdin_stdout"
},
{
"input": "40\n0000010010000000000001000110000001010100\n",
"output": "40",
"type": "stdin_stdout"
},
{
"input": "39\n100110001010001000000001010000000110100\n",
"output": "39",
"type": "stdin_stdout"
},
{
"input": "38\n01011110100111011\n",
"output": "79690256",
"type": "stdin_stdout"
},
{
"input": "37\n100110111000011010011010110011101\n",
"output": "592",
"type": "stdin_stdout"
},
{
"input": "30\n000000000110001011111011000\n",
"output": "240",
"type": "stdin_stdout"
},
{
"input": "33\n101110110010101\n",
"output": "8647584",
"type": "stdin_stdout"
},
{
"input": "34\n1101010100001111111\n",
"output": "1114095",
"type": "stdin_stdout"
},
{
"input": "32\n01100010110111100111110010\n",
"output": "2048",
"type": "stdin_stdout"
},
{
"input": "40\n000010101101010011111101011110010011\n",
"output": "640",
"type": "stdin_stdout"
},
{
"input": "32\n0111010100\n",
"output": "133105408",
"type": "stdin_stdout"
},
{
"input": "31\n0101100101100000111001\n",
"output": "15872",
"type": "stdin_stdout"
},
{
"input": "39\n00111\n",
"output": "419341377312",
"type": "stdin_stdout"
},
{
"input": "33\n00111101\n",
"output": "1068677566",
"type": "stdin_stdout"
},
{
"input": "37\n1010001011111100110101110\n",
"output": "151552",
"type": "stdin_stdout"
},
{
"input": "37\n111000011\n",
"output": "9626769261",
"type": "stdin_stdout"
},
{
"input": "37\n011111001111100010001011000001100111\n",
"output": "74",
"type": "stdin_stdout"
},
{
"input": "40\n0000\n",
"output": "848129718780",
"type": "stdin_stdout"
},
{
"input": "40\n1000\n",
"output": "1060965767804",
"type": "stdin_stdout"
},
{
"input": "40\n0100\n",
"output": "1029761794578",
"type": "stdin_stdout"
},
{
"input": "40\n1100\n",
"output": "1060965767804",
"type": "stdin_stdout"
},
{
"input": "40\n0010\n",
"output": "1029761794578",
"type": "stdin_stdout"
},
{
"input": "40\n1010\n",
"output": "1000453489698",
"type": "stdin_stdout"
},
{
"input": "40\n0110\n",
"output": "1029761794578",
"type": "stdin_stdout"
},
{
"input": "40\n1110\n",
"output": "1060965767804",
"type": "stdin_stdout"
},
{
"input": "40\n0001\n",
"output": "1060965767804",
"type": "stdin_stdout"
},
{
"input": "40\n0101\n",
"output": "1000453489698",
"type": "stdin_stdout"
},
{
"input": "40\n1101\n",
"output": "1029761794578",
"type": "stdin_stdout"
},
{
"input": "40\n0011\n",
"output": "1060965767804",
"type": "stdin_stdout"
},
{
"input": "40\n1011\n",
"output": "1029761794578",
"type": "stdin_stdout"
},
{
"input": "40\n0111\n",
"output": "1060965767804",
"type": "stdin_stdout"
},
{
"input": "40\n1111\n",
"output": "848129718780",
"type": "stdin_stdout"
},
{
"input": "40\n000\n",
"output": "1060965767805",
"type": "stdin_stdout"
},
{
"input": "40\n100\n",
"output": "1099282801648",
"type": "stdin_stdout"
},
{
"input": "40\n010\n",
"output": "1093624901051",
"type": "stdin_stdout"
},
{
"input": "40\n110\n",
"output": "1099282801648",
"type": "stdin_stdout"
},
{
"input": "40\n001\n",
"output": "1099282801648",
"type": "stdin_stdout"
},
{
"input": "40\n101\n",
"output": "1093624901051",
"type": "stdin_stdout"
},
{
"input": "40\n011\n",
"output": "1099282801648",
"type": "stdin_stdout"
},
{
"input": "40\n111\n",
"output": "1060965767805",
"type": "stdin_stdout"
},
{
"input": "40\n00\n",
"output": "1099282801649",
"type": "stdin_stdout"
},
{
"input": "40\n01\n",
"output": "1099511627774",
"type": "stdin_stdout"
},
{
"input": "40\n10\n",
"output": "1099511627774",
"type": "stdin_stdout"
},
{
"input": "40\n11\n",
"output": "1099282801649",
"type": "stdin_stdout"
},
{
"input": "40\n0\n",
"output": "1099511627775",
"type": "stdin_stdout"
},
{
"input": "40\n1\n",
"output": "1099511627775",
"type": "stdin_stdout"
},
{
"input": "1\n0\n",
"output": "1",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1038/F"
} | vfc_9922 |
apps | verifiable_code | 43 | Solve the following coding problem using the programming language python:
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
-----Input-----
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers x_{i} and y_{i} (|x|, |y| ≤ 10 000, x^2 + y^2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
-----Output-----
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
-----Examples-----
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from math import *
# stores counterclockwise angle between vector (1,0) and each vector in a
a = []
n = int(input())
for i in range(n):
x,y = list(map(int,input().split()))
# calculate counterclockwise angle between (1,0) and this vector
t = acos(x/sqrt(x**2+y**2))
a.append((i+1,[2*pi-t,t][y>=0],x,y))
cmp = lambda x:x[1]
a = sorted(a,key=cmp)
# construct pairs for adjacent vectors
b = []
for i in range(n):
i1,i2 = a[i][0],a[(i+1)%n][0]
x1,y1 = a[i][2:]
x2,y2 = a[(i+1)%n][2:]
inner_prod = x1*x2 + y1*y2
inner_prod *= abs(inner_prod)
norm_prod = ((x1**2+y1**2)*(x2**2+y2**2))
b.append((i1,i2,inner_prod,norm_prod))
# find the nearest vector
better = lambda p1,p2: p1[2]*p2[3]>p2[2]*p1[3]
ans = b[-1]
for i in range(n):
if better(b[i],ans):
ans = b[i]
print(ans[0],ans[1])
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n-1 0\n0 -1\n1 0\n1 1\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "6\n-1 0\n0 -1\n1 0\n1 1\n-4 -5\n-4 -6\n",
"output": "5 6\n",
"type": "stdin_stdout"
},
{
"input": "10\n8 6\n-7 -3\n9 8\n7 10\n-3 -8\n3 7\n6 -8\n-9 8\n9 2\n6 7\n",
"output": "1 3\n",
"type": "stdin_stdout"
},
{
"input": "20\n-9 8\n-7 3\n0 10\n3 7\n6 -9\n6 8\n7 -6\n-6 10\n-10 3\n-8 -10\n10 -2\n1 -8\n-8 10\n10 10\n10 6\n-5 6\n5 -8\n5 -9\n-9 -1\n9 2\n",
"output": "13 16\n",
"type": "stdin_stdout"
},
{
"input": "2\n351 -4175\n-328 -657\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n620 -1189\n8101 -2770\n3347 3473\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n-7061 -5800\n-3471 -9470\n-7639 2529\n5657 -6522\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n-7519 -3395\n-32 -257\n-4827 -1889\n9545 -7037\n2767 583\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "6\n-5120 -3251\n8269 -7984\n841 3396\n3136 -7551\n-1280 -3013\n-3263 -3278\n",
"output": "1 6\n",
"type": "stdin_stdout"
},
{
"input": "7\n-2722 6597\n-3303 200\n6508 -1021\n-1107 -1042\n6875 7616\n-3047 6749\n662 -1979\n",
"output": "1 6\n",
"type": "stdin_stdout"
},
{
"input": "8\n-36 749\n5126 943\n1165 533\n-1647 -5725\n5031 6532\n5956 8447\n2297 -2284\n1986 6937\n",
"output": "5 6\n",
"type": "stdin_stdout"
},
{
"input": "9\n-391 -1706\n995 -5756\n-5013 -154\n1121 3160\n-7111 8303\n-7303 -2414\n-7791 -935\n7576 -9361\n1072 203\n",
"output": "3 7\n",
"type": "stdin_stdout"
},
{
"input": "10\n-9920 -5477\n9691 -3200\n754 885\n-1895 1768\n-941 1588\n6293 -2631\n-2288 9129\n4067 696\n-6754 9869\n-5747 701\n",
"output": "5 9\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 0\n-1 0\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n0 1\n0 -1\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n2131 -3249\n-2131 3249\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n-5 1\n-5 -1\n5 0\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n-100 1\n-100 -1\n0 100\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 10\n10 1\n10 -1\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 0\n0 3\n1 -3\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n-1 0\n1 -1\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n-1 0\n10 -1\n1 0\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 10\n10 1\n-2 -2\n10 -1\n",
"output": "4 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n-6 0\n6 1\n6 -1\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n114 1\n-514 0\n114 -1\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-1 0\n0 -1\n-1 1\n1 0\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 1\n2 -1\n-1 1\n-1 -1\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 1\n3 -1\n0 3\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n9000 1\n9000 -1\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n-1 1\n-1 -1\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 1\n-1 -1\n0 20\n100 1\n-100 0\n100 -1\n",
"output": "6 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 0\n0 1\n-1 0\n-13 -1\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n-1 0\n1 -1\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n100 1\n-100 0\n100 -1\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n-100 1\n100 0\n-100 -1\n",
"output": "1 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 100\n0 -100\n-1 100\n",
"output": "1 3\n",
"type": "stdin_stdout"
},
{
"input": "11\n-7945 386\n7504 -576\n-6020 -8277\n930 9737\n1682 474\n-8279 1197\n2790 2607\n-5514 -9601\n-3159 5939\n-1806 4207\n-9073 -2138\n",
"output": "10 9\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n10000 -1\n1 1\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-7125 -1643\n-1235 4071\n-75 -8717\n2553 9278\n",
"output": "4 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n-6 0\n6 1\n6 -1\n0 6\n0 -6\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n5 5\n5 -5\n-555 1\n-555 -1\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1\n-1 1\n-1 -1\n2 -1\n",
"output": "4 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-1 -100\n1 -100\n-100 -100\n100 -100\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n1 -1\n-4 -6\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-1 -100\n1 -100\n100 -100\n-100 -100\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n-1 0\n0 -2\n-3 3\n4 0\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-2 0\n0 -3\n-5 5\n4 0\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 -100\n0 100\n-1 -100\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "5\n10000 2\n10000 -1\n10000 -5\n10000 -9\n10000 -13\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "8\n-9580 8545\n-9379 -1139\n5824 -391\n-8722 2765\n-1357 -5547\n-7700 217\n9323 -7008\n957 -8356\n",
"output": "6 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n5 5\n5 -5\n-500 1\n-500 -1\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "3\n30 1\n30 -1\n0 30\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n3966 -1107\n8007 -5457\n-7753 4945\n-2209 -4221\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 9999\n0 1\n10000 0\n10000 -1\n",
"output": "4 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n10000 1\n10000 -1\n-10000 0\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "13\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 8\n8 9\n9 10\n10 11\n11 12\n13 14\n12 13\n",
"output": "12 13\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 1\n2 -1\n0 1\n-1 0\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n10 3\n10 -3\n-500 1\n-500 -1\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 10000\n-1 1\n10000 0\n10000 -1\n",
"output": "4 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 1\n1 0\n1 -1\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n0 1\n1 -1\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1\n-1 1\n1 -2\n-1 -2\n",
"output": "4 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n0 -1\n-1 0\n-1 1\n1 0\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n-100 1\n-100 -1\n1 1\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n-3 1\n-3 -1\n2 -3\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 -1\n1 0\n0 1\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n-5 1\n0 5\n4 1\n0 -4\n-5 -1\n",
"output": "1 5\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 10000\n0 1\n10000 0\n9999 -1\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 3\n2 -3\n-3 2\n-3 -2\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 -3\n1 0\n0 1\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n-1 0\n-1 -1\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n-2 1\n-2 -1\n1 1\n1 -1\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 -1\n-1 1\n-1 -2\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n-1 -1\n1 -1\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 5\n-5 0\n5 -5\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 -2\n1 0\n-1 0\n10 -1\n",
"output": "4 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n-1000 1\n-1000 -1\n1000 0\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 1\n1 -1\n-1 1\n-1 -1\n1 -10000\n-1 -10000\n",
"output": "6 5\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n-1 0\n0 -1\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n5000 1\n5000 -1\n-2 -1\n2 -1\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n-1 1\n-1 -5\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n-5374 1323\n-4463 -8462\n6118 -7918\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n-6427 -6285\n-5386 -5267\n-3898 7239\n-3905 7252\n",
"output": "4 3\n",
"type": "stdin_stdout"
},
{
"input": "10\n-7 -3\n-2 8\n9 -9\n0 1\n4 5\n5 3\n-3 0\n10 2\n4 -1\n2 -10\n",
"output": "4 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n9999 1\n9999 -1\n-9998 1\n-10000 -1\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n10000 9999\n9999 9998\n9998 9997\n9997 9996\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-6285 -6427\n-5267 -5386\n7239 -3898\n7252 -3905\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n-6427 6285\n-5386 5267\n3898 -7239\n3905 -7252\n",
"output": "4 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n-6427 -6285\n-5386 -5267\n-3898 -7239\n-3905 -7252\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 1\n-1 -1\n1 -1\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n10000 1\n9998 -1\n-9999 1\n-9999 -1\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "3\n100 0\n100 2\n100 -1\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n-1 1\n-1 -1\n1 0\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n9844 9986\n181 9967\n-9812 -9925\n-194 -9900\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n9800 9981\n61 9899\n-9926 -9932\n-149 -9926\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n-9901 9900\n-10000 9899\n9899 9801\n9899 9900\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n9934 9989\n199 9949\n-9917 -9974\n-197 -9901\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "3\n-1 1\n1 0\n-1 -1\n",
"output": "1 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n-10 -10\n-10 -9\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n10000 -1\n-1 0\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n9999 1\n9999 -1\n-10000 1\n-10000 -1\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "3\n-5 1\n-5 -1\n1 0\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n10000 1\n-1 0\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n-9990 9995\n9994 -9991\n-9999 -9992\n9993 9992\n",
"output": "2 4\n",
"type": "stdin_stdout"
},
{
"input": "8\n1 0\n1 1\n0 1\n-1 1\n-1 0\n-1 -1\n0 -1\n1 -2\n",
"output": "7 8\n",
"type": "stdin_stdout"
},
{
"input": "3\n-9930 9932\n9909 -9909\n-9932 -9931\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n9876 9977\n127 9938\n-9820 -9934\n-120 -9921\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "3\n10000 -1\n-1 0\n0 -1\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n6427 -6285\n5386 -5267\n3898 7239\n3905 7252\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n9811 9970\n155 9994\n-9826 -9977\n-159 -9986\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n9851 9917\n74 9921\n-9855 -9916\n-77 -9984\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n9826 9977\n159 9986\n-9811 -9970\n-155 -9994\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n9849 9986\n148 9980\n-9800 -9999\n-116 -9927\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n9822 9967\n111 9905\n-9943 -9986\n-163 -9953\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n9959 9995\n113 9940\n-9965 -9931\n-148 -9945\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n9851 9972\n153 9983\n-9866 -9926\n-183 -9946\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n9816 -9979\n127 -9940\n-9876 9915\n-190 9978\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n9887 -9917\n138 -9977\n-9826 9995\n-68 9971\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n9936 -9965\n135 -9949\n-9928 9980\n-123 9908\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n9981 -9985\n191 -9956\n-9893 9937\n-171 9962\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-9811 9970\n-155 9994\n9826 -9977\n159 -9986\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n9808 9899\n179 9966\n-9870 -9961\n-179 -9950\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n9815 -9936\n168 -9937\n-9896 9995\n-180 9969\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1\n1 -1\n-100 1\n-100 -1\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n9965 114\n87 9916\n-9957 -106\n-95 -9929\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n9895 -9949\n188 -9978\n-9810 9935\n-151 9914\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-9957 106\n-95 9929\n9965 -114\n87 -9916\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-9862 9980\n-174 9917\n9845 -9967\n173 -9980\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n9944 9926\n9927 9935\n-9961 -9929\n-9997 -9991\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n9917 9909\n196 9925\n-9971 -9991\n-183 -9977\n",
"output": "3 4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/598/C"
} | vfc_9926 |
apps | verifiable_code | 44 | Solve the following coding problem using the programming language python:
Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers.
Vasiliy's car is not new — it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After repairing his car Vasiliy can drive again (but after k kilometers it will break again, and so on). In the beginning of the trip the car is just from repair station.
To drive one kilometer on car Vasiliy spends a seconds, to walk one kilometer on foot he needs b seconds (a < b).
Your task is to find minimal time after which Vasiliy will be able to reach the post office. Consider that in every moment of time Vasiliy can left his car and start to go on foot.
-----Input-----
The first line contains 5 positive integers d, k, a, b, t (1 ≤ d ≤ 10^12; 1 ≤ k, a, b, t ≤ 10^6; a < b), where: d — the distance from home to the post office; k — the distance, which car is able to drive before breaking; a — the time, which Vasiliy spends to drive 1 kilometer on his car; b — the time, which Vasiliy spends to walk 1 kilometer on foot; t — the time, which Vasiliy spends to repair his car.
-----Output-----
Print the minimal time after which Vasiliy will be able to reach the post office.
-----Examples-----
Input
5 2 1 4 10
Output
14
Input
5 2 1 4 5
Output
13
-----Note-----
In the first example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds) and then to walk on foot 3 kilometers (in 12 seconds). So the answer equals to 14 seconds.
In the second example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds), then repair his car (in 5 seconds) and drive 2 kilometers more on the car (in 2 seconds). After that he needs to walk on foot 1 kilometer (in 4 seconds). So the answer equals to 13 seconds.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
d, k, a, b, t = list(map(int, input().split()))
t1 = d * b
t2 = d * a + ((d - 1) // k) * t
t3 = max(0, d - k) * b + min(k, d) * a
dd = d % k
d1 = d - dd
t4 = d1 * a + max(0, (d1 // k - 1) * t) + dd * b
print(min([t1, t2, t3, t4]))
``` | {
"language": "python",
"test_cases": [
{
"input": "5 2 1 4 10\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "5 2 1 4 5\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 1000000 999999 1000000 1000000\n",
"output": "999999999999000000\n",
"type": "stdin_stdout"
},
{
"input": "997167959139 199252 232602 952690 802746\n",
"output": "231947279018960454\n",
"type": "stdin_stdout"
},
{
"input": "244641009859 748096 689016 889744 927808\n",
"output": "168561873458925288\n",
"type": "stdin_stdout"
},
{
"input": "483524125987 264237 209883 668942 244358\n",
"output": "101483941282301425\n",
"type": "stdin_stdout"
},
{
"input": "726702209411 813081 730750 893907 593611\n",
"output": "531038170074636443\n",
"type": "stdin_stdout"
},
{
"input": "965585325539 329221 187165 817564 718673\n",
"output": "180725885278576882\n",
"type": "stdin_stdout"
},
{
"input": "213058376259 910770 679622 814124 67926\n",
"output": "144799175679959130\n",
"type": "stdin_stdout"
},
{
"input": "451941492387 235422 164446 207726 192988\n",
"output": "74320341137487118\n",
"type": "stdin_stdout"
},
{
"input": "690824608515 751563 656903 733131 509537\n",
"output": "453805226165077316\n",
"type": "stdin_stdout"
},
{
"input": "934002691939 300407 113318 885765 858791\n",
"output": "105841987132852686\n",
"type": "stdin_stdout"
},
{
"input": "375802030518 196518 567765 737596 550121\n",
"output": "213368291855090933\n",
"type": "stdin_stdout"
},
{
"input": "614685146646 521171 24179 943227 899375\n",
"output": "14863532910609884\n",
"type": "stdin_stdout"
},
{
"input": "857863230070 37311 545046 657309 991732\n",
"output": "467597724229950776\n",
"type": "stdin_stdout"
},
{
"input": "101041313494 586155 1461 22992 340986\n",
"output": "147680137840428\n",
"type": "stdin_stdout"
},
{
"input": "344219396918 167704 522327 941101 690239\n",
"output": "179796501677835485\n",
"type": "stdin_stdout"
},
{
"input": "583102513046 683844 978741 986255 815301\n",
"output": "570707031914457669\n",
"type": "stdin_stdout"
},
{
"input": "821985629174 232688 471200 927237 164554\n",
"output": "387320209764489810\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 1 1 2 1000000\n",
"output": "1999999999999\n",
"type": "stdin_stdout"
},
{
"input": "1049 593 10 36 7\n",
"output": "10497\n",
"type": "stdin_stdout"
},
{
"input": "1 100 1 5 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 3 1 4 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 20 5 15 50\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "404319 964146 262266 311113 586991\n",
"output": "106039126854\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 1 1 4 1\n",
"output": "1999999999999\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 1 1 10 1\n",
"output": "1999999999999\n",
"type": "stdin_stdout"
},
{
"input": "100 123 1 2 1000\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 111 1 2 123456\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 110 1 2 100000\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 122 1 2 70505\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 300\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 125 1 2 300\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 305\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "10 12 3 4 5\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "100 1000 1 10 1000\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "5 10 1 2 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11 3 4 5 1\n",
"output": "47\n",
"type": "stdin_stdout"
},
{
"input": "100 121 1 2 666\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1 10 1 10 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 567\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1 2 1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 306\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1 2 1 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 307\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "3 100 1 2 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "11 12 3 4 5\n",
"output": "33\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 399\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1 9 54 722 945\n",
"output": "54\n",
"type": "stdin_stdout"
},
{
"input": "100 10 1 10 100\n",
"output": "910\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 98765\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 101 1 2 3\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 1 1 1000000 1\n",
"output": "1999999999999\n",
"type": "stdin_stdout"
},
{
"input": "1 100 2 200 900\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 505\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 3\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "2 100 1 2 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 10 1 2 10\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 100 5 6 1000\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 506\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "5 10 1 2 500\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 507\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 123 1 2 1006\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 509\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 510\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 512\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "4 5 3 4 199\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 513\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 123 1 2 1007\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "5 6 1 2 10000\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 10 10 11 12\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 515\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 516\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "5 10 1 2000 100000\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 3 4 5 1\n",
"output": "4333333333333\n",
"type": "stdin_stdout"
},
{
"input": "100 5 20 21 50\n",
"output": "2095\n",
"type": "stdin_stdout"
},
{
"input": "3 10 3 6 100\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "41 18467 6334 26500 19169\n",
"output": "259694\n",
"type": "stdin_stdout"
},
{
"input": "10 20 1 2 100\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "4 6 1 2 100\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "270 66 76 82 27\n",
"output": "20628\n",
"type": "stdin_stdout"
},
{
"input": "4492 4 3 13 28\n",
"output": "44892\n",
"type": "stdin_stdout"
},
{
"input": "28 32 37 38 180\n",
"output": "1036\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 520\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "5 10 2 3 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "66 21 11 21 97\n",
"output": "950\n",
"type": "stdin_stdout"
},
{
"input": "549 88 81471 83555 35615\n",
"output": "44941269\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 1\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1 999999 1 2 1000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 20 1 100 999999\n",
"output": "8020\n",
"type": "stdin_stdout"
},
{
"input": "3 9 8 9 4\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 600\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "6 3 4 9 4\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "9 1 1 2 1\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 522\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "501 47 789 798 250\n",
"output": "397789\n",
"type": "stdin_stdout"
},
{
"input": "3 6 1 6 9\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 5 8 9 4\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "9 1 3 8 2\n",
"output": "43\n",
"type": "stdin_stdout"
},
{
"input": "17 42 22 64 14\n",
"output": "374\n",
"type": "stdin_stdout"
},
{
"input": "20 5 82 93 50\n",
"output": "1790\n",
"type": "stdin_stdout"
},
{
"input": "5 6 2 3 50\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 525\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "6 3 7 9 1\n",
"output": "43\n",
"type": "stdin_stdout"
},
{
"input": "1686604166 451776 534914 885584 885904\n",
"output": "902191487931356\n",
"type": "stdin_stdout"
},
{
"input": "1 4 4 6 7\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5 67 61 68 83\n",
"output": "305\n",
"type": "stdin_stdout"
},
{
"input": "15 5 11 20 15\n",
"output": "195\n",
"type": "stdin_stdout"
},
{
"input": "15 2 9 15 13\n",
"output": "213\n",
"type": "stdin_stdout"
},
{
"input": "17 15 9 17 19\n",
"output": "169\n",
"type": "stdin_stdout"
},
{
"input": "1 17 9 10 6\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2 10 10 16 8\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "18419 54 591 791 797\n",
"output": "11157406\n",
"type": "stdin_stdout"
},
{
"input": "10 2 1 2 18\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "100 120 1 2 528\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "5 17 2 3 8\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "63793 358 368 369 367\n",
"output": "23539259\n",
"type": "stdin_stdout"
},
{
"input": "7 2 4 16 19\n",
"output": "78\n",
"type": "stdin_stdout"
},
{
"input": "3 8 3 5 19\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "17 7 6 9 13\n",
"output": "124\n",
"type": "stdin_stdout"
},
{
"input": "14 3 14 16 5\n",
"output": "215\n",
"type": "stdin_stdout"
},
{
"input": "2000002 1000000 1 3 1000000\n",
"output": "3000006\n",
"type": "stdin_stdout"
},
{
"input": "2 1 3 8 14\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "18 6 8 9 7\n",
"output": "156\n",
"type": "stdin_stdout"
},
{
"input": "10 20 10 20 7\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "12 7 8 18 1\n",
"output": "97\n",
"type": "stdin_stdout"
},
{
"input": "16 1 3 20 2\n",
"output": "78\n",
"type": "stdin_stdout"
},
{
"input": "5 1000 1 4 10\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/702/D"
} | vfc_9930 |
apps | verifiable_code | 45 | Solve the following coding problem using the programming language python:
You are given positive integer number n. You should create such strictly increasing sequence of k positive numbers a_1, a_2, ..., a_{k}, that their sum is equal to n and greatest common divisor is maximal.
Greatest common divisor of sequence is maximum of such numbers that every element of sequence is divisible by them.
If there is no possible sequence then output -1.
-----Input-----
The first line consists of two numbers n and k (1 ≤ n, k ≤ 10^10).
-----Output-----
If the answer exists then output k numbers — resulting sequence. Otherwise output -1. If there are multiple answers, print any of them.
-----Examples-----
Input
6 3
Output
1 2 3
Input
8 2
Output
2 6
Input
5 3
Output
-1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, k = map(int, input().split())
div = []
i = 1
n1 = n
while i * i <= n:
if n % i == 0:
div.append(i)
div.append(n // i)
i += 1
div.sort()
mx = -1
for i in range(len(div)):
a = div[i] * k * (k + 1) // 2
if a <= n:
mx = div[i]
if mx == -1:
print(-1)
else:
for i in range(k - 1):
print(mx * (i + 1), end= " ")
print(n - mx * k * (k - 1) // 2)
``` | {
"language": "python",
"test_cases": [
{
"input": "6 3\n",
"output": "1 2 3\n",
"type": "stdin_stdout"
},
{
"input": "8 2\n",
"output": "2 6\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 10000000000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6 2\n",
"output": "2 4\n",
"type": "stdin_stdout"
},
{
"input": "24 2\n",
"output": "8 16\n",
"type": "stdin_stdout"
},
{
"input": "24 3\n",
"output": "4 8 12\n",
"type": "stdin_stdout"
},
{
"input": "24 4\n",
"output": "2 4 6 12\n",
"type": "stdin_stdout"
},
{
"input": "24 5\n",
"output": "1 2 3 4 14\n",
"type": "stdin_stdout"
},
{
"input": "479001600 2\n",
"output": "159667200 319334400\n",
"type": "stdin_stdout"
},
{
"input": "479001600 3\n",
"output": "79833600 159667200 239500800\n",
"type": "stdin_stdout"
},
{
"input": "479001600 4\n",
"output": "47900160 95800320 143700480 191600640\n",
"type": "stdin_stdout"
},
{
"input": "479001600 5\n",
"output": "31933440 63866880 95800320 127733760 159667200\n",
"type": "stdin_stdout"
},
{
"input": "479001600 6\n",
"output": "22809600 45619200 68428800 91238400 114048000 136857600\n",
"type": "stdin_stdout"
},
{
"input": "3000000021 1\n",
"output": "3000000021\n",
"type": "stdin_stdout"
},
{
"input": "3000000021 2\n",
"output": "1000000007 2000000014\n",
"type": "stdin_stdout"
},
{
"input": "3000000021 3\n",
"output": "3 6 3000000012\n",
"type": "stdin_stdout"
},
{
"input": "3000000021 4\n",
"output": "3 6 9 3000000003\n",
"type": "stdin_stdout"
},
{
"input": "3000000021 100000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10000000000 100000000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10000000000 10000000000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 4000000000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4294967296 4294967296\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "71227122 9603838834\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10000000000 9603838835\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 5999999999\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 9324327498\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9 2\n",
"output": "3 6\n",
"type": "stdin_stdout"
},
{
"input": "10000000000 4294967296\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 3500000000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10000000000 4000000000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2000 9324327498\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10000000000 8589934592\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10000000000 3037000500\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9400000000 9324327498\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10000000000 3307000500\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 4000000000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1000 4294967295\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "36 3\n",
"output": "6 12 18\n",
"type": "stdin_stdout"
},
{
"input": "2147483648 4294967296\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "999 4294967295\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10000000000 6074001000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "12344321 1\n",
"output": "12344321\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "28 7\n",
"output": "1 2 3 4 5 6 7\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 9\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 9\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 9\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n",
"output": "1 3\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 9\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n",
"output": "1 4\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 9\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "6 2\n",
"output": "2 4\n",
"type": "stdin_stdout"
},
{
"input": "6 3\n",
"output": "1 2 3\n",
"type": "stdin_stdout"
},
{
"input": "6 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 9\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "7 1\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "7 2\n",
"output": "1 6\n",
"type": "stdin_stdout"
},
{
"input": "7 3\n",
"output": "1 2 4\n",
"type": "stdin_stdout"
},
{
"input": "7 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "7 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "7 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "7 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "7 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "7 9\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "7 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "8 1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "8 2\n",
"output": "2 6\n",
"type": "stdin_stdout"
},
{
"input": "8 3\n",
"output": "1 2 5\n",
"type": "stdin_stdout"
},
{
"input": "8 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "8 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "8 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "8 7\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "8 8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "8 9\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "8 10\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/803/C"
} | vfc_9934 |
apps | verifiable_code | 46 | Solve the following coding problem using the programming language python:
After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how many pairs of integers she can choose, one from the first column and the other from the second column, such that their sum is divisible by 5.
Formally, Alyona wants to count the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and $(x + y) \operatorname{mod} 5$ equals 0.
As usual, Alyona has some troubles and asks you to help.
-----Input-----
The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1 000 000).
-----Output-----
Print the only integer — the number of pairs of integers (x, y) such that 1 ≤ x ≤ n, 1 ≤ y ≤ m and (x + y) is divisible by 5.
-----Examples-----
Input
6 12
Output
14
Input
11 14
Output
31
Input
1 5
Output
1
Input
3 8
Output
5
Input
5 7
Output
7
Input
21 21
Output
88
-----Note-----
Following pairs are suitable in the first sample case: for x = 1 fits y equal to 4 or 9; for x = 2 fits y equal to 3 or 8; for x = 3 fits y equal to 2, 7 or 12; for x = 4 fits y equal to 1, 6 or 11; for x = 5 fits y equal to 5 or 10; for x = 6 fits y equal to 4 or 9.
Only the pair (1, 4) is suitable in the third sample case.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
ct=0
a, b = list(map(int, input().split(' ')))
x=[0]*5
for i in range(1, b+1):
x[i%5]+=1
for i in range(1, a+1):
ct+=x[(0-i)%5]
print(ct)
``` | {
"language": "python",
"test_cases": [
{
"input": "6 12\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "11 14\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"input": "1 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 8\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "21 21\n",
"output": "88\n",
"type": "stdin_stdout"
},
{
"input": "10 15\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000\n",
"output": "200000\n",
"type": "stdin_stdout"
},
{
"input": "1000000 1\n",
"output": "200000\n",
"type": "stdin_stdout"
},
{
"input": "1000000 1000000\n",
"output": "200000000000\n",
"type": "stdin_stdout"
},
{
"input": "944 844\n",
"output": "159348\n",
"type": "stdin_stdout"
},
{
"input": "368 984\n",
"output": "72423\n",
"type": "stdin_stdout"
},
{
"input": "792 828\n",
"output": "131155\n",
"type": "stdin_stdout"
},
{
"input": "920 969\n",
"output": "178296\n",
"type": "stdin_stdout"
},
{
"input": "640 325\n",
"output": "41600\n",
"type": "stdin_stdout"
},
{
"input": "768 170\n",
"output": "26112\n",
"type": "stdin_stdout"
},
{
"input": "896 310\n",
"output": "55552\n",
"type": "stdin_stdout"
},
{
"input": "320 154\n",
"output": "9856\n",
"type": "stdin_stdout"
},
{
"input": "744 999\n",
"output": "148652\n",
"type": "stdin_stdout"
},
{
"input": "630 843\n",
"output": "106218\n",
"type": "stdin_stdout"
},
{
"input": "54 688\n",
"output": "7431\n",
"type": "stdin_stdout"
},
{
"input": "478 828\n",
"output": "79157\n",
"type": "stdin_stdout"
},
{
"input": "902 184\n",
"output": "33194\n",
"type": "stdin_stdout"
},
{
"input": "31 29\n",
"output": "180\n",
"type": "stdin_stdout"
},
{
"input": "751 169\n",
"output": "25384\n",
"type": "stdin_stdout"
},
{
"input": "879 14\n",
"output": "2462\n",
"type": "stdin_stdout"
},
{
"input": "7 858\n",
"output": "1201\n",
"type": "stdin_stdout"
},
{
"input": "431 702\n",
"output": "60512\n",
"type": "stdin_stdout"
},
{
"input": "855 355\n",
"output": "60705\n",
"type": "stdin_stdout"
},
{
"input": "553 29\n",
"output": "3208\n",
"type": "stdin_stdout"
},
{
"input": "721767 525996\n",
"output": "75929310986\n",
"type": "stdin_stdout"
},
{
"input": "805191 74841\n",
"output": "12052259926\n",
"type": "stdin_stdout"
},
{
"input": "888615 590981\n",
"output": "105030916263\n",
"type": "stdin_stdout"
},
{
"input": "4743 139826\n",
"output": "132638943\n",
"type": "stdin_stdout"
},
{
"input": "88167 721374\n",
"output": "12720276292\n",
"type": "stdin_stdout"
},
{
"input": "171591 13322\n",
"output": "457187060\n",
"type": "stdin_stdout"
},
{
"input": "287719 562167\n",
"output": "32349225415\n",
"type": "stdin_stdout"
},
{
"input": "371143 78307\n",
"output": "5812618980\n",
"type": "stdin_stdout"
},
{
"input": "487271 627151\n",
"output": "61118498984\n",
"type": "stdin_stdout"
},
{
"input": "261436 930642\n",
"output": "48660664382\n",
"type": "stdin_stdout"
},
{
"input": "377564 446782\n",
"output": "33737759810\n",
"type": "stdin_stdout"
},
{
"input": "460988 28330\n",
"output": "2611958008\n",
"type": "stdin_stdout"
},
{
"input": "544412 352983\n",
"output": "38433636199\n",
"type": "stdin_stdout"
},
{
"input": "660540 869123\n",
"output": "114818101284\n",
"type": "stdin_stdout"
},
{
"input": "743964 417967\n",
"output": "62190480238\n",
"type": "stdin_stdout"
},
{
"input": "827388 966812\n",
"output": "159985729411\n",
"type": "stdin_stdout"
},
{
"input": "910812 515656\n",
"output": "93933134534\n",
"type": "stdin_stdout"
},
{
"input": "26940 64501\n",
"output": "347531388\n",
"type": "stdin_stdout"
},
{
"input": "110364 356449\n",
"output": "7867827488\n",
"type": "stdin_stdout"
},
{
"input": "636358 355531\n",
"output": "45248999219\n",
"type": "stdin_stdout"
},
{
"input": "752486 871672\n",
"output": "131184195318\n",
"type": "stdin_stdout"
},
{
"input": "803206 420516\n",
"output": "67552194859\n",
"type": "stdin_stdout"
},
{
"input": "919334 969361\n",
"output": "178233305115\n",
"type": "stdin_stdout"
},
{
"input": "35462 261309\n",
"output": "1853307952\n",
"type": "stdin_stdout"
},
{
"input": "118887 842857\n",
"output": "20040948031\n",
"type": "stdin_stdout"
},
{
"input": "202311 358998\n",
"output": "14525848875\n",
"type": "stdin_stdout"
},
{
"input": "285735 907842\n",
"output": "51880446774\n",
"type": "stdin_stdout"
},
{
"input": "401863 456686\n",
"output": "36705041203\n",
"type": "stdin_stdout"
},
{
"input": "452583 972827\n",
"output": "88056992428\n",
"type": "stdin_stdout"
},
{
"input": "235473 715013\n",
"output": "33673251230\n",
"type": "stdin_stdout"
},
{
"input": "318897 263858\n",
"output": "16828704925\n",
"type": "stdin_stdout"
},
{
"input": "402321 812702\n",
"output": "65393416268\n",
"type": "stdin_stdout"
},
{
"input": "518449 361546\n",
"output": "37488632431\n",
"type": "stdin_stdout"
},
{
"input": "634577 910391\n",
"output": "115542637921\n",
"type": "stdin_stdout"
},
{
"input": "685297 235043\n",
"output": "32214852554\n",
"type": "stdin_stdout"
},
{
"input": "801425 751183\n",
"output": "120403367155\n",
"type": "stdin_stdout"
},
{
"input": "884849 300028\n",
"output": "53095895155\n",
"type": "stdin_stdout"
},
{
"input": "977 848872\n",
"output": "165869588\n",
"type": "stdin_stdout"
},
{
"input": "51697 397716\n",
"output": "4112144810\n",
"type": "stdin_stdout"
},
{
"input": "834588 107199\n",
"output": "17893399803\n",
"type": "stdin_stdout"
},
{
"input": "918012 688747\n",
"output": "126455602192\n",
"type": "stdin_stdout"
},
{
"input": "1436 237592\n",
"output": "68236422\n",
"type": "stdin_stdout"
},
{
"input": "117564 753732\n",
"output": "17722349770\n",
"type": "stdin_stdout"
},
{
"input": "200988 302576\n",
"output": "12162829017\n",
"type": "stdin_stdout"
},
{
"input": "284412 818717\n",
"output": "46570587880\n",
"type": "stdin_stdout"
},
{
"input": "400540 176073\n",
"output": "14104855884\n",
"type": "stdin_stdout"
},
{
"input": "483964 724917\n",
"output": "70166746198\n",
"type": "stdin_stdout"
},
{
"input": "567388 241058\n",
"output": "27354683301\n",
"type": "stdin_stdout"
},
{
"input": "650812 789902\n",
"output": "102815540084\n",
"type": "stdin_stdout"
},
{
"input": "400999 756281\n",
"output": "60653584944\n",
"type": "stdin_stdout"
},
{
"input": "100 101\n",
"output": "2020\n",
"type": "stdin_stdout"
},
{
"input": "100 102\n",
"output": "2040\n",
"type": "stdin_stdout"
},
{
"input": "103 100\n",
"output": "2060\n",
"type": "stdin_stdout"
},
{
"input": "100 104\n",
"output": "2080\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "11 23\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "8 14\n",
"output": "23\n",
"type": "stdin_stdout"
},
{
"input": "23423 34234\n",
"output": "160372597\n",
"type": "stdin_stdout"
},
{
"input": "1 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "999999 999999\n",
"output": "199999600001\n",
"type": "stdin_stdout"
},
{
"input": "82 99\n",
"output": "1624\n",
"type": "stdin_stdout"
},
{
"input": "21 18\n",
"output": "75\n",
"type": "stdin_stdout"
},
{
"input": "234 234\n",
"output": "10952\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6 13\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "3 9\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "99999 99999\n",
"output": "1999960001\n",
"type": "stdin_stdout"
},
{
"input": "34 33\n",
"output": "225\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "333 1\n",
"output": "66\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2179 2218\n",
"output": "966605\n",
"type": "stdin_stdout"
},
{
"input": "1000000 999999\n",
"output": "199999800000\n",
"type": "stdin_stdout"
},
{
"input": "873828 774207\n",
"output": "135304750879\n",
"type": "stdin_stdout"
},
{
"input": "13 19\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "1648 576469\n",
"output": "190004183\n",
"type": "stdin_stdout"
},
{
"input": "11 13\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "5 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "650074 943659\n",
"output": "122689636154\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "54 43\n",
"output": "465\n",
"type": "stdin_stdout"
},
{
"input": "14 9\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "543 534\n",
"output": "57993\n",
"type": "stdin_stdout"
},
{
"input": "321 123\n",
"output": "7896\n",
"type": "stdin_stdout"
},
{
"input": "21 3\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "47474 74747\n",
"output": "709707816\n",
"type": "stdin_stdout"
},
{
"input": "4 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "7 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "9 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "12414 4214\n",
"output": "10462520\n",
"type": "stdin_stdout"
},
{
"input": "2 9\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "253 821\n",
"output": "41542\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/682/A"
} | vfc_9938 |
apps | verifiable_code | 47 | Solve the following coding problem using the programming language python:
You are given an array $a$ consisting of $n$ integers. Beauty of array is the maximum sum of some consecutive subarray of this array (this subarray may be empty). For example, the beauty of the array [10, -5, 10, -4, 1] is 15, and the beauty of the array [-3, -5, -1] is 0.
You may choose at most one consecutive subarray of $a$ and multiply all values contained in this subarray by $x$. You want to maximize the beauty of array after applying at most one such operation.
-----Input-----
The first line contains two integers $n$ and $x$ ($1 \le n \le 3 \cdot 10^5, -100 \le x \le 100$) — the length of array $a$ and the integer $x$ respectively.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \le a_i \le 10^9$) — the array $a$.
-----Output-----
Print one integer — the maximum possible beauty of array $a$ after multiplying all values belonging to some consecutive subarray $x$.
-----Examples-----
Input
5 -2
-3 8 -2 1 -6
Output
22
Input
12 -3
1 3 3 7 1 3 3 7 1 3 3 7
Output
42
Input
5 10
-1 -2 -3 -4 -5
Output
0
-----Note-----
In the first test case we need to multiply the subarray [-2, 1, -6], and the array becomes [-3, 8, 4, -2, 12] with beauty 22 ([-3, 8, 4, -2, 12]).
In the second test case we don't need to multiply any subarray at all.
In the third test case no matter which subarray we multiply, the beauty of array will be equal to 0.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
N, X = list(map(int, input().split()))
A = [int(a) for a in input().split()]
dp = [[0]*4 for _ in range(N+1)]
for i in range(1, N+1):
dp[i][0] = max(dp[i-1][0] + A[i-1], 0)
dp[i][1] = max(dp[i-1][1] + A[i-1] * X, dp[i][0])
dp[i][2] = max(dp[i-1][2] + A[i-1], dp[i][1])
dp[i][3] = max(dp[i-1][3], dp[i][2])
print(dp[N][3])
``` | {
"language": "python",
"test_cases": [
{
"input": "5 -2\n-3 8 -2 1 -6\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "12 -3\n1 3 3 7 1 3 3 7 1 3 3 7\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "5 10\n-1 -2 -3 -4 -5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 100\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "1000000000000\n",
"type": "stdin_stdout"
},
{
"input": "3 0\n1 -10 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n5 -10 -10 -10 6\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n-12 10 -9 10 -12\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n-3 8 -2 1 -6\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "5 -2\n-5 5 -5 5 5\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n10 -5 10 -4 7\n",
"output": "23\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n100 -2 -3 -4 5\n",
"output": "105\n",
"type": "stdin_stdout"
},
{
"input": "5 -1\n-3 3 -5 0 -5\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "8 -5\n-1 1 -4 0 1 -5 2 0\n",
"output": "43\n",
"type": "stdin_stdout"
},
{
"input": "6 -1\n-1 1 -1 1 -1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 0\n5 -5 -5 -5 5 5 5\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n1 -1 -2 3 -4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n1 -10 2 -10 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "12 0\n516886745 863558529 725534320 -476894082 -367873680 984444967 -179610789 -226927004 -433201102 -328480313 836969657 -860311698\n",
"output": "3090424561\n",
"type": "stdin_stdout"
},
{
"input": "8 0\n-2 -3 4 -1 -2 1 5 -3\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n0 -2 1 -4 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6 0\n100 100 100 -10000 100 -10000\n",
"output": "400\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n1 2 -3 4 5\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "6 0\n1 -5 2 -7 -7 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "20 -45\n258724997 -785871818 782985138 -634742565 -441581905 -805809066 280018540 -580223434 111100989 261073170 -228599873 -952789056 -546984180 63225670 928739598 -722252666 884612638 745266043 -890049463 -945276047\n",
"output": "161916758521\n",
"type": "stdin_stdout"
},
{
"input": "4 -2\n-1 1 -2 -3\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n1 2 3 -999999 10\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "4 -1\n-1 1 -1 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 10\n-1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 -2\n10 -3 10 -2 -2\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "17 -35\n138863522 -763922306 -747654041 62569781 913789268 51272833 508697810 773008119 -977056807 687653428 109017489 19592255 -861227612 -876222938 657271514 -395334151 -745198581\n",
"output": "85662026916\n",
"type": "stdin_stdout"
},
{
"input": "4 0\n-3 4 -1 9\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "14 0\n-13 -12 4 -12 21 -1 -17 21 3 4 21 -3 -5 -4\n",
"output": "70\n",
"type": "stdin_stdout"
},
{
"input": "5 -1\n-2 -4 5 -3 -4\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "5 -1\n-5 -2 6 -3 -5\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "10 -3\n0 -8 7 -2 -10 -10 7 1 7 -8\n",
"output": "88\n",
"type": "stdin_stdout"
},
{
"input": "42 0\n286046708 405034560 -729242288 -594215986 -417878652 197367358 -252467864 -633931002 396498018 -511564535 -989028451 133570042 -189524845 -823874429 -29495943 609283144 349227466 -228464789 -326269641 -837429605 310547279 27725681 -167613209 -86658444 900798243 607258117 280296177 -521198948 862072118 -758282415 -801169109 892055264 46442426 -23191339 -34045601 -537875046 538522323 -831256376 -700385529 758255934 -265266910 -962343358\n",
"output": "3171737624\n",
"type": "stdin_stdout"
},
{
"input": "26 0\n2 -6 0 6 -4 4 -2 -1 8 1 3 -10 7 -4 8 8 9 -8 -5 8 8 -8 4 3 -7 5\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "4 0\n-1000 5 -3 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "40 -98\n67397987 -343838159 -618322596 -546414490 293066140 -773772966 277974552 -434260219 -791222310 -340023233 -737934384 910703436 -308962211 735427170 -284205825 955071831 926268695 915895023 -442261754 -165237941 -739567764 -160138112 98200520 143131806 -205877346 -473890188 714869937 797682377 -395221452 551109182 -760816208 -244257455 895516323 -163654048 633273357 469354271 -419989073 -700814005 -939790951 694327902\n",
"output": "397915082781\n",
"type": "stdin_stdout"
},
{
"input": "7 -2\n-1000 999 -999 -1 -2 -3 10\n",
"output": "3019\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n-8 3 -3 5 -4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n1 2 -3 -4 6\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "3 0\n5 -5 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 0\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n100 -1 -2 -3 5\n",
"output": "105\n",
"type": "stdin_stdout"
},
{
"input": "1 0\n100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "21 -1\n369656457 983010976 579153117 966986334 -112879188 -583181121 606082142 63045074 -363741696 589071324 -328685035 755235379 909933454 541317219 450989416 -709630451 651403110 796187891 467448699 943322585 -963217967\n",
"output": "8993986588\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n1 2 -3 -4 5\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "8 -7\n0 -8 2 -4 0 9 -9 -3\n",
"output": "93\n",
"type": "stdin_stdout"
},
{
"input": "3 0\n9 -8 9\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "4 -2\n-4 3 -7 -1\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "5 -1\n1 -10 10 -10 7\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "8 -2\n-5 -3 -1 10 -2 -6 8 9\n",
"output": "43\n",
"type": "stdin_stdout"
},
{
"input": "12 0\n1 3 -77 7 -77 3 3 7 1 3 3 7\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "8 -1\n4 -3 -20 -1 20 -20 -2 10\n",
"output": "52\n",
"type": "stdin_stdout"
},
{
"input": "4 -4\n-6 5 -1 -9\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "4 0\n-100 10 -100 10\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n1 -2 -3 4 -5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 -2\n-7 7 -3 -7\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "10 -56\n40 -76 8 39 -23 38 -82 -41 -15 58\n",
"output": "8610\n",
"type": "stdin_stdout"
},
{
"input": "6 -1\n-5 1 2 -3 4 -5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "21 0\n-256 355 198 397 -970 -868 -697 -998 572 -271 358 923 176 -27 988 -956 677 -267 786 -157 363\n",
"output": "4121\n",
"type": "stdin_stdout"
},
{
"input": "4 0\n6 7 -10 4\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "8 -4\n-10 -9 10 -10 -5 10 -5 6\n",
"output": "107\n",
"type": "stdin_stdout"
},
{
"input": "59 -43\n0 -19 -25 96 -4 -34 59 23 60 33 51 -62 -97 -59 -89 -42 65 33 49 49 68 -74 23 20 15 -100 58 47 -89 93 -37 39 -19 66 -96 -43 -38 -57 58 -13 -19 79 -74 84 -77 44 -84 76 -61 23 -15 -13 -2 -86 -27 38 42 -90 -50\n",
"output": "19376\n",
"type": "stdin_stdout"
},
{
"input": "9 -2\n-9 7 -6 -3 -5 -6 7 -8 1\n",
"output": "54\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n-3 9 -5 1 10\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "3 0\n1 -41 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1 -5\n-5\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "9 0\n-6 0 2 -1 -4 -8 -10 2 -8\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6 -6\n77 -30 -5 -33 -67 -76\n",
"output": "1343\n",
"type": "stdin_stdout"
},
{
"input": "8 1\n-7 9 -3 0 5 8 -4 3\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "3 0\n5 -10 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "6 0\n-10 0 9 -4 -7 3\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "3 -6\n-9 -3 9\n",
"output": "81\n",
"type": "stdin_stdout"
},
{
"input": "5 -2\n-4 -3 6 -7 2\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "8 -1\n-1 -2 -3 6 -1 -2 -3 100\n",
"output": "112\n",
"type": "stdin_stdout"
},
{
"input": "9 0\n-10 8 -6 3 -4 9 -5 -8 -8\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "5 -1\n-3 3 -3 3 -3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n-12 11 -9 10 -12\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "1 59\n402422091\n",
"output": "23742903369\n",
"type": "stdin_stdout"
},
{
"input": "9 -6\n-9 8 -10 4 -10 -10 -9 -7 -8\n",
"output": "308\n",
"type": "stdin_stdout"
},
{
"input": "1 0\n-5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 0\n3 -1 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n-8 8 -1\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "6 0\n-3 2 -3 7 3 9\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "9 0\n-8 10 5 -9 6 -5 -9 7 -7\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "3 0\n1 -1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n5 1 -5 6 2\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "1 -7\n10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "4 -1\n-6 6 0 -9\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "4 0\n3 -6 -3 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 0\n10 -7 2 4\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "8 -7\n-9 9 -2 -10 -9 -8 1 10\n",
"output": "223\n",
"type": "stdin_stdout"
},
{
"input": "1 10\n10\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1 4\n7\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "7 0\n0 -4 -2 4 -6 8 -3\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "6 5\n-100 -100 -100 -100 -100 1000\n",
"output": "5000\n",
"type": "stdin_stdout"
},
{
"input": "5 -1\n5 -10 8 -10 -9\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "9 0\n-10 3 4 -8 -8 -4 -1 5 4\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "5 65\n344 -333 -155 758 -845\n",
"output": "49270\n",
"type": "stdin_stdout"
},
{
"input": "4 0\n1 -2 -3 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4 0\n-9 8 -6 8\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "1 6\n5\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "6 0\n1 -2 -3 3 -8 -2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "9 -2\n192 805 -674 966 -220 50 647 39 -691\n",
"output": "3827\n",
"type": "stdin_stdout"
},
{
"input": "6 -2\n-9 1 6 -7 -4 -1\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"input": "5 -1\n-5 4 -10 10 -1\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "10 -2\n-7 -4 10 -9 -5 -9 -2 -8 3 -9\n",
"output": "88\n",
"type": "stdin_stdout"
},
{
"input": "7 0\n9 8 1 -3 7 9 8\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "3 -1\n1 -9 -6\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "7 0\n1 -2 -3 3 -8 -2 7\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "9 0\n-8 -6 -8 3 -9 -6 5 4 -3\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "1 -1\n-1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 0\n-8 5 -4 -7 9 2 -8 -8 2 0\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "7 -1\n0 -9 15 -5 15 -9 0\n",
"output": "35\n",
"type": "stdin_stdout"
},
{
"input": "12 0\n-78 -23 -16 4 -12 -8 22 79 -52 26 19 -3\n",
"output": "146\n",
"type": "stdin_stdout"
},
{
"input": "3 -2\n-3 3 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "8 0\n-1 2 -1 1 -1 -2 2 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1 -1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n-1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n2 -2 0 1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 -2\n-2 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5 0\n-12 10 -10 10 -12\n",
"output": "20\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1155/D"
} | vfc_9942 |
apps | verifiable_code | 48 | Solve the following coding problem using the programming language python:
Bizon the Champion isn't just charming, he also is very smart.
While some of us were learning the multiplication table, Bizon the Champion had fun in his own manner. Bizon the Champion painted an n × m multiplication table, where the element on the intersection of the i-th row and j-th column equals i·j (the rows and columns of the table are numbered starting from 1). Then he was asked: what number in the table is the k-th largest number? Bizon the Champion always answered correctly and immediately. Can you repeat his success?
Consider the given multiplication table. If you write out all n·m numbers from the table in the non-decreasing order, then the k-th number you write out is called the k-th largest number.
-----Input-----
The single line contains integers n, m and k (1 ≤ n, m ≤ 5·10^5; 1 ≤ k ≤ n·m).
-----Output-----
Print the k-th largest number in a n × m multiplication table.
-----Examples-----
Input
2 2 2
Output
2
Input
2 3 4
Output
3
Input
1 10 5
Output
5
-----Note-----
A 2 × 3 multiplication table looks like this:
1 2 3
2 4 6
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
from math import sqrt
m, n, k = list(map(int, input().split()))
if n < m:
n, m = m, n
lo, hi = 1, k + 1
while lo + 1 < hi:
mid = (lo + hi) // 2
t = mid - 1
v = min(int(sqrt(t)), m)
tn, tm = (t - 1) // m, t // n
vv = [t // i for i in range(tm + 1, v + 1)]
if t // n * (n + m) + sum(vv) * 2 + max(min((tn - tm), len(vv)) * m, 0) - v * v - sum(
vv[:max(min(tn - tm, len(vv)), 0)]) < k:
lo = mid
else:
hi = mid
print(lo)
def __starting_point():
main()
__starting_point()
``` | {
"language": "python",
"test_cases": [
{
"input": "2 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1 10 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 1 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10 10 33\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "500000 500000 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "500000 500000 250000000000\n",
"output": "250000000000\n",
"type": "stdin_stdout"
},
{
"input": "3 3 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 3 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 3 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 3 8\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 3 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1 500000 74747\n",
"output": "74747\n",
"type": "stdin_stdout"
},
{
"input": "500000 1 47474\n",
"output": "47474\n",
"type": "stdin_stdout"
},
{
"input": "499975 499981 12345\n",
"output": "1634\n",
"type": "stdin_stdout"
},
{
"input": "499997 499989 248758432143\n",
"output": "225563648440\n",
"type": "stdin_stdout"
},
{
"input": "5 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 44 36\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "2 28 49\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "3 48 30\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "5 385 1296\n",
"output": "711\n",
"type": "stdin_stdout"
},
{
"input": "1 454 340\n",
"output": "340\n",
"type": "stdin_stdout"
},
{
"input": "1 450 399\n",
"output": "399\n",
"type": "stdin_stdout"
},
{
"input": "1 3304 218\n",
"output": "218\n",
"type": "stdin_stdout"
},
{
"input": "3 4175 661\n",
"output": "361\n",
"type": "stdin_stdout"
},
{
"input": "4 1796 2564\n",
"output": "1232\n",
"type": "stdin_stdout"
},
{
"input": "2 33975 17369\n",
"output": "11580\n",
"type": "stdin_stdout"
},
{
"input": "4 25555 45556\n",
"output": "21868\n",
"type": "stdin_stdout"
},
{
"input": "5 17136 9220\n",
"output": "4039\n",
"type": "stdin_stdout"
},
{
"input": "3 355632 94220\n",
"output": "51393\n",
"type": "stdin_stdout"
},
{
"input": "5 353491 107977\n",
"output": "47290\n",
"type": "stdin_stdout"
},
{
"input": "4 194790 114613\n",
"output": "55015\n",
"type": "stdin_stdout"
},
{
"input": "47 5 157\n",
"output": "87\n",
"type": "stdin_stdout"
},
{
"input": "26 5 79\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "40 2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "12 28 127\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "32 12 132\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "48 40 937\n",
"output": "364\n",
"type": "stdin_stdout"
},
{
"input": "45 317 6079\n",
"output": "2160\n",
"type": "stdin_stdout"
},
{
"input": "18 459 7733\n",
"output": "5684\n",
"type": "stdin_stdout"
},
{
"input": "38 127 1330\n",
"output": "404\n",
"type": "stdin_stdout"
},
{
"input": "25 1155 9981\n",
"output": "3318\n",
"type": "stdin_stdout"
},
{
"input": "41 4600 39636\n",
"output": "10865\n",
"type": "stdin_stdout"
},
{
"input": "20 2222 11312\n",
"output": "3502\n",
"type": "stdin_stdout"
},
{
"input": "32 11568 36460\n",
"output": "8988\n",
"type": "stdin_stdout"
},
{
"input": "48 33111 5809\n",
"output": "1308\n",
"type": "stdin_stdout"
},
{
"input": "27 24692 71714\n",
"output": "18432\n",
"type": "stdin_stdout"
},
{
"input": "46 356143 2399416\n",
"output": "598032\n",
"type": "stdin_stdout"
},
{
"input": "25 127045 1458997\n",
"output": "548779\n",
"type": "stdin_stdout"
},
{
"input": "41 246624 2596292\n",
"output": "751716\n",
"type": "stdin_stdout"
},
{
"input": "264 3 775\n",
"output": "741\n",
"type": "stdin_stdout"
},
{
"input": "495 3 17\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "252 5 672\n",
"output": "328\n",
"type": "stdin_stdout"
},
{
"input": "314 32 3903\n",
"output": "1345\n",
"type": "stdin_stdout"
},
{
"input": "472 15 932\n",
"output": "283\n",
"type": "stdin_stdout"
},
{
"input": "302 39 4623\n",
"output": "1589\n",
"type": "stdin_stdout"
},
{
"input": "318 440 57023\n",
"output": "19203\n",
"type": "stdin_stdout"
},
{
"input": "403 363 932\n",
"output": "175\n",
"type": "stdin_stdout"
},
{
"input": "306 433 25754\n",
"output": "6500\n",
"type": "stdin_stdout"
},
{
"input": "143 1735 246128\n",
"output": "218316\n",
"type": "stdin_stdout"
},
{
"input": "447 4446 802918\n",
"output": "268036\n",
"type": "stdin_stdout"
},
{
"input": "132 3890 439379\n",
"output": "265096\n",
"type": "stdin_stdout"
},
{
"input": "366 45769 5885721\n",
"output": "1841004\n",
"type": "stdin_stdout"
},
{
"input": "123 37349 4224986\n",
"output": "2895390\n",
"type": "stdin_stdout"
},
{
"input": "427 46704 7152399\n",
"output": "2256408\n",
"type": "stdin_stdout"
},
{
"input": "357 184324 28748161\n",
"output": "9992350\n",
"type": "stdin_stdout"
},
{
"input": "187 425625 25103321\n",
"output": "7534560\n",
"type": "stdin_stdout"
},
{
"input": "345 423483 40390152\n",
"output": "11441760\n",
"type": "stdin_stdout"
},
{
"input": "4775 3 7798\n",
"output": "4254\n",
"type": "stdin_stdout"
},
{
"input": "1035 2 2055\n",
"output": "2040\n",
"type": "stdin_stdout"
},
{
"input": "3119 3 7305\n",
"output": "5024\n",
"type": "stdin_stdout"
},
{
"input": "1140 18 11371\n",
"output": "4830\n",
"type": "stdin_stdout"
},
{
"input": "4313 40 86640\n",
"output": "33496\n",
"type": "stdin_stdout"
},
{
"input": "2396 24 55229\n",
"output": "43102\n",
"type": "stdin_stdout"
},
{
"input": "2115 384 385536\n",
"output": "140250\n",
"type": "stdin_stdout"
},
{
"input": "2376 308 665957\n",
"output": "445248\n",
"type": "stdin_stdout"
},
{
"input": "4460 377 1197310\n",
"output": "581462\n",
"type": "stdin_stdout"
},
{
"input": "2315 1673 225263\n",
"output": "40950\n",
"type": "stdin_stdout"
},
{
"input": "1487 3295 736705\n",
"output": "169290\n",
"type": "stdin_stdout"
},
{
"input": "3571 3828 7070865\n",
"output": "2696688\n",
"type": "stdin_stdout"
},
{
"input": "3082 23173 68350097\n",
"output": "51543000\n",
"type": "stdin_stdout"
},
{
"input": "1165 34678 7211566\n",
"output": "1745254\n",
"type": "stdin_stdout"
},
{
"input": "1426 26259 37212278\n",
"output": "33359110\n",
"type": "stdin_stdout"
},
{
"input": "2930 491026 923941798\n",
"output": "409544625\n",
"type": "stdin_stdout"
},
{
"input": "3191 454046 718852491\n",
"output": "267275676\n",
"type": "stdin_stdout"
},
{
"input": "1274 295345 301511265\n",
"output": "165699050\n",
"type": "stdin_stdout"
},
{
"input": "10657 3 9816\n",
"output": "5355\n",
"type": "stdin_stdout"
},
{
"input": "38939 3 6757\n",
"output": "3686\n",
"type": "stdin_stdout"
},
{
"input": "37107 4 28350\n",
"output": "13608\n",
"type": "stdin_stdout"
},
{
"input": "19618 16 313726\n",
"output": "311296\n",
"type": "stdin_stdout"
},
{
"input": "27824 40 906786\n",
"output": "518185\n",
"type": "stdin_stdout"
},
{
"input": "46068 31 424079\n",
"output": "131352\n",
"type": "stdin_stdout"
},
{
"input": "40716 482 14569037\n",
"output": "7363656\n",
"type": "stdin_stdout"
},
{
"input": "48922 150 653002\n",
"output": "135716\n",
"type": "stdin_stdout"
},
{
"input": "37203 219 2355222\n",
"output": "681502\n",
"type": "stdin_stdout"
},
{
"input": "23808 3322 48603931\n",
"output": "20824476\n",
"type": "stdin_stdout"
},
{
"input": "12090 2766 12261436\n",
"output": "3894264\n",
"type": "stdin_stdout"
},
{
"input": "20296 4388 29300901\n",
"output": "8862304\n",
"type": "stdin_stdout"
},
{
"input": "29699 38801 37684232\n",
"output": "6032628\n",
"type": "stdin_stdout"
},
{
"input": "17980 28231 221639883\n",
"output": "76707084\n",
"type": "stdin_stdout"
},
{
"input": "16148 39736 239320912\n",
"output": "76569666\n",
"type": "stdin_stdout"
},
{
"input": "35531 340928 9207622511\n",
"output": "4761654318\n",
"type": "stdin_stdout"
},
{
"input": "43737 111829 865416726\n",
"output": "208223208\n",
"type": "stdin_stdout"
},
{
"input": "21980 353130 2233068545\n",
"output": "638445948\n",
"type": "stdin_stdout"
},
{
"input": "339697 4 1259155\n",
"output": "993876\n",
"type": "stdin_stdout"
},
{
"input": "404625 2 132619\n",
"output": "88413\n",
"type": "stdin_stdout"
},
{
"input": "226111 2 359116\n",
"output": "266010\n",
"type": "stdin_stdout"
},
{
"input": "318377 38 7214261\n",
"output": "3108710\n",
"type": "stdin_stdout"
},
{
"input": "139863 21 1834174\n",
"output": "833220\n",
"type": "stdin_stdout"
},
{
"input": "204791 41 8382971\n",
"output": "8020256\n",
"type": "stdin_stdout"
},
{
"input": "149281 382 51428462\n",
"output": "33762615\n",
"type": "stdin_stdout"
},
{
"input": "370768 123 15161219\n",
"output": "4677246\n",
"type": "stdin_stdout"
},
{
"input": "313975 448 85041752\n",
"output": "36070940\n",
"type": "stdin_stdout"
},
{
"input": "136614 3211 364472869\n",
"output": "209750632\n",
"type": "stdin_stdout"
},
{
"input": "201542 4833 512478332\n",
"output": "197440230\n",
"type": "stdin_stdout"
},
{
"input": "423029 1365 126620483\n",
"output": "32780826\n",
"type": "stdin_stdout"
},
{
"input": "110941 47433 2098952903\n",
"output": "693548595\n",
"type": "stdin_stdout"
},
{
"input": "175869 39014 3201917805\n",
"output": "1148848775\n",
"type": "stdin_stdout"
},
{
"input": "397356 10518 874806404\n",
"output": "222468766\n",
"type": "stdin_stdout"
},
{
"input": "118728 168631 16269281609\n",
"output": "9092195490\n",
"type": "stdin_stdout"
},
{
"input": "183656 409931 42943608085\n",
"output": "17438143800\n",
"type": "stdin_stdout"
},
{
"input": "283422 407789 73398688052\n",
"output": "32237937640\n",
"type": "stdin_stdout"
},
{
"input": "500000 500000 888888\n",
"output": "77856\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/448/D"
} | vfc_9946 |
apps | verifiable_code | 49 | Solve the following coding problem using the programming language python:
Let's write all the positive integer numbers one after another from $1$ without any delimiters (i.e. as a single string). It will be the infinite sequence starting with 123456789101112131415161718192021222324252627282930313233343536...
Your task is to print the $k$-th digit of this sequence.
-----Input-----
The first and only line contains integer $k$ ($1 \le k \le 10^{12}$) — the position to process ($1$-based index).
-----Output-----
Print the $k$-th digit of the resulting infinite sequence.
-----Examples-----
Input
7
Output
7
Input
21
Output
5
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
k = int(input())
if k<=9:
print(k)
else:
num_arr = [9*(i+1)* 10**i for i in range(11)]
index = 0
while True:
if k<=num_arr[index]:
break
else:
k -= num_arr[index]
index += 1
digit = index+1
k += digit-1
num = k//digit
offset = k%digit
string_num = str(10**(digit-1)+ num-1)
print(string_num[offset])
``` | {
"language": "python",
"test_cases": [
{
"input": "7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "12\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "188\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "189\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "190\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "191\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "192\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "193\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "194\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "195\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "196\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "197\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "198\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "199\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "200\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "300\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "400\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "417\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "521\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "511\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2878\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2879\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2880\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "2881\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2882\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2883\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "2884\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2885\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2886\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "2887\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2888\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2889\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2890\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2891\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2892\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2893\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2894\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2895\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2896\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2897\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2898\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2899\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2900\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2901\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4000\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6000\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "7000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8000\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "9000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9900\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9990\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9991\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "9992\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "9993\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9994\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9995\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "9996\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "9997\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "9998\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9999\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10000\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "100000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "100000000\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "99999999995\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "99999999996\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "99999999997\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "99999999998\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "99999999999\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8888888887\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "8888888888\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "8888888889\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "8888888890\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8888888891\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8888888892\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8888888893\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8888888894\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8888888895\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8888888896\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "788888888\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "788888889\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "788888890\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "788888896\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "68888884\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "68888885\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "68888886\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "68888887\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "68888888\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "68888889\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "68888890\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "68888891\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "68888892\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "68888893\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "68888894\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "68888895\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "95863555435\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "100000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "999999999999\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100000000004\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100000000083\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "523452345325\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "134613461346\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "79437383\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "125312355\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "213412341\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1177/B"
} | vfc_9950 |
apps | verifiable_code | 50 | Solve the following coding problem using the programming language python:
Welcome to Codeforces Stock Exchange! We're pretty limited now as we currently allow trading on one stock, Codeforces Ltd. We hope you'll still be able to make profit from the market!
In the morning, there are $n$ opportunities to buy shares. The $i$-th of them allows to buy as many shares as you want, each at the price of $s_i$ bourles.
In the evening, there are $m$ opportunities to sell shares. The $i$-th of them allows to sell as many shares as you want, each at the price of $b_i$ bourles. You can't sell more shares than you have.
It's morning now and you possess $r$ bourles and no shares.
What is the maximum number of bourles you can hold after the evening?
-----Input-----
The first line of the input contains three integers $n, m, r$ ($1 \leq n \leq 30$, $1 \leq m \leq 30$, $1 \leq r \leq 1000$) — the number of ways to buy the shares on the market, the number of ways to sell the shares on the market, and the number of bourles you hold now.
The next line contains $n$ integers $s_1, s_2, \dots, s_n$ ($1 \leq s_i \leq 1000$); $s_i$ indicates the opportunity to buy shares at the price of $s_i$ bourles.
The following line contains $m$ integers $b_1, b_2, \dots, b_m$ ($1 \leq b_i \leq 1000$); $b_i$ indicates the opportunity to sell shares at the price of $b_i$ bourles.
-----Output-----
Output a single integer — the maximum number of bourles you can hold after the evening.
-----Examples-----
Input
3 4 11
4 2 5
4 4 5 4
Output
26
Input
2 2 50
5 7
4 2
Output
50
-----Note-----
In the first example test, you have $11$ bourles in the morning. It's optimal to buy $5$ shares of a stock at the price of $2$ bourles in the morning, and then to sell all of them at the price of $5$ bourles in the evening. It's easy to verify that you'll have $26$ bourles after the evening.
In the second example test, it's optimal not to take any action.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m, r = map(int, input().split())
S = list(map(int, input().split()))
B = list(map(int, input().split()))
x = min(S)
y = max(B)
cnt = r % x
act = r // x
cnt += act * y
print(max(r, cnt))
``` | {
"language": "python",
"test_cases": [
{
"input": "3 4 11\n4 2 5\n4 4 5 4\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "2 2 50\n5 7\n4 2\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1 35\n5\n7\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "1 1 36\n5\n7\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "3 5 20\n1000 4 6\n1 2 7 6 5\n",
"output": "35\n",
"type": "stdin_stdout"
},
{
"input": "5 3 20\n5 4 3 2 1\n6 7 1000\n",
"output": "20000\n",
"type": "stdin_stdout"
},
{
"input": "30 30 987\n413 937 166 77 749 925 792 353 773 88 218 863 71 186 753 306 952 966 236 501 84 163 767 99 887 380 435 888 589 761\n68 501 323 916 506 952 411 813 664 49 860 151 120 543 168 944 302 521 245 517 464 734 205 235 173 893 109 655 346 837\n",
"output": "12440\n",
"type": "stdin_stdout"
},
{
"input": "30 22 1000\n999 953 947 883 859 857 775 766 723 713 696 691 659 650 597 474 472 456 455 374 367 354 347 215 111 89 76 76 59 55\n172 188 223 247 404 445 449 489 493 554 558 587 588 627 686 714 720 744 747 786 830 953\n",
"output": "17164\n",
"type": "stdin_stdout"
},
{
"input": "28 29 1000\n555 962 781 562 856 700 628 591 797 873 950 607 526 513 552 954 768 823 863 650 984 653 741 548 676 577 625 902\n185 39 223 383 221 84 165 492 79 53 475 410 314 489 59 138 395 346 91 258 14 354 410 25 41 394 463 432 325\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "30 29 999\n993 982 996 992 988 984 981 982 981 981 992 997 982 996 995 981 995 982 994 996 988 986 990 991 987 993 1000 989 998 991\n19 12 14 5 20 11 15 11 7 14 12 8 1 9 7 15 6 20 15 20 17 15 20 1 4 13 2 2 17\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "30 30 999\n19 8 6 1 4 12 14 12 8 14 14 2 13 11 10 15 13 14 2 5 15 17 18 16 9 4 2 14 12 9\n993 987 993 998 998 987 980 986 995 987 998 989 981 982 983 981 997 991 989 989 993 990 984 997 995 984 982 994 990 984\n",
"output": "997002\n",
"type": "stdin_stdout"
},
{
"input": "28 30 1000\n185 184 177 171 165 162 162 154 150 136 133 127 118 111 106 106 95 92 86 85 77 66 65 40 28 10 10 4\n305 309 311 313 319 321 323 338 349 349 349 351 359 373 378 386 405 409 420 445 457 462 463 466 466 471 473 479 479 482\n",
"output": "120500\n",
"type": "stdin_stdout"
},
{
"input": "1 1 10\n11\n1000\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "29 30 989\n450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450 450\n451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451 451\n",
"output": "991\n",
"type": "stdin_stdout"
},
{
"input": "25 30 989\n153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153\n153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153 153\n",
"output": "989\n",
"type": "stdin_stdout"
},
{
"input": "30 26 997\n499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499 499\n384 384 384 384 384 384 384 384 384 384 384 384 384 384 384 384 384 384 384 384 384 384 384 384 384 384\n",
"output": "997\n",
"type": "stdin_stdout"
},
{
"input": "30 30 1000\n1 4 2 2 2 1 2 2 2 3 3 3 1 4 2 4 3 1 2 2 3 2 4 2 3 4 2 4 3 2\n1000 999 997 1000 999 998 999 999 1000 1000 997 997 999 997 999 997 997 999 1000 999 997 998 998 998 997 997 999 1000 998 998\n",
"output": "1000000\n",
"type": "stdin_stdout"
},
{
"input": "30 29 42\n632 501 892 532 293 47 45 669 129 616 322 92 812 499 205 115 889 442 589 34 681 944 49 546 134 625 937 179 1000 69\n837 639 443 361 323 493 639 573 645 55 711 190 905 628 627 278 967 926 398 479 71 829 960 916 360 43 341 337 90\n",
"output": "975\n",
"type": "stdin_stdout"
},
{
"input": "30 30 1000\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n962 987 940 905 911 993 955 994 984 994 923 959 923 993 959 925 922 909 932 911 994 1000 994 976 915 979 928 999 993 956\n",
"output": "1000000\n",
"type": "stdin_stdout"
},
{
"input": "1 1 100\n90\n91\n",
"output": "101\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1000\n501\n502\n",
"output": "1001\n",
"type": "stdin_stdout"
},
{
"input": "2 1 8\n3 4\n5\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "1 3 10\n2\n4 5 10\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "4 4 50\n12 11 30 30\n12 12 12 12\n",
"output": "54\n",
"type": "stdin_stdout"
},
{
"input": "5 10 10\n2 2 2 2 2\n2 2 2 2 2 2 2 2 2 3\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "1 2 100\n1\n1 100\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "9 7 999\n999 999 999 999 999 999 999 999 999\n999 999 999 999 999 999 999\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1 3 10\n2\n2 3 5\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "1 1 4\n3\n4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 1 100\n99\n100\n",
"output": "101\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5\n1\n2 5\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "3 3 10\n10 12 15\n30 50 50\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "1 1 13\n11\n12\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "1 2 2\n1\n1 10\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "1 10 10\n2\n4 5 10 1 1 1 1 1 1 1\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "2 16 729\n831 752\n331 882 112 57 754 314 781 390 193 285 109 301 308 750 39 94\n",
"output": "729\n",
"type": "stdin_stdout"
},
{
"input": "1 1 7\n5\n6\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "3 3 1000\n600 600 600\n999 999 999\n",
"output": "1399\n",
"type": "stdin_stdout"
},
{
"input": "1 1 10\n4\n5\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "1 1 7\n5\n7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1 1 5\n5\n6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "2 3 100\n2 2\n2 2 10\n",
"output": "500\n",
"type": "stdin_stdout"
},
{
"input": "1 5 10\n2\n1 1 1 1 10\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "2 4 2\n1 1\n1 1 1 100\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "1 2 100\n1\n1 2\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "1 1 15\n6\n7\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "2 5 100\n10 10\n2 2 2 100 100\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "1 2 4\n3\n4 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 2 100\n50\n50 100\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "1 2 10\n1\n2 10\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "2 4 100\n1 1\n1 1 1 100\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "1 1 10\n10\n20\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "1 1 4\n4\n5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 28 10\n5\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 10\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "1 1 3\n3\n20\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1000\n52 51\n53\n",
"output": "1038\n",
"type": "stdin_stdout"
},
{
"input": "2 1 7\n5 4\n10\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "2 1 10\n5 4\n100\n",
"output": "202\n",
"type": "stdin_stdout"
},
{
"input": "2 1 11\n5 4\n6\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "1 30 1\n1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1 5\n5\n10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 1 5\n5\n20\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "2 2 50\n5 7\n6 2\n",
"output": "60\n",
"type": "stdin_stdout"
},
{
"input": "2 1 8\n6 5\n10\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "2 1 17\n8 7\n10\n",
"output": "23\n",
"type": "stdin_stdout"
},
{
"input": "2 3 8\n4 3\n10 20 30\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "1 2 2\n2\n1 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1 2 10\n1\n1 5\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "1 1 100\n1000\n10\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "2 3 100\n5 5\n1 1 100\n",
"output": "2000\n",
"type": "stdin_stdout"
},
{
"input": "1 1 10\n20\n30\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 2 4\n1\n1 2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1 3 1\n1\n1 1 100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1 1 999\n500\n501\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "1 2 10\n1\n1 2\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "1 1 10\n7\n9\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "2 5 100\n2 2\n2 2 2 2 5\n",
"output": "250\n",
"type": "stdin_stdout"
},
{
"input": "2 3 10\n1 1\n1 1 2\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "1 2 10\n1\n9 8\n",
"output": "90\n",
"type": "stdin_stdout"
},
{
"input": "2 5 10\n2 2\n2 2 2 2 5\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "5 6 8\n7 7 10 5 5\n5 6 2 8 1 8\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "1 1 5\n1\n4\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "12 21 30\n24 15 29 5 16 29 12 17 6 19 16 11\n8 15 12 10 15 20 21 27 18 18 22 15 28 21 29 13 13 9 13 5 3\n",
"output": "174\n",
"type": "stdin_stdout"
},
{
"input": "1 3 5\n1\n1 2 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 3 1000\n10\n10 30 20\n",
"output": "3000\n",
"type": "stdin_stdout"
},
{
"input": "1 1 15\n4\n5\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "1 1 4\n8\n7\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1 1 12\n10\n11\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "2 4 7\n1 1\n1 1 1 10\n",
"output": "70\n",
"type": "stdin_stdout"
},
{
"input": "2 5 10\n1 2\n3 4 5 6 7\n",
"output": "70\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5\n3\n2 10\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "2 3 11\n2 2\n3 3 5\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "1 3 50\n10\n10 30 20\n",
"output": "150\n",
"type": "stdin_stdout"
},
{
"input": "1 5 10\n5\n1 1 1 1 10\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "1 2 19\n10\n1 11\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "1 3 4\n1\n1 5 2\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "1 2 100\n2\n1 10\n",
"output": "500\n",
"type": "stdin_stdout"
},
{
"input": "1 1 12\n9\n10\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "3 4 11\n4 2 5\n4 4 4 5\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "1 1 8\n6\n7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1 1 7\n4\n5\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1 5 10\n1\n5 5 5 5 10\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1 2 10\n1\n1 20\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5\n1\n2 3\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "1 3 100\n5\n1 1 1000\n",
"output": "20000\n",
"type": "stdin_stdout"
},
{
"input": "2 1 11\n5 4\n5\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "4 3 11\n1 2 3 4\n1 2 3\n",
"output": "33\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5\n2\n2 100\n",
"output": "201\n",
"type": "stdin_stdout"
},
{
"input": "1 5 10\n2\n1 1 1 1 100\n",
"output": "500\n",
"type": "stdin_stdout"
},
{
"input": "3 3 11\n4 5 6\n1 2 5\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "2 3 5\n1 1\n2 2 5\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "3 4 10\n5 3 1\n10 10 10 1000\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "1 1 13\n5\n6\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1000\n51\n52\n",
"output": "1019\n",
"type": "stdin_stdout"
},
{
"input": "1 2 10\n1\n3 10\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "3 4 2\n5 3 5\n10 10 10 1000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1 1 11\n8\n9\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5\n5\n5 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 5 10\n1\n2 2 2 2 5\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "1 2 1\n1\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 5 100\n1 1 1\n2 2 2 2 7\n",
"output": "700\n",
"type": "stdin_stdout"
},
{
"input": "1 2 10\n2\n2 10\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "3 9 15\n1 2 3\n1 2 3 4 4 6 5 5 4\n",
"output": "90\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1150/A"
} | vfc_9954 |
apps | verifiable_code | 51 | Solve the following coding problem using the programming language python:
В Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в одно. При таком слиянии конец первого сообщения совмещается с началом второго. Конечно, совмещение может происходить только по одинаковым символам. Длина совмещения должна быть положительным числом, меньшим длины текста сообщения.
Например, при передаче двух сообщений «abrakadabra» подряд возможно, что оно будет передано с ошибкой описанного вида, и тогда будет получено сообщение вида «abrakadabrabrakadabra» или «abrakadabrakadabra» (в первом случае совмещение произошло по одному символу, а во втором — по четырем).
По полученному сообщению t определите, возможно ли, что это результат ошибки описанного вида работы локальной сети, и если возможно, определите возможное значение s.
Не следует считать ошибкой ситуацию полного наложения друга на друга двух сообщений. К примеру, если получено сообщение «abcd», следует считать, что в нём ошибки нет. Аналогично, простое дописывание одного сообщения вслед за другим не является признаком ошибки. Например, если получено сообщение «abcabc», следует считать, что в нём ошибки нет.
-----Входные данные-----
В единственной строке выходных данных следует непустая строка t, состоящая из строчных букв латинского алфавита. Длина строки t не превосходит 100 символов.
-----Выходные данные-----
Если сообщение t не может содержать ошибки, выведите «NO» (без кавычек) в единственную строку выходных данных.
В противном случае в первой строке выведите «YES» (без кавычек), а в следующей строке выведите строку s — возможное сообщение, которое могло привести к ошибке. Если возможных ответов несколько, разрешается вывести любой из них.
-----Примеры-----
Входные данные
abrakadabrabrakadabra
Выходные данные
YES
abrakadabra
Входные данные
acacacaca
Выходные данные
YES
acaca
Входные данные
abcabc
Выходные данные
NO
Входные данные
abababab
Выходные данные
YES
ababab
Входные данные
tatbt
Выходные данные
NO
-----Примечание-----
Во втором примере подходящим ответом также является строка acacaca.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
t = 0
if len(s)%2==0:
n = (len(s)-1)//2+1
else:
n = (len(s)-1)//2
for i in range(n, len(s)-1):
a = i
b = len(s)-i-1
if s[:a+1]==s[b:]:
print('YES')
print(s[:a+1])
t = 1
break
if t==0:
print('NO')
``` | {
"language": "python",
"test_cases": [
{
"input": "abrakadabrabrakadabra\n",
"output": "YES\nabrakadabra\n",
"type": "stdin_stdout"
},
{
"input": "acacacaca\n",
"output": "YES\nacaca\n",
"type": "stdin_stdout"
},
{
"input": "abcabc\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "abababab\n",
"output": "YES\nababab\n",
"type": "stdin_stdout"
},
{
"input": "tatbt\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"output": "YES\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"type": "stdin_stdout"
},
{
"input": "r\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "zaz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "zaza\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "gg\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "gagaga\n",
"output": "YES\ngaga\n",
"type": "stdin_stdout"
},
{
"input": "hhhh\n",
"output": "YES\nhhh\n",
"type": "stdin_stdout"
},
{
"input": "sssss\n",
"output": "YES\nsss\n",
"type": "stdin_stdout"
},
{
"input": "nxnxnx\n",
"output": "YES\nnxnx\n",
"type": "stdin_stdout"
},
{
"input": "vygvygv\n",
"output": "YES\nvygv\n",
"type": "stdin_stdout"
},
{
"input": "rlrlrlrl\n",
"output": "YES\nrlrlrl\n",
"type": "stdin_stdout"
},
{
"input": "zyzyzyzyz\n",
"output": "YES\nzyzyz\n",
"type": "stdin_stdout"
},
{
"input": "jjjjjjjjjj\n",
"output": "YES\njjjjjj\n",
"type": "stdin_stdout"
},
{
"input": "kkhuskkhusk\n",
"output": "YES\nkkhusk\n",
"type": "stdin_stdout"
},
{
"input": "gzgzgzgzgzgz\n",
"output": "YES\ngzgzgzgz\n",
"type": "stdin_stdout"
},
{
"input": "vkyxvkyxvkyxv\n",
"output": "YES\nvkyxvkyxv\n",
"type": "stdin_stdout"
},
{
"input": "uuuuuuuuuuuuuu\n",
"output": "YES\nuuuuuuuu\n",
"type": "stdin_stdout"
},
{
"input": "esxwpesxwpesxwp\n",
"output": "YES\nesxwpesxwp\n",
"type": "stdin_stdout"
},
{
"input": "qltrajqltrajqltr\n",
"output": "YES\nqltrajqltr\n",
"type": "stdin_stdout"
},
{
"input": "alxalxalxalxalxal\n",
"output": "YES\nalxalxalxal\n",
"type": "stdin_stdout"
},
{
"input": "ijtojrijtojrijtojr\n",
"output": "YES\nijtojrijtojr\n",
"type": "stdin_stdout"
},
{
"input": "yhbhamyhbhamyhbhamy\n",
"output": "YES\nyhbhamyhbhamy\n",
"type": "stdin_stdout"
},
{
"input": "cdrcuccdrcuccdrcuccd\n",
"output": "YES\ncdrcuccdrcuccd\n",
"type": "stdin_stdout"
},
{
"input": "ddoaxeaddoaxeaddoaxea\n",
"output": "YES\nddoaxeaddoaxea\n",
"type": "stdin_stdout"
},
{
"input": "ejfrayejfrayejfrayejfr\n",
"output": "YES\nejfrayejfrayejfr\n",
"type": "stdin_stdout"
},
{
"input": "oxciazoxciazoxciazoxcia\n",
"output": "YES\noxciazoxciazoxcia\n",
"type": "stdin_stdout"
},
{
"input": "zfusxizfusxizfusxizfusxi\n",
"output": "YES\nzfusxizfusxizfusxi\n",
"type": "stdin_stdout"
},
{
"input": "kqkqkqkqkqkqkqkqkqkqkqkqk\n",
"output": "YES\nkqkqkqkqkqkqk\n",
"type": "stdin_stdout"
},
{
"input": "mrmrmrmrmrmrmrmrmrmrmrmrmr\n",
"output": "YES\nmrmrmrmrmrmrmr\n",
"type": "stdin_stdout"
},
{
"input": "wnwnwnwnwnwnwnwnwnwnwnwnwnw\n",
"output": "YES\nwnwnwnwnwnwnwnw\n",
"type": "stdin_stdout"
},
{
"input": "zchvhrmcrzchvhrmcrzchvhrmcrz\n",
"output": "YES\nzchvhrmcrzchvhrmcrz\n",
"type": "stdin_stdout"
},
{
"input": "hngryskhngryskhngryskhngryskh\n",
"output": "YES\nhngryskhngryskh\n",
"type": "stdin_stdout"
},
{
"input": "papapapapapapapapapapapapapapa\n",
"output": "YES\npapapapapapapapa\n",
"type": "stdin_stdout"
},
{
"input": "qqgedqkewrelydzqqgedqkewrelydzq\n",
"output": "YES\nqqgedqkewrelydzq\n",
"type": "stdin_stdout"
},
{
"input": "mtphoncwmtphoncwmtphoncwmtphoncw\n",
"output": "YES\nmtphoncwmtphoncwmtphoncw\n",
"type": "stdin_stdout"
},
{
"input": "sypfetgsuhifxzsypfetgsuhifxzsypfe\n",
"output": "YES\nsypfetgsuhifxzsypfe\n",
"type": "stdin_stdout"
},
{
"input": "avhiggygrtudeavhiggygrtudeavhiggyg\n",
"output": "YES\navhiggygrtudeavhiggyg\n",
"type": "stdin_stdout"
},
{
"input": "hphhiattwnahphhiattwnahphhiattwnahp\n",
"output": "YES\nhphhiattwnahphhiattwnahp\n",
"type": "stdin_stdout"
},
{
"input": "lpuilpuilpuilpuilpuilpuilpuilpuilpui\n",
"output": "YES\nlpuilpuilpuilpuilpui\n",
"type": "stdin_stdout"
},
{
"input": "bbztwlxbocpbbztwlxbocpbbztwlxbocpbbzt\n",
"output": "YES\nbbztwlxbocpbbztwlxbocpbbzt\n",
"type": "stdin_stdout"
},
{
"input": "dvdvdvdvdvdvdvdvdvdvdvdvdvdvdvdvdvdvdv\n",
"output": "YES\ndvdvdvdvdvdvdvdvdvdv\n",
"type": "stdin_stdout"
},
{
"input": "mnvkmnvkmnvkmnvkmnvkmnvkmnvkmnvkmnvkmnv\n",
"output": "YES\nmnvkmnvkmnvkmnvkmnvkmnv\n",
"type": "stdin_stdout"
},
{
"input": "ugugugugugugugugugugugugugugugugugugugug\n",
"output": "YES\nugugugugugugugugugugug\n",
"type": "stdin_stdout"
},
{
"input": "nyilpgayabfzpqifnyilpgayabfzpqifnyilpgaya\n",
"output": "YES\nnyilpgayabfzpqifnyilpgaya\n",
"type": "stdin_stdout"
},
{
"input": "awxmegcmrkzawxmegcmrkzawxmegcmrkzawxmegcmr\n",
"output": "YES\nawxmegcmrkzawxmegcmrkzawxmegcmr\n",
"type": "stdin_stdout"
},
{
"input": "ugduygugduygugduygugduygugduygugduygugduygu\n",
"output": "YES\nugduygugduygugduygugduygu\n",
"type": "stdin_stdout"
},
{
"input": "dkwelorlspdltsdkwelorlspdltsdkwelorlspdltsdk\n",
"output": "YES\ndkwelorlspdltsdkwelorlspdltsdk\n",
"type": "stdin_stdout"
},
{
"input": "xwyxssvcedrwtpgxwyxssvcedrwtpgxwyxssvcedrwtpg\n",
"output": "YES\nxwyxssvcedrwtpgxwyxssvcedrwtpg\n",
"type": "stdin_stdout"
},
{
"input": "pwjkpwjkpwjkpwjkpwjkpwjkpwjkpwjkpwjkpwjkpwjkpw\n",
"output": "YES\npwjkpwjkpwjkpwjkpwjkpwjkpw\n",
"type": "stdin_stdout"
},
{
"input": "vxumrzwwzrzzfuvxumrzwwzrzzfuvxumrzwwzrzzfuvxumr\n",
"output": "YES\nvxumrzwwzrzzfuvxumrzwwzrzzfuvxumr\n",
"type": "stdin_stdout"
},
{
"input": "kkkkrhhkkkkrhhkkkkrhhkkkkrhhkkkkrhhkkkkrhhkkkkrh\n",
"output": "YES\nkkkkrhhkkkkrhhkkkkrhhkkkkrh\n",
"type": "stdin_stdout"
},
{
"input": "lfbpinxnjsfvjsfbshblyvlfbpinxnjsfvjsfbshblyvlfbpi\n",
"output": "YES\nlfbpinxnjsfvjsfbshblyvlfbpi\n",
"type": "stdin_stdout"
},
{
"input": "sqdrmjqbfbmjmqfbcemrjtsqdrmjqbfbmjmqfbcemrjtsqdrmj\n",
"output": "YES\nsqdrmjqbfbmjmqfbcemrjtsqdrmj\n",
"type": "stdin_stdout"
},
{
"input": "eeaiaeeaiaeeaiaeeaiaeeaiaeeaiaeeaiaeeaiaeeaiaeeaiae\n",
"output": "YES\neeaiaeeaiaeeaiaeeaiaeeaiae\n",
"type": "stdin_stdout"
},
{
"input": "fhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfh\n",
"output": "YES\nfhfhfhfhfhfhfhfhfhfhfhfhfhfh\n",
"type": "stdin_stdout"
},
{
"input": "ouygsznbnotbouygsznbnotbouygsznbnotbouygsznbnotbouygs\n",
"output": "YES\nouygsznbnotbouygsznbnotbouygs\n",
"type": "stdin_stdout"
},
{
"input": "wtqqagwaguqgaffuqgqtwtwawtqqagwaguqgaffuqgqtwtwawtqqag\n",
"output": "YES\nwtqqagwaguqgaffuqgqtwtwawtqqag\n",
"type": "stdin_stdout"
},
{
"input": "sogoiyexpwmpaixsogoiyexpwmpaixsogoiyexpwmpaixsogoiyexpw\n",
"output": "YES\nsogoiyexpwmpaixsogoiyexpwmpaixsogoiyexpw\n",
"type": "stdin_stdout"
},
{
"input": "vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n",
"output": "YES\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\n",
"type": "stdin_stdout"
},
{
"input": "hlyjflfbvbtvtqtsjklkfsbqthvshlyjflfbvbtvtqtsjklkfsbqthvsh\n",
"output": "YES\nhlyjflfbvbtvtqtsjklkfsbqthvsh\n",
"type": "stdin_stdout"
},
{
"input": "mlymfzfkmkfjomlymfzfkmkfjomlymfzfkmkfjomlymfzfkmkfjomlymfz\n",
"output": "YES\nmlymfzfkmkfjomlymfzfkmkfjomlymfz\n",
"type": "stdin_stdout"
},
{
"input": "swylxswylxswylxswylxswylxswylxswylxswylxswylxswylxswylxswyl\n",
"output": "YES\nswylxswylxswylxswylxswylxswylxswyl\n",
"type": "stdin_stdout"
},
{
"input": "cifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcif\n",
"output": "YES\ncifcifcifcifcifcifcifcifcifcifcif\n",
"type": "stdin_stdout"
},
{
"input": "lvifmwwfkvewsezsufghillvifmwwfkvewsezsufghillvifmwwfkvewsezsu\n",
"output": "YES\nlvifmwwfkvewsezsufghillvifmwwfkvewsezsu\n",
"type": "stdin_stdout"
},
{
"input": "mhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtg\n",
"output": "YES\nmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtg\n",
"type": "stdin_stdout"
},
{
"input": "szfsdufuduiofckbszfsdufuduiofckbszfsdufuduiofckbszfsdufuduiofck\n",
"output": "YES\nszfsdufuduiofckbszfsdufuduiofckbszfsdufuduiofck\n",
"type": "stdin_stdout"
},
{
"input": "ceypvrszdqljkzezlcceypvrszdqljkzezlcceypvrszdqljkzezlcceypvrszdq\n",
"output": "YES\nceypvrszdqljkzezlcceypvrszdqljkzezlcceypvrszdq\n",
"type": "stdin_stdout"
},
{
"input": "ojmtpzmojamdjydojmtpzmojamdjydojmtpzmojamdjydojmtpzmojamdjydojmtp\n",
"output": "YES\nojmtpzmojamdjydojmtpzmojamdjydojmtp\n",
"type": "stdin_stdout"
},
{
"input": "uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\n",
"output": "YES\nuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\n",
"type": "stdin_stdout"
},
{
"input": "uhkuqbhrhlqjhgbshsvtqouquhkuqbhrhlqjhgbshsvtqouquhkuqbhrhlqjhgbshsv\n",
"output": "YES\nuhkuqbhrhlqjhgbshsvtqouquhkuqbhrhlqjhgbshsv\n",
"type": "stdin_stdout"
},
{
"input": "xcgtgdpomjvngwdtrvrttldigxcgtgdpomjvngwdtrvrttldigxcgtgdpomjvngwdtrv\n",
"output": "YES\nxcgtgdpomjvngwdtrvrttldigxcgtgdpomjvngwdtrv\n",
"type": "stdin_stdout"
},
{
"input": "vuuovdvktdjvuaafiguzdrrtratjyvuuovdvktdjvuaafiguzdrrtratjyvuuovdvktdj\n",
"output": "YES\nvuuovdvktdjvuaafiguzdrrtratjyvuuovdvktdj\n",
"type": "stdin_stdout"
},
{
"input": "yukcccrccccyukcccrccccyukcccrccccyukcccrccccyukcccrccccyukcccrccccyukc\n",
"output": "YES\nyukcccrccccyukcccrccccyukcccrccccyukc\n",
"type": "stdin_stdout"
},
{
"input": "rrriiiiaaainnrrrainniiarirrriiiiaaainnrrrainniiarirrriiiiaaainnrrrainni\n",
"output": "YES\nrrriiiiaaainnrrrainniiarirrriiiiaaainnrrrainni\n",
"type": "stdin_stdout"
},
{
"input": "xmxxumdfubrcsbccxmxxumdfubrcsbccxmxxumdfubrcsbccxmxxumdfubrcsbccxmxxumdf\n",
"output": "YES\nxmxxumdfubrcsbccxmxxumdfubrcsbccxmxxumdf\n",
"type": "stdin_stdout"
},
{
"input": "xovouvxuxtcvvovpxnhruswcphrstctxovouvxuxtcvvovpxnhruswcphrstctxovouvxuxtc\n",
"output": "YES\nxovouvxuxtcvvovpxnhruswcphrstctxovouvxuxtc\n",
"type": "stdin_stdout"
},
{
"input": "howwwscoebckiatfzarhowwwscoebckiatfzarhowwwscoebckiatfzarhowwwscoebckiatfz\n",
"output": "YES\nhowwwscoebckiatfzarhowwwscoebckiatfzarhowwwscoebckiatfz\n",
"type": "stdin_stdout"
},
{
"input": "ickpakvkbaljifqdifjfcdxpashuickpakvkbaljifqdifjfcdxpashuickpakvkbaljifqdifj\n",
"output": "YES\nickpakvkbaljifqdifjfcdxpashuickpakvkbaljifqdifj\n",
"type": "stdin_stdout"
},
{
"input": "zgzwgwggzggwzzwwwhzgzgzwgwggzggwzzwwwhzgzgzwgwggzggwzzwwwhzgzgzwgwggzggwzzww\n",
"output": "YES\nzgzwgwggzggwzzwwwhzgzgzwgwggzggwzzwwwhzgzgzwgwggzggwzzww\n",
"type": "stdin_stdout"
},
{
"input": "ppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyh\n",
"output": "YES\nppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyh\n",
"type": "stdin_stdout"
},
{
"input": "itlmmmqfkflfamdaqekrjlocitlmmmqfkflfamdaqekrjlocitlmmmqfkflfamdaqekrjlocitlmmm\n",
"output": "YES\nitlmmmqfkflfamdaqekrjlocitlmmmqfkflfamdaqekrjlocitlmmm\n",
"type": "stdin_stdout"
},
{
"input": "yqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqy\n",
"output": "YES\nyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqy\n",
"type": "stdin_stdout"
},
{
"input": "ijdghvidfbqqpajplojvtlppdiftzvhuqatijdghvidfbqqpajplojvtlppdiftzvhuqatijdghvidfb\n",
"output": "YES\nijdghvidfbqqpajplojvtlppdiftzvhuqatijdghvidfb\n",
"type": "stdin_stdout"
},
{
"input": "jozbicochmmtmmhogkgrfutknpjozbicochmmtmmhogkgrfutknpjozbicochmmtmmhogkgrfutknpjoz\n",
"output": "YES\njozbicochmmtmmhogkgrfutknpjozbicochmmtmmhogkgrfutknpjoz\n",
"type": "stdin_stdout"
},
{
"input": "tvsyxhopzmbebwoimyxhjbjuyszplhhggftvsyxhopzmbebwoimyxhjbjuyszplhhggftvsyxhopzmbebw\n",
"output": "YES\ntvsyxhopzmbebwoimyxhjbjuyszplhhggftvsyxhopzmbebw\n",
"type": "stdin_stdout"
},
{
"input": "kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n",
"output": "YES\nkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\n",
"type": "stdin_stdout"
},
{
"input": "zyqxlypnlpavjxuydvxcnnzszyqxlypnlpavjxuydvxcnnzszyqxlypnlpavjxuydvxcnnzszyqxlypnlpav\n",
"output": "YES\nzyqxlypnlpavjxuydvxcnnzszyqxlypnlpavjxuydvxcnnzszyqxlypnlpav\n",
"type": "stdin_stdout"
},
{
"input": "irlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlg\n",
"output": "YES\nirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlg\n",
"type": "stdin_stdout"
},
{
"input": "hththththththththththththththththththththththththththththththththththththththththththt\n",
"output": "YES\nhthththththththththththththththththththththt\n",
"type": "stdin_stdout"
},
{
"input": "wlladflfanfmlljbbldamdjabtfbnftawbfnllfjwlladflfanfmlljbbldamdjabtfbnftawbfnllfjwlladfl\n",
"output": "YES\nwlladflfanfmlljbbldamdjabtfbnftawbfnllfjwlladfl\n",
"type": "stdin_stdout"
},
{
"input": "frxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxa\n",
"output": "YES\nfrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxa\n",
"type": "stdin_stdout"
},
{
"input": "uzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbif\n",
"output": "YES\nuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbif\n",
"type": "stdin_stdout"
},
{
"input": "dzpttoozpoqsjywqnzokdzpttoozpoqsjywqnzokdzpttoozpoqsjywqnzokdzpttoozpoqsjywqnzokdzpttoozpo\n",
"output": "YES\ndzpttoozpoqsjywqnzokdzpttoozpoqsjywqnzokdzpttoozpo\n",
"type": "stdin_stdout"
},
{
"input": "avqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaa\n",
"output": "YES\navqriqniaavqriqniaavqriqniaavqriqniaavqriqniaa\n",
"type": "stdin_stdout"
},
{
"input": "qqpppqqpqqqqqpqqpqpqqqpqpqqqqqqqpppqqpqqqqqpqqpqpqqqpqpqqqqqqqpppqqpqqqqqpqqpqpqqqpqpqqqqqqq\n",
"output": "YES\nqqpppqqpqqqqqpqqpqpqqqpqpqqqqqqqpppqqpqqqqqpqqpqpqqqpqpqqqqqqq\n",
"type": "stdin_stdout"
},
{
"input": "mnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmn\n",
"output": "YES\nmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmn\n",
"type": "stdin_stdout"
},
{
"input": "qzcgreoroxoxqzwvvoeiggriwrzotcxizqzcgreoroxoxqzwvvoeiggriwrzotcxizqzcgreoroxoxqzwvvoeiggriwrzo\n",
"output": "YES\nqzcgreoroxoxqzwvvoeiggriwrzotcxizqzcgreoroxoxqzwvvoeiggriwrzo\n",
"type": "stdin_stdout"
},
{
"input": "pymvkuoucpujkekgnjrvnkrvodtszsbkmoabtlgdbpymvkuoucpujkekgnjrvnkrvodtszsbkmoabtlgdbpymvkuoucpujk\n",
"output": "YES\npymvkuoucpujkekgnjrvnkrvodtszsbkmoabtlgdbpymvkuoucpujk\n",
"type": "stdin_stdout"
},
{
"input": "yguclskcmiuobsgckhotgkzqykebvttqaqmtzsyguclskcmiuobsgckhotgkzqykebvttqaqmtzsyguclskcmiuobsgckhot\n",
"output": "YES\nyguclskcmiuobsgckhotgkzqykebvttqaqmtzsyguclskcmiuobsgckhot\n",
"type": "stdin_stdout"
},
{
"input": "kowiovfyffitkipvmccesjhatgyqaekowiovfyffitkipvmccesjhatgyqaekowiovfyffitkipvmccesjhatgyqaekowiovf\n",
"output": "YES\nkowiovfyffitkipvmccesjhatgyqaekowiovfyffitkipvmccesjhatgyqaekowiovf\n",
"type": "stdin_stdout"
},
{
"input": "mrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdreps\n",
"output": "YES\nmrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdreps\n",
"type": "stdin_stdout"
},
{
"input": "hgxenqnawiyiirinhraywlhgxenqnawiyiirinhraywlhgxenqnawiyiirinhraywlhgxenqnawiyiirinhraywlhgxenqnawiy\n",
"output": "YES\nhgxenqnawiyiirinhraywlhgxenqnawiyiirinhraywlhgxenqnawiy\n",
"type": "stdin_stdout"
},
{
"input": "foxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfo\n",
"output": "YES\nfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfo\n",
"type": "stdin_stdout"
},
{
"input": "bkwdegdnxtnvtczozttjitzmfienbtxhoipldptluxbtvhmybkwdegdnxtnvtczozttjitzmfienbtxhoipldptluxbtvhmybkwd\n",
"output": "YES\nbkwdegdnxtnvtczozttjitzmfienbtxhoipldptluxbtvhmybkwd\n",
"type": "stdin_stdout"
},
{
"input": "cftorbxtglokyoxsemzlysptutvldtlzqbhawyecivljlcftorbxtglokyoxsemzlysptutvldtlzqbhawyecivljlcftorbxtgl\n",
"output": "YES\ncftorbxtglokyoxsemzlysptutvldtlzqbhawyecivljlcftorbxtgl\n",
"type": "stdin_stdout"
},
{
"input": "twfflboprkkjobbgoubmybfkbmmconrjhsktwfflboprkkjobbgoubmybfkbmmconrjhsktwfflboprkkjobbgoubmybfkbmmcon\n",
"output": "YES\ntwfflboprkkjobbgoubmybfkbmmconrjhsktwfflboprkkjobbgoubmybfkbmmcon\n",
"type": "stdin_stdout"
},
{
"input": "wajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmk\n",
"output": "YES\nwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmk\n",
"type": "stdin_stdout"
},
{
"input": "pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\n",
"output": "YES\nppppppppppppppppppppppppppppppppppppppppppppppppppp\n",
"type": "stdin_stdout"
},
{
"input": "axquczgfdshcpqjcqaxquczgfdshcpqjcqaxquczgfdshcpqjcqaxquczxfdshcpqjcqaxquczgfdshcpqjcqaxquc\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "vyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvshsqvvyhsqvv\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "bpqxbraxrcxwdoftbpqxbraxryxwdoftbpqxbraxrcxwdoftbpqxbraxrcxwdoftbpqxbraxrcxwdoftbpqxbraxrcxw\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "renpsuotrenpsuotrenpsuotrenpsuotrenpsuotrenpsuoprenpsuotrenpsuotrenpsuotrenpsuotrenpsuotrenps\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "qqeemdmddqddkmudbmaabaedquqmqqdqqqeemdmddqddkmudbmaabaedquqmqqdqqqeemdmddqddkmudbmaabaedquqmqq\n",
"output": "YES\nqqeemdmddqddkmudbmaabaedquqmqqdqqqeemdmddqddkmudbmaabaedquqmqq\n",
"type": "stdin_stdout"
},
{
"input": "gfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpis\n",
"output": "YES\ngfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpis\n",
"type": "stdin_stdout"
},
{
"input": "nnsssnnngsbnngnsnnbgbgnbnbnnsssnnngsbnngnsnnbgbgnbnbnnsssnnngsbnngnbnnbgbgnbnbnnsssnnngsbnngnsnn\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "qimxxxojmmjqmxqfxfqiximjxqimxxxojqmjqmxqfxfqiximjxqimxxxojmmjqmxqfxfqiximjxqimxxxojmmjqmxqfxfqixi\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "otjwmbgahamrbbhnttmoqahohbhbjxwkbtotjwmbgahamrbbhnttmoqahohbhyjxwkbtotjwmbgahamrbbhnttmoqahohbhbjx\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "hligdsxyzyjejeskxapshligdsxyzyjejeskxapshligdsxyzyjejeskxapshligdsxyzyjejeskxapshligdsxyzljejeskxap\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "ooogesrsajsnzroyhabbckrnovooogesrsajsnzroyhabbckrnovooogesrsajsnzroyhabbckrnovooogesrsajsnzroyhadbck\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/646/B"
} | vfc_9958 |
apps | verifiable_code | 52 | Solve the following coding problem using the programming language python:
Daniel is organizing a football tournament. He has come up with the following tournament format: In the first several (possibly zero) stages, while the number of teams is even, they split in pairs and play one game for each pair. At each stage the loser of each pair is eliminated (there are no draws). Such stages are held while the number of teams is even. Eventually there will be an odd number of teams remaining. If there is one team remaining, it will be declared the winner, and the tournament ends. Otherwise each of the remaining teams will play with each other remaining team once in round robin tournament (if there are x teams, there will be $\frac{x \cdot(x - 1)}{2}$ games), and the tournament ends.
For example, if there were 20 teams initially, they would begin by playing 10 games. So, 10 teams would be eliminated, and the remaining 10 would play 5 games. Then the remaining 5 teams would play 10 games in a round robin tournament. In total there would be 10+5+10=25 games.
Daniel has already booked the stadium for n games. Help him to determine how many teams he should invite so that the tournament needs exactly n games. You should print all possible numbers of teams that will yield exactly n games in ascending order, or -1 if there are no such numbers.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 10^18), the number of games that should be played.
Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier.
-----Output-----
Print all possible numbers of invited teams in ascending order, one per line. If exactly n games cannot be played, output one number: -1.
-----Examples-----
Input
3
Output
3
4
Input
25
Output
20
Input
2
Output
-1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
res = set()
for r in range(100):
a = 1
b = 2**(r + 1) - 3
c = -2 * n
d = b * b - 4 * a * c
if d < 0:
continue
le = 0
ri = d
while le < ri:
c = (le + ri) // 2
if c * c < d:
le = c + 1
else:
ri = c
if le * le == d:
if (-b - le) % 4 == 2 and -b - le > 0:
res.add((-b - le) // 2 * 2**r)
if (-b + le) % 4 == 2 and -b + le > 0:
res.add((-b + le) // 2 * 2**r)
for i in sorted(list(res)):
print(i)
if not list(res):
print(-1)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n",
"output": "3\n4\n",
"type": "stdin_stdout"
},
{
"input": "25\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "15\n",
"output": "10\n16\n",
"type": "stdin_stdout"
},
{
"input": "314\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "524800\n",
"output": "1025\n",
"type": "stdin_stdout"
},
{
"input": "5149487579894806\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "249999998807430810\n",
"output": "1414213558\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "12\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "13\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "14\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "28\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "36\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "45\n",
"output": "18\n40\n",
"type": "stdin_stdout"
},
{
"input": "55\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "78\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "105\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "120\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "136\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "171\n",
"output": "19\n144\n",
"type": "stdin_stdout"
},
{
"input": "210\n",
"output": "21\n120\n",
"type": "stdin_stdout"
},
{
"input": "255\n",
"output": "136\n256\n",
"type": "stdin_stdout"
},
{
"input": "5460\n",
"output": "105\n1456\n",
"type": "stdin_stdout"
},
{
"input": "16383\n",
"output": "8256\n16384\n",
"type": "stdin_stdout"
},
{
"input": "391170\n",
"output": "885\n98176\n",
"type": "stdin_stdout"
},
{
"input": "1906128\n",
"output": "1953\n121024\n",
"type": "stdin_stdout"
},
{
"input": "576460752303423487\n",
"output": "576460752303423488\n",
"type": "stdin_stdout"
},
{
"input": "499999999500000000\n",
"output": "1999999998\n",
"type": "stdin_stdout"
},
{
"input": "250000001635857933\n",
"output": "2828427124\n",
"type": "stdin_stdout"
},
{
"input": "999999998765257141\n",
"output": "2828427122\n",
"type": "stdin_stdout"
},
{
"input": "321730048\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "499999500000\n",
"output": "1999998\n",
"type": "stdin_stdout"
},
{
"input": "250000000221644371\n",
"output": "1414213562\n",
"type": "stdin_stdout"
},
{
"input": "58819626242454945\n",
"output": "342985791\n",
"type": "stdin_stdout"
},
{
"input": "672900920488237864\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "994374468178120050\n",
"output": "1410230101\n",
"type": "stdin_stdout"
},
{
"input": "999971062750901550\n",
"output": "1414193101\n",
"type": "stdin_stdout"
},
{
"input": "999999912498231750\n",
"output": "1414213501\n",
"type": "stdin_stdout"
},
{
"input": "999999943610929003\n",
"output": "1414213523\n",
"type": "stdin_stdout"
},
{
"input": "999999995936830020\n",
"output": "2828427118\n",
"type": "stdin_stdout"
},
{
"input": "999999998765257141\n",
"output": "2828427122\n",
"type": "stdin_stdout"
},
{
"input": "999999997351043580\n",
"output": "1414213561\n",
"type": "stdin_stdout"
},
{
"input": "496\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "3012278988753\n",
"output": "4908994\n",
"type": "stdin_stdout"
},
{
"input": "20000000100000000\n",
"output": "200000001\n",
"type": "stdin_stdout"
},
{
"input": "980000156100006216\n",
"output": "2800000222\n",
"type": "stdin_stdout"
},
{
"input": "995460657326506216\n",
"output": "2822000222\n",
"type": "stdin_stdout"
},
{
"input": "38927073\n",
"output": "35284\n",
"type": "stdin_stdout"
},
{
"input": "30110278526854603\n",
"output": "981595076\n",
"type": "stdin_stdout"
},
{
"input": "6882\n",
"output": "888\n",
"type": "stdin_stdout"
},
{
"input": "20263965249\n",
"output": "1610472\n",
"type": "stdin_stdout"
},
{
"input": "936612417\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "529914\n",
"output": "8184\n",
"type": "stdin_stdout"
},
{
"input": "514948626567892275\n",
"output": "16237416336\n",
"type": "stdin_stdout"
},
{
"input": "514948642805308611\n",
"output": "32474832672\n",
"type": "stdin_stdout"
},
{
"input": "1459321801\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "16358075516553\n",
"output": "5856031744\n",
"type": "stdin_stdout"
},
{
"input": "1337521996548297\n",
"output": "105920063488\n",
"type": "stdin_stdout"
},
{
"input": "4877709674134636\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "487738618277701671\n",
"output": "8090864197632\n",
"type": "stdin_stdout"
},
{
"input": "487746708154228600\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "520088094975\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "32767\n",
"output": "32768\n",
"type": "stdin_stdout"
},
{
"input": "131071\n",
"output": "131072\n",
"type": "stdin_stdout"
},
{
"input": "1310755\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "32775625\n",
"output": "32768000\n",
"type": "stdin_stdout"
},
{
"input": "57819024375\n",
"output": "52756480000\n",
"type": "stdin_stdout"
},
{
"input": "1570397049375\n",
"output": "1059717120000\n",
"type": "stdin_stdout"
},
{
"input": "72315871219375\n",
"output": "21203517440000\n",
"type": "stdin_stdout"
},
{
"input": "5323259016854625\n",
"output": "212034912256000\n",
"type": "stdin_stdout"
},
{
"input": "257957076\n",
"output": "257949696\n",
"type": "stdin_stdout"
},
{
"input": "5180726200\n",
"output": "5179965440\n",
"type": "stdin_stdout"
},
{
"input": "8355443183554431\n",
"output": "3355443233554432\n",
"type": "stdin_stdout"
},
{
"input": "58687091686870911\n",
"output": "53687091736870912\n",
"type": "stdin_stdout"
},
{
"input": "5000000250000000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "500000003500000003\n",
"output": "4000000004\n",
"type": "stdin_stdout"
},
{
"input": "178120883702871\n",
"output": "178120883699712\n",
"type": "stdin_stdout"
},
{
"input": "266081813928931\n",
"output": "266081813921792\n",
"type": "stdin_stdout"
},
{
"input": "9005000239863810\n",
"output": "9005000231485440\n",
"type": "stdin_stdout"
},
{
"input": "10475010\n",
"output": "2096640\n",
"type": "stdin_stdout"
},
{
"input": "943414054006932870\n",
"output": "943413961980641280\n",
"type": "stdin_stdout"
},
{
"input": "431105316312401832\n",
"output": "431105315111436288\n",
"type": "stdin_stdout"
},
{
"input": "686288770539583120\n",
"output": "686288769778712576\n",
"type": "stdin_stdout"
},
{
"input": "434351073512812035\n",
"output": "434351073436631040\n",
"type": "stdin_stdout"
},
{
"input": "305752193461383075\n",
"output": "305752193451950080\n",
"type": "stdin_stdout"
},
{
"input": "660058820389234315\n",
"output": "660058820386488320\n",
"type": "stdin_stdout"
},
{
"input": "838795430598031275\n",
"output": "838795430597754880\n",
"type": "stdin_stdout"
},
{
"input": "270215977642229850\n",
"output": "270215977642229760\n",
"type": "stdin_stdout"
},
{
"input": "576460752303423490\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "864691128455135232\n",
"output": "864691128455135232\n",
"type": "stdin_stdout"
},
{
"input": "402653184\n",
"output": "402653184\n",
"type": "stdin_stdout"
},
{
"input": "576460752303423487\n",
"output": "576460752303423488\n",
"type": "stdin_stdout"
},
{
"input": "268435455\n",
"output": "134225920\n268435456\n",
"type": "stdin_stdout"
},
{
"input": "530516448\n",
"output": "130284\n16418304\n",
"type": "stdin_stdout"
},
{
"input": "8539349952\n",
"output": "522732\n132779008\n",
"type": "stdin_stdout"
},
{
"input": "4095\n",
"output": "91\n2080\n4096\n",
"type": "stdin_stdout"
},
{
"input": "7791518261859\n",
"output": "31580232\n1812942290944\n",
"type": "stdin_stdout"
},
{
"input": "72057594037927935\n",
"output": "36028797153181696\n72057594037927936\n",
"type": "stdin_stdout"
},
{
"input": "288230376151711743\n",
"output": "144115188344291328\n288230376151711744\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4095\n",
"output": "91\n2080\n4096\n",
"type": "stdin_stdout"
},
{
"input": "500000002500000003\n",
"output": "1000000003\n",
"type": "stdin_stdout"
},
{
"input": "605000000550000000\n",
"output": "1100000001\n",
"type": "stdin_stdout"
},
{
"input": "1099511627775\n",
"output": "549756338176\n1099511627776\n",
"type": "stdin_stdout"
},
{
"input": "73687091368435455\n",
"output": "53687091468435456\n",
"type": "stdin_stdout"
},
{
"input": "965211250482432409\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "432345564227567616\n",
"output": "432345564227567616\n",
"type": "stdin_stdout"
},
{
"input": "138485688541650132\n",
"output": "138485688541642752\n",
"type": "stdin_stdout"
},
{
"input": "4979826519\n",
"output": "2368241664\n",
"type": "stdin_stdout"
},
{
"input": "1125899906842623\n",
"output": "562949970198528\n1125899906842624\n",
"type": "stdin_stdout"
},
{
"input": "1073741823\n",
"output": "536887296\n1073741824\n",
"type": "stdin_stdout"
},
{
"input": "36028797018963967\n",
"output": "36028797018963968\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/325/B"
} | vfc_9962 |
apps | verifiable_code | 54 | Solve the following coding problem using the programming language python:
Vanya has a scales for weighing loads and weights of masses w^0, w^1, w^2, ..., w^100 grams where w is some integer not less than 2 (exactly one weight of each nominal value). Vanya wonders whether he can weight an item with mass m using the given weights, if the weights can be put on both pans of the scales. Formally speaking, your task is to determine whether it is possible to place an item of mass m and some weights on the left pan of the scales, and some weights on the right pan of the scales so that the pans of the scales were in balance.
-----Input-----
The first line contains two integers w, m (2 ≤ w ≤ 10^9, 1 ≤ m ≤ 10^9) — the number defining the masses of the weights and the mass of the item.
-----Output-----
Print word 'YES' if the item can be weighted and 'NO' if it cannot.
-----Examples-----
Input
3 7
Output
YES
Input
100 99
Output
YES
Input
100 50
Output
NO
-----Note-----
Note to the first sample test. One pan can have an item of mass 7 and a weight of mass 3, and the second pan can have two weights of masses 9 and 1, correspondingly. Then 7 + 3 = 9 + 1.
Note to the second sample test. One pan of the scales can have an item of mass 99 and the weight of mass 1, and the second pan can have the weight of mass 100.
Note to the third sample test. It is impossible to measure the weight of the item in the manner described in the input.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
w,m=map(int,input().split())
bb=True
while(m>0 and bb):
x=m%w
if x==1:m-=1
elif x==w-1:m+=1
elif x!=0:bb=False
m//=w
if bb:print("YES")
else:print("NO")
``` | {
"language": "python",
"test_cases": [
{
"input": "3 7\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 99\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 50\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 10002\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 11\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 781\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5077 5988\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 9596\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 1069\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 7134\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 9083\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 7927\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 6772\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 782\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 1000000000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 357913941\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 357918037\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 12207031\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 41503906\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 90332031\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "11 1786324\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 999\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 28087\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 28598\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "32 33586176\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "87 56631258\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "19 20\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "58 11316496\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "89 89\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "21 85756882\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "56 540897225\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "91 8189\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "27 14329927\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "58 198535\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "939 938\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "27463 754243832\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "21427 459137757\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "26045 26045\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "25336 25336\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "24627 24626\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "29245 855299270\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "28536 814274759\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "33154 33155\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "27118 27119\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "70 338171\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "24 346226\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "41 2966964\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "31 29792\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "48 2402\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "65 4159\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "20 67376840\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "72 5111\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "27 14349609\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "44 89146\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "22787 519292944\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "24525 601475624\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3716 13816089\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4020 4020\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "13766 13767\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "23512 23511\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "23816 567225671\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "33562 33564\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "33866 33866\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "13057 13059\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "441890232 441890232\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "401739553 401739553\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "285681920 285681919\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "464591587 464591588\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "703722884 703722884\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "982276216 982276216\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "867871061 867871062\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "48433217 48433216\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 324818663\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7 898367507\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 471916351\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 45465196\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9 768757144\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8 342305988\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 114457122\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 688005966\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 556522107\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 130070951\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 558395604\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 131944448\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 1000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 22222222\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 100000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 100000001\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 100000002\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 100000003\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 100000004\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "99999 1000000000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1000 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 999999999\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 99999999\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1000 999999999\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1000 999999998\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 536870912\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 99\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 26\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 8888\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 984742145\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 43\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4194304 4194305\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 899\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 47\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 822083581\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 999987989\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 31\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 15\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100000000 100000001\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/552/C"
} | vfc_9970 |
apps | verifiable_code | 55 | Solve the following coding problem using the programming language python:
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one.
To be more clear, consider all integer sequence with length k (a_1, a_2, ..., a_{k}) with $\sum_{i = 1}^{k} 2^{a_{i}} = n$. Give a value $y = \operatorname{max}_{1 \leq i \leq k} a_{i}$ to each sequence. Among all sequence(s) that have the minimum y value, output the one that is the lexicographically largest.
For definitions of powers and lexicographical order see notes.
-----Input-----
The first line consists of two integers n and k (1 ≤ n ≤ 10^18, 1 ≤ k ≤ 10^5) — the required sum and the length of the sequence.
-----Output-----
Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and k numbers separated by space in the second line — the required sequence.
It is guaranteed that the integers in the answer sequence fit the range [ - 10^18, 10^18].
-----Examples-----
Input
23 5
Output
Yes
3 3 2 1 0
Input
13 2
Output
No
Input
1 2
Output
Yes
-1 -1
-----Note-----
Sample 1:
2^3 + 2^3 + 2^2 + 2^1 + 2^0 = 8 + 8 + 4 + 2 + 1 = 23
Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.
Answers like (4, 1, 1, 1, 0) do not have the minimum y value.
Sample 2:
It can be shown there does not exist a sequence with length 2.
Sample 3:
$2^{-1} + 2^{-1} = \frac{1}{2} + \frac{1}{2} = 1$
Powers of 2:
If x > 0, then 2^{x} = 2·2·2·...·2 (x times).
If x = 0, then 2^{x} = 1.
If x < 0, then $2^{x} = \frac{1}{2^{-x}}$.
Lexicographical order:
Given two different sequences of the same length, (a_1, a_2, ... , a_{k}) and (b_1, b_2, ... , b_{k}), the first one is smaller than the second one for the lexicographical order, if and only if a_{i} < b_{i}, for the first i where a_{i} and b_{i} differ.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from collections import defaultdict
def solve(n, k):
as_bin = bin(n)[2:]
cnt = defaultdict(int)
cnt.update({i : 1 for i, b in enumerate(reversed(as_bin)) if b == '1'})
curr_len = len(cnt)
curr_pow = len(as_bin) - 1
if curr_len > k:
return None
while True:
new_len = curr_len + cnt[curr_pow]
if new_len > k:
break
cnt[curr_pow - 1] += 2 * cnt[curr_pow]
del cnt[curr_pow]
curr_pow -= 1
curr_len = new_len
i = min(cnt.keys())
while curr_len < k:
cnt[i] -= 1
cnt[i - 1] += 2
curr_len += 1
i -= 1
ans = []
for i in sorted(list(cnt.keys()), reverse=True):
ans.extend([i] * cnt[i])
return ans
n, k = [int(v) for v in input().split()]
ans = solve(n, k)
if ans is None:
print('No')
else:
print('Yes')
print(' '.join(str(c) for c in ans))
``` | {
"language": "python",
"test_cases": [
{
"input": "23 5\n",
"output": "Yes\n3 3 2 1 0 \n",
"type": "stdin_stdout"
},
{
"input": "13 2\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n",
"output": "Yes\n-1 -1 \n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "Yes\n0 \n",
"type": "stdin_stdout"
},
{
"input": "7 2\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "7 3\n",
"output": "Yes\n2 1 0 \n",
"type": "stdin_stdout"
},
{
"input": "7 4\n",
"output": "Yes\n1 1 1 0 \n",
"type": "stdin_stdout"
},
{
"input": "521325125150442808 10\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1 4\n",
"output": "Yes\n-2 -2 -2 -2 \n",
"type": "stdin_stdout"
},
{
"input": "9 4\n",
"output": "Yes\n2 2 -1 -1 \n",
"type": "stdin_stdout"
},
{
"input": "3 4\n",
"output": "Yes\n0 0 -1 -1 \n",
"type": "stdin_stdout"
},
{
"input": "144 4\n",
"output": "Yes\n6 6 3 3 \n",
"type": "stdin_stdout"
},
{
"input": "59 4\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "78 4\n",
"output": "Yes\n6 3 2 1 \n",
"type": "stdin_stdout"
},
{
"input": "192 4\n",
"output": "Yes\n6 6 5 5 \n",
"type": "stdin_stdout"
},
{
"input": "107 4\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "552 5\n",
"output": "Yes\n8 8 5 2 2 \n",
"type": "stdin_stdout"
},
{
"input": "680 5\n",
"output": "Yes\n8 8 7 5 3 \n",
"type": "stdin_stdout"
},
{
"input": "808 5\n",
"output": "Yes\n8 8 8 5 3 \n",
"type": "stdin_stdout"
},
{
"input": "1528 5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1656 5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "26972 8\n",
"output": "Yes\n14 13 11 8 6 4 3 2 \n",
"type": "stdin_stdout"
},
{
"input": "23100 8\n",
"output": "Yes\n14 12 11 9 5 4 3 2 \n",
"type": "stdin_stdout"
},
{
"input": "19228 8\n",
"output": "Yes\n13 13 11 9 8 4 3 2 \n",
"type": "stdin_stdout"
},
{
"input": "22652 8\n",
"output": "Yes\n14 12 11 6 5 4 3 2 \n",
"type": "stdin_stdout"
},
{
"input": "26076 8\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "329438 10\n",
"output": "Yes\n18 16 10 9 7 6 4 3 2 1 \n",
"type": "stdin_stdout"
},
{
"input": "12862 10\n",
"output": "Yes\n12 12 12 9 5 4 3 2 0 0 \n",
"type": "stdin_stdout"
},
{
"input": "96286 10\n",
"output": "Yes\n15 15 14 13 12 11 4 3 2 1 \n",
"type": "stdin_stdout"
},
{
"input": "12414 10\n",
"output": "Yes\n12 12 12 6 5 4 3 2 0 0 \n",
"type": "stdin_stdout"
},
{
"input": "95838 10\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1728568411 16\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "611684539 16\n",
"output": "Yes\n28 28 26 22 21 20 18 16 15 12 7 5 4 3 1 0 \n",
"type": "stdin_stdout"
},
{
"input": "84735259 16\n",
"output": "Yes\n25 25 24 19 18 15 14 13 12 10 8 4 3 1 -1 -1 \n",
"type": "stdin_stdout"
},
{
"input": "6967851387 16\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "2145934811 16\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "6795804571172 20\n",
"output": "Yes\n41 41 41 37 35 34 33 30 26 24 23 18 14 13 12 10 9 5 1 1 \n",
"type": "stdin_stdout"
},
{
"input": "1038982654596 20\n",
"output": "Yes\n38 38 38 37 36 32 31 30 29 27 21 20 16 13 11 9 7 1 0 0 \n",
"type": "stdin_stdout"
},
{
"input": "11277865770724 20\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "5525338821444 20\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "15764221937572 20\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "922239521698513045 30\n",
"output": "Yes\n58 58 58 55 54 51 50 46 45 44 41 40 39 38 37 36 34 32 30 29 28 23 21 19 17 15 7 4 2 0 \n",
"type": "stdin_stdout"
},
{
"input": "923065764876596469 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "923892008054679893 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "924718251232763317 30\n",
"output": "Yes\n58 58 58 55 54 52 50 48 46 41 38 36 35 32 31 29 25 19 18 15 12 11 10 8 7 5 4 2 -1 -1 \n",
"type": "stdin_stdout"
},
{
"input": "925544490115879445 30\n",
"output": "Yes\n59 58 55 54 52 51 45 44 40 39 38 35 34 33 32 30 28 27 26 24 21 19 18 16 14 12 9 4 2 0 \n",
"type": "stdin_stdout"
},
{
"input": "926370733293962869 30\n",
"output": "Yes\n57 57 57 57 57 57 55 54 52 51 49 48 45 40 38 34 33 28 27 22 19 18 17 10 9 6 5 4 2 0 \n",
"type": "stdin_stdout"
},
{
"input": "927196976472046293 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "928023215355162421 30\n",
"output": "Yes\n58 58 58 55 54 53 48 37 36 33 31 27 26 25 23 19 18 17 16 14 13 11 10 9 8 5 4 2 -1 -1 \n",
"type": "stdin_stdout"
},
{
"input": "928849458533245845 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "855969764271400156 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "856796007449483580 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "857622246332599708 30\n",
"output": "Yes\n58 58 57 56 55 54 53 50 49 47 46 45 41 39 38 37 33 32 31 29 21 15 11 10 8 7 4 3 1 1 \n",
"type": "stdin_stdout"
},
{
"input": "858448489510683132 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "859274728393799260 30\n",
"output": "Yes\n59 57 56 55 54 53 51 50 47 46 40 39 38 36 28 26 25 22 21 16 15 14 13 12 10 9 6 4 3 2 \n",
"type": "stdin_stdout"
},
{
"input": "860100975866849980 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "860927214749966108 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "861753457928049532 30\n",
"output": "Yes\n58 58 57 56 55 54 53 52 50 48 47 44 37 36 34 30 26 25 24 23 22 18 12 9 8 6 5 4 3 2 \n",
"type": "stdin_stdout"
},
{
"input": "862579701106132957 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "863405944284216381 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "374585535361966567 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n",
"output": "Yes\n2 \n",
"type": "stdin_stdout"
},
{
"input": "4 9\n",
"output": "Yes\n-1 -1 -1 -1 -1 -1 -1 -2 -2 \n",
"type": "stdin_stdout"
},
{
"input": "4 3\n",
"output": "Yes\n1 0 0 \n",
"type": "stdin_stdout"
},
{
"input": "4 144\n",
"output": "Yes\n-5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -21 \n",
"type": "stdin_stdout"
},
{
"input": "4 59\n",
"output": "Yes\n-3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -30 \n",
"type": "stdin_stdout"
},
{
"input": "4 78\n",
"output": "Yes\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -18 \n",
"type": "stdin_stdout"
},
{
"input": "4 107\n",
"output": "Yes\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -22 -23 -24 -25 -26 -27 -28 -29 -30 -31 -32 -33 -34 -35 -36 -37 -38 -39 -40 -41 -42 -43 -44 -45 -46 -47 -47 \n",
"type": "stdin_stdout"
},
{
"input": "281474976710656 5\n",
"output": "Yes\n46 46 46 45 45 \n",
"type": "stdin_stdout"
},
{
"input": "288230376151973890 5\n",
"output": "Yes\n57 57 18 0 0 \n",
"type": "stdin_stdout"
},
{
"input": "36029346774812736 5\n",
"output": "Yes\n55 39 15 11 6 \n",
"type": "stdin_stdout"
},
{
"input": "901283150305558530 5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "288318372649779720 50\n",
"output": "Yes\n53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 46 44 35 30 27 17 14 9 2 1 0 -1 -2 -3 -4 -5 -6 -6 \n",
"type": "stdin_stdout"
},
{
"input": "513703875844698663 50\n",
"output": "Yes\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 53 48 43 41 39 38 37 36 34 27 26 25 24 22 21 20 18 17 15 14 13 12 9 5 2 1 -1 -2 -3 -4 -5 -6 -7 -8 -9 -9 \n",
"type": "stdin_stdout"
},
{
"input": "287632104387196918 50\n",
"output": "Yes\n57 56 55 54 53 52 51 50 48 47 46 44 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 13 12 10 9 8 7 6 5 4 2 1 \n",
"type": "stdin_stdout"
},
{
"input": "864690028406636543 58\n",
"output": "Yes\n58 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 39 38 37 36 35 34 33 32 31 30 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 \n",
"type": "stdin_stdout"
},
{
"input": "576460752303423487 60\n",
"output": "Yes\n57 57 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 \n",
"type": "stdin_stdout"
},
{
"input": "141012366262272 1\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1100585377792 4\n",
"output": "Yes\n39 39 30 13 \n",
"type": "stdin_stdout"
},
{
"input": "18598239186190594 9\n",
"output": "Yes\n54 49 44 41 40 21 18 8 1 \n",
"type": "stdin_stdout"
},
{
"input": "18647719372456016 19\n",
"output": "Yes\n51 51 51 51 51 51 51 51 49 46 31 24 20 16 6 3 2 1 1 \n",
"type": "stdin_stdout"
},
{
"input": "9297478914673158 29\n",
"output": "Yes\n49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 48 43 33 18 11 9 2 0 -1 -2 -3 -4 -4 \n",
"type": "stdin_stdout"
},
{
"input": "668507368948226 39\n",
"output": "Yes\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 32 22 16 15 9 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -13 \n",
"type": "stdin_stdout"
},
{
"input": "1143595340402690 49\n",
"output": "Yes\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 44 36 35 27 25 19 12 0 -1 -2 -3 -4 -5 -6 -7 -8 -8 \n",
"type": "stdin_stdout"
},
{
"input": "35527987183872 59\n",
"output": "Yes\n40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 38 36 24 19 18 17 14 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -11 \n",
"type": "stdin_stdout"
},
{
"input": "324634416758413825 9\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "577030480059438572 19\n",
"output": "Yes\n59 49 42 41 37 35 33 28 26 23 18 12 10 8 7 6 5 3 2 \n",
"type": "stdin_stdout"
},
{
"input": "185505960265024385 29\n",
"output": "Yes\n54 54 54 54 54 54 54 54 54 54 52 49 48 43 42 39 37 36 29 24 22 20 15 9 8 7 -1 -2 -2 \n",
"type": "stdin_stdout"
},
{
"input": "57421517433081233 39\n",
"output": "Yes\n52 52 52 52 52 52 52 52 52 52 52 52 51 50 39 36 31 30 28 27 26 24 20 11 10 8 7 4 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -10 \n",
"type": "stdin_stdout"
},
{
"input": "90131572647657641 49\n",
"output": "Yes\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 45 44 42 41 37 36 28 25 23 21 20 18 17 7 5 3 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -12 \n",
"type": "stdin_stdout"
},
{
"input": "732268459757413905 59\n",
"output": "Yes\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 53 51 48 47 43 41 38 35 31 30 28 20 13 10 9 4 -1 -2 -2 \n",
"type": "stdin_stdout"
},
{
"input": "226111453445787190 9\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "478818723873062027 19\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "337790572680259391 29\n",
"output": "Yes\n58 55 53 52 44 41 39 37 36 35 34 30 29 28 26 24 20 18 16 13 10 9 8 5 4 3 2 1 0 \n",
"type": "stdin_stdout"
},
{
"input": "168057637182978458 39\n",
"output": "Yes\n54 54 54 54 54 54 54 54 54 52 50 48 43 42 41 40 39 34 33 32 31 30 28 26 25 20 18 16 13 12 11 8 7 4 3 0 -1 -2 -2 \n",
"type": "stdin_stdout"
},
{
"input": "401486559567818547 49\n",
"output": "Yes\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 52 49 46 44 43 42 40 39 38 37 34 33 28 26 24 21 17 13 11 10 9 8 5 4 1 -1 -1 \n",
"type": "stdin_stdout"
},
{
"input": "828935109688089201 59\n",
"output": "Yes\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 47 46 45 44 43 36 34 33 32 29 25 23 22 19 18 17 15 14 12 11 9 6 5 4 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -11 \n",
"type": "stdin_stdout"
},
{
"input": "954687629161163764 9\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "287025268967992526 19\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "844118423640988373 29\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "128233154575908599 39\n",
"output": "Yes\n56 55 54 50 49 48 47 44 41 40 38 36 35 34 33 32 31 30 29 27 25 23 22 21 19 18 15 13 12 11 10 9 7 6 5 4 2 1 0 \n",
"type": "stdin_stdout"
},
{
"input": "792058388714085231 49\n",
"output": "Yes\n56 56 56 56 56 56 56 56 56 56 55 54 53 52 51 50 48 47 46 45 44 42 39 38 37 35 30 29 28 26 23 21 19 17 16 15 14 12 11 9 8 6 5 3 2 1 -1 -2 -2 \n",
"type": "stdin_stdout"
},
{
"input": "827183623566145225 59\n",
"output": "Yes\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 54 53 52 51 49 47 45 44 43 42 41 40 36 35 34 33 32 30 29 28 27 26 25 23 21 19 18 17 13 12 10 9 7 6 3 -1 -1 \n",
"type": "stdin_stdout"
},
{
"input": "846113779983498737 9\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "780248358343081983 19\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "576460580458522095 29\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "540145805193625598 39\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "576388182371377103 49\n",
"output": "Yes\n58 57 56 55 54 53 52 51 50 49 48 47 45 44 43 42 40 39 38 37 36 35 34 33 32 30 29 28 27 26 25 23 22 21 20 19 17 15 12 11 10 9 8 7 6 3 2 1 0 \n",
"type": "stdin_stdout"
},
{
"input": "567448991726268409 59\n",
"output": "Yes\n56 56 56 56 56 56 56 55 54 52 51 50 49 48 47 46 45 44 43 41 40 39 38 36 35 32 31 30 29 28 27 25 24 23 22 21 20 19 18 17 16 14 13 11 10 9 8 7 6 5 4 3 -1 -2 -3 -4 -5 -6 -6 \n",
"type": "stdin_stdout"
},
{
"input": "576460752303423487 9\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "576460752303423487 19\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "864691128455135231 29\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "864691128455135231 39\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "576460752303423487 49\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "864691128455135231 59\n",
"output": "Yes\n59 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 \n",
"type": "stdin_stdout"
},
{
"input": "1 4\n",
"output": "Yes\n-2 -2 -2 -2 \n",
"type": "stdin_stdout"
},
{
"input": "2 64\n",
"output": "Yes\n-5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 \n",
"type": "stdin_stdout"
},
{
"input": "2 8\n",
"output": "Yes\n-2 -2 -2 -2 -2 -2 -2 -2 \n",
"type": "stdin_stdout"
},
{
"input": "1 5\n",
"output": "Yes\n-2 -2 -2 -3 -3 \n",
"type": "stdin_stdout"
},
{
"input": "1 7\n",
"output": "Yes\n-2 -2 -2 -3 -4 -5 -5 \n",
"type": "stdin_stdout"
},
{
"input": "19 5\n",
"output": "Yes\n3 3 1 -1 -1 \n",
"type": "stdin_stdout"
},
{
"input": "1 30\n",
"output": "Yes\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -18 \n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/916/B"
} | vfc_9974 |
apps | verifiable_code | 56 | Solve the following coding problem using the programming language python:
Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is n. The top level consists of only 1 glass, that stands on 2 glasses on the second level (counting from the top), then 3 glasses on the third level and so on.The bottom level consists of n glasses.
Vlad has seen in the movies many times how the champagne beautifully flows from top levels to bottom ones, filling all the glasses simultaneously. So he took a bottle and started to pour it in the glass located at the top of the pyramid.
Each second, Vlad pours to the top glass the amount of champagne equal to the size of exactly one glass. If the glass is already full, but there is some champagne flowing in it, then it pours over the edge of the glass and is equally distributed over two glasses standing under. If the overflowed glass is at the bottom level, then the champagne pours on the table. For the purpose of this problem we consider that champagne is distributed among pyramid glasses immediately. Vlad is interested in the number of completely full glasses if he stops pouring champagne in t seconds.
Pictures below illustrate the pyramid consisting of three levels. [Image] [Image]
-----Input-----
The only line of the input contains two integers n and t (1 ≤ n ≤ 10, 0 ≤ t ≤ 10 000) — the height of the pyramid and the number of seconds Vlad will be pouring champagne from the bottle.
-----Output-----
Print the single integer — the number of completely full glasses after t seconds.
-----Examples-----
Input
3 5
Output
4
Input
4 8
Output
6
-----Note-----
In the first sample, the glasses full after 5 seconds are: the top glass, both glasses on the second level and the middle glass at the bottom level. Left and right glasses of the bottom level will be half-empty.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, t = list(map(int,input().split()))
g = [[0.0] * i for i in range(1,n+1)]
for _ in range(t):
g[0][0] += 1.0
for i in range(n):
for j in range(i+1):
spill = max(0, g[i][j] - 1.0)
g[i][j] -= spill
if i < n - 1:
g[i + 1][j] += spill / 2
g[i + 1][j + 1] += spill / 2
if g[n-1][0] == 1.0:
break
cnt = 0
for i in range(n):
for j in range(i + 1):
if g[i][j] == 1.0:
cnt += 1
print(cnt)
``` | {
"language": "python",
"test_cases": [
{
"input": "3 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4 8\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 10000\n",
"output": "55\n",
"type": "stdin_stdout"
},
{
"input": "1 10000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 1022\n",
"output": "53\n",
"type": "stdin_stdout"
},
{
"input": "10 1023\n",
"output": "55\n",
"type": "stdin_stdout"
},
{
"input": "10 1024\n",
"output": "55\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 200\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7 128\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "8 198\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 100\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 10000\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 6\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3 8\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 12\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 15\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "4 14\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "4 10\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "4 16\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "4 999\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "4 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "5 31\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "5 30\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "5 28\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "5 25\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "5 15\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "5 32\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "5 9999\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "5 14\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "6 63\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "6 62\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "6 61\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "6 52\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "6 31\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "6 32\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "6 39\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "6 15\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "6 14\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "6 10\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "6 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6 7653\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "7 127\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "6 64\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "7 126\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "7 125\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "7 120\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "7 98\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "7 110\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "7 65\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "7 63\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "7 15\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "7 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7 83\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "7 214\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "8 2555\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "8 257\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "8 256\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "8 255\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "8 254\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "8 253\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "8 251\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "8 240\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "8 128\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "8 127\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "8 100\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"input": "8 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8 10000\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "8 94\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"input": "8 33\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "9 10000\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "9 513\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "9 512\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "9 511\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "9 510\n",
"output": "43\n",
"type": "stdin_stdout"
},
{
"input": "9 255\n",
"output": "43\n",
"type": "stdin_stdout"
},
{
"input": "9 256\n",
"output": "43\n",
"type": "stdin_stdout"
},
{
"input": "9 254\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "9 253\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "9 200\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "9 100\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "9 150\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "10 9999\n",
"output": "55\n",
"type": "stdin_stdout"
},
{
"input": "10 1025\n",
"output": "55\n",
"type": "stdin_stdout"
},
{
"input": "10 1021\n",
"output": "53\n",
"type": "stdin_stdout"
},
{
"input": "10 512\n",
"output": "53\n",
"type": "stdin_stdout"
},
{
"input": "10 689\n",
"output": "53\n",
"type": "stdin_stdout"
},
{
"input": "10 754\n",
"output": "53\n",
"type": "stdin_stdout"
},
{
"input": "10 985\n",
"output": "53\n",
"type": "stdin_stdout"
},
{
"input": "10 255\n",
"output": "51\n",
"type": "stdin_stdout"
},
{
"input": "10 256\n",
"output": "51\n",
"type": "stdin_stdout"
},
{
"input": "10 254\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "10 153\n",
"output": "47\n",
"type": "stdin_stdout"
},
{
"input": "10 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10 63\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "10 64\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "10 126\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "10 127\n",
"output": "47\n",
"type": "stdin_stdout"
},
{
"input": "10 128\n",
"output": "47\n",
"type": "stdin_stdout"
},
{
"input": "10 55\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "10 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10 37\n",
"output": "33\n",
"type": "stdin_stdout"
},
{
"input": "10 68\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 23\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/676/B"
} | vfc_9978 |
apps | verifiable_code | 57 | Solve the following coding problem using the programming language python:
After making bad dives into swimming pools, Wilbur wants to build a swimming pool in the shape of a rectangle in his backyard. He has set up coordinate axes, and he wants the sides of the rectangle to be parallel to them. Of course, the area of the rectangle must be positive. Wilbur had all four vertices of the planned pool written on a paper, until his friend came along and erased some of the vertices.
Now Wilbur is wondering, if the remaining n vertices of the initial rectangle give enough information to restore the area of the planned swimming pool.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 4) — the number of vertices that were not erased by Wilbur's friend.
Each of the following n lines contains two integers x_{i} and y_{i} ( - 1000 ≤ x_{i}, y_{i} ≤ 1000) —the coordinates of the i-th vertex that remains. Vertices are given in an arbitrary order.
It's guaranteed that these points are distinct vertices of some rectangle, that has positive area and which sides are parallel to the coordinate axes.
-----Output-----
Print the area of the initial rectangle if it could be uniquely determined by the points remaining. Otherwise, print - 1.
-----Examples-----
Input
2
0 0
1 1
Output
1
Input
1
1 1
Output
-1
-----Note-----
In the first sample, two opposite corners of the initial rectangle are given, and that gives enough information to say that the rectangle is actually a unit square.
In the second sample there is only one vertex left and this is definitely not enough to uniquely define the area.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
points = [[int(x) for x in input().split()] for _ in range(n)]
if n <= 1:
print(-1)
return
dx = [1e9, -1e9]
dy = [1e9, -1e9]
for x, y in points:
dx[0] = min(dx[0], x)
dx[1] = max(dx[1], x)
dy[0] = min(dy[0], y)
dy[1] = max(dy[1], y)
area = (dx[1] - dx[0]) * (dy[1] - dy[0])
if area:
print(area)
else:
print(-1)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n0 0\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n-188 17\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n71 -740\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-56 -858\n-56 -174\n778 -858\n778 -174\n",
"output": "570456\n",
"type": "stdin_stdout"
},
{
"input": "2\n14 153\n566 -13\n",
"output": "91632\n",
"type": "stdin_stdout"
},
{
"input": "2\n-559 894\n314 127\n",
"output": "669591\n",
"type": "stdin_stdout"
},
{
"input": "1\n-227 -825\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n-187 583\n25 13\n",
"output": "120840\n",
"type": "stdin_stdout"
},
{
"input": "2\n-337 451\n32 -395\n",
"output": "312174\n",
"type": "stdin_stdout"
},
{
"input": "4\n-64 -509\n-64 960\n634 -509\n634 960\n",
"output": "1025362\n",
"type": "stdin_stdout"
},
{
"input": "2\n-922 -505\n712 -683\n",
"output": "290852\n",
"type": "stdin_stdout"
},
{
"input": "2\n-1000 -1000\n-1000 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n-1000 -1000\n0 -1000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-414 -891\n-414 896\n346 -891\n346 896\n",
"output": "1358120\n",
"type": "stdin_stdout"
},
{
"input": "2\n56 31\n704 -121\n",
"output": "98496\n",
"type": "stdin_stdout"
},
{
"input": "4\n-152 198\n-152 366\n458 198\n458 366\n",
"output": "102480\n",
"type": "stdin_stdout"
},
{
"input": "3\n-890 778\n-418 296\n-890 296\n",
"output": "227504\n",
"type": "stdin_stdout"
},
{
"input": "4\n852 -184\n852 724\n970 -184\n970 724\n",
"output": "107144\n",
"type": "stdin_stdout"
},
{
"input": "1\n858 -279\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n-823 358\n446 358\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n-739 -724\n-739 443\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n686 664\n686 -590\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n-679 301\n240 -23\n-679 -23\n",
"output": "297756\n",
"type": "stdin_stdout"
},
{
"input": "2\n-259 -978\n978 -978\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n627 -250\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n-281 598\n679 -990\n-281 -990\n",
"output": "1524480\n",
"type": "stdin_stdout"
},
{
"input": "2\n-414 -431\n-377 -688\n",
"output": "9509\n",
"type": "stdin_stdout"
},
{
"input": "3\n-406 566\n428 426\n-406 426\n",
"output": "116760\n",
"type": "stdin_stdout"
},
{
"input": "3\n-686 695\n-547 308\n-686 308\n",
"output": "53793\n",
"type": "stdin_stdout"
},
{
"input": "1\n-164 -730\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n980 -230\n980 592\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-925 306\n-925 602\n398 306\n398 602\n",
"output": "391608\n",
"type": "stdin_stdout"
},
{
"input": "3\n576 -659\n917 -739\n576 -739\n",
"output": "27280\n",
"type": "stdin_stdout"
},
{
"input": "1\n720 -200\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n-796 -330\n-796 758\n171 -330\n171 758\n",
"output": "1052096\n",
"type": "stdin_stdout"
},
{
"input": "2\n541 611\n-26 611\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n-487 838\n134 691\n-487 691\n",
"output": "91287\n",
"type": "stdin_stdout"
},
{
"input": "2\n-862 -181\n-525 -181\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n-717 916\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n-841 -121\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n259 153\n259 999\n266 153\n266 999\n",
"output": "5922\n",
"type": "stdin_stdout"
},
{
"input": "2\n295 710\n295 254\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n137 -184\n137 700\n712 -184\n712 700\n",
"output": "508300\n",
"type": "stdin_stdout"
},
{
"input": "2\n157 994\n377 136\n",
"output": "188760\n",
"type": "stdin_stdout"
},
{
"input": "1\n193 304\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n5 -952\n5 292\n553 -952\n553 292\n",
"output": "681712\n",
"type": "stdin_stdout"
},
{
"input": "2\n-748 697\n671 575\n",
"output": "173118\n",
"type": "stdin_stdout"
},
{
"input": "2\n-457 82\n260 -662\n",
"output": "533448\n",
"type": "stdin_stdout"
},
{
"input": "2\n-761 907\n967 907\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n-639 51\n-321 -539\n-639 -539\n",
"output": "187620\n",
"type": "stdin_stdout"
},
{
"input": "2\n-480 51\n89 -763\n",
"output": "463166\n",
"type": "stdin_stdout"
},
{
"input": "4\n459 -440\n459 -94\n872 -440\n872 -94\n",
"output": "142898\n",
"type": "stdin_stdout"
},
{
"input": "2\n380 -849\n68 -849\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n-257 715\n102 715\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n247 -457\n434 -921\n",
"output": "86768\n",
"type": "stdin_stdout"
},
{
"input": "4\n-474 -894\n-474 -833\n-446 -894\n-446 -833\n",
"output": "1708\n",
"type": "stdin_stdout"
},
{
"input": "3\n-318 831\n450 31\n-318 31\n",
"output": "614400\n",
"type": "stdin_stdout"
},
{
"input": "3\n-282 584\n696 488\n-282 488\n",
"output": "93888\n",
"type": "stdin_stdout"
},
{
"input": "3\n258 937\n395 856\n258 856\n",
"output": "11097\n",
"type": "stdin_stdout"
},
{
"input": "1\n-271 -499\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n-612 208\n326 -559\n",
"output": "719446\n",
"type": "stdin_stdout"
},
{
"input": "2\n115 730\n562 -546\n",
"output": "570372\n",
"type": "stdin_stdout"
},
{
"input": "2\n-386 95\n-386 750\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n0 1\n1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 4\n3 4\n3 1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n1 2\n2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 4\n4 4\n4 1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n2 1\n1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n1 0\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n0 5\n5 0\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n0 1\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n0 0\n1 0\n1 1\n0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 4\n1 4\n4 1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n2 0\n2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n2 0\n0 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n0 1\n5 0\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n1 3\n3 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n0 0\n1 0\n0 1\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 0\n2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n1 0\n0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n0 0\n0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n0 5\n5 5\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n5 0\n5 10\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n1 0\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n0 1\n0 0\n1 0\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n2 0\n0 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n-2 -1\n-1 -1\n-1 -2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 0\n0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1\n3 3\n3 1\n1 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1\n1 2\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n0 3\n3 0\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2\n0 3\n3 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 0\n2 8\n5 8\n5 0\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "2\n0 999\n100 250\n",
"output": "74900\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n1 5\n5 1\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 1\n0 0\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n10 0\n0 10\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "2\n0 0\n-1 -1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 5\n2 2\n2 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n0 1\n2 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 1\n1 0\n0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n0 -1\n1 -1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 1\n1 0\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 5\n3 2\n7 2\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2\n1 3\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 0\n0 0\n0 5\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n1 3\n5 0\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n0 2\n2 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n0 0\n1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2\n1 3\n2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n0 0\n0 1\n1 1\n1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n-3 0\n3 3\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n0 1\n1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0\n5 0\n5 5\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "3\n79 79\n79 158\n158 79\n",
"output": "6241\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 0\n1 -1\n0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n1 2\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 1\n0 0\n1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1\n2 4\n6 1\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 0\n0 0\n5 5\n",
"output": "25\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/596/A"
} | vfc_9982 |
apps | verifiable_code | 58 | Solve the following coding problem using the programming language python:
Petya has equal wooden bars of length n. He wants to make a frame for two equal doors. Each frame has two vertical (left and right) sides of length a and one top side of length b. A solid (i.e. continuous without breaks) piece of bar is needed for each side.
Determine a minimal number of wooden bars which are needed to make the frames for two doors. Petya can cut the wooden bars into any parts, but each side of each door should be a solid piece of a wooden bar (or a whole wooden bar).
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 1 000) — the length of each wooden bar.
The second line contains a single integer a (1 ≤ a ≤ n) — the length of the vertical (left and right) sides of a door frame.
The third line contains a single integer b (1 ≤ b ≤ n) — the length of the upper side of a door frame.
-----Output-----
Print the minimal number of wooden bars with length n which are needed to make the frames for two doors.
-----Examples-----
Input
8
1
2
Output
1
Input
5
3
4
Output
6
Input
6
4
2
Output
4
Input
20
5
6
Output
2
-----Note-----
In the first example one wooden bar is enough, since the total length of all six sides of the frames for two doors is 8.
In the second example 6 wooden bars is enough, because for each side of the frames the new wooden bar is needed.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
'''input
6
4
2
'''
def list_input():
return list(map(int,input().split()))
def map_input():
return map(int,input().split())
def map_string():
return input().split()
def f(n,a,b,left,cnta = 4,cntb = 2):
if(cnta == 0 and cntb == 0): return 0
if(cnta < 0 or cntb < 0): return 100000000000000000000
if a <= left and cnta and b <= left and cntb:
return min(f(n,a,b,left-a,cnta-1,cntb),f(n,a,b,left-b,cnta,cntb-1))
if a <= left and cnta:
return f(n,a,b,left-a,cnta-1,cntb)
if b <= left and cntb:
return f(n,a,b,left-b,cnta,cntb-1)
return 1+min(f(n,a,b,n-a,cnta-1,cntb),f(n,a,b,n-b,cnta,cntb-1))
n = int(input())
a = int(input())
b = int(input())
print(f(n,a,b,0))
``` | {
"language": "python",
"test_cases": [
{
"input": "8\n1\n2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n3\n4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "6\n4\n2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "20\n5\n6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3\n1\n2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n2\n1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1000\n1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000\n1000\n1000\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1000\n1\n999\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1000\n1\n498\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000\n1\n998\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "31\n5\n6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "400\n100\n2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "399\n100\n2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "800\n401\n400\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "141\n26\n11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "717\n40\n489\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "293\n47\n30\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "165\n59\n40\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "404\n5\n183\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "828\n468\n726\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "956\n153\n941\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "676\n175\n514\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "296\n1\n10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "872\n3\n182\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "448\n15\n126\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "24\n2\n5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "289\n56\n26\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "713\n150\n591\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "841\n62\n704\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "266\n38\n164\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "156\n34\n7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "28\n14\n9\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "604\n356\n239\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "180\n18\n76\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "879\n545\n607\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "599\n160\n520\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "727\n147\n693\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "151\n27\n135\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "504\n71\n73\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "80\n57\n31\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "951\n225\n352\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "823\n168\n141\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "956\n582\n931\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "380\n108\n356\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "804\n166\n472\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "228\n12\n159\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "380\n126\n82\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "252\n52\n178\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "828\n363\n56\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "404\n122\n36\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "314\n4\n237\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "34\n5\n17\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "162\n105\n160\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "586\n22\n272\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "32\n9\n2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "904\n409\n228\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "480\n283\n191\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "56\n37\n10\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "429\n223\n170\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "149\n124\n129\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "277\n173\n241\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "701\n211\n501\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "172\n144\n42\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "748\n549\n256\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "324\n284\n26\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "900\n527\n298\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "648\n624\n384\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "72\n48\n54\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "200\n194\n87\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "624\n510\n555\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "17\n16\n2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "593\n442\n112\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "169\n158\n11\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "41\n38\n17\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "762\n609\n442\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "186\n98\n104\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "314\n304\n294\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "35\n35\n33\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "8\n3\n5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "11\n3\n5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n4\n2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "41\n5\n36\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\n4\n1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6\n1\n4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "597\n142\n484\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\n6\n1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8\n4\n2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1\n4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\n2\n3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100\n100\n50\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5\n1\n3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\n4\n6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8\n8\n2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5\n2\n4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "11\n5\n3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "668\n248\n336\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2\n2\n1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "465\n126\n246\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1\n5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "132\n34\n64\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "11\n1\n6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8\n4\n5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n2\n4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "576\n238\n350\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6\n1\n5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1\n4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "9\n2\n8\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\n3\n4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "9\n4\n5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10\n3\n4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "18\n5\n8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1\n1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100\n40\n60\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\n4\n4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3\n1\n1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10\n3\n7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "9\n2\n5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\n2\n3\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/910/B"
} | vfc_9986 |
apps | verifiable_code | 60 | Solve the following coding problem using the programming language python:
A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the left of an aisle (if one looks in the direction of the cockpit), while seats 'd', 'e' and 'f' are located to the right. Seats 'a' and 'f' are located near the windows, while seats 'c' and 'd' are located near the aisle. [Image]
It's lunch time and two flight attendants have just started to serve food. They move from the first rows to the tail, always maintaining a distance of two rows from each other because of the food trolley. Thus, at the beginning the first attendant serves row 1 while the second attendant serves row 3. When both rows are done they move one row forward: the first attendant serves row 2 while the second attendant serves row 4. Then they move three rows forward and the first attendant serves row 5 while the second attendant serves row 7. Then they move one row forward again and so on.
Flight attendants work with the same speed: it takes exactly 1 second to serve one passenger and 1 second to move one row forward. Each attendant first serves the passengers on the seats to the right of the aisle and then serves passengers on the seats to the left of the aisle (if one looks in the direction of the cockpit). Moreover, they always serve passengers in order from the window to the aisle. Thus, the first passenger to receive food in each row is located in seat 'f', and the last one — in seat 'c'. Assume that all seats are occupied.
Vasya has seat s in row n and wants to know how many seconds will pass before he gets his lunch.
-----Input-----
The only line of input contains a description of Vasya's seat in the format ns, where n (1 ≤ n ≤ 10^18) is the index of the row and s is the seat in this row, denoted as letter from 'a' to 'f'. The index of the row and the seat are not separated by a space.
-----Output-----
Print one integer — the number of seconds Vasya has to wait until he gets his lunch.
-----Examples-----
Input
1f
Output
1
Input
2d
Output
10
Input
4a
Output
11
Input
5e
Output
18
-----Note-----
In the first sample, the first flight attendant serves Vasya first, so Vasya gets his lunch after 1 second.
In the second sample, the flight attendants will spend 6 seconds to serve everyone in the rows 1 and 3, then they will move one row forward in 1 second. As they first serve seats located to the right of the aisle in order from window to aisle, Vasya has to wait 3 more seconds. The total is 6 + 1 + 3 = 10.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
seat = input()
time_to = {'a': 4, 'f': 1, 'b': 5, 'e': 2, 'c': 6, 'd': 3}
col = seat[-1]
row = int(seat[:-1])
row -= 1
blocks_to_serve = row // 4
time = (6 * 2 + 4) * blocks_to_serve
if row % 2 == 1:
time += 6 + 1
time += time_to[col]
print(time)
``` | {
"language": "python",
"test_cases": [
{
"input": "1f\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2d\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "4a\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "5e\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "2c\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "1b\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000d\n",
"output": "3999999999999999994\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999997a\n",
"output": "3999999999999999988\n",
"type": "stdin_stdout"
},
{
"input": "1c\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1d\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1e\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1a\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "2a\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "2b\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "2e\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2f\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "3a\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3b\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3c\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3d\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3e\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3f\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4b\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "4c\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "4d\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "4e\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "4f\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "999999997a\n",
"output": "3999999988\n",
"type": "stdin_stdout"
},
{
"input": "999999997b\n",
"output": "3999999989\n",
"type": "stdin_stdout"
},
{
"input": "999999997c\n",
"output": "3999999990\n",
"type": "stdin_stdout"
},
{
"input": "999999997d\n",
"output": "3999999987\n",
"type": "stdin_stdout"
},
{
"input": "999999997e\n",
"output": "3999999986\n",
"type": "stdin_stdout"
},
{
"input": "999999997f\n",
"output": "3999999985\n",
"type": "stdin_stdout"
},
{
"input": "999999998a\n",
"output": "3999999995\n",
"type": "stdin_stdout"
},
{
"input": "999999998b\n",
"output": "3999999996\n",
"type": "stdin_stdout"
},
{
"input": "999999998c\n",
"output": "3999999997\n",
"type": "stdin_stdout"
},
{
"input": "999999998d\n",
"output": "3999999994\n",
"type": "stdin_stdout"
},
{
"input": "999999998e\n",
"output": "3999999993\n",
"type": "stdin_stdout"
},
{
"input": "999999998f\n",
"output": "3999999992\n",
"type": "stdin_stdout"
},
{
"input": "999999999a\n",
"output": "3999999988\n",
"type": "stdin_stdout"
},
{
"input": "999999999b\n",
"output": "3999999989\n",
"type": "stdin_stdout"
},
{
"input": "999999999c\n",
"output": "3999999990\n",
"type": "stdin_stdout"
},
{
"input": "999999999d\n",
"output": "3999999987\n",
"type": "stdin_stdout"
},
{
"input": "999999999e\n",
"output": "3999999986\n",
"type": "stdin_stdout"
},
{
"input": "999999999f\n",
"output": "3999999985\n",
"type": "stdin_stdout"
},
{
"input": "1000000000a\n",
"output": "3999999995\n",
"type": "stdin_stdout"
},
{
"input": "1000000000b\n",
"output": "3999999996\n",
"type": "stdin_stdout"
},
{
"input": "1000000000c\n",
"output": "3999999997\n",
"type": "stdin_stdout"
},
{
"input": "1000000000d\n",
"output": "3999999994\n",
"type": "stdin_stdout"
},
{
"input": "1000000000e\n",
"output": "3999999993\n",
"type": "stdin_stdout"
},
{
"input": "1000000000f\n",
"output": "3999999992\n",
"type": "stdin_stdout"
},
{
"input": "100000b\n",
"output": "399996\n",
"type": "stdin_stdout"
},
{
"input": "100000f\n",
"output": "399992\n",
"type": "stdin_stdout"
},
{
"input": "100001d\n",
"output": "400003\n",
"type": "stdin_stdout"
},
{
"input": "100001e\n",
"output": "400002\n",
"type": "stdin_stdout"
},
{
"input": "100001f\n",
"output": "400001\n",
"type": "stdin_stdout"
},
{
"input": "100002a\n",
"output": "400011\n",
"type": "stdin_stdout"
},
{
"input": "100002b\n",
"output": "400012\n",
"type": "stdin_stdout"
},
{
"input": "100002d\n",
"output": "400010\n",
"type": "stdin_stdout"
},
{
"input": "1231273a\n",
"output": "4925092\n",
"type": "stdin_stdout"
},
{
"input": "82784f\n",
"output": "331128\n",
"type": "stdin_stdout"
},
{
"input": "88312c\n",
"output": "353245\n",
"type": "stdin_stdout"
},
{
"input": "891237e\n",
"output": "3564946\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999997b\n",
"output": "3999999999999999989\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999997c\n",
"output": "3999999999999999990\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999997d\n",
"output": "3999999999999999987\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999997e\n",
"output": "3999999999999999986\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999997f\n",
"output": "3999999999999999985\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999998a\n",
"output": "3999999999999999995\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999998b\n",
"output": "3999999999999999996\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999998c\n",
"output": "3999999999999999997\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999998d\n",
"output": "3999999999999999994\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999998e\n",
"output": "3999999999999999993\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999998f\n",
"output": "3999999999999999992\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999a\n",
"output": "3999999999999999988\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999b\n",
"output": "3999999999999999989\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999c\n",
"output": "3999999999999999990\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999d\n",
"output": "3999999999999999987\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000a\n",
"output": "3999999999999999995\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000e\n",
"output": "3999999999999999993\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000f\n",
"output": "3999999999999999992\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000c\n",
"output": "3999999999999999997\n",
"type": "stdin_stdout"
},
{
"input": "97a\n",
"output": "388\n",
"type": "stdin_stdout"
},
{
"input": "6f\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "7f\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "7e\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999992c\n",
"output": "3999999999999999965\n",
"type": "stdin_stdout"
},
{
"input": "7a\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "8f\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999992a\n",
"output": "3999999999999999963\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999992b\n",
"output": "3999999999999999964\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999992c\n",
"output": "3999999999999999965\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999992d\n",
"output": "3999999999999999962\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999992e\n",
"output": "3999999999999999961\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999992f\n",
"output": "3999999999999999960\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999993a\n",
"output": "3999999999999999972\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999993b\n",
"output": "3999999999999999973\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999993c\n",
"output": "3999999999999999974\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999993d\n",
"output": "3999999999999999971\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999993e\n",
"output": "3999999999999999970\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999993f\n",
"output": "3999999999999999969\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999994a\n",
"output": "3999999999999999979\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999994b\n",
"output": "3999999999999999980\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999994c\n",
"output": "3999999999999999981\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999994d\n",
"output": "3999999999999999978\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999994e\n",
"output": "3999999999999999977\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999994f\n",
"output": "3999999999999999976\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999995a\n",
"output": "3999999999999999972\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999995b\n",
"output": "3999999999999999973\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999995c\n",
"output": "3999999999999999974\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999995d\n",
"output": "3999999999999999971\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999995e\n",
"output": "3999999999999999970\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999995f\n",
"output": "3999999999999999969\n",
"type": "stdin_stdout"
},
{
"input": "10a\n",
"output": "43\n",
"type": "stdin_stdout"
},
{
"input": "11f\n",
"output": "33\n",
"type": "stdin_stdout"
},
{
"input": "681572647b\n",
"output": "2726290581\n",
"type": "stdin_stdout"
},
{
"input": "23f\n",
"output": "81\n",
"type": "stdin_stdout"
},
{
"input": "123a\n",
"output": "484\n",
"type": "stdin_stdout"
},
{
"input": "999999888888777777a\n",
"output": "3999999555555111108\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/725/B"
} | vfc_9994 |
apps | verifiable_code | 61 | Solve the following coding problem using the programming language python:
After seeing the "ALL YOUR BASE ARE BELONG TO US" meme for the first time, numbers X and Y realised that they have different bases, which complicated their relations.
You're given a number X represented in base b_{x} and a number Y represented in base b_{y}. Compare those two numbers.
-----Input-----
The first line of the input contains two space-separated integers n and b_{x} (1 ≤ n ≤ 10, 2 ≤ b_{x} ≤ 40), where n is the number of digits in the b_{x}-based representation of X.
The second line contains n space-separated integers x_1, x_2, ..., x_{n} (0 ≤ x_{i} < b_{x}) — the digits of X. They are given in the order from the most significant digit to the least significant one.
The following two lines describe Y in the same way: the third line contains two space-separated integers m and b_{y} (1 ≤ m ≤ 10, 2 ≤ b_{y} ≤ 40, b_{x} ≠ b_{y}), where m is the number of digits in the b_{y}-based representation of Y, and the fourth line contains m space-separated integers y_1, y_2, ..., y_{m} (0 ≤ y_{i} < b_{y}) — the digits of Y.
There will be no leading zeroes. Both X and Y will be positive. All digits of both numbers are given in the standard decimal numeral system.
-----Output-----
Output a single character (quotes for clarity): '<' if X < Y '>' if X > Y '=' if X = Y
-----Examples-----
Input
6 2
1 0 1 1 1 1
2 10
4 7
Output
=
Input
3 3
1 0 2
2 5
2 4
Output
<
Input
7 16
15 15 4 0 0 7 10
7 9
4 8 0 3 1 5 0
Output
>
-----Note-----
In the first sample, X = 101111_2 = 47_10 = Y.
In the second sample, X = 102_3 = 21_5 and Y = 24_5 = 112_3, thus X < Y.
In the third sample, $X = FF 4007 A_{16}$ and Y = 4803150_9. We may notice that X starts with much larger digits and b_{x} is much larger than b_{y}, so X is clearly larger than Y.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, bx = list(map(int, input().split()))
x1 = list(map(int, input().split()))
x = 0
for i in range(n):
x *= bx
x += x1[i]
n, by = list(map(int, input().split()))
y1 = list(map(int, input().split()))
y = 0
for i in range(n):
y *= by
y += y1[i]
if x == y:
print('=')
elif x < y:
print('<')
else:
print('>')
``` | {
"language": "python",
"test_cases": [
{
"input": "6 2\n1 0 1 1 1 1\n2 10\n4 7\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 0 2\n2 5\n2 4\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "7 16\n15 15 4 0 0 7 10\n7 9\n4 8 0 3 1 5 0\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n1 0\n2 3\n1 0\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n1 0\n1 3\n1\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "10 2\n1 0 1 0 1 0 1 0 1 0\n10 3\n2 2 2 2 2 2 2 2 2 2\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "10 16\n15 15 4 0 0 0 0 7 10 9\n7 9\n4 8 0 3 1 5 0\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n4 4 4 4 4\n4 6\n5 5 5 5\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "2 8\n1 0\n4 2\n1 0 0 0\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n1 0 0 0 1\n6 8\n1 4 7 2 0 0\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "6 7\n1 1 2 1 2 1\n6 6\n2 3 2 2 2 2\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "9 35\n34 3 20 29 27 30 2 8 5\n7 33\n17 3 22 31 1 11 6\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "1 8\n5\n9 27\n23 23 23 23 23 23 23 23 23\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "4 7\n3 0 6 6\n3 11\n7 10 10\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "1 40\n1\n2 5\n1 0\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "1 36\n35\n4 5\n2 4 4 1\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "1 30\n1\n1 31\n1\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n1\n1 2\n1\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n1\n1 40\n1\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "6 29\n1 1 1 1 1 1\n10 21\n1 1 1 1 1 1 1 1 1 1\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n1 0 0\n3 3\n2 2 2\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "2 8\n1 0\n2 3\n2 2\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n3 3\n2 15\n1 0\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "2 35\n1 0\n2 6\n5 5\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "2 6\n5 5\n2 34\n1 0\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "2 7\n1 0\n2 3\n2 2\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n1 0\n1 3\n2\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "2 9\n5 5\n4 3\n1 0 0 0\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "1 24\n6\n3 9\n1 1 1\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "5 37\n9 9 9 9 9\n6 27\n13 0 0 0 0 0\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "10 2\n1 1 1 1 1 1 1 1 1 1\n10 34\n14 14 14 14 14 14 14 14 14 14\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "7 26\n8 0 0 0 0 0 0\n9 9\n3 3 3 3 3 3 3 3 3\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "2 40\n2 0\n5 13\n4 0 0 0 0\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "1 22\n15\n10 14\n3 3 3 3 3 3 3 3 3 3\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "10 22\n3 3 3 3 3 3 3 3 3 3\n3 40\n19 19 19\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "2 29\n11 11\n6 26\n11 11 11 11 11 11\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n1 0 0 0 0\n4 27\n1 0 0 0\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n1 0 0 0 0 0 0 0 0 0\n8 13\n1 0 0 0 0 0 0 0\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "4 20\n1 1 1 1\n5 22\n1 1 1 1 1\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "10 39\n34 2 24 34 11 6 33 12 22 21\n10 36\n25 35 17 24 30 0 1 32 14 35\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "10 39\n35 12 31 35 28 27 25 8 22 25\n10 40\n23 21 18 12 15 29 38 32 4 8\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "10 38\n16 19 37 32 16 7 14 33 16 11\n10 39\n10 27 35 15 31 15 17 16 38 35\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "10 39\n20 12 10 32 24 14 37 35 10 38\n9 40\n1 13 0 10 22 20 1 5 35\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "10 40\n18 1 2 25 28 2 10 2 17 37\n10 39\n37 8 12 8 21 11 23 11 25 21\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "9 39\n10 20 16 36 30 29 28 9 8\n9 38\n12 36 10 22 6 3 19 12 34\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "7 39\n28 16 13 25 19 23 4\n7 38\n33 8 2 19 3 21 14\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "10 16\n15 15 4 0 0 0 0 7 10 9\n10 9\n4 8 0 3 1 5 4 8 1 0\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "7 22\n1 13 9 16 7 13 3\n4 4\n3 0 2 1\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "10 29\n10 19 8 27 1 24 13 15 13 26\n2 28\n20 14\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "6 16\n2 13 7 13 15 6\n10 22\n17 17 21 9 16 11 4 4 13 17\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "8 26\n6 6 17 25 24 8 8 25\n4 27\n24 7 5 24\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "10 23\n5 21 4 15 12 7 10 7 16 21\n4 17\n3 11 1 14\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "10 21\n4 7 7 2 13 7 19 19 18 19\n3 31\n6 11 28\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "1 30\n9\n7 37\n20 11 18 14 0 36 27\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "5 35\n22 18 28 29 11\n2 3\n2 0\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "7 29\n14 26 14 22 11 11 8\n6 28\n2 12 10 17 0 14\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "2 37\n25 2\n3 26\n13 13 12\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "8 8\n4 0 4 3 4 1 5 6\n8 24\n19 8 15 6 10 7 2 18\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "4 22\n18 16 1 2\n10 26\n23 0 12 24 16 2 24 25 1 11\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "7 31\n14 6 16 6 26 18 17\n7 24\n22 10 4 5 14 6 9\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "10 29\n15 22 0 5 11 12 17 22 4 27\n4 22\n9 2 8 14\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "2 10\n6 0\n10 26\n16 14 8 18 24 4 9 5 22 25\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "7 2\n1 0 0 0 1 0 1\n9 6\n1 1 5 1 2 5 3 5 3\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "3 9\n2 5 4\n1 19\n15\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "6 16\n4 9 13 4 2 8\n4 10\n3 5 2 4\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "2 12\n1 4\n8 16\n4 4 10 6 15 10 8 15\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "3 19\n9 18 16\n4 10\n4 3 5 4\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "7 3\n1 1 2 1 2 0 2\n2 2\n1 0\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n1 1 1\n1 3\n1\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n1 3 1 3\n9 3\n1 1 0 1 2 2 2 2 1\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "9 3\n1 0 0 1 1 0 0 1 2\n6 4\n1 2 0 1 3 2\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n1 1 3\n10 4\n3 3 2 3 0 0 0 3 1 1\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "6 4\n3 3 2 2 0 2\n6 5\n1 1 1 1 0 3\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "6 5\n4 4 4 3 1 3\n7 6\n4 2 2 2 5 0 4\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "2 5\n3 3\n6 6\n4 2 0 1 1 0\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "10 6\n3 5 4 2 4 2 3 5 4 2\n10 7\n3 2 1 1 3 1 0 3 4 5\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "9 7\n2 0 3 2 6 6 1 4 3\n9 6\n4 4 1 1 4 5 5 0 2\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "1 7\n2\n4 8\n3 2 3 2\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "2 8\n4 1\n1 7\n1\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "1 10\n7\n3 9\n2 1 7\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "9 9\n2 2 3 6 3 6 3 8 4\n6 10\n4 7 7 0 3 8\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "3 11\n6 5 2\n8 10\n5 0 1 8 3 5 1 4\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "6 11\n10 6 1 0 2 2\n9 10\n4 3 4 1 1 6 3 4 1\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "2 19\n4 8\n8 18\n7 8 6 8 4 11 9 1\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "2 24\n20 9\n10 23\n21 10 15 11 6 8 20 16 14 11\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "8 36\n23 5 27 1 10 7 26 27\n10 35\n28 33 9 22 10 28 26 4 27 29\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "6 37\n22 15 14 10 1 8\n6 36\n18 5 28 10 1 17\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "5 38\n1 31 2 21 21\n9 37\n8 36 32 30 13 9 24 2 35\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "3 39\n27 4 3\n8 38\n32 15 11 34 35 27 30 15\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "2 40\n22 38\n5 39\n8 9 32 4 1\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "9 37\n1 35 7 33 20 21 26 24 5\n10 40\n39 4 11 9 33 12 26 32 11 8\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "4 39\n13 25 23 35\n6 38\n19 36 20 4 12 33\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "5 37\n29 29 5 7 27\n3 39\n13 1 10\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "7 28\n1 10 7 0 13 14 11\n6 38\n8 11 27 5 14 35\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "2 34\n1 32\n2 33\n2 0\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "7 5\n4 0 4 1 3 0 4\n4 35\n1 18 7 34\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "9 34\n5 8 4 4 26 1 30 5 24\n10 27\n1 6 3 10 8 13 22 3 12 8\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "10 36\n1 13 13 23 31 35 5 32 18 21\n9 38\n32 1 20 14 12 37 13 15 23\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "10 40\n1 1 14 5 6 3 3 11 3 25\n10 39\n1 11 24 33 25 34 38 29 27 33\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "9 37\n2 6 1 9 19 6 11 28 35\n9 40\n1 6 14 37 1 8 31 4 9\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n1 4 2 0\n4 4\n3 2 2 3\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "6 4\n1 1 1 2 2 2\n7 3\n1 2 2 0 1 0 0\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "2 5\n3 3\n5 2\n1 0 0 1 0\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "1 9\n2\n1 10\n2\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "6 19\n4 9 14 1 3 1\n8 10\n1 1 1 7 3 7 3 0\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "7 15\n8 5 8 10 13 6 13\n8 13\n1 6 9 10 12 3 12 8\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "8 18\n1 1 4 15 7 4 9 3\n8 17\n1 10 2 10 3 11 14 10\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "8 21\n5 19 0 14 13 13 10 5\n10 13\n1 0 0 6 11 10 8 2 8 1\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "8 28\n3 1 10 19 10 14 21 15\n8 21\n14 0 18 13 2 1 18 6\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "7 34\n21 22 28 16 30 4 27\n7 26\n5 13 21 10 8 12 10\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "6 26\n7 6 4 18 6 1\n6 25\n5 3 11 1 8 15\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "10 31\n6 27 17 22 14 16 25 9 13 26\n10 39\n6 1 3 26 12 32 28 19 9 19\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n2 2 3\n3 6\n4 3 5\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "2 24\n4 18\n2 40\n29 24\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "5 38\n2 24 34 14 17\n8 34\n4 24 31 2 14 15 8 15\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "9 40\n39 39 39 39 39 39 39 39 39\n6 35\n34 34 34 34 34 34\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "10 40\n39 39 39 39 39 39 39 39 39 39\n10 8\n7 7 7 7 7 7 7 7 7 7\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "10 40\n39 39 39 39 39 39 39 39 39 39\n10 39\n38 38 38 38 38 38 38 38 38 38\n",
"output": ">\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/602/A"
} | vfc_9998 |
apps | verifiable_code | 62 | Solve the following coding problem using the programming language python:
Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games!
Since you are so curious about Bitland, I'll give you the chance of peeking at one of these games.
BitLGM and BitAryo are playing yet another of their crazy-looking genius-needed Bitlandish games. They've got a sequence of n non-negative integers a_1, a_2, ..., a_{n}. The players make moves in turns. BitLGM moves first. Each player can and must do one of the two following actions in his turn:
Take one of the integers (we'll denote it as a_{i}). Choose integer x (1 ≤ x ≤ a_{i}). And then decrease a_{i} by x, that is, apply assignment: a_{i} = a_{i} - x. Choose integer x $(1 \leq x \leq \operatorname{min}_{i = 1} a_{i})$. And then decrease all a_{i} by x, that is, apply assignment: a_{i} = a_{i} - x, for all i.
The player who cannot make a move loses.
You're given the initial sequence a_1, a_2, ..., a_{n}. Determine who wins, if both players plays optimally well and if BitLGM and BitAryo start playing the described game in this sequence.
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 3).
The next line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} < 300).
-----Output-----
Write the name of the winner (provided that both players play optimally well). Either "BitLGM" or "BitAryo" (without the quotes).
-----Examples-----
Input
2
1 1
Output
BitLGM
Input
2
1 2
Output
BitAryo
Input
3
1 2 1
Output
BitLGM
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from math import *
n=int(input())
if n==3:
li=list(map(int,input().split()))
ans=0
flag=0
for i in li:
ans^=i
if ans==0:
print("BitAryo")
else:
print("BitLGM")
elif n==2:
li=list(map(int,input().split()))
li.sort()
phi=(1+sqrt(5))/2
ch=[0]*(785)
for i in range(300):
a=floor(phi*i)
b=floor((phi**2)*i)
ch[a]=b
ch[b]=a
if ch[li[0]]==li[1]:
print("BitAryo")
else:
print("BitLGM")
else:
li=int(input())
if li==0:
print("BitAryo")
else:
print("BitLGM")
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n1 1\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2 1\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 3\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 5\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n9 10\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 8\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 0 0\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n223 58\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n106 227\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n125 123\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n31 132 7\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n41 29\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n103 286 100\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n9 183 275\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n19 88 202\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n234 44 69\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n244 241 295\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n6\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n231\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n241 289\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n200 185\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n218 142\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n124 47 228\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n134 244 95\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "1\n10\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n99\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n44 27\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n280 173\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n29 47\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n16 26\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n58 94\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n17 28\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n59 96\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n164 101\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n143 88\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n69 112\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n180 111\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n159 98\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n183 113\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n162 100\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n230 142\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n298 184\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n144 233\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n0 0\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n173 280\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n180 111\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n251 155\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n114 185\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n156 253\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n144 233\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n0 0\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n14 23\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 1\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n70 43\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n49 30\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n150 243\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 10\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n152 246\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n13 8\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n293 181\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n15 9\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n295 182\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n62 38\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n80 130\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "2\n40 65\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "1\n248\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n10\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n216 91\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n234\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n140 193\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n151 97 120\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n213\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n119 251 222\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n129 148 141\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n147\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n124 194\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n184 222 102\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n101 186 223\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 87 87\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n144 33 177\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n49 252 205\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n49 126 79\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n152 66 218\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n181 232 93\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n15 150 153\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n191 50 141\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n162 230 68\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 19 23\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n222 129 95\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n38 16 54\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n254 227 29\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n196 45 233\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n70 45 107\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n190 61 131\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n0 173 173\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "3\n50 69 119\n",
"output": "BitAryo\n",
"type": "stdin_stdout"
},
{
"input": "1\n108\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n15\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n85\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n291\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n11 222\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n218 127\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n280 24\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n298 281\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n275 70 60\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n299 299 298\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n299 299 299\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n299 299 299\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n298 299\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "2\n299 299\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "1\n299\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
},
{
"input": "3\n299 290 288\n",
"output": "BitLGM\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/282/D"
} | vfc_10002 |
apps | verifiable_code | 63 | Solve the following coding problem using the programming language python:
Vova again tries to play some computer card game.
The rules of deck creation in this game are simple. Vova is given an existing deck of n cards and a magic number k. The order of the cards in the deck is fixed. Each card has a number written on it; number a_{i} is written on the i-th card in the deck.
After receiving the deck and the magic number, Vova removes x (possibly x = 0) cards from the top of the deck, y (possibly y = 0) cards from the bottom of the deck, and the rest of the deck is his new deck (Vova has to leave at least one card in the deck after removing cards). So Vova's new deck actually contains cards x + 1, x + 2, ... n - y - 1, n - y from the original deck.
Vova's new deck is considered valid iff the product of all numbers written on the cards in his new deck is divisible by k. So Vova received a deck (possibly not a valid one) and a number k, and now he wonders, how many ways are there to choose x and y so the deck he will get after removing x cards from the top and y cards from the bottom is valid?
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 100 000, 1 ≤ k ≤ 10^9).
The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — the numbers written on the cards.
-----Output-----
Print the number of ways to choose x and y so the resulting deck is valid.
-----Examples-----
Input
3 4
6 2 8
Output
4
Input
3 6
9 1 14
Output
1
-----Note-----
In the first example the possible values of x and y are:
x = 0, y = 0; x = 1, y = 0; x = 2, y = 0; x = 0, y = 1.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n,k=map(int,input().split())
l=list(map(int,input().split()))
pf=[]
needed=[]
for i in range(2,40000):
if k%i==0:
pf.append(i)
c=0
while k%i==0:
k//=i
c+=1
needed.append(c)
if k>1:
pf.append(k)
needed.append(1)
pfl=len(pf)
cnt=[[0]*n for i in range(pfl)]
for i in range(n):
for j in range(len(pf)):
c=0
while l[i]%pf[j]==0:
c+=1
l[i]//=pf[j]
cnt[j][i]=c
have=[sum(i) for i in cnt]
pos=n
def ok():
for i in range(len(pf)):
if have[i]<needed[i]:
return False
return True
if not ok():
print(0)
quit()
for i in range(n-1,0,-1):
for j in range(len(pf)):
have[j]-=cnt[j][i]
if not ok():
for j in range(len(pf)):
have[j]+=cnt[j][i]
break
pos=i
ans=n-pos+1
for x in range(n-1):
for j in range(len(pf)):
have[j]-=cnt[j][x]
if pos==(x+1):
for j in range(len(pf)):
have[j]+=cnt[j][pos]
pos+=1
while pos<n:
if ok():
break
else:
for i in range(len(pf)):
have[i]+=cnt[i][pos]
pos+=1
if ok():
ans+=n-pos+1
else:
break
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "3 4\n6 2 8\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3 6\n9 1 14\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n1 3 1 3 1\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n5 5 5 5 5\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n5 4 4 4 4\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "100 1\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "5050\n",
"type": "stdin_stdout"
},
{
"input": "100 1\n3 3 2 1 1 2 1 2 3 4 1 5 2 4 5 1 1 3 2 3 4 2 1 3 4 4 5 5 1 5 2 5 3 3 1 1 1 3 2 2 3 4 4 4 4 3 1 3 5 3 3 3 3 2 3 2 2 3 3 1 2 4 3 2 2 5 3 1 5 2 2 5 1 2 1 1 5 1 5 2 4 5 3 4 2 5 4 2 2 5 5 5 3 3 5 3 4 3 3 1\n",
"output": "5050\n",
"type": "stdin_stdout"
},
{
"input": "100 5\n4 4 3 2 4 4 1 2 2 1 5 3 2 5 5 3 2 3 4 5 2 2 3 4 2 4 3 1 2 3 5 5 1 3 3 5 2 3 3 4 1 3 1 5 4 4 2 1 5 1 4 4 1 5 1 1 5 5 5 4 1 3 1 2 3 2 4 5 5 1 3 4 3 3 1 2 2 4 1 5 1 1 2 4 4 4 5 5 5 3 4 3 3 3 3 2 1 1 5 5\n",
"output": "4713\n",
"type": "stdin_stdout"
},
{
"input": "100 6\n4 4 1 1 1 1 3 3 5 5 4 2 2 4 3 4 4 5 5 4 5 1 3 1 5 4 5 1 2 5 5 2 2 4 2 4 4 2 5 5 3 3 1 3 3 5 2 3 1 4 1 4 4 1 5 5 1 2 3 2 3 3 5 3 4 2 3 4 3 1 5 3 5 5 3 5 4 4 3 1 1 2 1 2 1 3 2 4 3 2 1 4 3 1 1 5 1 5 4 3\n",
"output": "4580\n",
"type": "stdin_stdout"
},
{
"input": "100 72\n8 8 7 9 6 1 4 5 3 7 5 10 5 4 1 3 4 1 3 1 6 6 4 5 4 5 6 1 10 7 9 1 6 10 6 6 9 3 3 4 5 9 4 9 8 1 5 9 3 7 1 8 5 2 1 1 7 7 7 6 6 4 2 9 10 2 8 3 1 1 4 8 5 9 7 10 9 4 2 3 7 7 6 7 8 5 1 3 8 5 1 8 9 10 3 7 1 8 10 5\n",
"output": "4549\n",
"type": "stdin_stdout"
},
{
"input": "100 72\n3 2 1 3 3 3 4 3 5 5 2 5 1 2 2 2 1 4 1 5 1 4 5 4 3 1 4 3 4 4 1 4 4 3 4 1 4 4 5 2 2 3 3 5 4 5 4 2 4 3 1 1 1 4 5 5 3 1 5 3 4 4 5 3 5 1 4 3 2 2 1 4 2 1 3 2 4 2 1 4 4 1 3 4 4 4 1 5 5 2 5 2 3 1 5 1 1 1 2 3\n",
"output": "4123\n",
"type": "stdin_stdout"
},
{
"input": "2 999634589\n31607 31627\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 4\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 5\n3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 6\n4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 7\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 8\n3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 9\n5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 10\n3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 5\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 6\n2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 7\n1 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 8\n5 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 9\n2 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 10\n6 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n1 1 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n2 2 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n2 1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n2 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n1 1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 6\n4 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 7\n3 4 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 8\n5 1 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 9\n3 2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 10\n6 5 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n1 1 1 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n2 2 1 2\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n2 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n2 2 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n2 3 2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n1 1 3 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 7\n1 1 2 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 8\n5 4 5 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 9\n1 1 4 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 10\n2 6 2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n1 1 1 1 1\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n2 2 1 2 1\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n2 1 1 2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n2 2 1 3 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n2 3 1 1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n3 4 3 4 3\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n3 1 3 2 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 8\n2 2 3 3 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 9\n3 1 3 3 4\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5 10\n3 6 6 1 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n1 1 1 1 1 1\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "6 2\n1 2 2 1 1 1\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "6 3\n2 2 2 2 1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6 4\n1 3 3 3 3 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6 5\n2 3 3 2 1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6 6\n1 2 4 1 4 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6 7\n2 2 4 3 2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6 8\n3 2 3 5 5 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6 9\n1 4 1 2 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6 10\n1 2 5 6 6 6\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "7 1\n1 1 1 1 1 1 1\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "7 2\n1 1 2 2 2 2 1\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "7 3\n2 2 1 1 2 2 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "7 4\n3 2 1 2 1 1 1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "7 5\n2 3 3 3 2 3 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "7 6\n3 4 4 1 4 3 2\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "7 7\n4 2 4 4 1 4 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "7 8\n4 4 2 4 2 5 3\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "7 9\n2 1 3 4 4 5 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "7 10\n6 3 3 5 3 6 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "8 1\n1 1 1 1 1 1 1 1\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "8 2\n1 1 1 1 1 1 1 2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "8 3\n1 1 2 2 1 1 2 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8 4\n2 3 2 3 3 3 2 3\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "8 5\n1 3 1 2 2 2 1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8 6\n4 2 4 2 1 2 1 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8 7\n2 2 1 4 4 4 2 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8 8\n5 2 1 2 4 2 2 4\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "8 9\n4 4 2 2 5 5 4 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8 10\n2 1 4 4 3 4 4 6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "9 1\n1 1 1 1 1 1 1 1 1\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "9 2\n1 1 1 2 1 1 2 2 2\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "9 3\n1 1 1 2 2 1 1 2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "9 4\n1 1 2 1 2 1 1 1 1\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "9 5\n3 2 3 2 3 1 1 3 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "9 6\n2 1 1 3 2 4 1 2 2\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "9 7\n4 3 2 1 2 3 3 4 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "9 8\n5 5 2 1 3 1 3 1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "9 9\n2 4 1 4 4 3 3 4 1\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "9 10\n4 3 2 5 2 2 2 2 6\n",
"output": "23\n",
"type": "stdin_stdout"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1\n",
"output": "55\n",
"type": "stdin_stdout"
},
{
"input": "10 2\n2 2 2 2 2 2 2 1 2 1\n",
"output": "53\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n2 2 1 1 2 2 2 2 1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n1 1 2 3 3 1 2 2 2 3\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n3 3 2 2 3 1 1 1 3 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 6\n4 4 4 3 2 1 1 1 2 4\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "10 7\n4 2 2 2 3 3 2 4 4 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 8\n5 4 1 4 3 2 1 2 3 3\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "10 9\n1 2 3 4 5 2 3 5 5 4\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n5 3 2 5 1 2 5 1 5 1\n",
"output": "35\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000\n1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 100000000\n1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/818/E"
} | vfc_10006 |
apps | verifiable_code | 64 | Solve the following coding problem using the programming language python:
One day Kefa found n baloons. For convenience, we denote color of i-th baloon as s_{i} — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.
-----Input-----
The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends.
Next line contains string s — colors of baloons.
-----Output-----
Answer to the task — «YES» or «NO» in a single line.
You can choose the case (lower or upper) for each letter arbitrary.
-----Examples-----
Input
4 2
aabb
Output
YES
Input
6 3
aacaab
Output
NO
-----Note-----
In the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.
In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
alpha = [chr(ord('a')+i) for i in range(26)]
n,k = list(map(int,input().split()))
s = input()
arr = [s.count(alpha[i]) for i in range(26)]
print('YES' if max(arr) <= k else 'NO')
``` | {
"language": "python",
"test_cases": [
{
"input": "4 2\naabb\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 3\naacaab\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nlu\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 3\novvoo\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "36 13\nbzbzcffczzcbcbzzfzbbfzfzzbfbbcbfccbf\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "81 3\nooycgmvvrophvcvpoupepqllqttwcocuilvyxbyumdmmfapvpnxhjhxfuagpnntonibicaqjvwfhwxhbv\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100 100\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 1\nnubcvvjvbjgnjsdkajimdcxvewbcytvfkihunycdrlconddlwgzjasjlsrttlrzsumzpyumpveglfqzmaofbshbojmwuwoxxvrod\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100 13\nvyldolgryldqrvoldvzvrdrgorlorszddtgqvrlisxxrxdxlqtvtgsrqlzixoyrozxzogqxlsgzdddzqrgitxxritoolzolgrtvl\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "18 6\njzwtnkvmscqhmdlsxy\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "21 2\nfscegcqgzesefghhwcexs\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "32 22\ncduamsptaklqtxlyoutlzepxgyfkvngc\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "49 27\noxyorfnkzwsfllnyvdhdanppuzrnbxehugvmlkgeymqjlmfxd\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "50 24\nxxutzjwbggcwvxztttkmzovtmuwttzcbwoztttohzzxghuuthv\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "57 35\nglxshztrqqfyxthqamagvtmrdparhelnzrqvcwqxjytkbuitovkdxueul\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "75 23\nittttiiuitutuiiuuututiuttiuiuutuuuiuiuuuuttuuttuutuiiuiuiiuiitttuututuiuuii\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "81 66\nfeqevfqfebhvubhuuvfuqheuqhbeeuebehuvhffvbqvqvfbqqvvhevqffbqqhvvqhfeehuhqeqhueuqqq\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "93 42\npqeiafraiavfcteumflpcbpozcomlvpovlzdbldvoopnhdoeqaopzthiuzbzmeieiatthdeqovaqfipqlddllmfcrrnhb\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 53\nizszyqyndzwzyzgsdagdwdazadiawizinagqqgczaqqnawgijziziawzszdjdcqjdjqiwgadydcnqisaayjiqqsscwwzjzaycwwc\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 14\nvkrdcqbvkwuckpmnbydmczdxoagdsgtqxvhaxntdcxhjcrjyvukhugoglbmyoaqexgtcfdgemmizoniwtmisqqwcwfusmygollab\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 42\naaaaaiiiiaiiiaaiaiiaaiiiiiaaaaaiaiiiaiiiiaiiiaaaaaiiiaaaiiaaiiiaiiiaiaaaiaiiiiaaiiiaiiaiaiiaiiiaaaia\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100 89\ntjbkmydejporbqhcbztkcumxjjgsrvxpuulbhzeeckkbchpbxwhedrlhjsabcexcohgdzouvsgphjdthpuqrlkgzxvqbuhqxdsmf\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 100\njhpyiuuzizhubhhpxbbhpyxzhbpjphzppuhiahihiappbhuypyauhizpbibzixjbzxzpbphuiaypyujappuxiyuyaajaxjupbahb\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 3\nsszoovvzysavsvzsozzvoozvysozsaszayaszasaysszzzysosyayyvzozovavzoyavsooaoyvoozvvozsaosvayyovazzszzssa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100 44\ndluthkxwnorabqsukgnxnvhmsmzilyulpursnxkdsavgemiuizbyzebhyjejgqrvuckhaqtuvdmpziesmpmewpvozdanjyvwcdgo\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 90\ntljonbnwnqounictqqctgonktiqoqlocgoblngijqokuquoolciqwnctgoggcbojtwjlculoikbggquqncittwnjbkgkgubnioib\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 79\nykxptzgvbqxlregvkvucewtydvnhqhuggdsyqlvcfiuaiddnrrnstityyehiamrggftsqyduwxpuldztyzgmfkehprrneyvtknmf\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 79\naagwekyovbviiqeuakbqbqifwavkfkutoriovgfmittulhwojaptacekdirgqoovlleeoqkkdukpadygfwavppohgdrmymmulgci\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 93\nearrehrehenaddhdnrdddhdahnadndheeennrearrhraharddreaeraddhehhhrdnredanndneheddrraaneerreedhnadnerhdn\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 48\nbmmaebaebmmmbbmxvmammbvvebvaemvbbaxvbvmaxvvmveaxmbbxaaemxmxvxxxvxbmmxaaaevvaxmvamvvmaxaxavexbmmbmmev\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 55\nhsavbkehaaesffaeeffakhkhfehbbvbeasahbbbvkesbfvkefeesesevbsvfkbffakvshsbkahfkfakebsvafkbvsskfhfvaasss\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 2\ncscffcffsccffsfsfffccssfsscfsfsssffcffsscfccssfffcfscfsscsccccfsssffffcfcfsfffcsfsccffscffcfccccfffs\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100 3\nzrgznxgdpgfoiifrrrsjfuhvtqxjlgochhyemismjnanfvvpzzvsgajcbsulxyeoepjfwvhkqogiiwqxjkrpsyaqdlwffoockxnc\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100 5\njbltyyfjakrjeodqepxpkjideulofbhqzxjwlarufwzwsoxhaexpydpqjvhybmvjvntuvhvflokhshpicbnfgsqsmrkrfzcrswwi\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100 1\nfnslnqktlbmxqpvcvnemxcutebdwepoxikifkzaaixzzydffpdxodmsxjribmxuqhueifdlwzytxkklwhljswqvlejedyrgguvah\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100 21\nddjenetwgwmdtjbpzssyoqrtirvoygkjlqhhdcjgeurqpunxpupwaepcqkbjjfhnvgpyqnozhhrmhfwararmlcvpgtnopvjqsrka\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 100\nnjrhiauqlgkkpkuvciwzivjbbplipvhslqgdkfnmqrxuxnycmpheenmnrglotzuyxycosfediqcuadklsnzjqzfxnbjwvfljnlvq\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 100\nbbbbbbbtbbttbtbbbttbttbtbbttttbbbtbttbbbtbttbtbbttttbbbbbtbbttbtbbtbttbbbtbtbtbtbtbtbbbttbbtbtbtbbtb\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "14 5\nfssmmsfffmfmmm\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nff\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nhw\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nss\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 1\nl\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 50\nfffffttttttjjjuuuvvvvvdddxxxxwwwwgggbsssncccczzyyyyyhhhhhkrreeeeeeaaaaaiiillllllllooooqqqqqqmmpppppp\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 50\nbbbbbbbbgggggggggggaaaaaaaahhhhhhhhhhpppppppppsssssssrrrrrrrrllzzzzzzzeeeeeeekkkkkkkwwwwwwwwjjjjjjjj\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 50\nwwwwwwwwwwwwwwxxxxxxxxxxxxxxxxxxxxxxxxzzzzzzzzzzzzzzzzzzbbbbbbbbbbbbbbbbbbbbjjjjjjjjjjjjjjjjjjjjjjjj\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 80\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmmm\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 10\nbbttthhhhiiiiiiijjjjjvvvvpppssssseeeeeeewwwwgggkkkkkkkkmmmddddduuuzzzzllllnnnnnxxyyyffffccraaaaooooq\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 20\nssssssssssbbbbbbbhhhhhhhyyyyyyyzzzzzzzzzzzzcccccxxxxxxxxxxddddmmmmmmmeeeeeeejjjjjjjjjwwwwwwwtttttttt\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 2\na\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 1\nabb\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 1\naa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nab\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 2\naaaaaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8 4\naaaaaaaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 2\naaaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 3\naaaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3\na\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 3\nzzzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 1\naaaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 4\nabc\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 5\nab\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 4\nab\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 10\na\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 2\nzzzzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "53 26\naaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbb\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 1\nabab\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 1\nabcb\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 2\nabbb\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 2\nabccc\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 3\nab\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 3\nbbbs\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 2\nazzzzzzzzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2\nb\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nb\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 5\nabcd\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 6\naabb\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 2\naaaab\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 5\naaa\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 3\nazzzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 100\naabb\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 10\naaa\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 4\naaa\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "12 5\naaaaabbbbbbb\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 2\naabbb\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 5\nzzzzzzzzzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 4\naa\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 5\na\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 5\naaaaaaaaaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 3\naaaaaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7 1\nabcdeee\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "18 3\naaaaaabbbbbbcccccc\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8 2\naabbccdd\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 2\nzzzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 2\nabaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 2\naaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 1\nzzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 4\nzzzzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 2\naabbbc\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 6\naaa\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 3\naaaeeeeeee\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 5\naabb\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 1\naaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 2\naazzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 2\nabbbbc\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 2\nxxxx\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 3\nzzzzzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 2\nabb\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 2\nzzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 5\nzzzzzz\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 3\nbcaaaa\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100 100\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 6\nabc\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/841/A"
} | vfc_10010 |
apps | verifiable_code | 65 | Solve the following coding problem using the programming language python:
You are given an array of n integer numbers a_0, a_1, ..., a_{n} - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times.
-----Input-----
The first line contains positive integer n (2 ≤ n ≤ 10^5) — size of the given array. The second line contains n integers a_0, a_1, ..., a_{n} - 1 (1 ≤ a_{i} ≤ 10^9) — elements of the array. It is guaranteed that in the array a minimum occurs at least two times.
-----Output-----
Print the only number — distance between two nearest minimums in the array.
-----Examples-----
Input
2
3 3
Output
1
Input
3
5 6 5
Output
2
Input
9
2 1 3 5 4 1 2 3 1
Output
3
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n = int(input())
A = [int(x) for x in input().split()]
mn = min(A)
I = [i for i in range(len(A)) if A[i] == mn]
mindiff = min(I[i]-I[i-1] for i in range(1,len(I)))
print(mindiff)
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 6 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9\n2 1 3 5 4 1 2 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\n4 6 7 8 6 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2\n1000000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "42\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n10000000 10000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n100000000 100000001 100000000 100000001 100000000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9\n4 3 4 3 4 1 3 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n10000000 1000000000 10000000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "12\n5 6 6 5 6 1 9 9 9 9 9 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 5 1 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 2 1 3 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1000000000 1000000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n100000005 1000000000 100000005\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 2 2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n10000 1000000 10000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n999999999 999999998 999999998\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 1 1 2 3 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1000000000 900000000 900000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n7 7 2 7 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\n10 10 1 20 20 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2\n999999999 999999999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10\n100000 100000 1 2 3 4 5 6 7 1\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10\n3 3 1 2 2 1 10 10 10 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n900000000 900000001 900000000 900000001 900000001\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 3 2 5 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n100000000 100000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10\n10 15 10 2 54 54 54 54 2 10\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2\n999999 999999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n1000000000 100000000 1000000000 1000000000 100000000\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n10 9 10 9\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 3 2 3 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 2 1 4 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 2 2 2 2 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7\n3 7 6 7 6 7 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "8\n1 2 2 2 2 1 2 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10\n2 2 2 3 3 1 3 3 3 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "2\n88888888 88888888\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n100000000 100000000 100000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10\n1 3 2 4 5 5 4 3 2 1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 2 1 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\n900000005 900000000 900000001 900000000 900000001 900000001\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n41 41 1 41 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\n5 5 1 3 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8\n1 2 2 2 1 2 2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "7\n6 6 6 6 1 8 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n999999999 1000000000 999999999\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 5 4 10 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "11\n2 2 3 4 1 5 3 4 2 5 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 5 4 5 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6\n6 6 6 6 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7\n11 1 3 2 3 1 11\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 3 1 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n4 4 2 5 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n10000099 10000567 10000099 10000234\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n100000009 100000011 100000012 100000009\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2\n1000000 1000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n10000010 10000010\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8\n2 6 2 8 1 9 8 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n7 7 1 8 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7\n1 3 2 3 2 3 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7\n2 3 2 1 3 4 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1000000000 999999999 1000000000 1000000000 999999999\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1000000000 1000000000 1000000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 5 3 5 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 3 3 3 3 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n1000000000 1000000000 100000000 1000000000 100000000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7\n2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8\n2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10\n2 2 2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "11\n2 2 2 2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "12\n2 2 2 2 2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "13\n2 2 2 2 2 2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "14\n2 2 2 2 2 2 2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "15\n2 2 2 2 2 2 2 2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "16\n2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "17\n2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "18\n2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "19\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "20\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1000000000 100000000 100000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "21\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8\n5 5 5 5 3 5 5 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\n2 3 2 1 4 4 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\n3 3 1 2 4 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 3 2 8 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 1 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 1 1 3 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 2 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\n2 1 2 1 1 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9\n200000 500000 500000 500000 200000 500000 500000 500000 500000\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "85\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 1\n",
"output": "84\n",
"type": "stdin_stdout"
},
{
"input": "5\n1000000000 1000000000 999999999 1000000000 999999999\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 1 2 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 3 4 2 4 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9\n2 2 5 1 6 8 7 9 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10\n1000000000 1000000000 1000000000 999999999 1000000000 1000000000 1000000000 1000000000 1000000000 999999999\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7\n3 3 1 2 4 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\n3 3 1 2 3 4 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8\n10 5 10 1 10 10 10 1\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/911/A"
} | vfc_10014 |
apps | verifiable_code | 66 | Solve the following coding problem using the programming language python:
Vector Willman and Array Bolt are the two most famous athletes of Byteforces. They are going to compete in a race with a distance of L meters today.
[Image]
Willman and Bolt have exactly the same speed, so when they compete the result is always a tie. That is a problem for the organizers because they want a winner.
While watching previous races the organizers have noticed that Willman can perform only steps of length equal to w meters, and Bolt can perform only steps of length equal to b meters. Organizers decided to slightly change the rules of the race. Now, at the end of the racetrack there will be an abyss, and the winner will be declared the athlete, who manages to run farther from the starting point of the the racetrack (which is not the subject to change by any of the athletes).
Note that none of the athletes can run infinitely far, as they both will at some moment of time face the point, such that only one step further will cause them to fall in the abyss. In other words, the athlete will not fall into the abyss if the total length of all his steps will be less or equal to the chosen distance L.
Since the organizers are very fair, the are going to set the length of the racetrack as an integer chosen randomly and uniformly in range from 1 to t (both are included). What is the probability that Willman and Bolt tie again today?
-----Input-----
The first line of the input contains three integers t, w and b (1 ≤ t, w, b ≤ 5·10^18) — the maximum possible length of the racetrack, the length of Willman's steps and the length of Bolt's steps respectively.
-----Output-----
Print the answer to the problem as an irreducible fraction [Image]. Follow the format of the samples output.
The fraction [Image] (p and q are integers, and both p ≥ 0 and q > 0 holds) is called irreducible, if there is no such integer d > 1, that both p and q are divisible by d.
-----Examples-----
Input
10 3 2
Output
3/10
Input
7 1 2
Output
3/7
-----Note-----
In the first sample Willman and Bolt will tie in case 1, 6 or 7 are chosen as the length of the racetrack.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
from fractions import gcd
t,w,b = map(int,input().split())
per = w*b//gcd(w,b)
can = (t//per+1)*min(w,b)-1
if t%per<min(w,b):
can-=min(w,b)
can+=t%per+1
g = gcd(can,t)
can//=g
t//=g
print(str(can)+"/"+str(t))
``` | {
"language": "python",
"test_cases": [
{
"input": "10 3 2\n",
"output": "3/10\n",
"type": "stdin_stdout"
},
{
"input": "7 1 2\n",
"output": "3/7\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "5814 31 7\n",
"output": "94/2907\n",
"type": "stdin_stdout"
},
{
"input": "94268 813 766\n",
"output": "765/94268\n",
"type": "stdin_stdout"
},
{
"input": "262610 5583 4717\n",
"output": "2358/131305\n",
"type": "stdin_stdout"
},
{
"input": "3898439 96326 71937\n",
"output": "71936/3898439\n",
"type": "stdin_stdout"
},
{
"input": "257593781689876390 32561717 4411677\n",
"output": "7914548537/257593781689876390\n",
"type": "stdin_stdout"
},
{
"input": "111319886766128339 7862842484895022 3003994959686829\n",
"output": "3003994959686828/111319886766128339\n",
"type": "stdin_stdout"
},
{
"input": "413850294331656955 570110918058849723 409853735661743839\n",
"output": "409853735661743838/413850294331656955\n",
"type": "stdin_stdout"
},
{
"input": "3000000000000000000 2999999999999999873 2999999999999999977\n",
"output": "23437499999999999/23437500000000000\n",
"type": "stdin_stdout"
},
{
"input": "9 6 1\n",
"output": "1/9\n",
"type": "stdin_stdout"
},
{
"input": "32 9 2\n",
"output": "3/32\n",
"type": "stdin_stdout"
},
{
"input": "976 5 6\n",
"output": "41/244\n",
"type": "stdin_stdout"
},
{
"input": "5814 31 7\n",
"output": "94/2907\n",
"type": "stdin_stdout"
},
{
"input": "94268 714 345\n",
"output": "689/94268\n",
"type": "stdin_stdout"
},
{
"input": "262610 5583 4717\n",
"output": "2358/131305\n",
"type": "stdin_stdout"
},
{
"input": "3898439 96326 71937\n",
"output": "71936/3898439\n",
"type": "stdin_stdout"
},
{
"input": "54682301 778668 253103\n",
"output": "253102/54682301\n",
"type": "stdin_stdout"
},
{
"input": "329245015 1173508 8918834\n",
"output": "1173507/329245015\n",
"type": "stdin_stdout"
},
{
"input": "321076647734423976 7 7\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "455227494055672047 92 28\n",
"output": "19792499741550983/455227494055672047\n",
"type": "stdin_stdout"
},
{
"input": "595779167455745259 6954 8697\n",
"output": "205511958419723/595779167455745259\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000 2000000000\n",
"output": "1/2\n",
"type": "stdin_stdout"
},
{
"input": "462643382718281828 462643382718281507 462643382718281701\n",
"output": "33045955908448679/33045955908448702\n",
"type": "stdin_stdout"
},
{
"input": "4000000000000000000 9999999999999997 99999999999999999\n",
"output": "2499999999999999/1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "4003000100004000000 9999999099999999 99999999999999999\n",
"output": "4999999549999999/2001500050002000000\n",
"type": "stdin_stdout"
},
{
"input": "4903000100004000000 58997960959949999 99933992929999999\n",
"output": "29498980479974999/2451500050002000000\n",
"type": "stdin_stdout"
},
{
"input": "257593781689876390 32561717 4411677\n",
"output": "7914548537/257593781689876390\n",
"type": "stdin_stdout"
},
{
"input": "111319886766128339 7862842484895022 3003994959686829\n",
"output": "3003994959686828/111319886766128339\n",
"type": "stdin_stdout"
},
{
"input": "413850294331656955 570110918058849723 409853735661743839\n",
"output": "409853735661743838/413850294331656955\n",
"type": "stdin_stdout"
},
{
"input": "232 17 83\n",
"output": "2/29\n",
"type": "stdin_stdout"
},
{
"input": "5496272 63 200\n",
"output": "13765/2748136\n",
"type": "stdin_stdout"
},
{
"input": "180 174 53\n",
"output": "13/45\n",
"type": "stdin_stdout"
},
{
"input": "1954 190 537\n",
"output": "189/1954\n",
"type": "stdin_stdout"
},
{
"input": "146752429 510 514\n",
"output": "571199/146752429\n",
"type": "stdin_stdout"
},
{
"input": "579312860 55 70\n",
"output": "10344881/144828215\n",
"type": "stdin_stdout"
},
{
"input": "1 9 9\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "95 19 19\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "404 63 441\n",
"output": "31/202\n",
"type": "stdin_stdout"
},
{
"input": "5566 4798 4798\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "118289676 570846883 570846883\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "763 358 358\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "85356138 7223 482120804\n",
"output": "3611/42678069\n",
"type": "stdin_stdout"
},
{
"input": "674664088 435395270 5\n",
"output": "9/674664088\n",
"type": "stdin_stdout"
},
{
"input": "762200126044291557 370330636048898430 6\n",
"output": "17/762200126044291557\n",
"type": "stdin_stdout"
},
{
"input": "917148533938841535 47 344459175789842163\n",
"output": "28/183429706787768307\n",
"type": "stdin_stdout"
},
{
"input": "360212127113008697 877228952036215545 5259\n",
"output": "5258/360212127113008697\n",
"type": "stdin_stdout"
},
{
"input": "683705963104411677 89876390 116741460012229240\n",
"output": "539258339/683705963104411677\n",
"type": "stdin_stdout"
},
{
"input": "573003994959686829 275856334120822851 1319886766128339\n",
"output": "3959660298385016/573003994959686829\n",
"type": "stdin_stdout"
},
{
"input": "409853735661743839 413850294331656955 413850294331656955\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "19 1 19\n",
"output": "1/19\n",
"type": "stdin_stdout"
},
{
"input": "576 18 32\n",
"output": "1/16\n",
"type": "stdin_stdout"
},
{
"input": "9540 10 954\n",
"output": "1/477\n",
"type": "stdin_stdout"
},
{
"input": "101997840 6 16999640\n",
"output": "1/8499820\n",
"type": "stdin_stdout"
},
{
"input": "955944 1278 748\n",
"output": "1/639\n",
"type": "stdin_stdout"
},
{
"input": "482120804 66748 7223\n",
"output": "1/66748\n",
"type": "stdin_stdout"
},
{
"input": "370330636048898430 61721772674816405 6\n",
"output": "1/61721772674816405\n",
"type": "stdin_stdout"
},
{
"input": "344459175789842163 7328918633826429 47\n",
"output": "1/7328918633826429\n",
"type": "stdin_stdout"
},
{
"input": "877228952036215545 166805277055755 5259\n",
"output": "1/55601759018585\n",
"type": "stdin_stdout"
},
{
"input": "116741460012229240 1298911316 89876390\n",
"output": "1/649455658\n",
"type": "stdin_stdout"
},
{
"input": "275856334120822851 209 1319886766128339\n",
"output": "1/1319886766128339\n",
"type": "stdin_stdout"
},
{
"input": "413850294331656955 1 413850294331656955\n",
"output": "1/413850294331656955\n",
"type": "stdin_stdout"
},
{
"input": "54682301 778668 253103\n",
"output": "253102/54682301\n",
"type": "stdin_stdout"
},
{
"input": "329245015 3931027 6443236\n",
"output": "357366/29931365\n",
"type": "stdin_stdout"
},
{
"input": "321076647734423976 7 8\n",
"output": "1672274206950125/13378193655600999\n",
"type": "stdin_stdout"
},
{
"input": "455227494055672047 71 60\n",
"output": "6411654845854559/455227494055672047\n",
"type": "stdin_stdout"
},
{
"input": "595779167455745259 9741 9331\n",
"output": "61162012885196/595779167455745259\n",
"type": "stdin_stdout"
},
{
"input": "6470 80 160\n",
"output": "327/647\n",
"type": "stdin_stdout"
},
{
"input": "686325 828 1656\n",
"output": "114511/228775\n",
"type": "stdin_stdout"
},
{
"input": "4535304 2129 4258\n",
"output": "755973/1511768\n",
"type": "stdin_stdout"
},
{
"input": "40525189 6365 12730\n",
"output": "20265394/40525189\n",
"type": "stdin_stdout"
},
{
"input": "675297075 25986 51972\n",
"output": "112553659/225099025\n",
"type": "stdin_stdout"
},
{
"input": "5681598412 75376 226128\n",
"output": "1893897375/5681598412\n",
"type": "stdin_stdout"
},
{
"input": "384118571739435733 619773000 1859319000\n",
"output": "128039524053435733/384118571739435733\n",
"type": "stdin_stdout"
},
{
"input": "391554751752251913 625743359 1877230077\n",
"output": "130518250652782079/391554751752251913\n",
"type": "stdin_stdout"
},
{
"input": "390728504279201198 625082797 1250165594\n",
"output": "195364252413988195/390728504279201198\n",
"type": "stdin_stdout"
},
{
"input": "389902265396085075 624421544 1248843088\n",
"output": "64983710976697837/129967421798695025\n",
"type": "stdin_stdout"
},
{
"input": "734812071040507372 857211800 2571635400\n",
"output": "61234339274051543/183703017760126843\n",
"type": "stdin_stdout"
},
{
"input": "1 1 2\n",
"output": "0/1\n",
"type": "stdin_stdout"
},
{
"input": "3 1 4\n",
"output": "0/1\n",
"type": "stdin_stdout"
},
{
"input": "8 2 3\n",
"output": "3/8\n",
"type": "stdin_stdout"
},
{
"input": "64 32 16\n",
"output": "1/2\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1000000000\n",
"output": "0/1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 1\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 1000000000\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 2 4\n",
"output": "1/2\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 123 456\n",
"output": "6579023/1000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 123123 654\n",
"output": "24851/1000000000\n",
"type": "stdin_stdout"
},
{
"input": "123456 123 456\n",
"output": "215/30864\n",
"type": "stdin_stdout"
},
{
"input": "123456 1234567 123\n",
"output": "61/61728\n",
"type": "stdin_stdout"
},
{
"input": "314159265 271 8281\n",
"output": "37939/314159265\n",
"type": "stdin_stdout"
},
{
"input": "11071994 4231 1324\n",
"output": "2647/11071994\n",
"type": "stdin_stdout"
},
{
"input": "961748927 961748941 982451653\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "15485221 1259 90863\n",
"output": "1258/15485221\n",
"type": "stdin_stdout"
},
{
"input": "5000000000000000000 4999999999999999837 4999999999999999963\n",
"output": "1249999999999999959/1250000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "4000000000000000000 3999999999999999691 3999999999999999887\n",
"output": "399999999999999969/400000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999 999999999999999709 999999999999999737\n",
"output": "333333333333333236/333333333333333333\n",
"type": "stdin_stdout"
},
{
"input": "799999999999999999 799999999999999969 799999999999999991\n",
"output": "799999999999999968/799999999999999999\n",
"type": "stdin_stdout"
},
{
"input": "812312312312312222 812312312312311897 812312312312312029\n",
"output": "406156156156155948/406156156156156111\n",
"type": "stdin_stdout"
},
{
"input": "500000000000000000 499999999999999927 499999999999999931\n",
"output": "249999999999999963/250000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "555555555555555555 555555555555555083 555555555555555229\n",
"output": "50505050505050462/50505050505050505\n",
"type": "stdin_stdout"
},
{
"input": "199419941994199419 199419941994199369 199419941994199391\n",
"output": "66473313998066456/66473313998066473\n",
"type": "stdin_stdout"
},
{
"input": "145685485411238588 145685485411238483 145685485411238573\n",
"output": "72842742705619241/72842742705619294\n",
"type": "stdin_stdout"
},
{
"input": "314159265358979323 314159265358979167 314159265358979213\n",
"output": "314159265358979166/314159265358979323\n",
"type": "stdin_stdout"
},
{
"input": "10 1000000000000000000 1000000000000000001\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "5 100000000000000000 99999999999999999\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "5 1000000000000 1000000000001\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "5 1000000000000000000 1000000000000000001\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "2 1000000000000000000 1000000000000000001\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "2 10 11\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "10 123456789123456789 723456789123456781\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "12345678910 123456789101112131 123456789101112132\n",
"output": "1/1\n",
"type": "stdin_stdout"
},
{
"input": "5 499999999999999999 499999999999999998\n",
"output": "1/1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/592/C"
} | vfc_10018 |
apps | verifiable_code | 67 | Solve the following coding problem using the programming language python:
Nauuo is a girl who loves writing comments.
One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes.
It's known that there were $x$ persons who would upvote, $y$ persons who would downvote, and there were also another $z$ persons who would vote, but you don't know whether they would upvote or downvote. Note that each of the $x+y+z$ people would vote exactly one time.
There are three different results: if there are more people upvote than downvote, the result will be "+"; if there are more people downvote than upvote, the result will be "-"; otherwise the result will be "0".
Because of the $z$ unknown persons, the result may be uncertain (i.e. there are more than one possible results). More formally, the result is uncertain if and only if there exist two different situations of how the $z$ persons vote, that the results are different in the two situations.
Tell Nauuo the result or report that the result is uncertain.
-----Input-----
The only line contains three integers $x$, $y$, $z$ ($0\le x,y,z\le100$), corresponding to the number of persons who would upvote, downvote or unknown.
-----Output-----
If there is only one possible result, print the result : "+", "-" or "0".
Otherwise, print "?" to report that the result is uncertain.
-----Examples-----
Input
3 7 0
Output
-
Input
2 0 1
Output
+
Input
1 1 0
Output
0
Input
0 0 1
Output
?
-----Note-----
In the first example, Nauuo would definitely get three upvotes and seven downvotes, so the only possible result is "-".
In the second example, no matter the person unknown downvotes or upvotes, Nauuo would get more upvotes than downvotes. So the only possible result is "+".
In the third example, Nauuo would definitely get one upvote and one downvote, so the only possible result is "0".
In the fourth example, if the only one person upvoted, the result would be "+", otherwise, the result would be "-". There are two possible results, so the result is uncertain.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x, y, z = map(int, input().split())
if z == 0:
if x == y:
print('0')
elif x > y:
print('+')
else:
print('-')
else:
if x > y + z:
print('+')
elif x + z < y:
print('-')
else:
print('?')
``` | {
"language": "python",
"test_cases": [
{
"input": "3 7 0\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "2 0 1\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "1 1 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "0 0 1\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "12 1 11\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "22 99 77\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "28 99 70\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "73 29 43\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "100 100 100\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "1 0 1\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "5 7 1\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "13 6 8\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "94 37 25\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "45 0 44\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "62 56 5\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "88 88 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "0 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "0 100 0\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "0 0 100\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "100 0 100\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "100 100 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "50 100 50\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "100 50 50\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "48 100 48\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "100 48 48\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "0 100 48\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "100 0 48\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "0 100 99\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "100 0 99\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "96 55 0\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "21 50 0\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "86 1 0\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "58 58 1\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "12 89 2\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "34 51 3\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "93 21 2\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "97 78 2\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "19 90 4\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "21 52 5\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "42 40 4\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "58 97 4\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "26 92 6\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "8 87 7\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "49 8 6\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "97 64 6\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "43 93 9\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "21 55 9\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "66 27 9\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "58 83 8\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "52 14 10\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "2 87 10\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "80 29 11\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "92 93 10\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "62 63 12\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "33 24 13\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "79 42 12\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "98 82 13\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "60 33 15\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "37 5 15\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "21 31 14\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "78 95 14\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "2 82 17\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "42 43 16\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "98 44 17\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "82 84 16\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "80 63 18\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "21 24 18\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "97 33 19\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "87 98 19\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "99 20 7\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "47 78 6\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "47 40 10\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "96 71 19\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "25 35 23\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "36 3 35\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "74 2 16\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "58 83 39\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "40 51 11\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "0 87 13\n",
"output": "-",
"type": "stdin_stdout"
},
{
"input": "89 41 36\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "97 71 36\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "34 44 21\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "13 1 13\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "83 3 8\n",
"output": "+",
"type": "stdin_stdout"
},
{
"input": "60 60 32\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "25 39 32\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "46 1 89\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "43 9 61\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "82 98 93\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "2 2 1\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "10 5 6\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "9 8 2\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "5 3 3\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "8 5 5\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "5 3 2\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "1 50 50\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "3 2 3\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "1 3 4\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "1 2 2\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "7 4 3\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "7 3 5\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "5 1 6\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "3 4 5\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "25 12 100\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "3 3 2\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "5 2 10\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "7 4 4\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "4 3 1\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "5 5 3\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "2 1 3\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "1 2 7\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "6 5 4\n",
"output": "?",
"type": "stdin_stdout"
},
{
"input": "15 4 15\n",
"output": "?",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1173/A"
} | vfc_10022 |
apps | verifiable_code | 68 | Solve the following coding problem using the programming language python:
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U — move from $(x, y)$ to $(x, y + 1)$; D — move from $(x, y)$ to $(x, y - 1)$; L — move from $(x, y)$ to $(x - 1, y)$; R — move from $(x, y)$ to $(x + 1, y)$.
Vasya also has got a sequence of $n$ operations. Vasya wants to modify this sequence so after performing it the robot will end up in $(x, y)$.
Vasya wants to change the sequence so the length of changed subsegment is minimum possible. This length can be calculated as follows: $maxID - minID + 1$, where $maxID$ is the maximum index of a changed operation, and $minID$ is the minimum index of a changed operation. For example, if Vasya changes RRRRRRR to RLRRLRL, then the operations with indices $2$, $5$ and $7$ are changed, so the length of changed subsegment is $7 - 2 + 1 = 6$. Another example: if Vasya changes DDDD to DDRD, then the length of changed subsegment is $1$.
If there are no changes, then the length of changed subsegment is $0$. Changing an operation means replacing it with some operation (possibly the same); Vasya can't insert new operations into the sequence or remove them.
Help Vasya! Tell him the minimum length of subsegment that he needs to change so that the robot will go from $(0, 0)$ to $(x, y)$, or tell him that it's impossible.
-----Input-----
The first line contains one integer number $n~(1 \le n \le 2 \cdot 10^5)$ — the number of operations.
The second line contains the sequence of operations — a string of $n$ characters. Each character is either U, D, L or R.
The third line contains two integers $x, y~(-10^9 \le x, y \le 10^9)$ — the coordinates of the cell where the robot should end its path.
-----Output-----
Print one integer — the minimum possible length of subsegment that can be changed so the resulting sequence of operations moves the robot from $(0, 0)$ to $(x, y)$. If this change is impossible, print $-1$.
-----Examples-----
Input
5
RURUU
-2 3
Output
3
Input
4
RULR
1 1
Output
0
Input
3
UUU
100 100
Output
-1
-----Note-----
In the first example the sequence can be changed to LULUU. So the length of the changed subsegment is $3 - 1 + 1 = 3$.
In the second example the given sequence already leads the robot to $(x, y)$, so the length of the changed subsegment is $0$.
In the third example the robot can't end his path in the cell $(x, y)$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
#
import collections, atexit, math, sys, bisect
sys.setrecursionlimit(1000000)
def getIntList():
return list(map(int, input().split()))
try :
#raise ModuleNotFoundError
import numpy
def dprint(*args, **kwargs):
print(*args, **kwargs, file=sys.stderr)
dprint('debug mode')
except Exception:
def dprint(*args, **kwargs):
pass
inId = 0
outId = 0
if inId>0:
dprint('use input', inId)
sys.stdin = open('input'+ str(inId) + '.txt', 'r') #标准输出重定向至文件
if outId>0:
dprint('use output', outId)
sys.stdout = open('stdout'+ str(outId) + '.txt', 'w') #标准输出重定向至文件
atexit.register(lambda :sys.stdout.close()) #idle 中不会执行 atexit
N, = getIntList()
#print(N)
S = input()
X, Y = getIntList()
dd = ( (0,1), (0,-1), (-1,0), (1,0))
pp = 'UDLR'
zz = {}
for i in range(4):
zz[ pp[i]] = dd[i]
if abs(X) + abs(Y) >N:
print(-1)
return
if abs(X+Y-N)%2==1:
print(-1)
return
fromLeft = [None for i in range(N)]
fromRight = fromLeft.copy()
x0 = 0
y0 = 0
for i in range(N):
x = S[i]
fromLeft[i] = (x0,y0)
g = zz[x]
x0+= g[0]
y0+= g[1]
if x0==X and y0==Y:
print(0)
return
x0 = 0
y0 = 0
for i in range(N-1,-1,-1):
x = S[i]
fromRight[i] = (x0,y0)
g = zz[x]
x0+= g[0]
y0+= g[1]
up = N
down = 0
dprint(fromLeft)
dprint(fromRight)
while down+1<up:
mid = (up+down)//2
dprint('mid', mid)
ok = False
for i in range(N-mid + 1):
tx = fromLeft[i][0] + fromRight[i+mid-1][0]
ty = fromLeft[i][1] + fromRight[i+mid-1][1]
gg = abs(X-tx) + abs(Y- ty)
if gg <= mid:
ok = True
break
if ok:
up = mid
else:
down = mid
print(up)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\nRURUU\n-2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\nRULR\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3\nUUU\n100 100\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6\nUDUDUD\n0 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "100\nURDLDDLLDDLDDDRRLLRRRLULLRRLUDUUDUULURRRDRRLLDRLLUUDLDRDLDDLDLLLULRURRUUDDLDRULRDRUDDDDDDULRDDRLRDDL\n-59 -1\n",
"output": "58\n",
"type": "stdin_stdout"
},
{
"input": "8\nUUULLLUU\n-3 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9\nUULUURRUU\n6379095 -4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5\nDUUUD\n2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2\nUD\n2 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\nLRLRL\n-3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\nRRRR\n-6 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\nR\n0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\nU\n0 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "14\nRULDRULDRULDRR\n2 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2\nUU\n-4 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\nLRU\n0 -1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\nDRRD\n1 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8\nUUUUDDDD\n5 -5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\nR\n1 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3\nUUU\n-1 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "28\nDLUURUDLURRDLDRDLLUDDULDRLDD\n-12 -2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1\nR\n0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "20\nRDURLUUUUUULRLUUURLL\n8 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10\nURLRLURLRL\n0 -2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "16\nLRLRLRLRLRLRLRLR\n0 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "20\nRLRDDRDRUDURRUDDULDL\n8 6\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "52\nRUUUDDRULRRDUDLLRLLLDDULRDULLULUURURDRLDDRLUURLUUDDD\n1 47\n",
"output": "46\n",
"type": "stdin_stdout"
},
{
"input": "2\nUD\n-2 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\nLL\n1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\nU\n-1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "83\nDDLRDURDDDURDURLRRRUDLLDDRLLLDDRLULRLDRRULDDRRUUDLRUUUDLLLUUDURLLRLULDRRDDRRDDURLDR\n4 -5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\nULDRLU\n-1 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "38\nUDDURLDURUUULDLRLRLURURRUUDURRDRUURULR\n-3 3\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "2\nRL\n-2 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\nU\n0 -1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4\nLRUD\n2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "67\nRDLLULDLDLDDLDDLDRULDLULLULURLURRLULLLRULLRDRRDLRLURDRLRRLLUURURLUR\n6 -5\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "62\nLURLLRULDUDLDRRRRDDRLUDRUDRRURDLDRRULDULDULRLRRLDUURUUURDDLRRU\n6 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "22\nDUDDDRUDULDRRRDLURRUUR\n-2 -2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "386\nRUDLURLUURDDLLLRLDURLRRDLDUUURLLRDLRRDLDRLDDURDURURDRLUULLDUULRULDLLLLDLUURRLRRRUDULRDDRDLDULRLDDRDDRLRLDLDULLULUDULLLDUUDURURDDLDRLUDDDDLDUDUURLUUDURRUDRLUDRLULLRLRRDLULDRRURUULLRDLDRLURDUDRLDLRLLUURLURDUUDRDURUDDLLDURURLLRRULURULRRLDLDRLLUUURURDRRRLRDRURULUDURRLRLDRUDLRRRRLLRURDUUDLLLLURDLRLRRDLDLLLDUUDDURRLLDDDDDULURLUDLRRURUUURLRRDLLDRDLDUDDDULLDDDRURRDUUDDDUURLDRRDLRLLRUUULLUDLR\n-2993 495\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3\nUUU\n-1 -2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "41\nRRDDRUDRURLDRRRLLDLDULRUDDDRRULDRLLDUULDD\n-4 -1\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "25\nURRDDULRDDURUDLDUDURUDDDL\n1 -2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\nDUU\n-1 -2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "31\nRRDLDRUUUDRULDDDRURRULRLULDULRD\n0 -1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\nLDUR\n0 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "43\nDRURRUDUUDLLURUDURDDDUDRDLUDURRDRRDLRLURUDU\n-1 5\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "13\nUDLUUDUULDDLR\n0 -1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\nLRLRD\n-1 -2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "55\nLLULRLURRRURRLDDUURLRRRDURUDRLDDRRRDURDUDLUDLLLDDLUDDUD\n5 -4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "11\nULDRRRURRLR\n0 -1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "40\nDRURDRUDRUDUDDURRLLDRDDUUUULLLRDDUDULRUR\n-4 0\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "85\nURDDUUURDLURUDDRUDURUDDURUDLRDLLURDLDDLUDRDLDDLLRLUDLLRURUDULDURUDDRRUDULDLDUDLDDRDRL\n1 -8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\nRRR\n1 -2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "61\nDLUDLUDLUULDLDRDUDLLRULLULURLUDULDURDRLLLRLURDUURUUDLLLRDRLDU\n-3 -4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "60\nLLDDDULDLDRUULRLLLLLDURUDUDRDRUDLLRDDDRRRDRRLUDDDRRRDDLDLULL\n-4 0\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "93\nDDRDRDUDRULDLDRDLLLUUDLULRLLDURRRURRLDRDDLDRLLLURLDDLLRURUDDRLULLLDUDDDRDLRURDDURDRURRUUULRDD\n-4 -1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "27\nRLUUDUDDRRULRDDULDULRLDLDRL\n0 -3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "86\nUDDURDUULURDUUUDDDLRLDRUDDUURDRRUUDUURRRLDRLLUUURDRRULDDDRLRRDLLDRLDLULDDULDLDLDDUULLR\n10 -2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3\nLLD\n-2 -1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "55\nURRDRLLDRURDLRRRDRLRUURLRDRULURLULRURDULLDDDUUULLDRLLUD\n-6 -3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "4\nLURR\n0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "60\nDULDLRLLUULLURUDLDURRDDLDRUUUULRRRDLUDURULRDDLRRDLLRUUURLRDR\n-4 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\nU\n0 0\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "34\nDDRRURLDDULULLUDDLDRDUDDULDURRLRLR\n1 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "30\nLLUDLRLUULDLURURUDURDUDUDLUDRR\n3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "34\nLDRUDLRLULDLUDRUUUDUURDULLURRUULRD\n-4 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "31\nRDLRLRLDUURURRDLULDLULUULURRDLU\n-1 -2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "60\nDLURDLRDDURRLLLUULDRDLLDRDDUURURRURDLLRUDULRRURULDUDULRURLUU\n5 -5\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "27\nLRLULRDURDLRDRDURRRDDRRULLU\n-2 -1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "75\nRDLLLURRDUDUDLLRURURDRRLUULDRLLULDUDDUUULRRRDLDDLULURDRLURRDRDDRURDRLRRLRUU\n0 -3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "15\nUDLUULRLUULLUUR\n-1 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "29\nRRUULRLRUUUDLDRLDUUDLRDUDLLLU\n-3 -2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "49\nLDDURLLLDLRDLRLDURLRDDLDRRRULLDDUULRURDUDUULLLLDD\n2 -1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "65\nULRUDDLDULLLUDLRLDUUULLDRLRUDLDDRLLDLRRDRDRRUUUULDLRLRDDLULRDRDRD\n-3 -2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "93\nLRRDULLDDULUDRLRRLLRDDDLRUUURLRUULDDDUDLLDRUDDDRDDLDLRRRRDLRULRUDLLLRDDRUUUDRUUDULRLRURRRRLUL\n-9 -2\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "48\nRLDRRRDLRRRRRLDLDLLLLLDLLDRLRLDRRLDDUUUDULDDLLDU\n-5 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "60\nLDUDUDRRLRUULLDRUURRRDULUUULUDRDLUDLLLLDUDLRRLRLLURDDDUDDDRU\n3 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "77\nDDURRDLDURUDDDLLRULRURRULRULLULRRLLRUULLULRRLDULRRDURUURRLDDLUDURLLURDULDUDUD\n6 -7\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "15\nDURRULRRULRLRDD\n0 -1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\nULLUUD\n-3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "53\nULULLRULUDRDRDDDULDUDDRULRURLLRLDRRRDDUDUDLLULLLDDDLD\n1 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "67\nDLULDRUURDLURRRRDDLRDRUDDUDRDRDRLDRDDDLURRDDURRDUDURRDRDLURRUUDULRL\n-8 -1\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "77\nLRRUDLDUDRDRURURURLDLLURLULDDURUDUUDDUDLLDULRLRLRRRRULLRRRDURRDLUDULRUURRLDLU\n-6 -7\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "75\nRDRDRDDDRRLLRDRRLRLDRLULLRDUUDRULRRRDLLDUUULRRRULUDLLDRRUUURUUUUDUULLDRRUDL\n-6 -7\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "70\nRDDULUDRDUDRDLRUDUDRUUUDLLLRDUUDLLURUDRLLLRUUDUDUDRURUDRRRLLUDLDRDRDDD\n8 6\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "13\nUUULRUDDRLUUD\n13 -10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "17\nURURDULULDDDDLDLR\n-1 -8\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "13\nRRLUURUUDUUDL\n0 -1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "35\nDLUDLDUUULLRLRDURDLLRUUUULUDUUDLDUR\n-3 -4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "17\nLLRDURLURLRDLULRR\n2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\nDDD\n-1 -2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\nLUD\n-2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "18\nDRULLLLLLRDULLULRR\n-5 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "7\nLRRDRDD\n2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "15\nDLLLULDLDUURDDL\n-1 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "84\nUDRDDDRLRRRRDLLDLUULLRLRUDLRLDRDURLRDDDDDUULRRUURDLLDRRRUUUULLRDLDDDRRUDUUUDDLLLULUD\n2 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "65\nULLLLUDUDUUURRURLDRDLULRRDLLDDLRRDRURLDLLUDULLLDUDLLLULURDRLLULLL\n-4 -7\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "69\nUDUDLDUURLLUURRLDLRLDDDRRUUDULRULRDLRRLURLDLLRLURUDDURRDLDURUULDLLUDR\n-3 -4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "24\nURURUDDULLDUURLDLUUUUDRR\n-2 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "35\nDDLUDDLDLDRURLRUDRRRLLRRLURLLURDDRD\n1 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "88\nLRLULDLDLRDLRULRRDURUULUDDDURRDLLLDDUUULLLRDLLLDRDDDURDUURURDDLLDURRLRDRLUULUDDLLLDLRLUU\n7 -3\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "2\nDD\n0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "69\nLLRLLRLDLDLURLDRUUUULRDLLLURURUDLURDURRDRDRUUDUULRDLDRURLDUURRDRRULDL\n0 -3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8\nDDDRULDU\n4 0\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3\nRLR\n-3 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "45\nDUDDURRUDUDRLRLULRUDUDLRULRDDDRUDRLRUDUURDULL\n-2 -1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\nLUDDRRU\n5 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "97\nRRRUUULULRRLDDULLDRRRLRUDDDLDRLLULDUDUDLRUDRURDLUURDRDDDUULUDRRLDDRULURULRLDRDRDULUUUDULLDDLLDDDL\n12 9\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "1\nL\n0 -1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\nU\n1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "83\nLDRRLDRDUUURRRRULURRLLULDDULRRRRDDRUDRDRDDLDLDRLRULURDDLRRLRURURDURRRLULDRRDULRURUU\n8 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "16\nURRULDRLLUUDLULU\n-9 7\n",
"output": "11\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1073/C"
} | vfc_10026 |
apps | verifiable_code | 69 | Solve the following coding problem using the programming language python:
You are given string $s$ of length $n$ consisting of 0-s and 1-s. You build an infinite string $t$ as a concatenation of an infinite number of strings $s$, or $t = ssss \dots$ For example, if $s =$ 10010, then $t =$ 100101001010010...
Calculate the number of prefixes of $t$ with balance equal to $x$. The balance of some string $q$ is equal to $cnt_{0, q} - cnt_{1, q}$, where $cnt_{0, q}$ is the number of occurrences of 0 in $q$, and $cnt_{1, q}$ is the number of occurrences of 1 in $q$. The number of such prefixes can be infinite; if it is so, you must say that.
A prefix is a string consisting of several first letters of a given string, without any reorders. An empty prefix is also a valid prefix. For example, the string "abcd" has 5 prefixes: empty string, "a", "ab", "abc" and "abcd".
-----Input-----
The first line contains the single integer $T$ ($1 \le T \le 100$) — the number of test cases.
Next $2T$ lines contain descriptions of test cases — two lines per test case. The first line contains two integers $n$ and $x$ ($1 \le n \le 10^5$, $-10^9 \le x \le 10^9$) — the length of string $s$ and the desired balance, respectively.
The second line contains the binary string $s$ ($|s| = n$, $s_i \in \{\text{0}, \text{1}\}$).
It's guaranteed that the total sum of $n$ doesn't exceed $10^5$.
-----Output-----
Print $T$ integers — one per test case. For each test case print the number of prefixes or $-1$ if there is an infinite number of such prefixes.
-----Example-----
Input
4
6 10
010010
5 3
10101
1 0
0
2 0
01
Output
3
0
1
-1
-----Note-----
In the first test case, there are 3 good prefixes of $t$: with length $28$, $30$ and $32$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t=int(input())
for i in ' '*t:
n,x=map(int,input().split())
s=input()
L=[0]
for i in s:
if i=='0':L.append(L[-1]+1)
else:L.append(L[-1]-1)
L.pop(0)
k=L[-1]
c=0
if x==0:c+=1
if k>0:
for i in L:
if i%k==x%k and i<=x:c+=1
print(c)
elif k<0:
for i in L:
if i%k==x%k and i>=x:c+=1
print(c)
else:
for i in L:
if i==x:c=-1
print(c)
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n6 10\n010010\n5 3\n10101\n1 0\n0\n2 0\n01\n",
"output": "3\n0\n1\n-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 -548706795\n0\n1 -735838406\n1\n",
"output": "0\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 5\n00000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "19\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n1 1\n1\n",
"output": "0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 0\n011\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n20 6\n00000000000111111111\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1\n11 3\n00000111111\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 0\n101\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 -2\n1110000\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 0\n10010\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 -2\n111100\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n9 0\n000111010\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n5 1\n01010\n5 3\n00010\n15 0\n010101010010101\n10 0\n0000011111\n",
"output": "5\n2\n5\n-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 1\n00011\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 0\n111111\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 -1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 1\n10010\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1\n9 -1\n011110001\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 1\n011\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 0\n01010\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n9 5\n000001111\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 0\n01010\n3 1\n101\n",
"output": "3\n0\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 -2\n11000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n201 1\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000011111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n",
"output": "199\n",
"type": "stdin_stdout"
},
{
"input": "2\n8 -3\n11100000\n2 2\n00\n",
"output": "1\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 0\n1010110\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 -1\n100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 0\n001111\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n00\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 0\n010\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1\n0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 0\n0001111\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "4\n6 10\n010010\n5 3\n10101\n5 0\n11000\n2 0\n01\n",
"output": "3\n0\n5\n-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 -1\n11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 2\n00101\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 4\n000001\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n10 2\n1010101000\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 0\n00111\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 1\n00111\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 1\n010\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n8 0\n00011100\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 0\n10101\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 -3\n111001\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n9 0\n000111010\n15 5\n011010101100000\n11 0\n01010000010\n11 -5\n00010100010\n",
"output": "3\n6\n3\n0\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 0\n11000\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 0\n1110\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 -1\n111111\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 0\n01010\n2 1\n11\n",
"output": "3\n0\n",
"type": "stdin_stdout"
},
{
"input": "6\n9 0\n000111010\n15 5\n011010101100000\n11 0\n01010000010\n11 -5\n00010100010\n11 5\n00101000100\n11 4\n01010000010\n",
"output": "3\n6\n3\n0\n1\n2\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 2\n0110101\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 0\n100\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 1\n100001\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 -1\n11010\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n9 0\n010101011\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 -1\n10101\n9 -1\n011110001\n",
"output": "5\n6\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 2\n0011\n3 -1\n101\n2 0\n01\n5 5\n00000\n",
"output": "-1\n3\n-1\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 -2\n101\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\n9 0\n000111010\n15 5\n011010101100000\n11 0\n01010000010\n11 -5\n00010100010\n11 5\n00101000100\n11 4\n01010000010\n17 -3\n01011111110100000\n",
"output": "3\n6\n3\n0\n1\n2\n10\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 2\n001001\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n8 0\n01010111\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8\n9 0\n000111010\n15 5\n011010101100000\n11 0\n01010000010\n11 -5\n00010100010\n11 5\n00101000100\n11 4\n01010000010\n17 -3\n01011111110100000\n17 -17\n01011111110100000\n",
"output": "3\n6\n3\n0\n1\n2\n10\n17\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 -2\n11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 -1\n10011\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 -1\n10101\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 2\n110000\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 -3\n11111\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 -2\n11110\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 1\n011\n6 1\n100001\n6 3\n100001\n",
"output": "1\n2\n3\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 0\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8\n9 0\n000111010\n15 5\n111010101100001\n11 0\n01010000010\n11 -5\n00010100010\n11 5\n00101000100\n11 4\n01010000010\n17 -4\n01011101110100000\n17 -1\n00010101010101001\n",
"output": "3\n0\n3\n0\n1\n2\n2\n0\n",
"type": "stdin_stdout"
},
{
"input": "8\n9 0\n000111010\n17 0\n10100010100000000\n11 0\n01010000010\n15 5\n111010101100001\n11 -5\n00010100010\n11 5\n00101000100\n11 4\n01010000010\n17 0\n01011101110100000\n",
"output": "3\n3\n3\n0\n0\n1\n2\n15\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 1\n000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 0\n111\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 2\n001\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 2\n001111\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n9 -1\n011110001\n5 5\n00000\n",
"output": "6\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n9 6\n000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8\n9 0\n000111010\n17 0\n10100010100000000\n11 0\n01010000010\n15 5\n111010101100001\n11 -5\n00010100010\n11 5\n00101000100\n11 4\n01010000010\n17 0\n10000010010010100\n",
"output": "3\n3\n3\n0\n0\n1\n2\n2\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 0\n001100\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 0\n00111\n5 0\n11000\n",
"output": "5\n5\n",
"type": "stdin_stdout"
},
{
"input": "1\n8 0\n00011111\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8\n9 0\n000111010\n17 0\n10100010100000000\n11 0\n01010000010\n15 5\n111010101100001\n11 -5\n00010100010\n11 5\n00101000100\n11 4\n01010000010\n18 0\n010110101001010101\n",
"output": "3\n3\n3\n0\n0\n1\n2\n-1\n",
"type": "stdin_stdout"
},
{
"input": "6\n10 0\n0101111000\n10 -2\n0101111000\n1 2\n0\n1 -1\n1\n3 1000000000\n000\n1 -1\n0\n",
"output": "-1\n-1\n1\n1\n1\n0\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 2\n001001\n3 0\n011\n",
"output": "3\n3\n",
"type": "stdin_stdout"
},
{
"input": "8\n10 30\n0000011110\n10 0\n0101111000\n10 -2\n0101111000\n10 0\n0000011110\n1 2\n0\n1 -1\n1\n3 1000000000\n000\n1 -1\n0\n",
"output": "5\n-1\n-1\n1\n1\n1\n1\n0\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 0\n10011\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "7\n9 0\n000111010\n17 0\n10100010100000000\n11 0\n01010000010\n15 5\n111010101100001\n11 -5\n00010100010\n11 5\n00101000100\n11 -1234567\n00000111111\n",
"output": "3\n3\n3\n0\n0\n1\n11\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 0\n011\n6 2\n001001\n",
"output": "3\n3\n",
"type": "stdin_stdout"
},
{
"input": "7\n9 0\n000111010\n17 0\n10100010100000000\n11 0\n01010000010\n15 0\n111010101100001\n11 0\n11111001010\n11 0\n00110011010\n20 0\n00010010010110111010\n",
"output": "3\n3\n3\n2\n1\n4\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n63 -3\n001111111001000101001011110101111010100001011010101100111001010\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 -2\n11100\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "7\n9 0\n000111010\n17 0\n10100010100000000\n11 0\n01010000010\n15 0\n111010101100001\n11 0\n11111001010\n11 0\n00110011010\n20 0\n00011110010110111010\n",
"output": "3\n3\n3\n2\n1\n4\n8\n",
"type": "stdin_stdout"
},
{
"input": "6\n3 0\n100\n3 1\n100\n3 1\n101\n3 -1\n101\n3 0\n101\n3 -1\n100\n",
"output": "3\n3\n0\n3\n2\n1\n",
"type": "stdin_stdout"
},
{
"input": "1\n10 4\n0000111111\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 2\n001001\n3 0\n011\n1 1\n0\n",
"output": "3\n3\n1\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 2\n001001\n3 0\n011\n2 1\n00\n",
"output": "3\n3\n1\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 2\n001001\n3 0\n011\n2 0\n00\n",
"output": "3\n3\n1\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 2\n001001\n3 0\n011\n4 0\n0011\n",
"output": "3\n3\n-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 0\n0111\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n6 2\n001001\n3 0\n011\n2 0\n00\n1 1\n1\n",
"output": "3\n3\n1\n0\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 0\n010010\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\n6 0\n000111\n7 0\n0001111\n7 0\n0001110\n20 0\n00000000001111111111\n21 0\n000000000011111111111\n21 0\n000000000011111111110\n",
"output": "-1\n7\n2\n-1\n21\n2\n",
"type": "stdin_stdout"
},
{
"input": "1\n30 1\n001011010110111011110010111111\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n0\n6 2\n001001\n3 0\n011\n",
"output": "1\n3\n3\n",
"type": "stdin_stdout"
},
{
"input": "1\n32 -4\n10000111101011111111000001100011\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1\n5 0\n11001\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n6 -2\n110010\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n439 -6100238\n1000111101010011110001001010010011000101000101010010111000001100000000100110111111000100111001000000100110001101001110101001001001011011011001111000010100000101100001110111000000011101111001111100111100010010011000101101011001010111110101100101101011110010110001110100001011101000110101011011101111011100010000010010011111001111110000110110011000001110010010101100011010011111011100010011001011011110111010011101000011111011110000011100101\n",
"output": "439\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 -1\n10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1\n7 3\n0000111\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 0\n011\n7 3\n0000111\n",
"output": "3\n6\n",
"type": "stdin_stdout"
},
{
"input": "1\n86 -11\n01011111011111001001000111010010100111100011110001110111100100000010011100001001010001\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2\n11 3\n00000111111\n4 2\n1100\n",
"output": "5\n0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1295/B"
} | vfc_10030 |
apps | verifiable_code | 70 | Solve the following coding problem using the programming language python:
Polycarp is crazy about round numbers. He especially likes the numbers divisible by 10^{k}.
In the given number of n Polycarp wants to remove the least number of digits to get a number that is divisible by 10^{k}. For example, if k = 3, in the number 30020 it is enough to delete a single digit (2). In this case, the result is 3000 that is divisible by 10^3 = 1000.
Write a program that prints the minimum number of digits to be deleted from the given integer number n, so that the result is divisible by 10^{k}. The result should not start with the unnecessary leading zero (i.e., zero can start only the number 0, which is required to be written as exactly one digit).
It is guaranteed that the answer exists.
-----Input-----
The only line of the input contains two integer numbers n and k (0 ≤ n ≤ 2 000 000 000, 1 ≤ k ≤ 9).
It is guaranteed that the answer exists. All numbers in the input are written in traditional notation of integers, that is, without any extra leading zeros.
-----Output-----
Print w — the required minimal number of digits to erase. After removing the appropriate w digits from the number n, the result should have a value that is divisible by 10^{k}. The result can start with digit 0 in the single case (the result is zero and written by exactly the only digit 0).
-----Examples-----
Input
30020 3
Output
1
Input
100 9
Output
2
Input
10203049 2
Output
3
-----Note-----
In the example 2 you can remove two digits: 1 and any 0. The result is number 0 which is divisible by any number.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input().split()
k = int(s[1])
s = s[0]
if s.count('0') < k:
if s.count('0') > 0:
print(len(s) - 1)
else:
print(len(s))
return
have = 0
its = 0
for i in range(len(s) - 1, -1, -1):
its += 1
if s[i] == '0':
have += 1
if have == k:
print(its - have)
return
``` | {
"language": "python",
"test_cases": [
{
"input": "30020 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 9\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10203049 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "0 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "0 9\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "102030404 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000999999 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "12000000 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1090090090 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "101010110 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "101010110 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "101010110 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "101010110 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "101010110 5\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "101010110 9\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1234567890 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1234567890 2\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1234567890 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 9\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1010101010 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1010101010 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1010101010 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1010101010 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1010101010 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1010101010 6\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1010101010 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1010101010 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1010101010 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10001000 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10001000 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10001000 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10001000 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10001000 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10001000 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10001000 7\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10001000 8\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "10001000 9\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "1000000001 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000001 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000001 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000001 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000001 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000001 8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000001 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1000 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100001100 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7057 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "30000000 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "470 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "500500000 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2103 8\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "600000000 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "708404442 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5000140 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1100047 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "309500 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "70053160 4\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "44000 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "400370000 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5800 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "20700050 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "650 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "320005070 6\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "370000 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1011 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1000111 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1001111 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "99990 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10100200 6\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "200 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "103055 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1030555 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "100111 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "101 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1001 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100000 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1100000 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "123450 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1003 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1111100 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "532415007 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "801 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1230 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "9900 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "14540444 2\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "11111100 4\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "11001 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1011110 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "15450112 2\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "2220 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "90099 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10005 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1010 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "444444400 3\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10020 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10303 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "123000 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "12300 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "101 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "500001 8\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "121002 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10011 3\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/779/B"
} | vfc_10034 |
apps | verifiable_code | 71 | Solve the following coding problem using the programming language python:
On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.
Seating in the class looks like a rectangle, where n rows with m pupils in each.
The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...
The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.
During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values: the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei.
If there is only one row in the class, then the teacher always asks children from this row.
-----Input-----
The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 10^18, 1 ≤ x ≤ n, 1 ≤ y ≤ m).
-----Output-----
Print three integers: the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei.
-----Examples-----
Input
1 3 8 1 1
Output
3 2 3
Input
4 2 9 4 2
Output
2 1 1
Input
5 5 25 4 3
Output
1 1 1
Input
100 100 1000000000000000000 100 100
Output
101010101010101 50505050505051 50505050505051
-----Note-----
The order of asking pupils in the first test: the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table;
The order of asking pupils in the second test: the pupil from the first row who seats at the first table; the pupil from the first row who seats at the second table; the pupil from the second row who seats at the first table; the pupil from the second row who seats at the second table; the pupil from the third row who seats at the first table; the pupil from the third row who seats at the second table; the pupil from the fourth row who seats at the first table; the pupil from the fourth row who seats at the second table, it means it is Sergei; the pupil from the third row who seats at the first table;
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m, k, x, y = list(map(int, input().split()))
ans = [[0] * m for x in range(n)]
onebig = (2*n-2)*m or m
oo = k // onebig
for i in range(n):
for j in range(m):
if i == 0 or i == n-1:
ans[i][j] += oo
k -= oo
else:
ans[i][j] += 2*oo
k -= 2*oo
from itertools import chain
for i in chain(list(range(n)), list(range(n-2, 0, -1))):
if not k:
break
for j in range(m):
if not k:
break
ans[i][j] += 1
k -= 1
_max = max(list(map(max, ans)))
_min = min(list(map(min, ans)))
_ans = ans[x-1][y-1]
print(_max, _min, _ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "1 3 8 1 1\n",
"output": "3 2 3",
"type": "stdin_stdout"
},
{
"input": "4 2 9 4 2\n",
"output": "2 1 1",
"type": "stdin_stdout"
},
{
"input": "5 5 25 4 3\n",
"output": "1 1 1",
"type": "stdin_stdout"
},
{
"input": "100 100 1000000000000000000 100 100\n",
"output": "101010101010101 50505050505051 50505050505051",
"type": "stdin_stdout"
},
{
"input": "3 2 15 2 2\n",
"output": "4 2 3",
"type": "stdin_stdout"
},
{
"input": "4 1 8 3 1\n",
"output": "3 1 2",
"type": "stdin_stdout"
},
{
"input": "3 2 8 2 1\n",
"output": "2 1 2",
"type": "stdin_stdout"
},
{
"input": "4 2 9 4 1\n",
"output": "2 1 1",
"type": "stdin_stdout"
},
{
"input": "1 3 7 1 1\n",
"output": "3 2 3",
"type": "stdin_stdout"
},
{
"input": "2 2 8 2 1\n",
"output": "2 2 2",
"type": "stdin_stdout"
},
{
"input": "3 1 6 2 1\n",
"output": "3 1 3",
"type": "stdin_stdout"
},
{
"input": "5 6 30 5 4\n",
"output": "1 1 1",
"type": "stdin_stdout"
},
{
"input": "3 8 134010 3 4\n",
"output": "8376 4188 4188",
"type": "stdin_stdout"
},
{
"input": "10 10 25 5 1\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "100 100 1000000000 16 32\n",
"output": "101011 50505 101010",
"type": "stdin_stdout"
},
{
"input": "100 100 1 23 39\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "1 1 1000000000 1 1\n",
"output": "1000000000 1000000000 1000000000",
"type": "stdin_stdout"
},
{
"input": "1 1 1 1 1\n",
"output": "1 1 1",
"type": "stdin_stdout"
},
{
"input": "47 39 1772512 1 37\n",
"output": "989 494 495",
"type": "stdin_stdout"
},
{
"input": "37 61 421692 24 49\n",
"output": "192 96 192",
"type": "stdin_stdout"
},
{
"input": "89 97 875341288 89 96\n",
"output": "102547 51273 51274",
"type": "stdin_stdout"
},
{
"input": "100 1 1000000000000 100 1\n",
"output": "10101010101 5050505051 5050505051",
"type": "stdin_stdout"
},
{
"input": "1 100 1000000000000 1 100\n",
"output": "10000000000 10000000000 10000000000",
"type": "stdin_stdout"
},
{
"input": "2 4 6 1 4\n",
"output": "1 0 1",
"type": "stdin_stdout"
},
{
"input": "2 4 6 1 3\n",
"output": "1 0 1",
"type": "stdin_stdout"
},
{
"input": "2 4 49 1 1\n",
"output": "7 6 7",
"type": "stdin_stdout"
},
{
"input": "3 3 26 1 1\n",
"output": "4 2 3",
"type": "stdin_stdout"
},
{
"input": "5 2 77 4 2\n",
"output": "10 5 10",
"type": "stdin_stdout"
},
{
"input": "2 5 73 2 3\n",
"output": "8 7 7",
"type": "stdin_stdout"
},
{
"input": "5 2 81 5 1\n",
"output": "10 5 5",
"type": "stdin_stdout"
},
{
"input": "4 5 93 1 2\n",
"output": "6 3 4",
"type": "stdin_stdout"
},
{
"input": "4 4 74 4 1\n",
"output": "6 3 3",
"type": "stdin_stdout"
},
{
"input": "5 3 47 2 1\n",
"output": "4 2 4",
"type": "stdin_stdout"
},
{
"input": "5 4 61 1 1\n",
"output": "4 2 2",
"type": "stdin_stdout"
},
{
"input": "4 4 95 1 1\n",
"output": "8 4 4",
"type": "stdin_stdout"
},
{
"input": "2 5 36 1 3\n",
"output": "4 3 4",
"type": "stdin_stdout"
},
{
"input": "5 2 9 5 1\n",
"output": "1 0 1",
"type": "stdin_stdout"
},
{
"input": "4 1 50 1 1\n",
"output": "17 8 9",
"type": "stdin_stdout"
},
{
"input": "3 2 83 1 2\n",
"output": "21 10 11",
"type": "stdin_stdout"
},
{
"input": "3 5 88 1 5\n",
"output": "9 4 5",
"type": "stdin_stdout"
},
{
"input": "4 2 89 1 2\n",
"output": "15 7 8",
"type": "stdin_stdout"
},
{
"input": "2 1 1 1 1\n",
"output": "1 0 1",
"type": "stdin_stdout"
},
{
"input": "5 3 100 2 1\n",
"output": "9 4 9",
"type": "stdin_stdout"
},
{
"input": "4 4 53 3 1\n",
"output": "5 2 4",
"type": "stdin_stdout"
},
{
"input": "4 3 1 3 3\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "3 5 1 2 1\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "5 2 2 4 1\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "3 3 1 3 2\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "1 1 1 1 1\n",
"output": "1 1 1",
"type": "stdin_stdout"
},
{
"input": "1 1 100 1 1\n",
"output": "100 100 100",
"type": "stdin_stdout"
},
{
"input": "4 30 766048376 1 23\n",
"output": "8511649 4255824 4255825",
"type": "stdin_stdout"
},
{
"input": "3 90 675733187 1 33\n",
"output": "3754073 1877036 1877037",
"type": "stdin_stdout"
},
{
"input": "11 82 414861345 1 24\n",
"output": "505929 252964 252965",
"type": "stdin_stdout"
},
{
"input": "92 10 551902461 1 6\n",
"output": "606487 303243 303244",
"type": "stdin_stdout"
},
{
"input": "18 83 706805205 1 17\n",
"output": "500925 250462 250463",
"type": "stdin_stdout"
},
{
"input": "1 12 943872212 1 1\n",
"output": "78656018 78656017 78656018",
"type": "stdin_stdout"
},
{
"input": "91 15 237966754 78 6\n",
"output": "176272 88136 176272",
"type": "stdin_stdout"
},
{
"input": "58 66 199707458 15 9\n",
"output": "53086 26543 53085",
"type": "stdin_stdout"
},
{
"input": "27 34 77794947 24 4\n",
"output": "88004 44002 88004",
"type": "stdin_stdout"
},
{
"input": "22 89 981099971 16 48\n",
"output": "524934 262467 524933",
"type": "stdin_stdout"
},
{
"input": "10 44 222787770 9 25\n",
"output": "562596 281298 562596",
"type": "stdin_stdout"
},
{
"input": "9 64 756016805 7 55\n",
"output": "1476596 738298 1476595",
"type": "stdin_stdout"
},
{
"input": "91 86 96470485 12 43\n",
"output": "12464 6232 12464",
"type": "stdin_stdout"
},
{
"input": "85 53 576663715 13 1\n",
"output": "129530 64765 129529",
"type": "stdin_stdout"
},
{
"input": "2 21 196681588 2 18\n",
"output": "4682895 4682894 4682895",
"type": "stdin_stdout"
},
{
"input": "8 29 388254841 6 29\n",
"output": "1912586 956293 1912585",
"type": "stdin_stdout"
},
{
"input": "2 59 400923999 2 43\n",
"output": "3397662 3397661 3397661",
"type": "stdin_stdout"
},
{
"input": "3 71 124911502 1 67\n",
"output": "879658 439829 439829",
"type": "stdin_stdout"
},
{
"input": "1 17 523664480 1 4\n",
"output": "30803793 30803792 30803793",
"type": "stdin_stdout"
},
{
"input": "11 27 151005021 3 15\n",
"output": "559278 279639 559278",
"type": "stdin_stdout"
},
{
"input": "7 32 461672865 4 11\n",
"output": "2404547 1202273 2404546",
"type": "stdin_stdout"
},
{
"input": "2 90 829288586 1 57\n",
"output": "4607159 4607158 4607159",
"type": "stdin_stdout"
},
{
"input": "17 5 370710486 2 1\n",
"output": "4633882 2316941 4633881",
"type": "stdin_stdout"
},
{
"input": "88 91 6317 70 16\n",
"output": "1 0 1",
"type": "stdin_stdout"
},
{
"input": "19 73 1193 12 46\n",
"output": "1 0 1",
"type": "stdin_stdout"
},
{
"input": "84 10 405 68 8\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "92 80 20 9 69\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "69 21 203 13 16\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "63 22 1321 61 15\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "56 83 4572 35 22\n",
"output": "1 0 1",
"type": "stdin_stdout"
},
{
"input": "36 19 684 20 15\n",
"output": "1 1 1",
"type": "stdin_stdout"
},
{
"input": "33 2 1 8 2\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "76 74 1 38 39\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "1 71 1000000000000000000 1 5\n",
"output": "14084507042253522 14084507042253521 14084507042253522",
"type": "stdin_stdout"
},
{
"input": "13 89 1000000000000000000 10 14\n",
"output": "936329588014982 468164794007491 936329588014982",
"type": "stdin_stdout"
},
{
"input": "1 35 1000000000000000000 1 25\n",
"output": "28571428571428572 28571428571428571 28571428571428571",
"type": "stdin_stdout"
},
{
"input": "81 41 1000000000000000000 56 30\n",
"output": "304878048780488 152439024390244 304878048780488",
"type": "stdin_stdout"
},
{
"input": "4 39 1000000000000000000 3 32\n",
"output": "8547008547008547 4273504273504273 8547008547008547",
"type": "stdin_stdout"
},
{
"input": "21 49 1000000000000000000 18 11\n",
"output": "1020408163265307 510204081632653 1020408163265306",
"type": "stdin_stdout"
},
{
"input": "91 31 1000000000000000000 32 7\n",
"output": "358422939068101 179211469534050 358422939068101",
"type": "stdin_stdout"
},
{
"input": "51 99 1000000000000000000 48 79\n",
"output": "202020202020203 101010101010101 202020202020202",
"type": "stdin_stdout"
},
{
"input": "5 99 1000000000000000000 4 12\n",
"output": "2525252525252526 1262626262626263 2525252525252525",
"type": "stdin_stdout"
},
{
"input": "100 100 1000000000000000000 1 1\n",
"output": "101010101010101 50505050505051 50505050505051",
"type": "stdin_stdout"
},
{
"input": "100 100 1000000000000000000 31 31\n",
"output": "101010101010101 50505050505051 101010101010101",
"type": "stdin_stdout"
},
{
"input": "1 100 1000000000000000000 1 1\n",
"output": "10000000000000000 10000000000000000 10000000000000000",
"type": "stdin_stdout"
},
{
"input": "1 100 1000000000000000000 1 35\n",
"output": "10000000000000000 10000000000000000 10000000000000000",
"type": "stdin_stdout"
},
{
"input": "100 1 1000000000000000000 1 1\n",
"output": "10101010101010101 5050505050505051 5050505050505051",
"type": "stdin_stdout"
},
{
"input": "100 1 1000000000000000000 35 1\n",
"output": "10101010101010101 5050505050505051 10101010101010101",
"type": "stdin_stdout"
},
{
"input": "1 1 1000000000000000000 1 1\n",
"output": "1000000000000000000 1000000000000000000 1000000000000000000",
"type": "stdin_stdout"
},
{
"input": "3 2 5 1 1\n",
"output": "1 0 1",
"type": "stdin_stdout"
},
{
"input": "100 100 10001 1 1\n",
"output": "2 1 1",
"type": "stdin_stdout"
},
{
"input": "1 5 7 1 3\n",
"output": "2 1 1",
"type": "stdin_stdout"
},
{
"input": "2 2 7 1 1\n",
"output": "2 1 2",
"type": "stdin_stdout"
},
{
"input": "4 1 5 3 1\n",
"output": "2 1 2",
"type": "stdin_stdout"
},
{
"input": "2 3 4 2 3\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "3 5 21 1 2\n",
"output": "2 1 1",
"type": "stdin_stdout"
},
{
"input": "2 4 14 1 1\n",
"output": "2 1 2",
"type": "stdin_stdout"
},
{
"input": "5 9 8 5 4\n",
"output": "1 0 0",
"type": "stdin_stdout"
},
{
"input": "2 6 4 1 3\n",
"output": "1 0 1",
"type": "stdin_stdout"
},
{
"input": "1 5 9 1 1\n",
"output": "2 1 2",
"type": "stdin_stdout"
},
{
"input": "1 5 3 1 2\n",
"output": "1 0 1",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/758/C"
} | vfc_10038 |
apps | verifiable_code | 72 | Solve the following coding problem using the programming language python:
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $7$ because its subribbon a appears $7$ times, and the ribbon abcdabc has the beauty of $2$ because its subribbon abc appears twice.
The rules are simple. The game will have $n$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $n$ turns wins the treasure.
Could you find out who is going to be the winner if they all play optimally?
-----Input-----
The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.
-----Output-----
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
-----Examples-----
Input
3
Kuroo
Shiro
Katie
Output
Kuro
Input
7
treasurehunt
threefriends
hiCodeforces
Output
Shiro
Input
1
abcabc
cbabac
ababca
Output
Katie
Input
15
foPaErcvJ
mZaxowpbt
mkuOlaHRE
Output
Draw
-----Note-----
In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.
In the fourth example, since the length of each of the string is $9$ and the number of turn is $15$, everyone can change their ribbons in some way to reach the maximal beauty of $9$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
turns = int(input())
s0 = input()
s1 = input()
s2 = input()
d0 = dict()
d1 = dict()
d2 = dict()
alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
for char in alphabet:
d0[char] = 0
d1[char] = 0
d2[char] = 0
for char in s0:
d0[char] += 1
for char in s1:
d1[char] += 1
for char in s2:
d2[char] += 1
m0 = max([d0[char] for char in alphabet])
m1 = max([d1[char] for char in alphabet])
m2 = max([d2[char] for char in alphabet])
l0 = len(s0)
l1 = len(s1)
l2 = len(s2)
if turns == 1 and m0 == l0:
score0 = m0 - 1
else:
score0 = min(l0,m0+turns)
if turns == 1 and m1 == l1:
score1 = m1 - 1
else:
score1 = min(l1,m1+turns)
if turns == 1 and m2 == l2:
score2 = m2 - 1
else:
score2 = min(l2,m2+turns)
scores = [score0,score1,score2]
bestscore = max(scores)
winnerlist = [i for i in range(3) if scores[i] == bestscore]
if len(winnerlist) > 1:
print('Draw')
else:
print(['Kuro','Shiro','Katie'][winnerlist[0]])
``` | {
"language": "python",
"test_cases": [
{
"input": "3\nKuroo\nShiro\nKatie\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "7\ntreasurehunt\nthreefriends\nhiCodeforces\n",
"output": "Shiro\n",
"type": "stdin_stdout"
},
{
"input": "1\nabcabc\ncbabac\nababca\n",
"output": "Katie\n",
"type": "stdin_stdout"
},
{
"input": "15\nfoPaErcvJ\nmZaxowpbt\nmkuOlaHRE\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "1\naaaaaaaaaa\nAAAAAAcAAA\nbbbbbbzzbb\n",
"output": "Shiro\n",
"type": "stdin_stdout"
},
{
"input": "60\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\ndcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY\nXaZXbbdcXaadcYdYYcbZdcaXaYZabbXZZYbYbcXbaXabcXbXadbZYZ\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "9174\nbzbbbzzzbbzzccczzccczzbzbzcbzbbzccbzcccbccczzbbcbbzbzzzcbczbzbzzbbbczbbcbzzzbcbzczbcczb\ndbzzzccdcdczzzzzcdczbbzcdzbcdbzzdczbzddcddbdbzzzczcczzbdcbbzccbzzzdzbzddcbzbdzdcczccbdb\nzdczddzcdddddczdczdczdcdzczddzczdzddczdcdcdzczczzdzccdccczczdzczczdzcdddzddzccddcczczzd\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "727\nbaabbabbbababbbbaaaabaabbaabababaaababaaababbbbababbbbbbbbbbaaabaabbbbbbbbaaaabaabbaaabaabbabaa\nddcdcccccccdccdcdccdddcddcddcddddcdddcdcdccddcdddddccddcccdcdddcdcccdccccccdcdcdccccccdccccccdc\nfffeefeffeefeeeeffefffeeefffeefffefeefefeeeffefefefefefefffffffeeeeeffffeefeeeeffffeeeeeefeffef\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "61\nbzqiqprzfwddqwctcrhnkqcsnbmcmfmrgaljwieajfouvuiunmfbrehxchupmsdpwilwu\njyxxujvxkwilikqeegzxlyiugflxqqbwbujzedqnlzucdnuipacatdhcozuvgktwvirhs\ntqiahohijwfcetyyjlkfhfvkhdgllxmhyyhhtlhltcdspusyhwpwqzyagtsbaswaobwub\n",
"output": "Katie\n",
"type": "stdin_stdout"
},
{
"input": "30\njAjcdwkvcTYSYBBLniJIIIiubKWnqeDtUiaXSIPfhDTOrCWBQetm\nPQPOTgqfBWzQvPNeEaUaPQGdUgldmOZsBtsIqZGGyXozntMpOsyY\nNPfvGxMqIULNWOmUrHJfsqORUHkzKQfecXsTzgFCmUtFmIBudCJr\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\nabcabcabcabcdddabc\nzxytzytxxtytxyzxyt\nfgffghfghffgghghhh\n",
"output": "Katie\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaa\naaaaa\naaaab\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaaa\naaaabcd\nabcdefg\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaaa\naaabcde\nabcdefg\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaaa\naaaabbb\nabcdefg\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaa\nbbb\nabc\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaa\nabcde\nabcde\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaa\nqwert\nlkjhg\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaa\nbbbbb\naabcd\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\nabcde\nfghij\nkkkkk\n",
"output": "Katie\n",
"type": "stdin_stdout"
},
{
"input": "4\naaaabcd\naaaabcd\naaaaaaa\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaabb\naabcde\nabcdef\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "2\naaab\nabcd\naaaa\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaa\naaaaaa\nabcdef\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "1\nAAAAA\nBBBBB\nABCDE\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "1\nabcde\naaaaa\naaaaa\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "4\naaabbb\nabfcde\nabfcde\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "0\naaa\naab\nccd\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaa\naaaaa\naabbb\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\nxxxxxx\nxxxooo\nabcdef\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\noooo\naaac\nabcd\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "1\naaaaaaa\naaabcde\nabcdefg\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "3\nooooo\naaabb\nabcde\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaa\nqwert\nqwery\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "2\naaaaaa\nbbbbbb\naaaaab\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naabb\naabb\naabc\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\naaa\naab\naab\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\nbbbbcc\nbbbbbb\nsadfgh\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaacc\nxxxxkkkk\nxxxxkkkk\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "2\naaaac\nbbbbc\nccccc\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaaaaa\naaabbbbbb\nabcdewert\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaabc\naaaab\nabcde\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaaaa\naaaaaaab\naaaabbbb\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\nabcdefg\nabccccc\nacccccc\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaa\naabcd\nabcde\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "4\naaabbb\nabcdef\nabcdef\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "4\naaabbb\naabdef\nabcdef\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\nabba\nbbbb\naaaa\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaa\nbbaaa\nabcde\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\naaa\naaa\nabc\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaa\nabcda\nabcde\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaa\nabcde\nbcdef\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "3\naaabb\naabbc\nqwert\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaa\naabbcc\naabbcc\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "3\nAAAAAA\nAAAAAB\nABCDEF\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\nabc\naac\nbbb\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\naaaab\naabbc\naabbc\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "2\naaaaaab\naaaaabb\nabcdefg\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaaaaaaa\nbbbbbbbbaaa\nqwertyuiasd\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaa\nbbbb\naabb\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaabb\naaabcd\nabcdef\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaa\nabc\nbbb\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "1\naa\nab\nbb\n",
"output": "Shiro\n",
"type": "stdin_stdout"
},
{
"input": "1\naacb\nabcd\naaaa\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaabb\naaabbb\nabcdef\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaa\naaaa\nabcd\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\nabcd\nabcd\naaad\n",
"output": "Katie\n",
"type": "stdin_stdout"
},
{
"input": "3\naaa\nbbb\naab\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaa\naaaaab\naaaaaa\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\naaab\nabcd\nabcd\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "3\nooooo\nShiro\nKatie\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "3\naaabb\naabcd\nabcde\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "4\nabcd\nabcd\naaaa\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "4\naaa\nbbb\naab\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\nxxxx\nyyyx\nabcd\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\nAAAAA\nAAAAB\nABCDE\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaacdc\naaaaabc\naaaaabc\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaa\naabcde\naabcde\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "3\naaabb\naaabb\naaaaa\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "5\nabbbbb\ncbbbbb\nabcdef\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaaaaa\naaaaabbbb\naaaaabbbb\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "4\naaaaaab\naaabbbb\naaabbbb\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaabb\naaaabb\naaabbb\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\naaaabb\naaaaab\nabcdef\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\naaaaa\naaaae\nabcde\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaa\nbbbcde\nabcdef\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "4\naaaabbb\naabcdef\naabcdef\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "2\naaaaa\naaaab\nabcde\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naabbbbb\naaabbbb\nabcdefg\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\nabcde\naabcd\naaaaa\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "5\naaabbcc\nabcdefg\nabcdefg\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "3\naabbb\nabcde\nabcde\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "0\nbbb\nabb\nqer\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "5\naabbbbb\naaaaaaa\nabcdefg\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\naaaab\naaaab\naaabb\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\naaaaaab\naaaabbb\naaaaccc\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaaaaaaaa\naaaaaaaaaaab\naaaaaabbbbbb\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaabb\nabcde\naaaaa\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaac\naaaaebc\naaaaaac\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaaa\naaabbb\nqwerty\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\ncccca\nabcde\nabcde\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "100005\nAA\nBC\nCC\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaa\nbbbb\nccca\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaaa\nbcdef\nbcdef\n",
"output": "Kuro\n",
"type": "stdin_stdout"
},
{
"input": "2\naaab\naabb\nqwer\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\nabcddd\nabcdef\nbbaaaa\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "2\naaaa\naaaa\naabc\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\naaaa\naaaa\naaab\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "3\nabcddd\nabcdef\naaaaaa\n",
"output": "Draw\n",
"type": "stdin_stdout"
},
{
"input": "1\naaaa\nabcd\naaab\n",
"output": "Katie\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/979/B"
} | vfc_10042 |
apps | verifiable_code | 73 | Solve the following coding problem using the programming language python:
Mister B once received a gift: it was a book about aliens, which he started read immediately. This book had c pages.
At first day Mister B read v_0 pages, but after that he started to speed up. Every day, starting from the second, he read a pages more than on the previous day (at first day he read v_0 pages, at second — v_0 + a pages, at third — v_0 + 2a pages, and so on). But Mister B is just a human, so he physically wasn't able to read more than v_1 pages per day.
Also, to refresh his memory, every day, starting from the second, Mister B had to reread last l pages he read on the previous day. Mister B finished the book when he read the last page for the first time.
Help Mister B to calculate how many days he needed to finish the book.
-----Input-----
First and only line contains five space-separated integers: c, v_0, v_1, a and l (1 ≤ c ≤ 1000, 0 ≤ l < v_0 ≤ v_1 ≤ 1000, 0 ≤ a ≤ 1000) — the length of the book in pages, the initial reading speed, the maximum reading speed, the acceleration in reading speed and the number of pages for rereading.
-----Output-----
Print one integer — the number of days Mister B needed to finish the book.
-----Examples-----
Input
5 5 10 5 4
Output
1
Input
12 4 12 4 1
Output
3
Input
15 1 100 0 0
Output
15
-----Note-----
In the first sample test the book contains 5 pages, so Mister B read it right at the first day.
In the second sample test at first day Mister B read pages number 1 - 4, at second day — 4 - 11, at third day — 11 - 12 and finished the book.
In third sample test every day Mister B read 1 page of the book, so he finished in 15 days.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
read = lambda: map(int, input().split())
c, v0, v1, a, l = read()
cur = 0
cnt = 0
while cur < c:
cur = max(0, cur - l)
cur += min(v1, v0 + a * cnt)
cnt += 1
print(cnt)
``` | {
"language": "python",
"test_cases": [
{
"input": "5 5 10 5 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "12 4 12 4 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "15 1 100 0 0\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000 999 1000 1000 998\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000 2 2 5 1\n",
"output": "999\n",
"type": "stdin_stdout"
},
{
"input": "1000 1 1 1000 0\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "737 41 74 12 11\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "1000 1000 1000 0 999\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "765 12 105 5 7\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "15 2 2 1000 0\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1000 1 1000 1000 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "20 3 7 1 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1000 500 500 1000 499\n",
"output": "501\n",
"type": "stdin_stdout"
},
{
"input": "1 1000 1000 1000 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000 2 1000 56 0\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "1000 2 1000 802 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "16 1 8 2 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "20 6 10 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8 2 12 4 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8 6 13 2 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "70 4 20 87 0\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "97 8 13 234 5\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "16 4 23 8 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "65 7 22 7 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "93 10 18 11 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "86 13 19 15 9\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "333 17 50 10 16\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "881 16 55 10 12\n",
"output": "23\n",
"type": "stdin_stdout"
},
{
"input": "528 11 84 3 9\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "896 2 184 8 1\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "236 10 930 9 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "784 1 550 14 0\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "506 1 10 4 0\n",
"output": "53\n",
"type": "stdin_stdout"
},
{
"input": "460 1 3 2 0\n",
"output": "154\n",
"type": "stdin_stdout"
},
{
"input": "701 1 3 1 0\n",
"output": "235\n",
"type": "stdin_stdout"
},
{
"input": "100 49 50 1000 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100 1 100 100 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "12 1 4 2 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "22 10 12 0 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "20 10 15 1 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1000 5 10 1 4\n",
"output": "169\n",
"type": "stdin_stdout"
},
{
"input": "1000 1 1000 1 0\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "4 1 2 2 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1 5 5 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "19 10 11 0 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1 2 3 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 1 4 10 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "20 3 100 1 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1000 5 9 5 0\n",
"output": "112\n",
"type": "stdin_stdout"
},
{
"input": "1 11 12 0 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1 1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000 1 20 1 0\n",
"output": "60\n",
"type": "stdin_stdout"
},
{
"input": "9 1 4 2 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "129 2 3 4 0\n",
"output": "44\n",
"type": "stdin_stdout"
},
{
"input": "4 2 2 0 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1000 1 10 100 0\n",
"output": "101\n",
"type": "stdin_stdout"
},
{
"input": "100 1 100 1 0\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "8 3 4 2 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "20 1 6 4 0\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8 2 4 2 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "11 5 6 7 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100 120 130 120 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7 1 4 1 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5 3 10 0 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5 2 2 0 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1000 10 1000 10 0\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "25 3 50 4 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "9 10 10 10 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "17 10 12 6 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "15 5 10 3 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "8 3 5 1 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "19 1 12 5 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1000 10 1000 1 0\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "100 1 2 1000 0\n",
"output": "51\n",
"type": "stdin_stdout"
},
{
"input": "20 10 11 1000 9\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "16 2 100 1 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "18 10 13 2 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "12 3 5 3 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "17 3 11 2 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4 2 100 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7 4 5 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100 1 2 2 0\n",
"output": "51\n",
"type": "stdin_stdout"
},
{
"input": "50 4 5 5 0\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "1 2 2 0 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000 2 3 10 1\n",
"output": "500\n",
"type": "stdin_stdout"
},
{
"input": "500 10 500 1000 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000 4 12 1 0\n",
"output": "87\n",
"type": "stdin_stdout"
},
{
"input": "18 10 13 1 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 3 6 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "15 5 100 1 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "100 1 10 1 0\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "8 2 7 5 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "11 2 4 1 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1000 500 900 100 300\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 1 2 5 0\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "7 3 5 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 3 10 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000 501 510 1 499\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "1000 1 1000 2 0\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"input": "1 5 5 0 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "18 10 15 1 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100 4 1000 1 2\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "20 2 40 1 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1 11 1000 100 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6 4 4 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8 3 5 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 5 7 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "400 100 198 1 99\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "3 1 2 5 0\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/820/A"
} | vfc_10046 |
Subsets and Splits