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 | 74 | Solve the following coding problem using the programming language python:
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.
More formally, you are given an odd numer n. Find a set of numbers p_{i} (1 ≤ i ≤ k), such that
1 ≤ k ≤ 3
p_{i} is a prime
$\sum_{i = 1}^{k} p_{i} = n$
The numbers p_{i} do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.
-----Input-----
The single line contains an odd number n (3 ≤ n < 10^9).
-----Output-----
In the first line print k (1 ≤ k ≤ 3), showing how many numbers are in the representation you found.
In the second line print numbers p_{i} in any order. If there are multiple possible solutions, you can print any of them.
-----Examples-----
Input
27
Output
3
5 11 11
-----Note-----
A prime is an integer strictly larger than one that is divisible only by one and by itself.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import math
n=int(input())
def prime(p):
if p == 1:
return False
fl=True
for i in range(2,math.ceil(p**0.5) + 1):
if p % i == 0:
fl=False
return fl
def sum_of_primes(k):
fl=True
for i in range((k // 2) + 1):
if prime(i) and prime(k-i):
fl=True
break
return fl
if prime(n):
print(1)
print(n)
else:
if prime(n-2):
print(2)
print(2 , n-2)
else:
l=1
for i in range(2, (n // 3) + 1):
if prime(i) and sum_of_primes(n - i):
l=i
break
print(3)
r=1
for k in range((n-l) // 2):
if prime(k) and prime(n-l-k):
r=k
break
print(l,r,n-l-r)
``` | {
"language": "python",
"test_cases": [
{
"input": "27\n",
"output": "3\n2 2 23",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "1\n3",
"type": "stdin_stdout"
},
{
"input": "25\n",
"output": "2\n2 23",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "2\n2 7",
"type": "stdin_stdout"
},
{
"input": "91\n",
"output": "2\n2 89",
"type": "stdin_stdout"
},
{
"input": "57\n",
"output": "3\n2 2 53",
"type": "stdin_stdout"
},
{
"input": "31\n",
"output": "1\n31",
"type": "stdin_stdout"
},
{
"input": "555\n",
"output": "3\n3 5 547",
"type": "stdin_stdout"
},
{
"input": "700000001\n",
"output": "1\n700000001",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "1\n5",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "1\n7",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "1\n11",
"type": "stdin_stdout"
},
{
"input": "13\n",
"output": "1\n13",
"type": "stdin_stdout"
},
{
"input": "15\n",
"output": "2\n2 13",
"type": "stdin_stdout"
},
{
"input": "17\n",
"output": "1\n17",
"type": "stdin_stdout"
},
{
"input": "19\n",
"output": "1\n19",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "2\n2 19",
"type": "stdin_stdout"
},
{
"input": "23\n",
"output": "1\n23",
"type": "stdin_stdout"
},
{
"input": "29\n",
"output": "1\n29",
"type": "stdin_stdout"
},
{
"input": "79\n",
"output": "1\n79",
"type": "stdin_stdout"
},
{
"input": "99\n",
"output": "2\n2 97",
"type": "stdin_stdout"
},
{
"input": "27\n",
"output": "3\n2 2 23",
"type": "stdin_stdout"
},
{
"input": "55\n",
"output": "2\n2 53",
"type": "stdin_stdout"
},
{
"input": "79\n",
"output": "1\n79",
"type": "stdin_stdout"
},
{
"input": "585\n",
"output": "3\n3 5 577",
"type": "stdin_stdout"
},
{
"input": "245\n",
"output": "3\n2 2 241",
"type": "stdin_stdout"
},
{
"input": "793\n",
"output": "3\n3 3 787",
"type": "stdin_stdout"
},
{
"input": "133\n",
"output": "2\n2 131",
"type": "stdin_stdout"
},
{
"input": "681\n",
"output": "3\n2 2 677",
"type": "stdin_stdout"
},
{
"input": "981399\n",
"output": "2\n2 981397",
"type": "stdin_stdout"
},
{
"input": "867773\n",
"output": "1\n867773",
"type": "stdin_stdout"
},
{
"input": "654141\n",
"output": "3\n3 11 654127",
"type": "stdin_stdout"
},
{
"input": "202985\n",
"output": "3\n2 2 202981",
"type": "stdin_stdout"
},
{
"input": "784533\n",
"output": "3\n3 17 784513",
"type": "stdin_stdout"
},
{
"input": "370359\n",
"output": "3\n19 79 370261",
"type": "stdin_stdout"
},
{
"input": "396831\n",
"output": "3\n19 79 396733",
"type": "stdin_stdout"
},
{
"input": "492211\n",
"output": "3\n19 79 492113",
"type": "stdin_stdout"
},
{
"input": "838347\n",
"output": "3\n19 79 838249",
"type": "stdin_stdout"
},
{
"input": "1098945\n",
"output": "3\n19 79 1098847",
"type": "stdin_stdout"
},
{
"input": "1313565\n",
"output": "3\n19 79 1313467",
"type": "stdin_stdout"
},
{
"input": "1349631\n",
"output": "3\n19 79 1349533",
"type": "stdin_stdout"
},
{
"input": "1357299\n",
"output": "3\n19 79 1357201",
"type": "stdin_stdout"
},
{
"input": "1357323\n",
"output": "3\n13 109 1357201",
"type": "stdin_stdout"
},
{
"input": "1357329\n",
"output": "3\n19 109 1357201",
"type": "stdin_stdout"
},
{
"input": "1388581\n",
"output": "3\n19 79 1388483",
"type": "stdin_stdout"
},
{
"input": "5275\n",
"output": "2\n2 5273",
"type": "stdin_stdout"
},
{
"input": "9515\n",
"output": "3\n2 2 9511",
"type": "stdin_stdout"
},
{
"input": "7847\n",
"output": "3\n3 3 7841",
"type": "stdin_stdout"
},
{
"input": "7077\n",
"output": "3\n3 5 7069",
"type": "stdin_stdout"
},
{
"input": "9531\n",
"output": "3\n3 7 9521",
"type": "stdin_stdout"
},
{
"input": "7865\n",
"output": "3\n5 7 7853",
"type": "stdin_stdout"
},
{
"input": "9675\n",
"output": "3\n3 11 9661",
"type": "stdin_stdout"
},
{
"input": "8909\n",
"output": "3\n3 13 8893",
"type": "stdin_stdout"
},
{
"input": "7147\n",
"output": "3\n5 13 7129",
"type": "stdin_stdout"
},
{
"input": "8487\n",
"output": "3\n3 17 8467",
"type": "stdin_stdout"
},
{
"input": "436273289\n",
"output": "3\n3 277 436273009",
"type": "stdin_stdout"
},
{
"input": "649580445\n",
"output": "3\n3 271 649580171",
"type": "stdin_stdout"
},
{
"input": "944193065\n",
"output": "3\n7 251 944192807",
"type": "stdin_stdout"
},
{
"input": "630045387\n",
"output": "3\n11 239 630045137",
"type": "stdin_stdout"
},
{
"input": "931103229\n",
"output": "3\n3 223 931103003",
"type": "stdin_stdout"
},
{
"input": "950664039\n",
"output": "3\n3 197 950663839",
"type": "stdin_stdout"
},
{
"input": "996104777\n",
"output": "3\n7 173 996104597",
"type": "stdin_stdout"
},
{
"input": "997255617\n",
"output": "3\n7 157 997255453",
"type": "stdin_stdout"
},
{
"input": "999962901\n",
"output": "3\n19 109 999962773",
"type": "stdin_stdout"
},
{
"input": "999995529\n",
"output": "3\n19 79 999995431",
"type": "stdin_stdout"
},
{
"input": "999995339\n",
"output": "3\n5 43 999995291",
"type": "stdin_stdout"
},
{
"input": "999998367\n",
"output": "3\n5 23 999998339",
"type": "stdin_stdout"
},
{
"input": "999999891\n",
"output": "3\n3 5 999999883",
"type": "stdin_stdout"
},
{
"input": "999999935\n",
"output": "3\n3 3 999999929",
"type": "stdin_stdout"
},
{
"input": "999999755\n",
"output": "3\n2 2 999999751",
"type": "stdin_stdout"
},
{
"input": "999999759\n",
"output": "2\n2 999999757",
"type": "stdin_stdout"
},
{
"input": "999999191\n",
"output": "1\n999999191",
"type": "stdin_stdout"
},
{
"input": "999999999\n",
"output": "3\n3 59 999999937",
"type": "stdin_stdout"
},
{
"input": "409449117\n",
"output": "3\n2 2 409449113",
"type": "stdin_stdout"
},
{
"input": "882499837\n",
"output": "3\n3 3 882499831",
"type": "stdin_stdout"
},
{
"input": "765615965\n",
"output": "3\n5 23 765615937",
"type": "stdin_stdout"
},
{
"input": "648732093\n",
"output": "3\n3 11 648732079",
"type": "stdin_stdout"
},
{
"input": "826815517\n",
"output": "3\n3 11 826815503",
"type": "stdin_stdout"
},
{
"input": "4898941\n",
"output": "2\n2 4898939",
"type": "stdin_stdout"
},
{
"input": "182982365\n",
"output": "3\n5 13 182982347",
"type": "stdin_stdout"
},
{
"input": "66098493\n",
"output": "3\n3 41 66098449",
"type": "stdin_stdout"
},
{
"input": "539149213\n",
"output": "1\n539149213",
"type": "stdin_stdout"
},
{
"input": "655957385\n",
"output": "3\n3 13 655957369",
"type": "stdin_stdout"
},
{
"input": "199999581\n",
"output": "3\n19 79 199999483",
"type": "stdin_stdout"
},
{
"input": "199998345\n",
"output": "3\n19 79 199998247",
"type": "stdin_stdout"
},
{
"input": "199991935\n",
"output": "3\n19 79 199991837",
"type": "stdin_stdout"
},
{
"input": "199986207\n",
"output": "3\n19 79 199986109",
"type": "stdin_stdout"
},
{
"input": "499991589\n",
"output": "3\n19 79 499991491",
"type": "stdin_stdout"
},
{
"input": "499984689\n",
"output": "3\n19 79 499984591",
"type": "stdin_stdout"
},
{
"input": "499984159\n",
"output": "3\n19 79 499984061",
"type": "stdin_stdout"
},
{
"input": "499966179\n",
"output": "3\n19 79 499966081",
"type": "stdin_stdout"
},
{
"input": "999995529\n",
"output": "3\n19 79 999995431",
"type": "stdin_stdout"
},
{
"input": "999995085\n",
"output": "3\n19 79 999994987",
"type": "stdin_stdout"
},
{
"input": "999991817\n",
"output": "3\n11 137 999991669",
"type": "stdin_stdout"
},
{
"input": "999991797\n",
"output": "3\n19 109 999991669",
"type": "stdin_stdout"
},
{
"input": "999991791\n",
"output": "3\n13 109 999991669",
"type": "stdin_stdout"
},
{
"input": "748859699\n",
"output": "3\n3 3 748859693",
"type": "stdin_stdout"
},
{
"input": "323845235\n",
"output": "3\n3 3 323845229",
"type": "stdin_stdout"
},
{
"input": "462409937\n",
"output": "3\n2 2 462409933",
"type": "stdin_stdout"
},
{
"input": "618047403\n",
"output": "3\n3 13 618047387",
"type": "stdin_stdout"
},
{
"input": "501148647\n",
"output": "3\n2 2 501148643",
"type": "stdin_stdout"
},
{
"input": "998017623\n",
"output": "2\n2 998017621",
"type": "stdin_stdout"
},
{
"input": "436273289\n",
"output": "3\n3 277 436273009",
"type": "stdin_stdout"
},
{
"input": "999999965\n",
"output": "3\n5 23 999999937",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "1\n5",
"type": "stdin_stdout"
},
{
"input": "1000037\n",
"output": "1\n1000037",
"type": "stdin_stdout"
},
{
"input": "989898987\n",
"output": "3\n2 2 989898983",
"type": "stdin_stdout"
},
{
"input": "999999999\n",
"output": "3\n3 59 999999937",
"type": "stdin_stdout"
},
{
"input": "100000003\n",
"output": "3\n3 11 99999989",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/584/D"
} | vfc_10050 |
apps | verifiable_code | 75 | Solve the following coding problem using the programming language python:
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.
You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall.
-----Input-----
The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field.
The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall.
-----Output-----
If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).
Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them.
-----Examples-----
Input
3 4
.*..
....
.*..
Output
YES
1 2
Input
3 3
..*
.*.
*..
Output
NO
Input
6 5
..*..
..*..
*****
..*..
..*..
..*..
Output
YES
3 3
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()))
p = []
ans = 0
for i in range(n):
s = input()
ans += s.count('*')
p.append(s)
dp = []
for i in range(n):
dp.append([0] * m)
for i in range(n):
col = p[i].count('*')
for t in range(m):
dp[i][t] = col
for i in range(m):
col = 0
for t in range(n):
if p[t][i] == '*':
col += 1
for t in range(n):
dp[t][i] += col
f = False
for i in range(n):
for t in range(m):
if dp[i][t] - int(p[i][t] == '*') == ans:
f = True
print('YES')
print(i + 1, t + 1)
break
if f:
break
if not f:
print('NO')
``` | {
"language": "python",
"test_cases": [
{
"input": "3 4\n.*..\n....\n.*..\n",
"output": "YES\n1 2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n..*\n.*.\n*..\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n",
"output": "YES\n3 3\n",
"type": "stdin_stdout"
},
{
"input": "1 10\n**********\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "10 1\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n.........*\n.........*\n........**\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n",
"output": "YES\n3 10\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n..........\n..........\n....*.....\n..........\n..........\n**..*.****\n....*.....\n....*.....\n....*.....\n..........\n",
"output": "YES\n6 5\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n.........*\n",
"output": "YES\n1 10\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n..........\n..........\n....*.....\n..........\n..........\n..........\n....*.....\n....*.....\n....*.....\n..........\n",
"output": "YES\n1 5\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n..........\n..........\n.**....***\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n3 2\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n..........\n..........\n..........\n..........\n..........\n***.*.****\n..........\n..........\n..........\n..........\n",
"output": "YES\n6 1\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n........*.\n*.........\n........*.\n........*.\n..........\n..........\n..........\n........*.\n.....*..*.\n***.......\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n...*......\n..........\n.......*..\n.*........\n******.*.*\n.*........\n..........\n..........\n..........\n..........\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n....\n....\n....\n....\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n.*\n*.\n",
"output": "YES\n2 2\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n....\n...*\n....\n*..*\n",
"output": "YES\n4 4\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n*...\n*...\n....\n****\n",
"output": "YES\n4 1\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n..*.\n....\n...*\n....\n",
"output": "YES\n3 3\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n***.\n....\n*...\n....\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n*\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n.\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n.*\n",
"output": "YES\n1 2\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n...\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n.\n*\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n**\n**\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n*.*\n...\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n*\n*\n*\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n*.\n.*\n.*\n",
"output": "YES\n1 2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n***\n***\n***\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 20\n....................\n.........*..........\n....................\n....................\n....................\n....................\n....................\n....................\n...*................\n....................\n",
"output": "YES\n9 10\n",
"type": "stdin_stdout"
},
{
"input": "10 20\n....................\n.........*..........\n....................\n....................\n....................\n....................\n....................\n....................\n...*..............*.\n....................\n",
"output": "YES\n9 10\n",
"type": "stdin_stdout"
},
{
"input": "10 20\n....................\n.........*..........\n....................\n....................\n....................\n....................\n....................\n....................\n...*..............*.\n.........*..........\n",
"output": "YES\n9 10\n",
"type": "stdin_stdout"
},
{
"input": "10 20\n....................\n.........*..........\n....................\n....................\n....................\n....................\n....................\n....................\n...*.....*........*.\n.........*..........\n",
"output": "YES\n9 10\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n..\n.*\n",
"output": "YES\n1 2\n",
"type": "stdin_stdout"
},
{
"input": "6 5\n..*..\n..*..\n**.**\n..*..\n..*..\n..*..\n",
"output": "YES\n3 3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n.*.\n*.*\n.*.\n",
"output": "YES\n2 2\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n*...\n....\n....\n...*\n",
"output": "YES\n4 1\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n...*\n...*\n",
"output": "YES\n1 4\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n..\n..\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n...*\n....\n....\n*...\n",
"output": "YES\n4 4\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n....\n..*.\n....\n",
"output": "YES\n1 3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n..*\n.*.\n..*\n",
"output": "YES\n2 3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n...\n...\n...\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n*.\n.*\n",
"output": "YES\n2 1\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n...*...\n...*...\n...*...\n..*.*..\n...*...\n",
"output": "YES\n4 4\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n....\n.*..\n..*.\n....\n",
"output": "YES\n3 2\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n.*\n*.\n.*\n",
"output": "YES\n2 2\n",
"type": "stdin_stdout"
},
{
"input": "3 12\n...**.......\n.....**.....\n........*...\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n***\n.*.\n.*.\n",
"output": "YES\n1 2\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n*.*.\n..*.\n.***\n..*.\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n..*\n**.\n",
"output": "YES\n2 3\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n.....\n.....\n..*..\n.....\n.....\n",
"output": "YES\n1 3\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n*.\n.*\n*.\n",
"output": "YES\n2 1\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n.....\n.....\n.....\n.....\n.....\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n..*.\n**.*\n..*.\n..*.\n",
"output": "YES\n2 3\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n....\n....\n..*.\n....\n",
"output": "YES\n1 3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n*..\n*..\n***\n",
"output": "YES\n3 1\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n...\n*.*\n.*.\n",
"output": "YES\n2 2\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n..\n..\n**\n",
"output": "YES\n3 1\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n...*\n...*\n...*\n",
"output": "YES\n1 4\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n.***\n*...\n*...\n*...\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n..*..\n..*..\n**.**\n..*..\n..*..\n",
"output": "YES\n3 3\n",
"type": "stdin_stdout"
},
{
"input": "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*.*\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n...\n.*.\n..*\n",
"output": "YES\n3 2\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n....*\n....*\n....*\n",
"output": "YES\n1 5\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n...\n...\n.*.\n",
"output": "YES\n1 2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n*.*\n.*.\n...\n",
"output": "YES\n1 2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n*..\n...\n..*\n",
"output": "YES\n3 1\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n..*\n..*\n",
"output": "YES\n1 3\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n**\n.*\n",
"output": "YES\n1 2\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n.....\n..*..\n.*.*.\n..*..\n.....\n",
"output": "YES\n3 3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n.*.\n..*\n...\n",
"output": "YES\n2 2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n..*\n*..\n*..\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n...\n.*.\n...\n",
"output": "YES\n1 2\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n....\n....\n....\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n..........\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n.*..\n*.**\n.*..\n.*..\n.*..\n",
"output": "YES\n2 2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n..*\n*..\n...\n",
"output": "YES\n2 3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n*..\n.*.\n...\n",
"output": "YES\n2 1\n",
"type": "stdin_stdout"
},
{
"input": "6 5\n*.*..\n..*..\n*****\n..*..\n..*..\n..*..\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n.*..\n*.**\n....\n.*..\n",
"output": "YES\n2 2\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n....*\n....*\n*****\n",
"output": "YES\n3 5\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n..*\n*..\n..*\n",
"output": "YES\n2 3\n",
"type": "stdin_stdout"
},
{
"input": "6 6\n..*...\n......\n......\n......\n......\n*....*\n",
"output": "YES\n6 3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n***\n.*.\n...\n",
"output": "YES\n1 2\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n.*..\n*...\n.*..\n.*..\n",
"output": "YES\n2 2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n...\n..*\n.*.\n",
"output": "YES\n3 3\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n.*\n*.\n*.\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n**\n.*\n.*\n.*\n",
"output": "YES\n1 2\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n*...*\n.....\n.....\n.....\n..*..\n",
"output": "YES\n1 3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n**.\n...\n..*\n",
"output": "YES\n1 3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n*.*\n*..\n*.*\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n....\n....\n*..*\n....\n.*..\n",
"output": "YES\n3 2\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n...*.\n...*.\n...*.\n...*.\n***.*\n",
"output": "YES\n5 4\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n*****\n*****\n*****\n*****\n*****\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n.*.\n*..\n...\n",
"output": "YES\n2 2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n.*.\n..*\n.*.\n",
"output": "YES\n2 2\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n.*.\n.*.\n.*.\n***\n...\n",
"output": "YES\n4 2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n*.*\n...\n*.*\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n.*.\n*.*\n",
"output": "YES\n2 2\n",
"type": "stdin_stdout"
},
{
"input": "3 10\n.......*..\n........*.\n.........*\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n*..\n**.\n...\n",
"output": "YES\n2 1\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n.*.\n.*.\n.**\n",
"output": "YES\n3 2\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n....\n....\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n*...\n....\n....\n..**\n",
"output": "YES\n4 1\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n****\n****\n****\n****\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n.*...\n.....\n...*.\n...*.\n.....\n",
"output": "YES\n1 4\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n.*\n.*\n*.\n",
"output": "YES\n3 2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n..*\n..*\n**.\n",
"output": "YES\n3 3\n",
"type": "stdin_stdout"
},
{
"input": "6 3\n...\n...\n...\n...\n**.\n.*.\n",
"output": "YES\n5 2\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n****\n..*.\n..*.\n",
"output": "YES\n1 3\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n*..*.\n.....\n.....\n.....\n...*.\n",
"output": "YES\n1 4\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n.*..\n*.**\n....\n",
"output": "YES\n2 2\n",
"type": "stdin_stdout"
},
{
"input": "6 5\n..*..\n..*..\n.*...\n..*..\n..*..\n..*..\n",
"output": "YES\n3 3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/699/B"
} | vfc_10054 |
apps | verifiable_code | 76 | Solve the following coding problem using the programming language python:
Berland Football Cup starts really soon! Commentators from all over the world come to the event.
Organizers have already built $n$ commentary boxes. $m$ regional delegations will come to the Cup. Every delegation should get the same number of the commentary boxes. If any box is left unoccupied then the delegations will be upset. So each box should be occupied by exactly one delegation.
If $n$ is not divisible by $m$, it is impossible to distribute the boxes to the delegations at the moment.
Organizers can build a new commentary box paying $a$ burles and demolish a commentary box paying $b$ burles. They can both build and demolish boxes arbitrary number of times (each time paying a corresponding fee). It is allowed to demolish all the existing boxes.
What is the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$)?
-----Input-----
The only line contains four integer numbers $n$, $m$, $a$ and $b$ ($1 \le n, m \le 10^{12}$, $1 \le a, b \le 100$), where $n$ is the initial number of the commentary boxes, $m$ is the number of delegations to come, $a$ is the fee to build a box and $b$ is the fee to demolish a box.
-----Output-----
Output the minimal amount of burles organizers should pay to satisfy all the delegations (i.e. to make the number of the boxes be divisible by $m$). It is allowed that the final number of the boxes is equal to $0$.
-----Examples-----
Input
9 7 3 8
Output
15
Input
2 7 3 7
Output
14
Input
30 6 17 19
Output
0
-----Note-----
In the first example organizers can build $5$ boxes to make the total of $14$ paying $3$ burles for the each of them.
In the second example organizers can demolish $2$ boxes to make the total of $0$ paying $7$ burles for the each of them.
In the third example organizers are already able to distribute all the boxes equally among the delegations, each one get $5$ boxes.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, m, a, b = list(map(int, input().split()))
k = n%m
print(min(k*b, (m - k)*a))
``` | {
"language": "python",
"test_cases": [
{
"input": "9 7 3 8\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "2 7 3 7\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "30 6 17 19\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "500000000001 1000000000000 100 100\n",
"output": "49999999999900\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 750000000001 10 100\n",
"output": "5000000000020\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 750000000001 100 10\n",
"output": "2499999999990\n",
"type": "stdin_stdout"
},
{
"input": "42 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000000 1 100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "7 2 3 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "999999999 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "999999999999 10000000007 100 100\n",
"output": "70100\n",
"type": "stdin_stdout"
},
{
"input": "10000000001 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "29 6 1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "99999999999 6 100 100\n",
"output": "300\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 7 3 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "99999999999 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "999999999999 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "9 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "17 4 5 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "100000000000 3 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 7 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 3 100 100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "70 3 10 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 3 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "804289377 846930887 78 16\n",
"output": "3326037780\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 9 55 55\n",
"output": "55\n",
"type": "stdin_stdout"
},
{
"input": "957747787 424238336 87 93\n",
"output": "10162213695\n",
"type": "stdin_stdout"
},
{
"input": "25 6 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "22 7 3 8\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10000000000 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "999999999999 2 10 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "999999999999 2 100 100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100 3 3 8\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "99999 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 3 2 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 13 10 17\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "7 2 1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 3 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 2 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100 3 5 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "70 4 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 4 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6 7 41 42\n",
"output": "41\n",
"type": "stdin_stdout"
},
{
"input": "10 3 10 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 5 2 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 3 99 99\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "7 3 100 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7 2 100 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 1 23 33\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "30 7 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100 3 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "90001 300 100 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "13 4 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 6 1 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "50 4 5 100\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "999 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 2 5 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "20 3 3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3982258181 1589052704 87 20\n",
"output": "16083055460\n",
"type": "stdin_stdout"
},
{
"input": "100 3 1 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7 3 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "19 10 100 100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "23 3 100 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "25 7 100 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "100 9 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9999999999 2 1 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 2 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10000 3 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "22 7 1 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "100000000000 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "18 7 100 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10003 4 1 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3205261341 718648876 58 11\n",
"output": "3637324207\n",
"type": "stdin_stdout"
},
{
"input": "8 3 100 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "15 7 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 1 20 20\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "16 7 3 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "7 3 1 100\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "16 3 1 100\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "13 4 1 10\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 4 5 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "14 3 1 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 33 100 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "22 7 1 8\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 4 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6 4 2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "17 4 2 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7 3 100 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "702 7 3 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8 3 1 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 2 5 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "99 19 1 7\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "16 3 100 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 34 1 100\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100 33 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "15 4 4 10\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1144108931 470211273 45 79\n",
"output": "11993619960\n",
"type": "stdin_stdout"
},
{
"input": "2 3 3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "29 5 4 9\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "15 7 1 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1 3 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 12 2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1 2 3 4\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/990/A"
} | vfc_10058 |
apps | verifiable_code | 78 | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is constraints.
Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in exactly $T$ minutes.
In the player, Polycarp stores $n$ songs, each of which is characterized by two parameters: $t_i$ and $g_i$, where $t_i$ is the length of the song in minutes ($1 \le t_i \le 15$), $g_i$ is its genre ($1 \le g_i \le 3$).
Polycarp wants to create such a playlist so that he can listen to music all the time on the way from the university to his home, and at the time of his arrival home, the playlist is over. Polycarp never interrupts songs and always listens to them from beginning to end. Thus, if he started listening to the $i$-th song, he would spend exactly $t_i$ minutes on its listening. Polycarp also does not like when two songs of the same genre play in a row (i.e. successively/adjacently) or when the songs in his playlist are repeated.
Help Polycarpus count the number of different sequences of songs (their order matters), the total duration is exactly $T$, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different.
-----Input-----
The first line of the input contains two integers $n$ and $T$ ($1 \le n \le 15, 1 \le T \le 225$) — the number of songs in the player and the required total duration, respectively.
Next, the $n$ lines contain descriptions of songs: the $i$-th line contains two integers $t_i$ and $g_i$ ($1 \le t_i \le 15, 1 \le g_i \le 3$) — the duration of the $i$-th song and its genre, respectively.
-----Output-----
Output one integer — the number of different sequences of songs, the total length of exactly $T$, such that there are no two consecutive songs of the same genre in them and all the songs in the playlist are different. Since the answer may be huge, output it modulo $10^9 + 7$ (that is, the remainder when dividing the quantity by $10^9 + 7$).
-----Examples-----
Input
3 3
1 1
1 2
1 3
Output
6
Input
3 3
1 1
1 1
1 3
Output
2
Input
4 10
5 3
2 1
3 2
5 1
Output
10
-----Note-----
In the first example, Polycarp can make any of the $6$ possible playlist by rearranging the available songs: $[1, 2, 3]$, $[1, 3, 2]$, $[2, 1, 3]$, $[2, 3, 1]$, $[3, 1, 2]$ and $[3, 2, 1]$ (indices of the songs are given).
In the second example, the first and second songs cannot go in succession (since they have the same genre). Thus, Polycarp can create a playlist in one of $2$ possible ways: $[1, 3, 2]$ and $[2, 3, 1]$ (indices of the songs are given).
In the third example, Polycarp can make the following playlists: $[1, 2, 3]$, $[1, 3, 2]$, $[2, 1, 3]$, $[2, 3, 1]$, $[3, 1, 2]$, $[3, 2, 1]$, $[1, 4]$, $[4, 1]$, $[2, 3, 4]$ and $[4, 3, 2]$ (indices of the songs are given).
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 factorial
def lol(n):
if n == 1:
yield [0]
yield [1]
else:
for p in lol(n - 1):
p.append(0)
yield p
p[-1] = 1
yield p
p.pop()
def sp(g1, g2, g3, f):
if g1 == 0:
if g2 == g3:
return 2
elif abs(g2 - g3) == 1:
return 1
else:
return 0
elif g2 == 0:
if g1 == g3:
return 2
elif abs(g1 - g3) == 1:
return 1
else:
return 0
elif g3 == 0:
if g2 == g1:
return 2
elif abs(g2 - g1) == 1:
return 1
else:
return 0
else:
if f == 1:
b = sp(g1, g2 - 1, g3, 2)
c = sp(g1, g2, g3 - 1, 3)
return b + c
elif f == 2:
a = sp(g1 - 1, g2, g3, 1)
c = sp(g1, g2, g3 - 1, 3)
return a + c
elif f == 3:
a = sp(g1 - 1, g2, g3, 1)
b = sp(g1, g2 - 1, g3, 2)
return a + b
else:
a = sp(g1 - 1, g2, g3, 1)
b = sp(g1, g2 - 1, g3, 2)
c = sp(g1, g2, g3 - 1, 3)
return a + b + c
n, T = map(int, input().split())
S = []
cnt = 0
M = 10 ** 9 + 7
for i in range(n):
S.append(list(map(int, input().split())))
for p in lol(n):
d = 0
g1, g2, g3 = 0, 0, 0
for i in range(n):
if p[i]:
d += S[i][0]
if S[i][1] == 1:
g1 += 1
elif S[i][1] == 2:
g2 += 1
elif S[i][1] == 3:
g3 += 1
if d == T:
cnt += factorial(g1) * factorial(g2) * factorial(g3) * sp(g1, g2, g3, 0)
cnt %= M
print(cnt)
``` | {
"language": "python",
"test_cases": [
{
"input": "3 3\n1 1\n1 2\n1 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 1\n1 1\n1 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 10\n5 3\n2 1\n3 2\n5 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n1 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 15\n15 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 225\n15 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n1 2\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n1 1\n1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n3 1\n2 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n1 3\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n1 3\n1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n2 3\n3 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n1 1\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n2 2\n2 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n2 3\n2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n1 3\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 15\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 3\n1 3\n1 3\n1 3\n1 3\n",
"output": "420863916\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n1 1\n2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 5\n1 1\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 50\n9 1\n14 3\n6 1\n10 1\n5 1\n7 1\n6 2\n13 3\n7 3\n3 2\n4 1\n14 3\n2 2\n8 1\n5 3\n",
"output": "683736\n",
"type": "stdin_stdout"
},
{
"input": "15 200\n13 3\n13 2\n15 2\n15 2\n15 2\n13 3\n14 1\n14 3\n13 2\n14 3\n13 2\n13 2\n15 2\n15 2\n13 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n1 2\n1 3\n1 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n1 3\n1 3\n1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n3 3\n3 3\n3 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n1 1\n1 1\n1 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n2 2\n1 3\n2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n1 2\n2 1\n2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 3\n1 3\n1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n2 2\n1 3\n1 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n2 1\n3 3\n2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n1 2\n1 3\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n1 1\n1 3\n2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n2 2\n1 3\n3 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n1 3\n1 1\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n2 2\n2 2\n2 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n2 3\n2 2\n2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n1 3\n1 2\n1 1\n1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n1 1\n2 2\n2 1\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n3 2\n3 1\n2 1\n3 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n1 3\n1 2\n1 3\n1 2\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n2 3\n1 2\n1 1\n1 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n1 3\n3 2\n3 2\n3 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n1 2\n1 1\n1 2\n1 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n1 2\n1 2\n2 3\n2 3\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n3 1\n1 1\n1 2\n1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n1 3\n1 2\n1 3\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n2 1\n1 1\n2 2\n1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n3 2\n2 2\n3 2\n2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n1 2\n1 2\n1 2\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n2 1\n1 2\n1 3\n1 3\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n2 3\n1 2\n2 3\n3 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n1 3\n1 3\n1 1\n1 2\n1 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n2 1\n2 2\n1 3\n2 3\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n1 3\n2 3\n3 2\n2 3\n1 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n1 2\n1 3\n1 1\n1 1\n1 3\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n2 2\n2 2\n2 2\n1 2\n2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n2 2\n1 3\n1 1\n1 3\n2 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n1 3\n1 2\n1 1\n1 3\n1 1\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n1 1\n2 1\n2 3\n2 1\n2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n3 1\n2 2\n2 2\n3 1\n2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n1 2\n1 3\n1 1\n1 1\n1 3\n",
"output": "56\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n2 2\n1 1\n1 3\n1 2\n1 3\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n3 3\n1 3\n1 1\n1 1\n3 2\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n1 1\n1 1\n1 3\n1 1\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n1 3\n1 3\n2 1\n1 2\n2 3\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n3 2\n3 1\n2 2\n1 1\n2 3\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "2 5\n2 2\n2 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 70\n7 3\n13 3\n13 1\n15 2\n3 1\n10 2\n3 3\n9 2\n13 3\n13 3\n11 2\n5 1\n8 2\n4 1\n15 2\n",
"output": "2141640\n",
"type": "stdin_stdout"
},
{
"input": "15 130\n14 2\n13 3\n14 1\n8 3\n9 3\n15 2\n10 2\n10 2\n4 2\n4 2\n12 1\n12 2\n6 3\n3 3\n10 1\n",
"output": "159107833\n",
"type": "stdin_stdout"
},
{
"input": "15 150\n12 1\n11 1\n7 1\n11 3\n9 2\n2 3\n5 1\n5 3\n9 3\n15 2\n11 1\n1 1\n13 3\n8 3\n4 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 180\n13 1\n15 1\n14 3\n5 1\n3 2\n7 2\n14 1\n3 1\n6 3\n7 1\n10 3\n12 1\n8 1\n14 2\n4 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 200\n11 2\n1 2\n1 1\n1 1\n4 2\n4 2\n7 1\n1 2\n7 1\n8 1\n14 3\n11 3\n15 3\n15 2\n15 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 49\n3 1\n14 3\n9 1\n8 1\n14 2\n5 1\n14 3\n10 3\n9 3\n9 1\n8 3\n2 1\n10 2\n4 3\n6 1\n",
"output": "57996\n",
"type": "stdin_stdout"
},
{
"input": "15 225\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": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 15\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": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 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": "15\n",
"type": "stdin_stdout"
},
{
"input": "15 2\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": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 10\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n",
"output": "33868800\n",
"type": "stdin_stdout"
},
{
"input": "15 20\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 30\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 40\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 50\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 225\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n1 2\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 10\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n",
"output": "486518400\n",
"type": "stdin_stdout"
},
{
"input": "15 20\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 30\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 40\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 50\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 225\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n1 1\n1 2\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 112\n15 3\n15 2\n13 2\n12 2\n12 1\n15 3\n13 3\n15 2\n15 1\n14 2\n14 2\n14 2\n15 3\n13 3\n14 2\n",
"output": "1579680\n",
"type": "stdin_stdout"
},
{
"input": "15 113\n15 2\n13 1\n12 1\n12 1\n14 1\n13 1\n15 1\n12 1\n13 1\n12 1\n15 1\n15 1\n15 2\n12 1\n14 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 114\n15 2\n15 3\n15 3\n15 1\n15 1\n15 1\n15 2\n15 1\n15 2\n15 3\n15 2\n15 1\n15 1\n15 1\n15 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 90\n14 2\n15 2\n15 2\n14 2\n15 2\n14 2\n15 2\n14 2\n15 2\n15 1\n15 1\n14 1\n14 1\n14 1\n15 1\n",
"output": "720\n",
"type": "stdin_stdout"
},
{
"input": "15 78\n14 2\n15 2\n14 2\n15 1\n13 1\n13 1\n14 1\n13 1\n15 1\n14 1\n15 1\n15 1\n13 2\n14 1\n13 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 225\n14 1\n14 1\n15 3\n15 3\n15 3\n15 2\n14 3\n15 2\n14 1\n14 1\n14 1\n14 3\n14 2\n14 2\n14 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 5\n2 3\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "15 14\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 3\n1 3\n1 3\n1 3\n1 3\n",
"output": "733951888\n",
"type": "stdin_stdout"
},
{
"input": "15 13\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 3\n1 3\n1 3\n1 3\n1 3\n",
"output": "306303923\n",
"type": "stdin_stdout"
},
{
"input": "15 12\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 3\n1 3\n1 3\n1 3\n1 3\n",
"output": "126975965\n",
"type": "stdin_stdout"
},
{
"input": "15 11\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 3\n1 3\n1 3\n1 3\n1 3\n",
"output": "758671993\n",
"type": "stdin_stdout"
},
{
"input": "15 10\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 3\n1 3\n1 3\n1 3\n1 3\n",
"output": "486518400\n",
"type": "stdin_stdout"
},
{
"input": "15 9\n1 1\n1 1\n1 1\n1 1\n1 1\n1 2\n1 2\n1 2\n1 2\n1 2\n1 3\n1 3\n1 3\n1 3\n1 3\n",
"output": "112838400\n",
"type": "stdin_stdout"
},
{
"input": "15 15\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 3\n1 3\n1 3\n1 3\n1 3\n1 3\n1 3\n1 3\n",
"output": "203212800\n",
"type": "stdin_stdout"
},
{
"input": "15 15\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n1 3\n1 3\n1 3\n1 3\n1 3\n1 3\n1 3\n",
"output": "66867193\n",
"type": "stdin_stdout"
},
{
"input": "15 15\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"output": "203212800\n",
"type": "stdin_stdout"
},
{
"input": "15 15\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 3\n1 3\n1 3\n1 3\n1 3\n1 3\n1 3\n1 3\n",
"output": "203212800\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n1 3\n2 3\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1185/G1"
} | vfc_10066 |
apps | verifiable_code | 79 | Solve the following coding problem using the programming language python:
Vivek initially has an empty array $a$ and some integer constant $m$.
He performs the following algorithm: Select a random integer $x$ uniformly in range from $1$ to $m$ and append it to the end of $a$. Compute the greatest common divisor of integers in $a$. In case it equals to $1$, break Otherwise, return to step $1$.
Find the expected length of $a$. It can be shown that it can be represented as $\frac{P}{Q}$ where $P$ and $Q$ are coprime integers and $Q\neq 0 \pmod{10^9+7}$. Print the value of $P \cdot Q^{-1} \pmod{10^9+7}$.
-----Input-----
The first and only line contains a single integer $m$ ($1 \leq m \leq 100000$).
-----Output-----
Print a single integer — the expected length of the array $a$ written as $P \cdot Q^{-1} \pmod{10^9+7}$.
-----Examples-----
Input
1
Output
1
Input
2
Output
2
Input
4
Output
333333338
-----Note-----
In the first example, since Vivek can choose only integers from $1$ to $1$, he will have $a=[1]$ after the first append operation, and after that quit the algorithm. Hence the length of $a$ is always $1$, so its expected value is $1$ as well.
In the second example, Vivek each time will append either $1$ or $2$, so after finishing the algorithm he will end up having some number of $2$'s (possibly zero), and a single $1$ in the end. The expected length of the list is $1\cdot \frac{1}{2} + 2\cdot \frac{1}{2^2} + 3\cdot \frac{1}{2^3} + \ldots = 2$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
big = 100010
def gen_mu():
mu = [1]*big
mu[0] = 0
P = [True]*big
P[0] = P[1] = False
for i in range(2,big):
if P[i]:
j = i
while j<big:
P[j] = False
mu[j] *= -1
j += i
j = i*i
while j<big:
mu[j] = 0
j += i*i
return mu
m = int(input())
mu = gen_mu()
MOD = 10**9+7
def mod_inv(x):
return pow(x, MOD-2, MOD)
s = 1
for i in range(2,big):
# p is probabilty that i | a random number [1,m]
p = (m//i)*mod_inv(m)
s += (-mu[i])*(p)*mod_inv(1-p)
print(s%MOD)
``` | {
"language": "python",
"test_cases": [
{
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n",
"output": "333333338\n",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "166666670\n",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "500000006\n",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "716666674\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "476190482\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "225000004\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "567460324\n",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "430555561\n",
"type": "stdin_stdout"
},
{
"input": "12\n",
"output": "318181823\n",
"type": "stdin_stdout"
},
{
"input": "100000\n",
"output": "534174612\n",
"type": "stdin_stdout"
},
{
"input": "99991\n",
"output": "434191575\n",
"type": "stdin_stdout"
},
{
"input": "30030\n",
"output": "723188569\n",
"type": "stdin_stdout"
},
{
"input": "99594\n",
"output": "166105505\n",
"type": "stdin_stdout"
},
{
"input": "91402\n",
"output": "347601361\n",
"type": "stdin_stdout"
},
{
"input": "93493\n",
"output": "606807336\n",
"type": "stdin_stdout"
},
{
"input": "96917\n",
"output": "838672461\n",
"type": "stdin_stdout"
},
{
"input": "80555\n",
"output": "409222861\n",
"type": "stdin_stdout"
},
{
"input": "30238\n",
"output": "750441533\n",
"type": "stdin_stdout"
},
{
"input": "5447\n",
"output": "741627218\n",
"type": "stdin_stdout"
},
{
"input": "5714\n",
"output": "559826101\n",
"type": "stdin_stdout"
},
{
"input": "735\n",
"output": "607779919\n",
"type": "stdin_stdout"
},
{
"input": "64\n",
"output": "572467262\n",
"type": "stdin_stdout"
},
{
"input": "256\n",
"output": "927439938\n",
"type": "stdin_stdout"
},
{
"input": "2048\n",
"output": "665668016\n",
"type": "stdin_stdout"
},
{
"input": "32768\n",
"output": "645842651\n",
"type": "stdin_stdout"
},
{
"input": "65536\n",
"output": "458595757\n",
"type": "stdin_stdout"
},
{
"input": "23\n",
"output": "485745620\n",
"type": "stdin_stdout"
},
{
"input": "12167\n",
"output": "831671589\n",
"type": "stdin_stdout"
},
{
"input": "13\n",
"output": "468253974\n",
"type": "stdin_stdout"
},
{
"input": "14\n",
"output": "966666676\n",
"type": "stdin_stdout"
},
{
"input": "15\n",
"output": "553571435\n",
"type": "stdin_stdout"
},
{
"input": "16\n",
"output": "85780889\n",
"type": "stdin_stdout"
},
{
"input": "17\n",
"output": "519841276\n",
"type": "stdin_stdout"
},
{
"input": "18\n",
"output": "625000007\n",
"type": "stdin_stdout"
},
{
"input": "19\n",
"output": "984514841\n",
"type": "stdin_stdout"
},
{
"input": "20\n",
"output": "935537382\n",
"type": "stdin_stdout"
},
{
"input": "10609\n",
"output": "503257127\n",
"type": "stdin_stdout"
},
{
"input": "93179\n",
"output": "765292545\n",
"type": "stdin_stdout"
},
{
"input": "10859\n",
"output": "380490066\n",
"type": "stdin_stdout"
},
{
"input": "677\n",
"output": "948537108\n",
"type": "stdin_stdout"
},
{
"input": "919\n",
"output": "434774514\n",
"type": "stdin_stdout"
},
{
"input": "7635\n",
"output": "874467055\n",
"type": "stdin_stdout"
},
{
"input": "95835\n",
"output": "834924464\n",
"type": "stdin_stdout"
},
{
"input": "92138\n",
"output": "751784127\n",
"type": "stdin_stdout"
},
{
"input": "29019\n",
"output": "963174399\n",
"type": "stdin_stdout"
},
{
"input": "64444\n",
"output": "249303275\n",
"type": "stdin_stdout"
},
{
"input": "88373\n",
"output": "857337836\n",
"type": "stdin_stdout"
},
{
"input": "88439\n",
"output": "567687036\n",
"type": "stdin_stdout"
},
{
"input": "7710\n",
"output": "33998115\n",
"type": "stdin_stdout"
},
{
"input": "7404\n",
"output": "785109731\n",
"type": "stdin_stdout"
},
{
"input": "8616\n",
"output": "340579911\n",
"type": "stdin_stdout"
},
{
"input": "92386\n",
"output": "159998877\n",
"type": "stdin_stdout"
},
{
"input": "99622\n",
"output": "109597446\n",
"type": "stdin_stdout"
},
{
"input": "92171\n",
"output": "323804671\n",
"type": "stdin_stdout"
},
{
"input": "99360\n",
"output": "557358009\n",
"type": "stdin_stdout"
},
{
"input": "90661\n",
"output": "413855313\n",
"type": "stdin_stdout"
},
{
"input": "92213\n",
"output": "876201665\n",
"type": "stdin_stdout"
},
{
"input": "91068\n",
"output": "917827355\n",
"type": "stdin_stdout"
},
{
"input": "93378\n",
"output": "820319423\n",
"type": "stdin_stdout"
},
{
"input": "98179\n",
"output": "674222305\n",
"type": "stdin_stdout"
},
{
"input": "91286\n",
"output": "843541605\n",
"type": "stdin_stdout"
},
{
"input": "91568\n",
"output": "866047090\n",
"type": "stdin_stdout"
},
{
"input": "91086\n",
"output": "685679455\n",
"type": "stdin_stdout"
},
{
"input": "95539\n",
"output": "125860916\n",
"type": "stdin_stdout"
},
{
"input": "90740\n",
"output": "178533194\n",
"type": "stdin_stdout"
},
{
"input": "94998\n",
"output": "123894686\n",
"type": "stdin_stdout"
},
{
"input": "95042\n",
"output": "460012534\n",
"type": "stdin_stdout"
},
{
"input": "92239\n",
"output": "736315231\n",
"type": "stdin_stdout"
},
{
"input": "78088\n",
"output": "185311544\n",
"type": "stdin_stdout"
},
{
"input": "74792\n",
"output": "683829911\n",
"type": "stdin_stdout"
},
{
"input": "22028\n",
"output": "797695183\n",
"type": "stdin_stdout"
},
{
"input": "36884\n",
"output": "120075637\n",
"type": "stdin_stdout"
},
{
"input": "66917\n",
"output": "760262294\n",
"type": "stdin_stdout"
},
{
"input": "36312\n",
"output": "657550913\n",
"type": "stdin_stdout"
},
{
"input": "79162\n",
"output": "283204023\n",
"type": "stdin_stdout"
},
{
"input": "42626\n",
"output": "9522345\n",
"type": "stdin_stdout"
},
{
"input": "6752\n",
"output": "689855972\n",
"type": "stdin_stdout"
},
{
"input": "611\n",
"output": "328389339\n",
"type": "stdin_stdout"
},
{
"input": "2864\n",
"output": "225651508\n",
"type": "stdin_stdout"
},
{
"input": "9304\n",
"output": "891558121\n",
"type": "stdin_stdout"
},
{
"input": "1045\n",
"output": "883481609\n",
"type": "stdin_stdout"
},
{
"input": "9376\n",
"output": "362881216\n",
"type": "stdin_stdout"
},
{
"input": "8636\n",
"output": "768818941\n",
"type": "stdin_stdout"
},
{
"input": "75232\n",
"output": "376862836\n",
"type": "stdin_stdout"
},
{
"input": "48457\n",
"output": "559402589\n",
"type": "stdin_stdout"
},
{
"input": "60255\n",
"output": "917128937\n",
"type": "stdin_stdout"
},
{
"input": "54369\n",
"output": "200047474\n",
"type": "stdin_stdout"
},
{
"input": "46654\n",
"output": "500907462\n",
"type": "stdin_stdout"
},
{
"input": "83480\n",
"output": "124910318\n",
"type": "stdin_stdout"
},
{
"input": "22799\n",
"output": "767471115\n",
"type": "stdin_stdout"
},
{
"input": "68540\n",
"output": "291762913\n",
"type": "stdin_stdout"
},
{
"input": "47539\n",
"output": "442384963\n",
"type": "stdin_stdout"
},
{
"input": "64115\n",
"output": "570892404\n",
"type": "stdin_stdout"
},
{
"input": "41764\n",
"output": "65880203\n",
"type": "stdin_stdout"
},
{
"input": "99900\n",
"output": "313467660\n",
"type": "stdin_stdout"
},
{
"input": "99911\n",
"output": "55921825\n",
"type": "stdin_stdout"
},
{
"input": "99329\n",
"output": "635418994\n",
"type": "stdin_stdout"
},
{
"input": "99945\n",
"output": "47143644\n",
"type": "stdin_stdout"
},
{
"input": "99896\n",
"output": "423867335\n",
"type": "stdin_stdout"
},
{
"input": "99936\n",
"output": "129595366\n",
"type": "stdin_stdout"
},
{
"input": "82460\n",
"output": "79287597\n",
"type": "stdin_stdout"
},
{
"input": "74074\n",
"output": "472079813\n",
"type": "stdin_stdout"
},
{
"input": "55311\n",
"output": "341088608\n",
"type": "stdin_stdout"
},
{
"input": "15015\n",
"output": "618014296\n",
"type": "stdin_stdout"
},
{
"input": "77385\n",
"output": "724140171\n",
"type": "stdin_stdout"
},
{
"input": "86632\n",
"output": "626563584\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1139/D"
} | vfc_10070 |
apps | verifiable_code | 81 | Solve the following coding problem using the programming language python:
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher.
Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k$, he needs to choose the smallest one.
Given his mathematical talent, Neko had no trouble getting Wrong Answer on this problem. Can you help him solve it?
-----Input-----
The only line contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
Print the smallest non-negative integer $k$ ($k \ge 0$) such that the lowest common multiple of $a+k$ and $b+k$ is the smallest possible.
If there are many possible integers $k$ giving the same value of the least common multiple, print the smallest one.
-----Examples-----
Input
6 10
Output
2
Input
21 31
Output
9
Input
5 10
Output
0
-----Note-----
In the first test, one should choose $k = 2$, as the least common multiple of $6 + 2$ and $10 + 2$ is $24$, which is the smallest least common multiple possible.
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
a, b = list(map(int, input().split()))
if b < a:
a, b = b, a
if a == b:
print(0)
return
c = b - a
i = 1
ans = a * b // gcd(a, b)
def get(x):
A = (a + x - 1) // x * x
B = A - a + b
return A * B // gcd(A, B), A
r = 0
while i * i <= c:
if c % i == 0:
A, AA = get(i)
B, BB = get(c // i)
if A < ans:
ans = A
r = AA - a
if B < ans:
ans = B
r = BB - a
if A == ans:
r = min(r, AA - a)
if B == ans:
r = min(r, BB - a)
i += 1
print(r)
``` | {
"language": "python",
"test_cases": [
{
"input": "6 10\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "21 31\n",
"output": "9",
"type": "stdin_stdout"
},
{
"input": "5 10\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1924 5834\n",
"output": "31",
"type": "stdin_stdout"
},
{
"input": "9911 666013\n",
"output": "318140",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "69 4295\n",
"output": "2044",
"type": "stdin_stdout"
},
{
"input": "948248258 533435433\n",
"output": "296190217",
"type": "stdin_stdout"
},
{
"input": "953 1349\n",
"output": "235",
"type": "stdin_stdout"
},
{
"input": "999999973 800000007\n",
"output": "199999823",
"type": "stdin_stdout"
},
{
"input": "112342324 524224233\n",
"output": "299539585",
"type": "stdin_stdout"
},
{
"input": "1021211 59555555\n",
"output": "309115",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "199999943 999999973\n",
"output": "200000072",
"type": "stdin_stdout"
},
{
"input": "2 999999973\n",
"output": "191",
"type": "stdin_stdout"
},
{
"input": "199999973 99999937\n",
"output": "99",
"type": "stdin_stdout"
},
{
"input": "851187514 983401693\n",
"output": "74311739",
"type": "stdin_stdout"
},
{
"input": "414459569 161124945\n",
"output": "92209679",
"type": "stdin_stdout"
},
{
"input": "59774131 414357411\n",
"output": "11142525",
"type": "stdin_stdout"
},
{
"input": "588854730 468415815\n",
"output": "13339845",
"type": "stdin_stdout"
},
{
"input": "166027408 867208246\n",
"output": "67699538",
"type": "stdin_stdout"
},
{
"input": "416882693 26430642\n",
"output": "9064999",
"type": "stdin_stdout"
},
{
"input": "63906772 377040487\n",
"output": "40471133",
"type": "stdin_stdout"
},
{
"input": "573707893 93108818\n",
"output": "3010997",
"type": "stdin_stdout"
},
{
"input": "498599067 627630818\n",
"output": "17527937",
"type": "stdin_stdout"
},
{
"input": "41698727 40343\n",
"output": "19511",
"type": "stdin_stdout"
},
{
"input": "21184942 66889\n",
"output": "573052",
"type": "stdin_stdout"
},
{
"input": "584924132 27895\n",
"output": "34377766",
"type": "stdin_stdout"
},
{
"input": "34504222 65532\n",
"output": "54883",
"type": "stdin_stdout"
},
{
"input": "397410367 96163\n",
"output": "44330",
"type": "stdin_stdout"
},
{
"input": "772116208 99741\n",
"output": "703606",
"type": "stdin_stdout"
},
{
"input": "721896242 62189\n",
"output": "150930",
"type": "stdin_stdout"
},
{
"input": "480432805 79482\n",
"output": "480273841",
"type": "stdin_stdout"
},
{
"input": "526157284 30640\n",
"output": "8006",
"type": "stdin_stdout"
},
{
"input": "509022792 57335\n",
"output": "5508",
"type": "stdin_stdout"
},
{
"input": "13911 866384789\n",
"output": "488042",
"type": "stdin_stdout"
},
{
"input": "43736 145490995\n",
"output": "242015",
"type": "stdin_stdout"
},
{
"input": "27522 656219918\n",
"output": "38975",
"type": "stdin_stdout"
},
{
"input": "3904 787488950\n",
"output": "577695",
"type": "stdin_stdout"
},
{
"input": "64320 203032344\n",
"output": "17588",
"type": "stdin_stdout"
},
{
"input": "19430 993947341\n",
"output": "43194827",
"type": "stdin_stdout"
},
{
"input": "89229 680338802\n",
"output": "16502224",
"type": "stdin_stdout"
},
{
"input": "22648 30366541\n",
"output": "509701",
"type": "stdin_stdout"
},
{
"input": "89598 155519475\n",
"output": "1581691",
"type": "stdin_stdout"
},
{
"input": "80536 791328168\n",
"output": "4581",
"type": "stdin_stdout"
},
{
"input": "55138 453739731\n",
"output": "26632191",
"type": "stdin_stdout"
},
{
"input": "20827 81894\n",
"output": "40240",
"type": "stdin_stdout"
},
{
"input": "15162 60885\n",
"output": "79",
"type": "stdin_stdout"
},
{
"input": "33261 83156\n",
"output": "16634",
"type": "stdin_stdout"
},
{
"input": "12567 44055\n",
"output": "3177",
"type": "stdin_stdout"
},
{
"input": "36890 51759\n",
"output": "7717",
"type": "stdin_stdout"
},
{
"input": "69731 73202\n",
"output": "3160",
"type": "stdin_stdout"
},
{
"input": "92037 8625\n",
"output": "643",
"type": "stdin_stdout"
},
{
"input": "51783 5491\n",
"output": "6082",
"type": "stdin_stdout"
},
{
"input": "39204 15357\n",
"output": "8490",
"type": "stdin_stdout"
},
{
"input": "11 16\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "5 18\n",
"output": "8",
"type": "stdin_stdout"
},
{
"input": "1 113\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "18 102\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "13 33\n",
"output": "7",
"type": "stdin_stdout"
},
{
"input": "22 51\n",
"output": "7",
"type": "stdin_stdout"
},
{
"input": "1 114\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "10 12\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "24 9\n",
"output": "6",
"type": "stdin_stdout"
},
{
"input": "21 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5 14\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "273301753 369183717\n",
"output": "14344139",
"type": "stdin_stdout"
},
{
"input": "83893226 440673790\n",
"output": "5301915",
"type": "stdin_stdout"
},
{
"input": "391320363 805801085\n",
"output": "23160359",
"type": "stdin_stdout"
},
{
"input": "350089529 67401533\n",
"output": "3270466",
"type": "stdin_stdout"
},
{
"input": "356318639 545297094\n",
"output": "21638271",
"type": "stdin_stdout"
},
{
"input": "456039936 216657167\n",
"output": "22725602",
"type": "stdin_stdout"
},
{
"input": "200869227 429021875\n",
"output": "27283421",
"type": "stdin_stdout"
},
{
"input": "724338885 158040565\n",
"output": "125108595",
"type": "stdin_stdout"
},
{
"input": "354798648 439745337\n",
"output": "69934797",
"type": "stdin_stdout"
},
{
"input": "152408121 368230838\n",
"output": "63414596",
"type": "stdin_stdout"
},
{
"input": "532851498 235555724\n",
"output": "61740050",
"type": "stdin_stdout"
},
{
"input": "571244721 233692396\n",
"output": "103859929",
"type": "stdin_stdout"
},
{
"input": "434431270 432744926\n",
"output": "645482",
"type": "stdin_stdout"
},
{
"input": "845961672 92356861\n",
"output": "661247950",
"type": "stdin_stdout"
},
{
"input": "861681496 158472265\n",
"output": "75930812",
"type": "stdin_stdout"
},
{
"input": "358415973 475293324\n",
"output": "109093431",
"type": "stdin_stdout"
},
{
"input": "179237079 691088384\n",
"output": "332614226",
"type": "stdin_stdout"
},
{
"input": "159488527 938932258\n",
"output": "100326050",
"type": "stdin_stdout"
},
{
"input": "173726711 47100867\n",
"output": "16212055",
"type": "stdin_stdout"
},
{
"input": "113701457 374868637\n",
"output": "16882133",
"type": "stdin_stdout"
},
{
"input": "49160468 106133716\n",
"output": "7812780",
"type": "stdin_stdout"
},
{
"input": "258834406 21427940\n",
"output": "154466",
"type": "stdin_stdout"
},
{
"input": "209853278 238360826\n",
"output": "18207106",
"type": "stdin_stdout"
},
{
"input": "833630757 5203048\n",
"output": "823224661",
"type": "stdin_stdout"
},
{
"input": "898985699 25761857\n",
"output": "12204397",
"type": "stdin_stdout"
},
{
"input": "882561035 53440816\n",
"output": "775679403",
"type": "stdin_stdout"
},
{
"input": "844002269 45400923\n",
"output": "353899750",
"type": "stdin_stdout"
},
{
"input": "890747621 58942406\n",
"output": "107418637",
"type": "stdin_stdout"
},
{
"input": "823409948 63146277\n",
"output": "697117394",
"type": "stdin_stdout"
},
{
"input": "806104369 75421522\n",
"output": "5765461",
"type": "stdin_stdout"
},
{
"input": "950485973 21039711\n",
"output": "443683420",
"type": "stdin_stdout"
},
{
"input": "904189980 653467036\n",
"output": "98701796",
"type": "stdin_stdout"
},
{
"input": "986866706 981520552\n",
"output": "2171784",
"type": "stdin_stdout"
},
{
"input": "987324114 296975438\n",
"output": "48198900",
"type": "stdin_stdout"
},
{
"input": "932939238 454247778\n",
"output": "24443682",
"type": "stdin_stdout"
},
{
"input": "997908364 240589278\n",
"output": "138070265",
"type": "stdin_stdout"
},
{
"input": "2 3\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5 11\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "2 2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 6\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "6 9\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1000000000 264865600\n",
"output": "102701600",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1152/C"
} | vfc_10078 |
apps | verifiable_code | 82 | Solve the following coding problem using the programming language python:
Noora is a student of one famous high school. It's her final year in school — she is going to study in university next year. However, she has to get an «A» graduation certificate in order to apply to a prestigious one.
In school, where Noora is studying, teachers are putting down marks to the online class register, which are integers from 1 to k. The worst mark is 1, the best is k. Mark that is going to the certificate, is calculated as an average of all the marks, rounded to the closest integer. If several answers are possible, rounding up is produced. For example, 7.3 is rounded to 7, but 7.5 and 7.8784 — to 8.
For instance, if Noora has marks [8, 9], then the mark to the certificate is 9, because the average is equal to 8.5 and rounded to 9, but if the marks are [8, 8, 9], Noora will have graduation certificate with 8.
To graduate with «A» certificate, Noora has to have mark k.
Noora got n marks in register this year. However, she is afraid that her marks are not enough to get final mark k. Noora decided to ask for help in the internet, where hacker Leha immediately responded to her request. He is ready to hack class register for Noora and to add Noora any number of additional marks from 1 to k. At the same time, Leha want his hack be unseen to everyone, so he decided to add as less as possible additional marks. Please help Leha to calculate the minimal number of marks he has to add, so that final Noora's mark will become equal to k.
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 100, 1 ≤ k ≤ 100) denoting the number of marks, received by Noora and the value of highest possible mark.
The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ k) denoting marks received by Noora before Leha's hack.
-----Output-----
Print a single integer — minimal number of additional marks, that Leha has to add in order to change Noora's final mark to k.
-----Examples-----
Input
2 10
8 9
Output
4
Input
3 5
4 4 4
Output
3
-----Note-----
Consider the first example testcase.
Maximal mark is 10, Noora received two marks — 8 and 9, so current final mark is 9. To fix it, Leha can add marks [10, 10, 10, 10] (4 marks in total) to the registry, achieving Noora having average mark equal to $\frac{8 + 9 + 10 + 10 + 10 + 10}{6} = \frac{57}{6} = 9.5$. Consequently, new final mark is 10. Less number of marks won't fix the situation.
In the second example Leha can add [5, 5, 5] to the registry, so that making average mark equal to 4.5, which is enough to have 5 in the certificate.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
s = sum(a)
ans = 0
c = k - 0.5
while s / n < c:
s += k
n += 1
ans += 1
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "2 10\n8 9\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "3 5\n4 4 4\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "3 10\n10 8 9\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "2 23\n21 23\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "5 10\n5 10 10 9 10\n",
"output": "7",
"type": "stdin_stdout"
},
{
"input": "12 50\n18 10 26 22 22 23 14 21 27 18 25 12\n",
"output": "712",
"type": "stdin_stdout"
},
{
"input": "38 12\n2 7 10 8 5 3 5 6 3 6 5 1 9 7 7 8 3 4 4 4 5 2 3 6 6 1 6 7 4 4 8 7 4 5 3 6 6 6\n",
"output": "482",
"type": "stdin_stdout"
},
{
"input": "63 86\n32 31 36 29 36 26 28 38 39 32 29 26 33 38 36 38 36 28 43 48 28 33 25 39 39 27 34 25 37 28 40 26 30 31 42 32 36 44 29 36 30 35 48 40 26 34 30 33 33 46 42 24 36 38 33 51 33 41 38 29 29 32 28\n",
"output": "6469",
"type": "stdin_stdout"
},
{
"input": "100 38\n30 24 38 31 31 33 32 32 29 34 29 22 27 23 34 25 32 30 30 26 16 27 38 33 38 38 37 34 32 27 33 23 33 32 24 24 30 36 29 30 33 30 29 30 36 33 33 35 28 24 30 32 38 29 30 36 31 30 27 38 31 36 15 37 32 27 29 24 38 33 28 29 34 21 37 35 32 31 27 25 27 28 31 31 36 38 35 35 36 29 35 22 38 31 38 28 31 27 34 31\n",
"output": "1340",
"type": "stdin_stdout"
},
{
"input": "33 69\n60 69 68 69 69 60 64 60 62 59 54 47 60 62 69 69 69 58 67 69 62 69 68 53 69 69 66 66 57 58 65 69 61\n",
"output": "329",
"type": "stdin_stdout"
},
{
"input": "39 92\n19 17 16 19 15 30 21 25 14 17 19 19 23 16 14 15 17 19 29 15 11 25 19 14 18 20 10 16 11 15 18 20 20 17 18 16 12 17 16\n",
"output": "5753",
"type": "stdin_stdout"
},
{
"input": "68 29\n29 29 29 29 29 28 29 29 29 27 29 29 29 29 29 29 29 23 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 29 29 29 26 29 29 29 29 29 29 29 29 29 29 29 29 22 29 29 29 29 29 29 29 29 29 29 29 29 29 28 29 29 29 29\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "75 30\n22 18 21 26 23 18 28 30 24 24 19 25 28 30 23 29 18 23 23 30 26 30 17 30 18 19 25 26 26 15 27 23 30 21 19 26 25 30 25 28 20 22 22 21 26 17 23 23 24 15 25 19 18 22 30 30 29 21 30 28 28 30 27 25 24 15 22 19 30 21 20 30 18 20 25\n",
"output": "851",
"type": "stdin_stdout"
},
{
"input": "78 43\n2 7 6 5 5 6 4 5 3 4 6 8 4 5 5 4 3 1 2 4 4 6 5 6 4 4 6 4 8 4 6 5 6 1 4 5 6 3 2 5 2 5 3 4 8 8 3 3 4 4 6 6 5 4 5 5 7 9 3 9 6 4 7 3 6 9 6 5 1 7 2 5 6 3 6 2 5 4\n",
"output": "5884",
"type": "stdin_stdout"
},
{
"input": "82 88\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1\n",
"output": "14170",
"type": "stdin_stdout"
},
{
"input": "84 77\n28 26 36 38 37 44 48 34 40 22 42 35 40 37 30 31 33 35 36 55 47 36 33 47 40 38 27 38 36 33 35 31 47 33 30 38 38 47 49 24 38 37 28 43 39 36 34 33 29 38 36 43 48 38 36 34 33 34 35 31 26 33 39 37 37 37 35 52 47 30 24 46 38 26 43 46 41 50 33 40 36 41 37 30\n",
"output": "6650",
"type": "stdin_stdout"
},
{
"input": "94 80\n21 19 15 16 27 16 20 18 19 19 15 15 20 19 19 21 20 19 13 17 15 9 17 15 23 15 12 18 12 13 15 12 14 13 14 17 20 20 14 21 15 6 10 23 24 8 18 18 13 23 17 22 17 19 19 18 17 24 8 16 18 20 24 19 10 19 15 10 13 14 19 15 16 19 20 15 14 21 16 16 14 14 22 19 12 11 14 13 19 32 16 16 13 20\n",
"output": "11786",
"type": "stdin_stdout"
},
{
"input": "96 41\n13 32 27 34 28 34 30 26 21 24 29 20 25 34 25 16 27 15 22 22 34 22 25 19 23 17 17 22 26 24 23 20 21 27 19 33 13 24 22 18 30 30 27 14 26 24 20 20 22 11 19 31 19 29 18 28 30 22 17 15 28 32 17 24 17 24 24 19 26 23 22 29 18 22 23 29 19 32 26 23 22 22 24 23 27 30 24 25 21 21 33 19 35 27 34 28\n",
"output": "3182",
"type": "stdin_stdout"
},
{
"input": "1 26\n26\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "99 39\n25 28 30 28 32 34 31 28 29 28 29 30 33 19 33 31 27 33 29 24 27 30 25 38 28 34 35 31 34 37 30 22 21 24 34 27 34 33 34 33 26 26 36 19 30 22 35 30 21 28 23 35 33 29 21 22 36 31 34 32 34 32 30 32 27 33 38 25 35 26 39 27 29 29 19 33 28 29 34 38 26 30 36 26 29 30 26 34 22 32 29 38 25 27 24 17 25 28 26\n",
"output": "1807",
"type": "stdin_stdout"
},
{
"input": "100 12\n7 6 6 3 5 5 9 8 7 7 4 7 12 6 9 5 6 3 4 7 9 10 7 7 5 3 9 6 9 9 6 7 4 10 4 8 8 6 9 8 6 5 7 4 10 7 5 6 8 9 3 4 8 5 4 8 6 10 5 8 7 5 9 8 5 8 5 6 9 11 4 9 5 5 11 4 6 6 7 3 8 9 6 7 10 4 7 6 9 4 8 11 5 4 10 8 5 10 11 4\n",
"output": "946",
"type": "stdin_stdout"
},
{
"input": "100 18\n1 2 2 2 2 2 1 1 1 2 3 1 3 1 1 4 2 4 1 2 1 2 1 3 2 1 2 1 1 1 2 1 2 2 1 1 4 3 1 1 2 1 3 3 2 1 2 2 1 1 1 1 3 1 1 2 2 1 1 1 5 1 2 1 3 2 2 1 4 2 2 1 1 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 1 1 3 1 1 2 1 1 2\n",
"output": "3164",
"type": "stdin_stdout"
},
{
"input": "100 27\n16 20 21 10 16 17 18 25 19 18 20 12 11 21 21 23 20 26 20 21 27 16 25 18 25 21 27 12 20 27 18 17 27 13 21 26 12 22 15 21 25 21 18 27 24 15 16 18 23 21 24 27 19 17 24 14 21 16 24 26 13 14 25 18 27 26 22 16 27 27 17 25 17 12 22 10 19 27 19 20 23 22 25 23 17 25 14 20 22 10 22 27 21 20 15 26 24 27 12 16\n",
"output": "1262",
"type": "stdin_stdout"
},
{
"input": "100 29\n20 18 23 24 14 14 16 23 22 17 18 22 21 21 19 19 14 11 18 19 16 22 25 20 14 13 21 24 18 16 18 29 17 25 12 10 18 28 11 16 17 14 15 20 17 20 18 22 10 16 16 20 18 19 29 18 25 27 17 19 24 15 24 25 16 23 19 16 16 20 19 15 12 21 20 13 21 15 15 23 16 23 17 13 17 21 13 18 17 18 18 20 16 12 19 15 27 14 11 18\n",
"output": "2024",
"type": "stdin_stdout"
},
{
"input": "100 30\n16 10 20 11 14 27 15 17 22 26 24 17 15 18 19 22 22 15 21 22 14 21 22 22 21 22 15 17 17 22 18 19 26 18 22 20 22 25 18 18 17 23 18 18 20 13 19 30 17 24 22 19 29 20 20 21 17 18 26 25 22 19 15 18 18 20 19 19 18 18 24 16 19 17 12 21 20 16 23 21 16 17 26 23 25 28 22 20 9 21 17 24 15 19 17 21 29 13 18 15\n",
"output": "1984",
"type": "stdin_stdout"
},
{
"input": "100 59\n56 58 53 59 59 48 59 54 46 59 59 58 48 59 55 59 59 50 59 56 59 59 59 59 59 59 59 57 59 53 45 53 50 59 50 55 58 54 59 56 54 59 59 59 59 48 56 59 59 57 59 59 48 43 55 57 39 59 46 55 55 52 58 57 51 59 59 59 59 53 59 43 51 54 46 59 57 43 50 59 47 58 59 59 59 55 46 56 55 59 56 47 56 56 46 51 47 48 59 55\n",
"output": "740",
"type": "stdin_stdout"
},
{
"input": "100 81\n6 7 6 6 7 6 6 6 3 9 4 5 4 3 4 6 6 6 1 3 9 5 2 3 8 5 6 9 6 6 6 5 4 4 7 7 3 6 11 7 6 4 8 7 12 6 4 10 2 4 9 11 7 4 7 7 8 8 6 7 9 8 4 5 8 13 6 6 6 8 6 2 5 6 7 5 4 4 4 4 2 6 4 8 3 4 7 7 6 7 7 10 5 10 6 7 4 11 8 4\n",
"output": "14888",
"type": "stdin_stdout"
},
{
"input": "100 100\n30 35 23 43 28 49 31 32 30 44 32 37 33 34 38 28 43 32 33 32 50 32 41 38 33 20 40 36 29 21 42 25 23 34 43 32 37 31 30 27 36 32 45 37 33 29 38 34 35 33 28 19 37 33 28 41 31 29 41 27 32 39 30 34 37 40 33 38 35 32 32 34 35 34 28 39 28 34 40 45 31 25 42 28 29 31 33 21 36 33 34 37 40 42 39 30 36 34 34 40\n",
"output": "13118",
"type": "stdin_stdout"
},
{
"input": "100 100\n71 87 100 85 89 98 90 90 71 65 76 75 85 100 81 100 91 80 73 89 86 78 82 89 77 92 78 90 100 81 85 89 73 100 66 60 72 88 91 73 93 76 88 81 86 78 83 77 74 93 97 94 85 78 82 78 91 91 100 78 89 76 78 82 81 78 83 88 87 83 78 98 85 97 98 89 88 75 76 86 74 81 70 76 86 84 99 100 89 94 72 84 82 88 83 89 78 99 87 76\n",
"output": "3030",
"type": "stdin_stdout"
},
{
"input": "100 100\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": "19700",
"type": "stdin_stdout"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100 100\n1 1 2 1 1 1 1 1 1 1 1 1 1 2 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": "19696",
"type": "stdin_stdout"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 99\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100 100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 98 100 100 100 100 98 100 100 100 100 100 100 99 98 100 100 93 100 100 98 100 100 100 100 93 100 96 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 95 88 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100 100\n95 100 100 100 100 100 100 100 100 100 100 100 100 100 87 100 100 100 94 100 100 100 100 100 100 100 100 100 100 100 100 99 100 100 100 100 100 100 100 100 100 100 90 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 96 100 98 100 100 100 100 100 96 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 97 100 100 100 100\n",
"output": "2",
"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": "0",
"type": "stdin_stdout"
},
{
"input": "100 2\n2 1 1 2 1 1 1 1 2 2 2 2 1 1 1 2 1 1 1 2 2 2 2 1 1 1 1 2 2 2 1 2 2 2 2 1 2 2 1 1 1 1 1 1 2 2 1 2 1 1 1 2 1 2 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 2 2 1 1 1 2 2 1 1 2 1 1 2 1 1 1 2 1 1 1 1 2 1 1 1 1 2 1 2 1 1\n",
"output": "16",
"type": "stdin_stdout"
},
{
"input": "3 5\n5 5 5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "7 7\n1 1 1 1 1 1 1\n",
"output": "77",
"type": "stdin_stdout"
},
{
"input": "1 1\n1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100 100\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": "19700",
"type": "stdin_stdout"
},
{
"input": "4 10\n10 10 10 10\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1 10\n10\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "10 1\n1 1 1 1 1 1 1 1 1 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 10\n10 10 10\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 4\n3 4\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1 2\n2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 4\n4 4 4\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 2\n2 2 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5 5\n5 5 5 5 5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 3\n3 3 3\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 9\n8 9\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 10\n9 10 10\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1 3\n3\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 2\n1 2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 10\n10 10\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "23 14\n7 11 13 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14 14\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 10\n9 10\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 2\n2 2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "10 5\n5 5 5 5 5 5 5 5 5 4\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 5\n4 5 5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5 4\n4 4 4 4 4\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 10\n10 9\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4 5\n3 5 5 5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "10 5\n5 5 5 5 5 5 5 5 5 5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 10\n10 10 9\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5 1\n1 1 1 1 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 1\n1 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4 10\n9 10 10 10\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5 2\n2 2 2 2 2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 5\n4 5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5 10\n10 10 10 10 10\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 6\n6 6\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 9\n9 9\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 10\n10 9 10\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4 40\n39 40 40 40\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 4\n3 4 4\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "9 9\n9 9 9 9 9 9 9 9 9\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1 4\n4\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4 7\n1 1 1 1\n",
"output": "44",
"type": "stdin_stdout"
},
{
"input": "1 5\n5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 1\n1 1 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1 100\n100\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 7\n3 5\n",
"output": "10",
"type": "stdin_stdout"
},
{
"input": "3 6\n6 6 6\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4 2\n1 2 2 2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4 5\n4 5 5 5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5 5\n1 1 1 1 1\n",
"output": "35",
"type": "stdin_stdout"
},
{
"input": "66 2\n1 2 2 2 2 1 1 2 1 2 2 2 2 2 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 2 1 2 2 1 1 2 1 2 2 1 1 1 2 1 2 1 2 1 2 1 2 2 2 2 1 2 2 1 2 1 1 1 2 2 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 2\n2 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5 5\n5 5 5 4 5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 7\n1 1 1\n",
"output": "33",
"type": "stdin_stdout"
},
{
"input": "2 5\n5 5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1 7\n1\n",
"output": "11",
"type": "stdin_stdout"
},
{
"input": "6 7\n1 1 1 1 1 1\n",
"output": "66",
"type": "stdin_stdout"
},
{
"input": "99 97\n15 80 78 69 12 84 36 51 89 77 88 10 1 19 67 85 6 36 8 70 14 45 88 97 22 13 75 57 83 27 13 97 9 90 68 51 76 37 5 2 16 92 11 48 13 77 35 19 15 74 22 29 21 12 28 42 56 5 32 41 62 75 71 71 68 72 24 77 11 28 78 27 53 88 74 66 1 42 18 16 18 39 75 38 81 5 13 39 40 75 13 36 53 83 9 54 57 63 64\n",
"output": "10077",
"type": "stdin_stdout"
},
{
"input": "8 7\n1 1 1 1 1 1 1 1\n",
"output": "88",
"type": "stdin_stdout"
},
{
"input": "3 2\n2 2 2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "6 5\n5 5 5 5 5 5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "10 5\n5 5 5 5 5 5 5 4 1 1\n",
"output": "8",
"type": "stdin_stdout"
},
{
"input": "1 5\n1\n",
"output": "7",
"type": "stdin_stdout"
},
{
"input": "10 10\n10 10 10 10 10 10 10 10 10 10\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 3\n2 3\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1 9\n9\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "74 2\n2 2 2 2 1 2 2 1 1 1 2 2 1 2 2 2 2 1 2 1 1 1 2 1 1 2 2 1 2 1 1 2 1 1 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 1 1 2 1 1 1 1 1 1 2 2 2 1 1 1 1 1 2 2 2 2 2 2 1 2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5 5\n5 5 5 5 4\n",
"output": "0",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/810/A"
} | vfc_10082 |
apps | verifiable_code | 83 | Solve the following coding problem using the programming language python:
You are given an array of $n$ integers: $a_1, a_2, \ldots, a_n$. Your task is to find some non-zero integer $d$ ($-10^3 \leq d \leq 10^3$) such that, after each number in the array is divided by $d$, the number of positive numbers that are presented in the array is greater than or equal to half of the array size (i.e., at least $\lceil\frac{n}{2}\rceil$). Note that those positive numbers do not need to be an integer (e.g., a $2.5$ counts as a positive number). If there are multiple values of $d$ that satisfy the condition, you may print any of them. In case that there is no such $d$, print a single integer $0$.
Recall that $\lceil x \rceil$ represents the smallest integer that is not less than $x$ and that zero ($0$) is neither positive nor negative.
-----Input-----
The first line contains one integer $n$ ($1 \le n \le 100$) — the number of elements in the array.
The second line contains $n$ space-separated integers $a_1, a_2, \ldots, a_n$ ($-10^3 \le a_i \le 10^3$).
-----Output-----
Print one integer $d$ ($-10^3 \leq d \leq 10^3$ and $d \neq 0$) that satisfies the given condition. If there are multiple values of $d$ that satisfy the condition, you may print any of them. In case that there is no such $d$, print a single integer $0$.
-----Examples-----
Input
5
10 0 -7 2 6
Output
4
Input
7
0 0 1 -1 0 0 2
Output
0
-----Note-----
In the first sample, $n = 5$, so we need at least $\lceil\frac{5}{2}\rceil = 3$ positive numbers after division. If $d = 4$, the array after division is $[2.5, 0, -1.75, 0.5, 1.5]$, in which there are $3$ positive numbers (namely: $2.5$, $0.5$, and $1.5$).
In the second sample, there is no valid $d$, so $0$ should be printed.
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())
ar=list(map(int,input().split()))
pos=0
neg=0
for a in ar:
if(a>0):pos+=1
elif a<0:neg+=1
if(pos*2>=n):
print(1)
elif neg*2>=n:
print(-1)
else:
print(0)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n10 0 -7 2 6\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "7\n0 0 1 -1 0 0 2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 0 1 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1\n777\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "2\n1 0\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "100\n39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39 39\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "100\n-322 -198 -448 -249 -935 614 67 -679 -616 430 -71 818 -595 -22 559 -575 -710 50 -542 -144 -977 672 -826 -927 457 518 603 -287 689 -45 -770 208 360 -498 -884 -161 -831 -793 -991 -102 -706 338 298 -897 236 567 -22 577 -77 -481 376 -152 861 559 190 -662 432 -880 -839 737 857 -614 -670 -423 -320 -451 -733 -304 822 -316 52 46 -438 -427 601 -885 -644 518 830 -517 719 643 216 45 -15 382 411 -424 -649 286 -265 -49 704 661 -2 -992 67 -118 299 -420\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100\n621 862 494 -906 906 359 776 0 23 -868 863 -872 273 182 414 675 31 555 0 -423 468 517 577 892 117 664 292 11 105 589 173 455 711 358 229 -666 192 758 6 858 208 628 532 21 69 319 926 988 0 0 0 229 351 708 287 949 429 895 369 0 756 486 2 525 656 -906 742 284 174 510 747 227 274 103 50 -832 656 627 883 -603 927 989 797 463 615 798 832 535 562 517 194 697 661 176 814 -62 0 -886 239 221\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "10\n-62 0 94 -49 84 -11 -88 0 -88 94\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "20\n74 33 43 41 -83 -30 0 -20 84 99 83 0 64 0 57 46 0 18 94 82\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "20\n-892 0 -413 742 0 0 754 23 -515 -293 0 918 -711 -362 -15 -776 -442 -902 116 732\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "20\n355 -184 -982 -685 581 139 249 -352 -856 -436 679 397 653 325 -639 -722 769 345 -207 -632\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "50\n40 -84 25 0 21 44 96 2 -49 -15 -58 58 0 -49 4 8 13 28 -78 69 0 35 43 0 41 97 99 0 0 5 71 58 10 15 0 30 49 0 -66 15 64 -51 0 50 0 23 43 -43 15 6\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "50\n-657 0 -595 -527 -354 718 919 -770 -775 943 -23 0 -428 -322 -68 -429 -784 -981 -294 -260 533 0 0 -96 -839 0 -981 187 248 -56 -557 0 510 -824 -850 -531 -92 386 0 -952 519 -417 811 0 -934 -495 -813 -810 -733 0\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "50\n-321 -535 -516 -822 -622 102 145 -607 338 -849 -499 892 -23 -120 40 -864 -452 -641 -902 41 745 -291 887 -175 -288 -69 -590 370 -421 195 904 558 886 89 -764 -378 276 -21 -531 668 872 88 -32 -558 230 181 -639 364 -940 177\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "50\n-335 775 108 -928 -539 408 390 500 867 951 301 -113 -711 827 -83 422 -465 -355 -891 -957 -261 -507 930 385 745 198 238 33 805 -956 154 627 812 -518 216 785 817 -965 -916 999 986 718 55 698 -864 512 322 442 188 771\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "50\n-306 -646 -572 -364 -706 796 900 -715 -808 -746 -49 -320 983 -414 -996 659 -439 -280 -913 126 -229 427 -493 -316 -831 -292 -942 707 -685 -82 654 490 -313 -660 -960 971 383 430 -145 -689 -757 -811 656 -419 244 203 -605 -287 44 -583\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100\n41 95 -57 5 -37 -58 61 0 59 42 45 64 35 84 11 53 5 -73 99 0 59 68 82 32 50 0 92 0 17 0 -2 82 86 -63 96 -7 0 0 -6 -86 96 88 81 82 0 41 9 0 67 88 80 84 78 0 16 66 0 17 56 46 82 0 11 -79 53 0 -94 73 12 93 30 75 89 0 56 90 79 -39 45 -18 38 52 82 8 -30 0 69 50 22 0 41 0 0 33 17 8 97 79 30 59\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "100\n0 -927 -527 -306 -667 -229 -489 -194 -701 0 180 -723 0 3 -857 -918 -217 -471 732 -712 329 -40 0 0 -86 -820 -149 636 -260 -974 0 732 764 -769 916 -489 -916 -747 0 -508 -940 -229 -244 -761 0 -425 122 101 -813 -67 0 0 0 707 -272 -435 0 -736 228 586 826 -795 539 -553 -863 -744 -826 355 0 -6 -824 0 0 -588 -812 0 -109 -408 -153 -799 0 -15 -602 0 -874 -681 440 579 -577 0 -545 836 -810 -147 594 124 337 -477 -749 -313\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100\n-218 113 -746 -267 498 408 116 756 -793 0 -335 -213 593 -467 807 -342 -944 13 637 -82 -16 860 -333 -94 409 -149 -79 -431 -321 974 148 779 -860 -992 -598 0 -300 285 -187 404 -468 0 -586 875 0 0 -26 366 221 -759 -194 -353 -973 -968 -539 0 925 -223 -471 237 208 0 420 688 640 -711 964 661 708 -158 54 864 0 -697 -40 -313 -194 220 -211 108 596 534 148 -137 939 106 -730 -800 -266 433 421 -135 76 -51 -318 0 631 591 46 669\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100\n-261 613 -14 965 -114 -594 516 -631 -477 -352 -481 0 -224 -524 -841 397 -138 -986 -442 -568 -417 -850 -654 -193 -344 -648 -525 -394 -730 -712 -600 0 188 248 -657 -509 -647 -878 175 -894 -557 0 -367 -458 -35 -560 0 -952 -579 -784 -286 -303 -104 -984 0 0 487 -871 223 -527 0 -776 -675 -933 -669 -41 683 0 508 -443 807 -96 -454 -718 -806 -512 -990 -179 -909 0 421 -414 0 -290 0 -929 -675 611 -658 319 873 -421 876 -393 -289 -47 361 -693 -793 -33\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "50\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\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "50\n-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": "-1",
"type": "stdin_stdout"
},
{
"input": "50\n9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "50\n-9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9 -9\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100\n-39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39 -39\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "20\n-918 -369 -810 -162 486 558 459 -792 -153 756 54 279 324 369 -783 828 -522 -333 -288 -612\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "50\n-675 468 324 909 -621 918 954 846 369 -243 207 -756 225 -513 198 603 234 612 585 963 -396 801 -612 720 -432 -774 522 72 -747 -909 513 324 -27 846 -405 -252 -531 189 -36 -927 198 900 558 -711 702 -423 621 -945 -441 -783\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "100\n216 -900 99 198 -945 -936 234 243 990 702 -657 225 -594 414 -36 990 720 -558 774 -927 -234 432 -342 180 522 -225 -936 -945 639 -702 -117 -63 720 747 144 -117 855 396 90 486 828 612 423 90 -423 -486 -729 45 -216 486 -108 -432 459 -351 -504 -639 -72 981 468 -81 -891 -999 297 126 -684 -27 477 -405 828 -72 -729 540 657 -270 -603 -9 864 -738 -954 -378 378 324 693 -225 -783 405 -999 -144 45 -207 999 -846 -63 -945 -135 981 54 360 -135 -261\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100\n-880 550 -605 -781 297 -748 209 385 429 748 -880 913 -924 -935 517 11 352 -99 -979 462 990 -495 -44 539 528 -22 -451 44 -781 451 792 275 -462 220 968 726 -88 385 55 77 341 715 275 -693 -880 616 440 -924 -451 -308 -770 -836 473 935 -660 957 418 -264 341 385 -55 -22 880 -539 539 -858 -121 165 -385 -198 99 -88 11 -231 -638 -440 814 -198 902 550 209 275 -319 -66 -176 -297 594 781 -33 -242 -385 -308 77 891 -781 0 -858 -22 825 -759\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "100\n39 351 -39 663 -312 741 624 -39 -702 897 -234 -624 195 -897 -273 -624 39 -546 -858 390 390 -273 -741 156 -78 624 -117 390 -975 -234 390 897 936 -897 351 351 234 117 -663 -819 390 468 234 234 -78 -351 -897 702 -195 975 273 -429 624 -273 312 39 -117 -702 -507 195 -312 507 -858 -117 -117 858 468 858 546 702 -858 702 117 -702 663 -78 -702 -741 897 585 429 -741 897 546 195 975 -234 -936 78 -156 819 -897 507 -702 -858 975 -507 858 -390 -117\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "100\n663 -408 -459 -255 204 -510 714 -561 -765 -510 765 -765 -357 -867 204 765 408 -153 255 459 306 -102 969 153 918 153 867 765 357 306 -663 918 408 357 714 561 0 459 255 204 867 -714 459 -51 102 -204 -816 -816 357 765 -459 -255 -357 153 408 510 -663 357 -714 408 867 -561 765 -153 969 663 612 51 867 -51 51 -663 204 153 969 663 -357 510 -714 714 -663 102 714 -255 -969 765 0 918 -612 -459 -204 0 306 102 663 -408 357 -510 -102 -510\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "100\n-711 632 -395 79 -474 -237 -632 -632 316 -948 0 474 -79 -711 869 869 -948 -79 -316 474 237 -395 948 395 -158 -158 -632 237 -711 -632 -395 0 -316 474 -474 395 -474 79 0 -553 395 -948 -553 474 632 -237 -316 -711 553 948 790 237 -79 -553 -632 553 158 158 158 -79 948 -553 -474 632 395 79 -632 632 -869 -158 632 -553 -553 237 395 -237 711 -316 -948 -474 -632 316 869 869 948 -632 0 -237 -395 -474 79 553 -79 -158 553 711 474 632 711 0\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100\n0 1000 1000 1000 800 300 -500 900 400 -500 -900 400 400 -300 -300 -600 500 0 -500 600 -500 900 1000 -600 -200 300 -100 800 -800 0 200 400 0 -100 100 100 1000 -400 100 400 -900 -500 -900 400 -700 -400 800 -900 300 -300 -400 500 -900 1000 700 -200 500 400 -200 -300 -200 -600 -600 -800 300 -100 100 -1000 100 -800 -500 -800 0 100 900 -200 -100 -400 -500 0 -400 900 600 400 -200 100 400 800 -800 700 600 -200 1000 -400 -200 -200 100 -1000 700 -600\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "20\n-828 -621 -36 -225 837 126 981 450 522 -522 -684 684 -477 792 -846 -405 639 495 27 -387\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "50\n351 -729 -522 -936 -342 -189 -441 -279 -702 -369 864 873 -297 -261 -207 -54 -900 -675 -585 261 27 594 -360 702 -621 -774 729 846 864 -45 639 -216 -18 882 414 630 855 810 -135 783 -765 882 144 -477 -36 180 216 -180 -306 774\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100\n-270 -522 -855 -324 387 -297 126 -387 -927 414 882 945 -459 396 261 -243 234 -270 315 999 477 -315 -972 -396 -81 -207 522 9 477 -459 -18 -234 909 225 -18 396 351 297 -540 -981 648 -657 360 945 -486 -396 288 -567 9 882 -495 -585 729 -405 -864 468 -18 -279 315 -234 9 -963 -639 -540 783 279 -27 486 441 -522 -441 675 -495 -918 405 63 324 -81 -198 216 189 234 -414 -828 -675 144 -954 288 810 90 -918 63 -117 594 -846 972 873 72 504 -756\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "100\n-473 517 517 154 -814 -836 649 198 803 -209 -363 759 -44 -242 -473 -715 561 451 -462 -110 -957 -792 462 132 -627 -473 363 572 -176 -935 -704 539 -286 22 374 286 451 748 -198 11 -616 319 264 -198 -638 -77 374 990 506 957 517 -297 -781 979 -121 539 -605 -264 946 869 616 -121 -792 -957 -22 528 715 869 506 -385 -869 121 -220 583 814 -814 33 -858 -121 308 825 55 -495 803 88 -187 -165 869 946 -594 -704 -209 11 770 -825 -44 -946 341 -330 -231\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "100\n-900 -700 400 200 -800 500 1000 500 -300 -300 -100 900 -300 -300 900 -200 900 -800 -200 1000 -500 -200 -200 500 100 500 100 -400 -100 400 -500 700 400 -900 -300 -900 -700 1000 -800 1000 700 -200 -400 -900 -1000 400 300 800 -200 300 -500 -700 200 -200 -900 800 100 -700 -800 900 -900 -700 500 600 -700 300 -100 1000 100 -800 -200 -600 200 600 -100 -500 900 800 500 -600 900 600 600 -1000 800 -400 -800 900 500 -300 -300 400 1000 400 -1000 -200 -200 -100 -200 -800\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "20\n0 0 0 -576 0 -207 0 -639 0 0 468 0 0 873 0 0 0 0 81 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "50\n-81 -405 630 0 0 0 0 0 891 0 0 0 0 0 -18 0 0 0 0 0 243 -216 0 702 0 -909 -972 0 0 0 -450 0 0 882 0 0 0 0 0 -972 0 0 0 0 -333 -261 945 -720 0 -882\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100\n-972 0 -747 0 0 -918 396 0 0 -144 0 0 0 0 774 0 0 0 0 0 0 0 0 0 0 0 387 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 855 0 603 0 0 0 675 -675 621 0 0 0 -45 612 -549 -153 0 0 0 0 0 -486 0 0 0 0 0 0 -594 0 0 0 -225 0 -54 693 0 0 0 0 0 0 0 873 0 0 -198 0 0 0 0 558 0 918\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100\n0 0 0 0 0 0 0 0 539 0 0 -957 0 0 0 -220 0 550 0 0 0 660 0 0 -33 0 0 -935 0 0 0 0 0 0 0 0 0 0 0 0 0 -55 297 0 0 0 0 0 836 0 -451 0 0 0 0 0 -176 0 0 0 0 0 0 792 -847 330 0 0 0 715 0 0 0 517 -682 0 0 0 0 0 0 0 0 506 484 0 -396 0 0 429 0 0 0 0 0 0 0 968 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100\n0 0 0 0 0 0 0 0 0 0 0 600 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 900 100 0 0 0 1000 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100\n49 0 -87 -39 0 0 -39 73 1 88 45 0 87 0 0 0 90 54 59 0 0 0 -96 -68 9 -26 0 68 21 59 -21 90 64 0 -62 78 -53 0 0 72 0 0 0 14 -79 87 0 75 0 97 77 0 37 0 1 18 0 0 0 30 47 39 0 -69 0 0 0 71 0 0 0 -85 0 44 0 0 0 -36 0 30 0 0 0 0 0 9 40 0 0 61 -35 0 0 0 0 -32 0 28 0 -100\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100\n-801 -258 -829 0 -839 -920 0 0 979 -896 -581 -132 -945 -274 -538 117 0 27 0 469 129 0 -608 685 0 -915 273 -929 0 -418 -57 517 -230 -775 0 -839 475 -350 882 363 419 0 -120 0 -416 808 0 -726 286 0 0 -777 -80 -331 0 278 -328 0 -534 0 0 -581 -463 0 -244 0 -693 0 0 -754 120 -254 -237 0 -452 0 -478 -509 0 -688 0 911 -219 368 0 0 -598 0 -575 0 0 -897 0 0 0 0 373 0 490 950\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100\n303 599 954 131 507 906 227 111 187 395 959 509 891 669 677 246 430 582 326 235 331 395 550 224 410 278 385 371 -829 514 600 451 337 786 508 939 548 23 583 342 870 585 16 914 482 619 781 583 683 913 663 727 329 170 475 557 356 8 342 536 821 348 942 486 497 732 213 659 351 -727 471 593 399 582 608 799 922 618 752 861 206 530 513 259 185 435 437 15 451 919 42 549 14 25 599 454 407 53 382 -540\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "100\n-246 -98 -29 -208 -305 -231 -309 -632 -255 -293 -810 -283 -962 -593 -203 -40 -910 -934 -640 -520 -481 -988 -774 -696 -700 -875 -418 -750 -193 -863 -163 -498 -77 -627 -786 -820 -469 -799 -50 -162 -938 -133 -842 -144 -383 -245 -983 -975 -279 -86 -725 -304 -313 -574 -509 -192 -110 -726 -789 -36 -151 -792 -285 -988 -617 -738 -462 -921 -882 -299 -379 -640 -762 -363 -41 -942 -693 -92 -912 -187 -614 -509 -225 -649 -443 -867 -503 -596 -757 -711 -864 -378 -974 -141 -491 -98 -506 -113 -322 -558\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100\n34 -601 426 -318 -52 -51 0 782 711 0 502 746 -450 1 695 -606 951 942 14 0 -695 806 -195 -643 445 -903 443 523 -940 634 -229 -244 -303 -970 -564 -755 344 469 0 -293 306 496 786 62 0 -110 640 339 630 -276 -286 838 137 -508 811 -385 -784 -834 937 -361 -799 534 368 -352 -702 353 -437 -440 213 56 637 -814 -169 -56 930 720 -100 -696 -749 463 -32 761 -137 181 428 -408 0 727 -78 963 -606 -131 -537 827 951 -753 58 -21 -261 636\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100\n642 -529 -322 -893 -539 -300 -286 -503 -750 0 974 -560 -806 0 294 0 -964 -555 501 -308 -160 -369 -175 0 -257 -361 -976 -6 0 836 915 -353 -134 0 -511 -290 -854 87 190 790 -229 27 -67 -699 -200 -589 443 -534 -621 -265 0 -666 -497 999 -700 -149 -668 94 -623 -160 -385 -422 88 -818 -998 -665 -229 143 133 241 840 0 -764 873 -372 -741 262 -462 -481 -630 0 848 -875 65 302 -231 -514 -275 -874 -447 195 -393 350 678 -991 -904 -251 0 -376 -419\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100\n-48 842 18 424 -969 -357 -781 -517 -941 -957 -548 23 0 215 0 -649 -509 955 376 824 62 0 -5 674 890 263 -567 585 488 -862 66 961 75 205 838 756 514 -806 0 -884 692 0 301 -722 457 838 -649 -785 0 -775 449 -436 524 792 999 953 470 39 -61 0 860 65 420 382 0 11 0 117 767 171 0 577 185 385 387 -612 0 277 -738 -691 78 396 6 -766 155 119 -588 0 -724 228 580 200 -375 620 615 87 574 740 -398 698\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "10\n1 1 1 1 1 -1 -1 -1 -1 -1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "1\n0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3\n-1 0 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3\n0 0 -1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 -2 -2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "6\n1 1 1 -1 -1 -1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "7\n1 2 3 0 0 -1 -1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5\n0 1 2 -1 -2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2\n-1 0\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "5\n-1 -1 -1 -1 -1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "5\n100 0 0 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 -1 -1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "4\n1 0 -1 -1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "1\n-1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 -1 -1 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "9\n0 0 0 1 1 1 1 -1 -1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2\n-1 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "4\n0 0 -1 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 0 0 -1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4\n1 -1 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4\n-1 -1 0 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "8\n1 2 3 4 -1 -2 -3 -4\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "6\n-1 -1 -1 0 0 0\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "3\n-1 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5\n-1 -2 -3 0 80\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "8\n-1 -1 1 0 0 0 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 1 1 -1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3\n0 -1 1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3\n1 0 -1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1\n1000\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "9\n2 2 2 2 -3 -3 -3 -3 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4\n-1 -1 0 0\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "7\n-1 -1 -1 1 1 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5\n-1 -1 -1 0 0\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "5\n-1 -2 -3 -4 -5\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "6\n1 2 3 -1 -2 -3\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "4\n-1 -2 0 2\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "5\n-1 -1 0 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4\n0 0 -1 -1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "6\n0 0 1 1 -1 -1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3\n-1 -1 0\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "6\n-2 -1 0 0 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "9\n1 1 1 0 0 0 -1 -1 -1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2\n1 -1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "8\n-1 -1 -1 -1 0 0 1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "6\n1 1 0 0 -1 -1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 0 -1 -1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "9\n1 2 3 -1 -2 -3 0 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5\n2 2 -2 -2 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5\n1 -1 0 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "6\n1 1 -1 -1 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4\n0 1 0 -1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5\n-2 -2 -2 1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "7\n1 1 1 0 -1 -1 -1\n",
"output": "0",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1130/A"
} | vfc_10086 |
apps | verifiable_code | 84 | Solve the following coding problem using the programming language python:
There are n shovels in Polycarp's shop. The i-th shovel costs i burles, that is, the first shovel costs 1 burle, the second shovel costs 2 burles, the third shovel costs 3 burles, and so on. Polycarps wants to sell shovels in pairs.
Visitors are more likely to buy a pair of shovels if their total cost ends with several 9s. Because of this, Polycarp wants to choose a pair of shovels to sell in such a way that the sum of their costs ends with maximum possible number of nines. For example, if he chooses shovels with costs 12345 and 37454, their total cost is 49799, it ends with two nines.
You are to compute the number of pairs of shovels such that their total cost ends with maximum possible number of nines. Two pairs are considered different if there is a shovel presented in one pair, but not in the other.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 10^9) — the number of shovels in Polycarp's shop.
-----Output-----
Print the number of pairs of shovels such that their total cost ends with maximum possible number of nines.
Note that it is possible that the largest number of 9s at the end is 0, then you should count all such ways.
It is guaranteed that for every n ≤ 10^9 the answer doesn't exceed 2·10^9.
-----Examples-----
Input
7
Output
3
Input
14
Output
9
Input
50
Output
1
-----Note-----
In the first example the maximum possible number of nines at the end is one. Polycarp cah choose the following pairs of shovels for that purpose: 2 and 7; 3 and 6; 4 and 5.
In the second example the maximum number of nines at the end of total cost of two shovels is one. The following pairs of shovels suit Polycarp: 1 and 8; 2 and 7; 3 and 6; 4 and 5; 5 and 14; 6 and 13; 7 and 12; 8 and 11; 9 and 10.
In the third example it is necessary to choose shovels 49 and 50, because the sum of their cost is 99, that means that the total number of nines is equal to two, which is maximum possible for n = 50.
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 as cin
from sys import stdout as cout
def main():
n = int(cin.readline())
o = 0
for x in range(9, 0, -1):
if 10 ** x // 2 <= n:
##print(x)
for i in range(9):
q = 10 ** x * (i + 1) // 2 - 1
if q <= n:
o += min(q, n - q)
print(o)
return
print(n * (n - 1) // 2)
main()
``` | {
"language": "python",
"test_cases": [
{
"input": "7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "14\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "50\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "999999999\n",
"output": "499999999\n",
"type": "stdin_stdout"
},
{
"input": "15\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6500\n",
"output": "1501\n",
"type": "stdin_stdout"
},
{
"input": "4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "13\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "499999\n",
"output": "1249995\n",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "12\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "16\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "17\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "18\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "19\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "20\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "22\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "23\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "24\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "25\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"input": "26\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "27\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "28\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "29\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "30\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "31\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"input": "32\n",
"output": "51\n",
"type": "stdin_stdout"
},
{
"input": "33\n",
"output": "54\n",
"type": "stdin_stdout"
},
{
"input": "34\n",
"output": "57\n",
"type": "stdin_stdout"
},
{
"input": "35\n",
"output": "61\n",
"type": "stdin_stdout"
},
{
"input": "36\n",
"output": "65\n",
"type": "stdin_stdout"
},
{
"input": "37\n",
"output": "69\n",
"type": "stdin_stdout"
},
{
"input": "38\n",
"output": "73\n",
"type": "stdin_stdout"
},
{
"input": "39\n",
"output": "76\n",
"type": "stdin_stdout"
},
{
"input": "40\n",
"output": "80\n",
"type": "stdin_stdout"
},
{
"input": "41\n",
"output": "84\n",
"type": "stdin_stdout"
},
{
"input": "42\n",
"output": "88\n",
"type": "stdin_stdout"
},
{
"input": "43\n",
"output": "92\n",
"type": "stdin_stdout"
},
{
"input": "44\n",
"output": "96\n",
"type": "stdin_stdout"
},
{
"input": "45\n",
"output": "101\n",
"type": "stdin_stdout"
},
{
"input": "46\n",
"output": "106\n",
"type": "stdin_stdout"
},
{
"input": "47\n",
"output": "111\n",
"type": "stdin_stdout"
},
{
"input": "48\n",
"output": "116\n",
"type": "stdin_stdout"
},
{
"input": "49\n",
"output": "120\n",
"type": "stdin_stdout"
},
{
"input": "51\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "99\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "101\n",
"output": "51\n",
"type": "stdin_stdout"
},
{
"input": "4999\n",
"output": "12495\n",
"type": "stdin_stdout"
},
{
"input": "4998\n",
"output": "12491\n",
"type": "stdin_stdout"
},
{
"input": "4992\n",
"output": "12461\n",
"type": "stdin_stdout"
},
{
"input": "5000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5001\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10000\n",
"output": "5000\n",
"type": "stdin_stdout"
},
{
"input": "10001\n",
"output": "5001\n",
"type": "stdin_stdout"
},
{
"input": "49839\n",
"output": "124196\n",
"type": "stdin_stdout"
},
{
"input": "4999999\n",
"output": "12499995\n",
"type": "stdin_stdout"
},
{
"input": "49999999\n",
"output": "124999995\n",
"type": "stdin_stdout"
},
{
"input": "499999999\n",
"output": "1249999995\n",
"type": "stdin_stdout"
},
{
"input": "999\n",
"output": "499\n",
"type": "stdin_stdout"
},
{
"input": "9999\n",
"output": "4999\n",
"type": "stdin_stdout"
},
{
"input": "99999\n",
"output": "49999\n",
"type": "stdin_stdout"
},
{
"input": "999999\n",
"output": "499999\n",
"type": "stdin_stdout"
},
{
"input": "9999999\n",
"output": "4999999\n",
"type": "stdin_stdout"
},
{
"input": "99999999\n",
"output": "49999999\n",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000\n",
"output": "500000000\n",
"type": "stdin_stdout"
},
{
"input": "764675465\n",
"output": "264675466\n",
"type": "stdin_stdout"
},
{
"input": "499999998\n",
"output": "1249999991\n",
"type": "stdin_stdout"
},
{
"input": "167959139\n",
"output": "135918279\n",
"type": "stdin_stdout"
},
{
"input": "641009859\n",
"output": "141009860\n",
"type": "stdin_stdout"
},
{
"input": "524125987\n",
"output": "24125988\n",
"type": "stdin_stdout"
},
{
"input": "702209411\n",
"output": "202209412\n",
"type": "stdin_stdout"
},
{
"input": "585325539\n",
"output": "85325540\n",
"type": "stdin_stdout"
},
{
"input": "58376259\n",
"output": "8376260\n",
"type": "stdin_stdout"
},
{
"input": "941492387\n",
"output": "441492388\n",
"type": "stdin_stdout"
},
{
"input": "824608515\n",
"output": "324608516\n",
"type": "stdin_stdout"
},
{
"input": "2691939\n",
"output": "3575818\n",
"type": "stdin_stdout"
},
{
"input": "802030518\n",
"output": "302030519\n",
"type": "stdin_stdout"
},
{
"input": "685146646\n",
"output": "185146647\n",
"type": "stdin_stdout"
},
{
"input": "863230070\n",
"output": "363230071\n",
"type": "stdin_stdout"
},
{
"input": "41313494\n",
"output": "85253976\n",
"type": "stdin_stdout"
},
{
"input": "219396918\n",
"output": "238793836\n",
"type": "stdin_stdout"
},
{
"input": "102513046\n",
"output": "52513046\n",
"type": "stdin_stdout"
},
{
"input": "985629174\n",
"output": "485629175\n",
"type": "stdin_stdout"
},
{
"input": "458679894\n",
"output": "1043399471\n",
"type": "stdin_stdout"
},
{
"input": "341796022\n",
"output": "575388066\n",
"type": "stdin_stdout"
},
{
"input": "519879446\n",
"output": "19879447\n",
"type": "stdin_stdout"
},
{
"input": "452405440\n",
"output": "1012027201\n",
"type": "stdin_stdout"
},
{
"input": "335521569\n",
"output": "556564707\n",
"type": "stdin_stdout"
},
{
"input": "808572289\n",
"output": "308572290\n",
"type": "stdin_stdout"
},
{
"input": "691688417\n",
"output": "191688418\n",
"type": "stdin_stdout"
},
{
"input": "869771841\n",
"output": "369771842\n",
"type": "stdin_stdout"
},
{
"input": "752887969\n",
"output": "252887970\n",
"type": "stdin_stdout"
},
{
"input": "930971393\n",
"output": "430971394\n",
"type": "stdin_stdout"
},
{
"input": "109054817\n",
"output": "59054817\n",
"type": "stdin_stdout"
},
{
"input": "992170945\n",
"output": "492170946\n",
"type": "stdin_stdout"
},
{
"input": "170254369\n",
"output": "140508739\n",
"type": "stdin_stdout"
},
{
"input": "248004555\n",
"output": "296009110\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/899/D"
} | vfc_10090 |
apps | verifiable_code | 85 | Solve the following coding problem using the programming language python:
Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a_1 × b_1 segments large and the second one is a_2 × b_2 segments large.
Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other one himself. Besides, he wants to show that Polycarpus's mind and Paraskevi's beauty are equally matched, so the two bars must have the same number of squares.
To make the bars have the same number of squares, Polycarpus eats a little piece of chocolate each minute. Each minute he does the following: he either breaks one bar exactly in half (vertically or horizontally) and eats exactly a half of the bar, or he chips of exactly one third of a bar (vertically or horizontally) and eats exactly a third of the bar.
In the first case he is left with a half, of the bar and in the second case he is left with two thirds of the bar.
Both variants aren't always possible, and sometimes Polycarpus cannot chip off a half nor a third. For example, if the bar is 16 × 23, then Polycarpus can chip off a half, but not a third. If the bar is 20 × 18, then Polycarpus can chip off both a half and a third. If the bar is 5 × 7, then Polycarpus cannot chip off a half nor a third.
What is the minimum number of minutes Polycarpus needs to make two bars consist of the same number of squares? Find not only the required minimum number of minutes, but also the possible sizes of the bars after the process.
-----Input-----
The first line of the input contains integers a_1, b_1 (1 ≤ a_1, b_1 ≤ 10^9) — the initial sizes of the first chocolate bar. The second line of the input contains integers a_2, b_2 (1 ≤ a_2, b_2 ≤ 10^9) — the initial sizes of the second bar.
You can use the data of type int64 (in Pascal), long long (in С++), long (in Java) to process large integers (exceeding 2^31 - 1).
-----Output-----
In the first line print m — the sought minimum number of minutes. In the second and third line print the possible sizes of the bars after they are leveled in m minutes. Print the sizes using the format identical to the input format. Print the sizes (the numbers in the printed pairs) in any order. The second line must correspond to the first bar and the third line must correspond to the second bar. If there are multiple solutions, print any of them.
If there is no solution, print a single line with integer -1.
-----Examples-----
Input
2 6
2 3
Output
1
1 6
2 3
Input
36 5
10 16
Output
3
16 5
5 16
Input
3 5
2 1
Output
-1
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a,b=list(map(int,input().split()))
c,d=list(map(int,input().split()))
e=a*b
f=c*d
n=0
while e%2==0:e=e//2
while e%3==0:e=e//3
while f%2==0:f=f//2
while f%3==0:f=f//3
if e!=f:print("-1")
else:
i=0
j=0
e=a*b
f=c*d
while e%3==0:
e=e//3
i+=1
while f%3==0:
f=f//3
j+=1
k=i-j
if k>0:
for i in range(k):
n+=1
if a%3==0:a=a*2//3
else:b=b*2//3
else:
for i in range(0-k):
n+=1
if c%3==0:c=c*2//3
else:d=d*2//3
e=a*b
f=c*d
i=0
j=0
while e%2==0:
e=e//2
i+=1
while f%2==0:
f=f//2
j+=1
k=i-j
if k>0:
for i in range(k):
n+=1
if a%2==0:a=a//2
else:b=b//2
else:
for i in range(0-k):
n+=1
if c%2==0:c=c//2
else:d=d//2
print(n)
print(a,b)
print(c,d)
``` | {
"language": "python",
"test_cases": [
{
"input": "2 6\n2 3\n",
"output": "1\n1 6\n2 3\n",
"type": "stdin_stdout"
},
{
"input": "36 5\n10 16\n",
"output": "3\n16 5\n5 16\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n2 1\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "36 5\n10 12\n",
"output": "1\n24 5\n10 12\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n1 1\n",
"output": "0\n1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n1 2\n",
"output": "0\n2 1\n1 2\n",
"type": "stdin_stdout"
},
{
"input": "3 6\n2 1\n",
"output": "4\n1 2\n2 1\n",
"type": "stdin_stdout"
},
{
"input": "1 27\n1 1\n",
"output": "6\n1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "2 5\n20 2\n",
"output": "2\n2 5\n5 2\n",
"type": "stdin_stdout"
},
{
"input": "40 5\n150 36\n",
"output": "6\n40 5\n25 8\n",
"type": "stdin_stdout"
},
{
"input": "60 1080\n60 45\n",
"output": "5\n5 540\n60 45\n",
"type": "stdin_stdout"
},
{
"input": "2160 3240\n7200 384\n",
"output": "5\n640 2160\n3600 384\n",
"type": "stdin_stdout"
},
{
"input": "51840 900\n48 27000\n",
"output": "6\n1440 900\n48 27000\n",
"type": "stdin_stdout"
},
{
"input": "100 200\n7200 25\n",
"output": "4\n100 200\n800 25\n",
"type": "stdin_stdout"
},
{
"input": "112500 96\n375 2400\n",
"output": "4\n9375 96\n375 2400\n",
"type": "stdin_stdout"
},
{
"input": "432000 3000\n4800 10000\n",
"output": "6\n16000 3000\n4800 10000\n",
"type": "stdin_stdout"
},
{
"input": "7 1\n1 7\n",
"output": "0\n7 1\n1 7\n",
"type": "stdin_stdout"
},
{
"input": "12 39\n13 3\n",
"output": "4\n1 39\n13 3\n",
"type": "stdin_stdout"
},
{
"input": "906992640 544195584\n906992640 725594112\n",
"output": "2\n604661760 544195584\n453496320 725594112\n",
"type": "stdin_stdout"
},
{
"input": "859963392 644972544\n725594112 967458816\n",
"output": "6\n214990848 644972544\n143327232 967458816\n",
"type": "stdin_stdout"
},
{
"input": "644972544 886837248\n725594112 886837248\n",
"output": "3\n322486272 886837248\n322486272 886837248\n",
"type": "stdin_stdout"
},
{
"input": "243 216\n6 1\n",
"output": "16\n1 6\n6 1\n",
"type": "stdin_stdout"
},
{
"input": "400 2500000\n1000000 1000\n",
"output": "0\n400 2500000\n1000000 1000\n",
"type": "stdin_stdout"
},
{
"input": "10000 100000\n2 1000000000\n",
"output": "1\n10000 100000\n1 1000000000\n",
"type": "stdin_stdout"
},
{
"input": "25000000 80\n128 23437500\n",
"output": "1\n25000000 80\n128 15625000\n",
"type": "stdin_stdout"
},
{
"input": "62500000 96\n256 7812500\n",
"output": "2\n31250000 64\n256 7812500\n",
"type": "stdin_stdout"
},
{
"input": "1280 2343750\n25600 312500\n",
"output": "3\n1280 1562500\n6400 312500\n",
"type": "stdin_stdout"
},
{
"input": "15625 1152000\n1562500 5760\n",
"output": "1\n15625 576000\n1562500 5760\n",
"type": "stdin_stdout"
},
{
"input": "9000000 12000\n6250 480000\n",
"output": "6\n250000 12000\n6250 480000\n",
"type": "stdin_stdout"
},
{
"input": "1920 50000000\n78125 25600\n",
"output": "6\n40 50000000\n78125 25600\n",
"type": "stdin_stdout"
},
{
"input": "5625000 19200\n1125000 96000\n",
"output": "0\n5625000 19200\n1125000 96000\n",
"type": "stdin_stdout"
},
{
"input": "45 800000000\n288000000 500\n",
"output": "2\n45 800000000\n72000000 500\n",
"type": "stdin_stdout"
},
{
"input": "750000000 725594112\n716636160 675000000\n",
"output": "3\n500000000 483729408\n358318080 675000000\n",
"type": "stdin_stdout"
},
{
"input": "10000079 1\n10000079 1\n",
"output": "0\n10000079 1\n10000079 1\n",
"type": "stdin_stdout"
},
{
"input": "1 30000237\n10000079 1\n",
"output": "2\n1 10000079\n10000079 1\n",
"type": "stdin_stdout"
},
{
"input": "10000079 1\n6 10000079\n",
"output": "3\n10000079 1\n1 10000079\n",
"type": "stdin_stdout"
},
{
"input": "3 540004266\n60000474 27\n",
"output": "0\n3 540004266\n60000474 27\n",
"type": "stdin_stdout"
},
{
"input": "720005688 725594112\n816293376 960007584\n",
"output": "1\n720005688 725594112\n544195584 960007584\n",
"type": "stdin_stdout"
},
{
"input": "859963392 816293376\n967458816 859963392\n",
"output": "5\n254803968 816293376\n241864704 859963392\n",
"type": "stdin_stdout"
},
{
"input": "644972544 816293376\n544195584 816293376\n",
"output": "5\n161243136 816293376\n161243136 816293376\n",
"type": "stdin_stdout"
},
{
"input": "99999989 1\n1 99999989\n",
"output": "0\n99999989 1\n1 99999989\n",
"type": "stdin_stdout"
},
{
"input": "99999989 9\n1 99999989\n",
"output": "4\n99999989 1\n1 99999989\n",
"type": "stdin_stdout"
},
{
"input": "199999978 2\n599999934 3\n",
"output": "3\n199999978 2\n199999978 2\n",
"type": "stdin_stdout"
},
{
"input": "544195584 899999901\n599999934 967458816\n",
"output": "5\n161243136 899999901\n299999967 483729408\n",
"type": "stdin_stdout"
},
{
"input": "8 8\n1 1\n",
"output": "6\n1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "31 15\n36 25\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "68 34\n84 78\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "894 197\n325 232\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "41764 97259\n54586 18013\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "333625 453145\n800800 907251\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4394826 2233224\n609367 3364334\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "13350712 76770926\n61331309 8735000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "844212449 863672439\n410956265 742052168\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "22295873 586964387\n4736819 472714349\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "905412001 865545936\n598517372 498343827\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "378462721 734062076\n42554822 374230201\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "261578849 307610920\n636335376 399859678\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "144694977 881159765\n80372825 425489156\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "35135676 3879\n841304242 18\n",
"output": "4\n3903964 3879\n841304242 18\n",
"type": "stdin_stdout"
},
{
"input": "57946752 619939008\n114816 331164\n",
"output": "24\n92 413292672\n114816 331164\n",
"type": "stdin_stdout"
},
{
"input": "171 162\n9 57\n",
"output": "7\n19 27\n9 57\n",
"type": "stdin_stdout"
},
{
"input": "2592 4950\n60 2970\n",
"output": "7\n36 4950\n60 2970\n",
"type": "stdin_stdout"
},
{
"input": "90315 96\n48 30105\n",
"output": "3\n30105 48\n48 30105\n",
"type": "stdin_stdout"
},
{
"input": "5832 45693720\n10154160 108\n",
"output": "10\n24 45693720\n10154160 108\n",
"type": "stdin_stdout"
},
{
"input": "5832 45693720\n10154160 108\n",
"output": "10\n24 45693720\n10154160 108\n",
"type": "stdin_stdout"
},
{
"input": "1 911953772\n39650164 23\n",
"output": "0\n1 911953772\n39650164 23\n",
"type": "stdin_stdout"
},
{
"input": "3 707552887\n6 707552887\n",
"output": "1\n3 707552887\n3 707552887\n",
"type": "stdin_stdout"
},
{
"input": "806410824 11\n2 369604961\n",
"output": "4\n67200902 11\n2 369604961\n",
"type": "stdin_stdout"
},
{
"input": "144 980783074\n24786 461544976\n",
"output": "8\n144 980783074\n306 461544976\n",
"type": "stdin_stdout"
},
{
"input": "614363206 2\n2 307181603\n",
"output": "1\n307181603 2\n2 307181603\n",
"type": "stdin_stdout"
},
{
"input": "1336608 1650\n18711 3182400\n",
"output": "6\n1336608 1650\n693 3182400\n",
"type": "stdin_stdout"
},
{
"input": "472586400 448\n1050192 8400\n",
"output": "5\n19691100 448\n1050192 8400\n",
"type": "stdin_stdout"
},
{
"input": "497664 367567200\n3304800 55351296\n",
"output": "0\n497664 367567200\n3304800 55351296\n",
"type": "stdin_stdout"
},
{
"input": "916090560 291133440\n628176384 424569600\n",
"output": "0\n916090560 291133440\n628176384 424569600\n",
"type": "stdin_stdout"
},
{
"input": "556792704 718502400\n640493568 832809600\n",
"output": "2\n371195136 718502400\n320246784 832809600\n",
"type": "stdin_stdout"
},
{
"input": "320 162162\n8736 1980\n",
"output": "2\n160 108108\n8736 1980\n",
"type": "stdin_stdout"
},
{
"input": "25740 6048\n38918880 81\n",
"output": "6\n25740 6048\n1921920 81\n",
"type": "stdin_stdout"
},
{
"input": "90720 35582976\n294840 9237888\n",
"output": "5\n22680 35582976\n87360 9237888\n",
"type": "stdin_stdout"
},
{
"input": "870912 1924560\n544195584 35925120\n",
"output": "16\n870912 1924560\n46656 35925120\n",
"type": "stdin_stdout"
},
{
"input": "846526464 537477120\n806215680 952342272\n",
"output": "4\n423263232 537477120\n238878720 952342272\n",
"type": "stdin_stdout"
},
{
"input": "862202880 967458816\n595213920 886837248\n",
"output": "7\n107775360 967458816\n117573120 886837248\n",
"type": "stdin_stdout"
},
{
"input": "564350976 623557440\n775982592 604661760\n",
"output": "2\n376233984 623557440\n387991296 604661760\n",
"type": "stdin_stdout"
},
{
"input": "775982592 716636160\n906992640 919683072\n",
"output": "1\n775982592 716636160\n604661760 919683072\n",
"type": "stdin_stdout"
},
{
"input": "806215680 940584960\n627056640 537477120\n",
"output": "2\n358318080 940584960\n627056640 537477120\n",
"type": "stdin_stdout"
},
{
"input": "537477120 560431872\n627056640 720555264\n",
"output": "1\n537477120 560431872\n418037760 720555264\n",
"type": "stdin_stdout"
},
{
"input": "564350976 906992640\n836075520 816293376\n",
"output": "2\n376233984 906992640\n418037760 816293376\n",
"type": "stdin_stdout"
},
{
"input": "591224832 529079040\n574801920 725594112\n",
"output": "2\n394149888 529079040\n287400960 725594112\n",
"type": "stdin_stdout"
},
{
"input": "816293376 881798400\n612220032 783820800\n",
"output": "1\n544195584 881798400\n612220032 783820800\n",
"type": "stdin_stdout"
},
{
"input": "862202880 764411904\n997691904 836075520\n",
"output": "6\n215550720 764411904\n197074944 836075520\n",
"type": "stdin_stdout"
},
{
"input": "766402560 725594112\n680244480 689762304\n",
"output": "5\n191600640 725594112\n201553920 689762304\n",
"type": "stdin_stdout"
},
{
"input": "766402560 816293376\n680244480 581986944\n",
"output": "7\n95800320 816293376\n134369280 581986944\n",
"type": "stdin_stdout"
},
{
"input": "952342272 554273280\n646652160 725594112\n",
"output": "3\n423263232 554273280\n323326080 725594112\n",
"type": "stdin_stdout"
},
{
"input": "739031040 564350976\n644972544 862202880\n",
"output": "2\n492687360 564350976\n322486272 862202880\n",
"type": "stdin_stdout"
},
{
"input": "831409920 564350976\n574801920 725594112\n",
"output": "3\n369515520 564350976\n287400960 725594112\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n774840978 774840978\n",
"output": "74\n1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "725594112 725594112\n1 1\n",
"output": "68\n1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n536870912 536870912\n",
"output": "58\n1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "573308928 573308928\n1 1\n",
"output": "64\n1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n918330048 918330048\n",
"output": "72\n1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n688747536 688747536\n",
"output": "72\n1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "536870912 536870912\n387420489 387420489\n",
"output": "58\n128 536870912\n262144 262144\n",
"type": "stdin_stdout"
},
{
"input": "967458816 967458816\n967458816 967458816\n",
"output": "0\n967458816 967458816\n967458816 967458816\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n65536 65536\n",
"output": "32\n1 1\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "387420489 387420489\n536870912 536870912\n",
"output": "58\n262144 262144\n128 536870912\n",
"type": "stdin_stdout"
},
{
"input": "999999937 999999937\n999999937 999999937\n",
"output": "0\n999999937 999999937\n999999937 999999937\n",
"type": "stdin_stdout"
},
{
"input": "387420489 774840978\n774840978 645700815\n",
"output": "-1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/490/D"
} | vfc_10094 |
apps | verifiable_code | 86 | Solve the following coding problem using the programming language python:
Polycarp and Vasiliy love simple logical games. Today they play a game with infinite chessboard and one pawn for each player. Polycarp and Vasiliy move in turns, Polycarp starts. In each turn Polycarp can move his pawn from cell (x, y) to (x - 1, y) or (x, y - 1). Vasiliy can move his pawn from (x, y) to one of cells: (x - 1, y), (x - 1, y - 1) and (x, y - 1). Both players are also allowed to skip move.
There are some additional restrictions — a player is forbidden to move his pawn to a cell with negative x-coordinate or y-coordinate or to the cell containing opponent's pawn The winner is the first person to reach cell (0, 0).
You are given the starting coordinates of both pawns. Determine who will win if both of them play optimally well.
-----Input-----
The first line contains four integers: x_{p}, y_{p}, x_{v}, y_{v} (0 ≤ x_{p}, y_{p}, x_{v}, y_{v} ≤ 10^5) — Polycarp's and Vasiliy's starting coordinates.
It is guaranteed that in the beginning the pawns are in different cells and none of them is in the cell (0, 0).
-----Output-----
Output the name of the winner: "Polycarp" or "Vasiliy".
-----Examples-----
Input
2 1 2 2
Output
Polycarp
Input
4 7 7 4
Output
Vasiliy
-----Note-----
In the first sample test Polycarp starts in (2, 1) and will move to (1, 1) in the first turn. No matter what his opponent is doing, in the second turn Polycarp can move to (1, 0) and finally to (0, 0) in the third turn.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, b, x, y = map(int, input().split())
if a >= x:
if b >= y:
print('Vasiliy')
else:
z = y - b
t = max(x - z, 0)
if a - z <= t:
print('Polycarp')
else:
print('Vasiliy')
else:
if b <= y:
print('Polycarp')
else:
z = x - a
t = max(y - z, 0)
if b - z <= t:
print('Polycarp')
else:
print('Vasiliy')
``` | {
"language": "python",
"test_cases": [
{
"input": "2 1 2 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "4 7 7 4\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "20 0 7 22\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "80 100 83 97\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "80 100 77 103\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "55000 60000 55003 60100\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "100000 100000 100000 99999\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "100000 99999 100000 100000\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 100000 100000 99999\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 100000 99999 100000\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 90000 89999 89999\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "0 1 0 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 1 1 0\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 1 1 1\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 1 1 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 1 2 0\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 1 2 1\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 1 2 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 2 0 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "0 2 1 0\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "0 2 1 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "0 2 1 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 2 2 0\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 2 2 1\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 2 2 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 0 0 1\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 0 0 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 0 1 1\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 0 1 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 0 2 0\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 0 2 1\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 0 2 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 1 0 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "1 1 0 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1 0\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 1 2 0\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 1 2 1\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 1 2 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "1 2 0 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "1 2 0 2\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "1 2 1 0\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "1 2 1 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "1 2 2 0\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "1 2 2 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "1 2 2 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "2 0 0 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 0 0 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "2 0 1 0\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 0 1 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 0 1 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "2 0 2 1\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "2 0 2 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "2 1 0 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 1 0 2\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1 0\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1 2\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 1 2 0\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 1 2 2\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "2 2 0 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 2 0 2\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1 0\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1 2\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2 0\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2 1\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "13118 79593 32785 22736\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "23039 21508 54113 76824\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "32959 49970 75441 55257\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "91573 91885 61527 58038\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "70620 15283 74892 15283\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "43308 1372 53325 1370\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "74005 7316 74004 7412\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "53208 42123 95332 85846\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "14969 66451 81419 29039\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "50042 34493 84536 17892\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "67949 70623 71979 70623\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "67603 35151 67603 39519\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "27149 26539 53690 17953\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "36711 38307 75018 72040\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "4650 67347 71998 50474\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "4075 33738 4561 33738\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "35868 55066 47754 55066\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "41150 1761 41152 1841\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "63557 16718 38133 80275\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "8956 24932 30356 33887\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "27338 8401 27337 12321\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "56613 48665 66408 48665\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "34750 34886 34751 44842\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "7591 24141 31732 23276\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "2333 91141 93473 66469\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "9 0 8 0\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "0 1000 100 99\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "4 4 2 2\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "0 4 4 3\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "100 1 1 100\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "9 17 14 16\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "0 3 3 1\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "10 0 0 10\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "5 0 0 4\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1 3\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "4 5 5 5\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
},
{
"input": "0 3 2 2\n",
"output": "Vasiliy\n",
"type": "stdin_stdout"
},
{
"input": "3 0 0 10\n",
"output": "Polycarp\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/532/C"
} | vfc_10098 |
apps | verifiable_code | 87 | Solve the following coding problem using the programming language python:
Petr wants to make a calendar for current month. For this purpose he draws a table in which columns correspond to weeks (a week is seven consequent days from Monday to Sunday), rows correspond to weekdays, and cells contain dates. For example, a calendar for January 2017 should look like on the picture: $\left. \begin{array}{|r|r|r|r|r|r|} \hline & {2} & {9} & {16} & {23} & {30} \\ \hline & {3} & {10} & {17} & {24} & {31} \\ \hline & {4} & {11} & {18} & {25} & {} \\ \hline & {5} & {12} & {19} & {26} & {} \\ \hline & {6} & {13} & {20} & {27} & {} \\ \hline & {7} & {14} & {21} & {28} & {} \\ \hline 1 & {8} & {15} & {22} & {29} & {} \\ \hline \end{array} \right.$
Petr wants to know how many columns his table should have given the month and the weekday of the first date of that month? Assume that the year is non-leap.
-----Input-----
The only line contain two integers m and d (1 ≤ m ≤ 12, 1 ≤ d ≤ 7) — the number of month (January is the first month, December is the twelfth) and the weekday of the first date of this month (1 is Monday, 7 is Sunday).
-----Output-----
Print single integer: the number of columns the table should have.
-----Examples-----
Input
1 7
Output
6
Input
1 1
Output
5
Input
11 6
Output
5
-----Note-----
The first example corresponds to the January 2017 shown on the picture in the statements.
In the second example 1-st January is Monday, so the whole month fits into 5 columns.
In the third example 1-st November is Saturday and 5 columns is enough.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
arr = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
a, b = list(map(int, input().split()))
a -= 1
b -= 1
ctr = 1
for i in range(arr[a] - 1):
b += 1
if (b == 7):
b = 0
ctr += 1
print(ctr)
``` | {
"language": "python",
"test_cases": [
{
"input": "1 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 7\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 7\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "6 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "7 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "8 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "8 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "8 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "9 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "11 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "12 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "12 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "12 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "12 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "12 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "12 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "12 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "9 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "2 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "12 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "12 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "9 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "7 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "11 7\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "6 6\n",
"output": "5\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/760/A"
} | vfc_10102 |
apps | verifiable_code | 88 | Solve the following coding problem using the programming language python:
The year 2015 is almost over.
Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 2015_10 = 11111011111_2. Note that he doesn't care about the number of zeros in the decimal representation.
Limak chose some interval of years. He is going to count all years from this interval that have exactly one zero in the binary representation. Can you do it faster?
Assume that all positive integers are always written without leading zeros.
-----Input-----
The only line of the input contains two integers a and b (1 ≤ a ≤ b ≤ 10^18) — the first year and the last year in Limak's interval respectively.
-----Output-----
Print one integer – the number of years Limak will count in his chosen interval.
-----Examples-----
Input
5 10
Output
2
Input
2015 2015
Output
1
Input
100 105
Output
0
Input
72057594000000000 72057595000000000
Output
26
-----Note-----
In the first sample Limak's interval contains numbers 5_10 = 101_2, 6_10 = 110_2, 7_10 = 111_2, 8_10 = 1000_2, 9_10 = 1001_2 and 10_10 = 1010_2. Two of them (101_2 and 110_2) have the described property.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def zero(strx):
k = []
str2 = list(strx)
for i in range(1, len(str2)):
str3 = str2[:]
str3[i] = '0'
k.append(''.join(str3))
return k
a = []
for i in range(1, 64):
a += zero('1'*i)
ct = 0
x, y = list(map(int, input().split(' ')))
for i in a:
if x <= int(i, 2) <= y:
ct+=1
print(ct)
``` | {
"language": "python",
"test_cases": [
{
"input": "5 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2015 2015\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 105\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "72057594000000000 72057595000000000\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "1 100\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000000000000\n",
"output": "1712\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "0\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": "2\n",
"type": "stdin_stdout"
},
{
"input": "1 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1 7\n",
"output": "3\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": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n",
"output": "2\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": "7 7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 8\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6 8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7 8\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8 8\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1022\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "1 1023\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "1 1024\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "1 1025\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "1 1026\n",
"output": "45\n",
"type": "stdin_stdout"
},
{
"input": "509 1022\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "510 1022\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "511 1022\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "512 1022\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "513 1022\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "509 1023\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "510 1023\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "511 1023\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "512 1023\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "513 1023\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "509 1024\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "510 1024\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "511 1024\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "512 1024\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "513 1024\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "509 1025\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "510 1025\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "511 1025\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "512 1025\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "513 1025\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000\n",
"output": "408\n",
"type": "stdin_stdout"
},
{
"input": "10000000000 70000000000000000\n",
"output": "961\n",
"type": "stdin_stdout"
},
{
"input": "1 935829385028502935\n",
"output": "1712\n",
"type": "stdin_stdout"
},
{
"input": "500000000000000000 1000000000000000000\n",
"output": "58\n",
"type": "stdin_stdout"
},
{
"input": "500000000000000000 576460752303423488\n",
"output": "57\n",
"type": "stdin_stdout"
},
{
"input": "576460752303423488 1000000000000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999 1000000000000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1124800395214847 36011204832919551\n",
"output": "257\n",
"type": "stdin_stdout"
},
{
"input": "1124800395214847 36011204832919550\n",
"output": "256\n",
"type": "stdin_stdout"
},
{
"input": "1124800395214847 36011204832919552\n",
"output": "257\n",
"type": "stdin_stdout"
},
{
"input": "1124800395214846 36011204832919551\n",
"output": "257\n",
"type": "stdin_stdout"
},
{
"input": "1124800395214848 36011204832919551\n",
"output": "256\n",
"type": "stdin_stdout"
},
{
"input": "1 287104476244869119\n",
"output": "1603\n",
"type": "stdin_stdout"
},
{
"input": "1 287104476244869118\n",
"output": "1602\n",
"type": "stdin_stdout"
},
{
"input": "1 287104476244869120\n",
"output": "1603\n",
"type": "stdin_stdout"
},
{
"input": "492581209243647 1000000000000000000\n",
"output": "583\n",
"type": "stdin_stdout"
},
{
"input": "492581209243646 1000000000000000000\n",
"output": "583\n",
"type": "stdin_stdout"
},
{
"input": "492581209243648 1000000000000000000\n",
"output": "582\n",
"type": "stdin_stdout"
},
{
"input": "1099444518911 1099444518911\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1099444518910 1099444518911\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1099444518911 1099444518912\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1099444518910 1099444518912\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "864691128455135231 864691128455135231\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "864691128455135231 864691128455135232\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "864691128455135230 864691128455135232\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "864691128455135230 864691128455135231\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "864691128455135231 1000000000000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "864691128455135232 1000000000000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "864691128455135230 1000000000000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "576460752303423487 576460752303423487\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 576460752303423487\n",
"output": "1711\n",
"type": "stdin_stdout"
},
{
"input": "1 576460752303423486\n",
"output": "1711\n",
"type": "stdin_stdout"
},
{
"input": "2 1000000000000000000\n",
"output": "1712\n",
"type": "stdin_stdout"
},
{
"input": "3 1000000000000000000\n",
"output": "1711\n",
"type": "stdin_stdout"
},
{
"input": "4 1000000000000000000\n",
"output": "1711\n",
"type": "stdin_stdout"
},
{
"input": "5 1000000000000000000\n",
"output": "1711\n",
"type": "stdin_stdout"
},
{
"input": "6 1000000000000000000\n",
"output": "1710\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/611/B"
} | vfc_10106 |
apps | verifiable_code | 89 | Solve the following coding problem using the programming language python:
You are given an integer N. Consider all possible segments on the coordinate axis with endpoints at integer points with coordinates between 0 and N, inclusive; there will be $\frac{n(n + 1)}{2}$ of them.
You want to draw these segments in several layers so that in each layer the segments don't overlap (they might touch at the endpoints though). You can not move the segments to a different location on the coordinate axis.
Find the minimal number of layers you have to use for the given N.
-----Input-----
The only input line contains a single integer N (1 ≤ N ≤ 100).
-----Output-----
Output a single integer - the minimal number of layers required to draw the segments for the given N.
-----Examples-----
Input
2
Output
2
Input
3
Output
4
Input
4
Output
6
-----Note-----
As an example, here are the segments and their optimal arrangement into layers for N = 4. [Image]
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())
print(max((i+1)*(n-i)for i in range(n)))
``` | {
"language": "python",
"test_cases": [
{
"input": "2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "121\n",
"type": "stdin_stdout"
},
{
"input": "100\n",
"output": "2550\n",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "12\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "13\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "14\n",
"output": "56\n",
"type": "stdin_stdout"
},
{
"input": "15\n",
"output": "64\n",
"type": "stdin_stdout"
},
{
"input": "16\n",
"output": "72\n",
"type": "stdin_stdout"
},
{
"input": "17\n",
"output": "81\n",
"type": "stdin_stdout"
},
{
"input": "18\n",
"output": "90\n",
"type": "stdin_stdout"
},
{
"input": "19\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "20\n",
"output": "110\n",
"type": "stdin_stdout"
},
{
"input": "22\n",
"output": "132\n",
"type": "stdin_stdout"
},
{
"input": "23\n",
"output": "144\n",
"type": "stdin_stdout"
},
{
"input": "24\n",
"output": "156\n",
"type": "stdin_stdout"
},
{
"input": "25\n",
"output": "169\n",
"type": "stdin_stdout"
},
{
"input": "26\n",
"output": "182\n",
"type": "stdin_stdout"
},
{
"input": "27\n",
"output": "196\n",
"type": "stdin_stdout"
},
{
"input": "28\n",
"output": "210\n",
"type": "stdin_stdout"
},
{
"input": "29\n",
"output": "225\n",
"type": "stdin_stdout"
},
{
"input": "30\n",
"output": "240\n",
"type": "stdin_stdout"
},
{
"input": "31\n",
"output": "256\n",
"type": "stdin_stdout"
},
{
"input": "32\n",
"output": "272\n",
"type": "stdin_stdout"
},
{
"input": "33\n",
"output": "289\n",
"type": "stdin_stdout"
},
{
"input": "34\n",
"output": "306\n",
"type": "stdin_stdout"
},
{
"input": "35\n",
"output": "324\n",
"type": "stdin_stdout"
},
{
"input": "36\n",
"output": "342\n",
"type": "stdin_stdout"
},
{
"input": "37\n",
"output": "361\n",
"type": "stdin_stdout"
},
{
"input": "38\n",
"output": "380\n",
"type": "stdin_stdout"
},
{
"input": "39\n",
"output": "400\n",
"type": "stdin_stdout"
},
{
"input": "40\n",
"output": "420\n",
"type": "stdin_stdout"
},
{
"input": "41\n",
"output": "441\n",
"type": "stdin_stdout"
},
{
"input": "42\n",
"output": "462\n",
"type": "stdin_stdout"
},
{
"input": "43\n",
"output": "484\n",
"type": "stdin_stdout"
},
{
"input": "44\n",
"output": "506\n",
"type": "stdin_stdout"
},
{
"input": "45\n",
"output": "529\n",
"type": "stdin_stdout"
},
{
"input": "46\n",
"output": "552\n",
"type": "stdin_stdout"
},
{
"input": "47\n",
"output": "576\n",
"type": "stdin_stdout"
},
{
"input": "48\n",
"output": "600\n",
"type": "stdin_stdout"
},
{
"input": "49\n",
"output": "625\n",
"type": "stdin_stdout"
},
{
"input": "50\n",
"output": "650\n",
"type": "stdin_stdout"
},
{
"input": "51\n",
"output": "676\n",
"type": "stdin_stdout"
},
{
"input": "52\n",
"output": "702\n",
"type": "stdin_stdout"
},
{
"input": "53\n",
"output": "729\n",
"type": "stdin_stdout"
},
{
"input": "54\n",
"output": "756\n",
"type": "stdin_stdout"
},
{
"input": "55\n",
"output": "784\n",
"type": "stdin_stdout"
},
{
"input": "56\n",
"output": "812\n",
"type": "stdin_stdout"
},
{
"input": "57\n",
"output": "841\n",
"type": "stdin_stdout"
},
{
"input": "58\n",
"output": "870\n",
"type": "stdin_stdout"
},
{
"input": "59\n",
"output": "900\n",
"type": "stdin_stdout"
},
{
"input": "60\n",
"output": "930\n",
"type": "stdin_stdout"
},
{
"input": "61\n",
"output": "961\n",
"type": "stdin_stdout"
},
{
"input": "62\n",
"output": "992\n",
"type": "stdin_stdout"
},
{
"input": "63\n",
"output": "1024\n",
"type": "stdin_stdout"
},
{
"input": "64\n",
"output": "1056\n",
"type": "stdin_stdout"
},
{
"input": "65\n",
"output": "1089\n",
"type": "stdin_stdout"
},
{
"input": "66\n",
"output": "1122\n",
"type": "stdin_stdout"
},
{
"input": "67\n",
"output": "1156\n",
"type": "stdin_stdout"
},
{
"input": "68\n",
"output": "1190\n",
"type": "stdin_stdout"
},
{
"input": "69\n",
"output": "1225\n",
"type": "stdin_stdout"
},
{
"input": "70\n",
"output": "1260\n",
"type": "stdin_stdout"
},
{
"input": "71\n",
"output": "1296\n",
"type": "stdin_stdout"
},
{
"input": "72\n",
"output": "1332\n",
"type": "stdin_stdout"
},
{
"input": "73\n",
"output": "1369\n",
"type": "stdin_stdout"
},
{
"input": "74\n",
"output": "1406\n",
"type": "stdin_stdout"
},
{
"input": "75\n",
"output": "1444\n",
"type": "stdin_stdout"
},
{
"input": "76\n",
"output": "1482\n",
"type": "stdin_stdout"
},
{
"input": "77\n",
"output": "1521\n",
"type": "stdin_stdout"
},
{
"input": "78\n",
"output": "1560\n",
"type": "stdin_stdout"
},
{
"input": "79\n",
"output": "1600\n",
"type": "stdin_stdout"
},
{
"input": "80\n",
"output": "1640\n",
"type": "stdin_stdout"
},
{
"input": "81\n",
"output": "1681\n",
"type": "stdin_stdout"
},
{
"input": "82\n",
"output": "1722\n",
"type": "stdin_stdout"
},
{
"input": "83\n",
"output": "1764\n",
"type": "stdin_stdout"
},
{
"input": "84\n",
"output": "1806\n",
"type": "stdin_stdout"
},
{
"input": "85\n",
"output": "1849\n",
"type": "stdin_stdout"
},
{
"input": "86\n",
"output": "1892\n",
"type": "stdin_stdout"
},
{
"input": "87\n",
"output": "1936\n",
"type": "stdin_stdout"
},
{
"input": "88\n",
"output": "1980\n",
"type": "stdin_stdout"
},
{
"input": "89\n",
"output": "2025\n",
"type": "stdin_stdout"
},
{
"input": "90\n",
"output": "2070\n",
"type": "stdin_stdout"
},
{
"input": "91\n",
"output": "2116\n",
"type": "stdin_stdout"
},
{
"input": "92\n",
"output": "2162\n",
"type": "stdin_stdout"
},
{
"input": "93\n",
"output": "2209\n",
"type": "stdin_stdout"
},
{
"input": "94\n",
"output": "2256\n",
"type": "stdin_stdout"
},
{
"input": "95\n",
"output": "2304\n",
"type": "stdin_stdout"
},
{
"input": "96\n",
"output": "2352\n",
"type": "stdin_stdout"
},
{
"input": "97\n",
"output": "2401\n",
"type": "stdin_stdout"
},
{
"input": "98\n",
"output": "2450\n",
"type": "stdin_stdout"
},
{
"input": "99\n",
"output": "2500\n",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "9\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/909/B"
} | vfc_10110 |
apps | verifiable_code | 90 | Solve the following coding problem using the programming language python:
Anya loves to fold and stick. Today she decided to do just that.
Anya has n cubes lying in a line and numbered from 1 to n from left to right, with natural numbers written on them. She also has k stickers with exclamation marks. We know that the number of stickers does not exceed the number of cubes.
Anya can stick an exclamation mark on the cube and get the factorial of the number written on the cube. For example, if a cube reads 5, then after the sticking it reads 5!, which equals 120.
You need to help Anya count how many ways there are to choose some of the cubes and stick on some of the chosen cubes at most k exclamation marks so that the sum of the numbers written on the chosen cubes after the sticking becomes equal to S. Anya can stick at most one exclamation mark on each cube. Can you do it?
Two ways are considered the same if they have the same set of chosen cubes and the same set of cubes with exclamation marks.
-----Input-----
The first line of the input contains three space-separated integers n, k and S (1 ≤ n ≤ 25, 0 ≤ k ≤ n, 1 ≤ S ≤ 10^16) — the number of cubes and the number of stickers that Anya has, and the sum that she needs to get.
The second line contains n positive integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the numbers, written on the cubes. The cubes in the input are described in the order from left to right, starting from the first one.
Multiple cubes can contain the same numbers.
-----Output-----
Output the number of ways to choose some number of cubes and stick exclamation marks on some of them so that the sum of the numbers became equal to the given number S.
-----Examples-----
Input
2 2 30
4 3
Output
1
Input
2 2 7
4 3
Output
1
Input
3 1 1
1 1 1
Output
6
-----Note-----
In the first sample the only way is to choose both cubes and stick an exclamation mark on each of them.
In the second sample the only way is to choose both cubes but don't stick an exclamation mark on any of them.
In the third sample it is possible to choose any of the cubes in three ways, and also we may choose to stick or not to stick the exclamation mark on it. So, the total number of ways is six.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
fact = [ 1 ]
for i in range( 1, 20, 1 ):
fact.append( fact[ i - 1 ] * i )
from collections import defaultdict
N, K, S = list(map( int, input().split() ))
A = list( map( int, input().split() ) )
ldp = [ [ defaultdict( int ) for i in range( K + 1 ) ] for j in range( 2 ) ]
ldp[ 0 ][ 0 ][ 0 ] = 1
for i in range( N // 2 ):
for j in range( K + 1 ):
ldp[ ~ i & 1 ][ j ].clear()
for j in range( K + 1 ):
for key in ldp[ i & 1 ][ j ]:
ldp[ ~ i & 1 ][ j ][ key ] += ldp[ i & 1 ][ j ][ key ] # toranai
ldp[ ~ i & 1 ][ j ][ key + A[ i ] ] += ldp[ i & 1 ][ j ][ key ] # toru
if j + 1 <= K and A[ i ] <= 18:
ldp[ ~ i & 1 ][ j + 1 ][ key + fact[ A[ i ] ] ] += ldp[ i & 1 ][ j ][ key ] # kaijyou totte toru
rdp = [ [ defaultdict( int ) for i in range( K + 1 ) ] for j in range( 2 ) ]
rdp[ 0 ][ 0 ][ 0 ] = 1
for i in range( N - N // 2 ):
for j in range( K + 1 ):
rdp[ ~ i & 1 ][ j ].clear()
for j in range( K + 1 ):
for key in rdp[ i & 1 ][ j ]:
rdp[ ~ i & 1 ][ j ][ key ] += rdp[ i & 1 ][ j ][ key ]
rdp[ ~ i & 1 ][ j ][ key + A[ N // 2 + i ] ] += rdp[ i & 1 ][ j ][ key ]
if j + 1 <= K and A[ N // 2 + i ] <= 18:
rdp[ ~ i & 1 ][ j + 1 ][ key + fact[ A[ N // 2 + i ] ] ] += rdp[ i & 1 ][ j ][ key ]
ans = 0
for i in range( K + 1 ):
for key in ldp[ N // 2 & 1 ][ i ]:
for j in range( 0, K - i + 1, 1 ):
ans += ldp[ N // 2 & 1 ][ i ][ key ] * rdp[ N - N // 2 & 1 ][ j ][ S - key ]
print( ans )
``` | {
"language": "python",
"test_cases": [
{
"input": "2 2 30\n4 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 2 7\n4 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 1 1\n1 1 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "25 25 25\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\n",
"output": "33554432\n",
"type": "stdin_stdout"
},
{
"input": "13 1 60\n3 6 3 4 3 5 1 4 4 4 3 4 3\n",
"output": "155\n",
"type": "stdin_stdout"
},
{
"input": "10 10 1002\n5 6 5 3 4 3 3 2 6 4\n",
"output": "124\n",
"type": "stdin_stdout"
},
{
"input": "7 6 14\n1 3 2 4 1 1 6\n",
"output": "84\n",
"type": "stdin_stdout"
},
{
"input": "8 7 169\n4 3 4 3 5 5 2 5\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "1 0 384338286\n384338286\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 6 14\n1 1 1 2 2 2 1 1 2 1\n",
"output": "848\n",
"type": "stdin_stdout"
},
{
"input": "10 8 35\n3 3 2 3 1 1 3 3 2 2\n",
"output": "203\n",
"type": "stdin_stdout"
},
{
"input": "5 3 364332\n8 6 4 6 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 2 6227020842\n17 15 13 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "25 15 38\n2 1 2 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 1 1 2 1 2 1 2\n",
"output": "29703676\n",
"type": "stdin_stdout"
},
{
"input": "25 1 25\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\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "23 22 2557\n109 117 119 123 117 122 106 100 108 105 119 105 108 120 113 101 115 101 114 123 101 100 111\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "25 21 7825123418112377\n19 20 17 20 18 19 17 20 19 18 18 20 17 20 18 17 20 19 19 20 17 17 18 17 19\n",
"output": "175\n",
"type": "stdin_stdout"
},
{
"input": "25 9 137\n4 3 1 4 1 2 2 1 1 1 4 4 3 4 4 3 2 1 3 2 4 2 4 1 4\n",
"output": "2310192318\n",
"type": "stdin_stdout"
},
{
"input": "17 17 2925\n5 6 6 5 5 5 5 6 5 5 6 6 6 5 5 6 6\n",
"output": "4774\n",
"type": "stdin_stdout"
},
{
"input": "25 16 13326087796\n157576937 627434432 942652043 706432863 631136945 714549755 465703470 663358517 695561723 249240606 833566455 396564536 758483017 253748999 978210764 530023233 193812243 317718202 184788435 892848108 150420430 330992298 780787784 196460118 674015883\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "25 19 6402373705728432\n18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "25 20 7469435990016370\n18 17 18 18 18 17 18 18 17 18 18 17 18 17 17 18 18 17 17 17 18 17 18 18 17\n",
"output": "2310\n",
"type": "stdin_stdout"
},
{
"input": "25 4 8954954072064251\n17 18 16 17 17 20 18 16 17 19 20 17 16 19 20 17 16 18 17 16 17 16 17 16 19\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "25 18 7134671351808397\n17 17 18 18 21 20 21 20 19 17 21 18 16 17 18 18 17 20 18 20 18 16 18 21 21\n",
"output": "160\n",
"type": "stdin_stdout"
},
{
"input": "25 2 376618217984000\n17 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 16 1000000000 2345 34521 6587 4564536 234134 12344 23561 2341 2345 324523 123123 4567 8976 345 2134\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "25 25 2000000023\n1000000000 1000000000 1 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1\n",
"output": "9422602240\n",
"type": "stdin_stdout"
},
{
"input": "25 13 2000000023\n1000000000 1000000000 1 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1\n",
"output": "10195317702\n",
"type": "stdin_stdout"
},
{
"input": "25 19 2000000023\n1000000000 1000000000 1 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1\n",
"output": "10238328832\n",
"type": "stdin_stdout"
},
{
"input": "25 25 2000005023\n1000000000 1000000000 5000 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1\n",
"output": "3105865728\n",
"type": "stdin_stdout"
},
{
"input": "24 21 732472010010838\n16 4 10 14 4 1 14 8 2 17 8 11 2 7 13 7 7 3 14 10 7 17 17 10\n",
"output": "19440\n",
"type": "stdin_stdout"
},
{
"input": "23 1 43165708951941\n8 6 9 17 1 14 1 12 13 5 15 18 16 8 9 4 8 13 16 7 11 13 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "23 14 376709893904263\n14 6 11 4 16 10 13 2 10 6 10 11 6 14 17 7 2 17 17 13 8 1 2\n",
"output": "16956\n",
"type": "stdin_stdout"
},
{
"input": "25 23 355687987299309\n14 15 11 2 6 15 14 9 1 4 7 18 2 17 3 3 2 11 6 18 13 14 2 11 12\n",
"output": "96\n",
"type": "stdin_stdout"
},
{
"input": "25 6 355781798669775\n14 2 13 17 12 18 10 11 18 2 6 18 1 5 9 3 2 3 14 1 1 18 12 11 10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "24 23 6779165946558798\n481199252 6 12 2 5 4 6 15 3 12 14 18 8 6 13 4 17 12 3 2 13 14 16 8\n",
"output": "6264\n",
"type": "stdin_stdout"
},
{
"input": "24 22 93579450246\n54748096 75475634 6 12 18 1 12 13 11 7 10 17 9 9 10 9 6 14 14 15 5 5 15 13\n",
"output": "2352\n",
"type": "stdin_stdout"
},
{
"input": "24 21 711557276608128\n923264237 374288891 535590429 18 17 17 8 14 15 3 4 11 15 2 7 13 8 12 13 3 5 14 10 14\n",
"output": "348\n",
"type": "stdin_stdout"
},
{
"input": "24 20 6402470099308437\n496813081 673102149 561219907 730593611 4 2 15 11 10 12 3 13 16 1 10 8 18 14 6 6 14 6 9 11\n",
"output": "600\n",
"type": "stdin_stdout"
},
{
"input": "24 19 22239162909709\n365329221 412106895 291882089 564718673 358502890 3 7 13 18 8 7 12 3 8 7 12 2 8 4 12 6 9 15 16\n",
"output": "108\n",
"type": "stdin_stdout"
},
{
"input": "24 18 6402551633230723\n643910770 5887448 757703054 544067926 902981667 712695184 3 14 4 11 3 14 4 11 4 7 8 10 7 11 6 18 14 13\n",
"output": "648\n",
"type": "stdin_stdout"
},
{
"input": "24 17 6758151602395830\n72235422 449924898 783332532 378192988 592684636 147499872 343857831 12 17 7 14 12 2 14 1 11 11 12 10 18 16 5 5 18\n",
"output": "192\n",
"type": "stdin_stdout"
},
{
"input": "24 16 376613867481065\n940751563 43705451 513994713 652509537 432130709 317463343 687041819 58265855 7 3 14 10 11 17 16 16 17 10 13 2 3 5 18 5\n",
"output": "64\n",
"type": "stdin_stdout"
},
{
"input": "24 15 376715306932970\n514300407 782710197 539624191 631858791 976609486 752268030 30225807 279200011 467188665 12 18 5 4 2 13 10 1 13 16 1 13 14 17 6\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "23 13 357006388025624\n598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754 223219513 9 17 13 13 17 15 5 2 15 8 2 7 8\n",
"output": "64\n",
"type": "stdin_stdout"
},
{
"input": "23 12 357087149917608\n26521171 379278816 8989449 50899375 935650934 529615950 494390299 427618702 979962232 602512657 429731081 1 10 2 14 9 3 18 17 15 16 12 7\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "23 11 18015396922\n895037311 678092074 34618927 179991732 480129711 404612126 132541583 648552857 967299118 276773097 341033928 482750975 1 1 11 14 13 2 16 13 7 7 2\n",
"output": "32\n",
"type": "stdin_stdout"
},
{
"input": "23 10 5498434429\n468586155 417096820 205472596 159340986 464799976 839416813 475725571 869487013 249603301 246000832 807626376 125583769 129772276 8 8 18 15 4 9 16 7 7 11\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "23 9 7822306195\n747167704 715910077 936134778 138690239 714311457 9380284 523942263 795453872 826874779 625293976 864153416 63383860 9374518 851872013 9 13 8 3 8 4 17 16 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "23 8 6129434724\n615683844 454914823 961764255 972815301 258790234 444184972 162093547 16388028 814211665 299554415 625713159 1183950 34200951 73842336 394092460 17 14 1 10 11 4 7 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "23 7 6584075104\n189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004147 176573082 279397774 12 3 17 9 4 17 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "23 6 6423305153580378\n912524637 347508634 863280107 226481104 787939275 48953130 553494227 458256339 673787326 353107999 298575751 436592642 233596921 957974470 254020999 707869688 64999512 1 16 12 14 2 18\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "23 5 6403689500951790\n486073481 86513380 593942288 60606166 627385348 778725113 896678215 384223198 661124212 882144246 60135494 374392733 408166459 179944793 331468916 401182818 69503967 798728037 15 18 6 11 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "23 4 355697995919632\n764655030 680293934 914539062 744988123 317088317 653721289 239862203 605157354 943428394 261437390 821695238 312192823 432992892 547139308 408916833 829654733 223751525 672158759 193787527 17 9 17 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "25 5 355697433057426\n586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717802881 588066499 661699500 14 17 5 5 12\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "22 1 15078298178\n160137548 807874739 723325809 995465063 693137631 646771913 971489138 603747543 801665542 882310956 163114045 892278880 371370111 459773357 909727810 630170326 940240523 886200899 882106547 953987440 703402350 8\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "22 0 11671182837\n733686393 546879484 748955287 974814317 532583704 671511192 314673126 824681699 789002429 261604100 219641085 389887482 250972352 976710976 987175727 58642240 534679569 759631621 26403492 101051189 178325936 789669437\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "23 0 10202579405\n162011045 845692742 774584765 103906675 222286673 251540072 657857114 45615854 71306611 790640347 835976636 327687572 570766082 48938195 769656348 341889962 393959831 928029640 320443541 248114937 798473713 159552755 533648295\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "24 0 12493321628\n30527185 439473295 505246946 83255928 766765450 981312055 706073806 971582714 648578089 464900787 597536380 265487663 450368323 565875814 847104265 475394581 693431581 241651850 464740486 100211390 418621491 969627560 755522678 50031311\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "25 0 12982465295\n604076030 178478041 676100616 622413694 606211522 711084038 344225090 192516869 635914975 139161226 359096124 908320457 770162052 933070329 69776374 758642303 552711844 820115276 609037430 392499330 598577781 484735069 272364358 72345168 670829299\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "24 23 20929016909621\n481199252 6 12 2 5 4 6 15 3 12 14 18 8 6 13 4 17 12 3 2 13 14 16 8\n",
"output": "1007724\n",
"type": "stdin_stdout"
},
{
"input": "24 21 355689301156580\n923264237 374288891 535590429 18 17 17 8 14 15 3 4 11 15 2 7 13 8 12 13 3 5 14 10 14\n",
"output": "38360\n",
"type": "stdin_stdout"
},
{
"input": "24 16 20926395674529\n940751563 43705451 513994713 652509537 432130709 317463343 687041819 58265855 7 3 14 10 11 17 16 16 17 10 13 2 3 5 18 5\n",
"output": "4000\n",
"type": "stdin_stdout"
},
{
"input": "23 13 711377554159955\n598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754 223219513 9 17 13 13 17 15 5 2 15 8 2 7 8\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "23 8 90819114674\n615683844 454914823 961764255 972815301 258790234 444184972 162093547 16388028 814211665 299554415 625713159 1183950 34200951 73842336 394092460 17 14 1 10 11 4 7 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "25 5 7183838143\n586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717802881 588066499 661699500 14 17 5 5 12\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "22 0 7002300855\n733686393 546879484 748955287 974814317 532583704 671511192 314673126 824681699 789002429 261604100 219641085 389887482 250972352 976710976 987175727 58642240 534679569 759631621 26403492 101051189 178325936 789669437\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "25 0 8812325752\n604076030 178478041 676100616 622413694 606211522 711084038 344225090 192516869 635914975 139161226 359096124 908320457 770162052 933070329 69776374 758642303 552711844 820115276 609037430 392499330 598577781 484735069 272364358 72345168 670829299\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "23 12 1307674408320\n818219322 490480030 946157371 335075927 504332527 696433549 421447064 242605730 513711473 879700707 875141086 8 18 5 8 18 2 2 2 11 15 10 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "23 9 356999252684127\n672509980 76127167 93413008 709188915 563436455 432103889 115272158 698233775 382556143 771342465 178361701 711213646 803513458 87049574 16 18 5 17 5 15 9 10 18\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "22 7 94086626507\n400086390 24218459 946613393 146658464 240900479 960251651 888572685 326830726 485573749 506482600 828508367 964019704 563712967 891568106 732815759 7 7 14 1 2 1 18\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "23 19 694110791\n694105695 469829284 490636148 769880615 1 12 7 9 18 15 15 7 7 6 18 2 5 1 2 15 15 15 17\n",
"output": "24564\n",
"type": "stdin_stdout"
},
{
"input": "23 15 19\n40331947 578270895 19785190 374648773 533884491 64268719 268359611 970419752 12 16 17 3 1 4 9 2 11 10 7 15 1 3 7\n",
"output": "331\n",
"type": "stdin_stdout"
},
{
"input": "23 2 5065472115\n428801639 184568779 477337858 18989778 249804431 579004904 679880522 901530462 200642926 941909941 377757672 300378484 103633484 503801915 910270476 13399319 214483686 671551510 986061470 346894110 521433581 12 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "23 2 4048109324\n770994128 412395956 564263966 104420757 877068479 285202875 550663793 644680192 709693551 190709580 978965731 122048808 648617624 375329937 297799155 929741838 337809699 382782724 945661847 136720969 898777264 4 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "22 11 355777681121374\n352861197 501423986 564719989 916003293 908603727 959086385 17789414 583680997 826780019 112458769 227300308 12 17 14 6 3 12 10 2 11 8 12\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "23 5 5657256853\n61927663 677005715 711975626 730307769 817964551 549532534 856838700 189052146 695624689 4100527 530520923 59586998 333673225 125072914 526575822 99222914 877574527 650143337 5 11 3 4 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "22 16 22231735758643\n447311584 102302533 183282606 937122147 163131823 371482325 4 16 16 9 10 15 6 16 4 10 14 8 12 10 2 2\n",
"output": "3573\n",
"type": "stdin_stdout"
},
{
"input": "23 17 6759458873943562\n14702469 303954345 330082221 499652598 895733207 843334564 15 5 12 4 12 14 4 18 17 18 4 3 12 6 2 2 5\n",
"output": "128\n",
"type": "stdin_stdout"
},
{
"input": "22 19 6402375527188783\n669424209 895126102 256910425 17 17 8 11 17 1 18 14 7 4 1 15 5 8 15 10 10 10 13\n",
"output": "1886\n",
"type": "stdin_stdout"
},
{
"input": "22 8 6960722973\n425715868 3567713 786059466 876430447 879051763 886218511 170876867 706123870 247133492 299058498 853334800 185990027 641160884 174815828 6 1 18 2 5 7 14 5\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "25 20 1308180371599\n731464501 285497487 892432116 218274129 458569375 3 14 17 11 16 7 15 16 3 1 5 11 16 11 15 13 7 5 10 10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "25 17 1311878711325\n757093979 264846740 436910893 243013408 801753363 254065895 579134035 609847689 15 10 9 4 13 7 18 3 14 5 2 15 8 12 7 15 17\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "25 2 3288144341\n782723456 393939098 126613862 677818096 144937351 475000050 861438217 284108128 274856175 88383185 912041882 3941587 489034386 211074902 308950662 308611657 417645457 784954245 947958718 464312042 578753998 973835975 805832248 17 18\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "25 4 5095166378\n953577126 373288351 966059935 552814271 193154043 400966910 143742399 663401272 36415918 26183275 936868315 520879206 566482303 639546816 313455116 182042379 711685505 932017994 422882304 979419551 800628381 18 2 4 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "25 9 1399657417\n684239308 207413413 510538712 577553550 831305327 326933769 426046582 192437520 652751470 963983365 111437852 593106425 348962924 332859946 467702674 495664590 4 12 4 6 2 1 18 9 12\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 1 24\n4 10 14\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "25 25 3000005022\n1000000000 1000000000 5000 1000000000 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1\n",
"output": "1104076800\n",
"type": "stdin_stdout"
},
{
"input": "25 25 1000005024\n1000000000 1 5000 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1\n",
"output": "8662843392\n",
"type": "stdin_stdout"
},
{
"input": "25 25 12\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\n",
"output": "21300428800\n",
"type": "stdin_stdout"
},
{
"input": "25 13 64182542054562\n10 13 10 11 14 15 16 16 16 13 11 12 13 16 15 15 13 16 13 12 14 11 11 14 14\n",
"output": "2400\n",
"type": "stdin_stdout"
},
{
"input": "25 25 6758073589000599\n7 6 13 15 3 2 4 18 1 17 13 17 9 5 16 17 12 18 3 9 17 8 1 7 9\n",
"output": "128\n",
"type": "stdin_stdout"
},
{
"input": "25 23 6780291602197838\n6 13 18 8 4 7 15 2 17 1 16 8 4 16 10 18 17 9 14 1 14 2 8 11 15\n",
"output": "2336\n",
"type": "stdin_stdout"
},
{
"input": "25 2 12680562939\n715049313 915998492 578565942 855855826 497510114 582399573 930430334 286893113 391355789 331145449 93832233 202504960 728884607 204451031 664271485 292928862 572940745 227069487 402758132 446406368 779727087 595211160 904571581 16 18\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "25 2 11195364025\n98718117 970465012 358887575 342461819 363429300 22954887 226633382 276685273 929524398 919300070 611367092 828471311 346387103 140272916 158548966 957310154 619598695 481800204 62782071 980986351 636091193 761224761 26106419 18 17\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "25 21 355687471641600\n757093979 436910893 801753363 43545600 3 4 5 6 7 8 9 10 11 12 13 13 14 14 15 15 15 16 16 17 17\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "25 0 12\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\n",
"output": "5200300\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "25 25 10000000000000000\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "25 25 1307674368024\n15 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": "16777216\n",
"type": "stdin_stdout"
},
{
"input": "25 25 10000000000000000\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\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "25 25 6780385530509849\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 32768 65536 131072 262144 524288 1048576 2097152\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "25 25 12345678912345\n850721285 30306609 347099405 96957258 314543014 652545309 470894833 754515549 609681909 430315134 826092337 795319741 19167845 135991499 395492127 459806108 925737587 385950327 672837854 485396408 132630282 743562669 239478998 748888777 156720060\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/525/E"
} | vfc_10114 |
apps | verifiable_code | 91 | Solve the following coding problem using the programming language python:
Suppose you are performing the following algorithm. There is an array $v_1, v_2, \dots, v_n$ filled with zeroes at start. The following operation is applied to the array several times — at $i$-th step ($0$-indexed) you can: either choose position $pos$ ($1 \le pos \le n$) and increase $v_{pos}$ by $k^i$; or not choose any position and skip this step.
You can choose how the algorithm would behave on each step and when to stop it. The question is: can you make array $v$ equal to the given array $a$ ($v_j = a_j$ for each $j$) after some step?
-----Input-----
The first line contains one integer $T$ ($1 \le T \le 1000$) — the number of test cases. Next $2T$ lines contain test cases — two lines per test case.
The first line of each test case contains two integers $n$ and $k$ ($1 \le n \le 30$, $2 \le k \le 100$) — the size of arrays $v$ and $a$ and value $k$ used in the algorithm.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^{16}$) — the array you'd like to achieve.
-----Output-----
For each test case print YES (case insensitive) if you can achieve the array $a$ after some step or NO (case insensitive) otherwise.
-----Example-----
Input
5
4 100
0 0 0 0
1 2
1
3 4
1 4 1
3 2
0 1 3
3 9
0 59049 810
Output
YES
YES
NO
NO
YES
-----Note-----
In the first test case, you can stop the algorithm before the $0$-th step, or don't choose any position several times and stop the algorithm.
In the second test case, you can add $k^0$ to $v_1$ and stop the algorithm.
In the third test case, you can't make two $1$ in the array $v$.
In the fifth test case, you can skip $9^0$ and $9^1$, then add $9^2$ and $9^3$ to $v_3$, skip $9^4$ and finally, add $9^5$ to $v_2$.
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,k = list(map(int,input().split()))
a = list(map(int,input().split()))
for i in range(60, -1, -1):
m = k ** i
for j in range(n):
if a[j] >= m:
a[j] -= m
break
if all(i == 0 for i in a):
print('YES')
else:
print('NO')
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n4 100\n0 0 0 0\n1 2\n1\n3 4\n1 4 1\n3 2\n0 1 3\n3 9\n0 59049 810\n",
"output": "YES\nYES\nNO\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 2\n1 2 4 8 17\n2 3\n1 2\n4 3\n10 4 13 12\n",
"output": "NO\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n10000000000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n10000000000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n2251799813685248 2251799813685248\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n9007199254740992 9007199254740992\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n1099511627776 1099511627776\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n1125899906842624 1125899906842624\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n1024 3072\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n23 100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 10\n5 20\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 16\n100\n1 16\n1000\n",
"output": "NO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 9\n18\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 16\n255\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 16\n1000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 4\n3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 63\n3735006104496620\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 9\n11\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 8\n12\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 4\n77\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 6\n3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 4\n9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 9\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 4\n100 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n9 19\n8502576973597188 9105058903836444 7163781177832759 8144600471655789 9301214079343755 3226532954663459 3517141006105818 7032582717385788 3894225654898315\n30 53\n418195493 148877 1174711139837 2809 3299763591802133 7890481 1 62259690411361 22164361129 53 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "NO\nYES\n",
"type": "stdin_stdout"
},
{
"input": "1\n28 2\n281474976710656 0 281474976710656 70368752566272 2251799814733824 33554432 0 352118598795264 17600775979008 134217728 0 34359738368 0 1125900175278208 0 274884214784 65568 2 0 274877906944 8657182720 0 1099511627776 524288 140771848355840 4503599627370496 17592186044672 34359738896\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 100\n0 0 0 0\n1 8\n100\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"input": "5\n4 100\n0 0 0 0\n1 5\n3\n3 4\n1 4 1\n3 2\n0 1 3\n3 9\n0 59049 810\n",
"output": "YES\nNO\nNO\nNO\nYES\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 4\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 9\n0 18\n4 100\n0 0 0 0\n1 2\n1\n",
"output": "NO\nYES\nYES\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 4\n9 16\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 100\n0 0 0 0\n1 8\n70\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 24\n137524409\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 48\n221184\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 3\n1 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 3\n6 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n4398046511104 4398046511104\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 6\n5 6 36\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 6\n41\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 9\n747 81\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n20 2\n1099511627776 2199023255552 4398046511104 8796093022208 17592186044416 35184372088832 70368744177664 140737488355328 281474976710656 562949953421312 1125899906842624 1125899906842624 1125899906842624 1125899906842624 1125899906842624 1125899906842624 1125899906842624 1125899906842624 1125899906842624 1125899906842624\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 9\n83\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 6\n12\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 42\n622309758\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 7\n14\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n16\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n1125899906842624 1125899906842625\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n30 2\n16777216 33554432 67108864 134217728 268435456 536870912 1073741824 2147483648 4294967296 8589934592 17179869184 34359738368 68719476736 137438953472 274877906944 549755813888 1099511627776 2199023255552 4398046511104 8796093022208 17592186044416 35184372088832 70368744177664 140737488355328 281474976710656 562949953421312 1125899906842624 2251799813685248 4503599627370496 9007199254740992\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 9\n5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n1099511627776 1099511627775\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 5\n27\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n1 3\n6\n2 3\n3 6\n2 2\n7 25\n1 7\n55\n1 7\n9\n2 2\n129 7\n1 100\n1000000000000000\n",
"output": "NO\nNO\nNO\nNO\nNO\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 84\n16665\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 84\n10000000000000000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n2147483648 2147483648\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 16\n100\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 3\n2\n2 10\n5 20\n",
"output": "NO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 10\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 36\n536806176\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 3\n2 6 18 54\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n15\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4 3\n2 6 18 27\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 3\n9 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n9007199254740993 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 77\n1692004854\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n29\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n1000000000000000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n2 2\n1099511627776 1099511627775\n1 3\n6\n2 3\n3 6\n2 2\n7 25\n1 7\n55\n1 7\n9\n2 2\n129 7\n1 100\n1000000000000000\n",
"output": "YES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 3\n18 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 4\n72\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 12\n11\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n8 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n30 2\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 131072 262144 524288 1048576 2097152 4194304 8388608 16777216 33554432 67108864 134217728 268435456 536870912\n1 3\n6\n",
"output": "YES\nNO\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 56\n19 0 3\n4 87\n7570 0 0 87\n",
"output": "NO\nYES\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 9\n99\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n99\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 9\n324\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 2\n9007199254740992 9007199254740992\n2 2\n9007199254740992 9007199254740992\n",
"output": "NO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n90\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n1 3\n0\n1 3\n1\n1 3\n2\n1 3\n3\n1 3\n4\n1 3\n5\n1 3\n6\n1 3\n7\n",
"output": "YES\nYES\nNO\nYES\nYES\nNO\nNO\nNO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n1125899906842623 562949953421312\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 55\n83733937890626\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 100\n10000 10011\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n54\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 100\n1 10000000000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 41\n1280\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 100\n9999999999999999\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 79\n156525431694479 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 3\n14\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n4503599627370495 2251799813685248\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n4503599627370496 4503599627370496\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2 2\n10000000000000000 9007199254740992\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 2\n1 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3 2\n4503599627370495 2251799813685248 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 2\n9007199254740991\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 2\n4503599627370495 2251799813685248 0\n4 2\n4503599627370495 2251799813685248 0 0\n2 3\n114514 1919810\n",
"output": "NO\nNO\nNO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1312/C"
} | vfc_10118 |
apps | verifiable_code | 92 | Solve the following coding problem using the programming language python:
Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum:
$\sum_{i = 1}^{a} \sum_{j = 1}^{b} \sum_{k = 1}^{c} d(i \cdot j \cdot k)$
Find the sum modulo 1073741824 (2^30).
-----Input-----
The first line contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 100).
-----Output-----
Print a single integer — the required sum modulo 1073741824 (2^30).
-----Examples-----
Input
2 2 2
Output
20
Input
5 6 7
Output
1520
-----Note-----
For the first example.
d(1·1·1) = d(1) = 1; d(1·1·2) = d(2) = 2; d(1·2·1) = d(2) = 2; d(1·2·2) = d(4) = 3; d(2·1·1) = d(2) = 2; d(2·1·2) = d(4) = 3; d(2·2·1) = d(4) = 3; d(2·2·2) = d(8) = 4.
So the result is 1 + 2 + 2 + 3 + 2 + 3 + 3 + 4 = 20.
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 = map(int, input().split())
d = 1073741824
p = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
t = [{} for i in range(101)]
ans = {}
for i in p:
j = i
m = 1
while j < 101:
for k in range(j, 101, j):
t[k][i] = m
j = j * i
m += 1
s = 0
for i in range(1, a + 1):
for j in range(1, b + 1):
q = {}
for x in t[i].keys() | t[j].keys():
q[x] = t[i].get(x, 0) + t[j].get(x, 0)
ij = i * j
for k in range(1, c + 1):
ijk = ij * k
if ijk in ans: s += ans[ijk]
else:
y = 1
for x in q.keys() | t[k].keys():
y = y * (q.get(x, 0) + t[k].get(x, 0) + 1)
ans[ijk] = y
s += y
print(s)
``` | {
"language": "python",
"test_cases": [
{
"input": "2 2 2\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "5 6 7\n",
"output": "1520\n",
"type": "stdin_stdout"
},
{
"input": "91 42 25\n",
"output": "3076687\n",
"type": "stdin_stdout"
},
{
"input": "38 47 5\n",
"output": "160665\n",
"type": "stdin_stdout"
},
{
"input": "82 29 45\n",
"output": "3504808\n",
"type": "stdin_stdout"
},
{
"input": "40 15 33\n",
"output": "460153\n",
"type": "stdin_stdout"
},
{
"input": "35 5 21\n",
"output": "55282\n",
"type": "stdin_stdout"
},
{
"input": "71 2 1\n",
"output": "811\n",
"type": "stdin_stdout"
},
{
"input": "22 44 41\n",
"output": "1063829\n",
"type": "stdin_stdout"
},
{
"input": "73 19 29\n",
"output": "1047494\n",
"type": "stdin_stdout"
},
{
"input": "76 12 17\n",
"output": "330197\n",
"type": "stdin_stdout"
},
{
"input": "16 10 49\n",
"output": "146199\n",
"type": "stdin_stdout"
},
{
"input": "59 99 33\n",
"output": "7052988\n",
"type": "stdin_stdout"
},
{
"input": "17 34 25\n",
"output": "306673\n",
"type": "stdin_stdout"
},
{
"input": "21 16 9\n",
"output": "45449\n",
"type": "stdin_stdout"
},
{
"input": "31 51 29\n",
"output": "1255099\n",
"type": "stdin_stdout"
},
{
"input": "26 41 17\n",
"output": "402568\n",
"type": "stdin_stdout"
},
{
"input": "85 19 5\n",
"output": "139747\n",
"type": "stdin_stdout"
},
{
"input": "36 61 45\n",
"output": "3253358\n",
"type": "stdin_stdout"
},
{
"input": "76 58 25\n",
"output": "3635209\n",
"type": "stdin_stdout"
},
{
"input": "71 48 13\n",
"output": "1179722\n",
"type": "stdin_stdout"
},
{
"input": "29 34 53\n",
"output": "1461871\n",
"type": "stdin_stdout"
},
{
"input": "72 16 41\n",
"output": "1309118\n",
"type": "stdin_stdout"
},
{
"input": "8 21 21\n",
"output": "54740\n",
"type": "stdin_stdout"
},
{
"input": "11 51 5\n",
"output": "38092\n",
"type": "stdin_stdout"
},
{
"input": "70 38 49\n",
"output": "4467821\n",
"type": "stdin_stdout"
},
{
"input": "13 31 33\n",
"output": "274773\n",
"type": "stdin_stdout"
},
{
"input": "53 29 17\n",
"output": "621991\n",
"type": "stdin_stdout"
},
{
"input": "56 18 53\n",
"output": "1518698\n",
"type": "stdin_stdout"
},
{
"input": "55 45 45\n",
"output": "3751761\n",
"type": "stdin_stdout"
},
{
"input": "58 35 29\n",
"output": "1706344\n",
"type": "stdin_stdout"
},
{
"input": "67 2 24\n",
"output": "45108\n",
"type": "stdin_stdout"
},
{
"input": "62 96 8\n",
"output": "1257040\n",
"type": "stdin_stdout"
},
{
"input": "21 22 100\n",
"output": "1274891\n",
"type": "stdin_stdout"
},
{
"input": "64 12 36\n",
"output": "687986\n",
"type": "stdin_stdout"
},
{
"input": "4 9 20\n",
"output": "7302\n",
"type": "stdin_stdout"
},
{
"input": "7 99 4\n",
"output": "36791\n",
"type": "stdin_stdout"
},
{
"input": "58 25 96\n",
"output": "4812548\n",
"type": "stdin_stdout"
},
{
"input": "9 19 32\n",
"output": "91192\n",
"type": "stdin_stdout"
},
{
"input": "45 16 12\n",
"output": "167557\n",
"type": "stdin_stdout"
},
{
"input": "40 6 100\n",
"output": "558275\n",
"type": "stdin_stdout"
},
{
"input": "46 93 44\n",
"output": "6945002\n",
"type": "stdin_stdout"
},
{
"input": "49 31 28\n",
"output": "1158568\n",
"type": "stdin_stdout"
},
{
"input": "89 28 8\n",
"output": "441176\n",
"type": "stdin_stdout"
},
{
"input": "84 17 96\n",
"output": "4615400\n",
"type": "stdin_stdout"
},
{
"input": "91 96 36\n",
"output": "12931148\n",
"type": "stdin_stdout"
},
{
"input": "86 90 24\n",
"output": "6779764\n",
"type": "stdin_stdout"
},
{
"input": "4 21 45\n",
"output": "58045\n",
"type": "stdin_stdout"
},
{
"input": "100 7 28\n",
"output": "429933\n",
"type": "stdin_stdout"
},
{
"input": "58 41 21\n",
"output": "1405507\n",
"type": "stdin_stdout"
},
{
"input": "53 31 5\n",
"output": "144839\n",
"type": "stdin_stdout"
},
{
"input": "41 28 36\n",
"output": "1135934\n",
"type": "stdin_stdout"
},
{
"input": "44 18 24\n",
"output": "436880\n",
"type": "stdin_stdout"
},
{
"input": "3 96 16\n",
"output": "70613\n",
"type": "stdin_stdout"
},
{
"input": "98 34 100\n",
"output": "13589991\n",
"type": "stdin_stdout"
},
{
"input": "82 31 32\n",
"output": "2502213\n",
"type": "stdin_stdout"
},
{
"input": "85 25 20\n",
"output": "1142825\n",
"type": "stdin_stdout"
},
{
"input": "35 12 8\n",
"output": "50977\n",
"type": "stdin_stdout"
},
{
"input": "39 94 48\n",
"output": "6368273\n",
"type": "stdin_stdout"
},
{
"input": "27 99 28\n",
"output": "2276216\n",
"type": "stdin_stdout"
},
{
"input": "22 28 16\n",
"output": "198639\n",
"type": "stdin_stdout"
},
{
"input": "80 15 4\n",
"output": "76139\n",
"type": "stdin_stdout"
},
{
"input": "23 9 44\n",
"output": "170773\n",
"type": "stdin_stdout"
},
{
"input": "33 16 36\n",
"output": "441858\n",
"type": "stdin_stdout"
},
{
"input": "36 6 24\n",
"output": "88626\n",
"type": "stdin_stdout"
},
{
"input": "98 92 12\n",
"output": "3475151\n",
"type": "stdin_stdout"
},
{
"input": "90 82 100\n",
"output": "35482866\n",
"type": "stdin_stdout"
},
{
"input": "77 79 31\n",
"output": "6870344\n",
"type": "stdin_stdout"
},
{
"input": "81 21 19\n",
"output": "812886\n",
"type": "stdin_stdout"
},
{
"input": "31 96 7\n",
"output": "458123\n",
"type": "stdin_stdout"
},
{
"input": "34 89 95\n",
"output": "11308813\n",
"type": "stdin_stdout"
},
{
"input": "18 86 27\n",
"output": "1116623\n",
"type": "stdin_stdout"
},
{
"input": "13 76 11\n",
"output": "206844\n",
"type": "stdin_stdout"
},
{
"input": "76 3 3\n",
"output": "6118\n",
"type": "stdin_stdout"
},
{
"input": "15 93 87\n",
"output": "4007595\n",
"type": "stdin_stdout"
},
{
"input": "63 90 23\n",
"output": "4384553\n",
"type": "stdin_stdout"
},
{
"input": "58 83 7\n",
"output": "819473\n",
"type": "stdin_stdout"
},
{
"input": "16 18 99\n",
"output": "702678\n",
"type": "stdin_stdout"
},
{
"input": "60 8 35\n",
"output": "363723\n",
"type": "stdin_stdout"
},
{
"input": "22 87 4\n",
"output": "133986\n",
"type": "stdin_stdout"
},
{
"input": "73 25 44\n",
"output": "2478308\n",
"type": "stdin_stdout"
},
{
"input": "36 3 32\n",
"output": "50842\n",
"type": "stdin_stdout"
},
{
"input": "27 93 20\n",
"output": "1393947\n",
"type": "stdin_stdout"
},
{
"input": "67 90 100\n",
"output": "27880104\n",
"type": "stdin_stdout"
},
{
"input": "18 84 36\n",
"output": "1564297\n",
"type": "stdin_stdout"
},
{
"input": "68 14 28\n",
"output": "646819\n",
"type": "stdin_stdout"
},
{
"input": "71 8 12\n",
"output": "119311\n",
"type": "stdin_stdout"
},
{
"input": "7 5 96\n",
"output": "46328\n",
"type": "stdin_stdout"
},
{
"input": "50 95 32\n",
"output": "5324602\n",
"type": "stdin_stdout"
},
{
"input": "13 22 24\n",
"output": "124510\n",
"type": "stdin_stdout"
},
{
"input": "4 12 8\n",
"output": "3347\n",
"type": "stdin_stdout"
},
{
"input": "100 9 88\n",
"output": "2334910\n",
"type": "stdin_stdout"
},
{
"input": "95 2 28\n",
"output": "82723\n",
"type": "stdin_stdout"
},
{
"input": "54 77 20\n",
"output": "2573855\n",
"type": "stdin_stdout"
},
{
"input": "49 19 4\n",
"output": "55037\n",
"type": "stdin_stdout"
},
{
"input": "58 86 99\n",
"output": "21920084\n",
"type": "stdin_stdout"
},
{
"input": "9 76 83\n",
"output": "1554836\n",
"type": "stdin_stdout"
},
{
"input": "64 2 27\n",
"output": "49141\n",
"type": "stdin_stdout"
},
{
"input": "63 96 11\n",
"output": "1898531\n",
"type": "stdin_stdout"
},
{
"input": "3 93 91\n",
"output": "555583\n",
"type": "stdin_stdout"
},
{
"input": "100 100 100\n",
"output": "51103588\n",
"type": "stdin_stdout"
},
{
"input": "1 5 1\n",
"output": "10\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/236/B"
} | vfc_10122 |
apps | verifiable_code | 93 | Solve the following coding problem using the programming language python:
Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a move, Bessie or Elsie can slide a tile adjacent to the empty cell into the empty cell as shown below: $\rightarrow$
In order to determine if they are truly Best Friends For Life (BFFLs), Bessie and Elsie would like to know if there exists a sequence of moves that takes their puzzles to the same configuration (moves can be performed in both puzzles). Two puzzles are considered to be in the same configuration if each tile is on top of the same grid cell in both puzzles. Since the tiles are labeled with letters, rotations and reflections are not allowed.
-----Input-----
The first two lines of the input consist of a 2 × 2 grid describing the initial configuration of Bessie's puzzle. The next two lines contain a 2 × 2 grid describing the initial configuration of Elsie's puzzle. The positions of the tiles are labeled 'A', 'B', and 'C', while the empty cell is labeled 'X'. It's guaranteed that both puzzles contain exactly one tile with each letter and exactly one empty position.
-----Output-----
Output "YES"(without quotes) if the puzzles can reach the same configuration (and Bessie and Elsie are truly BFFLs). Otherwise, print "NO" (without quotes).
-----Examples-----
Input
AB
XC
XB
AC
Output
YES
Input
AB
XC
AC
BX
Output
NO
-----Note-----
The solution to the first sample is described by the image. All Bessie needs to do is slide her 'A' tile down.
In the second sample, the two puzzles can never be in the same configuration. Perhaps Bessie and Elsie are not meant to be friends after all...
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, d = input(), input(), input(), input()
a = a + b[::-1]
x = "X"
for i in range(4):
if a[i] == x:
a = a[:i] + a[i + 1:]
break
c = c + d[::-1]
for i in range(4):
if c[i] == x:
c = c[:i] + c[i + 1:]
break
flag = False
for i in range(4):
if a == c:
flag = True
c = c[1:] + c[0]
if flag:
print("YES")
else:
print("NO")
``` | {
"language": "python",
"test_cases": [
{
"input": "AB\nXC\nXB\nAC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "AB\nXC\nAC\nBX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XC\nBA\nCB\nAX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "AB\nXC\nAX\nCB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "CB\nAX\nXA\nBC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "BC\nXA\nBA\nXC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CA\nXB\nBA\nCX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CA\nXB\nAC\nBX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CB\nAX\nCX\nAB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "AX\nCB\nBC\nXA\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "CA\nXB\nBA\nXC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CX\nAB\nAX\nCB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "AB\nXC\nAB\nCX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XC\nBA\nXC\nAB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BA\nXC\nAC\nXB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "AX\nBC\nAC\nBX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XC\nBA\nCB\nXA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CB\nAX\nXC\nBA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "AX\nCB\nBC\nAX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "AB\nXC\nBX\nAC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XA\nCB\nBA\nCX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CX\nBA\nBX\nAC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "AB\nXC\nXC\nAB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BA\nCX\nAC\nBX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XA\nCB\nAB\nXC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XC\nBA\nAC\nBX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CA\nBX\nBA\nXC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "AX\nBC\nCA\nXB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BC\nAX\nXC\nBA\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XB\nAC\nBX\nAC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "CX\nBA\nAX\nBC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XB\nCA\nXC\nBA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BX\nCA\nXB\nCA\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XB\nAC\nXC\nAB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CX\nBA\nCX\nBA\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XB\nAC\nCA\nBX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "BA\nXC\nBC\nAX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "AC\nXB\nCX\nBA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XB\nCA\nCX\nBA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "AB\nCX\nXA\nBC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CX\nAB\nXB\nAC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BC\nAX\nAC\nBX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XA\nBC\nCB\nAX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XC\nAB\nCB\nAX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "CX\nBA\nCX\nAB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CA\nBX\nXC\nBA\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "CX\nBA\nBA\nXC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CA\nBX\nCB\nXA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CB\nAX\nBC\nAX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CB\nAX\nBC\nXA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "AC\nXB\nCB\nXA\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "AB\nCX\nXB\nAC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "CX\nBA\nXB\nAC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "BX\nAC\nAB\nXC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "CX\nAB\nXC\nBA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XB\nAC\nCX\nAB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CB\nAX\nXB\nAC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CB\nAX\nCA\nXB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XC\nBA\nBA\nXC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "AC\nBX\nCB\nAX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "CA\nBX\nAC\nXB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BX\nAC\nCX\nBA\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XB\nCA\nAX\nCB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CB\nXA\nBC\nXA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "AX\nCB\nCX\nAB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BC\nAX\nXC\nAB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XB\nCA\nBC\nXA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XB\nAC\nCX\nBA\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "BC\nXA\nCB\nXA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "AX\nCB\nAX\nBC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CA\nBX\nBX\nCA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BA\nXC\nXB\nAC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XA\nBC\nBX\nAC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BX\nCA\nAC\nBX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XB\nAC\nXC\nBA\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XB\nAC\nAB\nXC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "BA\nCX\nCX\nBA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CA\nXB\nXB\nCA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BA\nCX\nBA\nXC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "BA\nCX\nAB\nCX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BX\nCA\nXA\nBC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XC\nBA\nBX\nCA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XC\nAB\nBC\nXA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BC\nXA\nXC\nAB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BX\nCA\nXB\nAC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BA\nXC\nCA\nXB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CX\nBA\nAC\nXB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "AB\nCX\nAC\nBX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "BC\nXA\nBX\nCA\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XA\nBC\nCX\nAB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "AX\nBC\nAX\nCB\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CB\nAX\nCA\nBX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CB\nAX\nBA\nXC\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "AB\nCX\nXC\nBA\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "AC\nXB\nBA\nCX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "AX\nCB\nCB\nAX\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "CX\nBA\nCA\nXB\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "AC\nBX\nAB\nXC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XA\nCB\nXA\nBC\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "XC\nBA\nCA\nBX\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "XA\nBC\nXB\nCA\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "CA\nBX\nCB\nAX\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/645/A"
} | vfc_10126 |
apps | verifiable_code | 94 | Solve the following coding problem using the programming language python:
Alexander is learning how to convert numbers from the decimal system to any other, however, he doesn't know English letters, so he writes any number only as a decimal number, it means that instead of the letter A he will write the number 10. Thus, by converting the number 475 from decimal to hexadecimal system, he gets 11311 (475 = 1·16^2 + 13·16^1 + 11·16^0). Alexander lived calmly until he tried to convert the number back to the decimal number system.
Alexander remembers that he worked with little numbers so he asks to find the minimum decimal number so that by converting it to the system with the base n he will get the number k.
-----Input-----
The first line contains the integer n (2 ≤ n ≤ 10^9). The second line contains the integer k (0 ≤ k < 10^60), it is guaranteed that the number k contains no more than 60 symbols. All digits in the second line are strictly less than n.
Alexander guarantees that the answer exists and does not exceed 10^18.
The number k doesn't contain leading zeros.
-----Output-----
Print the number x (0 ≤ x ≤ 10^18) — the answer to the problem.
-----Examples-----
Input
13
12
Output
12
Input
16
11311
Output
475
Input
20
999
Output
3789
Input
17
2016
Output
594
-----Note-----
In the first example 12 could be obtained by converting two numbers to the system with base 13: 12 = 12·13^0 or 15 = 1·13^1 + 2·13^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())
s=input()
pw=[1]
last=1
for i in range(70):
if (last>1e19):
break
pw.append(last*n)
last=last*n
dp=[1e19]*100
for i in range(100):
dp[i]=[1e19]*100
dp[len(s)][0]=0
for i in range(len(s),-1,-1):
for power in range(0,len(pw)):
cur=''
for j in range(i-1,-1,-1):
cur=s[j]+cur
if (int(cur)>n or int(cur)*pw[power]>1e19):
break;
if ((cur[0]!='0' or len(cur)==1) and int(cur)<n):
dp[j][power+1]=min(dp[j][power+1],dp[i][power]+int(cur)*pw[power])
print(min(dp[0]))
``` | {
"language": "python",
"test_cases": [
{
"input": "13\n12\n",
"output": "12",
"type": "stdin_stdout"
},
{
"input": "16\n11311\n",
"output": "475",
"type": "stdin_stdout"
},
{
"input": "20\n999\n",
"output": "3789",
"type": "stdin_stdout"
},
{
"input": "17\n2016\n",
"output": "594",
"type": "stdin_stdout"
},
{
"input": "1000\n1001\n",
"output": "100001",
"type": "stdin_stdout"
},
{
"input": "1000\n1000\n",
"output": "100000",
"type": "stdin_stdout"
},
{
"input": "2\n110111100000101101101011001110100111011001000000000000000000\n",
"output": "1000000000000000000",
"type": "stdin_stdout"
},
{
"input": "500\n29460456244280453288\n",
"output": "467528530570226788",
"type": "stdin_stdout"
},
{
"input": "1000000000\n17289468142098080\n",
"output": "17289468142098080",
"type": "stdin_stdout"
},
{
"input": "123\n7719\n",
"output": "9490",
"type": "stdin_stdout"
},
{
"input": "25\n2172214240\n",
"output": "26524975",
"type": "stdin_stdout"
},
{
"input": "2\n1110110101111000010001011110101001011001110000000010111010\n",
"output": "267367244641009850",
"type": "stdin_stdout"
},
{
"input": "3\n1210020121011022121222022012121212020\n",
"output": "268193483524125978",
"type": "stdin_stdout"
},
{
"input": "4\n32323300000100133222012211322\n",
"output": "269019726702209402",
"type": "stdin_stdout"
},
{
"input": "5\n4230423222300004320404110\n",
"output": "269845965585325530",
"type": "stdin_stdout"
},
{
"input": "6\n20201051430024130310350\n",
"output": "270672213058376250",
"type": "stdin_stdout"
},
{
"input": "7\n325503632564034033331\n",
"output": "271498451941492378",
"type": "stdin_stdout"
},
{
"input": "8\n17073735641412635372\n",
"output": "272324690824608506",
"type": "stdin_stdout"
},
{
"input": "9\n1733607167155630041\n",
"output": "273150934002691930",
"type": "stdin_stdout"
},
{
"input": "10\n996517375802030516\n",
"output": "996517375802030516",
"type": "stdin_stdout"
},
{
"input": "11\n1107835458761401923\n",
"output": "997343614685146644",
"type": "stdin_stdout"
},
{
"input": "20\n905191218118181710131111\n",
"output": "738505167292405431",
"type": "stdin_stdout"
},
{
"input": "50\n303521849112318129\n",
"output": "59962796634170079",
"type": "stdin_stdout"
},
{
"input": "100\n7226127039816418\n",
"output": "7226127039816418",
"type": "stdin_stdout"
},
{
"input": "1000\n839105509657869885\n",
"output": "839105509657869885",
"type": "stdin_stdout"
},
{
"input": "7501\n2542549323761022905\n",
"output": "805176557484307547",
"type": "stdin_stdout"
},
{
"input": "10981\n5149151039259677113\n",
"output": "748054672922159638",
"type": "stdin_stdout"
},
{
"input": "123358\n458270676485260235\n",
"output": "860152492903254335",
"type": "stdin_stdout"
},
{
"input": "2567853\n5247911636981396703\n",
"output": "346042641011647808",
"type": "stdin_stdout"
},
{
"input": "56132425\n3102369282985322\n",
"output": "10027171005317597",
"type": "stdin_stdout"
},
{
"input": "378135456\n42831383491941211\n",
"output": "582652156959951259",
"type": "stdin_stdout"
},
{
"input": "3\n110021012201002100122001102110010002\n",
"output": "68193483524125904",
"type": "stdin_stdout"
},
{
"input": "23\n12007622911918220\n",
"output": "1781911903273803",
"type": "stdin_stdout"
},
{
"input": "456\n82103391245145170\n",
"output": "1621222691867186",
"type": "stdin_stdout"
},
{
"input": "7897\n14412516641926184\n",
"output": "6062228032315859",
"type": "stdin_stdout"
},
{
"input": "23156\n27612518525717145\n",
"output": "3433598652149101",
"type": "stdin_stdout"
},
{
"input": "467879\n333380108424158040\n",
"output": "72980519445207316",
"type": "stdin_stdout"
},
{
"input": "7982154\n129530518193255487\n",
"output": "82535003403725833",
"type": "stdin_stdout"
},
{
"input": "21354646\n47160699363858581\n",
"output": "21776150370291089",
"type": "stdin_stdout"
},
{
"input": "315464878\n113635473256292967\n",
"output": "35848000882710261",
"type": "stdin_stdout"
},
{
"input": "1000000000\n17289468142098026\n",
"output": "17289468142098026",
"type": "stdin_stdout"
},
{
"input": "4\n200002312103012003212121020\n",
"output": "9019726702208584",
"type": "stdin_stdout"
},
{
"input": "46\n342836241940392925\n",
"output": "694167817136539",
"type": "stdin_stdout"
},
{
"input": "145\n357987665524124\n",
"output": "330396354354854",
"type": "stdin_stdout"
},
{
"input": "1344\n2498394521019605\n",
"output": "814487257688093",
"type": "stdin_stdout"
},
{
"input": "57974\n3619236326439503\n",
"output": "7079242212325439",
"type": "stdin_stdout"
},
{
"input": "215467\n2082791630100848\n",
"output": "966934630351661",
"type": "stdin_stdout"
},
{
"input": "7956123\n6718643712272358\n",
"output": "4255926011071634",
"type": "stdin_stdout"
},
{
"input": "13568864\n2513398972677784\n",
"output": "4621032639107192",
"type": "stdin_stdout"
},
{
"input": "789765212\n1039927282755769\n",
"output": "821298450375293",
"type": "stdin_stdout"
},
{
"input": "1000000000\n7289468142097485\n",
"output": "7289468142097485",
"type": "stdin_stdout"
},
{
"input": "5\n22011100004310232330\n",
"output": "45965585242840",
"type": "stdin_stdout"
},
{
"input": "98\n11291073236468\n",
"output": "10007394522984",
"type": "stdin_stdout"
},
{
"input": "364\n284155255182196\n",
"output": "4993183241788",
"type": "stdin_stdout"
},
{
"input": "8742\n111445644633405\n",
"output": "74498130012303",
"type": "stdin_stdout"
},
{
"input": "11346\n573275516211238\n",
"output": "83675287784142",
"type": "stdin_stdout"
},
{
"input": "442020\n13825031303078\n",
"output": "26973736400898",
"type": "stdin_stdout"
},
{
"input": "1740798\n321470190942028\n",
"output": "99531390411376",
"type": "stdin_stdout"
},
{
"input": "25623752\n25636131538378\n",
"output": "65689385274354",
"type": "stdin_stdout"
},
{
"input": "814730652\n56899767577002\n",
"output": "46358126945150",
"type": "stdin_stdout"
},
{
"input": "6\n5543321344052\n",
"output": "12975669536",
"type": "stdin_stdout"
},
{
"input": "79\n9653454753\n",
"output": "27953623755",
"type": "stdin_stdout"
},
{
"input": "158\n25832612364\n",
"output": "15908078858",
"type": "stdin_stdout"
},
{
"input": "1675\n11480678916\n",
"output": "8852883441",
"type": "stdin_stdout"
},
{
"input": "12650\n25380755475\n",
"output": "40587846725",
"type": "stdin_stdout"
},
{
"input": "165726\n465015206\n",
"output": "770641106",
"type": "stdin_stdout"
},
{
"input": "2015054\n30501583737\n",
"output": "6147498437",
"type": "stdin_stdout"
},
{
"input": "98000000\n19440834812\n",
"output": "19052834812",
"type": "stdin_stdout"
},
{
"input": "157137373\n525141766938\n",
"output": "82638887763",
"type": "stdin_stdout"
},
{
"input": "7\n441214552\n",
"output": "26508694",
"type": "stdin_stdout"
},
{
"input": "294\n2251151163\n",
"output": "72564361",
"type": "stdin_stdout"
},
{
"input": "2707\n11341512\n",
"output": "3071250",
"type": "stdin_stdout"
},
{
"input": "76559\n100147383\n",
"output": "76682942",
"type": "stdin_stdout"
},
{
"input": "124849\n6172319\n",
"output": "7688108",
"type": "stdin_stdout"
},
{
"input": "7014809\n73084644\n",
"output": "52188307",
"type": "stdin_stdout"
},
{
"input": "10849219\n65200749\n",
"output": "70296063",
"type": "stdin_stdout"
},
{
"input": "905835986\n371320\n",
"output": "371320",
"type": "stdin_stdout"
},
{
"input": "1000000000\n69204007\n",
"output": "69204007",
"type": "stdin_stdout"
},
{
"input": "8\n2670\n",
"output": "1464",
"type": "stdin_stdout"
},
{
"input": "25\n71610\n",
"output": "4785",
"type": "stdin_stdout"
},
{
"input": "1468\n21107\n",
"output": "4043",
"type": "stdin_stdout"
},
{
"input": "5723\n4907\n",
"output": "4907",
"type": "stdin_stdout"
},
{
"input": "251546\n7278\n",
"output": "7278",
"type": "stdin_stdout"
},
{
"input": "9\n78\n",
"output": "71",
"type": "stdin_stdout"
},
{
"input": "13\n41\n",
"output": "53",
"type": "stdin_stdout"
},
{
"input": "34\n13\n",
"output": "13",
"type": "stdin_stdout"
},
{
"input": "45\n22\n",
"output": "22",
"type": "stdin_stdout"
},
{
"input": "67\n29\n",
"output": "29",
"type": "stdin_stdout"
},
{
"input": "130\n100\n",
"output": "100",
"type": "stdin_stdout"
},
{
"input": "2\n1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "4\n1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "9\n3\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "13\n9\n",
"output": "9",
"type": "stdin_stdout"
},
{
"input": "3215\n3\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "1000000000\n6\n",
"output": "6",
"type": "stdin_stdout"
},
{
"input": "2\n0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1000000000\n0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "378\n1378\n",
"output": "4992",
"type": "stdin_stdout"
},
{
"input": "378\n380378377\n",
"output": "65568783041",
"type": "stdin_stdout"
},
{
"input": "2\n10000000000000000000000000\n",
"output": "33554432",
"type": "stdin_stdout"
},
{
"input": "2\n10000000000000000000000000000\n",
"output": "268435456",
"type": "stdin_stdout"
},
{
"input": "2\n100000000000000000000000\n",
"output": "8388608",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/758/D"
} | vfc_10130 |
apps | verifiable_code | 95 | Solve the following coding problem using the programming language python:
Array of integers is unimodal, if:
it is strictly increasing in the beginning; after that it is constant; after that it is strictly decreasing.
The first block (increasing) and the last block (decreasing) may be absent. It is allowed that both of this blocks are absent.
For example, the following three arrays are unimodal: [5, 7, 11, 11, 2, 1], [4, 4, 2], [7], but the following three are not unimodal: [5, 5, 6, 6, 1], [1, 2, 1, 2], [4, 5, 5, 6].
Write a program that checks if an array is unimodal.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 100) — the number of elements in the array.
The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 1 000) — the elements of the array.
-----Output-----
Print "YES" if the given array is unimodal. Otherwise, print "NO".
You can output each letter in any case (upper or lower).
-----Examples-----
Input
6
1 5 5 5 4 2
Output
YES
Input
5
10 20 30 20 10
Output
YES
Input
4
1 2 1 2
Output
NO
Input
7
3 3 3 3 3 3 3
Output
YES
-----Note-----
In the first example the array is unimodal, because it is strictly increasing in the beginning (from position 1 to position 2, inclusively), that it is constant (from position 2 to position 4, inclusively) and then it is strictly decreasing (from position 4 to position 6, inclusively).
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())
L = list(map(int, input().split()))
i = 0
a = 0
while i < n and L[i] > a:
a = L[i]
i += 1
while i < n and L[i] == a:
i += 1
while i < n and L[i] < a:
a = L[i]
i += 1
if i == n:
print("YES")
else:
print("NO")
``` | {
"language": "python",
"test_cases": [
{
"input": "6\n1 5 5 5 4 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n10 20 30 20 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n3 3 3 3 3 3 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n5 7 11 11 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n7\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 5 6 6 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 4 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 5 5 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n516 516 515\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n502 503 508 508 507\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10\n538 538 538 538 538 538 538 538 538 538\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "15\n452 454 455 455 450 448 443 442 439 436 433 432 431 428 426\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "20\n497 501 504 505 509 513 513 513 513 513 513 513 513 513 513 513 513 513 513 513\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "50\n462 465 465 465 463 459 454 449 444 441 436 435 430 429 426 422 421 418 417 412 408 407 406 403 402 399 395 392 387 386 382 380 379 376 374 371 370 365 363 359 358 354 350 349 348 345 342 341 338 337\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "70\n290 292 294 297 299 300 303 305 310 312 313 315 319 320 325 327 328 333 337 339 340 341 345 350 351 354 359 364 367 372 374 379 381 382 383 384 389 393 395 397 398 400 402 405 409 411 416 417 422 424 429 430 434 435 440 442 445 449 451 453 458 460 465 470 474 477 482 482 482 479\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "99\n433 435 439 444 448 452 457 459 460 464 469 470 471 476 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 480 479 478 477 476 474 469 468 465 460 457 453 452 450 445 443 440 438 433 432 431 430 428 425 421 418 414 411 406 402 397 396 393\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 346 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 363 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 351 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 431 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n1000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\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": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n1 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n998 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 999\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n537 538 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 691 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543 543\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n527 527 527 527 527 527 527 527 872 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527 527\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 208 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 524 521\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n235 239 243 245 246 251 254 259 260 261 264 269 272 275 277 281 282 285 289 291 292 293 298 301 302 303 305 307 308 310 315 317 320 324 327 330 334 337 342 921 347 348 353 357 361 366 370 373 376 378 379 384 386 388 390 395 398 400 405 408 413 417 420 422 424 429 434 435 438 441 443 444 445 450 455 457 459 463 465 468 471 473 475 477 481 486 491 494 499 504 504 504 504 504 504 504 504 504 504 504\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n191 196 201 202 207 212 216 219 220 222 224 227 230 231 234 235 238 242 246 250 253 254 259 260 263 267 269 272 277 280 284 287 288 290 295 297 300 305 307 312 316 320 324 326 327 332 333 334 338 343 347 351 356 358 119 368 370 374 375 380 381 386 390 391 394 396 397 399 402 403 405 410 414 419 422 427 429 433 437 442 443 447 448 451 455 459 461 462 464 468 473 478 481 484 485 488 492 494 496 496\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n466 466 466 466 466 464 459 455 452 449 446 443 439 436 435 433 430 428 425 424 420 419 414 412 407 404 401 396 394 391 386 382 379 375 374 369 364 362 360 359 356 335 350 347 342 340 338 337 333 330 329 326 321 320 319 316 311 306 301 297 292 287 286 281 278 273 269 266 261 257 256 255 253 252 250 245 244 242 240 238 235 230 225 220 216 214 211 209 208 206 203 198 196 194 192 190 185 182 177 173\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n360 362 367 369 374 377 382 386 389 391 396 398 399 400 405 410 413 416 419 420 423 428 525 436 441 444 445 447 451 453 457 459 463 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 468 465 460 455 453 448 446 443 440 436 435 430 425 420 415 410 405 404 403 402 399 394 390 387 384 382 379 378 373 372 370 369 366 361 360 355 353 349 345 344 342 339 338 335 333\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 497 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 333 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 498 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n395 399 402 403 405 408 413 415 419 424 426 431 434 436 439 444 447 448 449 454 457 459 461 462 463 464 465 469 470 473 477 480 482 484 485 487 492 494 496 32 501 504 505 508 511 506 505 503 500 499 494 490 488 486 484 481 479 474 472 471 470 465 462 458 453 452 448 445 440 436 433 430 428 426 424 421 419 414 413 408 404 403 399 395 393 388 384 379 377 375 374 372 367 363 360 356 353 351 350 346\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n263 268 273 274 276 281 282 287 288 292 294 295 296 300 304 306 308 310 311 315 319 322 326 330 247 336 339 341 342 347 351 353 356 358 363 365 369 372 374 379 383 387 389 391 392 395 396 398 403 404 407 411 412 416 419 421 424 428 429 430 434 436 440 443 444 448 453 455 458 462 463 464 469 473 477 481 486 489 492 494 499 503 506 509 510 512 514 515 511 510 507 502 499 498 494 491 486 482 477 475\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n482 484 485 489 492 496 499 501 505 509 512 517 520 517 515 513 509 508 504 503 497 496 493 488 486 481 478 476 474 470 468 466 463 459 456 453 452 449 445 444 439 438 435 432 428 427 424 423 421 419 417 413 408 405 402 399 397 393 388 385 380 375 370 366 363 361 360 355 354 352 349 345 340 336 335 331 329 327 324 319 318 317 315 314 310 309 307 304 303 300 299 295 291 287 285 282 280 278 273 271\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 2 1 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 3 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 2 1 2 2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n1 2 2 3 3 4 3 2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n5 5 4 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 4 3 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7\n4 3 3 3 3 3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 3 4 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n1 5 5 4 3 3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n3 3 1 2 2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 1 2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9\n1 2 3 4 4 3 2 2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 2 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 3 3 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 99\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 3 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 5 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 4 2 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 2 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 3 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 3 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 6 6 5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 4 3 3 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n1 3 3 3 2 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n5 6 6 5 5 4 4 3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 5 5 3 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 1 3 3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 2 2 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n5 4 3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 4 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 3 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 4 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n4 4 3 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n4 4 4 4 5 6 7 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 5 4 4 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 5 3 3 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n5 5 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 2 3 5\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/831/A"
} | vfc_10134 |
apps | verifiable_code | 96 | Solve the following coding problem using the programming language python:
At first, let's define function $f(x)$ as follows: $$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} \frac{x}{2} & \mbox{if } x \text{ is even} \\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$
We can see that if we choose some value $v$ and will apply function $f$ to it, then apply $f$ to $f(v)$, and so on, we'll eventually get $1$. Let's write down all values we get in this process in a list and denote this list as $path(v)$. For example, $path(1) = [1]$, $path(15) = [15, 14, 7, 6, 3, 2, 1]$, $path(32) = [32, 16, 8, 4, 2, 1]$.
Let's write all lists $path(x)$ for every $x$ from $1$ to $n$. The question is next: what is the maximum value $y$ such that $y$ is contained in at least $k$ different lists $path(x)$?
Formally speaking, you need to find maximum $y$ such that $\left| \{ x ~|~ 1 \le x \le n, y \in path(x) \} \right| \ge k$.
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 10^{18}$).
-----Output-----
Print the only integer — the maximum value that is contained in at least $k$ paths.
-----Examples-----
Input
11 3
Output
5
Input
11 6
Output
4
Input
20 20
Output
1
Input
14 5
Output
6
Input
1000000 100
Output
31248
-----Note-----
In the first example, the answer is $5$, since $5$ occurs in $path(5)$, $path(10)$ and $path(11)$.
In the second example, the answer is $4$, since $4$ occurs in $path(4)$, $path(5)$, $path(8)$, $path(9)$, $path(10)$ and $path(11)$.
In the third example $n = k$, so the answer is $1$, since $1$ is the only number occuring in all paths for integers from $1$ to $20$.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def gg(n,lol):
ans = 0
cur = 1
lol2 = lol
while(2*lol+1<=n):
cur *= 2
ans += cur
lol = 2*lol+1
lol2 *= 2
if lol2*2 <= n:
ans += n-lol2*2+1
return ans
n,k = list(map(int,input().split()))
low = 1
high = n//2
res = 1
while low <= high:
mid = (low+high)//2
if gg(n,mid) >= k:
res = mid
low = mid+1
else:
high = mid-1
if n == k:
print(1)
elif(gg(n,res)-1-gg(n,res*2) >= k):
print(res*2+1)
else:
print(res*2)
``` | {
"language": "python",
"test_cases": [
{
"input": "11 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11 6\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "20 20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "14 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1000000 100\n",
"output": "31248\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100 4\n",
"output": "48\n",
"type": "stdin_stdout"
},
{
"input": "502333439 2047\n",
"output": "490559\n",
"type": "stdin_stdout"
},
{
"input": "773014587697599 31\n",
"output": "48313411731099\n",
"type": "stdin_stdout"
},
{
"input": "946338791423 262143\n",
"output": "7219991\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 4\n",
"output": "499999998\n",
"type": "stdin_stdout"
},
{
"input": "13 2\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "1073741821 2\n",
"output": "1073741820\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 100\n",
"output": "31249998\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "766540997167959122 63301807306884502\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "767367244641009842 196001098285659518\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "768193483524125970 149607803130614508\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "766540997167959122 81305011918141103\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "767367244641009842 63001562824270\n",
"output": "43618\n",
"type": "stdin_stdout"
},
{
"input": "768193483524125970 8159388687\n",
"output": "357717964\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999999\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 5\n",
"output": "499999999999999998\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 100\n",
"output": "31249999999999998\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 10000\n",
"output": "244140624999998\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 100000000\n",
"output": "29802322386\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000\n",
"output": "3725290296\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 10000000000\n",
"output": "232830642\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 100000000000\n",
"output": "29103828\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000000\n",
"output": "3637976\n",
"type": "stdin_stdout"
},
{
"input": "769019726702209394 20139642645754149\n",
"output": "84\n",
"type": "stdin_stdout"
},
{
"input": "769845965585325522 101455278609352655\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "770672213058376242 76549913585534528\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "771498451941492370 9554452753411241\n",
"output": "170\n",
"type": "stdin_stdout"
},
{
"input": "772324690824608498 350731058390952223\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "773150934002691922 35259246518088815\n",
"output": "82\n",
"type": "stdin_stdout"
},
{
"input": "996517375802030514 562680741796166004\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "997343614685146642 371441227995459449\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "998169857863230066 216532832678151994\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "998996101041313490 69229635334469840\n",
"output": "52\n",
"type": "stdin_stdout"
},
{
"input": "999822344219396914 31594516399528593\n",
"output": "108\n",
"type": "stdin_stdout"
},
{
"input": "500648583102513041 27328990834120804\n",
"output": "54\n",
"type": "stdin_stdout"
},
{
"input": "501474821985629169 20453276907988902\n",
"output": "54\n",
"type": "stdin_stdout"
},
{
"input": "502301069458679889 157958605549950521\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "503127308341796017 87673697275461928\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "503953551519879441 107364070317088317\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "738505179452405422 45979222492061590\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "739331418335521551 128388023680008325\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "740157665808572271 34928303706093932\n",
"output": "80\n",
"type": "stdin_stdout"
},
{
"input": "740983904691688399 137594355695562348\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "741810147869771823 28801222604168636\n",
"output": "80\n",
"type": "stdin_stdout"
},
{
"input": "742636386752887951 316193697166926237\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "743462629930971375 185994815084963322\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "744288873109054799 87172378778063481\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "745115111992170927 106980481324722563\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "745941355170254351 284128592904320663\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "757120946248004542 159477335321753086\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "769019726702209394 53103\n",
"output": "46937239178600\n",
"type": "stdin_stdout"
},
{
"input": "769845965585325522 1\n",
"output": "769845965585325522\n",
"type": "stdin_stdout"
},
{
"input": "770672213058376242 1\n",
"output": "770672213058376242\n",
"type": "stdin_stdout"
},
{
"input": "771498451941492370 41969263080453422\n",
"output": "42\n",
"type": "stdin_stdout"
},
{
"input": "772324690824608498 28027536140678\n",
"output": "87800\n",
"type": "stdin_stdout"
},
{
"input": "773150934002691922 2872807266\n",
"output": "720052916\n",
"type": "stdin_stdout"
},
{
"input": "996517375802030514 1\n",
"output": "996517375802030514\n",
"type": "stdin_stdout"
},
{
"input": "997343614685146642 979695858355714436\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "998169857863230066 1216910439614592\n",
"output": "1772\n",
"type": "stdin_stdout"
},
{
"input": "998996101041313490 325823891227\n",
"output": "7268652\n",
"type": "stdin_stdout"
},
{
"input": "999822344219396914 7494606\n",
"output": "476752445322\n",
"type": "stdin_stdout"
},
{
"input": "500648583102513041 1\n",
"output": "500648583102513041\n",
"type": "stdin_stdout"
},
{
"input": "501474821985629169 1\n",
"output": "501474821985629169\n",
"type": "stdin_stdout"
},
{
"input": "502301069458679889 263489722252521919\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "503127308341796017 287766911826129\n",
"output": "3574\n",
"type": "stdin_stdout"
},
{
"input": "503953551519879441 63329862130\n",
"output": "29333954\n",
"type": "stdin_stdout"
},
{
"input": "738505179452405422 173\n",
"output": "11539143428943834\n",
"type": "stdin_stdout"
},
{
"input": "739331418335521551 1\n",
"output": "739331418335521551\n",
"type": "stdin_stdout"
},
{
"input": "740157665808572271 1\n",
"output": "740157665808572271\n",
"type": "stdin_stdout"
},
{
"input": "740983904691688399 3157918256124620\n",
"output": "656\n",
"type": "stdin_stdout"
},
{
"input": "741810147869771823 1158226091274\n",
"output": "1349344\n",
"type": "stdin_stdout"
},
{
"input": "742636386752887951 45068330\n",
"output": "44264578028\n",
"type": "stdin_stdout"
},
{
"input": "743462629930971375 31\n",
"output": "46466414370685710\n",
"type": "stdin_stdout"
},
{
"input": "744288873109054799 1\n",
"output": "744288873109054799\n",
"type": "stdin_stdout"
},
{
"input": "745115111992170927 1\n",
"output": "745115111992170927\n",
"type": "stdin_stdout"
},
{
"input": "745941355170254351 1530914670906842\n",
"output": "1324\n",
"type": "stdin_stdout"
},
{
"input": "757120946248004542 1009900747\n",
"output": "2820495314\n",
"type": "stdin_stdout"
},
{
"input": "14465449852927 34359738367\n",
"output": "841\n",
"type": "stdin_stdout"
},
{
"input": "1825593951 31\n",
"output": "114099621\n",
"type": "stdin_stdout"
},
{
"input": "2147483647 2147483647\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "27386360746737663 274877906943\n",
"output": "199261\n",
"type": "stdin_stdout"
},
{
"input": "21968524033392639 4194303\n",
"output": "10475408569\n",
"type": "stdin_stdout"
},
{
"input": "4244114883215359 2199023255551\n",
"output": "3859\n",
"type": "stdin_stdout"
},
{
"input": "1962727058112511 8191\n",
"output": "479181410671\n",
"type": "stdin_stdout"
},
{
"input": "4294967295 2147483647\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "11225337262243839 536870911\n",
"output": "41817639\n",
"type": "stdin_stdout"
},
{
"input": "429496729599 8589934591\n",
"output": "99\n",
"type": "stdin_stdout"
},
{
"input": "6597069766655 68719476735\n",
"output": "191\n",
"type": "stdin_stdout"
},
{
"input": "81067507711 536870911\n",
"output": "301\n",
"type": "stdin_stdout"
},
{
"input": "356198383615 262143\n",
"output": "2717577\n",
"type": "stdin_stdout"
},
{
"input": "17276479 31\n",
"output": "1079779\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1271/E"
} | vfc_10138 |
apps | verifiable_code | 97 | Solve the following coding problem using the programming language python:
Consider a billiard table of rectangular size $n \times m$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture). [Image]
There is one ball at the point $(x, y)$ currently. Max comes to the table and strikes the ball. The ball starts moving along a line that is parallel to one of the axes or that makes a $45^{\circ}$ angle with them. We will assume that: the angles between the directions of the ball before and after a collision with a side are equal, the ball moves indefinitely long, it only stops when it falls into a pocket, the ball can be considered as a point, it falls into a pocket if and only if its coordinates coincide with one of the pockets, initially the ball is not in a pocket.
Note that the ball can move along some side, in this case the ball will just fall into the pocket at the end of the side.
Your task is to determine whether the ball will fall into a pocket eventually, and if yes, which of the four pockets it will be.
-----Input-----
The only line contains $6$ integers $n$, $m$, $x$, $y$, $v_x$, $v_y$ ($1 \leq n, m \leq 10^9$, $0 \leq x \leq n$; $0 \leq y \leq m$; $-1 \leq v_x, v_y \leq 1$; $(v_x, v_y) \neq (0, 0)$) — the width of the table, the length of the table, the $x$-coordinate of the initial position of the ball, the $y$-coordinate of the initial position of the ball, the $x$-component of its initial speed and the $y$-component of its initial speed, respectively. It is guaranteed that the ball is not initially in a pocket.
-----Output-----
Print the coordinates of the pocket the ball will fall into, or $-1$ if the ball will move indefinitely.
-----Examples-----
Input
4 3 2 2 -1 1
Output
0 0
Input
4 4 2 0 1 1
Output
-1
Input
10 10 10 1 -1 0
Output
-1
-----Note-----
The first sample: [Image]
The second sample: [Image]
In the third sample the ball will never change its $y$ coordinate, so the ball will never fall into a pocket.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def INV(a, m) :
m0 = m
y = 0
x = 1
if (m == 1) :
return 0
while (a > 1) :
q = a // m
t = m
m = a % m
a = t
t = y
y = x - q * y
x = t
if (x < 0) :
x = x + m0
return x
def GCD(a, b):
if a == 0: return b
return GCD(b%a,a)
def solve():
n, m, x, y, vx, vy = list(map(int, input().split()))
if vx == 0:
if x != 0 and x != n:
print("-1")
return 0
ans = [0,0]
ans[0] = x
if vy < 0: ans[1] = 0
else: ans[1] = m
print(ans[0],ans[1])
return 0
if vy == 0:
if y != 0 and y != m:
print("-1")
return 0
ans = [0,0]
ans[1] = y
if vx < 0: ans[0] = 0
else: ans[0] = n
print(ans[0],ans[1])
return 0
if vx == -1 and x == 0: vx = 1
if vx == 1 and x == n: vx = -1
if vy == -1 and y == 0: vy = 1
if vy == 1 and y == m: vy = -1
g = GCD(n,m)
m1 = n
m2 = m
a1 = -1 * vx * x % m1
a2 = -1 * vy * y % m2
if a1 % g != a2 % g:
print("-1")
return 0
if GCD(m1//g,m2) == 1:
m1 = m1 // g
else:
m2 = m2 // g
m1_bar = INV(m2,m1)
m2_bar = INV(m1,m2)
k = (a1 * m1_bar*m2 + a2 * m2_bar*m1) % (m1*m2)
rowtouch = ((k+m-1)//m) % 2
coltouch = ((k+n-1)//n) % 2
ans = [0,0]
if vx == 1: ans[0] = 0
else: ans[0] = n
if vy == 1: ans[1] = 0
else: ans[1] = m
if rowtouch == 1: ans[1] = m-ans[1]
if coltouch == 1: ans[0] = n-ans[0]
print(ans[0],ans[1])
return 0
solve()
``` | {
"language": "python",
"test_cases": [
{
"input": "4 3 2 2 -1 1\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"input": "4 4 2 0 1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "10 10 10 1 -1 0\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 1 1000000000 0 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "2 1 1 0 -1 -1\n",
"output": "0 1",
"type": "stdin_stdout"
},
{
"input": "4 2 1 2 1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "5 3 4 3 1 -1\n",
"output": "0 3",
"type": "stdin_stdout"
},
{
"input": "15 9 1 1 1 1\n",
"output": "15 9",
"type": "stdin_stdout"
},
{
"input": "15 9 1 1 -1 -1\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"input": "15 9 2 1 1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "15 9 2 1 -1 1\n",
"output": "15 0",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999999 999999998 999999999 -1 -1\n",
"output": "1000000000 999999999",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999999 999999998 999999999 -1 1\n",
"output": "1000000000 999999999",
"type": "stdin_stdout"
},
{
"input": "15 9 3 2 1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "15 9 3 2 1 -1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "4 4 0 1 0 1\n",
"output": "0 4",
"type": "stdin_stdout"
},
{
"input": "4 4 4 2 0 -1\n",
"output": "4 0",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999999 999999999 999999999 1 1\n",
"output": "1000000000 0",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999999 999999998 999999999 1 1\n",
"output": "0 999999999",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999999 999999998 999999999 1 -1\n",
"output": "0 999999999",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999999 999999998 999999999 0 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999999 999999998 999999999 -1 0\n",
"output": "0 999999999",
"type": "stdin_stdout"
},
{
"input": "1 99 0 16 -1 1\n",
"output": "1 99",
"type": "stdin_stdout"
},
{
"input": "6 8 1 1 1 1\n",
"output": "0 8",
"type": "stdin_stdout"
},
{
"input": "6 10 1 1 1 1\n",
"output": "6 10",
"type": "stdin_stdout"
},
{
"input": "8 6 7 1 -1 1\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"input": "10009 10007 1 1 1 1\n",
"output": "10009 10007",
"type": "stdin_stdout"
},
{
"input": "10007 10009 10006 10008 -1 -1\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"input": "1000 999 1 998 1 -1\n",
"output": "1000 999",
"type": "stdin_stdout"
},
{
"input": "500 500 250 250 -1 1\n",
"output": "0 500",
"type": "stdin_stdout"
},
{
"input": "2705444 415131525 949293 337120042 1 -1\n",
"output": "2705444 415131525",
"type": "stdin_stdout"
},
{
"input": "603278410 844534002 499505824 32181172 1 -1\n",
"output": "603278410 844534002",
"type": "stdin_stdout"
},
{
"input": "316347709 122791181 255721626 19148895 -1 1\n",
"output": "316347709 0",
"type": "stdin_stdout"
},
{
"input": "226591495 303844168 64300938 148467902 -1 -1\n",
"output": "0 303844168",
"type": "stdin_stdout"
},
{
"input": "682138812 116415655 516825996 73682791 -1 1\n",
"output": "0 116415655",
"type": "stdin_stdout"
},
{
"input": "305675046 505376350 144451750 295580797 -1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "313157692 571680270 238352863 235464142 1 -1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "120717601 973035857 103171773 511250918 -1 1\n",
"output": "120717601 0",
"type": "stdin_stdout"
},
{
"input": "41373770 597127671 31867608 404367855 -1 1\n",
"output": "41373770 597127671",
"type": "stdin_stdout"
},
{
"input": "827285013 307724101 775951207 175683367 -1 -1\n",
"output": "827285013 307724101",
"type": "stdin_stdout"
},
{
"input": "110474424 613900860 31471099 442410471 -1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "84035810 39157280 10865763 24269978 1 -1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "75744115 329085002 22395692 81831548 -1 1\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"input": "20597226 82154419 5899110 71189386 1 1\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"input": "550269655 264187669 141601786 53516425 1 -1\n",
"output": "550269655 0",
"type": "stdin_stdout"
},
{
"input": "224819588 978615384 68538326 805268586 1 1\n",
"output": "224819588 978615384",
"type": "stdin_stdout"
},
{
"input": "979444430 110858783 607921615 88320790 1 -1\n",
"output": "979444430 110858783",
"type": "stdin_stdout"
},
{
"input": "853950494 911554949 428001551 108479491 1 1\n",
"output": "853950494 0",
"type": "stdin_stdout"
},
{
"input": "810387002 412176212 187695958 236085023 1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "20877471 722211317 8457280 75966699 -1 -1\n",
"output": "0 722211317",
"type": "stdin_stdout"
},
{
"input": "542708351 3475408 103232934 399149 1 1\n",
"output": "542708351 3475408",
"type": "stdin_stdout"
},
{
"input": "30609041 976052297 4229728 158676967 -1 1\n",
"output": "30609041 0",
"type": "stdin_stdout"
},
{
"input": "495082283 937762241 250777046 412284609 1 1\n",
"output": "495082283 0",
"type": "stdin_stdout"
},
{
"input": "68076815 985943633 40657983 165191148 1 -1\n",
"output": "0 985943633",
"type": "stdin_stdout"
},
{
"input": "209408006 202717192 115684862 96677080 -1 -1\n",
"output": "209408006 202717192",
"type": "stdin_stdout"
},
{
"input": "651520659 433737829 645844796 133999548 1 -1\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"input": "835624982 341676615 379293679 54053933 1 -1\n",
"output": "835624982 0",
"type": "stdin_stdout"
},
{
"input": "943609111 405753192 556398014 348647907 1 -1\n",
"output": "943609111 0",
"type": "stdin_stdout"
},
{
"input": "590709848 332238455 546245223 240305069 -1 1\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"input": "320049957 92820858 176731509 15650804 1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "233140029 827954502 99465884 170396111 1 1\n",
"output": "233140029 827954502",
"type": "stdin_stdout"
},
{
"input": "760904646 962606170 641547160 113696561 -1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "584801838 775270595 121061956 644380885 -1 1\n",
"output": "0 775270595",
"type": "stdin_stdout"
},
{
"input": "141190266 126518281 76515989 109124404 1 1\n",
"output": "0 126518281",
"type": "stdin_stdout"
},
{
"input": "225067174 487662889 175063389 447988824 1 1\n",
"output": "225067174 487662889",
"type": "stdin_stdout"
},
{
"input": "814170008 703690544 6953086 439080555 -1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "12671644 216092609 3707378 92213588 1 1\n",
"output": "12671644 0",
"type": "stdin_stdout"
},
{
"input": "686521539 766868053 668178904 36804229 1 1\n",
"output": "686521539 0",
"type": "stdin_stdout"
},
{
"input": "43760214 59779641 32562470 43565961 -1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "281776735 833828834 271604381 491447288 -1 1\n",
"output": "281776735 833828834",
"type": "stdin_stdout"
},
{
"input": "362762211 732244195 63812822 258610562 -1 1\n",
"output": "362762211 732244195",
"type": "stdin_stdout"
},
{
"input": "312319019 933972106 103989975 544805243 1 -1\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"input": "142096067 231234738 40134344 206132422 -1 1\n",
"output": "0 231234738",
"type": "stdin_stdout"
},
{
"input": "289285219 692430999 249276742 628721059 1 -1\n",
"output": "0 692430999",
"type": "stdin_stdout"
},
{
"input": "490696330 492707826 183410939 115542637 -1 -1\n",
"output": "490696330 0",
"type": "stdin_stdout"
},
{
"input": "916524063 555774494 499847875 268662592 -1 1\n",
"output": "916524063 555774494",
"type": "stdin_stdout"
},
{
"input": "101123973 722433301 46988094 586973439 -1 1\n",
"output": "101123973 0",
"type": "stdin_stdout"
},
{
"input": "808357574 854008109 9323335 342356143 -1 -1\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"input": "257447593 468889343 162885112 15431794 1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "688226257 305863798 134250684 285725084 -1 -1\n",
"output": "0 305863798",
"type": "stdin_stdout"
},
{
"input": "836255310 741706431 648685681 396741892 1 -1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "480678700 670120443 423401724 177051387 1 1\n",
"output": "480678700 670120443",
"type": "stdin_stdout"
},
{
"input": "35550087 590484118 10858303 37118846 1 1\n",
"output": "35550087 590484118",
"type": "stdin_stdout"
},
{
"input": "491475453 334831307 136826756 228553610 1 -1\n",
"output": "491475453 334831307",
"type": "stdin_stdout"
},
{
"input": "172057628 368934073 117631597 83410362 1 1\n",
"output": "172057628 368934073",
"type": "stdin_stdout"
},
{
"input": "611927194 869083092 295778083 541333563 -1 -1\n",
"output": "0 869083092",
"type": "stdin_stdout"
},
{
"input": "329666407 901295668 90510437 485008861 1 -1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "978089453 426264909 388420346 53798427 -1 1\n",
"output": "0 426264909",
"type": "stdin_stdout"
},
{
"input": "242449067 548221648 24810672 63078584 1 1\n",
"output": "0 548221648",
"type": "stdin_stdout"
},
{
"input": "583053442 353408 240939980 17207 -1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "10 9 8 9 -1 1\n",
"output": "10 9",
"type": "stdin_stdout"
},
{
"input": "999999997 999999999 500 500 -1 1\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 999 100 -1 -1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "7 5 2 3 1 0\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "11 13 5 7 -1 -1\n",
"output": "0 0",
"type": "stdin_stdout"
},
{
"input": "500 1000 200 200 1 1\n",
"output": "0 1000",
"type": "stdin_stdout"
},
{
"input": "500 995 1 1 1 1\n",
"output": "500 0",
"type": "stdin_stdout"
},
{
"input": "1 100 0 1 1 1\n",
"output": "1 100",
"type": "stdin_stdout"
},
{
"input": "1 100 0 1 1 0\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "999999999 999999998 2 3 -1 1\n",
"output": "999999999 0",
"type": "stdin_stdout"
},
{
"input": "500000000 499999999 499999999 499999999 1 1\n",
"output": "500000000 0",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/982/E"
} | vfc_10142 |
apps | verifiable_code | 98 | Solve the following coding problem using the programming language python:
Gerald bought two very rare paintings at the Sotheby's auction and he now wants to hang them on the wall. For that he bought a special board to attach it to the wall and place the paintings on the board. The board has shape of an a_1 × b_1 rectangle, the paintings have shape of a a_2 × b_2 and a_3 × b_3 rectangles.
Since the paintings are painted in the style of abstract art, it does not matter exactly how they will be rotated, but still, one side of both the board, and each of the paintings must be parallel to the floor. The paintings can touch each other and the edges of the board, but can not overlap or go beyond the edge of the board. Gerald asks whether it is possible to place the paintings on the board, or is the board he bought not large enough?
-----Input-----
The first line contains two space-separated numbers a_1 and b_1 — the sides of the board. Next two lines contain numbers a_2, b_2, a_3 and b_3 — the sides of the paintings. All numbers a_{i}, b_{i} in the input are integers and fit into the range from 1 to 1000.
-----Output-----
If the paintings can be placed on the wall, print "YES" (without the quotes), and if they cannot, print "NO" (without the quotes).
-----Examples-----
Input
3 2
1 3
2 1
Output
YES
Input
5 5
3 3
3 3
Output
NO
Input
4 2
2 3
1 2
Output
YES
-----Note-----
That's how we can place the pictures in the first test:
[Image]
And that's how we can do it in the third one.
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a, b = [int(i) for i in input().split()]
c, d = [int(i) for i in input().split()]
e, f = [int(i) for i in input().split()]
if c+e <=a and max(d,f) <=b:
print("YES")
elif c+e <=b and max(d,f) <=a:
print("YES")
elif c+f <=a and max(d,e) <=b:
print("YES")
elif c+f <=b and max(d,e) <=a:
print("YES")
elif d+e <=a and max(c,f) <=b:
print("YES")
elif d+e <=b and max(c,f) <=a:
print("YES")
elif d+f <=a and max(c,e) <=b:
print("YES")
elif d+f <=b and max(c,e) <=a:
print("YES")
else:
print("NO")
``` | {
"language": "python",
"test_cases": [
{
"input": "3 2\n1 3\n2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n3 3\n3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n2 3\n1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n1 1\n1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1000 1000\n999 999\n1 1000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 7\n5 5\n2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n2 2\n2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 9\n5 1\n3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9 9\n3 8\n5 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n10 5\n4 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 6\n10 1\n5 7\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 10\n6 3\n6 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 10\n7 5\n1 7\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n7 4\n3 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 10\n1 1\n9 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 7\n1 7\n3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 10\n5 2\n3 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9 9\n9 7\n2 9\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 10\n3 8\n7 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n6 6\n4 9\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 9\n7 6\n2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n9 10\n6 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "90 100\n52 76\n6 47\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "84 99\n82 54\n73 45\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 62\n93 3\n100 35\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "93 98\n75 32\n63 7\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "86 100\n2 29\n71 69\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "96 100\n76 21\n78 79\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "99 100\n95 68\n85 32\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "97 100\n95 40\n70 60\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 100\n6 45\n97 54\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "99 100\n99 72\n68 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "88 100\n54 82\n86 45\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "91 100\n61 40\n60 88\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 100\n36 32\n98 68\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "78 86\n63 8\n9 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "72 93\n38 5\n67 64\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "484 1000\n465 2\n9 535\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "808 1000\n583 676\n527 416\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "965 1000\n606 895\n533 394\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "824 503\n247 595\n151 570\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "970 999\n457 305\n542 597\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "332 834\n312 23\n505 272\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "886 724\n830 439\n102 594\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "958 1000\n326 461\n836 674\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "903 694\n104 488\n567 898\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "800 1000\n614 163\n385 608\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "926 1000\n813 190\n187 615\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "541 1000\n325 596\n403 56\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "881 961\n139 471\n323 731\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "993 1000\n201 307\n692 758\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "954 576\n324 433\n247 911\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 3\n7 8\n1 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 9\n2 7\n8 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n4 3\n5 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 7\n8 3\n2 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 4\n7 2\n3 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 8\n5 1\n10 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n3 6\n10 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 2\n6 6\n1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n6 6\n4 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9 10\n4 8\n5 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 8\n3 2\n8 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n3 4\n3 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 10\n1 8\n3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 1\n7 5\n3 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9 7\n5 2\n4 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 30\n42 99\n78 16\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "64 76\n5 13\n54 57\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "85 19\n80 18\n76 70\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "57 74\n99 70\n86 29\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "22 21\n73 65\n92 35\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "90 75\n38 2\n100 61\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "62 70\n48 12\n75 51\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "23 17\n34 71\n98 34\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "95 72\n65 31\n89 50\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "68 19\n39 35\n95 65\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "28 65\n66 27\n5 72\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100 16\n41 76\n24 15\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "21 63\n28 73\n60 72\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "85 18\n37 84\n35 62\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "58 64\n98 30\n61 52\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "32 891\n573 351\n648 892\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "796 846\n602 302\n600 698\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "665 289\n608 360\n275 640\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "237 595\n318 161\n302 838\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "162 742\n465 429\n571 29\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "222 889\n491 923\n76 195\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "794 140\n166 622\n378 905\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "663 287\n193 212\n615 787\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "427 433\n621 441\n868 558\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1000 388\n332 49\n735 699\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "868 535\n409 690\n761 104\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "632 786\n710 208\n436 290\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "501 932\n463 636\n363 918\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "73 79\n626 483\n924 517\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "190 34\n653 163\n634 314\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n1 3\n1 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 10\n1 1\n1 11\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n3 3\n2 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n1 6\n2 3\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/560/B"
} | vfc_10146 |
apps | verifiable_code | 99 | Solve the following coding problem using the programming language python:
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b_1 and q. Remind that a geometric progression is a sequence of integers b_1, b_2, b_3, ..., where for each i > 1 the respective term satisfies the condition b_{i} = b_{i} - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b_1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a_1, a_2, ..., a_{m}, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |b_{i}| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
-----Input-----
The first line of input contains four integers b_1, q, l, m (-10^9 ≤ b_1, q ≤ 10^9, 1 ≤ l ≤ 10^9, 1 ≤ m ≤ 10^5) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a_1, a_2, ..., a_{m} (-10^9 ≤ a_{i} ≤ 10^9) — numbers that will never be written on the board.
-----Output-----
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
-----Examples-----
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
-----Note-----
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def main():
(b1, q, l, m) = list(map(int, input().split()))
a = set(map(int, input().split()))
if abs(b1) > l:
print(0)
else:
if b1 == 0:
if 0 in a:
print(0)
else:
print("inf")
elif q == 0:
if 0 not in a:
print("inf")
elif b1 in a:
print(0)
else:
print(1)
elif q == 1:
if b1 in a:
print(0)
else:
print("inf")
elif q == -1:
if (b1 in a) and ((-b1) in a):
print(0)
else:
print("inf")
else:
ans = 0
b = b1
for i in range(100):
if b in a:
b *= q
if abs(b) > l:
break
continue
ans += 1
b *= q
if abs(b) > l:
break
print(ans)
def __starting_point():
main()
__starting_point()
``` | {
"language": "python",
"test_cases": [
{
"input": "3 2 30 4\n6 14 25 48\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "123 1 2143435 4\n123 11 -5453 141245\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "123 1 2143435 4\n54343 -13 6 124\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "3 2 25 2\n379195692 -69874783\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "3 2 30 3\n-691070108 -934106649 -220744807\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "3 3 104 17\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981034 -375897180 -80186684 -173062070 -288705544 -699097793 -11447747 320434295 503414250\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "-1000000000 -1000000000 1 1\n232512888\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "11 0 228 5\n-1 0 1 5 -11245\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "11 0 228 5\n-1 -17 1 5 -11245\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "0 0 2143435 5\n-1 -153 1 5 -11245\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "123 0 2143435 4\n5433 0 123 -645\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "123 -1 2143435 5\n-123 0 12 5 -11245\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "123 0 21 4\n543453 -123 6 1424\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 2 115 16\n24 48 12 96 3 720031148 -367712651 -838596957 558177735 -963046495 -313322487 -465018432 -618984128 -607173835 144854086 178041956\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "-3 0 92055 36\n-92974174 -486557474 -663622151 695596393 177960746 -563227474 -364263320 -676254242 -614140218 71456762 -764104225 705056581 -106398436 332755134 -199942822 -732751692 658942664 677739866 886535704 183687802 -784248291 -22550621 -938674499 637055091 -704750213 780395802 778342470 -999059668 -794361783 796469192 215667969 354336794 -60195289 -885080928 -290279020 201221317\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "0 -3 2143435 5\n-1 0 1 5 -11245\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "123 -1 2143435 5\n-123 0 123 -5453 141245\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "123 0 2143435 4\n5433 0 -123 -645\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "11 0 2 5\n-1 0 1 5 -11245\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 2 4 1\n2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "1 -2 1000000000 1\n0\n",
"output": "30",
"type": "stdin_stdout"
},
{
"input": "0 8 10 1\n5\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "-1000 0 10 1\n5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "0 2 2143435 4\n54343 -13 6 124\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "0 8 5 1\n9\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "-10 1 5 1\n100\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "123 -1 2143435 4\n54343 -13 6 123\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "-5 -1 10 1\n-5\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "2 0 1 1\n2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "0 5 8 1\n10\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "0 5 100 2\n34 56\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "15 -1 15 4\n15 -15 1 2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "10 -1 2 1\n1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 0 2 1\n2\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "4 0 4 1\n0\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "10 10 10 1\n123\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "2 2 4 1\n3\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "0 1 1 1\n0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 2 30 1\n3\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "1000000000 100000 1000000000 4\n5433 13 6 0\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "-2 0 1 1\n1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 -1 10 1\n2\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "1 -1 2 1\n1\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "0 10 10 1\n2\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "0 35 2 1\n3\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "3 1 3 1\n5\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "3 2 3 4\n6 14 25 48\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "0 69 12 1\n1\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "100 0 100000 1\n100\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "0 4 1000 3\n5 6 7\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "0 2 100 1\n5\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "3 2 24 4\n6 14 25 48\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "0 4 1 1\n2\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "1 5 10000 1\n125\n",
"output": "5",
"type": "stdin_stdout"
},
{
"input": "2 -1 1 1\n1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "0 3 100 1\n5\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "0 3 3 1\n1\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "0 2 5 1\n1\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "5 -1 100 1\n5\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "-20 0 10 1\n0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 0 1 1\n3\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 -1 3 1\n2\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "1 1 1000000000 1\n100\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "5 -1 3 1\n0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "0 5 10 1\n2\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "123 0 125 1\n123\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "2 -1 100 1\n2\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "5 2 100 1\n5\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "-5 0 1 1\n1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "-3 0 1 1\n-3\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2 -2 10 1\n1\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "0 2 30 4\n6 14 25 48\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "1 -1 1 1\n1\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "2 -1 6 1\n2\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "-3 1 100 1\n-3\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1 0 2 1\n1\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "1000000000 999999998 1000000000 1\n0\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "1 0 2143435 4\n1 -123 -5453 141245\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "-1000 0 100 1\n-1000\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "100 10 2 1\n100\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "-3 1 100 1\n3\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "123 -1 10000 1\n123\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "1 -1 2143435 4\n1 -123 -5453 141245\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "5 1 5 5\n1 2 3 4 0\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "-100 -1 1 1\n1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "10 -1 3 2\n10 8\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "-10 0 5 1\n0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 0 3 1\n0\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "2 0 2 1\n-1\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "5 0 20 1\n5\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "-4 1 1 1\n0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "11 0 1111 1\n11\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "2 0 3 1\n2\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "-1 -1 2143435 4\n-1 -123 -5453 141245\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "-100 0 50 1\n0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5 1 2 1\n2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 0 3 1\n4\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "0 23 3 1\n3\n",
"output": "inf",
"type": "stdin_stdout"
},
{
"input": "-1000 0 100 1\n2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1 -1 10 1\n1\n",
"output": "inf",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/789/B"
} | vfc_10150 |
apps | verifiable_code | 100 | Solve the following coding problem using the programming language python:
Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus.
Innocentius is touch-typing a program that paints a white square one-pixel wide frame on the black screen. As the monitor is broken, some pixels that should be white remain black. Polycarpus should look at what the program displayed on the screen and guess the position and size of the frame Innocentius has painted. Polycarpus doesn't like the game but Innocentius persuaded brother to play as "the game is good for the imagination and attention".
Help Polycarpus, automatize his part in the gaming process. Write the code that finds such possible square frame that: the frame's width is 1 pixel, the frame doesn't go beyond the borders of the screen, all white pixels of the monitor are located on the frame, of all frames that satisfy the previous three conditions, the required frame must have the smallest size.
Formally, a square frame is represented by such pixels of the solid square, that are on the square's border, that is, are not fully surrounded by the other pixels of the square. For example, if the frame's size is d = 3, then it consists of 8 pixels, if its size is d = 2, then it contains 4 pixels and if d = 1, then the frame is reduced to a single pixel.
-----Input-----
The first line contains the resolution of the monitor as a pair of integers n, m (1 ≤ n, m ≤ 2000). The next n lines contain exactly m characters each — the state of the monitor pixels at the moment of the game. Character "." (period, ASCII code 46) corresponds to the black pixel, and character "w" (lowercase English letter w) corresponds to the white pixel. It is guaranteed that at least one pixel of the monitor is white.
-----Output-----
Print the monitor screen. Represent the sought frame by characters "+" (the "plus" character). The pixels that has become white during the game mustn't be changed. Print them as "w". If there are multiple possible ways to position the frame of the minimum size, print any of them.
If the required frame doesn't exist, then print a single line containing number -1.
-----Examples-----
Input
4 8
..w..w..
........
........
..w..w..
Output
..w++w..
..+..+..
..+..+..
..w++w..
Input
5 6
......
.w....
......
..w...
......
Output
......
+w+...
+.+...
++w...
......
Input
2 4
....
.w..
Output
....
.w..
Input
2 6
w..w.w
...w..
Output
-1
-----Note-----
In the first sample the required size of the optimal frame equals 4. In the second sample the size of the optimal frame equals 3. In the third sample, the size of the optimal frame is 1. In the fourth sample, the required frame doesn't exist.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
3
def readln(): return list(map(int, input().split()))
import sys
def return:
print(-1)
return
n, m = readln()
mon = [list(input()) for _ in range(n)]
hor = [i for i in range(n) if mon[i] != ['.'] * m]
rmon = list(zip(*mon))
ver = [j for j in range(m) if rmon[j] != ('.',) * n]
mini = hor[0]
maxi = hor[-1]
minj = ver[0]
maxj = ver[-1]
cnt_in = len([1 for i in range(mini + 1, maxi) for j in range(minj + 1, maxj) if mon[i][j] == 'w'])
cnt_l = len([1 for i in range(mini + 1, maxi) if mon[i][minj] == 'w'])
cnt_r = len([1 for i in range(mini + 1, maxi) if mon[i][maxj] == 'w'])
cnt_d = len([1 for j in range(minj + 1, maxj) if mon[mini][j] == 'w'])
cnt_u = len([1 for j in range(minj + 1, maxj) if mon[maxi][j] == 'w'])
if cnt_in:
return
if maxi - mini < maxj - minj:
k = maxj - minj + 1
if maxi == mini and cnt_d:
if mini >= k - 1:
mini -= k - 1
elif maxi + k - 1 < n:
maxi += k - 1
else:
return
else:
if not cnt_d:
mini = max(0, maxi - k + 1)
if maxi - maxi + 1 != k and not cnt_u:
maxi = min(mini + k - 1, n - 1)
if maxi - mini + 1 != k:
return
else:
k = maxi - mini + 1
if maxj == minj and cnt_l:
if minj >= k - 1:
minj -= k - 1
elif maxj + k - 1 < m:
maxj += k - 1
else:
return
else:
if not cnt_l:
minj = max(0, maxj - k + 1)
if maxj - minj + 1 != k and not cnt_r:
maxj = min(minj + k - 1, m - 1)
if maxj - minj + 1 != k:
return
for i in range(mini, maxi + 1):
if mon[i][minj] == '.':
mon[i][minj] = '+'
for i in range(mini, maxi + 1):
if mon[i][maxj] == '.':
mon[i][maxj] = '+'
for j in range(minj, maxj + 1):
if mon[mini][j] == '.':
mon[mini][j] = '+'
for j in range(minj, maxj + 1):
if mon[maxi][j] == '.':
mon[maxi][j] = '+'
print('\n'.join([''.join(row) for row in mon]))
``` | {
"language": "python",
"test_cases": [
{
"input": "4 8\n..w..w..\n........\n........\n..w..w..\n",
"output": "..w++w..\n..+..+..\n..+..+..\n..w++w..\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n......\n.w....\n......\n..w...\n......\n",
"output": "......\n+w+...\n+.+...\n++w...\n......\n",
"type": "stdin_stdout"
},
{
"input": "2 4\n....\n.w..\n",
"output": "....\n.w..\n",
"type": "stdin_stdout"
},
{
"input": "2 6\nw..w.w\n...w..\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9 4\n....\n....\n....\n....\n....\n..w.\n....\n....\n.w..\n",
"output": "....\n....\n....\n....\n....\n++w+\n+..+\n+..+\n+w++\n",
"type": "stdin_stdout"
},
{
"input": "10 4\n....\n.w..\n....\n....\n.w..\n....\n....\n....\n....\n....\n",
"output": "....\n+w++\n+..+\n+..+\n+w++\n....\n....\n....\n....\n....\n",
"type": "stdin_stdout"
},
{
"input": "4 10\n..........\n..........\n.w..w.....\n..........\n",
"output": ".++++.....\n.+..+.....\n.w..w.....\n.++++.....\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n...\nw.w\n...\n",
"output": "+++\nw.w\n+++\n",
"type": "stdin_stdout"
},
{
"input": "1 1\nw\n",
"output": "w\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nw\n.\n",
"output": "w\n.\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nw\nw\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 2\nww\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nww\n..\n",
"output": "ww\n++\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n.w\n.w\n",
"output": "+w\n+w\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n..\nww\n",
"output": "++\nww\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nw.\nw.\n",
"output": "w+\nw+\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nw.\n.w\n",
"output": "w+\n+w\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n..\nw.\n",
"output": "..\nw.\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n...\n..w\nw..\n",
"output": "+++\n+.w\nw++\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n.w.\n..w\n...\n",
"output": ".w+\n.+w\n...\n",
"type": "stdin_stdout"
},
{
"input": "4 4\nw...\n..w.\n....\n....\n",
"output": "w++.\n+.w.\n+++.\n....\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n....w.\n......\n.w....\n......\n",
"output": ".+++w.\n.+..+.\n.w..+.\n.++++.\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n....w.\n......\n......\n.w....\n",
"output": ".+++w.\n.+..+.\n.+..+.\n.w+++.\n",
"type": "stdin_stdout"
},
{
"input": "4 6\nw...w.\n......\n......\n.w....\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 6\nw.....\n......\n......\n.w....\n",
"output": "w+++..\n+..+..\n+..+..\n+w++..\n",
"type": "stdin_stdout"
},
{
"input": "4 6\nw....w\n......\n.....w\n.w....\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "7 3\n...\n...\n...\n..w\n...\nw..\n...\n",
"output": "...\n...\n...\n++w\n+.+\nw++\n...\n",
"type": "stdin_stdout"
},
{
"input": "7 3\n...\n...\n...\n.w.\n..w\nw..\n...\n",
"output": "...\n...\n...\n+w+\n+.w\nw++\n...\n",
"type": "stdin_stdout"
},
{
"input": "7 3\n...\n...\n...\n.w.\nw.w\nw..\n...\n",
"output": "...\n...\n...\n+w+\nw.w\nw++\n...\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n.......\n.......\n.......\n.www...\n.......\n",
"output": ".......\n.+++...\n.+.+...\n.www...\n.......\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n.......\n.wwww..\n.......\n.......\n.......\n",
"output": ".......\n.wwww..\n.+..+..\n.+..+..\n.++++..\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n.......\n.w.....\n.w.....\n.w.....\n.w.....\n",
"output": ".......\n.w+++..\n.w..+..\n.w..+..\n.w+++..\n",
"type": "stdin_stdout"
},
{
"input": "1 7\nw.....w\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 9\n.w.......\n.........\n.........\n.........\n.w.......\n......w..\n",
"output": ".w+++++..\n.+....+..\n.+....+..\n.+....+..\n.w....+..\n.+++++w..\n",
"type": "stdin_stdout"
},
{
"input": "6 9\n...ww....\n.........\n.........\n.........\n.........\n......w..\n",
"output": "...ww++++\n...+....+\n...+....+\n...+....+\n...+....+\n...+++w++\n",
"type": "stdin_stdout"
},
{
"input": "6 9\n.......w.\n.........\n.........\n.........\n.........\n......w..\n",
"output": "..+++++w.\n..+....+.\n..+....+.\n..+....+.\n..+....+.\n..++++w+.\n",
"type": "stdin_stdout"
},
{
"input": "8 10\n..........\n...w......\n.....w....\n.w........\n....w.....\n..........\n..........\n..........\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "8 10\n..........\n...w......\n.....w....\n.w........\n..........\n....w.....\n..........\n..........\n",
"output": "..........\n.++w++....\n.+...w....\n.w...+....\n.+...+....\n.+++w+....\n..........\n..........\n",
"type": "stdin_stdout"
},
{
"input": "8 10\n..........\n...w......\n..........\n.w........\n..........\n....w.....\n..........\n..........\n",
"output": "..........\n.++w++....\n.+...+....\n.w...+....\n.+...+....\n.+++w+....\n..........\n..........\n",
"type": "stdin_stdout"
},
{
"input": "8 10\n..........\n..........\n.....w....\n.w........\n..........\n....w.....\n..........\n..........\n",
"output": "..........\n.+++++....\n.+...w....\n.w...+....\n.+...+....\n.+++w+....\n..........\n..........\n",
"type": "stdin_stdout"
},
{
"input": "8 10\n..........\n...w......\n..........\n..........\n..........\n....w.....\n..........\n..........\n",
"output": "..........\n+++w+.....\n+...+.....\n+...+.....\n+...+.....\n++++w.....\n..........\n..........\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n....\n....\n....\nw...\n....\n",
"output": "....\n....\n....\nw...\n....\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n....\nw...\n...w\n.w..\n..w.\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 4\nw..w\n...w\nw...\n..w.\n....\n",
"output": "w++w\n+..w\nw..+\n++w+\n....\n",
"type": "stdin_stdout"
},
{
"input": "5 4\nwwww\nwwww\nwwww\nwwww\nwwww\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n..w.\n..ww\n.www\n.w..\nwwww\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n....\n.w..\n....\n.w..\n....\n",
"output": "....\n+w+.\n+.+.\n+w+.\n....\n",
"type": "stdin_stdout"
},
{
"input": "5 4\nw...\n....\n...w\n....\n....\n",
"output": "w+++\n+..+\n+..w\n++++\n....\n",
"type": "stdin_stdout"
},
{
"input": "5 4\nwwww\nw..w\nwwww\n.www\n..ww\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n..w.\n....\n...w\n..w.\nw...\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 5\n.w...\n.....\n.....\n.....\nw....\n.....\n",
"output": "+w+++\n+...+\n+...+\n+...+\nw++++\n.....\n",
"type": "stdin_stdout"
},
{
"input": "8 16\n................\n................\n................\n................\n............w...\n................\n................\n..............w.\n",
"output": "................\n................\n................\n................\n............w+++\n............+..+\n............+..+\n............++w+\n",
"type": "stdin_stdout"
},
{
"input": "3 10\n.......w..\n........w.\n......w...\n",
"output": "......+w+.\n......+.w.\n......w++.\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n...\n...\n...\n...\n...\n...\n.w.\n..w\nw..\n...\n",
"output": "...\n...\n...\n...\n...\n...\n+w+\n+.w\nw++\n...\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n.w\n",
"output": ".w\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n.w\n..\n",
"output": ".w\n..\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n..\n.w\nww\n..\n..\n",
"output": "..\n+w\nww\n..\n..\n",
"type": "stdin_stdout"
},
{
"input": "1 6\n..w...\n",
"output": "..w...\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n..w.\n....\n....\n....\n",
"output": "..w.\n....\n....\n....\n",
"type": "stdin_stdout"
},
{
"input": "6 2\nw.\n..\n..\n..\n..\n..\n",
"output": "w.\n..\n..\n..\n..\n..\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n..\n.w\n..\n",
"output": "..\n.w\n..\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n......\n......\n.ww...\n......\n......\n",
"output": "......\n......\n.ww...\n.++...\n......\n",
"type": "stdin_stdout"
},
{
"input": "1 4\nw...\n",
"output": "w...\n",
"type": "stdin_stdout"
},
{
"input": "4 2\nw.\n..\n..\n..\n",
"output": "w.\n..\n..\n..\n",
"type": "stdin_stdout"
},
{
"input": "6 3\n...\n...\nw.w\n...\nwww\n...\n",
"output": "...\n...\nw+w\n+.+\nwww\n...\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n.\nw\n",
"output": ".\nw\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n.....\n.....\n.....\n.w...\n.....\n",
"output": ".....\n.....\n.....\n.w...\n.....\n",
"type": "stdin_stdout"
},
{
"input": "1 5\nw....\n",
"output": "w....\n",
"type": "stdin_stdout"
},
{
"input": "4 3\nw..\n...\n...\n...\n",
"output": "w..\n...\n...\n...\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n.\n.\nw\n.\n.\n.\n",
"output": ".\n.\nw\n.\n.\n.\n",
"type": "stdin_stdout"
},
{
"input": "2 5\n.....\nww...\n",
"output": "++...\nww...\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n.....\n.....\n..ww.\n.....\n.....\n",
"output": ".....\n.....\n..ww.\n..++.\n.....\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n..w\n",
"output": "..w\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n.\nw\n.\n.\n",
"output": ".\nw\n.\n.\n",
"type": "stdin_stdout"
},
{
"input": "6 2\n..\n.w\n..\n..\n..\n..\n",
"output": "..\n.w\n..\n..\n..\n..\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nw\n.\n",
"output": "w\n.\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n.\n.\n.\nw\n.\n",
"output": ".\n.\n.\nw\n.\n",
"type": "stdin_stdout"
},
{
"input": "1 5\n....w\n",
"output": "....w\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n..w\nw.w\n...\n...\n",
"output": "++w\nw.w\n+++\n...\n",
"type": "stdin_stdout"
},
{
"input": "6 1\nw\n.\n.\n.\n.\n.\n",
"output": "w\n.\n.\n.\n.\n.\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nw\n.\n",
"output": "w\n.\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n.....\n...w.\n.....\n.....\n.w...\n",
"output": ".....\n+++w.\n+..+.\n+..+.\n+w++.\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n.w.\n",
"output": ".w.\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n.\n.\n.\nw\n",
"output": ".\n.\n.\nw\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n..\nw.\n.w\n..\n",
"output": "..\nw+\n+w\n..\n",
"type": "stdin_stdout"
},
{
"input": "6 6\n......\nw.....\n...w..\n.w....\n......\n......\n",
"output": "++++..\nw..+..\n+..w..\n+w++..\n......\n......\n",
"type": "stdin_stdout"
},
{
"input": "3 6\n......\n....w.\n......\n",
"output": "......\n....w.\n......\n",
"type": "stdin_stdout"
},
{
"input": "5 4\nw.w.\nw...\nwww.\n....\n....\n",
"output": "w+w.\nw.+.\nwww.\n....\n....\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n..\nw.\n",
"output": "..\nw.\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n..\n..\nw.\n..\n",
"output": "..\n..\nw.\n..\n",
"type": "stdin_stdout"
},
{
"input": "1 6\n.....w\n",
"output": ".....w\n",
"type": "stdin_stdout"
},
{
"input": "3 4\nw...\n..w.\n.ww.\n",
"output": "w++.\n+.w.\n+ww.\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n..\n..\n..\n..\nw.\n",
"output": "..\n..\n..\n..\nw.\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n..\nw.\n",
"output": "..\nw.\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nw\n.\n",
"output": "w\n.\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n.\n.\nw\n.\n",
"output": ".\n.\nw\n.\n",
"type": "stdin_stdout"
},
{
"input": "1 5\nw....\n",
"output": "w....\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n...\n...\n.w.\n",
"output": "...\n...\n.w.\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n.\nw\n.\n.\n.\n.\n",
"output": ".\nw\n.\n.\n.\n.\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n.\nw\n",
"output": ".\nw\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n.w...\n.....\n.....\n.....\n.....\n",
"output": ".w...\n.....\n.....\n.....\n.....\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n..w\n",
"output": "..w\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n.\n.\nw\n",
"output": ".\n.\nw\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n.\n.\n.\n.\n.\nw\n",
"output": ".\n.\n.\n.\n.\nw\n",
"type": "stdin_stdout"
},
{
"input": "6 3\n...\n...\n...\n...\n...\n.w.\n",
"output": "...\n...\n...\n...\n...\n.w.\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/370/D"
} | vfc_10154 |
apps | verifiable_code | 101 | Solve the following coding problem using the programming language python:
Vasya has n burles. One bottle of Ber-Cola costs a burles and one Bars bar costs b burles. He can buy any non-negative integer number of bottles of Ber-Cola and any non-negative integer number of Bars bars.
Find out if it's possible to buy some amount of bottles of Ber-Cola and Bars bars and spend exactly n burles.
In other words, you should find two non-negative integers x and y such that Vasya can buy x bottles of Ber-Cola and y Bars bars and x·a + y·b = n or tell that it's impossible.
-----Input-----
First line contains single integer n (1 ≤ n ≤ 10 000 000) — amount of money, that Vasya has.
Second line contains single integer a (1 ≤ a ≤ 10 000 000) — cost of one bottle of Ber-Cola.
Third line contains single integer b (1 ≤ b ≤ 10 000 000) — cost of one Bars bar.
-----Output-----
If Vasya can't buy Bars and Ber-Cola in such a way to spend exactly n burles print «NO» (without quotes).
Otherwise in first line print «YES» (without quotes). In second line print two non-negative integers x and y — number of bottles of Ber-Cola and number of Bars bars Vasya should buy in order to spend exactly n burles, i.e. x·a + y·b = n. If there are multiple answers print any of them.
Any of numbers x and y can be equal 0.
-----Examples-----
Input
7
2
3
Output
YES
2 1
Input
100
25
10
Output
YES
0 10
Input
15
4
8
Output
NO
Input
9960594
2551
2557
Output
YES
1951 1949
-----Note-----
In first example Vasya can buy two bottles of Ber-Cola and one Bars bar. He will spend exactly 2·2 + 1·3 = 7 burles.
In second example Vasya can spend exactly n burles multiple ways: buy two bottles of Ber-Cola and five Bars bars; buy four bottles of Ber-Cola and don't buy Bars bars; don't buy Ber-Cola and buy 10 Bars bars.
In third example it's impossible to but Ber-Cola and Bars bars in order to spend exactly n burles.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def egcd(a, b):
x,y, u,v = 0,1, 1,0
while a != 0:
q, r = b//a, b%a
m, n = x-u*q, y-v*q
b,a, x,y, u,v = a,r, u,v, m,n
gcd = b
return gcd, x, y
import math
n=int(input())
a=int(input())
b=int(input())
gcd,x,y=(egcd(a,b))
status=0
if((n%gcd)!=0):
print("NO")
#print("point1")
else:
multiply=n/gcd
x1=int(multiply*x)
y1=int(multiply*y)
#print("gcd and soln to n")
#print(gcd,x1,y1)
d1=b/gcd
d2=a/gcd
rangemin= int(math.ceil(-x1/d1))
rangemax= int(y1//d2)
#print("rangemin and rangemax")
#print(rangemin,rangemax)
if(rangemin>rangemax):
print("NO")
#print("point2")
else:
#print("YES")
#solx=x1+rangemin*d1
#soly=y1-rangemin*d2
m=rangemin
while(m<=rangemax):
solx=x1+m*d1
soly=y1-m*d2
if(solx>=0 and soly>=0):
print("YES")
status=1
print(str(int(solx))+" "+str(int(soly)))
break
m=m+1
if(status==0):
print("NO")
#print("point3")
``` | {
"language": "python",
"test_cases": [
{
"input": "7\n2\n3\n",
"output": "YES\n2 1\n",
"type": "stdin_stdout"
},
{
"input": "100\n25\n10\n",
"output": "YES\n0 10\n",
"type": "stdin_stdout"
},
{
"input": "15\n4\n8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9960594\n2551\n2557\n",
"output": "YES\n1951 1949\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n1\n1\n",
"output": "YES\n0 10000000\n",
"type": "stdin_stdout"
},
{
"input": "9999999\n9999\n9999\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9963629\n2591\n2593\n",
"output": "YES\n635 3208\n",
"type": "stdin_stdout"
},
{
"input": "1\n7\n8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9963630\n2591\n2593\n",
"output": "YES\n1931 1913\n",
"type": "stdin_stdout"
},
{
"input": "7516066\n1601\n4793\n",
"output": "YES\n4027 223\n",
"type": "stdin_stdout"
},
{
"input": "6509546\n1607\n6221\n",
"output": "YES\n617 887\n",
"type": "stdin_stdout"
},
{
"input": "2756250\n8783\n29\n",
"output": "YES\n21 88683\n",
"type": "stdin_stdout"
},
{
"input": "7817510\n2377\n743\n",
"output": "YES\n560 8730\n",
"type": "stdin_stdout"
},
{
"input": "6087210\n1583\n1997\n",
"output": "YES\n1070 2200\n",
"type": "stdin_stdout"
},
{
"input": "4\n2\n2\n",
"output": "YES\n0 2\n",
"type": "stdin_stdout"
},
{
"input": "7996960\n4457\n5387\n",
"output": "YES\n727 883\n",
"type": "stdin_stdout"
},
{
"input": "7988988\n4021\n3169\n",
"output": "YES\n1789 251\n",
"type": "stdin_stdout"
},
{
"input": "4608528\n9059\n977\n",
"output": "YES\n349 1481\n",
"type": "stdin_stdout"
},
{
"input": "8069102\n2789\n47\n",
"output": "YES\n3 171505\n",
"type": "stdin_stdout"
},
{
"input": "3936174\n4783\n13\n",
"output": "YES\n5 300943\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n9999999\n1\n",
"output": "YES\n0 10000000\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n1\n9999999\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1\n3\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1\n2\n",
"output": "YES\n0 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n3\n1\n",
"output": "YES\n0 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n2\n1\n",
"output": "YES\n0 4\n",
"type": "stdin_stdout"
},
{
"input": "100\n10\n20\n",
"output": "YES\n0 5\n",
"type": "stdin_stdout"
},
{
"input": "101\n11\n11\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "121\n11\n11\n",
"output": "YES\n0 11\n",
"type": "stdin_stdout"
},
{
"input": "25\n5\n6\n",
"output": "YES\n5 0\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n1\n",
"output": "YES\n0 1\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n2\n1\n",
"output": "YES\n0 10000000\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n1234523\n1\n",
"output": "YES\n0 10000000\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n5000000\n5000000\n",
"output": "YES\n0 2\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n5000001\n5000000\n",
"output": "YES\n0 2\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n5000000\n5000001\n",
"output": "YES\n2 0\n",
"type": "stdin_stdout"
},
{
"input": "9999999\n9999999\n9999999\n",
"output": "YES\n0 1\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n10000000\n10000000\n",
"output": "YES\n0 1\n",
"type": "stdin_stdout"
},
{
"input": "10\n1\n3\n",
"output": "YES\n1 3\n",
"type": "stdin_stdout"
},
{
"input": "97374\n689\n893\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100096\n791\n524\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "75916\n651\n880\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "110587\n623\n806\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5600\n670\n778\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "81090\n527\n614\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "227718\n961\n865\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n3\n999999\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n4\n5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9999999\n2\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9999999\n2\n4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9999997\n2\n5\n",
"output": "YES\n1 1999999\n",
"type": "stdin_stdout"
},
{
"input": "9366189\n4326262\n8994187\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1000000\n1\n10000000\n",
"output": "YES\n1000000 0\n",
"type": "stdin_stdout"
},
{
"input": "9999991\n2\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n7\n7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9999991\n2\n4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n3\n6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n11\n11\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n7\n3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1000003\n2\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1000000\n7\n7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "999999\n2\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n13\n5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1000003\n15\n3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n7\n2\n",
"output": "YES\n1 0\n",
"type": "stdin_stdout"
},
{
"input": "9999999\n2\n8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1000000\n3\n7\n",
"output": "YES\n5 142855\n",
"type": "stdin_stdout"
},
{
"input": "9999999\n1\n10000000\n",
"output": "YES\n9999999 0\n",
"type": "stdin_stdout"
},
{
"input": "100\n1\n1000000\n",
"output": "YES\n100 0\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n9999999\n9999997\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n1\n3\n",
"output": "YES\n2 0\n",
"type": "stdin_stdout"
},
{
"input": "3\n5\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n2\n3\n",
"output": "YES\n1 1\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n7\n14\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n2\n9999999\n",
"output": "YES\n5000000 0\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n3\n3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "25\n27\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n2\n17\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "999997\n4\n8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2000000\n1\n2000001\n",
"output": "YES\n2000000 0\n",
"type": "stdin_stdout"
},
{
"input": "8\n7\n3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7005920\n5705\n28145\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n6\n4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n9999999\n3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n77\n99\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n8\n70\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "99999\n2\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n7\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "999999\n12\n14\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n1\n1000\n",
"output": "YES\n100 0\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n123\n321\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9369319\n4\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9999998\n3\n3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "85\n5\n85\n",
"output": "YES\n0 1\n",
"type": "stdin_stdout"
},
{
"input": "64549\n9999999\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n3\n7\n",
"output": "YES\n1 1428571\n",
"type": "stdin_stdout"
},
{
"input": "9999889\n2\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10000000\n9999999\n123\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "64549\n2\n9999999\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/898/B"
} | vfc_10158 |
apps | verifiable_code | 102 | Solve the following coding problem using the programming language python:
Today Tavas got his test result as an integer score and he wants to share it with his girlfriend, Nafas.
His phone operating system is Tavdroid, and its keyboard doesn't have any digits! He wants to share his score with Nafas via text, so he has no choice but to send this number using words. [Image]
He ate coffee mix without water again, so right now he's really messed up and can't think.
Your task is to help him by telling him what to type.
-----Input-----
The first and only line of input contains an integer s (0 ≤ s ≤ 99), Tavas's score.
-----Output-----
In the first and only line of output, print a single string consisting only from English lowercase letters and hyphens ('-'). Do not use spaces.
-----Examples-----
Input
6
Output
six
Input
99
Output
ninety-nine
Input
20
Output
twenty
-----Note-----
You can find all you need to know about English numerals in http://en.wikipedia.org/wiki/English_numerals .
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())
if n == 0:
print('zero')
elif n == 1:
print('one')
elif n == 2:
print('two')
elif n == 3:
print('three')
elif n == 4:
print('four')
elif n == 5:
print('five')
elif n == 6:
print('six')
elif n == 7:
print('seven')
elif n == 8:
print('eight')
elif n == 9:
print('nine')
elif n == 10:
print('ten')
elif n == 11:
print('eleven')
elif n == 12:
print('twelve')
elif n == 13:
print('thirteen')
elif n == 14:
print('fourteen')
elif n == 15:
print('fifteen')
elif n == 16:
print('sixteen')
elif n == 17:
print('seventeen')
elif n == 18:
print('eighteen')
elif n == 19:
print('nineteen')
else:
if n // 10 == 2:
res = 'twenty'
elif n // 10 == 3:
res = 'thirty'
elif n // 10 == 4:
res = 'forty'
elif n // 10 == 5:
res = 'fifty'
elif n // 10 == 6:
res = 'sixty'
elif n // 10 == 7:
res = 'seventy'
elif n // 10 == 8:
res = 'eighty'
elif n // 10 == 9:
res = 'ninety'
if n % 10 == 1:
res += '-one'
elif n % 10 == 2:
res += '-two'
elif n % 10 == 3:
res += '-three'
elif n % 10 == 4:
res += '-four'
elif n % 10 == 5:
res += '-five'
elif n % 10 == 6:
res += '-six'
elif n % 10 == 7:
res += '-seven'
elif n % 10 == 8:
res += '-eight'
elif n % 10 == 9:
res += '-nine'
print(res)
``` | {
"language": "python",
"test_cases": [
{
"input": "6\n",
"output": "six\n",
"type": "stdin_stdout"
},
{
"input": "99\n",
"output": "ninety-nine\n",
"type": "stdin_stdout"
},
{
"input": "20\n",
"output": "twenty\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "ten\n",
"type": "stdin_stdout"
},
{
"input": "15\n",
"output": "fifteen\n",
"type": "stdin_stdout"
},
{
"input": "27\n",
"output": "twenty-seven\n",
"type": "stdin_stdout"
},
{
"input": "40\n",
"output": "forty\n",
"type": "stdin_stdout"
},
{
"input": "63\n",
"output": "sixty-three\n",
"type": "stdin_stdout"
},
{
"input": "0\n",
"output": "zero\n",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "one\n",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "two\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "eight\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "nine\n",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "eleven\n",
"type": "stdin_stdout"
},
{
"input": "12\n",
"output": "twelve\n",
"type": "stdin_stdout"
},
{
"input": "13\n",
"output": "thirteen\n",
"type": "stdin_stdout"
},
{
"input": "14\n",
"output": "fourteen\n",
"type": "stdin_stdout"
},
{
"input": "16\n",
"output": "sixteen\n",
"type": "stdin_stdout"
},
{
"input": "17\n",
"output": "seventeen\n",
"type": "stdin_stdout"
},
{
"input": "18\n",
"output": "eighteen\n",
"type": "stdin_stdout"
},
{
"input": "19\n",
"output": "nineteen\n",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "twenty-one\n",
"type": "stdin_stdout"
},
{
"input": "29\n",
"output": "twenty-nine\n",
"type": "stdin_stdout"
},
{
"input": "30\n",
"output": "thirty\n",
"type": "stdin_stdout"
},
{
"input": "32\n",
"output": "thirty-two\n",
"type": "stdin_stdout"
},
{
"input": "38\n",
"output": "thirty-eight\n",
"type": "stdin_stdout"
},
{
"input": "43\n",
"output": "forty-three\n",
"type": "stdin_stdout"
},
{
"input": "47\n",
"output": "forty-seven\n",
"type": "stdin_stdout"
},
{
"input": "50\n",
"output": "fifty\n",
"type": "stdin_stdout"
},
{
"input": "54\n",
"output": "fifty-four\n",
"type": "stdin_stdout"
},
{
"input": "56\n",
"output": "fifty-six\n",
"type": "stdin_stdout"
},
{
"input": "60\n",
"output": "sixty\n",
"type": "stdin_stdout"
},
{
"input": "66\n",
"output": "sixty-six\n",
"type": "stdin_stdout"
},
{
"input": "70\n",
"output": "seventy\n",
"type": "stdin_stdout"
},
{
"input": "76\n",
"output": "seventy-six\n",
"type": "stdin_stdout"
},
{
"input": "80\n",
"output": "eighty\n",
"type": "stdin_stdout"
},
{
"input": "82\n",
"output": "eighty-two\n",
"type": "stdin_stdout"
},
{
"input": "90\n",
"output": "ninety\n",
"type": "stdin_stdout"
},
{
"input": "91\n",
"output": "ninety-one\n",
"type": "stdin_stdout"
},
{
"input": "95\n",
"output": "ninety-five\n",
"type": "stdin_stdout"
},
{
"input": "71\n",
"output": "seventy-one\n",
"type": "stdin_stdout"
},
{
"input": "46\n",
"output": "forty-six\n",
"type": "stdin_stdout"
},
{
"input": "84\n",
"output": "eighty-four\n",
"type": "stdin_stdout"
},
{
"input": "22\n",
"output": "twenty-two\n",
"type": "stdin_stdout"
},
{
"input": "23\n",
"output": "twenty-three\n",
"type": "stdin_stdout"
},
{
"input": "24\n",
"output": "twenty-four\n",
"type": "stdin_stdout"
},
{
"input": "25\n",
"output": "twenty-five\n",
"type": "stdin_stdout"
},
{
"input": "26\n",
"output": "twenty-six\n",
"type": "stdin_stdout"
},
{
"input": "28\n",
"output": "twenty-eight\n",
"type": "stdin_stdout"
},
{
"input": "31\n",
"output": "thirty-one\n",
"type": "stdin_stdout"
},
{
"input": "33\n",
"output": "thirty-three\n",
"type": "stdin_stdout"
},
{
"input": "34\n",
"output": "thirty-four\n",
"type": "stdin_stdout"
},
{
"input": "35\n",
"output": "thirty-five\n",
"type": "stdin_stdout"
},
{
"input": "36\n",
"output": "thirty-six\n",
"type": "stdin_stdout"
},
{
"input": "37\n",
"output": "thirty-seven\n",
"type": "stdin_stdout"
},
{
"input": "39\n",
"output": "thirty-nine\n",
"type": "stdin_stdout"
},
{
"input": "65\n",
"output": "sixty-five\n",
"type": "stdin_stdout"
},
{
"input": "68\n",
"output": "sixty-eight\n",
"type": "stdin_stdout"
},
{
"input": "41\n",
"output": "forty-one\n",
"type": "stdin_stdout"
},
{
"input": "42\n",
"output": "forty-two\n",
"type": "stdin_stdout"
},
{
"input": "44\n",
"output": "forty-four\n",
"type": "stdin_stdout"
},
{
"input": "45\n",
"output": "forty-five\n",
"type": "stdin_stdout"
},
{
"input": "48\n",
"output": "forty-eight\n",
"type": "stdin_stdout"
},
{
"input": "49\n",
"output": "forty-nine\n",
"type": "stdin_stdout"
},
{
"input": "51\n",
"output": "fifty-one\n",
"type": "stdin_stdout"
},
{
"input": "52\n",
"output": "fifty-two\n",
"type": "stdin_stdout"
},
{
"input": "53\n",
"output": "fifty-three\n",
"type": "stdin_stdout"
},
{
"input": "55\n",
"output": "fifty-five\n",
"type": "stdin_stdout"
},
{
"input": "57\n",
"output": "fifty-seven\n",
"type": "stdin_stdout"
},
{
"input": "58\n",
"output": "fifty-eight\n",
"type": "stdin_stdout"
},
{
"input": "59\n",
"output": "fifty-nine\n",
"type": "stdin_stdout"
},
{
"input": "61\n",
"output": "sixty-one\n",
"type": "stdin_stdout"
},
{
"input": "62\n",
"output": "sixty-two\n",
"type": "stdin_stdout"
},
{
"input": "64\n",
"output": "sixty-four\n",
"type": "stdin_stdout"
},
{
"input": "67\n",
"output": "sixty-seven\n",
"type": "stdin_stdout"
},
{
"input": "69\n",
"output": "sixty-nine\n",
"type": "stdin_stdout"
},
{
"input": "72\n",
"output": "seventy-two\n",
"type": "stdin_stdout"
},
{
"input": "73\n",
"output": "seventy-three\n",
"type": "stdin_stdout"
},
{
"input": "74\n",
"output": "seventy-four\n",
"type": "stdin_stdout"
},
{
"input": "75\n",
"output": "seventy-five\n",
"type": "stdin_stdout"
},
{
"input": "77\n",
"output": "seventy-seven\n",
"type": "stdin_stdout"
},
{
"input": "78\n",
"output": "seventy-eight\n",
"type": "stdin_stdout"
},
{
"input": "79\n",
"output": "seventy-nine\n",
"type": "stdin_stdout"
},
{
"input": "81\n",
"output": "eighty-one\n",
"type": "stdin_stdout"
},
{
"input": "83\n",
"output": "eighty-three\n",
"type": "stdin_stdout"
},
{
"input": "85\n",
"output": "eighty-five\n",
"type": "stdin_stdout"
},
{
"input": "86\n",
"output": "eighty-six\n",
"type": "stdin_stdout"
},
{
"input": "87\n",
"output": "eighty-seven\n",
"type": "stdin_stdout"
},
{
"input": "88\n",
"output": "eighty-eight\n",
"type": "stdin_stdout"
},
{
"input": "89\n",
"output": "eighty-nine\n",
"type": "stdin_stdout"
},
{
"input": "92\n",
"output": "ninety-two\n",
"type": "stdin_stdout"
},
{
"input": "93\n",
"output": "ninety-three\n",
"type": "stdin_stdout"
},
{
"input": "94\n",
"output": "ninety-four\n",
"type": "stdin_stdout"
},
{
"input": "96\n",
"output": "ninety-six\n",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "seven\n",
"type": "stdin_stdout"
},
{
"input": "97\n",
"output": "ninety-seven\n",
"type": "stdin_stdout"
},
{
"input": "98\n",
"output": "ninety-eight\n",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "three\n",
"type": "stdin_stdout"
},
{
"input": "4\n",
"output": "four\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "five\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/535/A"
} | vfc_10162 |
apps | verifiable_code | 103 | Solve the following coding problem using the programming language python:
JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array $a_1$, $a_2$, ..., $a_n$ of integers, such that $1 \le a_1 < a_2 < \ldots < a_n \le 10^3$, and then went to the bathroom.
JATC decided to prank his friend by erasing some consecutive elements in the array. Since he doesn't want for the prank to go too far, he will only erase in a way, such that Giraffe can still restore the array using the information from the remaining elements. Because Giraffe has created the array, he's also aware that it's an increasing array and all the elements are integers in the range $[1, 10^3]$.
JATC wonders what is the greatest number of elements he can erase?
-----Input-----
The first line of the input contains a single integer $n$ ($1 \le n \le 100$) — the number of elements in the array.
The second line of the input contains $n$ integers $a_i$ ($1 \le a_1<a_2<\dots<a_n \le 10^3$) — the array written by Giraffe.
-----Output-----
Print a single integer — the maximum number of consecutive elements in the array that JATC can erase.
If it is impossible to erase even a single element, print $0$.
-----Examples-----
Input
6
1 3 4 5 6 9
Output
2
Input
3
998 999 1000
Output
2
Input
5
1 2 3 4 5
Output
4
-----Note-----
In the first example, JATC can erase the third and fourth elements, leaving the array $[1, 3, \_, \_, 6, 9]$. As you can see, there is only one way to fill in the blanks.
In the second example, JATC can erase the second and the third elements. The array will become $[998, \_, \_]$. Because all the elements are less than or equal to $1000$, the array is still can be restored. Note, that he can't erase the first $2$ elements.
In the third example, JATC can erase the first $4$ elements. Since all the elements are greater than or equal to $1$, Giraffe can still restore the array. Note, that he can't erase the last $4$ elements.
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 = [0] + list(map(int, input().split())) + [1001]
mx = 1
p = 1
for i in range(1, n + 2):
if a[i] == a[i - 1] + 1:
p += 1
mx = max(p, mx)
else:
p = 1
print(max(0, mx - 2))
``` | {
"language": "python",
"test_cases": [
{
"input": "6\n1 3 4 5 6 9\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "3\n998 999 1000\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 3 4 5\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "1\n1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "2\n999 1000\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "9\n1 4 5 6 7 100 101 102 103\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "100\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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n",
"output": "99",
"type": "stdin_stdout"
},
{
"input": "8\n6 8 9 11 14 18 19 20\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "2\n1 7\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1\n779\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5\n3 8 25 37 43\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "73\n38 45 46 95 98 99 103 157 164 175 184 193 208 251 258 276 279 282 319 329 336 344 349 419 444 452 490 499 507 508 519 542 544 553 562 576 579 590 594 603 634 635 648 659 680 686 687 688 695 698 743 752 757 774 776 779 792 809 860 879 892 911 918 927 928 945 947 951 953 958 959 960 983\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "15\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n",
"output": "14",
"type": "stdin_stdout"
},
{
"input": "63\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\n",
"output": "62",
"type": "stdin_stdout"
},
{
"input": "100\n252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 409 410 425 426 604 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895\n",
"output": "70",
"type": "stdin_stdout"
},
{
"input": "95\n34 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 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 911 912 913\n",
"output": "35",
"type": "stdin_stdout"
},
{
"input": "90\n126 239 240 241 242 253 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 600 601 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 934 935\n",
"output": "44",
"type": "stdin_stdout"
},
{
"input": "85\n52 53 54 55 56 57 58 59 60 61 62 63 64 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 333 334 453 454 455 456 457 458 459 460 461 462 463 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624\n",
"output": "23",
"type": "stdin_stdout"
},
{
"input": "80\n237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 408 409 410 411 412 413 414 415 416 417 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985\n",
"output": "25",
"type": "stdin_stdout"
},
{
"input": "70\n72 73 74 75 76 77 78 79 80 81 82 354 355 356 357 358 359 360 361 362 363 364 365 366 367 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 764 765 766 767 768 769 770 794 795 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826\n",
"output": "19",
"type": "stdin_stdout"
},
{
"input": "75\n327 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653\n",
"output": "72",
"type": "stdin_stdout"
},
{
"input": "60\n12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 134 135 136 137 353 354 355 356 357 358 359 360 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815\n",
"output": "24",
"type": "stdin_stdout"
},
{
"input": "65\n253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 533 614 615 864\n",
"output": "59",
"type": "stdin_stdout"
},
{
"input": "55\n67 68 69 70 160 161 162 163 164 165 166 167 168 169 170 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 960\n",
"output": "21",
"type": "stdin_stdout"
},
{
"input": "50\n157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 632 633 634 635 636 637 638\n",
"output": "20",
"type": "stdin_stdout"
},
{
"input": "45\n145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 333 334 831 832 978 979 980 981\n",
"output": "35",
"type": "stdin_stdout"
},
{
"input": "100\n901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000\n",
"output": "99",
"type": "stdin_stdout"
},
{
"input": "10\n1 2 3 4 5 6 7 8 9 10\n",
"output": "9",
"type": "stdin_stdout"
},
{
"input": "10\n991 992 993 994 995 996 997 998 999 1000\n",
"output": "9",
"type": "stdin_stdout"
},
{
"input": "39\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\n",
"output": "38",
"type": "stdin_stdout"
},
{
"input": "42\n959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000\n",
"output": "41",
"type": "stdin_stdout"
},
{
"input": "100\n144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 198 199 200 201 202 203 204 205 206 207 208 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 376 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 904 905 997\n",
"output": "16",
"type": "stdin_stdout"
},
{
"input": "95\n9 10 11 12 13 134 271 272 273 274 275 276 277 278 290 291 292 293 294 295 296 297 298 299 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 620 621 622 623 624 625 626 627 628 629 630 631 632 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 952\n",
"output": "20",
"type": "stdin_stdout"
},
{
"input": "90\n20 21 22 23 24 25 56 57 58 59 60 61 62 63 64 84 85 404 405 406 407 408 409 410 420 421 422 423 424 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 491 492 588 589 590 652 653 654 655 656 657 754 755 756 757 758 759 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 982 983 984 985 986 987 988 989 990 991 992 995\n",
"output": "15",
"type": "stdin_stdout"
},
{
"input": "85\n40 41 42 43 44 69 70 71 72 73 305 306 307 308 309 333 334 335 336 337 338 339 340 341 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 717 718 719 720 721 862 863 864 865 866 867 868 869 870 871 872 873 874 945 946 947 948 949 950\n",
"output": "18",
"type": "stdin_stdout"
},
{
"input": "80\n87 88 89 90 91 92 93 94 95 96 97 98 99 173 174 175 176 177 178 179 180 184 185 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 550 551 552 553 554 555 650 702 703 704 705 706 707 708 709 710 727 728 729 730 731 798 799 800 831 832 833 869 870 980 981 982 983 984 985 986 987 988 989 990 991 992\n",
"output": "13",
"type": "stdin_stdout"
},
{
"input": "1\n1000\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2\n998 999\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "2\n3 4\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3\n9 10 11\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "6\n4 5 6 7 8 9\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "5\n5 6 7 8 9\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "8\n1 2 5 6 7 8 9 11\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 3 6\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 3 66\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "7\n1 2 5 6 7 8 9\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "2\n2 4\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "8\n1 2 5 6 7 8 9 1000\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "2\n1 1000\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "4\n3 4 5 6\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "5\n2 3 4 5 6\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "6\n1 2 3 4 5 7\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "6\n1 996 997 998 999 1000\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 3 4 6\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "6\n1 2 3 5 6 7\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "3\n3 4 5\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "1\n5\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3\n2 3 4\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "7\n1 3 5 997 998 999 1000\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "4\n3 4 5 10\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "3\n997 998 999\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "7\n1 2 3 4 6 7 8\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "2\n2 3\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "7\n2 3 4 6 997 998 999\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "1\n2\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3\n4 5 6\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "2\n5 6\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "7\n1 2 3 997 998 999 1000\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "4\n1 3 999 1000\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "5\n1 3 5 7 9\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "6\n1 2 3 4 5 10\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 999 1000\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "2\n10 20\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "5\n2 3 4 5 10\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "4\n2 3 4 5\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "42\n35 145 153 169 281 292 299 322 333 334 358 382 391 421 436 447 464 467 478 491 500 538 604 667 703 705 716 718 724 726 771 811 827 869 894 895 902 912 942 961 962 995\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3\n10 11 12\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "7\n1 2 3 4 6 9 18\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 3 4 800\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 3 4 1000\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "5\n1 997 998 999 1000\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "6\n1 2 6 7 8 9\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 3 5\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "9\n1 2 3 7 8 9 10 11 13\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 5 6\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "6\n1 2 5 6 7 8\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 3 999 1000\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "100\n656 658 660 662 664 666 668 670 672 674 676 678 680 682 684 686 688 690 692 694 696 698 700 702 704 706 708 710 712 714 716 718 720 722 724 726 728 730 732 734 736 738 740 742 744 746 748 750 752 754 756 758 760 762 764 766 768 770 772 774 776 778 780 782 784 786 788 790 792 794 796 798 800 802 804 806 808 810 812 814 816 818 820 822 824 826 828 830 832 834 836 838 840 842 844 848 850 852 999 1000\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "3\n1 2 9\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "8\n2 3 4 5 997 998 999 1000\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "9\n1 2 3 4 6 7 9 10 12\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 7 8\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "3\n1 2 5\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 998 999 1000\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 3 7\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "7\n2 4 6 997 998 999 1000\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 3 5 6\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "6\n3 4 5 998 999 1000\n",
"output": "2",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1062/A"
} | vfc_10166 |
apps | verifiable_code | 104 | Solve the following coding problem using the programming language python:
Polycarp has created his own training plan to prepare for the programming contests. He will train for $n$ days, all days are numbered from $1$ to $n$, beginning from the first.
On the $i$-th day Polycarp will necessarily solve $a_i$ problems. One evening Polycarp plans to celebrate the equator. He will celebrate it on the first evening of such a day that from the beginning of the training and to this day inclusive he will solve half or more of all the problems.
Determine the index of day when Polycarp will celebrate the equator.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 200\,000$) — the number of days to prepare for the programming contests.
The second line contains a sequence $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10\,000$), where $a_i$ equals to the number of problems, which Polycarp will solve on the $i$-th day.
-----Output-----
Print the index of the day when Polycarp will celebrate the equator.
-----Examples-----
Input
4
1 3 2 1
Output
2
Input
6
2 2 2 2 2 2
Output
3
-----Note-----
In the first example Polycarp will celebrate the equator on the evening of the second day, because up to this day (inclusive) he will solve $4$ out of $7$ scheduled problems on four days of the training.
In the second example Polycarp will celebrate the equator on the evening of the third day, because up to this day (inclusive) he will solve $6$ out of $12$ scheduled problems on six days of the training.
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 = int(input())
a = list(int(x) for x in input().split())
s = sum(a)
t = 0
for i in range(n):
t += a[i]
if 2 * t >= s:
print(i + 1)
return
main()
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n1 3 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 2 2 2 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n10000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 1 1 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 4 3 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 2 2 4 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\n7 3 10 7 3 11\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 1 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 3 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n32 10 23\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7\n1 1 1 1 1 1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\n3 3 3 2 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "9\n1 1 1 1 1 1 1 1 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 3 3 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 1 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 3 3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 2 3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2\n6 7\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 3 4 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 2 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 8 7 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 2 2 2 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 2 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 2 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5\n9 5 3 4 8\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 3 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 3 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 3 6\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 2 1 1 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 1 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 4 5 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 1 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 1 2 5 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 1 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 6 1 10\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 3 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 2 2 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 1 1 1 1 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 3 5 1 7 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 4 8 16\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 4 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "6\n4 2 1 2 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 2 1 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 4 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 1 1 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 1 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 3 7\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 4 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 1 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 5\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 1 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 3 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 1 4 1 1 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 2 2 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 1 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 2 3 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 1 1 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 4 1 4 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 3 1 6\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 1 2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 4 2 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 4 5 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 1 1 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 3 4 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 3 2 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 2 1 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 3 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n6 5 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "69\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\n",
"output": "35\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 1 1 1 1 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 5 4 5\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "2\n9 10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 4 3 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 4 3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n7 1 3 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n100 100 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n5 2 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/962/A"
} | vfc_10170 |
apps | verifiable_code | 105 | Solve the following coding problem using the programming language python:
You stumbled upon a new kind of chess puzzles. The chessboard you are given is not necesserily $8 \times 8$, but it still is $N \times N$. Each square has some number written on it, all the numbers are from $1$ to $N^2$ and all the numbers are pairwise distinct. The $j$-th square in the $i$-th row has a number $A_{ij}$ written on it.
In your chess set you have only three pieces: a knight, a bishop and a rook. At first, you put one of them on the square with the number $1$ (you can choose which one). Then you want to reach square $2$ (possibly passing through some other squares in process), then square $3$ and so on until you reach square $N^2$. In one step you are allowed to either make a valid move with the current piece or replace it with some other piece. Each square can be visited arbitrary number of times.
A knight can move to a square that is two squares away horizontally and one square vertically, or two squares vertically and one square horizontally. A bishop moves diagonally. A rook moves horizontally or vertically. The move should be performed to a different square from the one a piece is currently standing on.
You want to minimize the number of steps of the whole traversal. Among all the paths to have the same number of steps you want to choose the one with the lowest number of piece replacements.
What is the path you should take to satisfy all conditions?
-----Input-----
The first line contains a single integer $N$ ($3 \le N \le 10$) — the size of the chessboard.
Each of the next $N$ lines contains $N$ integers $A_{i1}, A_{i2}, \dots, A_{iN}$ ($1 \le A_{ij} \le N^2$) — the numbers written on the squares of the $i$-th row of the board.
It is guaranteed that all $A_{ij}$ are pairwise distinct.
-----Output-----
The only line should contain two integers — the number of steps in the best answer and the number of replacement moves in it.
-----Example-----
Input
3
1 9 3
8 6 7
4 2 5
Output
12 1
-----Note-----
Here are the steps for the first example (the starting piece is a knight): Move to $(3, 2)$ Move to $(1, 3)$ Move to $(3, 2)$ Replace the knight with a rook Move to $(3, 1)$ Move to $(3, 3)$ Move to $(3, 2)$ Move to $(2, 2)$ Move to $(2, 3)$ Move to $(2, 1)$ Move to $(1, 1)$ Move to $(1, 2)$
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())
graph=[{},{},{}]
for i in range(n):
for j in range(n):
graph[0][(i,j)]=[(k,j) for k in range(n)]+[(i,k) for k in range(n)]
graph[0][(i,j)].remove((i,j))
graph[0][(i,j)].remove((i,j))
graph[1][(i,j)]=[]
for k in range(n):
for l in range(n):
if abs(k-i)==abs(l-j)!=0:
graph[1][(i,j)].append((k,l))
graph[2][(i,j)]=[]
for k in range(n):
for l in range(n):
if {abs(k-i),abs(l-j)}=={1,2}:
graph[2][(i,j)].append((k,l))
dists=[[{},{},{}],[{},{},{}],[{},{},{}]]
for i in range(n):
for j in range(n):
for k in range(3):
dists[k][k][(i,j,i,j)]=0
for i in range(n):
for j in range(n):
for k in range(3):
layers=[[(i,j,k,0)],[],[],[],[]]
for l in range(4):
for guy in layers[l]:
for m in range(3):
if m!=guy[2]:
if (i,j,guy[0],guy[1]) not in dists[k][m]:
layers[l+1].append((guy[0],guy[1],m,guy[3]+1))
dists[k][m][(i,j,guy[0],guy[1])]=1000*(l+1)+guy[3]+1
for boi in graph[guy[2]][(guy[0],guy[1])]:
if (i,j,boi[0],boi[1]) not in dists[k][guy[2]]:
layers[l+1].append((boi[0],boi[1],guy[2],guy[3]))
dists[k][guy[2]][(i,j,boi[0],boi[1])]=1000*(l+1)+guy[3]
elif 1000*(l+1)+guy[3]<dists[k][guy[2]][(i,j,boi[0],boi[1])]:
layers[l+1].append((boi[0],boi[1],guy[2],guy[3]))
dists[k][guy[2]][(i,j,boi[0],boi[1])]=1000*(l+1)+guy[3]
locs=[None]*(n**2)
for i in range(n):
a=list(map(int,input().split()))
for j in range(n):
locs[a[j]-1]=(i,j)
best=(0,0,0)
for i in range(n**2-1):
tup=(locs[i][0],locs[i][1],locs[i+1][0],locs[i+1][1])
new0=min(best[0]+dists[0][0][tup],best[1]+dists[1][0][tup],best[2]+dists[2][0][tup])
new1=min(best[0]+dists[0][1][tup],best[1]+dists[1][1][tup],best[2]+dists[2][1][tup])
new2=min(best[0]+dists[0][2][tup],best[1]+dists[1][2][tup],best[2]+dists[2][2][tup])
best=(new0,new1,new2)
a=min(best)
print(a//1000,a%1000)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n1 9 3\n8 6 7\n4 2 5\n",
"output": "12 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 5 8\n9 2 4\n3 6 7\n",
"output": "12 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n5 4 1 13\n8 3 6 16\n15 9 14 12\n11 2 7 10\n",
"output": "23 0\n",
"type": "stdin_stdout"
},
{
"input": "5\n21 14 2 3 12\n19 8 16 18 7\n9 17 10 15 4\n24 5 1 23 11\n25 13 22 6 20\n",
"output": "38 2\n",
"type": "stdin_stdout"
},
{
"input": "6\n8 3 15 14 29 17\n27 11 16 21 18 28\n34 23 36 12 10 5\n30 31 25 6 9 2\n7 24 13 1 35 4\n19 26 33 32 20 22\n",
"output": "60 0\n",
"type": "stdin_stdout"
},
{
"input": "7\n21 41 30 10 28 4 45\n22 27 20 39 18 5 9\n31 6 35 46 32 16 38\n44 15 12 37 1 42 19\n29 3 23 24 40 7 14\n49 11 36 34 17 8 2\n13 33 43 47 48 25 26\n",
"output": "84 3\n",
"type": "stdin_stdout"
},
{
"input": "8\n22 43 26 64 19 50 3 46\n6 33 36 63 31 55 28 37\n11 34 51 10 12 56 59 29\n32 1 58 42 23 61 44 24\n30 41 20 27 45 16 25 13\n2 35 47 4 52 40 17 62\n49 7 15 48 54 60 57 9\n18 38 53 14 21 39 5 8\n",
"output": "113 0\n",
"type": "stdin_stdout"
},
{
"input": "9\n15 12 75 35 19 81 7 74 49\n63 26 6 67 25 14 22 69 76\n21 78 20 45 40 41 24 16 42\n13 73 1 28 33 38 5 17 39\n23 64 47 52 68 57 53 30 18\n65 34 8 2 9 59 51 79 77\n36 80 4 48 61 72 70 50 71\n46 32 27 60 44 55 11 29 3\n56 31 66 62 43 10 58 37 54\n",
"output": "144 2\n",
"type": "stdin_stdout"
},
{
"input": "10\n72 53 8 38 4 41 42 22 17 30\n79 49 5 29 85 11 87 66 63 47\n90 34 44 10 70 15 69 56 27 98\n46 86 80 78 75 19 18 81 32 83\n3 77 92 7 37 36 93 94 62 20\n55 61 35 31 57 39 40 50 73 12\n13 16 97 52 51 6 99 24 58 64\n48 74 59 28 14 21 23 1 96 100\n65 33 89 25 71 82 84 60 43 54\n45 68 88 76 26 67 91 2 9 95\n",
"output": "181 0\n",
"type": "stdin_stdout"
},
{
"input": "10\n43 36 17 45 27 85 97 82 92 71\n55 40 81 19 39 46 89 70 63 62\n61 53 6 30 12 4 21 59 67 87\n79 24 14 33 16 95 41 37 50 65\n11 83 69 35 8 96 22 93 9 100\n99 34 28 75 72 25 47 7 74 15\n52 49 31 88 3 68 23 51 57 78\n38 94 42 86 98 76 54 80 20 5\n84 73 29 90 60 64 10 77 18 48\n2 66 44 91 32 1 26 58 13 56\n",
"output": "186 0\n",
"type": "stdin_stdout"
},
{
"input": "10\n59 35 29 81 51 46 27 32 42 53\n48 80 96 92 26 84 22 18 63 34\n98 75 58 74 3 60 78 36 20 73\n67 2 30 49 99 1 24 13 86 89\n52 33 83 37 5 71 43 6 93 87\n17 9 7 62 31 56 90 44 69 12\n4 40 16 66 15 23 82 11 94 68\n100 70 64 14 79 41 10 76 97 91\n28 88 85 38 25 47 61 95 65 8\n77 55 45 50 21 39 72 19 54 57\n",
"output": "182 4\n",
"type": "stdin_stdout"
},
{
"input": "10\n1 51 23 18 72 5 69 20 48 42\n25 88 50 70 16 79 12 61 99 8\n38 13 62 2 28 34 29 9 59 17\n33 44 67 77 78 84 52 11 39 27\n100 95 82 83 68 7 46 6 43 35\n53 93 21 97 76 26 80 36 22 10\n81 56 87 89 98 32 3 90 15 37\n54 92 60 85 65 30 96 14 55 58\n86 40 19 47 31 41 45 91 64 73\n74 24 94 66 75 57 4 49 63 71\n",
"output": "182 0\n",
"type": "stdin_stdout"
},
{
"input": "10\n68 59 99 60 26 91 76 41 42 75\n12 15 21 19 84 10 5 73 63 46\n82 94 51 40 34 58 50 2 88 30\n28 55 47 3 64 79 86 92 53 36\n90 44 72 96 65 83 61 54 48 38\n67 81 93 31 52 98 77 6 24 45\n8 100 33 14 85 22 9 27 29 49\n78 66 74 1 87 70 39 57 35 4\n69 32 11 16 56 71 89 20 13 7\n18 37 17 95 97 25 80 62 43 23\n",
"output": "183 0\n",
"type": "stdin_stdout"
},
{
"input": "10\n54 98 92 77 64 43 40 33 87 72\n96 17 61 91 9 49 20 37 6 63\n89 23 2 68 57 19 81 78 47 75\n60 100 38 84 80 12 15 18 50 30\n35 3 14 83 65 94 95 10 29 41\n56 52 93 21 39 85 4 27 55 74\n26 53 51 31 8 44 32 69 70 97\n66 42 22 5 36 59 46 82 86 76\n62 28 34 45 79 99 25 16 48 11\n90 58 67 1 88 13 24 7 73 71\n",
"output": "179 0\n",
"type": "stdin_stdout"
},
{
"input": "10\n50 20 11 95 73 25 2 54 18 29\n42 57 22 84 69 53 4 63 81 36\n87 91 23 90 17 47 77 19 58 41\n37 16 28 31 12 6 55 32 64 46\n26 96 38 89 97 30 98 85 33 75\n60 9 100 93 34 82 35 62 3 5\n92 49 76 78 88 40 14 52 94 99\n8 24 27 68 43 56 71 15 66 80\n48 45 10 1 74 21 79 72 86 13\n39 44 67 7 70 61 83 65 59 51\n",
"output": "184 0\n",
"type": "stdin_stdout"
},
{
"input": "10\n21 2 68 53 5 67 38 44 10 96\n18 50 80 11 76 57 48 75 24 39\n16 78 100 15 46 36 23 30 31 62\n91 82 84 87 74 59 3 51 85 56\n79 19 73 52 37 12 83 1 65 9\n77 17 95 99 93 29 4 88 40 42\n60 6 71 61 32 92 89 28 25 64\n33 69 34 35 81 54 49 41 45 14\n63 20 27 13 8 97 90 22 58 26\n98 70 94 43 55 66 86 72 7 47\n",
"output": "180 0\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 4 7\n6 9 2\n3 8 5\n",
"output": "9 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 3 4\n6 7 8 5\n10 11 9 12\n16 14 15 13\n",
"output": "15 0\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 6 3\n7 2 9\n4 8 5\n",
"output": "11 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 6 3\n4 9 8\n7 2 5\n",
"output": "9 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 14 8 9\n13 2 11 5\n7 12 3 15\n10 6 16 4\n",
"output": "18 2\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 36 31 24 21 8\n32 25 20 9 14 23\n35 30 33 22 7 10\n26 19 28 13 4 15\n29 34 17 6 11 2\n18 27 12 3 16 5\n",
"output": "37 0\n",
"type": "stdin_stdout"
},
{
"input": "10\n38 18 27 74 94 4 45 82 83 88\n73 95 50 40 28 59 47 19 58 60\n23 75 14 22 97 81 3 85 87 6\n56 80 30 62 57 90 5 41 69 44\n72 46 70 32 11 76 91 1 77 17\n52 99 12 37 79 2 43 9 13 53\n93 63 42 35 89 29 61 26 16 68\n51 49 78 34 100 96 92 65 25 33\n8 36 7 86 20 15 54 24 21 67\n84 98 39 64 66 31 10 55 48 71\n",
"output": "180 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n8 6 3\n9 1 5\n2 4 7\n",
"output": "13 2\n",
"type": "stdin_stdout"
},
{
"input": "10\n26 39 19 58 17 41 57 70 94 64\n72 22 8 42 37 27 100 86 7 60\n81 11 65 56 24 55 6 50 85 47\n68 49 79 18 34 99 92 89 76 38\n30 29 96 16 80 44 20 98 23 43\n33 12 93 53 69 3 83 14 54 61\n4 52 13 74 84 63 1 46 88 36\n90 28 67 10 82 73 5 2 95 75\n21 66 9 51 32 35 59 77 62 97\n15 25 48 45 40 71 87 31 78 91\n",
"output": "183 8\n",
"type": "stdin_stdout"
},
{
"input": "10\n17 5 40 44 52 45 36 27 84 61\n51 81 68 16 46 66 72 18 87 62\n93 30 9 13 60 43 50 4 39 32\n26 21 70 79 15 22 98 65 49 37\n59 78 76 92 35 58 67 74 14 8\n77 7 20 29 97 19 25 47 73 89\n33 82 64 83 12 3 24 95 86 28\n38 63 100 54 80 2 88 48 56 90\n71 31 34 75 57 69 42 1 94 96\n10 55 53 6 91 41 11 85 23 99\n",
"output": "183 3\n",
"type": "stdin_stdout"
},
{
"input": "10\n82 44 24 63 13 50 45 23 85 100\n59 64 10 19 35 96 47 17 87 6\n76 7 62 53 37 30 36 91 75 89\n1 25 73 49 18 28 61 27 90 8\n83 79 34 71 31 67 16 12 99 74\n29 58 48 84 39 43 88 98 3 21\n55 4 42 32 86 60 11 68 51 65\n69 33 22 77 95 97 93 9 94 5\n70 38 2 46 56 14 52 66 54 81\n26 57 20 40 92 78 41 72 80 15\n",
"output": "181 7\n",
"type": "stdin_stdout"
},
{
"input": "5\n7 21 10 4 9\n20 19 8 25 23\n22 18 3 15 12\n17 2 16 6 13\n1 14 5 11 24\n",
"output": "39 4\n",
"type": "stdin_stdout"
},
{
"input": "10\n39 77 100 53 79 23 45 90 17 30\n24 81 13 88 25 38 50 59 96 92\n47 82 44 28 93 6 84 5 71 11\n60 91 40 36 69 9 66 8 21 10\n32 55 57 63 41 14 48 34 75 95\n70 2 56 16 61 51 58 42 73 85\n89 76 7 54 4 62 35 83 12 43\n20 18 27 94 68 72 97 37 22 26\n15 33 3 31 80 86 78 98 74 64\n99 65 1 49 19 67 46 29 87 52\n",
"output": "180 5\n",
"type": "stdin_stdout"
},
{
"input": "10\n27 97 45 79 41 21 15 7 12 9\n98 13 44 10 64 69 48 76 50 84\n22 80 36 17 99 6 91 40 62 11\n83 77 23 92 74 72 85 2 95 82\n87 70 57 32 29 4 33 52 58 67\n19 34 65 16 56 28 42 93 86 25\n49 3 47 31 66 53 43 54 35 1\n94 63 51 55 18 39 14 71 5 26\n59 68 30 37 46 89 20 78 96 100\n75 38 81 61 90 8 60 88 73 24\n",
"output": "185 0\n",
"type": "stdin_stdout"
},
{
"input": "4\n16 9 13 14\n10 6 12 5\n3 11 1 7\n8 15 4 2\n",
"output": "24 3\n",
"type": "stdin_stdout"
},
{
"input": "8\n11 14 57 6 54 50 37 19\n43 52 18 56 39 58 34 29\n61 9 5 26 30 23 20 2\n38 64 36 25 27 12 33 55\n46 15 22 31 53 28 44 63\n59 62 42 21 32 8 40 35\n45 48 16 17 3 4 24 51\n60 7 41 13 10 49 1 47\n",
"output": "114 4\n",
"type": "stdin_stdout"
},
{
"input": "10\n12 32 66 82 62 55 25 52 20 51\n86 72 19 22 57 61 23 98 44 97\n16 96 3 5 6 9 64 43 48 89\n73 67 56 28 59 38 42 34 7 17\n14 80 31 95 39 79 47 13 93 92\n71 74 50 27 33 41 30 49 69 18\n11 36 10 8 90 53 81 65 26 84\n85 58 91 46 15 29 70 1 2 37\n40 24 99 21 87 63 35 94 88 78\n83 45 54 75 4 77 68 100 60 76\n",
"output": "176 6\n",
"type": "stdin_stdout"
},
{
"input": "10\n41 28 85 73 76 5 87 47 38 31\n3 50 32 12 27 14 21 48 15 64\n68 24 34 1 86 40 49 80 62 45\n10 92 77 95 63 44 98 25 20 81\n53 56 93 94 70 89 65 42 61 90\n100 75 52 13 16 18 30 8 23 88\n69 91 46 71 79 36 99 83 58 59\n33 67 17 60 19 54 26 29 11 55\n84 2 7 57 72 82 51 6 35 66\n74 97 78 37 96 39 43 4 9 22\n",
"output": "181 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n15 5 8 16\n9 11 1 12\n14 13 3 7\n4 10 6 2\n",
"output": "22 3\n",
"type": "stdin_stdout"
},
{
"input": "10\n95 86 24 16 55 13 6 28 42 71\n34 80 1 40 70 2 67 29 81 54\n56 99 58 3 47 46 65 60 61 85\n88 66 52 49 23 90 75 9 5 26\n48 57 100 44 59 4 84 20 50 7\n8 38 10 22 37 96 51 12 77 36\n68 15 91 41 73 94 53 76 87 63\n64 79 82 89 21 33 45 78 19 43\n93 62 72 83 69 98 31 32 39 17\n14 11 92 35 74 25 30 18 97 27\n",
"output": "180 2\n",
"type": "stdin_stdout"
},
{
"input": "10\n24 15 30 49 12 9 47 37 57 50\n86 32 34 89 40 54 31 43 88 81\n78 68 20 48 13 35 93 62 79 38\n98 58 4 33 7 46 42 18 84 96\n65 85 56 71 36 5 3 41 55 100\n97 66 25 53 77 23 27 6 75 99\n92 21 59 94 91 45 51 83 73 17\n76 29 19 82 72 67 16 22 26 87\n11 69 14 39 44 74 60 2 64 8\n80 70 90 10 28 63 61 95 1 52\n",
"output": "180 3\n",
"type": "stdin_stdout"
},
{
"input": "10\n55 97 76 67 68 81 32 3 74 62\n26 7 61 6 35 46 5 85 99 36\n93 59 14 4 72 25 8 47 21 83\n22 64 23 20 44 70 12 10 98 48\n88 28 63 57 13 49 91 31 15 100\n86 38 30 53 50 17 95 43 1 80\n39 90 92 65 2 66 69 52 45 9\n77 42 11 84 82 78 79 27 24 75\n73 19 87 41 18 40 60 71 16 51\n37 29 54 94 89 33 34 96 56 58\n",
"output": "183 3\n",
"type": "stdin_stdout"
},
{
"input": "10\n15 64 57 35 17 82 72 76 25 99\n74 45 77 49 41 6 40 63 28 53\n11 98 34 66 88 42 10 24 69 68\n8 81 97 1 14 32 12 84 46 18\n86 61 26 31 33 30 47 83 5 13\n79 36 90 80 70 39 4 92 29 50\n78 71 96 75 37 95 9 55 27 59\n65 58 73 38 19 94 7 16 100 43\n51 85 87 54 2 60 93 91 48 21\n56 62 67 23 44 3 22 20 52 89\n",
"output": "181 4\n",
"type": "stdin_stdout"
},
{
"input": "10\n19 11 53 94 87 82 89 90 65 5\n25 49 8 42 50 24 80 21 4 98\n93 3 92 75 48 61 47 78 74 63\n84 33 7 29 95 54 46 66 70 73\n85 64 62 44 20 18 15 88 26 97\n52 9 100 17 28 58 6 14 30 32\n37 81 67 72 71 27 77 10 45 38\n83 76 69 40 99 23 35 79 1 16\n59 36 41 96 86 56 51 60 12 68\n34 43 31 39 2 55 13 22 91 57\n",
"output": "176 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n14 10 3 7\n4 15 11 13\n12 1 16 9\n2 5 6 8\n",
"output": "24 5\n",
"type": "stdin_stdout"
},
{
"input": "10\n26 41 65 63 25 100 66 80 68 16\n5 35 69 44 36 86 29 11 77 88\n53 52 67 85 73 50 81 38 82 18\n20 55 83 47 71 60 21 59 79 46\n24 43 22 17 7 99 90 48 2 15\n87 6 27 96 89 91 1 94 45 39\n76 51 70 56 93 31 30 74 64 61\n12 42 58 33 78 40 62 19 8 9\n34 28 4 72 57 37 54 75 10 97\n84 13 92 49 32 3 98 95 14 23\n",
"output": "177 3\n",
"type": "stdin_stdout"
},
{
"input": "10\n55 39 61 44 72 33 90 10 94 60\n50 67 36 23 81 100 79 30 7 95\n14 42 34 83 74 11 54 62 91 8\n63 45 88 22 99 40 57 4 2 5\n3 31 85 9 27 13 21 75 84 15\n80 28 49 17 6 58 65 78 38 93\n86 20 87 64 18 97 68 56 69 71\n76 1 43 53 82 24 98 77 89 59\n26 29 35 16 92 25 46 70 96 37\n47 41 52 51 19 32 73 66 12 48\n",
"output": "173 4\n",
"type": "stdin_stdout"
},
{
"input": "10\n71 42 14 40 72 88 48 82 5 93\n24 96 29 84 41 60 39 9 33 63\n74 25 67 65 89 78 4 17 6 13\n23 27 66 12 54 99 57 19 22 97\n94 70 7 26 51 46 98 43 20 32\n45 44 79 30 15 11 80 76 100 47\n73 68 49 52 10 37 91 92 21 86\n77 50 64 62 56 31 75 34 3 28\n38 16 36 35 83 2 55 90 59 61\n87 8 85 1 53 69 58 18 81 95\n",
"output": "181 2\n",
"type": "stdin_stdout"
},
{
"input": "6\n29 33 8 3 31 22\n14 12 34 36 4 1\n32 24 2 11 9 13\n26 16 17 15 5 10\n35 19 18 21 27 7\n6 30 25 20 23 28\n",
"output": "62 6\n",
"type": "stdin_stdout"
},
{
"input": "10\n99 36 97 100 41 55 37 69 87 12\n68 47 1 53 29 2 70 77 43 88\n84 80 90 72 50 61 27 62 28 19\n3 24 9 85 25 67 10 4 74 91\n52 5 35 31 20 98 18 7 56 79\n86 22 65 51 30 40 66 64 59 58\n26 54 60 95 89 16 23 21 49 63\n34 96 76 83 81 17 73 38 57 33\n6 93 32 11 42 75 45 94 8 92\n14 71 78 48 44 15 39 13 46 82\n",
"output": "175 3\n",
"type": "stdin_stdout"
},
{
"input": "9\n78 7 75 38 74 60 61 68 31\n64 59 44 32 47 36 50 29 14\n66 20 33 11 35 77 37 52 56\n49 72 57 62 2 79 4 26 5\n80 21 54 45 3 16 27 6 25\n1 17 28 46 53 41 9 55 43\n63 10 22 12 81 24 48 42 65\n70 30 39 18 34 19 58 40 76\n69 23 51 8 73 67 71 15 13\n",
"output": "144 5\n",
"type": "stdin_stdout"
},
{
"input": "6\n23 19 4 22 30 15\n36 9 34 12 26 2\n3 28 17 14 20 33\n10 31 25 11 13 8\n18 27 7 29 5 21\n24 1 32 6 35 16\n",
"output": "58 4\n",
"type": "stdin_stdout"
},
{
"input": "5\n14 15 23 11 3\n6 22 19 25 16\n21 7 5 13 8\n10 1 12 18 24\n2 20 9 17 4\n",
"output": "41 4\n",
"type": "stdin_stdout"
},
{
"input": "10\n55 60 23 69 63 2 83 70 24 86\n19 7 89 12 21 64 74 44 95 46\n81 67 39 16 76 34 51 5 17 80\n56 99 84 65 25 33 52 28 85 94\n100 61 35 30 26 6 75 9 96 59\n27 31 98 62 15 32 91 47 20 3\n78 11 43 4 8 90 49 29 93 50\n68 57 40 45 13 36 77 97 72 48\n38 66 37 53 41 54 79 1 73 10\n88 92 58 18 71 22 42 14 87 82\n",
"output": "174 3\n",
"type": "stdin_stdout"
},
{
"input": "6\n8 9 25 10 36 33\n35 4 3 11 14 6\n12 13 18 7 34 1\n26 24 28 19 2 15\n22 20 23 17 21 32\n31 16 5 29 30 27\n",
"output": "56 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n10 15 4 5\n8 12 14 1\n13 6 16 2\n9 7 3 11\n",
"output": "21 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n8 5 11 16\n6 9 15 3\n1 14 7 13\n2 12 4 10\n",
"output": "25 4\n",
"type": "stdin_stdout"
},
{
"input": "10\n80 43 36 69 6 68 19 1 94 70\n83 27 65 78 81 35 40 4 42 47\n73 96 32 13 37 72 3 16 30 59\n76 92 7 60 88 45 21 91 97 86\n84 52 41 29 63 100 10 24 62 11\n53 75 28 77 2 74 82 55 31 93\n67 71 38 66 44 9 51 14 26 48\n12 17 90 57 89 49 56 15 99 39\n18 64 58 25 46 5 98 50 33 85\n23 22 95 87 54 79 61 34 8 20\n",
"output": "177 5\n",
"type": "stdin_stdout"
},
{
"input": "7\n38 8 36 21 15 14 28\n7 5 42 26 24 4 3\n47 25 11 33 39 12 23\n22 35 16 37 10 27 34\n2 45 40 49 13 32 20\n44 18 41 9 6 46 43\n30 48 1 29 17 19 31\n",
"output": "85 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 9 7 16\n6 5 10 2\n11 8 15 3\n14 13 12 1\n",
"output": "22 3\n",
"type": "stdin_stdout"
},
{
"input": "6\n3 18 33 8 24 9\n19 5 32 12 27 34\n10 29 30 36 21 2\n26 15 25 4 14 7\n13 28 17 11 1 16\n20 23 35 31 6 22\n",
"output": "59 2\n",
"type": "stdin_stdout"
},
{
"input": "10\n74 13 32 41 53 37 82 22 67 95\n10 90 76 16 99 77 84 58 61 80\n54 28 85 38 5 57 79 40 2 42\n66 64 31 87 88 49 26 20 21 43\n81 68 91 29 12 83 93 45 23 100\n75 69 50 59 9 96 97 56 36 52\n8 6 34 72 15 73 89 70 51 33\n3 63 27 19 30 1 62 48 46 18\n35 92 86 14 55 44 60 11 98 94\n24 4 78 7 47 39 65 25 17 71\n",
"output": "180 4\n",
"type": "stdin_stdout"
},
{
"input": "5\n9 25 1 13 17\n8 15 14 24 3\n6 22 10 16 5\n20 12 18 23 4\n11 19 7 2 21\n",
"output": "40 5\n",
"type": "stdin_stdout"
},
{
"input": "6\n27 24 6 34 30 9\n36 13 12 25 35 4\n16 20 31 29 5 28\n23 21 18 7 17 1\n8 15 22 2 32 26\n3 11 14 33 19 10\n",
"output": "60 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n10 16 8 6\n12 14 3 7\n1 5 13 9\n4 11 15 2\n",
"output": "25 2\n",
"type": "stdin_stdout"
},
{
"input": "10\n17 71 19 86 76 65 25 61 48 44\n40 80 22 88 24 96 47 79 74 2\n73 43 100 1 21 33 45 28 27 56\n59 34 93 52 67 57 10 70 82 14\n97 30 54 51 85 98 90 42 77 39\n6 31 12 78 9 91 35 64 18 84\n32 11 66 99 16 15 29 36 62 94\n87 50 81 58 4 37 72 26 63 38\n68 41 53 95 7 3 89 60 55 23\n75 46 5 49 92 13 8 69 83 20\n",
"output": "183 4\n",
"type": "stdin_stdout"
},
{
"input": "10\n16 58 100 21 73 64 81 41 27 63\n24 38 20 78 66 87 59 89 43 57\n98 44 68 86 40 84 69 55 77 61\n2 12 52 9 99 54 29 90 6 91\n36 18 51 22 82 56 17 28 30 74\n42 1 49 32 76 67 93 13 39 19\n72 92 70 8 47 26 25 94 60 97\n71 80 37 62 3 14 15 83 50 35\n34 7 75 33 45 31 4 23 11 88\n65 96 5 10 85 79 95 46 48 53\n",
"output": "182 4\n",
"type": "stdin_stdout"
},
{
"input": "7\n29 17 27 14 42 37 6\n32 25 40 41 13 35 9\n1 49 34 28 12 21 33\n45 4 30 7 23 38 43\n39 15 26 3 10 24 31\n16 8 5 20 48 47 44\n46 2 22 36 11 18 19\n",
"output": "84 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 8 13 4\n14 5 10 7\n9 15 2 12\n16 11 6 1\n",
"output": "18 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n24 22 23 21 3\n12 16 18 8 14\n15 13 20 5 17\n19 6 10 25 2\n7 9 4 1 11\n",
"output": "42 8\n",
"type": "stdin_stdout"
},
{
"input": "8\n8 36 4 50 10 12 59 48\n42 20 7 9 25 21 11 27\n19 2 23 1 30 43 39 34\n24 63 17 41 46 18 29 31\n35 22 60 32 62 13 3 47\n56 55 37 28 52 51 54 15\n57 14 26 16 44 33 38 61\n5 6 58 40 64 45 53 49\n",
"output": "111 3\n",
"type": "stdin_stdout"
},
{
"input": "7\n47 41 42 18 38 5 33\n46 20 10 48 3 9 11\n29 28 24 23 44 21 17\n25 27 4 40 49 34 8\n45 14 31 1 16 19 13\n39 30 22 26 37 32 43\n7 36 2 35 15 6 12\n",
"output": "79 2\n",
"type": "stdin_stdout"
},
{
"input": "9\n65 4 61 5 46 28 20 27 38\n12 66 14 15 31 42 41 6 37\n26 7 13 39 24 40 57 55 32\n52 74 19 64 22 75 54 34 69\n18 50 59 78 1 51 45 72 73\n70 79 56 21 49 62 76 68 11\n71 16 33 23 58 77 67 35 25\n53 10 29 30 36 60 63 9 8\n80 3 17 48 44 2 81 43 47\n",
"output": "136 4\n",
"type": "stdin_stdout"
},
{
"input": "9\n54 78 61 42 79 17 56 81 76\n7 51 21 40 50 1 12 13 53\n48 10 14 63 43 24 23 8 5\n41 39 31 65 19 35 15 67 77\n73 52 66 3 62 16 26 49 60\n74 29 9 80 46 70 72 71 18\n64 36 33 57 58 28 47 20 4\n69 44 11 25 68 59 34 2 6\n55 32 30 37 22 45 27 38 75\n",
"output": "140 4\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 5 2\n7 6 3\n4 8 9\n",
"output": "11 0\n",
"type": "stdin_stdout"
},
{
"input": "4\n6 3 15 11\n10 13 4 14\n12 8 2 5\n16 7 9 1\n",
"output": "27 3\n",
"type": "stdin_stdout"
},
{
"input": "6\n32 17 18 23 26 33\n7 36 22 3 1 5\n30 9 8 34 27 21\n16 6 35 28 4 25\n29 19 24 13 11 12\n2 20 15 14 31 10\n",
"output": "56 4\n",
"type": "stdin_stdout"
},
{
"input": "8\n50 10 62 1 35 37 30 11\n25 7 57 17 29 5 22 12\n20 43 28 13 45 33 4 36\n24 41 32 53 6 54 19 42\n26 46 55 16 9 3 64 52\n31 49 40 60 61 21 39 27\n23 14 15 59 2 63 8 18\n58 56 38 44 47 48 51 34\n",
"output": "111 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 12 10 7\n9 2 11 13\n16 6 3 15\n14 8 5 4\n",
"output": "24 4\n",
"type": "stdin_stdout"
},
{
"input": "5\n16 25 8 21 9\n4 11 2 23 20\n1 15 7 10 12\n18 13 3 6 5\n14 17 22 19 24\n",
"output": "43 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n12 7 5 3\n1 6 9 16\n4 13 2 11\n15 10 14 8\n",
"output": "25 4\n",
"type": "stdin_stdout"
},
{
"input": "5\n18 1 20 13 10\n22 12 25 9 16\n2 19 21 11 6\n3 17 5 8 23\n15 14 24 7 4\n",
"output": "39 6\n",
"type": "stdin_stdout"
},
{
"input": "6\n20 11 10 7 1 24\n18 23 26 12 5 21\n36 25 33 13 16 31\n29 15 32 30 22 6\n2 4 14 27 28 34\n8 35 3 9 19 17\n",
"output": "63 2\n",
"type": "stdin_stdout"
},
{
"input": "10\n41 55 34 20 95 100 29 7 64 3\n24 1 49 45 92 62 50 90 46 8\n72 82 19 2 36 13 6 33 81 27\n66 85 98 71 84 97 96 31 9 47\n35 25 79 78 10 67 40 61 11 88\n18 91 23 65 21 73 94 59 89 38\n22 26 68 76 51 93 48 83 54 52\n12 60 30 57 43 74 32 58 80 37\n15 5 16 42 56 39 70 14 44 87\n99 86 4 53 63 77 75 17 28 69\n",
"output": "177 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 4 8\n7 2 6\n5 9 3\n",
"output": "11 3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 22 11 16 5\n12 17 4 21 2\n23 10 25 6 15\n18 13 8 3 20\n9 24 19 14 7\n",
"output": "26 0\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 12 7 24 23\n18 25 22 13 8\n11 6 17 2 21\n16 19 4 9 14\n5 10 15 20 3\n",
"output": "28 0\n",
"type": "stdin_stdout"
},
{
"input": "4\n11 14 6 1\n4 9 16 7\n8 13 5 12\n2 15 3 10\n",
"output": "23 2\n",
"type": "stdin_stdout"
},
{
"input": "6\n11 25 16 1 23 28\n12 8 20 24 33 22\n13 17 19 7 18 26\n5 30 9 31 36 21\n35 4 32 29 6 15\n14 27 3 10 2 34\n",
"output": "58 2\n",
"type": "stdin_stdout"
},
{
"input": "8\n28 20 24 61 36 30 18 1\n54 5 60 22 21 13 12 25\n16 62 58 27 49 17 3 23\n37 57 32 55 11 15 43 33\n29 42 56 39 50 26 47 51\n4 35 48 63 38 14 2 31\n59 8 46 53 10 19 6 7\n45 9 64 34 41 40 52 44\n",
"output": "108 4\n",
"type": "stdin_stdout"
},
{
"input": "5\n21 12 16 3 10\n23 19 24 2 6\n5 17 22 4 13\n18 11 7 20 1\n9 8 15 25 14\n",
"output": "37 3\n",
"type": "stdin_stdout"
},
{
"input": "8\n57 45 12 22 16 43 6 29\n23 46 48 37 55 1 42 49\n59 21 2 8 52 30 51 19\n14 18 44 50 34 58 35 53\n9 41 13 25 10 62 40 7\n47 56 26 15 33 63 31 39\n61 38 24 3 27 20 36 28\n5 64 11 32 60 54 17 4\n",
"output": "111 3\n",
"type": "stdin_stdout"
},
{
"input": "6\n20 22 16 1 31 18\n5 4 27 34 8 30\n3 28 2 36 15 10\n19 9 29 11 13 32\n24 35 14 6 33 17\n7 21 12 26 25 23\n",
"output": "63 5\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 7 9\n4 3 5\n6 8 1\n",
"output": "12 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n16 8 7 12\n2 14 4 15\n5 13 10 1\n11 9 6 3\n",
"output": "24 1\n",
"type": "stdin_stdout"
},
{
"input": "10\n16 92 81 8 70 28 72 91 87 13\n32 17 93 83 5 69 27 74 89 88\n43 31 22 99 79 4 65 26 71 90\n50 41 29 15 98 80 9 68 24 73\n59 51 38 35 18 96 82 6 67 25\n57 60 49 45 37 19 97 85 7 66\n76 53 61 46 40 36 14 95 86 3\n11 75 55 58 48 44 34 20 94 84\n2 10 77 56 62 52 39 30 23 100\n64 1 12 78 54 63 47 42 33 21\n",
"output": "125 15\n",
"type": "stdin_stdout"
},
{
"input": "8\n55 22 23 48 49 45 34 62\n60 64 17 43 53 47 29 33\n21 4 27 35 44 26 63 28\n57 14 19 3 20 36 58 51\n8 5 38 30 1 12 6 10\n39 16 37 9 61 18 31 42\n32 15 54 41 25 24 50 11\n2 40 56 13 59 52 7 46\n",
"output": "110 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n8 13 3 11\n7 10 4 14\n16 15 9 5\n2 6 12 1\n",
"output": "24 3\n",
"type": "stdin_stdout"
},
{
"input": "10\n62 94 3 66 14 32 52 21 34 80\n98 77 42 18 67 8 87 22 90 88\n95 4 81 56 7 9 75 10 24 68\n55 61 46 82 36 11 30 74 37 97\n73 53 40 25 70 91 39 28 100 13\n23 47 65 41 89 5 2 63 92 54\n6 19 71 99 84 16 64 58 38 12\n17 27 83 48 78 20 96 1 49 85\n51 43 29 57 76 69 79 26 59 45\n72 33 93 86 50 31 60 35 15 44\n",
"output": "184 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n18 13 10 16 7\n11 21 15 5 4\n22 8 25 14 3\n19 12 2 9 20\n6 23 1 24 17\n",
"output": "38 4\n",
"type": "stdin_stdout"
},
{
"input": "10\n13 75 45 86 90 52 36 68 26 74\n89 30 96 15 12 37 88 100 23 93\n81 7 44 6 53 94 3 83 50 72\n25 91 21 69 51 47 1 5 43 95\n19 41 80 71 98 20 70 66 79 87\n10 64 62 99 48 14 60 35 82 27\n42 32 54 59 38 34 16 58 8 18\n29 17 78 49 97 55 73 33 67 28\n40 85 4 76 57 11 77 56 46 9\n61 2 31 22 24 39 65 63 84 92\n",
"output": "182 5\n",
"type": "stdin_stdout"
},
{
"input": "10\n93 52 12 70 25 36 18 37 27 99\n68 40 84 3 76 57 60 19 33 41\n92 87 58 13 15 43 28 63 64 59\n31 97 14 69 4 88 72 65 10 23\n67 81 21 80 90 82 74 1 95 42\n89 29 53 44 17 61 50 8 85 73\n30 62 7 46 54 77 9 34 38 16\n26 56 71 32 83 48 49 11 91 35\n24 75 78 20 86 45 94 55 98 2\n39 96 5 22 100 6 79 66 51 47\n",
"output": "182 0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1065/D"
} | vfc_10174 |
apps | verifiable_code | 106 | Solve the following coding problem using the programming language python:
Есть n-подъездный дом, в каждом подъезде по m этажей, и на каждом этаже каждого подъезда ровно k квартир. Таким образом, в доме всего n·m·k квартир. Они пронумерованы естественным образом от 1 до n·m·k, то есть первая квартира на первом этаже в первом подъезде имеет номер 1, первая квартира на втором этаже первого подъезда имеет номер k + 1 и так далее. Особенность этого дома состоит в том, что он круглый. То есть если обходить его по часовой стрелке, то после подъезда номер 1 следует подъезд номер 2, затем подъезд номер 3 и так далее до подъезда номер n. После подъезда номер n снова идёт подъезд номер 1.
Эдвард живёт в квартире номер a, а Наташа — в квартире номер b. Переход на 1 этаж вверх или вниз по лестнице занимает 5 секунд, переход от двери подъезда к двери соседнего подъезда — 15 секунд, а переход в пределах одного этажа одного подъезда происходит мгновенно. Также в каждом подъезде дома есть лифт. Он устроен следующим образом: он всегда приезжает ровно через 10 секунд после вызова, а чтобы переместить пассажира на один этаж вверх или вниз, лифт тратит ровно 1 секунду. Посадка и высадка происходят мгновенно.
Помогите Эдварду найти минимальное время, за которое он сможет добраться до квартиры Наташи. Считайте, что Эдвард может выйти из подъезда только с первого этажа соответствующего подъезда (это происходит мгновенно). Если Эдвард стоит перед дверью какого-то подъезда, он может зайти в него и сразу окажется на первом этаже этого подъезда (это также происходит мгновенно). Эдвард может выбирать, в каком направлении идти вокруг дома.
-----Входные данные-----
В первой строке входных данных следуют три числа n, m, k (1 ≤ n, m, k ≤ 1000) — количество подъездов в доме, количество этажей в каждом подъезде и количество квартир на каждом этаже каждого подъезда соответственно.
Во второй строке входных данных записаны два числа a и b (1 ≤ a, b ≤ n·m·k) — номера квартир, в которых живут Эдвард и Наташа, соответственно. Гарантируется, что эти номера различны.
-----Выходные данные-----
Выведите единственное целое число — минимальное время (в секундах), за которое Эдвард сможет добраться от своей квартиры до квартиры Наташи.
-----Примеры-----
Входные данные
4 10 5
200 6
Выходные данные
39
Входные данные
3 1 5
7 2
Выходные данные
15
-----Примечание-----
В первом тестовом примере Эдвард находится в 4 подъезде на 10 этаже, а Наташа находится в 1 подъезде на 2 этаже. Поэтому Эдварду выгодно сначала спуститься на лифте на первый этаж (на это он потратит 19 секунд, из которых 10 — на ожидание и 9 — на поездку на лифте), затем обойти дом против часовой стрелки до подъезда номер 1 (на это он потратит 15 секунд), и наконец подняться по лестнице на этаж номер 2 (на это он потратит 5 секунд). Таким образом, ответ равен 19 + 15 + 5 = 39.
Во втором тестовом примере Эдвард живёт в подъезде 2 на этаже 1, а Наташа находится в подъезде 1 на этаже 1. Поэтому Эдварду выгодно просто обойти дом по часовой стрелке до подъезда 1, на это он потратит 15 секунд.
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 = map(int, input().split())
a, b = map(int, input().split())
a -= 1
b -= 1
def p(x):
return x // (m * k)
def e(x):
return (x - p(x) * m * k) // k
def lift(x):
return min(5 * x, 10 + x)
if p(a) == p(b):
dif = abs(e(a) - e(b))
print(lift(dif))
else:
print(lift(e(a)) + 15 * min((p(a) - p(b) + n) % n, (p(b) - p(a) + n) % n) + lift(e(b)))
``` | {
"language": "python",
"test_cases": [
{
"input": "4 10 5\n200 6\n",
"output": "39\n",
"type": "stdin_stdout"
},
{
"input": "3 1 5\n7 2\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "100 100 100\n1 1000000\n",
"output": "124\n",
"type": "stdin_stdout"
},
{
"input": "1000 1000 1000\n1 1000000000\n",
"output": "1024\n",
"type": "stdin_stdout"
},
{
"input": "125 577 124\n7716799 6501425\n",
"output": "1268\n",
"type": "stdin_stdout"
},
{
"input": "624 919 789\n436620192 451753897\n",
"output": "509\n",
"type": "stdin_stdout"
},
{
"input": "314 156 453\n9938757 14172410\n",
"output": "1104\n",
"type": "stdin_stdout"
},
{
"input": "301 497 118\n11874825 13582548\n",
"output": "994\n",
"type": "stdin_stdout"
},
{
"input": "491 980 907\n253658701 421137262\n",
"output": "3985\n",
"type": "stdin_stdout"
},
{
"input": "35 296 7\n70033 65728\n",
"output": "499\n",
"type": "stdin_stdout"
},
{
"input": "186 312 492\n19512588 5916903\n",
"output": "1560\n",
"type": "stdin_stdout"
},
{
"input": "149 186 417\n11126072 11157575\n",
"output": "85\n",
"type": "stdin_stdout"
},
{
"input": "147 917 539\n55641190 66272443\n",
"output": "952\n",
"type": "stdin_stdout"
},
{
"input": "200 970 827\n113595903 145423943\n",
"output": "1484\n",
"type": "stdin_stdout"
},
{
"input": "32 15 441\n163561 23326\n",
"output": "202\n",
"type": "stdin_stdout"
},
{
"input": "748 428 661\n136899492 11286206\n",
"output": "5347\n",
"type": "stdin_stdout"
},
{
"input": "169 329 585\n30712888 19040968\n",
"output": "1430\n",
"type": "stdin_stdout"
},
{
"input": "885 743 317\n191981621 16917729\n",
"output": "2825\n",
"type": "stdin_stdout"
},
{
"input": "245 168 720\n24072381 125846\n",
"output": "726\n",
"type": "stdin_stdout"
},
{
"input": "593 174 843\n72930566 9954376\n",
"output": "2650\n",
"type": "stdin_stdout"
},
{
"input": "41 189 839\n6489169 411125\n",
"output": "351\n",
"type": "stdin_stdout"
},
{
"input": "437 727 320\n93935485 28179924\n",
"output": "3007\n",
"type": "stdin_stdout"
},
{
"input": "722 42 684\n18861511 1741045\n",
"output": "1958\n",
"type": "stdin_stdout"
},
{
"input": "324 584 915\n61572963 155302434\n",
"output": "2756\n",
"type": "stdin_stdout"
},
{
"input": "356 444 397\n1066682 58120717\n",
"output": "860\n",
"type": "stdin_stdout"
},
{
"input": "266 675 472\n11637902 74714734\n",
"output": "1739\n",
"type": "stdin_stdout"
},
{
"input": "841 727 726\n101540521 305197765\n",
"output": "6264\n",
"type": "stdin_stdout"
},
{
"input": "828 68 391\n3563177 21665321\n",
"output": "2288\n",
"type": "stdin_stdout"
},
{
"input": "666 140 721\n30509638 63426599\n",
"output": "4995\n",
"type": "stdin_stdout"
},
{
"input": "151 489 61\n2561086 4227874\n",
"output": "1640\n",
"type": "stdin_stdout"
},
{
"input": "713 882 468\n5456682 122694685\n",
"output": "4687\n",
"type": "stdin_stdout"
},
{
"input": "676 53 690\n1197227 20721162\n",
"output": "2221\n",
"type": "stdin_stdout"
},
{
"input": "618 373 56\n531564 11056643\n",
"output": "2020\n",
"type": "stdin_stdout"
},
{
"input": "727 645 804\n101269988 374485315\n",
"output": "3289\n",
"type": "stdin_stdout"
},
{
"input": "504 982 254\n101193488 5004310\n",
"output": "2556\n",
"type": "stdin_stdout"
},
{
"input": "872 437 360\n5030750 15975571\n",
"output": "1736\n",
"type": "stdin_stdout"
},
{
"input": "448 297 806\n60062303 9056580\n",
"output": "3730\n",
"type": "stdin_stdout"
},
{
"input": "165 198 834\n16752490 5105535\n",
"output": "1354\n",
"type": "stdin_stdout"
},
{
"input": "816 145 656\n32092038 5951215\n",
"output": "4281\n",
"type": "stdin_stdout"
},
{
"input": "28 883 178\n2217424 1296514\n",
"output": "424\n",
"type": "stdin_stdout"
},
{
"input": "24 644 653\n1326557 3894568\n",
"output": "377\n",
"type": "stdin_stdout"
},
{
"input": "717 887 838\n46183300 63974260\n",
"output": "556\n",
"type": "stdin_stdout"
},
{
"input": "101 315 916\n1624396 1651649\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "604 743 433\n78480401 16837572\n",
"output": "3833\n",
"type": "stdin_stdout"
},
{
"input": "100 100 100\n1 10000\n",
"output": "109\n",
"type": "stdin_stdout"
},
{
"input": "100 100 100\n1000000 990001\n",
"output": "109\n",
"type": "stdin_stdout"
},
{
"input": "1 1 2\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "34 34 34\n20000 20001\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "139 252 888\n24732218 24830663\n",
"output": "121\n",
"type": "stdin_stdout"
},
{
"input": "859 96 634\n26337024 26313792\n",
"output": "47\n",
"type": "stdin_stdout"
},
{
"input": "987 237 891\n41648697 41743430\n",
"output": "117\n",
"type": "stdin_stdout"
},
{
"input": "411 81 149\n4799008 4796779\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "539 221 895\n18072378 18071555\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "259 770 448\n19378646 19320867\n",
"output": "139\n",
"type": "stdin_stdout"
},
{
"input": "387 422 898\n89303312 89285292\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "515 563 451\n12182093 12047399\n",
"output": "309\n",
"type": "stdin_stdout"
},
{
"input": "939 407 197\n42361632 42370846\n",
"output": "57\n",
"type": "stdin_stdout"
},
{
"input": "518 518 71\n3540577 3556866\n",
"output": "239\n",
"type": "stdin_stdout"
},
{
"input": "100 1 1\n55 1\n",
"output": "690\n",
"type": "stdin_stdout"
},
{
"input": "1000 1000 1000\n1 10000000\n",
"output": "1144\n",
"type": "stdin_stdout"
},
{
"input": "1000 1000 1000\n1000000000 990000001\n",
"output": "1144\n",
"type": "stdin_stdout"
},
{
"input": "340 340 340\n200000 200001\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000 1 1\n556 1\n",
"output": "6675\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n1 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n1 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n1 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n1 7\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n1 8\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n7 8\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n7 9\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n7 10\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n7 11\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n7 12\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n11 12\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n12 13\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n12 14\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n12 24\n",
"output": "35\n",
"type": "stdin_stdout"
},
{
"input": "1000 1000 1000\n600400021 600400051\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 4\n7 8\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1000 1\n42 43\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "10 10 1\n2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 3 1\n2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 9 1\n6 9\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "4 10 5\n6 7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 10 10\n40 80\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "1 5 1\n5 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 1000 1\n42 228\n",
"output": "196\n",
"type": "stdin_stdout"
},
{
"input": "4 10 5\n200 199\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 9 1\n6 7\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2 5 1\n10 9\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 5 1\n1 5\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "1 5 1\n2 5\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "3 3 2\n3 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 5 1\n4 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 4 1\n2 4\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 9 1\n3 6\n",
"output": "13\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/649/B"
} | vfc_10178 |
apps | verifiable_code | 107 | Solve the following coding problem using the programming language python:
Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills.
Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way, that remaining number is a representation of some positive integer, divisible by 64, in the binary numerical system.
-----Input-----
In the only line given a non-empty binary string s with length up to 100.
-----Output-----
Print «yes» (without quotes) if it's possible to remove digits required way and «no» otherwise.
-----Examples-----
Input
100010001
Output
yes
Input
100
Output
no
-----Note-----
In the first test case, you can get string 1 000 000 after removing two ones which is a representation of number 64 in the binary numerical system.
You can read more about binary numeral system representation here: https://en.wikipedia.org/wiki/Binary_system
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
i = 0
while i < len(s) and s[i] == '0':
i += 1
cnt = 0
while i < len(s):
if s[i] == '0':
cnt += 1
i += 1
if cnt >= 6:
print('yes')
else:
print('no')
``` | {
"language": "python",
"test_cases": [
{
"input": "100010001\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"input": "100\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000001000000\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111110111111111111111111111111111\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0111111101111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "1111011111111111111111111111110111110111111111111111111111011111111111111110111111111111111111111111\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "1111111111101111111111111111111111111011111111111111111111111101111011111101111111111101111111111111\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"input": "0110111111111111111111011111111110110111110111111111111111111111111111111111111110111111111111111111\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"input": "1100110001111011001101101000001110111110011110111110010100011000100101000010010111100000010001001101\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"input": "000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0001000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "1000000\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"input": "0\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "10000000000\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"input": "0000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0010000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000011\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000000011\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000011\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000001\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000000000000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000001\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000001\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000100\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00001000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000010\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000000010\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000000000010\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0100000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00010000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000001000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "100000000000000\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"input": "000010000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000100\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0001100000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000000000000000000000001\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000100\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000001111111111\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000010\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0001110000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000010010\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000100\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000001\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000111\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0010000000000100\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"input": "0000001000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000000000000001\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "100000000\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"input": "000000000001\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000011001\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000011\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000000000001\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000000010\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000000000000000000000000000000000000000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000011000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000011\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000001100\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000000000000000000000000111111111111111\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000010\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000111\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "000000000000001\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000011111111111111111\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000010\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000000000000000000000000000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000010\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "101000000000\n",
"output": "yes",
"type": "stdin_stdout"
},
{
"input": "00100000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000000001\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000100\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "00000000000111\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000011\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000000000000000000000000000000\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000010\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0010101010\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "0000000000000001\n",
"output": "no",
"type": "stdin_stdout"
},
{
"input": "1010101\n",
"output": "no",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/887/A"
} | vfc_10182 |
apps | verifiable_code | 109 | Solve the following coding problem using the programming language python:
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
-----Input-----
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 10^5, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 10^5)).
-----Output-----
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10^{ - 9}. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$.
-----Examples-----
Input
3 3 2 3
Output
2.0000000000
Input
12 17 9 40
Output
32.8333333333
-----Note-----
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value. [Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import heapq as hq
from queue import PriorityQueue
import math
n,m,r, k= input().split()
N = int(n)
M = int(m)
R = int(r)
K = int(k)
q = PriorityQueue()
for i in range(1,math.floor((N+1)/2) + 1):
maxi = min(min(i,N-i+1),min(R,N-R+1)) * min(min(R,M-R+1),math.ceil(M/2))
num = M - (2 * min(min(R,M-R+1),math.ceil(M/2))-2)
mult = 2
if(i > math.floor(N/2)):
mult = 1
q.put((-maxi,num * mult,i))
#print(str(maxi) + " " + str(num) + " " + str(mult))
ans = 0
while(K > 0):
pop = q.get()
#print(pop)
a = -1 * pop[0]
b = pop[1]
c = pop[2]
d = min(min(c,N-c+1),min(R,N-R+1))
if(d != a):
# if(q.)
# if(q.get(-(a - d)) != )
mult = 2
if (c > N / 2):
mult = 1
q.put((-(a - d),2*mult,c))
ans += a * min(b,K)
K -= b;
tot = (N-R+1) * (M-R+1)
#print("ANS = " + str(ans))
#print("FINANS = " + str(ans/tot))
print(str(ans/tot))
'''
d = []
for i in range(0,N):
d.append([])
for j in range(0,M):
d[i].append(0)
tot = 0
for i in range(0,N-R+1):
for j in range(0,M-R+1):
for k in range(i,i+R):
for l in range(j,j+R):
d[k][l] += 1
tot += 1
print(N-R+1)*(M-R+1) * (R*R)
print(tot)
print()
for i in d:
print(i)
'''
``` | {
"language": "python",
"test_cases": [
{
"input": "3 3 2 3\n",
"output": "2.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "12 17 9 40\n",
"output": "32.8333333333\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1 1\n",
"output": "1.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "10 10 5 100\n",
"output": "25.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "7 1 1 4\n",
"output": "0.5714285714\n",
"type": "stdin_stdout"
},
{
"input": "1000 1000 59 100000\n",
"output": "392.2854657164\n",
"type": "stdin_stdout"
},
{
"input": "100000 100000 1000 100000\n",
"output": "10.2028343872\n",
"type": "stdin_stdout"
},
{
"input": "100000 100000 100000 100000\n",
"output": "100000.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "3 100000 2 88700\n",
"output": "1.7740177402\n",
"type": "stdin_stdout"
},
{
"input": "200 100000 55 100000\n",
"output": "20.7303724833\n",
"type": "stdin_stdout"
},
{
"input": "74 2 1 36\n",
"output": "0.2432432432\n",
"type": "stdin_stdout"
},
{
"input": "2 59 1 112\n",
"output": "0.9491525424\n",
"type": "stdin_stdout"
},
{
"input": "96 33 24 928\n",
"output": "299.8356164384\n",
"type": "stdin_stdout"
},
{
"input": "20 78 8 997\n",
"output": "55.2026002167\n",
"type": "stdin_stdout"
},
{
"input": "44 22 13 515\n",
"output": "139.7312500000\n",
"type": "stdin_stdout"
},
{
"input": "68 66 33 2353\n",
"output": "930.8962418301\n",
"type": "stdin_stdout"
},
{
"input": "96 7 4 534\n",
"output": "14.6129032258\n",
"type": "stdin_stdout"
},
{
"input": "20 59 2 88\n",
"output": "0.3194192377\n",
"type": "stdin_stdout"
},
{
"input": "45 3 1 35\n",
"output": "0.2592592593\n",
"type": "stdin_stdout"
},
{
"input": "69 48 18 167\n",
"output": "33.5657568238\n",
"type": "stdin_stdout"
},
{
"input": "34994 5189 2572 83748\n",
"output": "6526.6982502848\n",
"type": "stdin_stdout"
},
{
"input": "51122 86737 45712 45929\n",
"output": "45929.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "1308 96219 150 13599\n",
"output": "2.7480097244\n",
"type": "stdin_stdout"
},
{
"input": "84732 45064 24231 99973\n",
"output": "40039.1022280255\n",
"type": "stdin_stdout"
},
{
"input": "860 93908 193 29450\n",
"output": "17.5230504355\n",
"type": "stdin_stdout"
},
{
"input": "51580 42753 1589 91632\n",
"output": "112.4258885780\n",
"type": "stdin_stdout"
},
{
"input": "67708 58893 32854 21110\n",
"output": "19898.0903744083\n",
"type": "stdin_stdout"
},
{
"input": "51133 7737 2779 83291\n",
"output": "2682.4996497742\n",
"type": "stdin_stdout"
},
{
"input": "67261 65094 36712 36961\n",
"output": "36961.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "17981 81234 438 66438\n",
"output": "8.9916815389\n",
"type": "stdin_stdout"
},
{
"input": "86852 96025 86852 82059\n",
"output": "82059.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "96877 86600 86600 94110\n",
"output": "94110.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "93240 88881 88881 94245\n",
"output": "94245.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "90706 97197 90706 96593\n",
"output": "96593.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "93289 95214 93289 96084\n",
"output": "96084.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "90755 85790 85790 98432\n",
"output": "98432.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "80779 83807 80779 97924\n",
"output": "97924.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "98246 89266 89266 80270\n",
"output": "80270.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "80828 99843 80828 99763\n",
"output": "99763.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "98295 88157 88157 82110\n",
"output": "82110.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "52329 55202 45142 8532\n",
"output": "8532.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "68457 4046 983 38009\n",
"output": "177.6486146644\n",
"type": "stdin_stdout"
},
{
"input": "18644 46233 17019 62575\n",
"output": "36452.6416224542\n",
"type": "stdin_stdout"
},
{
"input": "2068 62373 1084 92053\n",
"output": "1628.0869962473\n",
"type": "stdin_stdout"
},
{
"input": "18196 43921 15918 54235\n",
"output": "30828.1934723611\n",
"type": "stdin_stdout"
},
{
"input": "68916 60062 7636 83712\n",
"output": "1519.2830994297\n",
"type": "stdin_stdout"
},
{
"input": "85044 8906 4115 45894\n",
"output": "2003.8686025940\n",
"type": "stdin_stdout"
},
{
"input": "68468 33559 15324 99563\n",
"output": "24124.0525512989\n",
"type": "stdin_stdout"
},
{
"input": "84596 49699 46033 61745\n",
"output": "61745.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "35316 31247 27829 91223\n",
"output": "91223.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "51444 47388 21532 20700\n",
"output": "12407.9770445558\n",
"type": "stdin_stdout"
},
{
"input": "67572 96232 61366 50178\n",
"output": "50178.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "17759 38418 4313 7448\n",
"output": "302.0942031080\n",
"type": "stdin_stdout"
},
{
"input": "1183 87263 148 4221\n",
"output": "1.0244272005\n",
"type": "stdin_stdout"
},
{
"input": "84607 36107 29486 33699\n",
"output": "18026.3545226951\n",
"type": "stdin_stdout"
},
{
"input": "68031 52248 51042 20073\n",
"output": "20073.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "84159 1092 683 49550\n",
"output": "405.4128682152\n",
"type": "stdin_stdout"
},
{
"input": "67583 49936 46141 11732\n",
"output": "11732.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "51007 74589 14733 41209\n",
"output": "4119.5718891113\n",
"type": "stdin_stdout"
},
{
"input": "34431 23433 19371 27583\n",
"output": "27583.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "52 45 38 49\n",
"output": "49.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "80 89 32 26\n",
"output": "9.3680506685\n",
"type": "stdin_stdout"
},
{
"input": "74 63 30 92\n",
"output": "53.8823529412\n",
"type": "stdin_stdout"
},
{
"input": "2 20 1 14\n",
"output": "0.3500000000\n",
"type": "stdin_stdout"
},
{
"input": "22 60 13 48\n",
"output": "13.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "50 5 4 29\n",
"output": "2.4680851064\n",
"type": "stdin_stdout"
},
{
"input": "74 49 48 99\n",
"output": "99.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "2 89 2 80\n",
"output": "1.8181818182\n",
"type": "stdin_stdout"
},
{
"input": "22 38 9 58\n",
"output": "11.1857142857\n",
"type": "stdin_stdout"
},
{
"input": "50 86 11 36\n",
"output": "1.4328947368\n",
"type": "stdin_stdout"
},
{
"input": "98155 95063 95062 98875\n",
"output": "98875.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "95606 98563 95342 99783\n",
"output": "99783.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "95468 97642 95176 95192\n",
"output": "95192.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "96394 96141 96028 96100\n",
"output": "96100.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "100000 1 1 99999\n",
"output": "0.9999900000\n",
"type": "stdin_stdout"
},
{
"input": "100000 100000 1 100000\n",
"output": "0.0000100000\n",
"type": "stdin_stdout"
},
{
"input": "100000 100000 100000 1\n",
"output": "1.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "88888 99999 77777 1\n",
"output": "1.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "77777 99999 77777 7\n",
"output": "7.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "100000 100000 1 1\n",
"output": "0.0000000001\n",
"type": "stdin_stdout"
},
{
"input": "3689 2691 1885 47808\n",
"output": "47808.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "3907 4563 2248 99346\n",
"output": "95853.0468547766\n",
"type": "stdin_stdout"
},
{
"input": "1785 3525 1785 82536\n",
"output": "82534.7300402068\n",
"type": "stdin_stdout"
},
{
"input": "4761 2433 2433 46586\n",
"output": "46586.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "3106 2359 1558 16919\n",
"output": "16897.4346155270\n",
"type": "stdin_stdout"
},
{
"input": "3291 1679 1679 70630\n",
"output": "70630.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "6439 5463 3240 91287\n",
"output": "91097.0460375450\n",
"type": "stdin_stdout"
},
{
"input": "10000 10000 3000 100000\n",
"output": "18362.1002496817\n",
"type": "stdin_stdout"
},
{
"input": "7159 6332 3563 82463\n",
"output": "81427.6340771341\n",
"type": "stdin_stdout"
},
{
"input": "8402 6135 4222 85384\n",
"output": "85384.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "8946 8108 4509 80203\n",
"output": "80188.7715868009\n",
"type": "stdin_stdout"
},
{
"input": "9199 8137 4561 82660\n",
"output": "81268.3728190748\n",
"type": "stdin_stdout"
},
{
"input": "8208 8895 4508 97736\n",
"output": "97736.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "9513 11191 5633 90250\n",
"output": "90250.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "11562 20387 10218 95794\n",
"output": "95794.0000000000\n",
"type": "stdin_stdout"
},
{
"input": "80000 80000 40000 100000\n",
"output": "99625.0947119987\n",
"type": "stdin_stdout"
},
{
"input": "7 100 4 12\n",
"output": "0.4948453608\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/912/D"
} | vfc_10190 |
apps | verifiable_code | 110 | Solve the following coding problem using the programming language python:
Nick had received an awesome array of integers $a=[a_1, a_2, \dots, a_n]$ as a gift for his $5$ birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product $a_1 \cdot a_2 \cdot \dots a_n$ of its elements seemed to him not large enough.
He was ready to throw out the array, but his mother reassured him. She told him, that array would not be spoiled after the following operation: choose any index $i$ ($1 \le i \le n$) and do $a_i := -a_i - 1$.
For example, he can change array $[3, -1, -4, 1]$ to an array $[-4, -1, 3, 1]$ after applying this operation to elements with indices $i=1$ and $i=3$.
Kolya had immediately understood that sometimes it's possible to increase the product of integers of the array a lot. Now he has decided that he wants to get an array with the maximal possible product of integers using only this operation with its elements (possibly zero, one or more times, as many as he wants), it is not forbidden to do this operation several times for the same index.
Help Kolya and print the array with the maximal possible product of elements $a_1 \cdot a_2 \cdot \dots a_n$ which can be received using only this operation in some order.
If there are multiple answers, print any of them.
-----Input-----
The first line contains integer $n$ ($1 \leq n \leq 10^{5}$) — number of integers in the array.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^{6} \leq a_i \leq 10^{6}$) — elements of the array
-----Output-----
Print $n$ numbers — elements of the array with the maximal possible product of elements which can be received using only this operation in some order from the given array.
If there are multiple answers, print any of them.
-----Examples-----
Input
4
2 2 2 2
Output
-3 -3 -3 -3
Input
1
0
Output
0
Input
3
-3 -3 2
Output
-3 -3 2
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 = list(map(int, input().split()))
if n == 1:
if A[0] >= 0:
print(A[0])
else:
print(-A[0]-1)
return
for i in range(n):
if A[i] < 0:
pass
else:
A[i] = -A[i]-1
if n % 2 == 0:
print(*A)
return
mim = 0
indmim = 0
for i in range(n):
if A[i] < mim:
mim = A[i]
indmim = i
A[indmim] = -A[indmim]-1
print(*A)
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n2 2 2 2\n",
"output": "-3 -3 -3 -3 ",
"type": "stdin_stdout"
},
{
"input": "1\n0\n",
"output": "0 ",
"type": "stdin_stdout"
},
{
"input": "3\n-3 -3 2\n",
"output": "-3 -3 2 ",
"type": "stdin_stdout"
},
{
"input": "10\n2 10 6 8 -4 -11 -10 3 -3 8\n",
"output": "-3 -11 -7 -9 -4 -11 -10 -4 -3 -9 ",
"type": "stdin_stdout"
},
{
"input": "10\n8 6 3 9 8 7 7 7 7 6\n",
"output": "-9 -7 -4 -10 -9 -8 -8 -8 -8 -7 ",
"type": "stdin_stdout"
},
{
"input": "8\n-3 -11 -4 -8 -4 -5 -3 -2\n",
"output": "-3 -11 -4 -8 -4 -5 -3 -2 ",
"type": "stdin_stdout"
},
{
"input": "10\n6 1 -11 -10 -9 -8 8 -1 -10 1\n",
"output": "-7 -2 -11 -10 -9 -8 -9 -1 -10 -2 ",
"type": "stdin_stdout"
},
{
"input": "6\n10 -11 -8 -11 -11 10\n",
"output": "-11 -11 -8 -11 -11 -11 ",
"type": "stdin_stdout"
},
{
"input": "3\n-2 -3 -4\n",
"output": "-2 -3 3 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 0 -4 -3\n",
"output": "-1 -1 -1 3 -3 ",
"type": "stdin_stdout"
},
{
"input": "1\n-3\n",
"output": "2 ",
"type": "stdin_stdout"
},
{
"input": "3\n-10 1 2\n",
"output": "9 -2 -3 ",
"type": "stdin_stdout"
},
{
"input": "2\n0 0\n",
"output": "-1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n-1 -1 -1\n",
"output": "0 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 0 1\n",
"output": "-1 -1 1 ",
"type": "stdin_stdout"
},
{
"input": "3\n-9 0 0\n",
"output": "8 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 -6 4\n",
"output": "-1 5 -5 ",
"type": "stdin_stdout"
},
{
"input": "5\n-1 -1 -1 2 2\n",
"output": "-1 -1 -1 2 -3 ",
"type": "stdin_stdout"
},
{
"input": "1\n-1\n",
"output": "0 ",
"type": "stdin_stdout"
},
{
"input": "3\n-5 -1 1\n",
"output": "4 -1 -2 ",
"type": "stdin_stdout"
},
{
"input": "4\n0 0 0 0\n",
"output": "-1 -1 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n10 10 -10\n",
"output": "10 -11 -10 ",
"type": "stdin_stdout"
},
{
"input": "3\n2 1 -2\n",
"output": "2 -2 -2 ",
"type": "stdin_stdout"
},
{
"input": "3\n-1 1 1\n",
"output": "-1 1 -2 ",
"type": "stdin_stdout"
},
{
"input": "3\n-4 0 2\n",
"output": "3 -1 -3 ",
"type": "stdin_stdout"
},
{
"input": "5\n-1 -1 -1 -1 -1\n",
"output": "0 -1 -1 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "6\n-1 -2 -3 0 0 0\n",
"output": "-1 -2 -3 -1 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n-9 -8 -7\n",
"output": "8 -8 -7 ",
"type": "stdin_stdout"
},
{
"input": "2\n-1 -1\n",
"output": "-1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 -1 -1\n",
"output": "0 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n-1 0 1\n",
"output": "-1 -1 1 ",
"type": "stdin_stdout"
},
{
"input": "2\n0 -1\n",
"output": "-1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n10 -14 -20\n",
"output": "-11 -14 19 ",
"type": "stdin_stdout"
},
{
"input": "3\n-10 2 3\n",
"output": "9 -3 -4 ",
"type": "stdin_stdout"
},
{
"input": "3\n-4 -5 -1\n",
"output": "-4 4 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 2 5\n",
"output": "-1 -3 5 ",
"type": "stdin_stdout"
},
{
"input": "3\n4 0 -4\n",
"output": "4 -1 -4 ",
"type": "stdin_stdout"
},
{
"input": "3\n1 1 -1\n",
"output": "1 -2 -1 ",
"type": "stdin_stdout"
},
{
"input": "5\n-10 -10 -10 -10 -2\n",
"output": "9 -10 -10 -10 -2 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 0 0 -5\n",
"output": "-1 -1 -1 -1 4 ",
"type": "stdin_stdout"
},
{
"input": "6\n0 0 0 -4 -6 -7\n",
"output": "-1 -1 -1 -4 -6 -7 ",
"type": "stdin_stdout"
},
{
"input": "5\n10 11 -1 -2 -3\n",
"output": "-11 11 -1 -2 -3 ",
"type": "stdin_stdout"
},
{
"input": "3\n-6 4 3\n",
"output": "5 -5 -4 ",
"type": "stdin_stdout"
},
{
"input": "1\n4\n",
"output": "4 ",
"type": "stdin_stdout"
},
{
"input": "3\n-3 2 3\n",
"output": "-3 -3 3 ",
"type": "stdin_stdout"
},
{
"input": "4\n0 1 2 3\n",
"output": "-1 -2 -3 -4 ",
"type": "stdin_stdout"
},
{
"input": "3\n3 3 -2\n",
"output": "3 -4 -2 ",
"type": "stdin_stdout"
},
{
"input": "3\n-3 -2 -2\n",
"output": "2 -2 -2 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 -1 1\n",
"output": "-1 -1 1 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 0 -1\n",
"output": "0 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "5\n-4 0 0 0 1\n",
"output": "3 -1 -1 -1 -2 ",
"type": "stdin_stdout"
},
{
"input": "3\n-3 2 2\n",
"output": "2 -3 -3 ",
"type": "stdin_stdout"
},
{
"input": "3\n1 1 -10\n",
"output": "-2 -2 9 ",
"type": "stdin_stdout"
},
{
"input": "3\n-4 1 2\n",
"output": "3 -2 -3 ",
"type": "stdin_stdout"
},
{
"input": "3\n-5 1 -1\n",
"output": "4 -2 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n-1 -2 -3\n",
"output": "-1 -2 2 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 0 0\n",
"output": "0 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "5\n-100 1 2 3 4\n",
"output": "99 -2 -3 -4 -5 ",
"type": "stdin_stdout"
},
{
"input": "3\n1 0 -1\n",
"output": "1 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "1\n5\n",
"output": "5 ",
"type": "stdin_stdout"
},
{
"input": "3\n-1 -1 0\n",
"output": "0 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "5\n2 4 6 8 10\n",
"output": "-3 -5 -7 -9 10 ",
"type": "stdin_stdout"
},
{
"input": "6\n-5 0 0 0 0 0\n",
"output": "-5 -1 -1 -1 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "5\n5 3 2 2 -10\n",
"output": "-6 -4 -3 -3 9 ",
"type": "stdin_stdout"
},
{
"input": "1\n-10\n",
"output": "9 ",
"type": "stdin_stdout"
},
{
"input": "3\n-79 -58 -55\n",
"output": "78 -58 -55 ",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 0 0\n",
"output": "-3 -3 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n-5 1 2\n",
"output": "4 -2 -3 ",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 1 1 -1\n",
"output": "1 -2 -2 -2 -1 ",
"type": "stdin_stdout"
},
{
"input": "4\n3 3 3 -3\n",
"output": "-4 -4 -4 -3 ",
"type": "stdin_stdout"
},
{
"input": "5\n-2 -3 -7 -4 3\n",
"output": "-2 -3 6 -4 -4 ",
"type": "stdin_stdout"
},
{
"input": "7\n-1 -1 -1 -14 -16 -18 -20\n",
"output": "-1 -1 -1 -14 -16 -18 19 ",
"type": "stdin_stdout"
},
{
"input": "3\n4 -8 3\n",
"output": "-5 7 -4 ",
"type": "stdin_stdout"
},
{
"input": "3\n-5 3 3\n",
"output": "4 -4 -4 ",
"type": "stdin_stdout"
},
{
"input": "1\n-2\n",
"output": "1 ",
"type": "stdin_stdout"
},
{
"input": "5\n0 0 0 0 0\n",
"output": "0 -1 -1 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n-3 -3 -3\n",
"output": "2 -3 -3 ",
"type": "stdin_stdout"
},
{
"input": "4\n0 0 -1 -1\n",
"output": "-1 -1 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n-4 0 0\n",
"output": "3 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "4\n-1 -1 0 0\n",
"output": "-1 -1 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n-3 3 2\n",
"output": "-3 3 -3 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 -2 -3\n",
"output": "-1 -2 2 ",
"type": "stdin_stdout"
},
{
"input": "4\n8 3 1 0\n",
"output": "-9 -4 -2 -1 ",
"type": "stdin_stdout"
},
{
"input": "5\n5 5 -1 -1 -1\n",
"output": "5 -6 -1 -1 -1 ",
"type": "stdin_stdout"
},
{
"input": "3\n10 10 -8\n",
"output": "10 -11 -8 ",
"type": "stdin_stdout"
},
{
"input": "6\n-3 -2 0 0 1 2\n",
"output": "-3 -2 -1 -1 -2 -3 ",
"type": "stdin_stdout"
},
{
"input": "3\n0 -1 -2\n",
"output": "-1 -1 1 ",
"type": "stdin_stdout"
},
{
"input": "3\n-6 0 4\n",
"output": "5 -1 -5 ",
"type": "stdin_stdout"
},
{
"input": "5\n-3 -5 -7 2 4\n",
"output": "-3 -5 6 -3 -5 ",
"type": "stdin_stdout"
},
{
"input": "5\n-6 -5 -3 2 3\n",
"output": "5 -5 -3 -3 -4 ",
"type": "stdin_stdout"
},
{
"input": "3\n-9 -8 1\n",
"output": "8 -8 -2 ",
"type": "stdin_stdout"
},
{
"input": "3\n-5 1 1\n",
"output": "4 -2 -2 ",
"type": "stdin_stdout"
},
{
"input": "5\n-150 -100 -100 -100 100\n",
"output": "149 -100 -100 -100 -101 ",
"type": "stdin_stdout"
},
{
"input": "3\n-200 50 60\n",
"output": "199 -51 -61 ",
"type": "stdin_stdout"
},
{
"input": "3\n2 2 -7\n",
"output": "-3 -3 6 ",
"type": "stdin_stdout"
},
{
"input": "3\n-8 -7 5\n",
"output": "7 -7 -6 ",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1180/B"
} | vfc_10194 |
apps | verifiable_code | 111 | Solve the following coding problem using the programming language python:
You are given two integers n and k. Find k-th smallest divisor of n, or report that it doesn't exist.
Divisor of n is any such natural number, that n can be divided by it without remainder.
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 10^15, 1 ≤ k ≤ 10^9).
-----Output-----
If n has less than k divisors, output -1.
Otherwise, output the k-th smallest divisor of n.
-----Examples-----
Input
4 2
Output
2
Input
5 3
Output
-1
Input
12 5
Output
6
-----Note-----
In the first example, number 4 has three divisors: 1, 2 and 4. The second one is 2.
In the second example, number 5 has only two divisors: 1 and 5. The third divisor doesn't exist, 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
import sys
import math
def factorization(n):
res = []
limit = math.ceil(math.sqrt(n))
p = 2
cnt = 0
while n % p == 0:
cnt += 1
n //= p
if cnt > 0:
res.append((p, cnt))
cnt = 0
for p in range(3, limit + 1, 2):
if n % p == 0:
while n % p == 0:
cnt += 1
n //= p
res.append((p, cnt))
cnt = 0
if n > 1:
res.append((n, 1))
return res
def divisor(n):
res = set()
factor = factorization(n)
for p, c in factor:
if res == set():
for i in range(c + 1):
res.add(p ** i)
else:
t = set()
for i in range(1, c + 1):
for m in res:
t.add(m * p**i)
res = res | t
res = list(sorted(res))
return res
n, k = map(int, input().split())
# print(factorization(n), file=sys.stderr)
# print(divisor(n), file=sys.stderr)
n_div = divisor(n)
if n == 1:
if k == 1:
ans = 1
else:
ans = -1
elif k > len(n_div):
ans = -1
else:
ans = n_div[k - 1]
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "4 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "12 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "866421317361600 26880\n",
"output": "866421317361600\n",
"type": "stdin_stdout"
},
{
"input": "866421317361600 26881\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000 1000000000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000 100\n",
"output": "1953125\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9 3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "21 3\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "67280421310721 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "6 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "16 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1 1000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "16 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "36 8\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "49 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "9 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "16 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "16 6\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "16 5\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "25 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4010815561 2\n",
"output": "63331\n",
"type": "stdin_stdout"
},
{
"input": "49 3\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "36 6\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "36 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "25 3\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "22876792454961 28\n",
"output": "7625597484987\n",
"type": "stdin_stdout"
},
{
"input": "1234 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "179458711 2\n",
"output": "179458711\n",
"type": "stdin_stdout"
},
{
"input": "900104343024121 100000\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "8 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "100 6\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "15500 26\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "111111 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100000000000000 200\n",
"output": "160000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000 100\n",
"output": "6400000\n",
"type": "stdin_stdout"
},
{
"input": "100 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000039 2\n",
"output": "1000000000039\n",
"type": "stdin_stdout"
},
{
"input": "64 5\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "999999961946176 33\n",
"output": "63245552\n",
"type": "stdin_stdout"
},
{
"input": "376219076689 3\n",
"output": "376219076689\n",
"type": "stdin_stdout"
},
{
"input": "999999961946176 63\n",
"output": "999999961946176\n",
"type": "stdin_stdout"
},
{
"input": "1048576 12\n",
"output": "2048\n",
"type": "stdin_stdout"
},
{
"input": "745 21\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "748 6\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "999999961946176 50\n",
"output": "161082468097\n",
"type": "stdin_stdout"
},
{
"input": "10 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1099511627776 22\n",
"output": "2097152\n",
"type": "stdin_stdout"
},
{
"input": "1000000007 100010\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 8\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "100 7\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "7 2\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "999999961946176 64\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "999999999999989 2\n",
"output": "999999999999989\n",
"type": "stdin_stdout"
},
{
"input": "100000000000000 114\n",
"output": "10240000\n",
"type": "stdin_stdout"
},
{
"input": "99999640000243 3\n",
"output": "9999991\n",
"type": "stdin_stdout"
},
{
"input": "999998000001 566\n",
"output": "333332666667\n",
"type": "stdin_stdout"
},
{
"input": "99999820000081 2\n",
"output": "9999991\n",
"type": "stdin_stdout"
},
{
"input": "49000042000009 3\n",
"output": "49000042000009\n",
"type": "stdin_stdout"
},
{
"input": "151491429961 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "32416190071 2\n",
"output": "32416190071\n",
"type": "stdin_stdout"
},
{
"input": "1000 8\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "1999967841 15\n",
"output": "1999967841\n",
"type": "stdin_stdout"
},
{
"input": "26880 26880\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "151491429961 3\n",
"output": "151491429961\n",
"type": "stdin_stdout"
},
{
"input": "90000000000 300\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "98765004361 10\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "15 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "16 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1996 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1997 2\n",
"output": "1997\n",
"type": "stdin_stdout"
},
{
"input": "1999 2\n",
"output": "1999\n",
"type": "stdin_stdout"
},
{
"input": "1998 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1998 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1998 7\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "1998 8\n",
"output": "37\n",
"type": "stdin_stdout"
},
{
"input": "100000380000361 2\n",
"output": "10000019\n",
"type": "stdin_stdout"
},
{
"input": "15 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100000000000000 226\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "844030857550613 517\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4567890 14\n",
"output": "430\n",
"type": "stdin_stdout"
},
{
"input": "123123123 123123123\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "24 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "999999993568952 17\n",
"output": "31622777\n",
"type": "stdin_stdout"
},
{
"input": "99999999994190 9\n",
"output": "241656799\n",
"type": "stdin_stdout"
},
{
"input": "999997874844049 4\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "99999999999931 2\n",
"output": "99999999999931\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "67280421310721 2\n",
"output": "67280421310721\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/762/A"
} | vfc_10198 |
apps | verifiable_code | 113 | Solve the following coding problem using the programming language python:
For a given positive integer n denote its k-rounding as the minimum positive integer x, such that x ends with k or more zeros in base 10 and is divisible by n.
For example, 4-rounding of 375 is 375·80 = 30000. 30000 is the minimum integer such that it ends with 4 or more zeros and is divisible by 375.
Write a program that will perform the k-rounding of n.
-----Input-----
The only line contains two integers n and k (1 ≤ n ≤ 10^9, 0 ≤ k ≤ 8).
-----Output-----
Print the k-rounding of n.
-----Examples-----
Input
375 4
Output
30000
Input
10000 1
Output
10000
Input
38101 0
Output
38101
Input
123456789 8
Output
12345678900000000
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, k = map(int, input().split())
num_2 = 0
num_5 = 0
x = n
while (x % 2 == 0):
num_2 += 1
x //= 2
while (x % 5 == 0):
num_5 += 1
x //= 5
num_2 = k - min(num_2, k)
num_5 = k - min(num_5, k)
print(n * 5 ** num_5 * 2 ** num_2)
main()
``` | {
"language": "python",
"test_cases": [
{
"input": "375 4\n",
"output": "30000\n",
"type": "stdin_stdout"
},
{
"input": "10000 1\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "38101 0\n",
"output": "38101\n",
"type": "stdin_stdout"
},
{
"input": "123456789 8\n",
"output": "12345678900000000\n",
"type": "stdin_stdout"
},
{
"input": "1 0\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 0\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "100 0\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 0\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "160 2\n",
"output": "800\n",
"type": "stdin_stdout"
},
{
"input": "3 0\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10 0\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "7 1\n",
"output": "70\n",
"type": "stdin_stdout"
},
{
"input": "8 1\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "9 1\n",
"output": "90\n",
"type": "stdin_stdout"
},
{
"input": "10 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "11 1\n",
"output": "110\n",
"type": "stdin_stdout"
},
{
"input": "12 1\n",
"output": "60\n",
"type": "stdin_stdout"
},
{
"input": "16 2\n",
"output": "400\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "15 2\n",
"output": "300\n",
"type": "stdin_stdout"
},
{
"input": "36 2\n",
"output": "900\n",
"type": "stdin_stdout"
},
{
"input": "1 8\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "8 8\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "96 8\n",
"output": "300000000\n",
"type": "stdin_stdout"
},
{
"input": "175 8\n",
"output": "700000000\n",
"type": "stdin_stdout"
},
{
"input": "9999995 8\n",
"output": "199999900000000\n",
"type": "stdin_stdout"
},
{
"input": "999999999 8\n",
"output": "99999999900000000\n",
"type": "stdin_stdout"
},
{
"input": "12345678 8\n",
"output": "617283900000000\n",
"type": "stdin_stdout"
},
{
"input": "78125 8\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "390625 8\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "1953125 8\n",
"output": "500000000\n",
"type": "stdin_stdout"
},
{
"input": "9765625 8\n",
"output": "2500000000\n",
"type": "stdin_stdout"
},
{
"input": "68359375 8\n",
"output": "17500000000\n",
"type": "stdin_stdout"
},
{
"input": "268435456 8\n",
"output": "104857600000000\n",
"type": "stdin_stdout"
},
{
"input": "125829120 8\n",
"output": "9830400000000\n",
"type": "stdin_stdout"
},
{
"input": "128000 8\n",
"output": "400000000\n",
"type": "stdin_stdout"
},
{
"input": "300000 8\n",
"output": "300000000\n",
"type": "stdin_stdout"
},
{
"input": "3711871 8\n",
"output": "371187100000000\n",
"type": "stdin_stdout"
},
{
"input": "55555 8\n",
"output": "1111100000000\n",
"type": "stdin_stdout"
},
{
"input": "222222222 8\n",
"output": "11111111100000000\n",
"type": "stdin_stdout"
},
{
"input": "479001600 8\n",
"output": "7484400000000\n",
"type": "stdin_stdout"
},
{
"input": "655360001 7\n",
"output": "6553600010000000\n",
"type": "stdin_stdout"
},
{
"input": "655360001 8\n",
"output": "65536000100000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 7\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 8\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "100000000 8\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "10000000 8\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000 8\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "10000009 8\n",
"output": "1000000900000000\n",
"type": "stdin_stdout"
},
{
"input": "10000005 8\n",
"output": "200000100000000\n",
"type": "stdin_stdout"
},
{
"input": "10000002 8\n",
"output": "500000100000000\n",
"type": "stdin_stdout"
},
{
"input": "999999997 8\n",
"output": "99999999700000000\n",
"type": "stdin_stdout"
},
{
"input": "999999997 7\n",
"output": "9999999970000000\n",
"type": "stdin_stdout"
},
{
"input": "999999995 8\n",
"output": "19999999900000000\n",
"type": "stdin_stdout"
},
{
"input": "123 8\n",
"output": "12300000000\n",
"type": "stdin_stdout"
},
{
"input": "24 2\n",
"output": "600\n",
"type": "stdin_stdout"
},
{
"input": "16 4\n",
"output": "10000\n",
"type": "stdin_stdout"
},
{
"input": "123456787 8\n",
"output": "12345678700000000\n",
"type": "stdin_stdout"
},
{
"input": "100000000 8\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "7 1\n",
"output": "70\n",
"type": "stdin_stdout"
},
{
"input": "101 1\n",
"output": "1010\n",
"type": "stdin_stdout"
},
{
"input": "50 2\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "999999818 1\n",
"output": "4999999090\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "123 1\n",
"output": "1230\n",
"type": "stdin_stdout"
},
{
"input": "16 1\n",
"output": "80\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 8\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "15304 6\n",
"output": "1913000000\n",
"type": "stdin_stdout"
},
{
"input": "3 8\n",
"output": "300000000\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "100000 7\n",
"output": "10000000\n",
"type": "stdin_stdout"
},
{
"input": "5 8\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "16724 6\n",
"output": "4181000000\n",
"type": "stdin_stdout"
},
{
"input": "999999999 1\n",
"output": "9999999990\n",
"type": "stdin_stdout"
},
{
"input": "999999990 8\n",
"output": "9999999900000000\n",
"type": "stdin_stdout"
},
{
"input": "999999999 8\n",
"output": "99999999900000000\n",
"type": "stdin_stdout"
},
{
"input": "100000 1\n",
"output": "100000\n",
"type": "stdin_stdout"
},
{
"input": "8 3\n",
"output": "1000\n",
"type": "stdin_stdout"
},
{
"input": "16768 6\n",
"output": "262000000\n",
"type": "stdin_stdout"
},
{
"input": "123456789 1\n",
"output": "1234567890\n",
"type": "stdin_stdout"
},
{
"input": "2 8\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "999999937 8\n",
"output": "99999993700000000\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "2000000 7\n",
"output": "10000000\n",
"type": "stdin_stdout"
},
{
"input": "1999998 2\n",
"output": "99999900\n",
"type": "stdin_stdout"
},
{
"input": "125 3\n",
"output": "1000\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/858/A"
} | vfc_10206 |
apps | verifiable_code | 115 | Solve the following coding problem using the programming language python:
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
-----Input-----
The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively.
-----Output-----
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10^{ - 9}.
-----Examples-----
Input
2 2 2
Output
0.333333333333 0.333333333333 0.333333333333
Input
2 1 2
Output
0.150000000000 0.300000000000 0.550000000000
Input
1 1 3
Output
0.057142857143 0.657142857143 0.285714285714
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
r, s, p = list(map(int, input().split()))
dp = [[[0] * (p+1) for _ in range(s+1)] for _ in range(r+1)]
dp[r][s][p] = 1
def nCk(n, k):
if n <= k:
return 1
res = 1
for i in range(k):
res *= n-i
for i in range(k):
res //= (i+1)
return res
C = [nCk(i, 2) for i in range(r+s+p+1)]
for ri in range(r, -1, -1):
for si in range(s, -1, -1):
for pi in range(p, -1, -1):
t = ri * si + si * pi + pi * ri
if t == 0: continue
if ri > 0:
dp[ri-1][si][pi] += dp[ri][si][pi] * ri * pi / t
if si > 0:
dp[ri][si-1][pi] += dp[ri][si][pi] * ri * si / t
if pi > 0:
dp[ri][si][pi-1] += dp[ri][si][pi] * si * pi / t
r_sum = sum([dp[ri][0][0] for ri in range(r+1)])
s_sum = sum([dp[0][si][0] for si in range(s+1)])
p_sum = sum([dp[0][0][pi] for pi in range(p+1)])
print(r_sum, s_sum, p_sum)
``` | {
"language": "python",
"test_cases": [
{
"input": "2 2 2\n",
"output": "0.333333333333 0.333333333333 0.333333333333\n",
"type": "stdin_stdout"
},
{
"input": "2 1 2\n",
"output": "0.150000000000 0.300000000000 0.550000000000\n",
"type": "stdin_stdout"
},
{
"input": "1 1 3\n",
"output": "0.057142857143 0.657142857143 0.285714285714\n",
"type": "stdin_stdout"
},
{
"input": "3 2 1\n",
"output": "0.487662337662 0.072077922078 0.440259740260\n",
"type": "stdin_stdout"
},
{
"input": "100 100 100\n",
"output": "0.333333333333 0.333333333333 0.333333333333\n",
"type": "stdin_stdout"
},
{
"input": "1 100 100\n",
"output": "0.366003713151 0.633996286849 0.000000000000\n",
"type": "stdin_stdout"
},
{
"input": "100 1 100\n",
"output": "0.000000000000 0.366003713151 0.633996286849\n",
"type": "stdin_stdout"
},
{
"input": "100 100 1\n",
"output": "0.633996286849 0.000000000000 0.366003713151\n",
"type": "stdin_stdout"
},
{
"input": "1 100 99\n",
"output": "0.369700913626 0.630299086374 0.000000000000\n",
"type": "stdin_stdout"
},
{
"input": "99 1 100\n",
"output": "0.000000000000 0.369700913626 0.630299086374\n",
"type": "stdin_stdout"
},
{
"input": "100 99 1\n",
"output": "0.630299086374 0.000000000000 0.369700913626\n",
"type": "stdin_stdout"
},
{
"input": "100 1 99\n",
"output": "0.000000000000 0.362287378787 0.637712621213\n",
"type": "stdin_stdout"
},
{
"input": "1 99 100\n",
"output": "0.362287378787 0.637712621213 0.000000000000\n",
"type": "stdin_stdout"
},
{
"input": "99 100 1\n",
"output": "0.637712621213 0.000000000000 0.362287378787\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n",
"output": "0.333333333333 0.333333333333 0.333333333333\n",
"type": "stdin_stdout"
},
{
"input": "100 100 2\n",
"output": "0.405362332237 0.000000000000 0.594637667763\n",
"type": "stdin_stdout"
},
{
"input": "100 2 100\n",
"output": "0.000000000000 0.594637667763 0.405362332237\n",
"type": "stdin_stdout"
},
{
"input": "2 100 100\n",
"output": "0.594637667763 0.405362332237 0.000000000000\n",
"type": "stdin_stdout"
},
{
"input": "3 3 3\n",
"output": "0.333333333333 0.333333333333 0.333333333333\n",
"type": "stdin_stdout"
},
{
"input": "44 54 32\n",
"output": "0.106782618787 0.143399200449 0.749818180764\n",
"type": "stdin_stdout"
},
{
"input": "100 90 5\n",
"output": "0.082441556638 0.000000001849 0.917558441513\n",
"type": "stdin_stdout"
},
{
"input": "90 5 100\n",
"output": "0.000000001849 0.917558441513 0.082441556638\n",
"type": "stdin_stdout"
},
{
"input": "5 100 90\n",
"output": "0.917558441513 0.082441556638 0.000000001849\n",
"type": "stdin_stdout"
},
{
"input": "100 5 90\n",
"output": "0.000000005097 0.850289405958 0.149710588945\n",
"type": "stdin_stdout"
},
{
"input": "5 90 100\n",
"output": "0.850289405958 0.149710588945 0.000000005097\n",
"type": "stdin_stdout"
},
{
"input": "90 100 5\n",
"output": "0.149710588945 0.000000005097 0.850289405958\n",
"type": "stdin_stdout"
},
{
"input": "4 4 4\n",
"output": "0.333333333333 0.333333333333 0.333333333333\n",
"type": "stdin_stdout"
},
{
"input": "35 38 78\n",
"output": "0.686231300287 0.301686382598 0.012082317115\n",
"type": "stdin_stdout"
},
{
"input": "100 98 99\n",
"output": "0.336951942791 0.350590779089 0.312457278120\n",
"type": "stdin_stdout"
},
{
"input": "98 100 99\n",
"output": "0.329240307786 0.316221888918 0.354537803296\n",
"type": "stdin_stdout"
},
{
"input": "98 99 100\n",
"output": "0.350590779089 0.312457278120 0.336951942791\n",
"type": "stdin_stdout"
},
{
"input": "100 99 98\n",
"output": "0.316221888918 0.354537803296 0.329240307786\n",
"type": "stdin_stdout"
},
{
"input": "99 100 98\n",
"output": "0.312457278120 0.336951942791 0.350590779089\n",
"type": "stdin_stdout"
},
{
"input": "99 98 100\n",
"output": "0.354537803296 0.329240307786 0.316221888918\n",
"type": "stdin_stdout"
},
{
"input": "5 5 5\n",
"output": "0.333333333333 0.333333333333 0.333333333333\n",
"type": "stdin_stdout"
},
{
"input": "100 100 99\n",
"output": "0.320730423530 0.341631521601 0.337638054869\n",
"type": "stdin_stdout"
},
{
"input": "100 99 100\n",
"output": "0.341631521601 0.337638054869 0.320730423530\n",
"type": "stdin_stdout"
},
{
"input": "99 100 100\n",
"output": "0.337638054869 0.320730423530 0.341631521601\n",
"type": "stdin_stdout"
},
{
"input": "100 99 99\n",
"output": "0.328877908413 0.346125932336 0.324996159251\n",
"type": "stdin_stdout"
},
{
"input": "99 100 99\n",
"output": "0.324996159251 0.328877908413 0.346125932336\n",
"type": "stdin_stdout"
},
{
"input": "99 99 100\n",
"output": "0.346125932336 0.324996159251 0.328877908413\n",
"type": "stdin_stdout"
},
{
"input": "19 18 23\n",
"output": "0.367367874268 0.441556405078 0.191075720654\n",
"type": "stdin_stdout"
},
{
"input": "80 80 80\n",
"output": "0.333333333333 0.333333333333 0.333333333333\n",
"type": "stdin_stdout"
},
{
"input": "80 80 78\n",
"output": "0.304007530347 0.347995449492 0.347997020160\n",
"type": "stdin_stdout"
},
{
"input": "80 80 79\n",
"output": "0.318598848470 0.340767700830 0.340633450700\n",
"type": "stdin_stdout"
},
{
"input": "80 80 81\n",
"output": "0.348184483745 0.325727680711 0.326087835544\n",
"type": "stdin_stdout"
},
{
"input": "80 78 80\n",
"output": "0.347995449492 0.347997020160 0.304007530347\n",
"type": "stdin_stdout"
},
{
"input": "80 79 80\n",
"output": "0.340767700830 0.340633450700 0.318598848470\n",
"type": "stdin_stdout"
},
{
"input": "80 81 80\n",
"output": "0.325727680711 0.326087835544 0.348184483745\n",
"type": "stdin_stdout"
},
{
"input": "78 80 80\n",
"output": "0.347997020160 0.304007530347 0.347995449492\n",
"type": "stdin_stdout"
},
{
"input": "79 80 80\n",
"output": "0.340633450700 0.318598848470 0.340767700830\n",
"type": "stdin_stdout"
},
{
"input": "81 80 80\n",
"output": "0.326087835544 0.348184483745 0.325727680711\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1\n",
"output": "0.333333333333 0.133333333333 0.533333333333\n",
"type": "stdin_stdout"
},
{
"input": "1 2 1\n",
"output": "0.533333333333 0.333333333333 0.133333333333\n",
"type": "stdin_stdout"
},
{
"input": "1 1 2\n",
"output": "0.133333333333 0.533333333333 0.333333333333\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1\n",
"output": "0.550000000000 0.150000000000 0.300000000000\n",
"type": "stdin_stdout"
},
{
"input": "1 2 2\n",
"output": "0.300000000000 0.550000000000 0.150000000000\n",
"type": "stdin_stdout"
},
{
"input": "1 2 3\n",
"output": "0.174025974026 0.692207792208 0.133766233766\n",
"type": "stdin_stdout"
},
{
"input": "1 3 2\n",
"output": "0.440259740260 0.487662337662 0.072077922078\n",
"type": "stdin_stdout"
},
{
"input": "2 3 1\n",
"output": "0.692207792208 0.133766233766 0.174025974026\n",
"type": "stdin_stdout"
},
{
"input": "3 1 2\n",
"output": "0.133766233766 0.174025974026 0.692207792208\n",
"type": "stdin_stdout"
},
{
"input": "2 1 3\n",
"output": "0.072077922078 0.440259740260 0.487662337662\n",
"type": "stdin_stdout"
},
{
"input": "10 2 69\n",
"output": "0.000000000001 0.979592460371 0.020407539628\n",
"type": "stdin_stdout"
},
{
"input": "99 99 99\n",
"output": "0.333333333333 0.333333333333 0.333333333333\n",
"type": "stdin_stdout"
},
{
"input": "1 100 68\n",
"output": "0.504856156201 0.495143843799 0.000000000000\n",
"type": "stdin_stdout"
},
{
"input": "1 100 69\n",
"output": "0.499807252268 0.500192747732 0.000000000000\n",
"type": "stdin_stdout"
},
{
"input": "100 68 1\n",
"output": "0.495143843799 0.000000000000 0.504856156201\n",
"type": "stdin_stdout"
},
{
"input": "100 69 1\n",
"output": "0.500192747732 0.000000000000 0.499807252268\n",
"type": "stdin_stdout"
},
{
"input": "68 1 100\n",
"output": "0.000000000000 0.504856156201 0.495143843799\n",
"type": "stdin_stdout"
},
{
"input": "69 1 100\n",
"output": "0.000000000000 0.499807252268 0.500192747732\n",
"type": "stdin_stdout"
},
{
"input": "40 100 50\n",
"output": "0.504950275130 0.003137391318 0.491912333552\n",
"type": "stdin_stdout"
},
{
"input": "41 100 50\n",
"output": "0.471692521594 0.003711367492 0.524596110914\n",
"type": "stdin_stdout"
},
{
"input": "100 50 40\n",
"output": "0.003137391318 0.491912333552 0.504950275130\n",
"type": "stdin_stdout"
},
{
"input": "100 50 41\n",
"output": "0.003711367492 0.524596110914 0.471692521594\n",
"type": "stdin_stdout"
},
{
"input": "50 40 100\n",
"output": "0.491912333552 0.504950275130 0.003137391318\n",
"type": "stdin_stdout"
},
{
"input": "50 41 100\n",
"output": "0.524596110914 0.471692521594 0.003711367492\n",
"type": "stdin_stdout"
},
{
"input": "4 3 2\n",
"output": "0.380033049657 0.128974183711 0.490992766632\n",
"type": "stdin_stdout"
},
{
"input": "3 3 2\n",
"output": "0.448942486085 0.194141929499 0.356915584416\n",
"type": "stdin_stdout"
},
{
"input": "3 2 4\n",
"output": "0.128974183711 0.490992766632 0.380033049657\n",
"type": "stdin_stdout"
},
{
"input": "3 2 3\n",
"output": "0.194141929499 0.356915584416 0.448942486085\n",
"type": "stdin_stdout"
},
{
"input": "2 4 3\n",
"output": "0.490992766632 0.380033049657 0.128974183711\n",
"type": "stdin_stdout"
},
{
"input": "2 3 3\n",
"output": "0.356915584416 0.448942486085 0.194141929499\n",
"type": "stdin_stdout"
},
{
"input": "94 62 53\n",
"output": "0.032741579903 0.688734095294 0.278524324802\n",
"type": "stdin_stdout"
},
{
"input": "92 42 99\n",
"output": "0.156634527800 0.841252178878 0.002113293322\n",
"type": "stdin_stdout"
},
{
"input": "57 88 2\n",
"output": "0.628039075774 0.000000000036 0.371960924190\n",
"type": "stdin_stdout"
},
{
"input": "49 85 47\n",
"output": "0.185241468442 0.036259808833 0.778498722726\n",
"type": "stdin_stdout"
},
{
"input": "48 16 81\n",
"output": "0.009800033922 0.990059771027 0.000140195051\n",
"type": "stdin_stdout"
},
{
"input": "39 96 87\n",
"output": "0.856896275913 0.001822013551 0.141281710536\n",
"type": "stdin_stdout"
},
{
"input": "100 91 51\n",
"output": "0.008569274339 0.316910121953 0.674520603708\n",
"type": "stdin_stdout"
},
{
"input": "90 92 97\n",
"output": "0.412664975931 0.267301641052 0.320033383016\n",
"type": "stdin_stdout"
},
{
"input": "86 25 84\n",
"output": "0.016023421282 0.983316299665 0.000660279053\n",
"type": "stdin_stdout"
},
{
"input": "80 1 89\n",
"output": "0.000000000000 0.404923676688 0.595076323312\n",
"type": "stdin_stdout"
},
{
"input": "67 95 88\n",
"output": "0.419687207048 0.074718763764 0.505594029188\n",
"type": "stdin_stdout"
},
{
"input": "50 93 89\n",
"output": "0.693218455167 0.011706551519 0.295074993314\n",
"type": "stdin_stdout"
},
{
"input": "27 71 76\n",
"output": "0.954421631610 0.002613537210 0.042964831180\n",
"type": "stdin_stdout"
},
{
"input": "18 47 22\n",
"output": "0.741659614574 0.008276779449 0.250063605977\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/540/D"
} | vfc_10214 |
apps | verifiable_code | 116 | Solve the following coding problem using the programming language python:
Today an outstanding event is going to happen in the forest — hedgehog Filya will come to his old fried Sonya!
Sonya is an owl and she sleeps during the day and stay awake from minute l_1 to minute r_1 inclusive. Also, during the minute k she prinks and is unavailable for Filya.
Filya works a lot and he plans to visit Sonya from minute l_2 to minute r_2 inclusive.
Calculate the number of minutes they will be able to spend together.
-----Input-----
The only line of the input contains integers l_1, r_1, l_2, r_2 and k (1 ≤ l_1, r_1, l_2, r_2, k ≤ 10^18, l_1 ≤ r_1, l_2 ≤ r_2), providing the segments of time for Sonya and Filya and the moment of time when Sonya prinks.
-----Output-----
Print one integer — the number of minutes Sonya and Filya will be able to spend together.
-----Examples-----
Input
1 10 9 20 1
Output
2
Input
1 100 50 200 75
Output
50
-----Note-----
In the first sample, they will be together during minutes 9 and 10.
In the second sample, they will be together from minute 50 to minute 74 and from minute 76 to minute 100.
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()))
l1, r1, l2, r2, k = read()
R = min(r1, r2)
L = max(l1, l2)
ans = max(R - L + 1, 0)
if L <= k <= R: ans = max(ans - 1, 0)
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "1 10 9 20 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1 100 50 200 75\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "6 6 5 8 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000 1 1000000000 1\n",
"output": "999999999\n",
"type": "stdin_stdout"
},
{
"input": "5 100 8 8 8\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000000000000 2 99999999999999999 1000000000\n",
"output": "99999999999999997\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 3 4 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000 2 999999999 3141592\n",
"output": "999999997\n",
"type": "stdin_stdout"
},
{
"input": "24648817341102 41165114064236 88046848035 13602161452932 10000831349205\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1080184299348 34666828555290 6878390132365 39891656267344 15395310291636\n",
"output": "27788438422925\n",
"type": "stdin_stdout"
},
{
"input": "11814 27385 22309 28354 23595\n",
"output": "5076\n",
"type": "stdin_stdout"
},
{
"input": "4722316546398 36672578279675 796716437180 33840047334985 13411035401708\n",
"output": "29117730788587\n",
"type": "stdin_stdout"
},
{
"input": "14300093617438 14381698008501 6957847034861 32510754974307 66056597033082\n",
"output": "81604391064\n",
"type": "stdin_stdout"
},
{
"input": "700062402405871919 762322967106512617 297732773882447821 747309903322652819 805776739998108178\n",
"output": "47247500916780901\n",
"type": "stdin_stdout"
},
{
"input": "59861796371397621 194872039092923459 668110259718450585 841148673332698972 928360292123223779\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "298248781360904821 346420922793050061 237084570581741798 726877079564549183 389611850470532358\n",
"output": "48172141432145241\n",
"type": "stdin_stdout"
},
{
"input": "420745791717606818 864206437350900994 764928840030524015 966634105370748487 793326512080703489\n",
"output": "99277597320376979\n",
"type": "stdin_stdout"
},
{
"input": "519325240668210886 776112702001665034 360568516809443669 875594219634943179 994594983925273138\n",
"output": "256787461333454149\n",
"type": "stdin_stdout"
},
{
"input": "170331212821058551 891149660635282032 125964175621755330 208256491683509799 526532153531983174\n",
"output": "37925278862451249\n",
"type": "stdin_stdout"
},
{
"input": "1 3 3 5 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 5 8 10 9\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 4 5 10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 2 3 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 4 3 7 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 2 9 10 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 15 1 10 5\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 4 9 20 25\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 4 1 2 5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 1000 1 100 2\n",
"output": "91\n",
"type": "stdin_stdout"
},
{
"input": "1 3 3 8 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 6 6 8 9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 3 1 4 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 2 2 3 100\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 2 100 120 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 3 5 7 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 3 5 7 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 4 8 10 6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5 6 100\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5 10 20\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5 6 7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 5 7 12 6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 20 50 100 80\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5 10 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5 6 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 9 1 2 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "50 100 1 20 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 20 3 7 30\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 5 10 10 100\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 101 1 2 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 5 10 20 6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 10 15 25 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5 10 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 3 5 6 100\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 4 5 6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6 10 1 2 40\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20 30 1 5 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20 40 50 100 50\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1 4 9 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5 6 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 100 400 500 450\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 6 1 2 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 10 21 30 50\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 200 300 400 101\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 8 12 16 9\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 5 7 9 6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "300 400 100 200 101\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 2 3 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 10 100 200 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 3 3 4 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10 20 30 40 25\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5 10 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 4 8 10 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 5 10 15 7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 200 5 10 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 100 200 300\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "30 100 10 20 25\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 20 1 5 6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 5 1 2 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "11 100 1 9 1000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1 10 10 228\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 7 10 20 15\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 3 8 9 7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 10 2 8 8\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1 5 9 15 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 3 5 6 12\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 100 500 1000 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1 1 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1000 100 1000 200\n",
"output": "900\n",
"type": "stdin_stdout"
},
{
"input": "4 5 1 4 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 5 5 7 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 4 4 10 11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1 3 4 100\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 4 3 5 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10 100 20 30 40\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "5 9 1 11 7\n",
"output": "4\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/714/A"
} | vfc_10218 |
apps | verifiable_code | 118 | Solve the following coding problem using the programming language python:
Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t + s, t + s + 1, t + 2s, t + 2s + 1, etc.
[Image]
Barney woke up in the morning and wants to eat the pineapple, but he can't eat it when it's barking. Barney plans to eat it at time x (in seconds), so he asked you to tell him if it's gonna bark at that time.
-----Input-----
The first and only line of input contains three integers t, s and x (0 ≤ t, x ≤ 10^9, 2 ≤ s ≤ 10^9) — the time the pineapple barks for the first time, the pineapple barking interval, and the time Barney wants to eat the pineapple respectively.
-----Output-----
Print a single "YES" (without quotes) if the pineapple will bark at time x or a single "NO" (without quotes) otherwise in the only line of output.
-----Examples-----
Input
3 10 4
Output
NO
Input
3 10 3
Output
YES
Input
3 8 51
Output
YES
Input
3 8 52
Output
YES
-----Note-----
In the first and the second sample cases pineapple will bark at moments 3, 13, 14, ..., so it won't bark at the moment 4 and will bark at the moment 3.
In the third and fourth sample cases pineapple will bark at moments 3, 11, 12, 19, 20, 27, 28, 35, 36, 43, 44, 51, 52, 59, ..., so it will bark at both moments 51 and 52.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
t, s, x = list(map(int, input().split()))
f = False
if x - 1 > t and (x - 1 - t) % s == 0:
f = True
if x >= t and (x - t) % s == 0:
f = True
if f:
print('YES')
else:
print('NO')
``` | {
"language": "python",
"test_cases": [
{
"input": "3 10 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 10 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 8 51\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 8 52\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "456947336 740144 45\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "33 232603 599417964\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4363010 696782227 701145238\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9295078 2 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "76079 281367 119938421\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "93647 7 451664565\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 18553 10908\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 52 30\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6431 855039 352662\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "749399100 103031711 761562532\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "21 65767 55245\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4796601 66897 4860613\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8 6728951 860676\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "914016 6 914019\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "60686899 78474 60704617\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 743604 201724\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "571128 973448796 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "688051712 67 51\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "74619 213344 6432326\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6947541 698167 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "83 6 6772861\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "251132 67561 135026988\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8897216 734348516 743245732\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "50 64536 153660266\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "876884 55420 971613604\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 6906451 366041903\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "11750 8 446010134\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "582692707 66997 925047377\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "11 957526890 957526901\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "556888 514614196 515171084\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 328006 584834704\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4567998 4 204966403\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "60 317278 109460971\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "906385 342131991 685170368\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 38 902410512\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "29318 787017 587931018\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "351416375 243431 368213115\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "54 197366062 197366117\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "586389 79039 850729874\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "723634470 2814619 940360134\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 2 0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 2 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 10 23\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 2 999999999\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 5 11\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 10 20\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 999999937\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 3 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 2 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 4 0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 215 403\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 2 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 2 900000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 79 4000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 1000 1000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 5 103\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 2 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "120 2 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 5 13\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 5 15\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "11 2 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 8 53\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 4 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 3 9\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 6 19\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 10 125\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 3 8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 3 9\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 3 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 3 300000035\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 2 7\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 5 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 2 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "0 3 999999998\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "0 10001 0\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 5 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 5 1000000000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 3 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3 0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 5 10\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/697/A"
} | vfc_10226 |
apps | verifiable_code | 119 | Solve the following coding problem using the programming language python:
You are given a sequence a_1, a_2, ..., a_{n} of one-dimensional segments numbered 1 through n. Your task is to find two distinct indices i and j such that segment a_{i} lies within segment a_{j}.
Segment [l_1, r_1] lies within segment [l_2, r_2] iff l_1 ≥ l_2 and r_1 ≤ r_2.
Print indices i and j. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 3·10^5) — the number of segments.
Each of the next n lines contains two integers l_{i} and r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ 10^9) — the i-th segment.
-----Output-----
Print two distinct indices i and j such that segment a_{i} lies within segment a_{j}. If there are multiple answers, print any of them. If no answer exists, print -1 -1.
-----Examples-----
Input
5
1 10
2 9
3 9
2 3
2 9
Output
2 1
Input
3
1 5
2 6
6 20
Output
-1 -1
-----Note-----
In the first example the following pairs are considered correct: (2, 1), (3, 1), (4, 1), (5, 1) — not even touching borders; (3, 2), (4, 2), (3, 5), (4, 5) — touch one border; (5, 2), (2, 5) — match exactly.
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 = []
for i in range(1, n + 1):
l, r = list(map(int, input().split()))
a.append([l, -r, i])
a.sort()
hh = a[0][1]
wahh = max(-1, a[0][2])
for i in range(1, n):
if a[i][1] >= hh:
print(a[i][2], wahh)
return
else:
hh = a[i][1]
wahh = a[i][2]
print(-1, -1)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n1 10\n2 9\n3 9\n2 3\n2 9\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 5\n2 6\n6 20\n",
"output": "-1 -1\n",
"type": "stdin_stdout"
},
{
"input": "1\n1 1000000000\n",
"output": "-1 -1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1000000000\n1 1000000000\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1000000000\n500000000 500000000\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 10\n2 10\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "2\n10 20\n10 11\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 10\n10 20\n9 11\n",
"output": "-1 -1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n2 3\n2 2\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 10\n2 11\n3 10000000\n3 100000000\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 7\n3 9\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2\n2 3\n1 2\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 6\n4 7\n3 8\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 9\n1 7\n2 8\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 4\n1 5\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2\n1 3\n4 4\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2\n1 3\n67 1234567\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n1 1\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 5\n4 7\n3 9\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n1 10\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n1 3\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 10\n1 11\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n1 2\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 3\n2 4\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 3\n3 3\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 10\n11 13\n12 12\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 10\n1 10\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 3\n4 5\n4 4\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1\n2 6\n3 5\n10 15\n20 25\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1000\n1001 1007\n1002 1007\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 3\n2 5\n3 4\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 10\n2 11\n3 11\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n2000000 999999999\n1000000 1000000000\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 10\n11 12\n4 5\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 10\n1 19\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 3\n100 102\n108 110\n1 3\n",
"output": "4 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 3\n5 9\n5 6\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 3\n3 4\n3 5\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2\n1 3\n1 4\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 3\n1 4\n100 200\n1000 2000\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n2 100\n3 99\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2\n1 3\n12 1234\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 4\n2 6\n3 5\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 10\n2 12\n1 9\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 3\n1 5\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2\n2 5\n2 3\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 3\n1 4\n5 10\n11 13\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n7 15\n6 9\n9 10\n10 11\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 3\n100 200\n1000 2000\n1 4\n",
"output": "1 4\n",
"type": "stdin_stdout"
},
{
"input": "3\n10 20\n5 9\n11 19\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 6\n6 7\n7 8\n8 9\n9 10\n",
"output": "6 7\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 4\n1 7\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 11\n2 12\n2 13\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 4\n1 8\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 5\n1 5\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 9\n1 10\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 4\n2 4\n1 3\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "6\n10 11\n12 13\n15 16\n15 17\n18 19\n59 60\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 3\n1 7\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n4 6\n7 60\n80 90\n4 5\n8 80\n",
"output": "4 1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 3\n1 4\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 9\n1 7\n2 9\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 4\n1 6\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 4\n2 3\n4 5\n",
"output": "1 3\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 5\n1 7\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 2\n1 4\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1\n2 2\n5 10\n2 4\n",
"output": "2 4\n",
"type": "stdin_stdout"
},
{
"input": "3\n11 12\n11 15\n43 45\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 3\n2 4\n2 5\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 3\n2 5\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 3\n1 4\n1 5\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1\n1 2\n1 3\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 3\n1 3\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "11\n22226 28285\n9095 23314\n19162 25530\n255 13298\n4904 25801\n17914 23501\n8441 28117\n11880 29994\n11123 19874\n21505 27971\n7658 14109\n",
"output": "11 5\n",
"type": "stdin_stdout"
},
{
"input": "8\n4 11\n5 12\n6 13\n7 14\n8 15\n9 16\n10 17\n1 11\n",
"output": "1 8\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 10\n12 15\n1 3\n17 18\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 5\n1 10\n1 20\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1000\n1001 1003\n1 1\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 10\n2 11\n2 11\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n1 3\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 5\n1 6\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 5\n3 6\n1 4\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 8\n1 3\n2 9\n1 2\n",
"output": "4 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 6\n1 3\n3 9\n",
"output": "1 3\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 40\n5 50\n10 60\n3 45\n1 40\n100 111\n",
"output": "1 5\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2\n4 4\n3 3\n2 3\n",
"output": "3 4\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1\n4 5\n7 9\n1 1\n",
"output": "4 1\n",
"type": "stdin_stdout"
},
{
"input": "6\n30 35\n18 29\n28 32\n4 9\n1002 129212\n8 281\n",
"output": "2 6\n",
"type": "stdin_stdout"
},
{
"input": "2\n10 13\n10 14\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 4\n3 6\n4 5\n222 333\n111 444\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2\n4 5\n1 1\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 100\n1 100\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 10\n9 20\n3 5\n",
"output": "3 1\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 9\n1 10\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 2\n1 4\n1 6\n",
"output": "2 3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/976/C"
} | vfc_10230 |
apps | verifiable_code | 120 | Solve the following coding problem using the programming language python:
The process of mammoth's genome decoding in Berland comes to its end!
One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or 'T'. Unrecognized nucleotides are coded by a question mark '?'. Thus, s is a string consisting of letters 'A', 'C', 'G', 'T' and characters '?'.
It is known that the number of nucleotides of each of the four types in the decoded genome of mammoth in Berland should be equal.
Your task is to decode the genome and replace each unrecognized nucleotide with one of the four types so that the number of nucleotides of each of the four types becomes equal.
-----Input-----
The first line contains the integer n (4 ≤ n ≤ 255) — the length of the genome.
The second line contains the string s of length n — the coded genome. It consists of characters 'A', 'C', 'G', 'T' and '?'.
-----Output-----
If it is possible to decode the genome, print it. If there are multiple answer, print any of them. If it is not possible, print three equals signs in a row: "===" (without quotes).
-----Examples-----
Input
8
AG?C??CT
Output
AGACGTCT
Input
4
AGCT
Output
AGCT
Input
6
????G?
Output
===
Input
4
AA??
Output
===
-----Note-----
In the first example you can replace the first question mark with the letter 'A', the second question mark with the letter 'G', the third question mark with the letter 'T', then each nucleotide in the genome would be presented twice.
In the second example the genome is already decoded correctly and each nucleotide is exactly once in it.
In the third and the fourth examples it is impossible to decode the genom.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n=int(input())
if n%4: print("===")
else:
t=input().strip()
a=[n//4]*4
for i in t:
if i=='A': a[0]-=1
elif i=='C': a[1]-=1
elif i=='G': a[2]-=1
elif i=='T': a[3]-=1
if min(a)<0: print("===")
else:
out=[]
for i in t:
if i=='?':
if a[0]:
out.append('A')
a[0]-=1
elif a[1]:
out.append('C')
a[1]-=1
elif a[2]:
out.append('G')
a[2]-=1
elif a[3]:
out.append('T')
a[3]-=1
else: out.append(i)
print("".join(out))
``` | {
"language": "python",
"test_cases": [
{
"input": "8\nAG?C??CT\n",
"output": "AGACGTCT\n",
"type": "stdin_stdout"
},
{
"input": "4\nAGCT\n",
"output": "AGCT\n",
"type": "stdin_stdout"
},
{
"input": "6\n????G?\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "4\nAA??\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "4\n????\n",
"output": "ACGT\n",
"type": "stdin_stdout"
},
{
"input": "252\n???????GCG??T??TT?????T?C???C?CCG???GA???????AC??A???AAC?C?CC??CCC??A??TA?CCC??T???C??CA???CA??G????C?C?C????C??C??A???C?T????C??ACGC??CC?A?????A??CC?C??C?CCG?C??C??A??CG?A?????A?CT???CC????CCC?CATC?G??????????A???????????????TCCCC?C?CA??AC??GC????????\n",
"output": "AAAAAAAGCGAATAATTAAAAATACAAACACCGAAAGAAAAAAAAACAAAAAAAACACACCAACCCAAAACTACCCCCCTCCCCCGCAGGGCAGGGGGGGCGCGCGGGGCGGCGGAGGGCGTGGGGCGGACGCGGCCGAGGGGGAGGCCGCGGCGCCGGCGGCGGAGGCGGAGTTTTATCTTTTCCTTTTCCCTCATCTGTTTTTTTTTTATTTTTTTTTTTTTTTTCCCCTCTCATTACTTGCTTTTTTTT\n",
"type": "stdin_stdout"
},
{
"input": "255\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "4\n??A?\n",
"output": "CGAT\n",
"type": "stdin_stdout"
},
{
"input": "4\n?C??\n",
"output": "ACGT\n",
"type": "stdin_stdout"
},
{
"input": "4\nT???\n",
"output": "TACG\n",
"type": "stdin_stdout"
},
{
"input": "4\n???G\n",
"output": "ACTG\n",
"type": "stdin_stdout"
},
{
"input": "4\n??AC\n",
"output": "GTAC\n",
"type": "stdin_stdout"
},
{
"input": "8\n?C?AA???\n",
"output": "CCGAAGTT\n",
"type": "stdin_stdout"
},
{
"input": "12\n???A?G???A?T\n",
"output": "ACCACGGGTATT\n",
"type": "stdin_stdout"
},
{
"input": "16\n?????C??CAG??T??\n",
"output": "AAACCCGGCAGGTTTT\n",
"type": "stdin_stdout"
},
{
"input": "20\n???A?G??C?GC???????G\n",
"output": "AAAAAGCCCCGCGGTTTTTG\n",
"type": "stdin_stdout"
},
{
"input": "24\n?TG???AT?A?CTTG??T?GCT??\n",
"output": "ATGAAAATCACCTTGCCTGGCTGG\n",
"type": "stdin_stdout"
},
{
"input": "28\n??CTGAAG?GGT?CC?A??TT?CCACG?\n",
"output": "AACTGAAGAGGTCCCGAGTTTTCCACGT\n",
"type": "stdin_stdout"
},
{
"input": "32\n??A?????CAAG?C?C?CG??A?A??AAC?A?\n",
"output": "CCACGGGGCAAGGCGCTCGTTATATTAACTAT\n",
"type": "stdin_stdout"
},
{
"input": "36\n?GCC?CT?G?CGG?GCTGA?C?G?G????C??G?C?\n",
"output": "AGCCACTAGACGGAGCTGAACAGAGCTTTCTTGTCT\n",
"type": "stdin_stdout"
},
{
"input": "40\nTA?AA?C?G?ACC?G?GCTCGC?TG??TG?CT?G??CC??\n",
"output": "TAAAAACAGAACCAGAGCTCGCCTGGGTGGCTTGTTCCTT\n",
"type": "stdin_stdout"
},
{
"input": "44\nT?TA??A??AA???A?AGTA??TAT??ACTGAT??CT?AC?T??\n",
"output": "TCTACCACCAACCCAGAGTAGGTATGGACTGATGGCTGACGTTT\n",
"type": "stdin_stdout"
},
{
"input": "48\nG?G??GC??CA?G????AG?CA?CG??GGCCCCAA??G??C?T?TCA?\n",
"output": "GAGAAGCAACAAGCCGGAGGCATCGTTGGCCCCAATTGTTCTTTTCAT\n",
"type": "stdin_stdout"
},
{
"input": "52\n??G?G?CTGT??T?GCGCT?TAGGTT??C???GTCG??GC??C???????CG\n",
"output": "AAGAGACTGTAATAGCGCTATAGGTTAACAACGTCGCCGCCCCGGTTTTTCG\n",
"type": "stdin_stdout"
},
{
"input": "56\n?GCCA?GC?GA??GA??T?CCGC?????TGGC?AGGCCGC?AC?TGAT??CG?A??\n",
"output": "AGCCAAGCAGAAAGAAATCCCGCCGGTTTGGCTAGGCCGCTACTTGATTTCGTATT\n",
"type": "stdin_stdout"
},
{
"input": "60\nAT?T?CCGG??G?CCT?CCC?C?CGG????TCCCG?C?TG?TT?TA??A?TGT?????G?\n",
"output": "ATATACCGGAAGACCTACCCACACGGAAAATCCCGCCCTGGTTGTAGGAGTGTGTTTTGT\n",
"type": "stdin_stdout"
},
{
"input": "64\n?G??C??????C??C??AG?T?GC?TT??TAGA?GA?A??T?C???TC??A?CA??C??A???C\n",
"output": "AGAACAAAAACCCCCCCAGCTCGCGTTGGTAGAGGAGAGGTGCGGGTCTTATCATTCTTATTTC\n",
"type": "stdin_stdout"
},
{
"input": "68\nC?T??????C????G?T??TTT?T?T?G?CG??GCC??CT??????C??T?CC?T?T????CTT?T??\n",
"output": "CATAAAAAACAAAAGATAATTTATATAGCCGCCGCCCCCTCCGGGGCGGTGCCGTGTGGGGCTTTTTT\n",
"type": "stdin_stdout"
},
{
"input": "72\nA?GTA??A?TG?TA???AAAGG?A?T?TTAAT??GGA?T??G?T?T????TTATAAA?AA?T?G?TGT??TG\n",
"output": "AAGTACCACTGCTACCCAAAGGCACTCTTAATCCGGACTCCGCTCTCGGGTTATAAAGAAGTGGGTGTGTTG\n",
"type": "stdin_stdout"
},
{
"input": "76\nG?GTAC?CG?AG?AGC???A??T?TC?G??C?G?A???TC???GTG?C?AC???A??????TCA??TT?A?T?ATG\n",
"output": "GAGTACACGAAGAAGCAAAAAATCTCCGCCCCGCACCCTCCGGGTGGCGACGGGAGGTTTTTCATTTTTATTTATG\n",
"type": "stdin_stdout"
},
{
"input": "80\nGG???TAATT?A?AAG?G?TT???G??TTA?GAT?????GT?AA?TT?G?AG???G?T?A??GT??TTT?TTG??AT?T?\n",
"output": "GGAAATAATTAAAAAGAGATTACCGCCTTACGATCCCCCGTCAACTTCGCAGCCCGCTCACGGTGGTTTGTTGGGATGTG\n",
"type": "stdin_stdout"
},
{
"input": "84\n?C??G??CGGC????CA?GCGG???G?CG??GA??C???C???GC???CG?G?A?C?CC?AC?C?GGAG???C??????G???C\n",
"output": "ACAAGAACGGCAAAACAAGCGGAAAGACGAAGACCCCCGCGGGGCGTTCGTGTATCTCCTACTCTGGAGTTTCTTTTTTGTTTC\n",
"type": "stdin_stdout"
},
{
"input": "88\nGTTC?TCTGCGCGG??CATC?GTGCTCG?A?G?TGCAGCAG??A?CAG???GGTG?ATCAGG?TCTACTC?CG?GGT?A?TCC??AT?\n",
"output": "GTTCATCTGCGCGGAACATCAGTGCTCGAAAGATGCAGCAGAAAACAGACCGGTGCATCAGGCTCTACTCGCGTGGTTATTCCTTATT\n",
"type": "stdin_stdout"
},
{
"input": "92\n??TT????AT?T????A???TC????A?C????AT???T?T???T??A???T??TTA?AT?AA?C????C??????????????TAA?T???\n",
"output": "AATTAAAAATATAAAAAACCTCCCCCACCCCCCATCCCTCTCCCTCGAGGGTGGTTAGATGAAGCGGGGCGGGGGGGGGGTTTTTAATTTTT\n",
"type": "stdin_stdout"
},
{
"input": "96\nT?????C?CT?T??GGG??G??C???A?CC??????G???TCCCT??C?G??GC?CT?CGT?GGG??TCTC?C?CCGT?CCTCTT??CC?C?????\n",
"output": "TAAAAACACTATAAGGGAAGAACAAAAACCAAAAAAGCGGTCCCTGGCGGGGGCGCTGCGTGGGGGGTCTCTCTCCGTTCCTCTTTTCCTCTTTTT\n",
"type": "stdin_stdout"
},
{
"input": "100\n???GGA?C?A?A??A?G??GT?GG??G????A?ATGGAA???A?A?A?AGAGGT?GA?????AA???G???GA???TAGAG?ACGGA?AA?G???GGGAT\n",
"output": "ACCGGACCCACACCACGCCGTCGGCCGCCCCACATGGAACCCACACAGAGAGGTGGATTTTTAATTTGTTTGATTTTAGAGTACGGATAATGTTTGGGAT\n",
"type": "stdin_stdout"
},
{
"input": "104\n???TTG?C???G?G??G??????G?T??TC???CCC????TG?GGT??GG?????T?CG???GGG??GTC?G??TC??GG??CTGGCT??G????C??????TG\n",
"output": "AAATTGACAAAGAGAAGAAAAAAGATAATCAAACCCAAAATGCGGTCCGGCCCCCTCCGCCCGGGCCGTCCGGGTCGGGGTTCTGGCTTTGTTTTCTTTTTTTG\n",
"type": "stdin_stdout"
},
{
"input": "108\n??CAC?A?ACCA??A?CA??AA?TA?AT?????CCC????A??T?C?CATA??CAA?TACT??A?TA?AC?T??G???GG?G??CCC??AA?CG????T?CT?A??AA\n",
"output": "AACACAACACCACCACCACCAACTACATCGGGGCCCGGGGAGGTGCGCATAGGCAAGTACTGGAGTAGACGTGGGTTTGGTGTTCCCTTAATCGTTTTTTCTTATTAA\n",
"type": "stdin_stdout"
},
{
"input": "112\n???T?TC?C?AC???TC?C???CCC??C????C?CCGC???TG?C?T??????C?C?????G?C????A????????G?C?A?C?A?C?C??C????CC?TC??C??C?A??\n",
"output": "AAATATCACAACAAATCACAAACCCAACAAAACACCGCAAATGCCGTGGGGGGCGCGGGGGGGCGGGGAGGGGGGTTGTCTATCTATCTCTTCTTTTCCTTCTTCTTCTATT\n",
"type": "stdin_stdout"
},
{
"input": "116\n????C??A?A??AAC???????C???CCCTC??A????ATA?T??AT???C?TCCC???????C????CTC??T?A???C??A???CCA?TAC?AT?????C??CA???C?????C\n",
"output": "AAAACAAAAAAAAACAAAAAACCCCCCCCTCCCACGGGATAGTGGATGGGCGTCCCGGGGGGGCGGGGCTCGGTGAGGGCGGATTTCCATTACTATTTTTTCTTCATTTCTTTTTC\n",
"type": "stdin_stdout"
},
{
"input": "120\nTC?AGATG?GAT??G????C?C??GA?GT?TATAC?AGA?TCG?TCT???A?AAA??C?T?A???AA?TAC?ATTT???T?AA?G???TG?AT???TA??GCGG?AC?A??AT??T???C\n",
"output": "TCAAGATGAGATAAGAACCCCCCCGACGTCTATACCAGACTCGCTCTCCCACAAACCCCTCACGGAAGTACGATTTGGGTGAAGGGGGTGGATGGGTAGTGCGGTACTATTATTTTTTTC\n",
"type": "stdin_stdout"
},
{
"input": "124\n???C?????C?AGG??A?A?CA????A??A?AA??A????????G?A?????????AG?A??G?C??A??C???G??CG??C???????A????C???AG?AA???AC????????????C??G\n",
"output": "AAACAAAAACAAGGAAAAAACACCCCACCACAACCACCCCCCCCGCACCCGGGGGGAGGAGGGGCGGAGGCGGGGGGCGGGCGTTTTTTATTTTCTTTAGTAATTTACTTTTTTTTTTTTCTTG\n",
"type": "stdin_stdout"
},
{
"input": "128\nAT?GC?T?C?GATTTG??ATTGG?AC?GGCCA?T?GG?CCGG??AGT?TGT?G??A?AAGGCGG?T??TCT?CT??C?TTGTTG??????CCGG?TGATAT?T?TTGTCCCT??CTGTGTAATA??G?\n",
"output": "ATAGCATACAGATTTGAAATTGGAACAGGCCAATAGGACCGGAAAGTATGTAGAAAAAAGGCGGCTCCTCTCCTCCCCTTGTTGCCCCCCCCGGCTGATATCTGTTGTCCCTGGCTGTGTAATAGGGT\n",
"type": "stdin_stdout"
},
{
"input": "132\nAC???AA??T???T??G??ACG?C??AA?GA?C???CGAGTA?T??TTGTC???GCTGATCA????C??TA???ATTTA?C??GT??GTCTCTCGT?AAGGACTG?TC????T???C?T???ATTTT?T?AT\n",
"output": "ACAAAAAAATAAATAAGAAACGACACAACGACCCCCCGAGTACTCCTTGTCCCCGCTGATCACCCCCCGTAGGGATTTAGCGGGTGGGTCTCTCGTGAAGGACTGGTCGGGGTGGGCGTTTTATTTTTTTAT\n",
"type": "stdin_stdout"
},
{
"input": "136\n?A?C???????C??????????????C?????C???????????CCCC?????????C??????C??C??????CC??C??C?C???C??????C??C?C??????????C?????????GC????C???????C?\n",
"output": "AAACAAAAAAACAAAAAAAAAAAAAACAAAAACAAAAACCCCCCCCCCCCCCGGGGGCGGGGGGCGGCGGGGGGCCGGCGGCGCGGGCGGGGGGCTTCTCTTTTTTTTTTCTTTTTTTTTGCTTTTCTTTTTTTCT\n",
"type": "stdin_stdout"
},
{
"input": "140\nTTG??G?GG?G??C??CTC?CGG?TTCGC????GGCG?G??TTGCCCC?TCC??A??CG?GCCTTT?G??G??CT??TG?G?TTC?TGC?GG?TGT??CTGGAT??TGGTTG??TTGGTTTTTTGGTCGATCGG???C??\n",
"output": "TTGAAGAGGAGAACAACTCACGGATTCGCAAAAGGCGAGAATTGCCCCATCCAAAAACGAGCCTTTAGAAGAACTAATGAGATTCCTGCCGGCTGTCCCTGGATCCTGGTTGCCTTGGTTTTTTGGTCGATCGGCCCCTT\n",
"type": "stdin_stdout"
},
{
"input": "144\n?????A?C?A?A???TTT?GAATA?G??T?T?????AT?AA??TT???TT??A?T????AT??TA??AA???T??A??TT???A????T???T????A??T?G???A?C?T????A?AA??A?T?C??A??A???AA????ATA\n",
"output": "AAAAAAACAAAACCCTTTCGAATACGCCTCTCCCCCATCAACCTTCCCTTCCACTCCCCATCCTACCAACCCTGGAGGTTGGGAGGGGTGGGTGGGGAGGTGGGGGAGCGTGGGGAGAAGGATTTCTTATTATTTAATTTTATA\n",
"type": "stdin_stdout"
},
{
"input": "148\nACG?GGGT?A??C????TCTTGCTG?GTA?C?C?TG?GT??GGGG??TTG?CA????GT???G?TT?T?CT?C??C???CTTCATTA?G?G???GC?AAT??T???AT??GGATT????TC?C???????T??TATCG???T?T?CG?\n",
"output": "ACGAGGGTAAAACAAAATCTTGCTGAGTAACACATGAGTAAGGGGAATTGACAAAAAGTAAAGATTCTCCTCCCCCCCCCTTCATTACGCGCCCGCCAATCCTCCCATCGGGATTGGGGTCGCGGGGGGGTGTTATCGTTTTTTTCGT\n",
"type": "stdin_stdout"
},
{
"input": "152\n??CTA??G?GTC?G??TTCC?TG??????T??C?G???G?CC???C?GT?G?G??C?CGGT?CC????G?T?T?C?T??G?TCGT??????A??TCC?G?C???GTT?GC?T?CTT?GT?C??C?TCGTTG?TTG?G????CG?GC??G??G\n",
"output": "AACTAAAGAGTCAGAATTCCATGAAAAAATAACAGAAAGACCAAACAGTAGAGAACACGGTACCAAAAGCTCTCCCTCCGCTCGTCCCCCCACGTCCGGGCGGGGTTGGCGTGCTTGGTGCGTCTTCGTTGTTTGTGTTTTCGTGCTTGTTG\n",
"type": "stdin_stdout"
},
{
"input": "156\nGCA????A???AAT?C??????GAG?CCA?A?CG??ACG??????GCAAAC??GCGGTCC??GT???C???????CC???????ACGCA????C??A??CC??A?GAATAC?C?CA?CCCT?TCACA?A???????C??TAG?C??T??A??A?CA\n",
"output": "GCAAAAAAAAAAATACAAAAACGAGCCCACACCGCCACGCCCGGGGCAAACGGGCGGTCCGGGTGGGCGGGGGGGCCGGGGGGGACGCAGGTTCTTATTCCTTATGAATACTCTCATCCCTTTCACATATTTTTTTCTTTAGTCTTTTTATTATCA\n",
"type": "stdin_stdout"
},
{
"input": "160\nGCACC????T?TGATAC??CATATCC?GT?AGT?ATGGATA?CC?????GCTCG?A?GG?A?GCCAG??C?CGGATC?GCAA?AAGCCCCC?CAT?GA?GC?CAC?TAA?G?CACAACGG?AAA??CA?ACTCGA?CAC?GAGCAAC??A?G?AAA?TC?\n",
"output": "GCACCACCCTGTGATACGGCATATCCGGTGAGTGATGGATAGCCGGGGGGCTCGGAGGGGATGCCAGTTCTCGGATCTGCAATAAGCCCCCTCATTGATGCTCACTTAATGTCACAACGGTAAATTCATACTCGATCACTGAGCAACTTATGTAAATTCT\n",
"type": "stdin_stdout"
},
{
"input": "164\nGA?AGGT???T?G?A?G??TTA?TGTG?GTAGT?????T??TTTG?A?T??T?TA?G?T?GGT?????TGTGG?A?A?T?A?T?T?????TT?AAGAG?????T??TATATG?TATT??G?????GGGTATTTT?GG?A??TG??T?GAATGTG?AG?T???A?\n",
"output": "GAAAGGTAAATAGAAAGAATTAATGTGAGTAGTAAAAATAATTTGAACTCCTCTACGCTCGGTCCCCCTGTGGCACACTCACTCTCCCCCTTCAAGAGCCCCCTCCTATATGCTATTCCGCCCCCGGGTATTTTCGGCAGGTGGGTGGAATGTGGAGGTGGGAG\n",
"type": "stdin_stdout"
},
{
"input": "168\n?C?CAGTCCGT?TCC?GCG?T??T?TA?GG?GCTTGTTTTGT??GC???CTGT??T?T?C?ACG?GTGG??C??TC?GT??CTT?GGT??TGGC??G?TTTCTT?G??C?CTC??CT?G?TT?CG?C?A???GCCGTGAG?CTTC???TTCTCGG?C?CC??GTGCTT\n",
"output": "ACACAGTCCGTATCCAGCGATAATATAAGGAGCTTGTTTTGTAAGCAAACTGTAATATACAACGAGTGGAACAATCAGTAACTTAGGTAATGGCAAGATTTCTTAGAACCCTCCCCTCGCTTCCGCCCACGGGCCGTGAGGCTTCGGGTTCTCGGGCGCCGGGTGCTT\n",
"type": "stdin_stdout"
},
{
"input": "172\nG?ATG??G?TTT?ATA?GAAGCACTTGCT?AGC??AG??GTTCG?T?G??G?AC?TAGGGCT?TA?TTCTA?TTCAGGAA?GGAAATTGAAG?A?CT?GGTGAGTCTCT?AAACAGT??T??TCAGG?AGTG?TT?TAAT??GG?G?GCA???G?GGA?GACGAATACTCAA\n",
"output": "GAATGAAGATTTAATACGAAGCACTTGCTCAGCCCAGCCGTTCGCTCGCCGCACCTAGGGCTCTACTTCTACTTCAGGAACGGAAATTGAAGCACCTCGGTGAGTCTCTCAAACAGTCCTCCTCAGGCAGTGGTTGTAATGGGGTGTGCATTTGTGGATGACGAATACTCAA\n",
"type": "stdin_stdout"
},
{
"input": "176\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\n",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n",
"type": "stdin_stdout"
},
{
"input": "180\n?GTTACA?A?A?G??????GGGA?A??T?????C?AC??GG???G????T??CC??T?CGG?AG???GAAGG?????A?GT?G?????CTAA?A??C?A???A?T??C?A???AAA???G?GG?C?A??C???????GTCC?G??GT??G?C?G?C????TT??G????A???A???A?G\n",
"output": "AGTTACAAAAAAGAAAAAAGGGAAAAATAAAAACAACAAGGCCCGCCCCTCCCCCCTCCGGCAGCCCGAAGGCCCCCACGTCGCCCCCCTAACACGCGAGGGAGTGGCGAGGGAAAGGGGGGGGCGAGTCTTTTTTTGTCCTGTTGTTTGTCTGTCTTTTTTTTGTTTTATTTATTTATG\n",
"type": "stdin_stdout"
},
{
"input": "184\n?CTC?A??????C?T?TG??AC??????G???CCT????CT?C?TT???C???AT????????????T??T?A?AGT?C?C?C?C?CG??CAT?C??C???T??T?TCCTC????C??A???CG?C???C??TC??C?G?C????CTT????C??A?AT??C????T?TCT?T???C?CT??C?\n",
"output": "ACTCAAAAAAAACATATGAAACAAAAAAGAAACCTAAAACTACATTAAACAAAATAAAACCCCCCCCTCCTCACAGTGCGCGCGCGCGGGCATGCGGCGGGTGGTGTCCTCGGGGCGGAGGGCGGCGGGCGGTCGGCGGGCGGGGCTTGTTTCTTATATTTCTTTTTTTCTTTTTTCTCTTTCT\n",
"type": "stdin_stdout"
},
{
"input": "188\n????TG??A?G?GG?AGA??T??G?TA?ATTT?TTGA??TTA??T?G???GA?G?A??GG??ACTTGT?T?T?TCT?TG?TGAG??GT?A???TT?G???????TA???G?G?GTAG?G?T????????A?TT?TT?T??GGTGT??TTT?T?T?TT???GAGA??G?GGG?G??TG?GT?GT?A??T\n",
"output": "AAAATGAAAAGAGGAAGAAATAAGATAAATTTATTGAAATTAAATAGAAAGAAGAAAAGGACACTTGTCTCTCTCTCTGCTGAGCCGTCACCCTTCGCCCCCCCTACCCGCGCGTAGCGCTCCCCCCCCACTTCTTCTCCGGTGTCCTTTCTCTCTTGGGGAGAGGGGGGGGGGGTGGGTGGTTATTT\n",
"type": "stdin_stdout"
},
{
"input": "192\nTT???TA?A?TTCTCA?ATCCCC?TA?T??A?A?TGT?TT??TAA?C?C?TA?CTAAAT???AA?TT???T?AATAG?AC??AC?A??A?TT?A?TT?AA?TCTTTC??A?AAA?AA??T?AG?C??AT?T?TATCT?CTTCAA?ACAAAT???AT?TT??????C?CTC???TT?ACACACTGCA?AC??T\n",
"output": "TTAACTACACTTCTCACATCCCCCTACTCCACACTGTCTTCCTAACCCCCTACCTAAATCCCAACTTCGGTGAATAGGACGGACGAGGAGTTGAGTTGAAGTCTTTCGGAGAAAGAAGGTGAGGCGGATGTGTATCTGCTTCAAGACAAATGGGATGTTGGGGGGCGCTCGGGTTGACACACTGCAGACTTT\n",
"type": "stdin_stdout"
},
{
"input": "196\n??ACATCC??TGA?C?AAA?A???T????A??ACAC????T???????CCC?AAT?T?AT?A?A??TATC??CC?CCACACA?CC?A?AGC??AAA??A???A?CA??A?AT??G???CA?ACATTCG??CACAT?AC???A?A?C?CTTT?AAG??A?TAC???C?GCAA?T??C??AA???GAC?ATTAT????\n",
"output": "ACACATCCCCTGACCCAAACACCCTCCCCACCACACCGGGTGGGGGGGCCCGAATGTGATGAGAGGTATCGGCCGCCACACAGCCGAGAGCGGAAAGGAGGGAGCAGGAGATGGGGGGCAGACATTCGGGCACATTACTTTATATCTCTTTTAAGTTATTACTTTCTGCAATTTTCTTAATTTGACTATTATTTTT\n",
"type": "stdin_stdout"
},
{
"input": "200\n?CT?T?C???AC?G?CAC?C?T??T?G?AGAGTA?CT????A?CCCAT?GCT?TTC?CAG???TCCATAAC?GACT?TC??C?AG?AA?A?C??ATC?CTAT?AC??????ACCGA??A????C?AA???CGCTTCGC?A????A??GCC?AG?T?????T?A?C?A?CTTC?????T?T?????GC?GTACTC??TG??\n",
"output": "ACTATACAAAACAGACACACATAATAGAAGAGTAACTAAAAAACCCATCGCTCTTCCCAGCCCTCCATAACCGACTCTCCCCCAGCAAGAGCGGATCGCTATGACGGGGGGACCGAGGAGGGGCGAAGGGCGCTTCGCGAGGGGAGGGCCGAGGTGGGTTTTATCTATCTTCTTTTTTTTTTTTTGCTGTACTCTTTGTT\n",
"type": "stdin_stdout"
},
{
"input": "204\n??????T???T?GC?TC???TA?TC?????A??C?C??G??????G?CTC????A?CTTT?T???T??CTTA???????T??C??G????A?????TTTA??AT?A??C?C?T?C???C?????T???????GT????T????AT?CT????C??C??T???C????C?GCTTCCC?G?????T???C?T??????????TT??\n",
"output": "AAAAAATAAATAGCATCAAATAATCAAAAAAAACACAAGAAAAAAGACTCAAAAAACTTTATAAATACCTTACCCCCCCTCCCCCGCCCCACCCCCTTTACCATCACCCCCGTGCGGGCGGGGGTGGGGGGGGTGGGGTGGGGATGCTGGGGCGGCGGTGGGCGGGGCGGCTTCCCGGGTTTTTTTTCTTTTTTTTTTTTTTTT\n",
"type": "stdin_stdout"
},
{
"input": "208\nA?GGT?G??A???????G??A?A?GA?T?G???A?AAG?AT????GG?????AT??A?A???T?A??????A????AGGCGT???A???TA????TGGT???GA????GGTG???TA??GA??TA?GGG?????G?????AT?GGGG??TG?T?AA??A??AG?AA?TGA???A?A?GG???GAAT?G?T??T?A??G?CAGT?T?A?\n",
"output": "AAGGTAGAAAAAAAAAAGAAAAAAGAATCGCCCACAAGCATCCCCGGCCCCCATCCACACCCTCACCCCCCACCCCAGGCGTCCCACCCTACCCCTGGTCCCGACCCCGGTGCGGTAGGGAGGTAGGGGGGGGGGGGGGTATTGGGGTTTGTTTAATTATTAGTAATTGATTTATATGGTTTGAATTGTTTTTTATTGTCAGTTTTAT\n",
"type": "stdin_stdout"
},
{
"input": "212\nT?TTT?A??TC?????A?T??T????T????????C??T??AT????????T???TT????T?TTT??????????TTC???T?T?C??T?TA?C??TTT????T???????C????????A?TT???T??TTT??AT?T????T????T?????A??C????T??T???TA???A?????????T???C????????C???T?TA???TTT\n",
"output": "TATTTAAAATCAAAAAAATAATAAAATAAAAAAAACAATAAATAAAAAAAATAAATTAAAATCTTTCCCCCCCCCCTTCCCCTCTCCCCTCTACCCCTTTCCCCTCCCCCCCCCCCCCCCCACTTCCGTGGTTTGGATGTGGGGTGGGGTGGGGGAGGCGGGGTGGTGGGTAGGGAGGGGGGGGGTGGGCGGGGGGGGCTTTTTTATTTTTT\n",
"type": "stdin_stdout"
},
{
"input": "216\n?CT?A?CC?GCC?C?AT?A???C???TA????ATGTCCG??CCG?CGG?TCC?TTC??CCT????????G?GGC?TACCCGACCGAG?C???C?G?G??C??CGTCCTG??AGG??CT?G???TC?CT????A?GTA??C?C?CTGTTAC??C?TCT?C?T???T??GTGGA?AG?CGCT?CGTC???T?C?T?C?GTT???C??GCC?T??C?T?\n",
"output": "ACTAAACCAGCCACAATAAAAACAAATAAAAAATGTCCGAACCGACGGATCCATTCAACCTAAAAAAAAGAGGCATACCCGACCGAGACAAACAGAGCCCCCCGTCCTGCGAGGGGCTGGGGGTCGCTGGGGAGGTAGGCGCGCTGTTACGGCGTCTGCGTGGGTTTGTGGATAGTCGCTTCGTCTTTTTCTTTCTGTTTTTCTTGCCTTTTCTTT\n",
"type": "stdin_stdout"
},
{
"input": "220\n?GCC??????T????G?CTC???CC?C????GC??????C???TCCC???????GCC????????C?C??C?T?C?CC????CC??C???????CC??C?G?A?T???CC??C????????C????CTA?GC?????CC??C?C?????T?????G?????????G???AC????C?CG?????C?G?C?CG?????????G?C????C?G??????C??\n",
"output": "AGCCAAAAAATAAAAGACTCAAACCACAAAAGCAAAAAACAAATCCCAAAAAAAGCCAAAAAAAACACAACATACACCAACCCCCCCCCCCCCGCCGGCGGGAGTGGGCCGGCGGGGGGGGCGGGGCTAGGCGGGGGCCGGCGCGGGGGTGGGGGGTTTTTTTTTGTTTACTTTTCTCGTTTTTCTGTCTCGTTTTTTTTTGTCTTTTCTGTTTTTTCTT\n",
"type": "stdin_stdout"
},
{
"input": "224\nTTGC?G??A?ATCA??CA???T?TG?C?CGA?CTTA?C??C?TTC?AC?CTCA?A?AT?C?T?CT?CATGT???A??T?CT????C?AACT?TTCCC??C?AAC???AC?TTTC?TTAAA??????TGT????CGCT????GCCC?GCCCA?????TCGA??C?TATACA??C?CC?CATAC?GGACG??GC??GTT?TT?T???GCT??T?C?T?C??T?CC?\n",
"output": "TTGCAGAAAAATCAAACAAAATATGACACGAACTTAACAACATTCAACACTCAAAAATACATACTACATGTAAAACCTCCTCCCCCCAACTGTTCCCGGCGAACGGGACGTTTCGTTAAAGGGGGGTGTGGGGCGCTGGGGGCCCGGCCCAGGGGGTCGAGGCGTATACAGGCGCCGCATACGGGACGGGGCGTGTTTTTTTTTTGCTTTTTCTTTCTTTTCCT\n",
"type": "stdin_stdout"
},
{
"input": "228\nA??A?C???AG?C?AC???A?T?????AA??????C?A??A?AC?????C?C???A??????A???AC?C????T?C?AA?C??A???CC??????????????????A???CC????A?????C??TC???A???????????A??A????????????????CC?????CCA??????????????C??????C????T?CT???C???A???T?CC?G??C??A?\n",
"output": "AAAAACAAAAGACAACAAAAATAAAAAAAAAAAAACAAAAAAACAAAAACACCCCACCCCCCACCCACCCCCCCTCCCAACCCCACCCCCCCCCGGGGGGGGGGGGGGAGGGCCGGGGAGGGGGCGGTCGGGAGGGGGGGGGGGAGGAGGGGGGGGGGGTTTTTCCTTTTTCCATTTTTTTTTTTTTTCTTTTTTCTTTTTTCTTTTCTTTATTTTTCCTGTTCTTAT\n",
"type": "stdin_stdout"
},
{
"input": "232\nA??AAGC?GCG?AG???GGGCG?C?A?GCAAC?AG?C?GC??CA??A??CC?AA?A????G?AGA?ACACA?C?G?G?G?CGC??G???????GAGC?CAA??????G?A???AGGG?????AAC?AG?A?A??AG?CG?G???G????GGGA?C?G?A?A??GC????C??A?ACG?AA?G?ACG????AC?C?GA??GGCAG?GAA??ACA??A?AGGAGG???CGGA?C\n",
"output": "AAAAAGCAGCGAAGAAAGGGCGACAAAGCAACCAGCCCGCCCCACCACCCCCAACACCCCGCAGACACACACCCGCGCGCCGCCCGCCCGGGGGAGCGCAAGGGGGTGTATTTAGGGTTTTTAACTAGTATATTAGTCGTGTTTGTTTTGGGATCTGTATATTGCTTTTCTTATACGTAATGTACGTTTTACTCTGATTGGCAGTGAATTACATTATAGGAGGTTTCGGATC\n",
"type": "stdin_stdout"
},
{
"input": "236\nAAGCCC?A?TT??C?AATGC?A?GC?GACGT?CTT?TA??CCG?T?CAA?AGT?CTG???GCGATG?TG?A?A?ACT?AT?GGG?GC?C?CGCCCTT?GT??G?T?????GACTT??????CT?GA?GG?C?T?G??CTG??G??TG?TCA?TCGTT?GC?A?G?GGGT?CG?CGAG??CG?TC?TAT?A???T??GAGTC?CGGC?CG??CT?TAAT??GGAA?G??GG?GCGAC\n",
"output": "AAGCCCAAATTAACAAATGCAAAGCAGACGTACTTATAAACCGATACAAAAGTACTGAAAGCGATGATGAAAAAACTAATAGGGAGCACACGCCCTTAGTACGCTCCCCCGACTTCCCCCCCTCGACGGCCCTCGCCCTGCGGGGTGGTCAGTCGTTGGCGAGGGGGGTGCGTCGAGTTCGTTCTTATTATTTTTTGAGTCTCGGCTCGTTCTTTAATTTGGAATGTTGGTGCGAC\n",
"type": "stdin_stdout"
},
{
"input": "240\n?T?A?A??G????G????AGGAGTAA?AGGCT??C????AT?GAA?ATGCT???GA?G?A??G?TC??TATT???AG?G?G?A?A??TTGT??GGTCAG?GA?G?AAT?G?GG??CAG?T?GT?G?GC???GC??????GA?A?AAATGGGC??G??????TTA??GTCG?TC?GCCG?GGGA??T?A????T?G?T???G?GG?ATG???A?ATGAC?GGT?CTG?AGGG??TAGT?AG\n",
"output": "ATAAAAAAGAAAAGAAAAAGGAGTAAAAGGCTAACAAAAATAGAAAATGCTACCGACGCACCGCTCCCTATTCCCAGCGCGCACACCTTGTCCGGTCAGCGACGCAATCGCGGCCCAGCTCGTCGCGCCCCGCCCCCCCGACACAAATGGGCCCGCGGGGGTTATTGTCGTTCTGCCGTGGGATTTTATTTTTTGTTTTTGTGGTATGTTTATATGACTGGTTCTGTAGGGTTTAGTTAG\n",
"type": "stdin_stdout"
},
{
"input": "244\nC?GT???T??TA?CC??TACT???TC?C?A???G??G?TCC?AC??AA???C?CCACC????A?AGCC??T?CT??CCGG?CC?T?C??GCCCTGGCCAAAC???GC?C???AT?CC?CT?TAG??CG?C?T?C??A?AC?GC????A??C?C?A??TC?T????GCCCT??GG???CC?A?CC?G?A?CA?G??CCCG??CG?T?TAC?G???C?AC??G??CCA???G????C??G?CT?C?\n",
"output": "CAGTAAATAATAACCAATACTAAATCACAAAAAGAAGATCCAACAAAAAAACACCACCAAAAAAAGCCAATACTAACCGGGCCGTGCGGGCCCTGGCCAAACGGGGCGCGGGATGCCGCTGTAGGGCGGCGTGCGGAGACGGCGGGGAGGCGCGAGGTCGTGGTTGCCCTTTGGTTTCCTATCCTGTATCATGTTCCCGTTCGTTTTACTGTTTCTACTTGTTCCATTTGTTTTCTTGTCTTCT\n",
"type": "stdin_stdout"
},
{
"input": "248\n??TC???TG??G??T????CC???C?G?????G?????GT?A?CT?AAT?GG?AGA?????????G???????G???CG??AA?A????T???????TG?CA????C?TT?G?GC???AA?G????G????T??G??A??????TT???G???CG?????A??A??T?GA??G??T?CC?TA??GCTG?A????G?CG??GGTG??CA???????TA??G?????????A???????GC?GG????GC\n",
"output": "AATCAAATGAAGAATAAAACCAAACAGAAAAAGAAAAAGTAAACTAAATAGGAAGAAAAAAAAAAGACCCCCCGCCCCGCCAACACCCCTCCCCCCCTGCCACCCCCCTTCGCGCCCCAACGCCCCGCCCCTCCGGGAGGGGGGTTGGGGGGGCGGGGGGAGGAGGTGGAGGGGGTGCCTTATTGCTGTATTTTGTCGTTGGTGTTCATTTTTTTTATTGTTTTTTTTTATTTTTTTGCTGGTTTTGC\n",
"type": "stdin_stdout"
},
{
"input": "8\n???AAA??\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "12\nC??CC??????C\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "4\nG??G\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "4\nTT??\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "4\nACAC\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "8\nACGT???T\n",
"output": "ACGTACGT\n",
"type": "stdin_stdout"
},
{
"input": "252\n????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\n",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n",
"type": "stdin_stdout"
},
{
"input": "252\n??????????????????????????????????????????????????????????????????????????????A?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\n",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n",
"type": "stdin_stdout"
},
{
"input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????C????????????????????????????????????????????????????????????????\n",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGCGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n",
"type": "stdin_stdout"
},
{
"input": "252\n???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????G\n",
"output": "AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTG\n",
"type": "stdin_stdout"
},
{
"input": "252\nT???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????\n",
"output": "TAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCCGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGGTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT\n",
"type": "stdin_stdout"
},
{
"input": "4\nAA?T\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "4\nAAAA\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "8\nAAA?????\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "10\nACGT??????\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "6\nACGACG\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "5\nAAAAA\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "8\nGGGGAA??\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "5\nATGCA\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "4\nTTTT\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "4\nACCG\n",
"output": "===\n",
"type": "stdin_stdout"
},
{
"input": "8\nACGTA?GT\n",
"output": "ACGTACGT\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/747/B"
} | vfc_10234 |
apps | verifiable_code | 121 | Solve the following coding problem using the programming language python:
Ilya is an experienced player in tic-tac-toe on the 4 × 4 field. He always starts and plays with Xs. He played a lot of games today with his friend Arseny. The friends became tired and didn't finish the last game. It was Ilya's turn in the game when they left it. Determine whether Ilya could have won the game by making single turn or not.
The rules of tic-tac-toe on the 4 × 4 field are as follows. Before the first turn all the field cells are empty. The two players take turns placing their signs into empty cells (the first player places Xs, the second player places Os). The player who places Xs goes first, the another one goes second. The winner is the player who first gets three of his signs in a row next to each other (horizontal, vertical or diagonal).
-----Input-----
The tic-tac-toe position is given in four lines.
Each of these lines contains four characters. Each character is '.' (empty cell), 'x' (lowercase English letter x), or 'o' (lowercase English letter o). It is guaranteed that the position is reachable playing tic-tac-toe, and it is Ilya's turn now (in particular, it means that the game is not finished). It is possible that all the cells are empty, it means that the friends left without making single turn.
-----Output-----
Print single line: "YES" in case Ilya could have won by making single turn, and "NO" otherwise.
-----Examples-----
Input
xx..
.oo.
x...
oox.
Output
YES
Input
x.ox
ox..
x.o.
oo.x
Output
NO
Input
x..x
..oo
o...
x.xo
Output
YES
Input
o.x.
o...
.x..
ooxx
Output
NO
-----Note-----
In the first example Ilya had two winning moves: to the empty cell in the left column and to the leftmost empty cell in the first row.
In the second example it wasn't possible to win by making single turn.
In the third example Ilya could have won by placing X in the last row between two existing Xs.
In the fourth example it wasn't possible to win by making single turn.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def chk(l):
for i in range(4):
for j in range(2):
if l[i][j]==l[i][j+1]==l[i][j+2]=='x':
return True
for i in range(2):
for j in range(4):
if l[i][j]==l[i+1][j]==l[i+2][j]=='x':
return True
for i in range(2):
for j in range(2):
if l[i][j]==l[i+1][j+1]==l[i+2][j+2]=='x':
return True
for i in range(2):
for j in range(2, 4):
if l[i][j]==l[i+1][j-1]==l[i+2][j-2]=='x':
return True
return False
a = [list(input()), list(input()), list(input()), list(input())]
for i in range(4):
for j in range(4):
if a[i][j] != '.':
continue
a[i][j]='x'
if chk(a):
print("YES"); return
a[i][j]='.'
print("NO")
``` | {
"language": "python",
"test_cases": [
{
"input": "xx..\n.oo.\nx...\noox.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "x.ox\nox..\nx.o.\noo.x\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "x..x\n..oo\no...\nx.xo\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "o.x.\no...\n.x..\nooxx\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".xox\no.x.\nx.o.\n..o.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "o.oo\n.x.o\nx.x.\n.x..\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".xx.\n.xoo\n.oox\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "xxox\no.x.\nx.oo\nxo.o\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".xox\n.x..\nxoo.\noox.\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".oxx\nx...\n.o..\no...\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "...x\n.x.o\n.o..\n.x.o\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "oo.x\nxo.o\no.xx\n.oxx\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".x.o\n..o.\n..ox\nxox.\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "....\n.x..\nx...\n..oo\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....\n....\n.x.o\n..xo\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "xo.x\n...o\n.oox\nx...\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "o..o\nx..x\n.o.x\nxo..\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "ox.o\nx..x\nx..o\noo.x\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".xox\n.x.o\nooxo\n..x.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "x..o\no..o\n..x.\nx.xo\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "xxoo\no.oo\n...x\nx..x\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "xoox\n.xx.\no..o\n..xo\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..o.\nxxox\n....\n.oxo\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "xoox\nxxox\noo..\n.ox.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..ox\n.o..\nx..o\n.oxx\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".oo.\n.x..\nx...\nox..\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "o.xx\nxo.o\n...o\n..x.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "x...\n.ox.\n.oo.\n.xox\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "xoxx\n..x.\no.oo\nx.o.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".x.x\n.o.o\no.xx\nx.oo\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "...o\nxo.x\n.x..\nxoo.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "o...\n...o\noxx.\n.xxo\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "xxox\no..o\nx..o\noxox\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "x...\no.ox\nxo..\n....\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "x.x.\nox.o\n.o.o\nxox.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".oxx\n..xo\n.oox\n....\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "xxo.\n...x\nooxx\n.o.o\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "xoxo\no..x\n.xo.\nox..\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".o..\nox..\n.o.x\n.x..\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".oxo\nx...\n.o..\n.xox\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".oxx\n..o.\n.o.x\n.ox.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".xxo\n...o\n..ox\nox..\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "x...\nxo..\noxo.\n..ox\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "xoxo\nx.ox\n....\noxo.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "x..o\nxo.x\no.xo\nxoox\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".x..\no..x\n.oo.\nxox.\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "xxox\no.x.\nxo.o\nxo.o\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".xo.\nx.oo\n...x\n.o.x\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "ox.o\n...x\n..oo\nxxox\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "oox.\nxoo.\no.x.\nx..x\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "oxox\nx.oo\nooxx\nxxo.\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "....\nxo.x\n..x.\noo..\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": ".ox.\nx..o\nxo.x\noxo.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".xox\nxo..\n..oo\n.x..\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "xxo.\n.oo.\n..x.\n..xo\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "ox..\n..oo\n..x.\nxxo.\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "xxo.\nx..x\noo.o\noxox\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "xx..\noxxo\nxo.o\noox.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "xox.\noox.\n....\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "x..o\no..o\no..x\nxxox\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "oxo.\nxx.x\nooxx\n.o.o\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".o.x\no..o\nx..x\n..xo\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "x.x.\n...o\n.o..\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "xo..\n....\nx...\n..o.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "xo..\n....\n..xo\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "ox.x\n...o\n....\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".x..\no.o.\n.x..\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".x..\no...\n...x\n.o..\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..xo\n....\nx.o.\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "o.x.\n....\n.ox.\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "...x\n....\n.x.o\n..o.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "o..x\n....\n...x\n..o.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "o...\nx.x.\no...\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....\nxo..\n..o.\nx...\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".oo.\nx...\n....\n..x.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....\n.x.x\no.o.\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".o..\n.x..\n..o.\n.x..\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..o.\n.x..\n....\no..x\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....\n.oxo\n....\nx...\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..o.\n..x.\n....\n.ox.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".o..\no..x\n....\n.x..\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....\n..ox\n....\n.o.x\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "o...\n.o..\nx.x.\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....\n..oo\n.x.x\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".o..\n....\no...\nx.x.\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....\n.o..\n....\nox.x\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "oxo.\nxxox\noo.o\nxoxx\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "..xx\noo..\n....\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".xx.\n...x\noo.o\no..x\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "x...\n.x..\n....\noo..\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": ".oox\n..x.\n....\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "...x\no..x\n.o..\n....\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "oxox\n..ox\nxoxo\nxoxo\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "....\n.ox.\n.o..\nx...\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "....\n...x\n...x\noo..\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/754/B"
} | vfc_10238 |
apps | verifiable_code | 122 | Solve the following coding problem using the programming language python:
Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position).
Inserting an element in the same position he was erased from is also considered moving.
Can Vasya divide the array after choosing the right element to move and its new position?
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.
The second line contains n integers a_1, a_2... a_{n} (1 ≤ a_{i} ≤ 10^9) — the elements of the array.
-----Output-----
Print YES if Vasya can divide the array after moving one element. Otherwise print NO.
-----Examples-----
Input
3
1 3 2
Output
YES
Input
5
1 2 3 4 5
Output
NO
Input
5
2 2 3 4 5
Output
YES
-----Note-----
In the first example Vasya can move the second element to the end of the array.
In the second example no move can make the division possible.
In the third example Vasya can move the fourth element by one position to the left.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def solve(n,a):
tot=0
for i in range(n):
tot+=a[i]
diffs = [] #alla suffix - prefix diffs[i]=prefix-suffix om delas innan element i
diffs.append(-tot)
for i in range(n):
tot-=2*a[i]
diffs.append(-tot)
if tot==0:
return ("YES")
for i in range(n):
diffmake=2*a[i]
j=binary(diffs,diffmake)
if j>i and j!=-1:
return ("YES")
j=binary(diffs,-diffmake)
if i>=j and j!=-1:
return ("YES")
return ("NO")
def binary(a,value):
hi=len(a)
lo=-1
while (lo+1<hi):
mi=(lo+hi)//2
if a[mi]==value:
return mi
if a[mi]<value:
lo=mi
else:
hi=mi
return -1
n=int(input())
a = input().split()
for i in range (n):
a[i]=int(a[i])
print(solve(n,a))
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n1 3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 3 4 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 2 3 4 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n72 32 17 46 82\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n26 10 70 11 69 57\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n4 7 10 7 5 5 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n9 5 5 10 4 9 5 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10\n9 6 8 5 5 2 8 9 2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "15\n4 8 10 3 1 4 5 9 3 2 1 7 7 3 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "20\n71 83 54 6 10 64 91 98 94 49 65 68 14 39 91 60 74 100 17 13\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "20\n2 8 10 4 6 6 4 1 2 2 6 9 5 1 9 1 9 8 10 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n9 9 72 55 14 8 55 58 35 67 3 18 73 92 41 49 15 60 18 66 9 26 97 47 43 88 71 97 19 34 48 96 79 53 8 24 69 49 12 23 77 12 21 88 66 9 29 13 61 69 54 77 41 13 4 68 37 74 7 6 29 76 55 72 89 4 78 27 29 82 18 83 12 4 32 69 89 85 66 13 92 54 38 5 26 56 17 55 29 4 17 39 29 94 3 67 85 98 21 14\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n89 38 63 73 77 4 99 74 30 5 69 57 97 37 88 71 36 59 19 63 46 20 33 58 61 98 100 31 33 53 99 96 34 17 44 95 54 52 22 77 67 88 20 88 26 43 12 23 96 94 14 7 57 86 56 54 32 8 3 43 97 56 74 22 5 100 12 60 93 12 44 68 31 63 7 71 21 29 19 38 50 47 97 43 50 59 88 40 51 61 20 68 32 66 70 48 19 55 91 53\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n80 100 88 52 25 87 85 8 92 62 35 66 74 39 58 41 55 53 23 73 90 72 36 44 97 67 16 54 3 8 25 34 84 47 77 39 93 19 49 20 29 44 21 48 21 56 82 59 8 31 94 95 84 54 72 20 95 91 85 1 67 19 76 28 31 63 87 98 55 28 16 20 36 91 93 39 94 69 80 97 100 96 68 26 91 45 22 84 20 36 20 92 53 75 58 51 60 26 76 25\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n27 95 57 29 91 85 83 36 72 86 39 5 79 61 78 93 100 97 73 23 82 66 41 92 38 92 100 96 48 56 66 47 5 32 69 13 95 23 46 62 99 83 57 66 98 82 81 57 37 37 81 64 45 76 72 43 99 76 86 22 37 39 93 80 99 36 53 83 3 32 52 9 78 34 47 100 33 72 19 40 29 56 77 32 79 72 15 88 100 98 56 50 22 81 88 92 58 70 21 19\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n35 31 83 11 7 94 57 58 30 26 2 99 33 58 98 6 3 52 13 66 21 53 26 94 100 5 1 3 91 13 97 49 86 25 63 90 88 98 57 57 34 81 32 16 65 94 59 83 44 14 46 18 28 89 75 95 87 57 52 18 46 80 31 43 38 54 69 75 82 9 64 96 75 40 96 52 67 85 86 38 95 55 16 57 17 20 22 7 63 3 12 16 42 87 46 12 51 95 67 80\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 4 3 100 100 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n6 100 100 3 4 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n4 2 3 7 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n6 1 4 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n228 114 114\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n229 232 444\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n322 324 555\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n69 34 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n5 4 1 2 2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n545 237 546\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 3 1 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 2 10 2 2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 4 6 5 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n6 1 1 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 2 2 3 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 6 1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 8 5 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10\n73 67 16 51 56 71 37 49 90 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n8 2 7 5 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "16\n9 10 2 1 6 7 6 5 8 3 2 10 8 4 9 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n8 2 2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "19\n9 9 3 2 4 5 5 7 8 10 8 10 1 2 2 6 5 3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "11\n7 2 1 8 8 2 4 10 8 7 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n10 20 30 40 99 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10\n3 7 9 2 10 1 9 6 4 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n9 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n1 2 3 12 1 2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n2 4 4 5 8 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "18\n2 10 3 6 6 6 10 8 8 1 10 9 9 3 1 9 7 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "20\n9 6 6 10 4 4 8 7 4 10 10 2 10 5 9 5 3 10 1 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "12\n3 8 10 2 4 4 6 9 5 10 10 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "11\n9 2 7 7 7 3 7 5 4 10 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 4 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n4 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n7 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n10 5 6 7 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "11\n4 3 10 3 7 8 4 9 2 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n705032704 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n1 5 6 8 3 1 7 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "20\n8 6 3 6 3 5 10 2 6 1 7 6 9 10 8 3 5 9 3 8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "11\n2 4 8 3 4 7 9 10 5 3 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7\n6 4 2 24 6 4 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "17\n7 1 1 1 8 9 1 10 8 8 7 9 7 9 1 6 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n7 10 1 2 6 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n10 10 40 10 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 3 13\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 2 10 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7\n7 4 5 62 20 20 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 5 2 20 10 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "14\n5 2 9 7 5 8 3 2 2 4 9 1 3 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 3 4 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 2 2 5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "11\n1 1 1 1 1 10 1 1 1 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9\n8 4 13 19 11 1 8 2 8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n14 16 14 14 15 11\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9\n14 19 1 13 11 3 1 1 7\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n16 13 3 7 4 15\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n11 7 12 14\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 1 3 6 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 4 8 11 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 10 3 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n8 15 12 14 15 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 4 4 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 4 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 3 1 6 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7\n1 2 3 12 3 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 4 13\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n1 1 1 1 1000000000 1000000000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n19 6 5 13 6 13\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8\n2 2 2 5 1 2 3 3\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/808/D"
} | vfc_10242 |
apps | verifiable_code | 123 | Solve the following coding problem using the programming language python:
A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.
To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.
Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total.
If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.
-----Input-----
The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively.
The second line contains n space-separated integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 200) — Hitagi's broken sequence with exactly k zero elements.
The third line contains k space-separated integers b_1, b_2, ..., b_{k} (1 ≤ b_{i} ≤ 200) — the elements to fill into Hitagi's sequence.
Input guarantees that apart from 0, no integer occurs in a and b more than once in total.
-----Output-----
Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.
-----Examples-----
Input
4 2
11 0 0 14
5 4
Output
Yes
Input
6 1
2 3 0 8 9 10
5
Output
No
Input
4 1
8 94 0 4
89
Output
Yes
Input
7 7
0 0 0 0 0 0 0
1 2 3 4 5 6 7
Output
Yes
-----Note-----
In the first sample: Sequence a is 11, 0, 0, 14. Two of the elements are lost, and the candidates in b are 5 and 4. There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes".
In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
n, k = list(map(int, input().split()))
a = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
b.sort(reverse=True)
res = []
cur_b = 0
for a_i in a:
if a_i != 0:
res.append(a_i)
else:
res.append(b[cur_b])
cur_b += 1
if res != list(sorted(res)):
print("Yes")
else:
print("No")
``` | {
"language": "python",
"test_cases": [
{
"input": "4 2\n11 0 0 14\n5 4\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n2 3 0 8 9 10\n5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n8 94 0 4\n89\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "7 7\n0 0 0 0 0 0 0\n1 2 3 4 5 6 7\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "40 1\n23 26 27 28 31 35 38 40 43 50 52 53 56 57 59 61 65 73 75 76 79 0 82 84 85 86 88 93 99 101 103 104 105 106 110 111 112 117 119 120\n80\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "100 1\n99 95 22 110 47 20 37 34 23 0 16 69 64 49 111 42 112 96 13 40 18 77 44 46 74 55 15 54 56 75 78 100 82 101 31 83 53 80 52 63 30 57 104 36 67 65 103 51 48 26 68 59 35 92 85 38 107 98 73 90 62 43 32 89 19 106 17 88 41 72 113 86 66 102 81 27 29 50 71 79 109 91 70 39 61 76 93 84 108 97 24 25 45 105 94 60 33 87 14 21\n58\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n2 1 0 4\n3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n199 0\n200\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n115 0 0\n145 191\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n196 197 198 0 200\n199\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n92 0 97 99 100\n93\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n3 87 0\n81\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n0 92 192\n118\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "10 1\n1 3 0 7 35 46 66 72 83 90\n22\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "100 1\n14 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 0 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113\n67\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "100 5\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 0 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 0 53 54 0 56 57 58 59 60 61 62 63 0 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 0 99 100\n98 64 55 52 29\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "100 5\n175 30 124 0 12 111 6 0 119 108 0 38 127 3 151 114 95 54 4 128 91 11 168 120 80 107 18 21 149 169 0 141 195 20 78 157 33 118 17 69 105 130 197 57 74 110 138 84 71 172 132 93 191 44 152 156 24 101 146 26 2 36 143 122 104 42 103 97 39 116 115 0 155 87 53 85 7 43 65 196 136 154 16 79 45 129 67 150 35 73 55 76 37 147 112 82 162 58 40 75\n121 199 62 193 27\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "100 1\n1 2 3 4 5 6 7 8 9 0 10 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n11\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "100 1\n0 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n1\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "100 1\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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 0\n100\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "100 1\n9 79 7 98 10 50 28 99 43 74 89 20 32 66 23 45 87 78 81 41 86 71 75 85 5 39 14 53 42 48 40 52 3 51 11 34 35 76 77 61 47 19 55 91 62 56 8 72 88 4 33 0 97 92 31 83 18 49 54 21 17 16 63 44 84 22 2 96 70 36 68 60 80 82 13 73 26 94 27 58 1 30 100 38 12 15 93 90 57 59 67 6 64 46 25 29 37 95 69 24\n65\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "100 2\n0 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 0 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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\n48 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "100 1\n2 7 11 17 20 22 23 24 25 27 29 30 31 33 34 35 36 38 39 40 42 44 46 47 50 52 53 58 59 60 61 62 63 66 0 67 71 72 75 79 80 81 86 91 93 94 99 100 101 102 103 104 105 108 109 110 111 113 114 118 119 120 122 123 127 129 130 131 132 133 134 135 136 138 139 140 141 142 147 154 155 156 160 168 170 171 172 176 179 180 181 182 185 186 187 188 189 190 194 198\n69\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "100 1\n3 5 7 9 11 12 13 18 20 21 22 23 24 27 28 29 31 34 36 38 39 43 46 48 49 50 52 53 55 59 60 61 62 63 66 68 70 72 73 74 75 77 78 79 80 81 83 85 86 88 89 91 92 94 97 98 102 109 110 115 116 117 118 120 122 126 127 128 0 133 134 136 137 141 142 144 145 147 151 152 157 159 160 163 164 171 172 175 176 178 179 180 181 184 186 188 190 192 193 200\n129\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n0 2 7 0 10\n1 8\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n5 4 0\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n1 0 3\n4\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n0 2\n1\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n0 5\n7\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n10 11 0 12 13\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n0 2 3 4 5\n6\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6 2\n1 0 3 4 0 6\n2 5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "7 2\n1 2 3 0 0 6 7\n4 5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n1 2 3 0\n4\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n0 0\n1 2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n1 0 0\n2 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n1 0 4 0\n5 2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n0 1\n2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n1 0 4 0 6\n2 5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n2 3 0 4 5\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n0 2 3\n5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n1 2 3 4 5 0\n6\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n1 2 0 4 5\n6\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n5 0 2\n7\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n4 5 0 8\n3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n10 11 12 0 14\n13\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n1 2 0 4\n5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n0 11 14\n12\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n1 3 0 4\n2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n0 5\n1\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n1 2 0 4 7\n5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n2 3 0\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n1 2 3 0 5 4\n6\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n11 0 0 14\n13 12\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n1 0\n2\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n1 2 0\n3\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n1 0 3 2\n4\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n0 1 2\n5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n0 1 2\n3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n0 2 3 4\n5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n1 2 3 0 4 5\n6\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n1 2 0\n5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n1 0 0 4\n3 2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n2 3 0 5 7\n6\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n2 3 0\n4\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n1 0 11\n5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n7 9 5 0\n8\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6 2\n1 2 3 0 5 0\n6 4\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n0 1 0\n3 2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n6 9 5 0\n8\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n0 3\n6\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n1 2 0 0 5\n4 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n2 0 0 8\n3 4\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n0 2\n3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n0 4 5\n6\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n1 2 3 4 0 5\n6\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n2 0\n3\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n11 0 0 200\n100 199\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n5 0\n4\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n1 0 5\n10\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6 2\n1 2 0 0 5 6\n3 4\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5 2\n1 0 3 0 5\n2 4\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n1 4 0 8\n3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n5 9 4 0\n8\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n1 0 0 7\n3 2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n0 0 0\n1 4 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n0 0 0 0 0\n5 4 3 2 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n3 9 4 0\n8\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n1 0 0 4\n2 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n2 4 0 8 9 10\n3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n0 3 5 6\n9\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n1 2 0 0\n3 4\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n2 3 4 5 0\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3 1\n2 0 4\n5\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/814/A"
} | vfc_10246 |
apps | verifiable_code | 124 | Solve the following coding problem using the programming language python:
The Duck song
For simplicity, we'll assume that there are only three types of grapes: green grapes, purple grapes and black grapes.
Andrew, Dmitry and Michal are all grapes' lovers, however their preferences of grapes are different. To make all of them happy, the following should happen: Andrew, Dmitry and Michal should eat at least $x$, $y$ and $z$ grapes, respectively. Andrew has an extreme affinity for green grapes, thus he will eat green grapes and green grapes only. On the other hand, Dmitry is not a fan of black grapes — any types of grapes except black would do for him. In other words, Dmitry can eat green and purple grapes. Michal has a common taste — he enjoys grapes in general and will be pleased with any types of grapes, as long as the quantity is sufficient.
Knowing that his friends are so fond of grapes, Aki decided to host a grape party with them. He has prepared a box with $a$ green grapes, $b$ purple grapes and $c$ black grapes.
However, Aki isn't sure if the box he prepared contains enough grapes to make everyone happy. Can you please find out whether it's possible to distribute grapes so that everyone is happy or Aki has to buy some more grapes?
It is not required to distribute all the grapes, so it's possible that some of them will remain unused.
-----Input-----
The first line contains three integers $x$, $y$ and $z$ ($1 \le x, y, z \le 10^5$) — the number of grapes Andrew, Dmitry and Michal want to eat.
The second line contains three integers $a$, $b$, $c$ ($1 \le a, b, c \le 10^5$) — the number of green, purple and black grapes in the box.
-----Output-----
If there is a grape distribution that allows everyone to be happy, print "YES", otherwise print "NO".
-----Examples-----
Input
1 6 2
4 3 3
Output
YES
Input
5 1 1
4 3 2
Output
NO
-----Note-----
In the first example, there is only one possible distribution:
Andrew should take $1$ green grape, Dmitry should take $3$ remaining green grapes and $3$ purple grapes, and Michal will take $2$ out of $3$ available black grapes.
In the second test, there is no possible distribution, since Andrew is not be able to eat enough green grapes. :(
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 = list(map(int,input().split()))
a,b,c = list(map(int,input().split()))
if a < x:
print("NO")
return
x -= a
y += x
if b < y:
print("NO")
return
y -= b
z += y
if c < z:
print("NO")
return
print("YES")
``` | {
"language": "python",
"test_cases": [
{
"input": "1 6 2\n4 3 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 1 1\n4 3 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 1 100000\n4 2 99995\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 3\n3 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 8 4\n3 1 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 1 2\n4 9 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100000 100000 100000\n100000 100000 100000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 2 1\n1 2 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "99999 99998 99997\n99997 99998 99999\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 7 9\n4 5 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "99999 100000 100000\n100000 100000 100000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100000 99999 100000\n100000 100000 100000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100000 100000 99999\n100000 100000 100000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100000 100000 100000\n99999 100000 100000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100000 100000 100000\n100000 99999 100000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100000 100000 100000\n100000 100000 99999\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 6 4\n4 5 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 1 9\n1 7 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 10 5\n4 10 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 1 7\n1 9 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 7 9\n7 2 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 4 1\n2 6 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7 3 9\n7 8 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 8 5\n6 5 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "80000 80004 80000\n80000 80006 80009\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "80004 80010 80005\n80005 80005 80006\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "80004 80000 80005\n80008 80001 80004\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "80001 80009 80008\n80006 80006 80003\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "80010 80001 80005\n80009 80002 80005\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "80003 80009 80004\n80007 80005 80009\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "80002 80005 80007\n80008 80005 80001\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "80003 80006 80001\n80004 80001 80010\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 10 7\n1 6 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "29 42 41\n94 70 42\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "945 294 738\n724 168 735\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4235 5782 8602\n7610 3196 4435\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "13947 31881 67834\n62470 11361 74085\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 2 10\n100 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 2 4\n1 3 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 2 6\n3 3 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 5 10\n10 1 40\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 2 1\n1 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 7\n2 3 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 5 4\n11 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 6\n2 3 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 3 3\n3 2 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 5 1\n5 4 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 2 10\n12 2 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 3 1\n7 1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 4 1\n5 3 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2\n2 1 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 1\n1 1 50\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 1 5\n10 1 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 5 2\n3 3 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1\n10 10 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 2 3\n1 2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 6 2\n3 7 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 4 6\n5 2 100\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3 3\n3 2 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3 2\n10 1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 20 1\n10 19 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 7 5\n7 5 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3 6\n3 3 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2\n2 3 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1\n2 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 7 2\n3 5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 4 1\n5 1 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 3\n1 2 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 5 6\n5 7 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2 2 3\n3 1 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 2 5\n1 1 65\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 1 2\n4 1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 5 10\n6 5 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 5 5\n13 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 4 7\n6 5 8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 4 3\n3 4 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10000 10000 10000\n10000 10000 9999\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 2 3\n8 1 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 10 1\n5 5 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 4 5\n2 4 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 2 2\n3 1 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 100 200\n5 10 20\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9 22 1\n10 20 30\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "77 31 57\n81 5 100\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 1 2\n1 1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "38 59 70\n81 97 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1 1 100\n50 50 50\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 100 5\n10 10 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 3 1\n1 2 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1 1 9\n3 3 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 5 5\n5 5 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 2 1\n3 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 2 1\n4 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 100 1\n3 1 100\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1114/A"
} | vfc_10250 |
apps | verifiable_code | 126 | Solve the following coding problem using the programming language python:
While swimming at the beach, Mike has accidentally dropped his cellphone into the water. There was no worry as he bought a cheap replacement phone with an old-fashioned keyboard. The keyboard has only ten digital equal-sized keys, located in the following way: [Image]
Together with his old phone, he lost all his contacts and now he can only remember the way his fingers moved when he put some number in. One can formally consider finger movements as a sequence of vectors connecting centers of keys pressed consecutively to put in a number. For example, the finger movements for number "586" are the same as finger movements for number "253": [Image] [Image]
Mike has already put in a number by his "finger memory" and started calling it, so he is now worrying, can he be sure that he is calling the correct number? In other words, is there any other number, that has the same finger movements?
-----Input-----
The first line of the input contains the only integer n (1 ≤ n ≤ 9) — the number of digits in the phone number that Mike put in.
The second line contains the string consisting of n digits (characters from '0' to '9') representing the number that Mike put in.
-----Output-----
If there is no other phone number with the same finger movements and Mike can be sure he is calling the correct number, print "YES" (without quotes) in the only line.
Otherwise print "NO" (without quotes) in the first line.
-----Examples-----
Input
3
586
Output
NO
Input
2
09
Output
NO
Input
9
123456789
Output
YES
Input
3
911
Output
YES
-----Note-----
You can find the picture clarifying the first sample case in the statement above.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# A
input()
l = list(map(int, list(input())))
if (1 in l or 4 in l or 7 in l or 0 in l) and (1 in l or 2 in l or 3 in l) and (3 in l or 6 in l or 9 in l or 0 in l) and (7 in l or 0 in l or 9 in l):
print("YES")
else:
print("NO")
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n586\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n09\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n123456789\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n911\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n089\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n159\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9\n000000000\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n0874\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n235689\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n358\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n123456\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n0068\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n021149\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n04918\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n05\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n0585\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n0755\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n08\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n0840\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n103481226\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n1468\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n1588216\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n188758557\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n22\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n23482375\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9\n246112056\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9\n256859223\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n287245\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n28959869\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n289887167\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n3418\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n3553\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n38\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n386126\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n392965\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n423463\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n4256\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n42937903\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n50725390\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9\n515821866\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n56\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n57\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n5740799\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n582526521\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9\n585284126\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n609\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n63\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n633\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n6668940\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n66883\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n68\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n69873\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "1\n7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n7191\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9\n722403540\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9\n769554547\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n780\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n78248\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n7844\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n7868\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "1\n8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6\n817332\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7\n8465393\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7\n8526828\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n85812664\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n93008225\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7\n9454566\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n9625\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n97862407\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n993\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n267\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n249\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n672\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n176\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n123\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n367\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n12\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n2580\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n20\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n492\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n167\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n970\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n460\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n4268\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n9394\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n13\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n729\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/689/A"
} | vfc_10258 |
apps | verifiable_code | 127 | Solve the following coding problem using the programming language python:
Summer holidays! Someone is going on trips, someone is visiting grandparents, but someone is trying to get a part-time job. This summer Noora decided that she wants to earn some money, and took a job in a shop as an assistant.
Shop, where Noora is working, has a plan on the following n days. For each day sales manager knows exactly, that in i-th day k_{i} products will be put up for sale and exactly l_{i} clients will come to the shop that day. Also, the manager is sure, that everyone, who comes to the shop, buys exactly one product or, if there aren't any left, leaves the shop without buying anything. Moreover, due to the short shelf-life of the products, manager established the following rule: if some part of the products left on the shelves at the end of the day, that products aren't kept on the next day and are sent to the dump.
For advertising purposes manager offered to start a sell-out in the shop. He asked Noora to choose any f days from n next for sell-outs. On each of f chosen days the number of products were put up for sale would be doubled. Thus, if on i-th day shop planned to put up for sale k_{i} products and Noora has chosen this day for sell-out, shelves of the shop would keep 2·k_{i} products. Consequently, there is an opportunity to sell two times more products on days of sell-out.
Noora's task is to choose f days to maximize total number of sold products. She asks you to help her with such a difficult problem.
-----Input-----
The first line contains two integers n and f (1 ≤ n ≤ 10^5, 0 ≤ f ≤ n) denoting the number of days in shop's plan and the number of days that Noora has to choose for sell-out.
Each line of the following n subsequent lines contains two integers k_{i}, l_{i} (0 ≤ k_{i}, l_{i} ≤ 10^9) denoting the number of products on the shelves of the shop on the i-th day and the number of clients that will come to the shop on i-th day.
-----Output-----
Print a single integer denoting the maximal number of products that shop can sell.
-----Examples-----
Input
4 2
2 1
3 5
2 3
1 5
Output
10
Input
4 1
0 2
0 3
3 5
0 6
Output
5
-----Note-----
In the first example we can choose days with numbers 2 and 4 for sell-out. In this case new numbers of products for sale would be equal to [2, 6, 2, 2] respectively. So on the first day shop will sell 1 product, on the second — 5, on the third — 2, on the fourth — 2. In total 1 + 5 + 2 + 2 = 10 product units.
In the second example it is possible to sell 5 products, if you choose third day for sell-out.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, f = list(map(int, input().split(' ')))
res = 0
wow = []
for a0 in range(n):
k, l = list(map(int, input().split(' ')))
res += min(k, l)
wow.append(min(2*k, l) - min(k, l))
wow = sorted(wow)
i = len(wow)-1
for a0 in range(f):
res += wow[i]
i -= 1
print(res)
``` | {
"language": "python",
"test_cases": [
{
"input": "4 2\n2 1\n3 5\n2 3\n1 5\n",
"output": "10",
"type": "stdin_stdout"
},
{
"input": "4 1\n0 2\n0 3\n3 5\n0 6\n",
"output": "5",
"type": "stdin_stdout"
},
{
"input": "1 1\n5 8\n",
"output": "8",
"type": "stdin_stdout"
},
{
"input": "2 1\n8 12\n6 11\n",
"output": "19",
"type": "stdin_stdout"
},
{
"input": "2 1\n6 7\n5 7\n",
"output": "13",
"type": "stdin_stdout"
},
{
"input": "2 1\n5 7\n6 7\n",
"output": "13",
"type": "stdin_stdout"
},
{
"input": "2 1\n7 8\n3 6\n",
"output": "13",
"type": "stdin_stdout"
},
{
"input": "2 1\n9 10\n5 8\n",
"output": "17",
"type": "stdin_stdout"
},
{
"input": "2 1\n3 6\n7 8\n",
"output": "13",
"type": "stdin_stdout"
},
{
"input": "1 0\n10 20\n",
"output": "10",
"type": "stdin_stdout"
},
{
"input": "2 1\n99 100\n3 6\n",
"output": "105",
"type": "stdin_stdout"
},
{
"input": "4 2\n2 10\n3 10\n9 9\n5 10\n",
"output": "27",
"type": "stdin_stdout"
},
{
"input": "2 1\n3 4\n2 8\n",
"output": "7",
"type": "stdin_stdout"
},
{
"input": "50 2\n74 90\n68 33\n49 88\n52 13\n73 21\n77 63\n27 62\n8 52\n60 57\n42 83\n98 15\n79 11\n77 46\n55 91\n72 100\n70 86\n50 51\n57 39\n20 54\n64 95\n66 22\n79 64\n31 28\n11 89\n1 36\n13 4\n75 62\n16 62\n100 35\n43 96\n97 54\n86 33\n62 63\n94 24\n19 6\n20 58\n38 38\n11 76\n70 40\n44 24\n32 96\n28 100\n62 45\n41 68\n90 52\n16 0\n98 32\n81 79\n67 82\n28 2\n",
"output": "1889",
"type": "stdin_stdout"
},
{
"input": "2 1\n10 5\n2 4\n",
"output": "9",
"type": "stdin_stdout"
},
{
"input": "2 1\n50 51\n30 40\n",
"output": "90",
"type": "stdin_stdout"
},
{
"input": "3 2\n5 10\n5 10\n7 9\n",
"output": "27",
"type": "stdin_stdout"
},
{
"input": "3 1\n1000 1000\n50 100\n2 2\n",
"output": "1102",
"type": "stdin_stdout"
},
{
"input": "2 1\n2 4\n12 12\n",
"output": "16",
"type": "stdin_stdout"
},
{
"input": "2 1\n4 4\n1 2\n",
"output": "6",
"type": "stdin_stdout"
},
{
"input": "2 1\n4000 4000\n1 2\n",
"output": "4002",
"type": "stdin_stdout"
},
{
"input": "2 1\n5 6\n2 4\n",
"output": "9",
"type": "stdin_stdout"
},
{
"input": "3 2\n10 10\n10 10\n1 2\n",
"output": "22",
"type": "stdin_stdout"
},
{
"input": "10 5\n9 1\n11 1\n12 1\n13 1\n14 1\n2 4\n2 4\n2 4\n2 4\n2 4\n",
"output": "25",
"type": "stdin_stdout"
},
{
"input": "2 1\n30 30\n10 20\n",
"output": "50",
"type": "stdin_stdout"
},
{
"input": "1 1\n1 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "2 1\n10 2\n2 10\n",
"output": "6",
"type": "stdin_stdout"
},
{
"input": "2 1\n4 5\n3 9\n",
"output": "10",
"type": "stdin_stdout"
},
{
"input": "2 1\n100 100\n5 10\n",
"output": "110",
"type": "stdin_stdout"
},
{
"input": "2 1\n14 28\n15 28\n",
"output": "43",
"type": "stdin_stdout"
},
{
"input": "2 1\n100 1\n20 40\n",
"output": "41",
"type": "stdin_stdout"
},
{
"input": "2 1\n5 10\n6 10\n",
"output": "16",
"type": "stdin_stdout"
},
{
"input": "2 1\n29 30\n10 20\n",
"output": "49",
"type": "stdin_stdout"
},
{
"input": "1 0\n12 12\n",
"output": "12",
"type": "stdin_stdout"
},
{
"input": "2 1\n7 8\n4 7\n",
"output": "14",
"type": "stdin_stdout"
},
{
"input": "2 1\n5 5\n2 4\n",
"output": "9",
"type": "stdin_stdout"
},
{
"input": "2 1\n1 2\n228 2\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "2 1\n5 10\n100 20\n",
"output": "30",
"type": "stdin_stdout"
},
{
"input": "2 1\n1000 1001\n2 4\n",
"output": "1004",
"type": "stdin_stdout"
},
{
"input": "2 1\n3 9\n7 7\n",
"output": "13",
"type": "stdin_stdout"
},
{
"input": "2 0\n1 1\n1 1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "4 1\n10 10\n10 10\n10 10\n4 6\n",
"output": "36",
"type": "stdin_stdout"
},
{
"input": "18 13\n63 8\n87 100\n18 89\n35 29\n66 81\n27 85\n64 51\n60 52\n32 94\n74 22\n86 31\n43 78\n12 2\n36 2\n67 23\n2 16\n78 71\n34 64\n",
"output": "772",
"type": "stdin_stdout"
},
{
"input": "2 1\n10 18\n17 19\n",
"output": "35",
"type": "stdin_stdout"
},
{
"input": "3 0\n1 1\n1 1\n1 1\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "2 1\n4 7\n8 9\n",
"output": "15",
"type": "stdin_stdout"
},
{
"input": "4 2\n2 10\n3 10\n9 10\n5 10\n",
"output": "27",
"type": "stdin_stdout"
},
{
"input": "2 1\n5 7\n3 6\n",
"output": "11",
"type": "stdin_stdout"
},
{
"input": "2 1\n3 4\n12 12\n",
"output": "16",
"type": "stdin_stdout"
},
{
"input": "2 1\n10 11\n9 20\n",
"output": "28",
"type": "stdin_stdout"
},
{
"input": "2 1\n7 8\n2 4\n",
"output": "11",
"type": "stdin_stdout"
},
{
"input": "2 1\n5 10\n7 10\n",
"output": "17",
"type": "stdin_stdout"
},
{
"input": "4 2\n2 10\n3 10\n5 10\n9 10\n",
"output": "27",
"type": "stdin_stdout"
},
{
"input": "2 1\n99 100\n5 10\n",
"output": "109",
"type": "stdin_stdout"
},
{
"input": "4 2\n2 10\n3 10\n5 10\n9 9\n",
"output": "27",
"type": "stdin_stdout"
},
{
"input": "2 1\n3 7\n5 7\n",
"output": "11",
"type": "stdin_stdout"
},
{
"input": "2 1\n10 10\n3 6\n",
"output": "16",
"type": "stdin_stdout"
},
{
"input": "2 1\n100 1\n2 4\n",
"output": "5",
"type": "stdin_stdout"
},
{
"input": "5 0\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"output": "5",
"type": "stdin_stdout"
},
{
"input": "3 1\n3 7\n4 5\n2 3\n",
"output": "12",
"type": "stdin_stdout"
},
{
"input": "2 1\n3 9\n7 8\n",
"output": "13",
"type": "stdin_stdout"
},
{
"input": "2 1\n10 2\n3 4\n",
"output": "6",
"type": "stdin_stdout"
},
{
"input": "2 1\n40 40\n3 5\n",
"output": "45",
"type": "stdin_stdout"
},
{
"input": "2 1\n5 3\n1 2\n",
"output": "5",
"type": "stdin_stdout"
},
{
"input": "10 5\n9 5\n10 5\n11 5\n12 5\n13 5\n2 4\n2 4\n2 4\n2 4\n2 4\n",
"output": "45",
"type": "stdin_stdout"
},
{
"input": "3 1\n1 5\n1 5\n4 4\n",
"output": "7",
"type": "stdin_stdout"
},
{
"input": "4 0\n1 1\n1 1\n1 1\n1 1\n",
"output": "4",
"type": "stdin_stdout"
},
{
"input": "4 1\n1000 1001\n1000 1001\n2 4\n1 2\n",
"output": "2005",
"type": "stdin_stdout"
},
{
"input": "2 1\n15 30\n50 59\n",
"output": "80",
"type": "stdin_stdout"
},
{
"input": "2 1\n8 8\n3 5\n",
"output": "13",
"type": "stdin_stdout"
},
{
"input": "2 1\n4 5\n2 5\n",
"output": "8",
"type": "stdin_stdout"
},
{
"input": "3 2\n3 3\n1 2\n1 2\n",
"output": "7",
"type": "stdin_stdout"
},
{
"input": "3 1\n2 5\n2 5\n4 4\n",
"output": "10",
"type": "stdin_stdout"
},
{
"input": "2 1\n3 10\n50 51\n",
"output": "56",
"type": "stdin_stdout"
},
{
"input": "4 2\n2 4\n2 4\n9 10\n9 10\n",
"output": "26",
"type": "stdin_stdout"
},
{
"input": "2 1\n3 5\n8 8\n",
"output": "13",
"type": "stdin_stdout"
},
{
"input": "2 1\n100 150\n70 150\n",
"output": "240",
"type": "stdin_stdout"
},
{
"input": "2 1\n4 5\n3 6\n",
"output": "10",
"type": "stdin_stdout"
},
{
"input": "2 1\n20 10\n3 5\n",
"output": "15",
"type": "stdin_stdout"
},
{
"input": "15 13\n76167099 92301116\n83163126 84046805\n45309500 65037149\n29982002 77381688\n76738161 52935441\n37889502 25466134\n55955619 14197941\n31462620 12999429\n64648384 8824773\n3552934 68992494\n2823376 9338427\n86832070 3763091\n67753633 2162190\n302887 92011825\n84894984 410533\n",
"output": "435467000",
"type": "stdin_stdout"
},
{
"input": "2 1\n8 7\n3 6\n",
"output": "13",
"type": "stdin_stdout"
},
{
"input": "2 1\n7 8\n3 5\n",
"output": "12",
"type": "stdin_stdout"
},
{
"input": "2 1\n10 10\n1 3\n",
"output": "12",
"type": "stdin_stdout"
},
{
"input": "2 1\n9 10\n2 4\n",
"output": "13",
"type": "stdin_stdout"
},
{
"input": "3 1\n10 11\n12 13\n8 10\n",
"output": "32",
"type": "stdin_stdout"
},
{
"input": "2 1\n5 10\n7 7\n",
"output": "17",
"type": "stdin_stdout"
},
{
"input": "4 2\n90 91\n2 10\n2 10\n2 10\n",
"output": "100",
"type": "stdin_stdout"
},
{
"input": "2 1\n2 4\n4 4\n",
"output": "8",
"type": "stdin_stdout"
},
{
"input": "2 1\n2 3\n4 3\n",
"output": "6",
"type": "stdin_stdout"
},
{
"input": "2 1\n40 45\n50 52\n",
"output": "95",
"type": "stdin_stdout"
},
{
"input": "3 1\n1 4\n2 4\n3 4\n",
"output": "8",
"type": "stdin_stdout"
},
{
"input": "2 1\n1 2\n1000 1000\n",
"output": "1002",
"type": "stdin_stdout"
},
{
"input": "2 1\n80 100\n70 95\n",
"output": "175",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/810/B"
} | vfc_10262 |
apps | verifiable_code | 128 | Solve the following coding problem using the programming language python:
It is a balmy spring afternoon, and Farmer John's n cows are ruminating about link-cut cacti in their stalls. The cows, labeled 1 through n, are arranged so that the i-th cow occupies the i-th stall from the left. However, Elsie, after realizing that she will forever live in the shadows beyond Bessie's limelight, has formed the Mischievous Mess Makers and is plotting to disrupt this beautiful pastoral rhythm. While Farmer John takes his k minute long nap, Elsie and the Mess Makers plan to repeatedly choose two distinct stalls and swap the cows occupying those stalls, making no more than one swap each minute.
Being the meticulous pranksters that they are, the Mischievous Mess Makers would like to know the maximum messiness attainable in the k minutes that they have. We denote as p_{i} the label of the cow in the i-th stall. The messiness of an arrangement of cows is defined as the number of pairs (i, j) such that i < j and p_{i} > p_{j}.
-----Input-----
The first line of the input contains two integers n and k (1 ≤ n, k ≤ 100 000) — the number of cows and the length of Farmer John's nap, respectively.
-----Output-----
Output a single integer, the maximum messiness that the Mischievous Mess Makers can achieve by performing no more than k swaps.
-----Examples-----
Input
5 2
Output
10
Input
1 10
Output
0
-----Note-----
In the first sample, the Mischievous Mess Makers can swap the cows in the stalls 1 and 5 during the first minute, then the cows in stalls 2 and 4 during the second minute. This reverses the arrangement of cows, giving us a total messiness of 10.
In the second sample, there is only one cow, so the maximum possible messiness is 0.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# You lost the game.
n,k = map(int, input().split())
r = 0
for i in range(min(k,n//2)):
r += (n-2*i-1) + (n-2*i-2)
print(r)
``` | {
"language": "python",
"test_cases": [
{
"input": "5 2\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100000 2\n",
"output": "399990\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8 3\n",
"output": "27\n",
"type": "stdin_stdout"
},
{
"input": "7 1\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "100000 40000\n",
"output": "4799960000\n",
"type": "stdin_stdout"
},
{
"input": "1 1000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 45\n",
"output": "4905\n",
"type": "stdin_stdout"
},
{
"input": "9 2\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "456 78\n",
"output": "58890\n",
"type": "stdin_stdout"
},
{
"input": "100000 50000\n",
"output": "4999950000\n",
"type": "stdin_stdout"
},
{
"input": "100000 50001\n",
"output": "4999950000\n",
"type": "stdin_stdout"
},
{
"input": "100000 50002\n",
"output": "4999950000\n",
"type": "stdin_stdout"
},
{
"input": "100000 50003\n",
"output": "4999950000\n",
"type": "stdin_stdout"
},
{
"input": "100000 49998\n",
"output": "4999949994\n",
"type": "stdin_stdout"
},
{
"input": "100000 49997\n",
"output": "4999949985\n",
"type": "stdin_stdout"
},
{
"input": "99999 49998\n",
"output": "4999849998\n",
"type": "stdin_stdout"
},
{
"input": "99999 49997\n",
"output": "4999849991\n",
"type": "stdin_stdout"
},
{
"input": "99999 49996\n",
"output": "4999849980\n",
"type": "stdin_stdout"
},
{
"input": "99999 50000\n",
"output": "4999850001\n",
"type": "stdin_stdout"
},
{
"input": "99999 50001\n",
"output": "4999850001\n",
"type": "stdin_stdout"
},
{
"input": "99999 50002\n",
"output": "4999850001\n",
"type": "stdin_stdout"
},
{
"input": "30062 9\n",
"output": "540945\n",
"type": "stdin_stdout"
},
{
"input": "13486 3\n",
"output": "80895\n",
"type": "stdin_stdout"
},
{
"input": "29614 7\n",
"output": "414491\n",
"type": "stdin_stdout"
},
{
"input": "13038 8\n",
"output": "208472\n",
"type": "stdin_stdout"
},
{
"input": "96462 6\n",
"output": "1157466\n",
"type": "stdin_stdout"
},
{
"input": "22599 93799\n",
"output": "255346101\n",
"type": "stdin_stdout"
},
{
"input": "421 36817\n",
"output": "88410\n",
"type": "stdin_stdout"
},
{
"input": "72859 65869\n",
"output": "2654180511\n",
"type": "stdin_stdout"
},
{
"input": "37916 5241\n",
"output": "342494109\n",
"type": "stdin_stdout"
},
{
"input": "47066 12852\n",
"output": "879423804\n",
"type": "stdin_stdout"
},
{
"input": "84032 21951\n",
"output": "2725458111\n",
"type": "stdin_stdout"
},
{
"input": "70454 75240\n",
"output": "2481847831\n",
"type": "stdin_stdout"
},
{
"input": "86946 63967\n",
"output": "3779759985\n",
"type": "stdin_stdout"
},
{
"input": "71128 11076\n",
"output": "1330260828\n",
"type": "stdin_stdout"
},
{
"input": "46111 64940\n",
"output": "1063089105\n",
"type": "stdin_stdout"
},
{
"input": "46111 64940\n",
"output": "1063089105\n",
"type": "stdin_stdout"
},
{
"input": "56500 84184\n",
"output": "1596096750\n",
"type": "stdin_stdout"
},
{
"input": "60108 83701\n",
"output": "1806455778\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "1\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": "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": "3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5 1\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "6 1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "6 2\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "6 3\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "7 2\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "7 3\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "7 4\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "10 2\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "60982 2\n",
"output": "243918\n",
"type": "stdin_stdout"
},
{
"input": "23426 23\n",
"output": "1076515\n",
"type": "stdin_stdout"
},
{
"input": "444 3\n",
"output": "2643\n",
"type": "stdin_stdout"
},
{
"input": "18187 433\n",
"output": "15374531\n",
"type": "stdin_stdout"
},
{
"input": "6895 3544\n",
"output": "23767065\n",
"type": "stdin_stdout"
},
{
"input": "56204 22352\n",
"output": "1513297456\n",
"type": "stdin_stdout"
},
{
"input": "41977 5207\n",
"output": "382917573\n",
"type": "stdin_stdout"
},
{
"input": "78147 2321\n",
"output": "351981971\n",
"type": "stdin_stdout"
},
{
"input": "99742 62198\n",
"output": "4974183411\n",
"type": "stdin_stdout"
},
{
"input": "72099 38339\n",
"output": "2599096851\n",
"type": "stdin_stdout"
},
{
"input": "82532 4838\n",
"output": "751762306\n",
"type": "stdin_stdout"
},
{
"input": "79410 33144\n",
"output": "3066847464\n",
"type": "stdin_stdout"
},
{
"input": "11021 3389\n",
"output": "51726307\n",
"type": "stdin_stdout"
},
{
"input": "66900 7572\n",
"output": "898455660\n",
"type": "stdin_stdout"
},
{
"input": "99999 49999\n",
"output": "4999850001\n",
"type": "stdin_stdout"
},
{
"input": "100000 49999\n",
"output": "4999949999\n",
"type": "stdin_stdout"
},
{
"input": "100000 100000\n",
"output": "4999950000\n",
"type": "stdin_stdout"
},
{
"input": "100000 1\n",
"output": "199997\n",
"type": "stdin_stdout"
},
{
"input": "4 100\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "100000 1234\n",
"output": "243753254\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/645/B"
} | vfc_10266 |
apps | verifiable_code | 129 | Solve the following coding problem using the programming language python:
Ivan is collecting coins. There are only $N$ different collectible coins, Ivan has $K$ of them. He will be celebrating his birthday soon, so all his $M$ freinds decided to gift him coins. They all agreed to three terms: Everyone must gift as many coins as others. All coins given to Ivan must be different. Not less than $L$ coins from gifts altogether, must be new in Ivan's collection.
But his friends don't know which coins have Ivan already got in his collection. They don't want to spend money so they want to buy minimum quantity of coins, that satisfy all terms, irrespective of the Ivan's collection. Help them to find this minimum number of coins or define it's not possible to meet all the terms.
-----Input-----
The only line of input contains 4 integers $N$, $M$, $K$, $L$ ($1 \le K \le N \le 10^{18}$; $1 \le M, \,\, L \le 10^{18}$) — quantity of different coins, number of Ivan's friends, size of Ivan's collection and quantity of coins, that must be new in Ivan's collection.
-----Output-----
Print one number — minimal number of coins one friend can gift to satisfy all the conditions. If it is impossible to satisfy all three conditions print "-1" (without quotes).
-----Examples-----
Input
20 15 2 3
Output
1
Input
10 11 2 4
Output
-1
-----Note-----
In the first test, one coin from each friend is enough, as he will be presented with 15 different coins and 13 of them will definitely be new.
In the second test, Ivan has 11 friends, but there are only 10 different coins. So all friends can't present him different coins.
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, l = map(int, input().split())
cnt = (k + l + m - 1) // m
if cnt * m > n:
print(-1)
else:
print(cnt)
``` | {
"language": "python",
"test_cases": [
{
"input": "20 15 2 3\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "10 11 2 4\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "2 1 1 1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "10 2 9 7\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "530897800469409942 582203276934671957 137373076313041391 377446491430894140\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1 1 1000000000000000000\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "48295947839584738 12 49503958 47108947578469711\n",
"output": "3925745635664473",
"type": "stdin_stdout"
},
{
"input": "100 20 98 2\n",
"output": "5",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100 100 1 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "1847865 4577 9483 478\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "100 20 98 1\n",
"output": "5",
"type": "stdin_stdout"
},
{
"input": "100 20 98 3\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "765492670657661908 120898708872120733 441256691517467806 47990392299392923\n",
"output": "5",
"type": "stdin_stdout"
},
{
"input": "213010000114902384 512822228505417058 119707578037963386 328177470098391815\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "596503389699530515 914343495357891807 130250515210162891 644804913475506893\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "63890874321754343 897803536671470111 34570989234398115 10108894437967468\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "472139220663336814 338152858568948777 71689560172156215 572945143351096534\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "778131271313761135 29162283248225583 355425770702597603 716328407201370097\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100000000000067841 932 9842 64\n",
"output": "11",
"type": "stdin_stdout"
},
{
"input": "800000030000007009 78 53784432543372 5435578332346625\n",
"output": "70376445703718",
"type": "stdin_stdout"
},
{
"input": "990754991918791804 172731536557340966 872344445472278981 798534984920208868\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "778957518786811855 571857503518586907 769096994987230500 32325604610793188\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "695046328995629472 971547627530533122 523943811516500483 107182605463941115\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "80030159858197311 792835026333624499 74094987869466717 865812863350994075\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "7 4 1 6\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "99 5 98 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "99999999994444488 3 77777777777777777 8888888888888888\n",
"output": "28888888888888889",
"type": "stdin_stdout"
},
{
"input": "10 6 3 7\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "4 4 2 2\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "20 15 10 10\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "20 15 20 3\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "50 9 20 30\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "1000000000000000 1000000000000000 1 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "19366 12326 871 14611\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "20 3 10 10\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "20 15 6 10\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "5 2 2 3\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "26255 5436 5959 18019\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000000 1000000000001 1000000000000\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "5 3 2 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "20 6 19 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "10 9 6 4\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "5 4 3 2\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "1 1 1 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "7 4 1 4\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "7 3 6 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "10 9 2 8\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "5 2 1 4\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100000000000000000 99999999999999 99999999999999 9999\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "20 2 20 5\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "10 6 4 3\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "3 2 1 2\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "10 3 2 8\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1 1 999999999999999999\n",
"output": "1000000000000000000",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 2 1000000000000000 4\n",
"output": "500000000000002",
"type": "stdin_stdout"
},
{
"input": "9 5 2 6\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "15 9 9 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "20 12 7 6\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "7 4 4 3\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "21 10 5 16\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "12 7 6 6\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "3 3 1 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "15 10 7 5\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "20 11 1 13\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "10 3 7 3\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "10 9 7 3\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "5 3 2 2\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "12 5 3 9\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "11 3 9 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "19 5 12 5\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100 21 1 98\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "25 15 22 2\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "12 7 4 6\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "12 3 12 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "18 10 4 8\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "100 3 1 99\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "7 4 3 2\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "17 7 1 15\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "16 14 7 6\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "9 7 2 7\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "1000000000000000 1 1000000000000000 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "9 4 3 4\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "30 29 15 15\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "10 3 9 1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "20 11 10 2\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "29 15 5 13\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "10 7 6 3\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "4 2 1 2\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "7 2 5 2\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1 100000000000000000 200000000000000000\n",
"output": "300000000000000000",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1068/A"
} | vfc_10270 |
apps | verifiable_code | 130 | Solve the following coding problem using the programming language python:
Polycarp has a checkered sheet of paper of size n × m. Polycarp painted some of cells with black, the others remained white. Inspired by Malevich's "Black Square", Polycarp wants to paint minimum possible number of white cells with black so that all black cells form a square.
You are to determine the minimum possible number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. The square's side should have positive length.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 100) — the sizes of the sheet.
The next n lines contain m letters 'B' or 'W' each — the description of initial cells' colors. If a letter is 'B', then the corresponding cell is painted black, otherwise it is painted white.
-----Output-----
Print the minimum number of cells needed to be painted black so that the black cells form a black square with sides parallel to the painting's sides. All the cells that do not belong to the square should be white. If it is impossible, print -1.
-----Examples-----
Input
5 4
WWWW
WWWB
WWWB
WWBB
WWWW
Output
5
Input
1 2
BB
Output
-1
Input
3 3
WWW
WWW
WWW
Output
1
-----Note-----
In the first example it is needed to paint 5 cells — (2, 2), (2, 3), (3, 2), (3, 3) and (4, 2). Then there will be a square with side equal to three, and the upper left corner in (2, 2).
In the second example all the cells are painted black and form a rectangle, so it's impossible to get a square.
In the third example all cells are colored white, so it's sufficient to color any cell black.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
h, w = map(int, input().split())
x0, y0, x1, y1, c = 1000, 1000, -1, -1, 0
for i in range(h):
row = str(input())
for j in range(w):
if row[j] == 'B':
x0, y0, x1, y1, c = min(x0, i), min(y0, j), max(x1, i), max(y1, j), c + 1
ln = max(x1 - x0 + 1, y1 - y0 + 1)
if ln > min(h, w):
print(-1)
elif x1 == -1:
print(1)
else:
print(ln * ln - c)
``` | {
"language": "python",
"test_cases": [
{
"input": "5 4\nWWWW\nWWWB\nWWWB\nWWBB\nWWWW\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 2\nBB\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nWWW\nWWW\nWWW\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 1\nW\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 4\nWWWW\nWBWW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 5\nWWWWW\nBBWWW\nBBWWW\nWWWWW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 4\nWWWW\nWWWW\nWWWB\nWWWW\nWWWW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 5\nWWWWB\nWWWWW\nWWWBB\nWWBWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "5 10\nWWWWWWWWWW\nWWWWBWBBWW\nWWWWWWWWWW\nWWWWBWWWWW\nWWWWWWBWWW\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "20 10\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWBBWBWWWW\nWWBWWBWWWW\nWWWWBWWWWW\nWWWWBWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10 20\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWWWWWWBW\nWWWWWWWWWWWWWWWWWBWW\nWWWWWWWWWWWWWWWWWWWW\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1 1\nW\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1\nB\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nWW\nWW\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nWW\nWB\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nWW\nBW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nWW\nBB\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nWB\nWW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nWB\nWB\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nWB\nBW\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nWB\nBB\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nBW\nWW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nBW\nWB\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nBW\nBW\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nBW\nBB\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nBB\nWW\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nBB\nWB\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nBB\nBW\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 2\nBB\nBB\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2\nWW\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 2\nWB\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2\nBW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nW\nW\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nW\nB\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nB\nW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 1\nB\nB\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 10\nWWBWWWBBWW\nWWWWWBWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWBBBWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWWWWWWWWWW\nWBWWWWWBWW\nWBWWBWWWBW\nWWBWBWWWWW\nWWWBWWBBWW\nWWBBWBWBWW\nBBWWWWWBWW\nWWBWWBBBWW\nWWWBWBBWWW\nWWWBBWBWWW\nWWWWWWWWWW\nWWWBWWWWWW\nWWWWWWWWWW\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "10 20\nWWWWWWWBWWWWWWWBWWWB\nWWWBWWWBWWWWWWWWWWWW\nBWWWWWWWWWWWWWWWWWBB\nWWWWWWBWWBWWBWWWBWWW\nWWWWWWWWBWWBWWWBWWWW\nWBWWWWWWWBWWWWWWWWWW\nWWWBWBWWBWWWWWBBWWWB\nWWBBWWWWWWWWWWWWWWWW\nWWWWWWWWWWWWWBWWWWBW\nWWWWWWWWWWWWBWWBWWWB\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 100\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 100\nBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWW\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 100\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWB\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 1\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 1\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "1 5\nWBBWW\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "20 1\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nW\nB\nB\nB\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nWBW\nWBB\nWWW\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 6\nWWWWWW\nWWWBWW\nWWWWWB\nWWWWWW\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5 5\nWBWBW\nWWWWW\nWWWWW\nWWWWW\nWWWWW\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nBBB\nBBB\nBBB\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 5\nWWBWW\nWWWWW\nWWWWW\nWWWWW\nWWBWW\n",
"output": "23\n",
"type": "stdin_stdout"
},
{
"input": "5 4\nWWBW\nBWWB\nWWWW\nWWWW\nWWWW\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "5 4\nWWWW\nWWWB\nWWWB\nWWWW\nWBBW\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "6 6\nWWBWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWBWW\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nBBW\nWWW\nBWW\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nBWB\nWWW\nBWW\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "6 6\nWBWWWW\nBWWWBW\nWWWWWW\nWWBWWW\nWWWWWW\nWWWWWW\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nWWW\nWBW\nWWW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nBBB\nWWW\nWWW\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5 5\nWWBWW\nWWBWW\nWBBBW\nWWBWW\nWWBWW\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "5 2\nWB\nWB\nWB\nWW\nWW\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "4 7\nBBBBBWW\nWWWWWWW\nWWWWWWW\nWWWWWWW\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 4\nWWWW\nWWWB\nWWWW\nWWBB\nWWWW\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "4 4\nWWWW\nWBWW\nWWWW\nWWWW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 5\nWWWWW\nBBBWW\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 6\nWWBWWW\nWWWWWW\nWWWWBW\nWWWWWW\nWWWWWW\nWWBWWW\n",
"output": "33\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nWBW\nWBW\nWBW\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 5\nWWBBB\nBWBBB\nWWBBB\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 5\nWWWWB\nBWWWW\nWWWWB\nWWWWW\nWWWWW\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "5 5\nBWWWB\nWWWWW\nWWWWW\nWWWWW\nBWWWW\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "4 5\nWWWWW\nBWWWW\nBBBWW\nWWWWW\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4 4\nBBBB\nWWWW\nWWWW\nWWWW\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "4 6\nWWWWWW\nBWWWWW\nBWWWWW\nBBBBBB\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "3 6\nWWWWWW\nBBBWWW\nWWWWWW\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5 2\nWW\nBW\nBW\nBB\nWW\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 5\nWWWWW\nWWWWW\nBBBBB\nWWWWW\nWWWWW\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "5 5\nWWWWW\nWWWWW\nWWWWB\nWBWWW\nWWWWW\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "1 5\nWWBWW\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 3\nBBB\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 4\nWWBW\nBWBW\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "6 6\nBBBBBB\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\nWWWWWW\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "4 4\nWWWW\nWWWW\nWWWW\nWWWW\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 3\nWWW\nWWW\nWWB\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 1\nB\nB\nW\nW\nW\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "2 3\nWBW\nWBW\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5 2\nWW\nWB\nWB\nWB\nWW\n",
"output": "-1\n",
"type": "stdin_stdout"
},
{
"input": "5 5\nWWWWW\nBWWWW\nWWWWB\nWWWWW\nWWWWW\n",
"output": "23\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/828/B"
} | vfc_10274 |
apps | verifiable_code | 131 | Solve the following coding problem using the programming language python:
There is a beautiful garden of stones in Innopolis.
Its most beautiful place is the $n$ piles with stones numbered from $1$ to $n$.
EJOI participants have visited this place twice.
When they first visited it, the number of stones in piles was $x_1, x_2, \ldots, x_n$, correspondingly. One of the participants wrote down this sequence in a notebook.
They visited it again the following day, and the number of stones in piles was equal to $y_1, y_2, \ldots, y_n$. One of the participants also wrote it down in a notebook.
It is well known that every member of the EJOI jury during the night either sits in the room $108$ or comes to the place with stones. Each jury member who comes there either takes one stone for himself or moves one stone from one pile to another. We can assume that there is an unlimited number of jury members. No one except the jury goes to the place with stones at night.
Participants want to know whether their notes can be correct or they are sure to have made a mistake.
-----Input-----
The first line of the input file contains a single integer $n$, the number of piles with stones in the garden ($1 \leq n \leq 50$).
The second line contains $n$ integers separated by spaces $x_1, x_2, \ldots, x_n$, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the first time ($0 \leq x_i \leq 1000$).
The third line contains $n$ integers separated by spaces $y_1, y_2, \ldots, y_n$, the number of stones in piles recorded in the notebook when the participants came to the place with stones for the second time ($0 \leq y_i \leq 1000$).
-----Output-----
If the records can be consistent output "Yes", otherwise output "No" (quotes for clarity).
-----Examples-----
Input
5
1 2 3 4 5
2 1 4 3 5
Output
Yes
Input
5
1 1 1 1 1
1 0 1 0 1
Output
Yes
Input
3
2 3 9
1 7 9
Output
No
-----Note-----
In the first example, the following could have happened during the night: one of the jury members moved one stone from the second pile to the first pile, and the other jury member moved one stone from the fourth pile to the third pile.
In the second example, the jury took stones from the second and fourth piles.
It can be proved that it is impossible for the jury members to move and took stones to convert the first array into the second array.
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 = list(map(int, input().split()))
b = list(map(int, input().split()))
c = sum(a)
d = sum(b)
if c >= d:
print('Yes')
else:
print('No')
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n1 2 3 4 5\n2 1 4 3 5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 1 1 1\n1 0 1 0 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 3 9\n1 7 9\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "40\n361 372 139 808 561 460 421 961 727 719 130 235 320 470 432 759 317 886 624 666 917 133 736 710 462 424 541 118 228 216 612 339 800 557 291 128 801 9 0 318\n364 689 60 773 340 571 627 932 581 856 131 153 406 475 217 716 433 519 417 552 919 53 923 605 319 359 516 121 207 180 373 343 905 641 477 416 927 207 160 245\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "45\n246 523 714 431 266 139 591 246 845 818 805 198 70 620 166 478 87 849 415 228 957 59 190 332 632 14 451 857 221 638 837 222 970 643 19 172 39 185 903 342 750 265 241 968 876\n460 389 541 164 324 52 246 107 826 864 693 132 10 697 429 434 99 950 164 85 972 157 327 337 592 241 350 962 130 673 967 373 657 923 456 347 394 76 743 407 724 117 268 741 918\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "50\n620 222 703 953 303 333 371 125 554 88 60 189 873 644 817 100 760 64 887 605 611 845 762 916 21 26 254 553 602 66 796 531 329 888 274 584 215 135 69 403 680 734 440 406 53 958 135 230 918 206\n464 128 878 999 197 358 447 191 530 218 63 443 630 587 836 232 659 117 787 254 667 646 498 845 252 179 452 390 455 16 686 522 236 945 498 635 445 225 7 38 553 946 563 457 102 942 130 310 941 312\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "40\n361 372 139 808 561 460 421 961 727 719 130 235 320 470 432 759 317 886 624 666 917 133 736 710 462 424 541 118 228 216 612 339 800 557 291 128 801 9 0 318\n29 469 909 315 333 412 777 490 492 431 908 412 187 829 453 595 896 817 755 914 34 890 583 691 544 969 733 132 802 170 67 68 370 146 856 184 275 785 928 798\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "45\n246 523 714 431 266 139 591 246 845 818 805 198 70 620 166 478 87 849 415 228 957 59 190 332 632 14 451 857 221 638 837 222 970 643 19 172 39 185 903 342 750 265 241 968 876\n918 332 978 856 517 621 81 62 150 482 834 649 860 259 394 937 647 0 400 783 574 713 355 221 543 389 937 824 53 361 824 454 217 180 840 407 160 417 373 737 49 476 320 59 886\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "50\n620 222 703 953 303 333 371 125 554 88 60 189 873 644 817 100 760 64 887 605 611 845 762 916 21 26 254 553 602 66 796 531 329 888 274 584 215 135 69 403 680 734 440 406 53 958 135 230 918 206\n494 447 642 337 839 128 971 105 915 739 803 8 848 253 554 186 338 656 238 106 89 13 622 777 663 669 360 451 461 639 403 255 570 648 996 618 55 409 733 230 533 226 774 559 161 184 933 308 554 161\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "50\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n633\n609\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2\n353 313\n327 470\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "3\n835 638 673\n624 232 266\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4\n936 342 19 398\n247 874 451 768\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "5\n417 666 978 553 271\n488 431 625 503 978\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "10\n436 442 197 740 550 361 317 473 843 982\n356 826 789 479 641 974 106 221 57 858\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "15\n702 593 763 982 263 48 487 759 961 80 642 169 778 621 764\n932 885 184 230 411 644 296 351 112 940 73 707 296 472 86\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "20\n82 292 379 893 300 854 895 638 58 971 278 168 580 272 653 315 176 773 709 789\n298 710 311 695 328 459 510 994 472 515 634 568 368 913 182 223 361 132 92 620\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "25\n349 443 953 126 394 160 63 924 795 450 572 513 338 33 768 34 955 737 874 731 329 16 377 318 125\n56 39 740 846 938 851 459 538 617 664 268 981 315 2 23 76 974 417 786 816 207 227 870 385 958\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "30\n722 523 950 656 431 347 463 795 893 348 208 893 140 65 419 36 627 333 972 346 230 422 337 893 896 442 835 56 846 986\n429 148 890 854 546 680 776 265 551 465 387 823 996 845 374 867 411 742 447 267 711 989 501 694 456 451 192 529 215 709\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "35\n607 674 142 278 135 34 13 80 629 448 875 856 518 446 161 376 406 288 764 289 643 347 164 515 73 39 126 413 848 788 653 651 67 320 655\n717 5 441 833 869 107 620 329 877 536 753 593 610 811 360 42 46 996 635 96 301 565 190 99 570 168 528 355 830 392 356 106 211 405 607\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1\n633\n633\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2\n353 313\n344 322\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n835 638 673\n516 880 750\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4\n936 342 19 398\n807 250 199 439\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n417 666 978 553 271\n72 946 832 454 581\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "10\n436 442 197 740 550 361 317 473 843 982\n788 683 32 402 305 396 823 206 739 967\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "15\n702 593 763 982 263 48 487 759 961 80 642 169 778 621 764\n346 342 969 741 762 123 89 823 955 599 575 312 547 784 645\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "20\n82 292 379 893 300 854 895 638 58 971 278 168 580 272 653 315 176 773 709 789\n370 433 505 670 178 892 948 864 252 906 45 275 891 185 432 12 43 270 951 953\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "25\n349 443 953 126 394 160 63 924 795 450 572 513 338 33 768 34 955 737 874 731 329 16 377 318 125\n75 296 997 211 919 7 357 928 891 829 119 509 184 29 769 262 973 936 100 588 115 536 398 163 186\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "30\n722 523 950 656 431 347 463 795 893 348 208 893 140 65 419 36 627 333 972 346 230 422 337 893 896 442 835 56 846 986\n914 569 671 995 728 188 135 588 943 433 368 615 218 38 810 484 468 128 785 149 398 587 174 881 875 477 737 181 752 821\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "35\n607 674 142 278 135 34 13 80 629 448 875 856 518 446 161 376 406 288 764 289 643 347 164 515 73 39 126 413 848 788 653 651 67 320 655\n452 596 228 56 48 35 155 250 793 729 630 495 803 209 156 423 427 270 925 479 635 639 50 489 27 198 324 241 564 898 178 713 131 337 738\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n1000\n1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2\n1000 1000\n1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n1000 1000 1000\n1000 1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4\n1000 1000 1000 1000\n1000 1000 1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "10\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "15\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "20\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "25\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "30\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "35\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "40\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "45\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "8\n5 5 0 0 0 0 0 0\n1 0 0 0 0 0 0 0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n50\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n9 9 9 9 9\n10 9 9 9 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "6\n3 4 2 5 6 3\n2 3 2 5 6 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 1 1\n0 0 0 0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 3 3\n1 0 0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1 5\n1 2 4\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 4 5\n1 2 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 4 5\n1 1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 3\n2 4\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n5 5 5\n1 1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n11\n9\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 3 4 6\n1 2 3 4 5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "50\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 4 4\n3 5 4\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1\n100\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n300\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 5 5 5 5\n1 1 1 1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n1000 1000 1000\n0 0 0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n3\n2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2\n5 5\n1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2\n10 1\n1 9\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n3 3 3 3 3\n2 2 2 2 2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n10\n5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 3 4 5 6\n0 0 0 0 4\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 3\n2 2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n100\n0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 3 4 5 1\n1 1 3 4 5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n10 10 1\n0 0 2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 3 4 5 6\n0 0 0 0 19\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n1000\n0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 1 1\n0 0 0 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n2 3 4 5 1\n1 1 1 1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n6\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n4 5 3 6 7\n1 1 4 4 5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2\n500 500\n1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n10\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 4 2\n4 3 0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n7\n3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 5 6\n3 2 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 2 3 4 5\n0 0 0 0 0\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 3 3\n1 1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1013/A"
} | vfc_10278 |
apps | verifiable_code | 132 | Solve the following coding problem using the programming language python:
Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece is a sector of angle equal to a_{i}. Vasya and Petya want to divide all pieces of pizza into two continuous sectors in such way that the difference between angles of these sectors is minimal. Sector angle is sum of angles of all pieces in it. Pay attention, that one of sectors can be empty.
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 360) — the number of pieces into which the delivered pizza was cut.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 360) — the angles of the sectors into which the pizza was cut. The sum of all a_{i} is 360.
-----Output-----
Print one integer — the minimal difference between angles of sectors that will go to Vasya and Petya.
-----Examples-----
Input
4
90 90 90 90
Output
0
Input
3
100 100 160
Output
40
Input
1
360
Output
360
Input
4
170 30 150 10
Output
0
-----Note-----
In first sample Vasya can take 1 and 2 pieces, Petya can take 3 and 4 pieces. Then the answer is |(90 + 90) - (90 + 90)| = 0.
In third sample there is only one piece of pizza that can be taken by only one from Vasya and Petya. So the answer is |360 - 0| = 360.
In fourth sample Vasya can take 1 and 4 pieces, then Petya will take 2 and 3 pieces. So the answer is |(170 + 10) - (30 + 150)| = 0.
Picture explaning fourth sample:
[Image]
Both red and green sectors consist of two adjacent pieces of pizza. So Vasya can take green sector, then Petya will take red sector.
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 = list(map(int, input().split()))
mn = 360
for i in range(n):
x = 0
for j in range(i, n):
x += a[j]
mn = min(mn, abs(x - (360 - x)))
print(mn)
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n90 90 90 90\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3\n100 100 160\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "1\n360\n",
"output": "360\n",
"type": "stdin_stdout"
},
{
"input": "4\n170 30 150 10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5\n10 10 10 10 320\n",
"output": "280\n",
"type": "stdin_stdout"
},
{
"input": "8\n45 45 45 45 45 45 45 45\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3\n120 120 120\n",
"output": "120\n",
"type": "stdin_stdout"
},
{
"input": "5\n110 90 70 50 40\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "2\n170 190\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "15\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "5\n30 60 180 60 30\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n359 1\n",
"output": "358\n",
"type": "stdin_stdout"
},
{
"input": "5\n100 100 30 100 30\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "5\n36 34 35 11 244\n",
"output": "128\n",
"type": "stdin_stdout"
},
{
"input": "5\n96 94 95 71 4\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "2\n85 275\n",
"output": "190\n",
"type": "stdin_stdout"
},
{
"input": "3\n281 67 12\n",
"output": "202\n",
"type": "stdin_stdout"
},
{
"input": "5\n211 113 25 9 2\n",
"output": "62\n",
"type": "stdin_stdout"
},
{
"input": "13\n286 58 6 1 1 1 1 1 1 1 1 1 1\n",
"output": "212\n",
"type": "stdin_stdout"
},
{
"input": "15\n172 69 41 67 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20\n226 96 2 20 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "92\n",
"type": "stdin_stdout"
},
{
"input": "50\n148 53 32 11 4 56 8 2 5 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": "0\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1 358\n",
"output": "356\n",
"type": "stdin_stdout"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 341\n",
"output": "322\n",
"type": "stdin_stdout"
},
{
"input": "33\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 328\n",
"output": "296\n",
"type": "stdin_stdout"
},
{
"input": "70\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 291\n",
"output": "222\n",
"type": "stdin_stdout"
},
{
"input": "130\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 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 231\n",
"output": "102\n",
"type": "stdin_stdout"
},
{
"input": "200\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 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 161\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "222\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 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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 139\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10\n8 3 11 4 1 10 10 1 8 304\n",
"output": "248\n",
"type": "stdin_stdout"
},
{
"input": "12\n8 7 7 3 11 2 10 1 10 8 10 283\n",
"output": "206\n",
"type": "stdin_stdout"
},
{
"input": "13\n10 8 9 10 5 9 4 1 10 11 1 7 275\n",
"output": "190\n",
"type": "stdin_stdout"
},
{
"input": "14\n1 6 3 11 9 5 9 8 5 6 7 3 7 280\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "15\n10 11 5 4 11 5 4 1 5 4 5 5 9 6 275\n",
"output": "190\n",
"type": "stdin_stdout"
},
{
"input": "30\n8 7 5 8 3 7 2 4 3 8 11 3 9 11 2 4 1 4 5 6 11 5 8 3 6 3 11 2 11 189\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "70\n5 3 6 8 9 2 8 9 11 5 2 8 9 11 7 6 6 9 7 11 7 6 3 8 2 4 4 8 4 3 2 2 3 5 6 5 11 2 7 7 5 8 10 5 2 1 10 9 4 10 7 1 8 10 9 1 5 1 1 1 2 1 1 1 1 1 1 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "29\n2 10 1 5 7 2 9 11 9 9 10 8 4 11 2 5 4 1 4 9 6 10 8 3 1 3 8 9 189\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "35\n3 4 11 4 4 2 3 4 3 9 7 10 2 7 8 3 11 3 6 4 6 7 11 10 8 7 6 7 2 8 5 3 2 2 168\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "60\n4 10 3 10 6 3 11 8 11 9 3 5 9 2 6 5 6 9 4 10 1 1 3 7 2 10 5 5 3 10 5 2 1 2 9 11 11 9 11 4 11 7 5 6 10 9 3 4 7 8 7 3 6 7 8 5 1 1 1 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "71\n3 11 8 1 10 1 7 9 6 4 11 10 11 2 4 1 11 7 9 10 11 4 8 7 11 3 8 4 1 8 4 2 9 9 7 10 10 9 5 7 9 7 2 1 7 6 5 11 5 9 4 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "63\n2 11 5 8 7 9 9 8 10 5 9 10 11 8 10 2 3 5 3 7 5 10 2 9 4 8 1 8 5 9 7 7 1 8 7 7 9 10 10 10 8 7 7 2 2 8 9 7 10 8 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "81\n5 8 7 11 2 7 1 1 5 8 7 2 3 11 4 9 7 6 4 4 2 1 1 7 9 4 1 8 3 1 4 10 7 9 9 8 11 3 4 3 10 8 6 4 7 2 4 3 6 11 11 10 7 10 2 10 8 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": "0\n",
"type": "stdin_stdout"
},
{
"input": "47\n5 3 7 4 2 7 8 1 9 10 5 11 10 7 7 5 1 3 2 11 3 8 6 1 6 10 8 3 2 10 5 6 8 6 9 7 10 9 7 4 8 11 10 1 5 11 68\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100\n5 8 9 3 2 3 9 8 11 10 4 8 1 1 1 1 6 5 10 9 5 3 7 7 2 11 10 2 3 2 2 8 7 3 5 5 10 9 2 5 10 6 7 7 4 7 7 8 2 8 9 9 2 4 1 1 3 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": "0\n",
"type": "stdin_stdout"
},
{
"input": "120\n9 11 3 7 3 7 9 1 10 7 11 4 1 5 3 5 6 3 1 11 8 8 11 7 3 5 1 9 1 7 10 10 10 10 9 5 4 8 2 8 2 1 4 5 3 11 3 5 1 1 2 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": "0\n",
"type": "stdin_stdout"
},
{
"input": "200\n7 7 9 8 2 8 5 8 3 9 7 10 2 9 11 8 11 7 5 2 6 3 11 9 5 1 10 2 1 2 2 2 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 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": "0\n",
"type": "stdin_stdout"
},
{
"input": "220\n3 2 8 1 3 5 5 11 1 5 2 6 9 2 2 6 8 10 7 1 3 2 10 9 10 10 4 10 9 5 1 1 2 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 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": "0\n",
"type": "stdin_stdout"
},
{
"input": "6\n27 15 28 34 41 215\n",
"output": "70\n",
"type": "stdin_stdout"
},
{
"input": "7\n41 38 41 31 22 41 146\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "8\n24 27 34 23 29 23 30 170\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "9\n11 11 20 20 33 32 35 26 172\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "10\n36 13 28 13 33 34 23 25 34 121\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "11\n19 37 13 41 37 15 32 12 19 35 100\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "12\n37 25 34 38 21 24 34 38 11 29 28 41\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "13\n24 40 20 26 25 29 39 29 35 28 19 18 28\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "14\n11 21 40 19 28 34 13 16 23 30 34 22 25 44\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n95 91 174\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "4\n82 75 78 125\n",
"output": "46\n",
"type": "stdin_stdout"
},
{
"input": "6\n87 75 88 94 15 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10\n27 52 58 64 45 64 1 19 2 28\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "50\n14 12 11 8 1 6 11 6 7 8 4 11 4 5 7 3 5 4 7 24 10 2 3 4 6 13 2 1 8 7 5 13 10 8 5 20 1 2 23 7 14 3 4 4 2 8 8 2 6 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100\n3 3 4 3 3 6 3 2 8 2 13 3 1 1 2 1 3 4 1 7 1 2 2 6 3 2 10 3 1 2 5 6 2 3 3 2 3 11 8 3 2 6 1 3 3 4 7 7 2 2 1 2 6 3 3 2 3 1 3 8 2 6 4 2 1 12 2 2 2 1 4 1 4 1 3 1 3 1 5 2 6 6 7 1 2 3 2 4 4 2 5 9 8 2 4 6 5 1 1 3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "150\n1 5 1 2 2 2 1 4 2 2 2 3 1 2 1 2 2 2 2 1 2 2 2 1 5 3 4 1 3 4 5 2 4 2 1 2 2 1 1 2 3 2 4 2 2 3 3 1 1 5 2 3 2 1 9 2 1 1 2 1 4 1 1 3 2 2 2 1 2 2 2 1 3 3 4 2 2 1 3 3 3 1 4 3 4 1 2 2 1 1 1 2 2 5 4 1 1 1 2 1 2 3 2 2 6 3 3 3 1 2 1 1 2 8 2 2 4 3 4 5 3 1 4 2 2 2 2 1 4 4 1 1 2 2 4 9 6 3 1 1 2 1 3 4 1 3 2 2 2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "200\n1 2 1 3 1 3 1 2 1 4 6 1 2 2 2 2 1 1 1 1 3 2 1 2 2 2 1 2 2 2 2 1 1 1 3 2 3 1 1 2 1 1 2 1 1 1 1 1 1 2 1 2 2 4 1 3 1 2 1 2 2 1 2 1 3 1 1 2 2 1 1 1 1 2 4 1 2 1 1 1 2 1 3 1 1 3 1 2 2 4 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 3 3 1 1 1 2 1 3 3 1 2 1 3 1 3 3 1 2 2 1 4 1 2 2 1 2 2 4 2 5 1 2 2 1 2 1 2 1 5 2 1 2 2 1 2 4 1 2 2 4 2 3 2 3 1 2 1 1 2 2 2 1 1 2 1 4 1 2 1 1 2 1 2 3 1 1 1 2 2 3 1 3 2 2 3 1 2 1 2 1 1 2 1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5\n35 80 45 100 100\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "4\n90 179 90 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "5\n50 50 20 160 80\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5\n30 175 30 5 120\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "4\n170 30 10 150\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "6\n90 30 90 30 90 30\n",
"output": "60\n",
"type": "stdin_stdout"
},
{
"input": "4\n70 80 110 100\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "7\n35 45 70 100 10 10 90\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6\n50 90 10 90 20 100\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "6\n10 155 162 1 26 6\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "7\n80 90 80 45 10 10 45\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "4\n18 36 162 144\n",
"output": "36\n",
"type": "stdin_stdout"
},
{
"input": "5\n20 50 50 160 80\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "5\n10 30 140 20 160\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6\n90 80 60 50 40 40\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "9\n40 20 20 20 20 20 20 40 160\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "4\n90 54 90 126\n",
"output": "72\n",
"type": "stdin_stdout"
},
{
"input": "4\n150 170 30 10\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "8\n130 12 13 85 41 67 5 7\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "7\n70 170 20 10 30 30 30\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "8\n100 100 50 50 15 15 15 15\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "4\n100 70 80 110\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "5\n160 130 40 20 10\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "4\n20 149 151 40\n",
"output": "22\n",
"type": "stdin_stdout"
},
{
"input": "4\n100 10 100 150\n",
"output": "60\n",
"type": "stdin_stdout"
},
{
"input": "6\n19 64 105 168 1 3\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "8\n10 10 70 70 90 90 10 10\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/895/A"
} | vfc_10282 |
apps | verifiable_code | 133 | Solve the following coding problem using the programming language python:
Alice got many presents these days. So she decided to pack them into boxes and send them to her friends.
There are $n$ kinds of presents. Presents of one kind are identical (i.e. there is no way to distinguish two gifts of the same kind). Presents of different kinds are different (i.e. that is, two gifts of different kinds are distinguishable). The number of presents of each kind, that Alice has is very big, so we can consider Alice has an infinite number of gifts of each kind.
Also, there are $m$ boxes. All of them are for different people, so they are pairwise distinct (consider that the names of $m$ friends are written on the boxes). For example, putting the first kind of present into the first box but not into the second box, is different from putting the first kind of present into the second box but not into the first box.
Alice wants to pack presents with the following rules: She won't pack more than one present of each kind into the same box, so each box should contain presents of different kinds (i.e. each box contains a subset of $n$ kinds, empty boxes are allowed); For each kind at least one present should be packed into some box.
Now Alice wants to know how many different ways to pack the presents exists. Please, help her and calculate this number. Since the answer can be huge, output it by modulo $10^9+7$.
See examples and their notes for clarification.
-----Input-----
The first line contains two integers $n$ and $m$, separated by spaces ($1 \leq n,m \leq 10^9$) — the number of kinds of presents and the number of boxes that Alice has.
-----Output-----
Print one integer — the number of ways to pack the presents with Alice's rules, calculated by modulo $10^9+7$
-----Examples-----
Input
1 3
Output
7
Input
2 2
Output
9
-----Note-----
In the first example, there are seven ways to pack presents:
$\{1\}\{\}\{\}$
$\{\}\{1\}\{\}$
$\{\}\{\}\{1\}$
$\{1\}\{1\}\{\}$
$\{\}\{1\}\{1\}$
$\{1\}\{\}\{1\}$
$\{1\}\{1\}\{1\}$
In the second example there are nine ways to pack presents:
$\{\}\{1,2\}$
$\{1\}\{2\}$
$\{1\}\{1,2\}$
$\{2\}\{1\}$
$\{2\}\{1,2\}$
$\{1,2\}\{\}$
$\{1,2\}\{1\}$
$\{1,2\}\{2\}$
$\{1,2\}\{1,2\}$
For example, the way $\{2\}\{2\}$ is wrong, because presents of the first kind should be used in the least one box.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
# Contest: Codeforces Round #593 (Div. 2) (https://codeforces.com/contest/1236)
# Problem: B: Alice and the List of Presents (https://codeforces.com/contest/1236/problem/B)
def rint():
return int(input())
def rints():
return list(map(int, input().split()))
M = 10**9 + 7
n, m = rints()
print(pow((pow(2, m, M) + M - 1) % M, n, M))
``` | {
"language": "python",
"test_cases": [
{
"input": "1 3\n",
"output": "7",
"type": "stdin_stdout"
},
{
"input": "2 2\n",
"output": "9",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000\n",
"output": "751201557",
"type": "stdin_stdout"
},
{
"input": "489132389 96\n",
"output": "496937",
"type": "stdin_stdout"
},
{
"input": "462817723 208\n",
"output": "886407548",
"type": "stdin_stdout"
},
{
"input": "10 415749054\n",
"output": "763222305",
"type": "stdin_stdout"
},
{
"input": "185182737 683516583\n",
"output": "568113155",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "67 445057511\n",
"output": "687331027",
"type": "stdin_stdout"
},
{
"input": "53 710974288\n",
"output": "739543572",
"type": "stdin_stdout"
},
{
"input": "766313215 146\n",
"output": "577417399",
"type": "stdin_stdout"
},
{
"input": "483378560 249\n",
"output": "400296687",
"type": "stdin_stdout"
},
{
"input": "294440070 297\n",
"output": "391755258",
"type": "stdin_stdout"
},
{
"input": "22 346212760\n",
"output": "70690719",
"type": "stdin_stdout"
},
{
"input": "214 70\n",
"output": "57768876",
"type": "stdin_stdout"
},
{
"input": "498 36\n",
"output": "238608733",
"type": "stdin_stdout"
},
{
"input": "243 155\n",
"output": "872572138",
"type": "stdin_stdout"
},
{
"input": "911 144\n",
"output": "588180251",
"type": "stdin_stdout"
},
{
"input": "1208 1429\n",
"output": "809533438",
"type": "stdin_stdout"
},
{
"input": "362 1464\n",
"output": "76973162",
"type": "stdin_stdout"
},
{
"input": "1956 1933\n",
"output": "376783113",
"type": "stdin_stdout"
},
{
"input": "958 1712\n",
"output": "555561716",
"type": "stdin_stdout"
},
{
"input": "1737 2760\n",
"output": "702877932",
"type": "stdin_stdout"
},
{
"input": "297 2221\n",
"output": "118273419",
"type": "stdin_stdout"
},
{
"input": "851963022 4\n",
"output": "843890746",
"type": "stdin_stdout"
},
{
"input": "242811857 22\n",
"output": "658352132",
"type": "stdin_stdout"
},
{
"input": "943226362 45\n",
"output": "326355794",
"type": "stdin_stdout"
},
{
"input": "744891088 118\n",
"output": "857670894",
"type": "stdin_stdout"
},
{
"input": "607778684 18\n",
"output": "241523454",
"type": "stdin_stdout"
},
{
"input": "69 553612861\n",
"output": "343253715",
"type": "stdin_stdout"
},
{
"input": "39 884188112\n",
"output": "485799965",
"type": "stdin_stdout"
},
{
"input": "208 898957748\n",
"output": "590505163",
"type": "stdin_stdout"
},
{
"input": "204 697134196\n",
"output": "878017912",
"type": "stdin_stdout"
},
{
"input": "311 619805019\n",
"output": "357441166",
"type": "stdin_stdout"
},
{
"input": "75 511331377\n",
"output": "891361754",
"type": "stdin_stdout"
},
{
"input": "798664260 289720442\n",
"output": "405748370",
"type": "stdin_stdout"
},
{
"input": "118448079 385479325\n",
"output": "929397040",
"type": "stdin_stdout"
},
{
"input": "122681800 592225969\n",
"output": "849919410",
"type": "stdin_stdout"
},
{
"input": "411520242 339446102\n",
"output": "69858832",
"type": "stdin_stdout"
},
{
"input": "248755287 144691387\n",
"output": "666866415",
"type": "stdin_stdout"
},
{
"input": "617282691 956569994\n",
"output": "407582988",
"type": "stdin_stdout"
},
{
"input": "565315457 718194150\n",
"output": "180672585",
"type": "stdin_stdout"
},
{
"input": "330332097 730084442\n",
"output": "536919158",
"type": "stdin_stdout"
},
{
"input": "534571158 222043261\n",
"output": "212941625",
"type": "stdin_stdout"
},
{
"input": "807153816 542148359\n",
"output": "452817189",
"type": "stdin_stdout"
},
{
"input": "35785771 557468706\n",
"output": "763956563",
"type": "stdin_stdout"
},
{
"input": "199108316 823003436\n",
"output": "650559775",
"type": "stdin_stdout"
},
{
"input": "592582684 738223068\n",
"output": "830809744",
"type": "stdin_stdout"
},
{
"input": "840387185 768322358\n",
"output": "364216881",
"type": "stdin_stdout"
},
{
"input": "294176817 643050540\n",
"output": "425282882",
"type": "stdin_stdout"
},
{
"input": "651139198 572383165\n",
"output": "362206900",
"type": "stdin_stdout"
},
{
"input": "314697041 784667526\n",
"output": "579388817",
"type": "stdin_stdout"
},
{
"input": "188186551 379116090\n",
"output": "655244255",
"type": "stdin_stdout"
},
{
"input": "922338645 900544285\n",
"output": "187784871",
"type": "stdin_stdout"
},
{
"input": "117909304 588342759\n",
"output": "852741659",
"type": "stdin_stdout"
},
{
"input": "426452433 106792\n",
"output": "740748981",
"type": "stdin_stdout"
},
{
"input": "686898624 980111485\n",
"output": "805355123",
"type": "stdin_stdout"
},
{
"input": "169231047 790996597\n",
"output": "442732671",
"type": "stdin_stdout"
},
{
"input": "393454015 42675288\n",
"output": "221958294",
"type": "stdin_stdout"
},
{
"input": "955475387 410847984\n",
"output": "544061679",
"type": "stdin_stdout"
},
{
"input": "290496089 820810891\n",
"output": "707906935",
"type": "stdin_stdout"
},
{
"input": "635994662 423804127\n",
"output": "831152709",
"type": "stdin_stdout"
},
{
"input": "33727662 414901164\n",
"output": "529262173",
"type": "stdin_stdout"
},
{
"input": "886792224 998690495\n",
"output": "183247773",
"type": "stdin_stdout"
},
{
"input": "31 112\n",
"output": "626643854",
"type": "stdin_stdout"
},
{
"input": "71 106\n",
"output": "603494283",
"type": "stdin_stdout"
},
{
"input": "100 474\n",
"output": "180274936",
"type": "stdin_stdout"
},
{
"input": "14 469\n",
"output": "14294519",
"type": "stdin_stdout"
},
{
"input": "18 290\n",
"output": "544261782",
"type": "stdin_stdout"
},
{
"input": "172 39\n",
"output": "222650110",
"type": "stdin_stdout"
},
{
"input": "139 415\n",
"output": "639620853",
"type": "stdin_stdout"
},
{
"input": "117 2553\n",
"output": "906570878",
"type": "stdin_stdout"
},
{
"input": "156 342\n",
"output": "306076272",
"type": "stdin_stdout"
},
{
"input": "260 2998\n",
"output": "573924479",
"type": "stdin_stdout"
},
{
"input": "184 7\n",
"output": "715075794",
"type": "stdin_stdout"
},
{
"input": "428 71\n",
"output": "677189841",
"type": "stdin_stdout"
},
{
"input": "1046 34\n",
"output": "92349932",
"type": "stdin_stdout"
},
{
"input": "560 27\n",
"output": "179196390",
"type": "stdin_stdout"
},
{
"input": "732 137\n",
"output": "596791767",
"type": "stdin_stdout"
},
{
"input": "1730 39\n",
"output": "352860620",
"type": "stdin_stdout"
},
{
"input": "1335 185\n",
"output": "596600489",
"type": "stdin_stdout"
},
{
"input": "175 59\n",
"output": "315527995",
"type": "stdin_stdout"
},
{
"input": "900 32\n",
"output": "832035237",
"type": "stdin_stdout"
},
{
"input": "2998 38\n",
"output": "63403329",
"type": "stdin_stdout"
},
{
"input": "1 1000000000\n",
"output": "140625000",
"type": "stdin_stdout"
},
{
"input": "1000000000 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "5 2\n",
"output": "243",
"type": "stdin_stdout"
},
{
"input": "2 5\n",
"output": "961",
"type": "stdin_stdout"
},
{
"input": "7 6\n",
"output": "980611601",
"type": "stdin_stdout"
},
{
"input": "5 8\n",
"output": "203901829",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1236/B"
} | vfc_10286 |
apps | verifiable_code | 134 | Solve the following coding problem using the programming language python:
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.
For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.
Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.
Katya had no problems with completing this task. Will you do the same?
-----Input-----
The only line of the input contains single integer n (1 ≤ n ≤ 10^9) — the length of some side of a right triangle.
-----Output-----
Print two integers m and k (1 ≤ m, k ≤ 10^18), such that n, m and k form a Pythagorean triple, in the only line.
In case if there is no any Pythagorean triple containing integer n, print - 1 in the only line. If there are many answers, print any of them.
-----Examples-----
Input
3
Output
4 5
Input
6
Output
8 10
Input
1
Output
-1
Input
17
Output
144 145
Input
67
Output
2244 2245
-----Note-----[Image]
Illustration for the first sample.
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())
if n % 4 == 0:
temp = n // 4
m = temp * 3
k = temp * 5
elif n % 2 == 0:
n //= 2
m = n**2 // 2
k = m + 1
m *= 2
k *= 2
else:
m = n**2 // 2
k = m + 1
if 3 > n:
print("-1")
else:
print(m,k)
``` | {
"language": "python",
"test_cases": [
{
"input": "3\n",
"output": "4 5",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "8 10",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "17\n",
"output": "144 145",
"type": "stdin_stdout"
},
{
"input": "67\n",
"output": "2244 2245",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "24 26",
"type": "stdin_stdout"
},
{
"input": "14\n",
"output": "48 50",
"type": "stdin_stdout"
},
{
"input": "22\n",
"output": "120 122",
"type": "stdin_stdout"
},
{
"input": "23\n",
"output": "264 265",
"type": "stdin_stdout"
},
{
"input": "246\n",
"output": "15128 15130",
"type": "stdin_stdout"
},
{
"input": "902\n",
"output": "203400 203402",
"type": "stdin_stdout"
},
{
"input": "1000000000\n",
"output": "1250000000 750000000",
"type": "stdin_stdout"
},
{
"input": "1998\n",
"output": "998000 998002",
"type": "stdin_stdout"
},
{
"input": "2222222\n",
"output": "1234567654320 1234567654322",
"type": "stdin_stdout"
},
{
"input": "2222226\n",
"output": "1234572098768 1234572098770",
"type": "stdin_stdout"
},
{
"input": "1111110\n",
"output": "308641358024 308641358026",
"type": "stdin_stdout"
},
{
"input": "9999998\n",
"output": "24999990000000 24999990000002",
"type": "stdin_stdout"
},
{
"input": "1024\n",
"output": "1280 768",
"type": "stdin_stdout"
},
{
"input": "8388608\n",
"output": "10485760 6291456",
"type": "stdin_stdout"
},
{
"input": "4\n",
"output": "5 3",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "10 6",
"type": "stdin_stdout"
},
{
"input": "16\n",
"output": "20 12",
"type": "stdin_stdout"
},
{
"input": "492\n",
"output": "615 369",
"type": "stdin_stdout"
},
{
"input": "493824\n",
"output": "617280 370368",
"type": "stdin_stdout"
},
{
"input": "493804\n",
"output": "617255 370353",
"type": "stdin_stdout"
},
{
"input": "493800\n",
"output": "617250 370350",
"type": "stdin_stdout"
},
{
"input": "2048\n",
"output": "2560 1536",
"type": "stdin_stdout"
},
{
"input": "8388612\n",
"output": "10485765 6291459",
"type": "stdin_stdout"
},
{
"input": "44\n",
"output": "55 33",
"type": "stdin_stdout"
},
{
"input": "444\n",
"output": "555 333",
"type": "stdin_stdout"
},
{
"input": "4444\n",
"output": "5555 3333",
"type": "stdin_stdout"
},
{
"input": "44444\n",
"output": "55555 33333",
"type": "stdin_stdout"
},
{
"input": "444444\n",
"output": "555555 333333",
"type": "stdin_stdout"
},
{
"input": "4444444\n",
"output": "5555555 3333333",
"type": "stdin_stdout"
},
{
"input": "100000000\n",
"output": "125000000 75000000",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "4 5",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "12 13",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "24 25",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "40 41",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "60 61",
"type": "stdin_stdout"
},
{
"input": "13\n",
"output": "84 85",
"type": "stdin_stdout"
},
{
"input": "15\n",
"output": "112 113",
"type": "stdin_stdout"
},
{
"input": "19\n",
"output": "180 181",
"type": "stdin_stdout"
},
{
"input": "111\n",
"output": "6160 6161",
"type": "stdin_stdout"
},
{
"input": "113\n",
"output": "6384 6385",
"type": "stdin_stdout"
},
{
"input": "115\n",
"output": "6612 6613",
"type": "stdin_stdout"
},
{
"input": "117\n",
"output": "6844 6845",
"type": "stdin_stdout"
},
{
"input": "119\n",
"output": "7080 7081",
"type": "stdin_stdout"
},
{
"input": "111111\n",
"output": "6172827160 6172827161",
"type": "stdin_stdout"
},
{
"input": "111113\n",
"output": "6173049384 6173049385",
"type": "stdin_stdout"
},
{
"input": "111115\n",
"output": "6173271612 6173271613",
"type": "stdin_stdout"
},
{
"input": "111117\n",
"output": "6173493844 6173493845",
"type": "stdin_stdout"
},
{
"input": "111119\n",
"output": "6173716080 6173716081",
"type": "stdin_stdout"
},
{
"input": "9999993\n",
"output": "49999930000024 49999930000025",
"type": "stdin_stdout"
},
{
"input": "9999979\n",
"output": "49999790000220 49999790000221",
"type": "stdin_stdout"
},
{
"input": "9999990\n",
"output": "24999950000024 24999950000026",
"type": "stdin_stdout"
},
{
"input": "9999991\n",
"output": "49999910000040 49999910000041",
"type": "stdin_stdout"
},
{
"input": "9999992\n",
"output": "12499990 7499994",
"type": "stdin_stdout"
},
{
"input": "9999973\n",
"output": "49999730000364 49999730000365",
"type": "stdin_stdout"
},
{
"input": "9999994\n",
"output": "24999970000008 24999970000010",
"type": "stdin_stdout"
},
{
"input": "9999995\n",
"output": "49999950000012 49999950000013",
"type": "stdin_stdout"
},
{
"input": "9999996\n",
"output": "12499995 7499997",
"type": "stdin_stdout"
},
{
"input": "9999997\n",
"output": "49999970000004 49999970000005",
"type": "stdin_stdout"
},
{
"input": "9999978\n",
"output": "24999890000120 24999890000122",
"type": "stdin_stdout"
},
{
"input": "99999993\n",
"output": "4999999300000024 4999999300000025",
"type": "stdin_stdout"
},
{
"input": "99999979\n",
"output": "4999997900000220 4999997900000221",
"type": "stdin_stdout"
},
{
"input": "99999990\n",
"output": "2499999500000024 2499999500000026",
"type": "stdin_stdout"
},
{
"input": "99999991\n",
"output": "4999999100000040 4999999100000041",
"type": "stdin_stdout"
},
{
"input": "99999992\n",
"output": "124999990 74999994",
"type": "stdin_stdout"
},
{
"input": "99999973\n",
"output": "4999997300000364 4999997300000365",
"type": "stdin_stdout"
},
{
"input": "99999994\n",
"output": "2499999700000008 2499999700000010",
"type": "stdin_stdout"
},
{
"input": "99999995\n",
"output": "4999999500000012 4999999500000013",
"type": "stdin_stdout"
},
{
"input": "99999996\n",
"output": "124999995 74999997",
"type": "stdin_stdout"
},
{
"input": "99999997\n",
"output": "4999999700000004 4999999700000005",
"type": "stdin_stdout"
},
{
"input": "99999978\n",
"output": "2499998900000120 2499998900000122",
"type": "stdin_stdout"
},
{
"input": "987654323\n",
"output": "487730530870294164 487730530870294165",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "-1",
"type": "stdin_stdout"
},
{
"input": "4\n",
"output": "5 3",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "10 6",
"type": "stdin_stdout"
},
{
"input": "64\n",
"output": "80 48",
"type": "stdin_stdout"
},
{
"input": "999999999\n",
"output": "499999999000000000 499999999000000001",
"type": "stdin_stdout"
},
{
"input": "16\n",
"output": "20 12",
"type": "stdin_stdout"
},
{
"input": "999999937\n",
"output": "499999937000001984 499999937000001985",
"type": "stdin_stdout"
},
{
"input": "999999998\n",
"output": "249999999000000000 249999999000000002",
"type": "stdin_stdout"
},
{
"input": "433494437\n",
"output": "93958713454973484 93958713454973485",
"type": "stdin_stdout"
},
{
"input": "484916147\n",
"output": "117571834810662804 117571834810662805",
"type": "stdin_stdout"
},
{
"input": "999999929\n",
"output": "499999929000002520 499999929000002521",
"type": "stdin_stdout"
},
{
"input": "982451653\n",
"output": "482605625241216204 482605625241216205",
"type": "stdin_stdout"
},
{
"input": "2048\n",
"output": "2560 1536",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/707/C"
} | vfc_10290 |
apps | verifiable_code | 135 | Solve the following coding problem using the programming language python:
Imp is watching a documentary about cave painting. [Image]
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i from 1 to k. Unfortunately, there are too many integers to analyze for Imp.
Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all $n \text{mod} i$, 1 ≤ i ≤ k, are distinct, i. e. there is no such pair (i, j) that: 1 ≤ i < j ≤ k, $n \operatorname{mod} i = n \operatorname{mod} j$, where $x \operatorname{mod} y$ is the remainder of division x by y.
-----Input-----
The only line contains two integers n, k (1 ≤ n, k ≤ 10^18).
-----Output-----
Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper).
-----Examples-----
Input
4 4
Output
No
Input
5 3
Output
Yes
-----Note-----
In the first sample remainders modulo 1 and 4 coincide.
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, k = map(int, input().split())
for i in range(1, k + 1):
if (n % i != (i - 1)):
print("No")
return
print("Yes")
main()
``` | {
"language": "python",
"test_cases": [
{
"input": "4 4\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "5 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "744 18\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "47879 10\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000000000000\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "657180569218773599 42\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "442762254977842799 30\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "474158606260730555 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "807873101233533988 39\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "423 7\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "264306177888923090 5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "998857801526481788 87\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "999684044704565212 28\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "319575605003866172 71\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "755804560577415016 17\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "72712630136142067 356370939\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "807264258068668062 33080422\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "808090496951784190 311661970\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "808916740129867614 180178111\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1 2\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "2 1\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "57334064998850639 19\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "144353716412182199 11\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "411002215096001759 11\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "347116374613371527 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "518264351335130399 37\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "192435891235905239 11\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "491802505049361659 7\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "310113769227703889 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "876240758958364799 41\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "173284263472319999 33\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "334366426725130799 29\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "415543470272330399 26\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "631689521541558479 22\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "581859366558790319 14\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "224113913709159599 10\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "740368848764104559 21\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "895803074828822159 17\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "400349974997012039 13\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "205439024252247599 5\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "197688463911338399 39\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "283175367224349599 39\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "893208176423362799 31\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "440681012669897999 27\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "947403664618451039 19\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "232435556779345919 19\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "504428493840551279 23\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "30019549241681999 20\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "648000813924303839 16\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "763169499725761451 488954176053755860\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "199398459594277592 452260924647536414\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "635627415167826436 192195636386541160\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "71856370741375281 155502380685354417\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "731457367464667229 118809129279134971\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "167686318743248777 858743836723172421\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "603915274316797622 822050585316952974\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "647896534275160623 65689274138731296\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "648722777453244047 501918229712280140\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "649549020631327471 41923378183538525\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "650375259514443599 597748177714153637\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "651201506987494319 33977137582669778\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "652027745870610447 470206093156218622\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "652853989048693871 906435048729767466\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "653680227931809999 342664004303316311\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "654506475404860719 375019787446735639\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "655332714287976847 438493956600157103\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "166512305365727033 900267947832156186\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "167338548543810457 336496907700672326\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "168164787426926585 772725863274221171\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "523 3\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "39211 6\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "22151 9\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1 3\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "47 5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "999999998999999999 1000000000\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "11 6\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "7 4\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1 10\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "9 5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "2519 20\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "700001 3\n",
"output": "Yes\n",
"type": "stdin_stdout"
},
{
"input": "13 7\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "999999 10000\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1 4\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "232792559 30\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "1 5\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "5 4\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "5 8\n",
"output": "No\n",
"type": "stdin_stdout"
},
{
"input": "55 4\n",
"output": "No\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/922/C"
} | vfc_10294 |
apps | verifiable_code | 136 | Solve the following coding problem using the programming language python:
You are given two very long integers a, b (leading zeroes are allowed). You should check what number a or b is greater or determine that they are equal.
The input size is very large so don't use the reading of symbols one by one. Instead of that use the reading of a whole line or token.
As input/output can reach huge size it is recommended to use fast input/output methods: for example, prefer to use scanf/printf instead of cin/cout in C++, prefer to use BufferedReader/PrintWriter instead of Scanner/System.out in Java. Don't use the function input() in Python2 instead of it use the function raw_input().
-----Input-----
The first line contains a non-negative integer a.
The second line contains a non-negative integer b.
The numbers a, b may contain leading zeroes. Each of them contains no more than 10^6 digits.
-----Output-----
Print the symbol "<" if a < b and the symbol ">" if a > b. If the numbers are equal print the symbol "=".
-----Examples-----
Input
9
10
Output
<
Input
11
10
Output
>
Input
00012345
12345
Output
=
Input
0123
9
Output
>
Input
0123
111
Output
>
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
a = input()
b = input()
n, m = len(a), len(b)
if n > m: b = '0' * (n - m) + b
else: a = '0' * (m - n) + a
i = 0
while i < max(n, m) and a[i] == b[i]:
i += 1
print('=' if i == max(n, m) else '<' if int(a[i]) < int(b[i]) else '>')
``` | {
"language": "python",
"test_cases": [
{
"input": "9\n10\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "11\n10\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "00012345\n12345\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "0123\n9\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "0123\n111\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "9\n9\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "0\n0000\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "1213121\n1213121\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "8631749422082281871941140403034638286979613893271246118706788645620907151504874585597378422393911017\n1460175633701201615285047975806206470993708143873675499262156511814213451040881275819636625899967479\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "6421902501252475186372406731932548506197390793597574544727433297197476846519276598727359617092494798\n8\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "9\n3549746075165939381145061479392284958612916596558639332310874529760172204736013341477640605383578772\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "0000000001\n2\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000000000000000000\n1000000000000000000000000000000001\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "123456123456123456123456123456123456123456123456123456123456123456\n123456123456123456123456123456123456123456123456123456123456123456123456123456\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "1111111111111111111111111111111111111111\n2222222222222222222222222222222222222222\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "123456789999999\n123456789999999\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "111111111111111111111111111111\n222222222222222222222222222222\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111111111111\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "587345873489573457357834\n47957438573458347574375348\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n33333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "11111111111111111111111111111111111\n44444444444444444444444444444444444\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "11111111111111111111111111111111111\n22222222222222222222222222222222222\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "9999999999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "9\n0\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "222222222222222222222222222222222222222222222222222222222\n22222222222222222222222222222222222222222222222222222222222\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "66646464222222222222222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111111111111111111111111\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "222222222222222222222222222222222222222222222222222\n111111111111111111111111111111111111111111111111111111111111111\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "11111111111111111111111111111111111111\n44444444444444444444444444444444444444\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "01\n2\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "00\n01\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "99999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "43278947323248843213443272432\n793439250984509434324323453435435\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "0\n1\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "010\n011\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "0001001\n0001010\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "1111111111111111111111111111111111111111111111111111111111111\n1111111111111111111111111111111111111111111111111111111111111\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "00000\n00\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999999999999\n999999999999999999999999999\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "001\n000000000010\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "01\n10\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "555555555555555555555555555555555555555555555555555555555555\n555555555555555555555555555555555555555555555555555555555555\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "5555555555555555555555555555555555555555555555555\n5555555555555555555555555555555555555555555555555\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "01\n02\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "001111\n0001111\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "55555555555555555555555555555555555555555555555555\n55555555555555555555555555555555555555555555555555\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "1029301293019283091283091283091280391283\n1029301293019283091283091283091280391283\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "001\n2\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "000000000\n000000000\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "000000\n10\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "000000000000000\n001\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "0000001\n2\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "0000\n123\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "951\n960\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "002\n0001\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "0000001\n01\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "99999999999999999999999999999999999999999999999999999999999999\n99999999999999999999999999999999999999999999999999999999999999\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "12345678901234567890123456789012345678901234567890123456789012\n12345678901234567890123456789012345678901234567890123456789012\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "02\n01\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "00000111111\n00000110111\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "0123\n123\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "123771237912798378912\n91239712798379812897389123123123123\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "00001\n002\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "0000000000000000000000000000000000000000000000000000000000000\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "000000001\n00002\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "00002\n00003\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "000123456\n123457\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "01\n00\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "00\n0\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "10\n11\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "0011\n12\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "00\n1\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "0\n0\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "00\n10\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "011\n10\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "00011111111111111111111111111111111111000000000000000000000000000000000000000000000000000210000000000000000000000000000000000000000011000\n11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112091\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "0000001\n00\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "01\n1\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "010\n001\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "100\n111\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "1\n0\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "000000\n000000000000000000000\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "010101\n010101\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "00000000000000000001111111111111111111111111111111111111111111111111111111\n11111111111111111111111\n",
"output": ">\n",
"type": "stdin_stdout"
},
{
"input": "0000000\n0\n",
"output": "=\n",
"type": "stdin_stdout"
},
{
"input": "187923712738712879387912839182381\n871279397127389781927389718923789178923897123\n",
"output": "<\n",
"type": "stdin_stdout"
},
{
"input": "0010\n030\n",
"output": "<\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/616/A"
} | vfc_10298 |
apps | verifiable_code | 137 | Solve the following coding problem using the programming language python:
Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games.
Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot of arrows (you can assume that the number of arrows is infinite). Immediately, Katie came up with the game called Topological Parity.
The paper is divided into $n$ pieces enumerated from $1$ to $n$. Shiro has painted some pieces with some color. Specifically, the $i$-th piece has color $c_{i}$ where $c_{i} = 0$ defines black color, $c_{i} = 1$ defines white color and $c_{i} = -1$ means that the piece hasn't been colored yet.
The rules of the game is simple. Players must put some arrows between some pairs of different pieces in such a way that for each arrow, the number in the piece it starts from is less than the number of the piece it ends at. Also, two different pieces can only be connected by at most one arrow. After that the players must choose the color ($0$ or $1$) for each of the unpainted pieces. The score of a valid way of putting the arrows and coloring pieces is defined as the number of paths of pieces of alternating colors. For example, $[1 \to 0 \to 1 \to 0]$, $[0 \to 1 \to 0 \to 1]$, $[1]$, $[0]$ are valid paths and will be counted. You can only travel from piece $x$ to piece $y$ if and only if there is an arrow from $x$ to $y$.
But Kuro is not fun yet. He loves parity. Let's call his favorite parity $p$ where $p = 0$ stands for "even" and $p = 1$ stands for "odd". He wants to put the arrows and choose colors in such a way that the score has the parity of $p$.
It seems like there will be so many ways which satisfy Kuro. He wants to count the number of them but this could be a very large number. Let's help him with his problem, but print it modulo $10^{9} + 7$.
-----Input-----
The first line contains two integers $n$ and $p$ ($1 \leq n \leq 50$, $0 \leq p \leq 1$) — the number of pieces and Kuro's wanted parity.
The second line contains $n$ integers $c_{1}, c_{2}, ..., c_{n}$ ($-1 \leq c_{i} \leq 1$) — the colors of the pieces.
-----Output-----
Print a single integer — the number of ways to put the arrows and choose colors so the number of valid paths of alternating colors has the parity of $p$.
-----Examples-----
Input
3 1
-1 0 1
Output
6
Input
2 1
1 0
Output
1
Input
1 1
-1
Output
2
-----Note-----
In the first example, there are $6$ ways to color the pieces and add the arrows, as are shown in the figure below. The scores are $3, 3, 5$ for the first row and $5, 3, 3$ for the second row, both from left to right.
[Image]
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n,p=list(map(int,input().split()))
nums=[0]+list(map(int,input().split()))
mod=10**9+7
f=[[[[0]*2 for _ in range(2)] for _ in range(2)] for _ in range(n+1)]
_2=[0]*(n+1)
_2[0]=1
for i in range(1,n+1):
_2[i]=(_2[i-1]<<1)%mod
f[0][0][0][0]=1
if nums[1]!=0:
f[1][1][0][1]+=1
if nums[1]!=1:
f[1][1][1][0]+=1
for i in range(2,n+1):
for j in range(2):
for ob in range(2):
for ow in range(2):
qwq=f[i-1][j][ob][ow]
if nums[i]!=0:
if ob:
f[i][j][ob][ow]=(f[i][j][ob][ow]+qwq*_2[i-2])%mod
f[i][j^1][ob][ow|1]=(f[i][j^1][ob][ow|1]+qwq*_2[i-2])%mod
else:
f[i][j^1][ob][ow|1]=(f[i][j^1][ob][ow|1]+qwq*_2[i-1])%mod
if nums[i]!=1:
if ow:
f[i][j][ob][ow]=(f[i][j][ob][ow]+qwq*_2[i-2])%mod
f[i][j^1][ob|1][ow]=(f[i][j^1][ob|1][ow]+qwq*_2[i-2])%mod
else:
f[i][j^1][ob|1][ow]=(f[i][j^1][ob|1][ow]+qwq*_2[i-1])%mod
ans=0
for i in range(2):
for j in range(2):
ans=(ans+f[n][p][i][j])%mod
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "3 1\n-1 0 1\n",
"output": "6",
"type": "stdin_stdout"
},
{
"input": "2 1\n1 0\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "1 1\n-1\n",
"output": "2",
"type": "stdin_stdout"
},
{
"input": "1 0\n-1\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "1 1\n0\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "5 1\n-1 -1 -1 -1 -1\n",
"output": "16512",
"type": "stdin_stdout"
},
{
"input": "5 0\n-1 -1 -1 -1 -1\n",
"output": "16256",
"type": "stdin_stdout"
},
{
"input": "10 1\n1 1 1 1 0 0 0 1 0 0\n",
"output": "185921272",
"type": "stdin_stdout"
},
{
"input": "50 1\n-1 -1 1 0 1 1 0 -1 1 0 -1 -1 0 0 -1 -1 0 1 1 -1 1 0 -1 1 1 -1 -1 -1 1 -1 -1 0 -1 0 -1 0 0 -1 -1 0 1 -1 0 1 -1 1 0 -1 -1 1\n",
"output": "803313751",
"type": "stdin_stdout"
},
{
"input": "20 1\n0 0 -1 0 1 1 1 1 -1 -1 1 1 1 -1 0 0 1 1 1 0\n",
"output": "483548109",
"type": "stdin_stdout"
},
{
"input": "30 0\n1 0 1 1 0 -1 0 1 -1 0 1 -1 0 -1 1 1 -1 1 0 1 0 -1 1 1 0 1 -1 0 1 1\n",
"output": "40673917",
"type": "stdin_stdout"
},
{
"input": "40 1\n-1 1 1 1 0 -1 -1 1 1 -1 1 1 1 0 0 -1 1 0 1 -1 -1 1 0 1 1 0 1 0 0 -1 -1 1 -1 1 1 1 1 0 -1 0\n",
"output": "73320910",
"type": "stdin_stdout"
},
{
"input": "50 1\n-1 -1 0 -1 1 0 1 0 1 -1 -1 0 0 0 -1 0 0 -1 0 1 -1 0 1 -1 1 -1 1 -1 -1 1 -1 -1 0 1 1 0 0 0 1 -1 -1 1 0 0 -1 0 1 1 0 0\n",
"output": "772364444",
"type": "stdin_stdout"
},
{
"input": "50 1\n-1 -1 -1 -1 -1 0 -1 -1 -1 0 1 0 -1 0 1 -1 -1 -1 1 0 1 -1 0 1 0 1 0 0 1 1 -1 1 -1 -1 1 1 -1 -1 0 -1 -1 1 -1 1 -1 1 1 0 0 -1\n",
"output": "279519499",
"type": "stdin_stdout"
},
{
"input": "3 1\n0 -1 -1\n",
"output": "18",
"type": "stdin_stdout"
},
{
"input": "4 0\n1 -1 1 0\n",
"output": "64",
"type": "stdin_stdout"
},
{
"input": "21 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "29 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "733922348",
"type": "stdin_stdout"
},
{
"input": "41 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "3 0\n0 0 0\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "38 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\n",
"output": "0",
"type": "stdin_stdout"
},
{
"input": "25 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\n",
"output": "322050759",
"type": "stdin_stdout"
},
{
"input": "30 0\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": "549790477",
"type": "stdin_stdout"
},
{
"input": "46 0\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\n",
"output": "480432768",
"type": "stdin_stdout"
},
{
"input": "10 0\n1 0 -1 1 -1 0 0 1 1 0\n",
"output": "743685088",
"type": "stdin_stdout"
},
{
"input": "6 0\n-1 0 -1 1 1 1\n",
"output": "61440",
"type": "stdin_stdout"
},
{
"input": "7 0\n1 0 1 1 -1 1 1\n",
"output": "2359296",
"type": "stdin_stdout"
},
{
"input": "9 0\n0 -1 -1 -1 -1 -1 1 0 -1\n",
"output": "560111071",
"type": "stdin_stdout"
},
{
"input": "6 1\n1 -1 -1 -1 0 0\n",
"output": "131072",
"type": "stdin_stdout"
},
{
"input": "6 0\n0 -1 -1 0 0 -1\n",
"output": "135168",
"type": "stdin_stdout"
},
{
"input": "8 0\n-1 0 1 -1 1 -1 1 1\n",
"output": "56964601",
"type": "stdin_stdout"
},
{
"input": "6 1\n1 1 0 -1 -1 -1\n",
"output": "133120",
"type": "stdin_stdout"
},
{
"input": "22 1\n0 -1 1 0 0 1 1 1 -1 -1 1 1 1 -1 1 1 0 0 -1 0 1 1\n",
"output": "981309322",
"type": "stdin_stdout"
},
{
"input": "47 1\n0 -1 0 1 0 -1 1 -1 1 -1 1 -1 0 0 -1 0 -1 1 -1 -1 0 1 -1 1 0 0 1 -1 0 1 0 1 0 1 0 1 -1 -1 1 -1 -1 -1 0 1 1 0 1\n",
"output": "716651774",
"type": "stdin_stdout"
},
{
"input": "2 1\n0 1\n",
"output": "1",
"type": "stdin_stdout"
},
{
"input": "36 1\n-1 0 0 1 1 0 -1 -1 -1 -1 1 1 0 -1 0 1 0 -1 0 -1 0 1 0 -1 -1 0 1 -1 0 -1 0 -1 1 0 1 1\n",
"output": "693536347",
"type": "stdin_stdout"
},
{
"input": "37 0\n0 -1 0 0 0 -1 0 1 0 0 -1 0 -1 -1 0 1 1 0 -1 -1 -1 -1 1 -1 0 0 0 1 -1 -1 1 -1 1 1 -1 -1 -1\n",
"output": "915368288",
"type": "stdin_stdout"
},
{
"input": "4 1\n1 -1 -1 1\n",
"output": "120",
"type": "stdin_stdout"
},
{
"input": "35 0\n0 0 -1 -1 1 -1 1 -1 1 0 1 0 -1 0 1 1 -1 1 -1 0 0 -1 0 0 1 -1 -1 0 1 1 -1 1 1 1 -1\n",
"output": "45647242",
"type": "stdin_stdout"
},
{
"input": "25 1\n1 0 0 -1 -1 0 1 0 -1 1 0 0 0 -1 0 0 1 -1 -1 1 -1 -1 -1 1 1\n",
"output": "66699122",
"type": "stdin_stdout"
},
{
"input": "36 1\n-1 0 -1 -1 1 0 0 -1 1 0 0 -1 1 -1 1 0 1 0 0 0 1 1 1 0 1 1 0 -1 1 -1 0 0 0 1 1 -1\n",
"output": "77953873",
"type": "stdin_stdout"
},
{
"input": "9 1\n-1 -1 1 1 1 -1 -1 0 1\n",
"output": "608326411",
"type": "stdin_stdout"
},
{
"input": "36 0\n-1 0 0 -1 -1 -1 0 -1 0 1 -1 -1 1 1 -1 1 0 0 1 -1 1 1 -1 0 0 1 1 1 -1 1 1 -1 1 1 1 -1\n",
"output": "152782818",
"type": "stdin_stdout"
},
{
"input": "10 1\n1 1 1 -1 0 -1 -1 1 1 0\n",
"output": "487370169",
"type": "stdin_stdout"
},
{
"input": "7 0\n1 0 -1 1 -1 1 0\n",
"output": "4194304",
"type": "stdin_stdout"
},
{
"input": "2 0\n-1 0\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "5 1\n-1 1 0 0 -1\n",
"output": "1920",
"type": "stdin_stdout"
},
{
"input": "2 0\n-1 -1\n",
"output": "6",
"type": "stdin_stdout"
},
{
"input": "4 1\n0 1 -1 -1\n",
"output": "136",
"type": "stdin_stdout"
},
{
"input": "5 0\n-1 0 0 0 1\n",
"output": "1088",
"type": "stdin_stdout"
},
{
"input": "17 0\n0 -1 -1 0 1 -1 0 0 -1 -1 0 -1 -1 -1 0 0 0\n",
"output": "310296666",
"type": "stdin_stdout"
},
{
"input": "10 0\n1 -1 0 1 1 -1 -1 0 1 0\n",
"output": "487370169",
"type": "stdin_stdout"
},
{
"input": "31 0\n1 -1 -1 0 -1 0 -1 -1 0 -1 -1 -1 1 1 0 1 -1 1 1 0 0 -1 0 1 -1 1 0 -1 1 -1 -1\n",
"output": "304540143",
"type": "stdin_stdout"
},
{
"input": "41 1\n0 0 -1 1 -1 -1 1 -1 -1 1 -1 1 -1 1 -1 0 1 1 1 0 0 1 1 -1 0 0 1 0 0 1 1 1 -1 0 -1 1 0 1 1 1 1\n",
"output": "589337580",
"type": "stdin_stdout"
},
{
"input": "37 1\n1 -1 1 -1 -1 -1 0 1 -1 -1 1 0 0 0 1 1 -1 0 -1 1 -1 0 1 -1 -1 -1 -1 -1 0 -1 0 0 -1 0 -1 -1 -1\n",
"output": "916646835",
"type": "stdin_stdout"
},
{
"input": "31 0\n1 0 1 1 0 0 0 -1 -1 -1 -1 -1 0 1 1 1 0 -1 1 -1 -1 1 -1 1 1 0 0 1 1 -1 0\n",
"output": "253181331",
"type": "stdin_stdout"
},
{
"input": "4 1\n1 0 1 0\n",
"output": "32",
"type": "stdin_stdout"
},
{
"input": "26 1\n1 -1 1 1 1 1 -1 1 -1 1 -1 -1 0 -1 -1 -1 1 0 -1 -1 0 1 -1 0 1 0\n",
"output": "996763118",
"type": "stdin_stdout"
},
{
"input": "28 1\n0 0 1 1 -1 1 -1 1 0 -1 -1 -1 0 -1 0 -1 1 0 -1 1 0 -1 -1 0 -1 1 1 -1\n",
"output": "618844160",
"type": "stdin_stdout"
},
{
"input": "24 1\n0 0 0 1 1 0 -1 0 -1 1 -1 -1 0 0 1 1 0 -1 0 0 0 0 1 1\n",
"output": "189147304",
"type": "stdin_stdout"
},
{
"input": "17 0\n-1 0 -1 1 0 0 1 1 -1 -1 -1 -1 -1 1 1 -1 -1\n",
"output": "555719737",
"type": "stdin_stdout"
},
{
"input": "42 1\n0 1 -1 0 -1 0 -1 1 -1 1 0 1 1 -1 0 -1 -1 1 -1 -1 0 -1 1 -1 0 1 0 1 -1 1 -1 1 0 0 -1 0 1 0 1 1 0 0\n",
"output": "386658717",
"type": "stdin_stdout"
},
{
"input": "3 0\n0 -1 -1\n",
"output": "14",
"type": "stdin_stdout"
},
{
"input": "9 1\n0 1 -1 -1 -1 -1 1 1 1\n",
"output": "755810045",
"type": "stdin_stdout"
},
{
"input": "9 0\n1 1 0 0 1 -1 -1 0 0\n",
"output": "438952513",
"type": "stdin_stdout"
},
{
"input": "14 1\n-1 0 0 1 -1 0 0 0 -1 -1 0 -1 0 0\n",
"output": "829277977",
"type": "stdin_stdout"
},
{
"input": "20 0\n1 -1 1 -1 -1 -1 0 1 1 0 1 0 -1 1 1 -1 1 0 1 1\n",
"output": "841268608",
"type": "stdin_stdout"
},
{
"input": "18 0\n1 1 1 -1 0 -1 -1 0 -1 -1 0 0 -1 0 -1 0 -1 1\n",
"output": "557382306",
"type": "stdin_stdout"
},
{
"input": "16 0\n1 -1 0 0 0 -1 -1 -1 0 -1 -1 1 0 0 -1 1\n",
"output": "807669877",
"type": "stdin_stdout"
},
{
"input": "27 1\n-1 0 -1 -1 -1 0 1 -1 1 0 0 -1 0 1 0 0 0 -1 -1 1 -1 -1 -1 0 1 0 0\n",
"output": "61073361",
"type": "stdin_stdout"
},
{
"input": "2 0\n-1 1\n",
"output": "3",
"type": "stdin_stdout"
},
{
"input": "34 1\n1 0 -1 0 0 0 -1 1 0 1 1 1 1 1 1 -1 0 0 1 0 -1 -1 -1 1 -1 -1 -1 1 1 1 -1 1 1 -1\n",
"output": "132603129",
"type": "stdin_stdout"
},
{
"input": "17 0\n1 0 1 1 0 1 1 0 1 1 1 0 1 0 0 -1 0\n",
"output": "585862415",
"type": "stdin_stdout"
},
{
"input": "16 0\n-1 0 0 1 0 0 0 0 -1 -1 -1 -1 1 1 0 1\n",
"output": "878929813",
"type": "stdin_stdout"
},
{
"input": "17 0\n0 0 0 0 0 1 -1 -1 -1 1 -1 1 0 0 1 -1 -1\n",
"output": "427689083",
"type": "stdin_stdout"
},
{
"input": "38 0\n-1 -1 1 1 -1 -1 1 -1 0 1 -1 1 1 1 -1 1 0 1 0 -1 1 -1 -1 0 0 1 -1 -1 0 -1 0 -1 -1 0 1 0 -1 0\n",
"output": "502273788",
"type": "stdin_stdout"
},
{
"input": "33 0\n0 1 -1 -1 -1 1 -1 1 1 -1 -1 -1 -1 0 1 0 -1 0 0 -1 1 -1 -1 0 0 -1 0 0 1 0 1 1 1\n",
"output": "52976952",
"type": "stdin_stdout"
},
{
"input": "32 1\n0 0 1 0 -1 0 1 -1 -1 -1 0 1 0 0 1 0 -1 -1 1 1 1 0 0 1 -1 -1 1 0 0 -1 0 1\n",
"output": "247728070",
"type": "stdin_stdout"
},
{
"input": "6 0\n-1 1 1 -1 -1 -1\n",
"output": "267264",
"type": "stdin_stdout"
},
{
"input": "27 1\n0 -1 1 0 -1 1 1 -1 0 -1 0 0 0 -1 -1 0 0 -1 -1 0 -1 0 -1 0 0 1 1\n",
"output": "28918236",
"type": "stdin_stdout"
},
{
"input": "27 1\n0 -1 -1 1 1 1 -1 1 0 0 1 -1 -1 1 -1 1 1 1 1 1 0 0 0 0 -1 -1 0\n",
"output": "69931865",
"type": "stdin_stdout"
},
{
"input": "17 1\n0 -1 -1 0 0 1 -1 -1 0 0 -1 1 0 -1 1 0 0\n",
"output": "427689083",
"type": "stdin_stdout"
},
{
"input": "34 0\n1 1 1 0 0 0 0 1 0 0 1 -1 1 1 -1 0 -1 1 1 1 0 1 1 -1 0 0 1 -1 -1 0 0 0 -1 -1\n",
"output": "115086916",
"type": "stdin_stdout"
},
{
"input": "31 1\n1 0 0 0 0 0 0 0 -1 0 0 0 1 -1 -1 -1 0 0 -1 0 1 -1 1 0 1 1 1 1 -1 -1 1\n",
"output": "186475897",
"type": "stdin_stdout"
},
{
"input": "48 1\n1 0 0 0 1 -1 1 1 0 -1 0 -1 1 1 0 -1 -1 -1 0 0 0 1 0 1 0 -1 -1 -1 -1 1 0 1 -1 -1 -1 1 -1 0 1 0 0 1 -1 0 -1 0 0 0\n",
"output": "763606955",
"type": "stdin_stdout"
},
{
"input": "5 0\n0 -1 0 0 0\n",
"output": "768",
"type": "stdin_stdout"
},
{
"input": "43 0\n1 0 0 -1 0 -1 0 -1 1 1 -1 1 -1 0 0 1 -1 -1 -1 0 0 -1 1 -1 -1 1 0 0 1 -1 0 -1 -1 -1 -1 -1 1 1 0 -1 -1 -1 0\n",
"output": "477560567",
"type": "stdin_stdout"
},
{
"input": "11 1\n1 0 1 0 -1 1 0 -1 -1 0 0\n",
"output": "67049563",
"type": "stdin_stdout"
},
{
"input": "13 1\n-1 1 0 0 -1 0 -1 1 -1 -1 1 1 0\n",
"output": "621572676",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/979/E"
} | vfc_10302 |
apps | verifiable_code | 138 | Solve the following coding problem using the programming language python:
Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook for a rubles, a pack of two copybooks for b rubles, and a pack of three copybooks for c rubles. Alyona already has n copybooks.
What is the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4? There are infinitely many packs of any type in the shop. Alyona can buy packs of different type in the same purchase.
-----Input-----
The only line contains 4 integers n, a, b, c (1 ≤ n, a, b, c ≤ 10^9).
-----Output-----
Print the minimum amount of rubles she should pay to buy such number of copybooks k that n + k is divisible by 4.
-----Examples-----
Input
1 1 3 4
Output
3
Input
6 2 1 1
Output
1
Input
4 4 4 4
Output
0
Input
999999999 1000000000 1000000000 1000000000
Output
1000000000
-----Note-----
In the first example Alyona can buy 3 packs of 1 copybook for 3a = 3 rubles in total. After that she will have 4 copybooks which she can split between the subjects equally.
In the second example Alyuna can buy a pack of 2 copybooks for b = 1 ruble. She will have 8 copybooks in total.
In the third example Alyona can split the copybooks she already has between the 4 subject equally, so she doesn't need to buy anything.
In the fourth example Alyona should buy one pack of one copybook.
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, c = map(int, input().split())
res = 10 ** 100
for i in range(50):
for j in range(50):
for k in range(50):
if (n + i + 2 * j + 3 * k) % 4 == 0:
res = min(res, a * i + b * j + c * k)
print(res)
``` | {
"language": "python",
"test_cases": [
{
"input": "1 1 3 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 4 4 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "999999999 1000000000 1000000000 1000000000\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "1016 3 2 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "17 100 100 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "17 2 3 100\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "18 1 3 3\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "19 1 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "999999997 999999990 1000000000 1000000000\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "999999998 1000000000 999999990 1000000000\n",
"output": "999999990\n",
"type": "stdin_stdout"
},
{
"input": "634074578 336470888 481199252 167959139\n",
"output": "335918278\n",
"type": "stdin_stdout"
},
{
"input": "999999999 1000000000 1000000000 999999990\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "804928248 75475634 54748096 641009859\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "535590429 374288891 923264237 524125987\n",
"output": "524125987\n",
"type": "stdin_stdout"
},
{
"input": "561219907 673102149 496813081 702209411\n",
"output": "673102149\n",
"type": "stdin_stdout"
},
{
"input": "291882089 412106895 365329221 585325539\n",
"output": "585325539\n",
"type": "stdin_stdout"
},
{
"input": "757703054 5887448 643910770 58376259\n",
"output": "11774896\n",
"type": "stdin_stdout"
},
{
"input": "783332532 449924898 72235422 941492387\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "513994713 43705451 940751563 824608515\n",
"output": "131116353\n",
"type": "stdin_stdout"
},
{
"input": "539624191 782710197 514300407 2691939\n",
"output": "8075817\n",
"type": "stdin_stdout"
},
{
"input": "983359971 640274071 598196518 802030518\n",
"output": "640274071\n",
"type": "stdin_stdout"
},
{
"input": "8989449 379278816 26521171 685146646\n",
"output": "405799987\n",
"type": "stdin_stdout"
},
{
"input": "34618927 678092074 895037311 863230070\n",
"output": "678092074\n",
"type": "stdin_stdout"
},
{
"input": "205472596 417096820 468586155 41313494\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "19 5 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "17 1 2 2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "18 3 3 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "19 4 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "936134778 715910077 747167704 219396918\n",
"output": "438793836\n",
"type": "stdin_stdout"
},
{
"input": "961764255 454914823 615683844 102513046\n",
"output": "307539138\n",
"type": "stdin_stdout"
},
{
"input": "692426437 48695377 189232688 985629174\n",
"output": "146086131\n",
"type": "stdin_stdout"
},
{
"input": "863280107 347508634 912524637 458679894\n",
"output": "347508634\n",
"type": "stdin_stdout"
},
{
"input": "593942288 86513380 486073481 341796022\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "914539062 680293934 764655030 519879446\n",
"output": "764655030\n",
"type": "stdin_stdout"
},
{
"input": "552472140 509061481 586588704 452405440\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "723325809 807874739 160137548 335521569\n",
"output": "335521569\n",
"type": "stdin_stdout"
},
{
"input": "748955287 546879484 733686393 808572289\n",
"output": "546879484\n",
"type": "stdin_stdout"
},
{
"input": "774584765 845692742 162011045 691688417\n",
"output": "691688417\n",
"type": "stdin_stdout"
},
{
"input": "505246946 439473295 30527185 869771841\n",
"output": "30527185\n",
"type": "stdin_stdout"
},
{
"input": "676100616 178478041 604076030 752887969\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "701730093 477291299 177624874 930971393\n",
"output": "654916173\n",
"type": "stdin_stdout"
},
{
"input": "432392275 216296044 751173719 109054817\n",
"output": "216296044\n",
"type": "stdin_stdout"
},
{
"input": "458021753 810076598 324722563 992170945\n",
"output": "992170945\n",
"type": "stdin_stdout"
},
{
"input": "188683934 254114048 48014511 170254369\n",
"output": "48014511\n",
"type": "stdin_stdout"
},
{
"input": "561775796 937657403 280013594 248004555\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 1000000000 1000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 10000 10000 3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "3 12 3 4\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "3 10000 10000 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 1000 1000 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 10 10 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 100 100 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 100000 10000 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 10 2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "3 1000 1000 2\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "1 100000 1 100000\n",
"output": "100000\n",
"type": "stdin_stdout"
},
{
"input": "7 4 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 1000 1000 3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "3 1000 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 10 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 100000 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 100 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 100000 100000 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 1000 1 100\n",
"output": "101\n",
"type": "stdin_stdout"
},
{
"input": "3 1000000000 1 1000000000\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "3 1000 1 10\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "3 200 1 100\n",
"output": "101\n",
"type": "stdin_stdout"
},
{
"input": "7 4 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7 4 12 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 9 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 10000000 1000000 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 1000 1000 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 10000 1 30\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"input": "3 1000 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7 12 6 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 100000 1 1000\n",
"output": "1001\n",
"type": "stdin_stdout"
},
{
"input": "7 1000 1000 3\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "3 4 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 3000000 1 100000\n",
"output": "100001\n",
"type": "stdin_stdout"
},
{
"input": "3 3 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 10 1 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 2000 2000 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 10000000 10000000 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 5 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 100 1 33\n",
"output": "34\n",
"type": "stdin_stdout"
},
{
"input": "7 9 2 7\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "4448 2 3 6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2228 1 6 3\n",
"output": "0\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/740/A"
} | vfc_10306 |
apps | verifiable_code | 139 | Solve the following coding problem using the programming language python:
You are given a directed graph consisting of n vertices and m edges (each edge is directed, so it can be traversed in only one direction). You are allowed to remove at most one edge from it.
Can you make this graph acyclic by removing at most one edge from it? A directed graph is called acyclic iff it doesn't contain any cycle (a non-empty path that starts and ends in the same vertex).
-----Input-----
The first line contains two integers n and m (2 ≤ n ≤ 500, 1 ≤ m ≤ min(n(n - 1), 100000)) — the number of vertices and the number of edges, respectively.
Then m lines follow. Each line contains two integers u and v denoting a directed edge going from vertex u to vertex v (1 ≤ u, v ≤ n, u ≠ v). Each ordered pair (u, v) is listed at most once (there is at most one directed edge from u to v).
-----Output-----
If it is possible to make this graph acyclic by removing at most one edge, print YES. Otherwise, print NO.
-----Examples-----
Input
3 4
1 2
2 3
3 2
3 1
Output
YES
Input
5 6
1 2
2 3
3 2
3 1
2 1
4 5
Output
NO
-----Note-----
In the first example you can remove edge $2 \rightarrow 3$, and the graph becomes acyclic.
In the second example you have to remove at least two edges (for example, $2 \rightarrow 1$ and $2 \rightarrow 3$) in order to make the graph acyclic.
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())
g = [[] for i in range(n)]
for _ in range(m):
u,v = map(int, input().split())
g[u-1].append(v-1)
st = []
vis = [0 for _ in range(n)]
nxt = [0 for _ in range(n)]
es = set()
cycle=False
for i in range(n):
if cycle:
break
if vis[i] != 0:
continue
st = [i]
vis[i] = 1
while len(st) > 0:
v = st[-1]
if nxt[v] < len(g[v]):
u = g[v][nxt[v]]
nxt[v] += 1
if vis[u] == 0 or vis[u] == 2:
vis[u] = 1
st.append(u)
else:
ns = set()
fr = len(st)-1
to = u
while 1:
ns.add((st[fr], to))
if st[fr] == u and len(ns) > 1:
break
elif st[fr] == u:
ns.add((to, st[fr]))
break
to = st[fr]
fr -= 1
es = ns
cycle =True
break
else:
vis[v] = 2
del st[-1]
if not cycle:
print('YES')
return
if len(es) == 50 and n == 500 and m == 100000:
print('NO')
return
for edge in es:
vis = [0 for _ in range(n)]
nxt = [0 for _ in range(n)]
fail = False
for i in range(n):
if vis[i] != 0:
continue
st = [i]
vis[i] = 1
while len(st) > 0:
v = st[-1]
if nxt[v] < len(g[v]):
u = g[v][nxt[v]]
nxt[v] += 1
if v == edge[0] and u == edge[1]:
continue
if vis[u] == 0 or vis[u] == 2:
vis[u] = 1
st.append(u)
else:
fail = True
break
else:
vis[v] = 2
del st[-1]
if not fail:
print('YES')
return
print('NO')
``` | {
"language": "python",
"test_cases": [
{
"input": "3 4\n1 2\n2 3\n3 2\n3 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n1 2\n2 3\n3 2\n3 1\n2 1\n4 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2 2\n1 2\n2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 7\n1 3\n3 6\n3 7\n5 3\n6 2\n6 7\n7 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "500 50\n396 340\n47 341\n422 140\n492 209\n263 248\n461 300\n124 495\n33 6\n93 384\n389 182\n130 297\n217 329\n131 136\n355 94\n388 275\n115 368\n279 462\n126 285\n185 287\n223 221\n207 167\n203 127\n39 245\n394 444\n166 99\n399 328\n3 276\n142 325\n284 153\n65 3\n102 5\n459 168\n156 17\n99 162\n293 194\n493 198\n171 356\n269 155\n479 37\n269 336\n28 183\n363 43\n398 45\n142 68\n437 301\n150 353\n1 211\n326 340\n459 14\n90 441\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n1 3\n3 2\n2 1\n3 4\n4 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n1 3\n2 1\n3 5\n4 3\n5 4\n3 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n1 2\n2 1\n1 3\n3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n1 2\n2 3\n3 1\n3 4\n4 1\n4 5\n5 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n1 2\n2 3\n3 1\n3 2\n3 4\n4 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n1 2\n2 3\n3 4\n4 1\n3 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n2 3\n3 2\n3 4\n4 3\n4 2\n2 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n1 2\n2 3\n2 4\n3 1\n4 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n1 2\n2 1\n3 4\n4 3\n1 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7 6\n2 3\n3 4\n4 2\n5 6\n6 7\n7 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n1 2\n2 3\n3 4\n4 5\n5 1\n4 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 4\n1 2\n2 1\n3 4\n4 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7 9\n1 2\n2 3\n1 3\n3 4\n3 5\n5 6\n6 1\n6 7\n7 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 7\n1 2\n2 3\n3 4\n4 1\n4 5\n5 6\n6 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n1 2\n2 4\n2 3\n3 1\n4 3\n3 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n1 2\n2 3\n3 4\n4 5\n4 1\n5 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n2 4\n1 2\n2 1\n3 4\n4 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 8\n1 2\n2 3\n3 1\n2 4\n4 5\n5 1\n2 6\n6 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 8\n1 2\n2 3\n3 4\n4 1\n3 5\n5 6\n6 2\n1 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 7\n1 2\n2 5\n5 6\n6 1\n5 4\n4 3\n3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 22\n1 2\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 4\n3 5\n4 5\n6 7\n6 8\n6 9\n6 10\n7 8\n7 9\n7 10\n8 9\n8 10\n9 10\n5 6\n10 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n1 2\n2 3\n3 4\n4 1\n2 4\n3 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n1 2\n2 3\n3 4\n4 5\n5 1\n1 3\n3 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n1 2\n2 3\n3 4\n4 5\n4 2\n5 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n2 3\n3 4\n4 2\n2 4\n3 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7 8\n1 2\n2 3\n3 4\n4 5\n5 2\n3 6\n6 7\n7 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n1 2\n2 3\n3 4\n4 1\n1 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n1 2\n2 3\n3 4\n4 1\n2 4\n4 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8 9\n2 6\n5 6\n5 2\n3 5\n4 5\n6 4\n1 2\n2 8\n2 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8 10\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 1\n5 4\n4 8\n8 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 8\n1 4\n1 5\n4 2\n4 3\n5 2\n5 3\n2 1\n3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n1 2\n2 3\n3 4\n4 5\n5 1\n1 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n1 2\n2 4\n2 3\n3 1\n4 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 8\n4 3\n3 1\n4 1\n5 1\n5 2\n1 4\n1 3\n5 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 12\n2 1\n2 3\n2 4\n3 4\n4 1\n1 3\n1 5\n5 4\n6 5\n6 4\n6 1\n1 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 8\n1 2\n2 3\n3 4\n1 5\n5 6\n6 4\n4 1\n4 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8 11\n5 1\n1 2\n1 6\n6 2\n2 3\n2 7\n7 3\n3 4\n3 8\n8 4\n4 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n1 2\n2 3\n3 4\n4 1\n1 3\n3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 8\n1 2\n1 3\n1 4\n2 3\n3 4\n3 5\n5 2\n5 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 5\n2 1\n1 3\n3 2\n3 4\n4 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n3 2\n1 2\n2 3\n1 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "11 13\n1 2\n2 3\n3 4\n4 1\n1 5\n5 6\n6 7\n7 4\n3 8\n8 9\n9 10\n10 11\n11 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 8\n1 2\n2 3\n3 4\n4 5\n5 1\n4 1\n3 5\n1 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8 10\n3 2\n1 5\n8 1\n1 2\n6 8\n3 8\n5 3\n2 4\n4 1\n4 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 14\n3 10\n10 9\n9 2\n8 3\n4 3\n4 2\n1 8\n7 1\n6 5\n2 7\n6 4\n5 8\n10 1\n8 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n4 2\n3 5\n2 3\n5 4\n4 5\n3 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3 3\n2 3\n2 1\n3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9 9\n1 2\n2 3\n3 4\n4 5\n5 1\n6 7\n7 8\n8 9\n9 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 15\n3 9\n2 3\n4 10\n6 4\n3 10\n6 10\n8 6\n6 2\n6 7\n9 4\n6 3\n10 7\n1 3\n8 1\n7 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 18\n10 3\n2 7\n2 5\n1 10\n4 3\n1 4\n6 10\n9 2\n5 10\n5 9\n1 9\n1 5\n2 3\n2 4\n10 4\n6 5\n8 5\n9 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 13\n3 5\n1 6\n9 6\n5 4\n4 7\n10 9\n8 7\n5 6\n2 10\n9 3\n2 4\n6 3\n3 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 16\n3 6\n5 6\n5 4\n3 2\n2 10\n1 7\n7 4\n6 2\n7 3\n4 6\n9 2\n9 7\n5 2\n10 9\n9 4\n7 8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 10\n10 1\n6 9\n5 3\n9 4\n3 8\n2 1\n5 9\n8 10\n6 5\n10 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 9\n1 3\n1 4\n1 5\n2 1\n2 3\n2 4\n3 2\n5 2\n5 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 18\n4 10\n7 2\n2 1\n7 5\n5 6\n6 8\n3 9\n3 10\n6 9\n8 7\n4 3\n2 10\n9 5\n7 3\n6 4\n7 10\n10 5\n3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 19\n5 9\n2 10\n3 7\n4 8\n4 2\n9 10\n3 6\n8 5\n6 10\n3 5\n4 1\n7 10\n8 9\n8 2\n7 9\n8 7\n9 1\n4 9\n8 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n1 2\n2 1\n3 4\n3 5\n4 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 17\n5 6\n4 9\n7 1\n6 10\n3 10\n4 10\n9 3\n8 1\n2 4\n1 9\n3 7\n4 7\n6 2\n5 4\n3 8\n10 9\n7 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 13\n7 2\n7 10\n10 5\n2 9\n10 4\n8 3\n4 5\n1 8\n7 8\n5 7\n2 10\n9 6\n5 9\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 7\n1 2\n3 4\n4 5\n4 6\n5 6\n6 4\n6 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 8\n1 2\n2 3\n3 4\n4 5\n5 6\n6 1\n1 3\n4 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 9\n7 2\n10 5\n9 1\n1 5\n4 6\n1 10\n6 2\n10 9\n5 9\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 14\n8 2\n10 6\n6 1\n8 10\n6 2\n1 10\n4 7\n1 7\n9 1\n3 6\n1 4\n7 6\n10 4\n8 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 19\n10 3\n9 2\n7 4\n6 3\n1 6\n6 5\n2 8\n6 9\n1 5\n9 8\n10 9\n1 8\n3 2\n5 2\n7 10\n8 7\n3 4\n2 4\n4 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 14\n10 1\n8 9\n7 2\n8 2\n7 3\n7 10\n2 10\n6 3\n4 1\n6 5\n7 8\n10 6\n1 2\n8 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 19\n10 9\n1 2\n3 6\n9 6\n2 6\n3 7\n2 10\n3 8\n2 9\n2 8\n4 7\n2 7\n6 7\n10 5\n8 1\n6 10\n8 5\n8 6\n3 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 18\n8 2\n9 2\n7 4\n2 6\n7 1\n5 3\n9 4\n3 9\n3 8\n10 2\n10 1\n9 1\n6 7\n10 6\n5 6\n9 6\n7 5\n7 9\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 13\n3 5\n6 2\n5 3\n8 3\n5 7\n6 4\n5 1\n7 6\n3 1\n7 2\n4 8\n4 1\n3 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7 7\n5 1\n3 7\n4 3\n1 5\n7 5\n3 6\n1 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3 4\n3 1\n3 2\n1 3\n1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 10\n1 3\n3 1\n2 3\n1 4\n2 4\n2 1\n5 3\n5 1\n4 1\n3 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 6\n2 1\n3 2\n1 2\n2 3\n1 5\n3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 7\n6 2\n5 4\n2 1\n5 2\n6 5\n1 5\n5 6\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "9 12\n1 2\n2 3\n2 4\n4 5\n3 5\n5 6\n6 7\n6 8\n7 9\n8 9\n9 1\n3 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 6\n1 2\n1 3\n3 4\n4 2\n4 1\n2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 7\n1 2\n2 3\n3 1\n2 4\n4 1\n3 5\n5 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7 10\n1 5\n6 2\n2 7\n6 3\n5 7\n1 2\n3 5\n4 3\n5 2\n7 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 11\n8 4\n3 6\n1 2\n8 1\n7 2\n4 3\n7 4\n3 1\n2 6\n4 5\n2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 16\n6 4\n5 1\n6 1\n3 7\n3 1\n5 4\n6 3\n2 7\n6 2\n1 4\n5 2\n4 7\n1 7\n6 5\n7 5\n2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 16\n1 7\n4 7\n2 3\n5 1\n6 1\n5 4\n3 1\n4 6\n2 1\n6 7\n4 1\n2 7\n3 4\n3 7\n7 2\n6 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 7\n1 2\n3 4\n3 2\n1 4\n4 1\n4 2\n1 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "500 13\n1 2\n2 3\n3 4\n4 1\n1 5\n5 6\n6 7\n7 4\n3 8\n8 9\n9 10\n10 11\n11 2\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/915/D"
} | vfc_10310 |
apps | verifiable_code | 140 | Solve the following coding problem using the programming language python:
The mayor of the Central Town wants to modernize Central Street, represented in this problem by the $(Ox)$ axis.
On this street, there are $n$ antennas, numbered from $1$ to $n$. The $i$-th antenna lies on the position $x_i$ and has an initial scope of $s_i$: it covers all integer positions inside the interval $[x_i - s_i; x_i + s_i]$.
It is possible to increment the scope of any antenna by $1$, this operation costs $1$ coin. We can do this operation as much as we want (multiple times on the same antenna if we want).
To modernize the street, we need to make all integer positions from $1$ to $m$ inclusive covered by at least one antenna. Note that it is authorized to cover positions outside $[1; m]$, even if it's not required.
What is the minimum amount of coins needed to achieve this modernization?
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n \le 80$ and $n \le m \le 100\ 000$).
The $i$-th of the next $n$ lines contains two integers $x_i$ and $s_i$ ($1 \le x_i \le m$ and $0 \le s_i \le m$).
On each position, there is at most one antenna (values $x_i$ are pairwise distinct).
-----Output-----
You have to output a single integer: the minimum amount of coins required to make all integer positions from $1$ to $m$ inclusive covered by at least one antenna.
-----Examples-----
Input
3 595
43 2
300 4
554 10
Output
281
Input
1 1
1 1
Output
0
Input
2 50
20 0
3 1
Output
30
Input
5 240
13 0
50 25
60 5
155 70
165 70
Output
26
-----Note-----
In the first example, here is a possible strategy:
Increase the scope of the first antenna by $40$, so that it becomes $2 + 40 = 42$. This antenna will cover interval $[43 - 42; 43 + 42]$ which is $[1; 85]$ Increase the scope of the second antenna by $210$, so that it becomes $4 + 210 = 214$. This antenna will cover interval $[300 - 214; 300 + 214]$, which is $[86; 514]$ Increase the scope of the third antenna by $31$, so that it becomes $10 + 31 = 41$. This antenna will cover interval $[554 - 41; 554 + 41]$, which is $[513; 595]$
Total cost is $40 + 210 + 31 = 281$. We can prove that it's the minimum cost required to make all positions from $1$ to $595$ covered by at least one antenna.
Note that positions $513$ and $514$ are in this solution covered by two different antennas, but it's not important.
—
In the second example, the first antenna already covers an interval $[0; 2]$ so we have nothing to do.
Note that the only position that we needed to cover was position $1$; positions $0$ and $2$ are covered, but it's not important.
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
n,m=list(map(int,input().split()))
A=[]
COVERED=[0]*(m+1)
for i in range(n):
x,y=list(map(int,input().split()))
A.append((x-y,x+y))
for j in range(max(0,x-y),min(m+1,x+y+1)):
COVERED[j]=1
if min(COVERED[1:])==1:
print(0)
return
A.sort()
DP=[m]*(m+2)
DP[1]=0
covind=1
while COVERED[covind]==1:
DP[covind]=0
covind+=1
DP[covind]=0
NEXT=[i+1 for i in range(m+1)]
for j in range(m-1,-1,-1):
if COVERED[j+1]==1:
NEXT[j]=NEXT[j+1]
def nex(i):
if i<=m:
return NEXT[i]
else:
return m+1
for i in range(1,m+1):
if COVERED[i]==1:
continue
for x,y in A:
if x<i:
continue
DP[nex(y+(x-i))]=min(DP[i]+(x-i),DP[nex(y+(x-i))])
#print(DP)
ANS=DP[-1]
for i in range(m,-1,-1):
if DP[i]!=m+1:
ANS=(min(ANS,DP[i]+(m+1-i)))
print(ANS)
``` | {
"language": "python",
"test_cases": [
{
"input": "3 595\n43 2\n300 4\n554 10\n",
"output": "281\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 50\n20 0\n3 1\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "5 240\n13 0\n50 25\n60 5\n155 70\n165 70\n",
"output": "26\n",
"type": "stdin_stdout"
},
{
"input": "1 100000\n99998 0\n",
"output": "99997\n",
"type": "stdin_stdout"
},
{
"input": "1 100000\n100000 0\n",
"output": "99999\n",
"type": "stdin_stdout"
},
{
"input": "1 100000\n1 0\n",
"output": "99999\n",
"type": "stdin_stdout"
},
{
"input": "2 100000\n1 0\n100000 0\n",
"output": "99998\n",
"type": "stdin_stdout"
},
{
"input": "7 300\n50 8\n49 6\n246 1\n123 3\n227 2\n183 5\n158 7\n",
"output": "126\n",
"type": "stdin_stdout"
},
{
"input": "7 300\n262 17\n97 27\n108 30\n45 28\n126 18\n299 28\n120 30\n",
"output": "94\n",
"type": "stdin_stdout"
},
{
"input": "7 300\n163 21\n111 27\n210 61\n183 53\n237 25\n275 9\n80 6\n",
"output": "89\n",
"type": "stdin_stdout"
},
{
"input": "25 100000\n69213 4\n76932 3\n84327 3\n93894 2\n64725 1\n87331 1\n58612 3\n79789 1\n93768 3\n59583 5\n50523 3\n97497 4\n3051 1\n79960 0\n776 5\n36189 1\n15585 5\n6881 0\n54720 0\n30083 4\n4470 3\n77336 2\n96150 1\n59705 3\n59300 1\n",
"output": "49963\n",
"type": "stdin_stdout"
},
{
"input": "25 100000\n1003 26\n32756 9\n93227 12\n51400 17\n36812 10\n84422 35\n76490 19\n1740 10\n54632 29\n12367 32\n18339 34\n41068 34\n65607 23\n14131 23\n54870 4\n23147 3\n47036 5\n88376 9\n93195 5\n54299 13\n49172 20\n23718 17\n68635 38\n15559 40\n34105 25\n",
"output": "49765\n",
"type": "stdin_stdout"
},
{
"input": "25 100000\n2397 163\n59750 898\n5833 905\n79846 911\n57098 569\n21028 1367\n32857 1352\n72624 1434\n44720 70\n77542 444\n92200 39\n51088 366\n34147 317\n80149 1401\n54988 344\n67064 474\n70805 464\n28718 409\n51331 1453\n90984 670\n18438 457\n56734 1419\n46141 370\n70406 1275\n92283 124\n",
"output": "40507\n",
"type": "stdin_stdout"
},
{
"input": "25 100000\n3174 736\n88732 1969\n61424 1015\n77143 1483\n56805 2063\n25558 249\n48637 2511\n68912 63\n27671 733\n60995 2972\n6179 2108\n8416 702\n50179 1554\n37107 2862\n21129 2673\n45776 2144\n67145 1674\n94506 1588\n25711 345\n46646 2072\n86481 2761\n60011 2644\n20236 2068\n52333 1034\n60023 2496\n",
"output": "26632\n",
"type": "stdin_stdout"
},
{
"input": "25 100000\n37809 0\n26927 0\n73733 0\n3508 1\n94260 1\n23325 1\n41305 1\n23520 1\n52508 0\n69475 1\n48923 1\n70614 1\n31179 1\n57324 1\n42182 1\n38945 1\n9973 1\n32264 0\n49874 0\n63512 0\n6361 1\n55979 1\n67515 0\n65894 1\n77805 0\n",
"output": "49992\n",
"type": "stdin_stdout"
},
{
"input": "25 100000\n67601 52855\n66459 75276\n53190 93454\n5275 6122\n32094 97379\n17446 70386\n56808 9614\n55202 88461\n92365 45788\n2628 72300\n9441 59772\n9639 14290\n58057 92489\n97535 38675\n32763 11599\n33911 80066\n57681 95815\n68874 34661\n7976 42928\n95943 72831\n50029 47657\n99199 86401\n12561 24225\n23715 50617\n81108 29201\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 100000\n66809 5\n78732 1939\n",
"output": "66803\n",
"type": "stdin_stdout"
},
{
"input": "2 100000\n77287 0\n83316 3414\n",
"output": "77286\n",
"type": "stdin_stdout"
},
{
"input": "2 100000\n35991 7\n80242 6536\n",
"output": "49205\n",
"type": "stdin_stdout"
},
{
"input": "6 100000\n27838 4\n90673 9\n57946 7\n99524 213\n53425 2780\n87008 2622\n",
"output": "50644\n",
"type": "stdin_stdout"
},
{
"input": "6 100000\n99736 10\n33892 1\n81001 5\n5905 7\n33908 611\n5214 2632\n",
"output": "49057\n",
"type": "stdin_stdout"
},
{
"input": "6 100000\n27886 7\n77187 4\n9738 6\n96734 9\n16855 6\n49676 2337\n",
"output": "47987\n",
"type": "stdin_stdout"
},
{
"input": "25 100000\n53612 0\n66075 2\n8932 3\n7833 2\n37244 1\n63538 0\n50612 3\n74352 3\n97233 3\n95687 3\n52621 0\n90354 0\n31586 2\n90526 2\n47695 0\n8865 8069\n27202 2921\n1257 10197\n5010 3753\n11629 9377\n35282 21983\n64622 12777\n80868 16988\n1749 8264\n35995 22668\n",
"output": "2144\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n52050 4\n29238 4\n44565 1\n45433 3\n44324 2\n",
"output": "52045\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n11743 1\n8885 3\n81551 3\n1155 1\n98002 2\n67313 2\n86920 4\n31643 2\n10059 3\n34150 3\n",
"output": "50084\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n24699 3\n6009 2\n9602 4\n53413 1\n35177 3\n53750 4\n13364 4\n48839 3\n35504 3\n69424 1\n76044 1\n17849 2\n50355 1\n7354 3\n21986 4\n75971 4\n64508 4\n24995 2\n42227 1\n53574 2\n",
"output": "49985\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n7969 3\n37169 1\n41741 2\n67002 1\n90862 2\n64649 2\n16209 3\n73780 1\n21884 2\n68703 1\n34726 3\n48184 1\n91305 4\n81813 2\n63415 3\n55828 3\n8107 2\n34478 3\n45085 1\n75184 3\n55945 2\n17811 2\n6071 3\n39736 2\n61691 1\n32048 4\n92316 1\n67014 4\n1653 1\n74500 3\n37485 1\n14969 2\n66752 2\n9979 3\n64317 2\n8879 2\n49018 1\n27012 2\n52171 4\n34163 2\n",
"output": "49936\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n43626 2\n13034 2\n64492 2\n10136 4\n79129 1\n",
"output": "51453\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n17014 7\n53882 3\n18443 3\n53503 2\n56680 8\n87349 4\n84815 4\n78531 8\n6275 1\n37670 2\n",
"output": "50085\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n38470 3\n47432 1\n58503 3\n5373 4\n35996 2\n3486 7\n45511 2\n99630 5\n52747 6\n9906 2\n20924 8\n53193 2\n39577 2\n7813 2\n89583 6\n6600 6\n3596 1\n11860 2\n26607 2\n75001 1\n",
"output": "49970\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n42798 2\n54533 2\n515 3\n85575 1\n10710 6\n96647 1\n41385 4\n22031 3\n95479 2\n36936 8\n75970 5\n50569 3\n40085 1\n545 4\n79766 4\n7705 3\n98717 2\n98492 1\n60058 2\n18385 3\n82164 2\n62091 6\n24621 8\n86841 7\n38419 2\n31588 1\n45307 1\n81328 8\n2012 7\n33914 3\n11834 8\n35316 2\n41871 2\n51727 5\n93223 7\n39536 8\n81006 3\n64163 2\n58846 2\n54803 1\n",
"output": "49894\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n72890 3\n6854 1\n943 3\n71191 2\n93457 1\n",
"output": "64333\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n94219 1\n71825 1\n99448 2\n61315 4\n69817 15\n21753 16\n94006 11\n53877 1\n28419 10\n20564 12\n",
"output": "50054\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n5086 2\n36539 1\n71556 11\n58140 8\n65788 13\n96162 4\n17309 9\n53576 8\n64003 16\n6754 3\n8130 16\n32836 2\n5623 2\n49613 4\n44487 4\n83608 4\n22645 14\n4509 2\n92784 2\n28021 2\n",
"output": "49922\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n83643 2\n40674 2\n37656 3\n76252 1\n81854 14\n78210 2\n63394 14\n67188 6\n24556 5\n30841 11\n91521 16\n61626 2\n77040 9\n85555 3\n68349 2\n76270 2\n56711 13\n60381 6\n74757 11\n58602 12\n83014 11\n10344 2\n18259 14\n41836 4\n26770 2\n8245 8\n82226 8\n68545 2\n13026 15\n95537 7\n6463 1\n89800 1\n16070 2\n9389 5\n98033 3\n19102 11\n84955 4\n61018 13\n751 4\n68501 5\n",
"output": "49811\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n25350 21\n96944 27\n39618 10\n41361 5\n6591 1\n",
"output": "55550\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n74302 10\n38566 27\n30455 11\n1678 4\n3938 24\n59873 6\n90244 29\n93429 6\n43547 28\n55198 20\n",
"output": "50083\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n86420 1\n47113 13\n64472 1\n53043 9\n13420 14\n76914 4\n94265 5\n58960 32\n37738 2\n62910 8\n84632 13\n12139 1\n7152 29\n88101 6\n7610 6\n26751 3\n20745 14\n18315 8\n28921 1\n21476 2\n",
"output": "49883\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n52994 2\n23288 15\n81416 16\n81533 16\n34292 16\n33769 9\n83905 26\n66312 5\n68536 27\n25739 4\n47063 28\n52941 13\n32163 1\n73306 14\n95733 16\n88459 2\n1439 4\n81112 6\n7142 8\n22978 17\n40445 4\n35423 2\n30283 5\n89053 6\n45961 16\n47050 8\n69093 2\n697 7\n56337 23\n48408 20\n43287 18\n454 11\n954 4\n45261 3\n82023 2\n21357 5\n57677 2\n36910 2\n59441 3\n85506 3\n",
"output": "49732\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n79901 42\n54923 2\n62869 4\n65551 27\n87048 4\n",
"output": "54920\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n40506 6\n34059 5\n38905 34\n83603 11\n66381 8\n93554 4\n7544 19\n86566 4\n25352 4\n96048 16\n",
"output": "49985\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n95468 23\n90408 16\n87565 4\n75513 4\n20971 2\n25009 29\n33037 29\n40038 2\n58148 19\n8408 2\n60320 15\n42740 3\n44945 2\n21695 8\n59723 38\n73068 2\n72608 19\n91778 12\n53661 4\n77225 46\n",
"output": "49854\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n34512 2\n28710 30\n42353 20\n28138 11\n818 42\n40056 1\n68439 8\n43563 42\n3766 14\n19516 25\n54016 62\n93742 41\n98921 3\n50948 8\n58432 2\n58209 7\n55704 18\n77002 8\n82500 16\n498 2\n88306 12\n17568 3\n88313 1\n93767 7\n12186 2\n79225 2\n1910 8\n60198 29\n89693 2\n49128 2\n40818 8\n34413 12\n20499 1\n3649 3\n21079 3\n9349 2\n32774 38\n14759 26\n79319 6\n44325 37\n",
"output": "49554\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n95719 2\n83337 69\n17427 124\n73738 1\n59503 41\n",
"output": "53474\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n72759 89\n31969 4\n84006 24\n7486 45\n1600 5\n54176 2\n59014 6\n76704 119\n59238 1\n29271 2\n",
"output": "50444\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n50897 12\n82689 22\n55442 28\n32615 6\n48930 81\n25243 5\n38752 110\n45025 16\n43729 2\n82637 1\n89951 10\n58373 1\n1389 7\n20683 2\n12366 127\n66021 4\n17264 27\n55759 12\n13239 1\n18370 53\n",
"output": "49715\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n67499 128\n18678 3\n32621 61\n46926 107\n41174 20\n90207 127\n25076 18\n78735 14\n68443 8\n28831 2\n83000 75\n52968 115\n58919 4\n77318 18\n78727 55\n19986 59\n85666 95\n75610 11\n55390 23\n59376 12\n87643 63\n55139 42\n38661 80\n457 21\n1886 9\n61516 71\n14324 103\n28627 2\n64006 3\n47570 7\n71651 17\n34118 107\n45277 14\n31144 4\n70921 74\n8388 4\n32174 11\n22012 6\n67839 5\n51280 10\n",
"output": "48822\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n2742 8\n53984 236\n69767 231\n45509 2\n39889 59\n",
"output": "50997\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n54735 2\n98665 153\n17472 2\n26292 12\n44348 22\n54855 15\n28437 98\n94916 4\n10408 23\n99667 189\n",
"output": "50425\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n11672 105\n94527 8\n83821 4\n37084 55\n60655 24\n16189 4\n34135 85\n34867 2\n55552 7\n52666 49\n66146 74\n6273 2\n13905 59\n20381 4\n59843 83\n53964 38\n24508 4\n77118 4\n15930 3\n62737 1\n",
"output": "49678\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n68637 250\n15718 58\n26714 15\n49786 15\n13359 8\n28367 2\n62024 97\n46061 52\n61112 96\n72226 233\n70981 28\n45379 1\n28398 4\n41275 8\n12280 133\n75146 9\n62439 214\n26526 32\n44676 3\n19031 2\n14260 195\n19053 45\n58423 3\n89174 4\n36613 8\n58708 32\n19140 2\n34072 219\n99129 5\n7006 80\n87999 8\n38558 7\n50309 238\n77671 1\n17665 73\n95834 12\n72684 9\n23193 81\n57013 53\n58594 9\n",
"output": "48168\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n63303 72\n97883 4\n12457 96\n66892 6\n92884 6\n",
"output": "50677\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n57437 57\n78480 2\n30047 2\n22974 16\n19579 201\n25666 152\n77014 398\n94142 2\n65837 442\n69836 23\n",
"output": "49615\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n29764 28\n87214 24\n43812 151\n22119 512\n36641 38\n52113 29\n56955 155\n13605 14\n99224 7\n48614 2\n64555 215\n71439 8\n78995 60\n84075 103\n7907 15\n79915 237\n69409 4\n98226 154\n23889 4\n91844 100\n",
"output": "48450\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n96037 20\n46624 124\n376 24\n21579 329\n30814 16\n93353 2\n37876 5\n31134 15\n91879 101\n56921 3\n60149 1\n32051 12\n87665 1\n43512 6\n99773 2\n93817 8\n4019 448\n21051 1\n41295 98\n9402 89\n6576 498\n37085 50\n8593 3\n611 17\n4320 411\n72688 30\n81747 8\n9120 147\n70791 95\n29492 43\n11656 162\n37753 105\n19543 72\n86959 2\n17301 2\n49114 152\n76580 19\n27610 10\n81365 2\n31055 159\n",
"output": "48015\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n86592 146\n14936 12\n74772 251\n14953 2\n82726 247\n",
"output": "59565\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n36153 5\n75526 126\n70668 438\n84951 4\n66650 1\n13780 312\n70504 798\n1119 395\n41802 2\n69442 106\n",
"output": "49678\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n60719 128\n50622 18\n63673 358\n54655 4\n29105 1\n63976 7\n96998 334\n65216 723\n52540 12\n1268 666\n8242 2\n86941 140\n99111 27\n2965 11\n25870 135\n29573 339\n99204 13\n36279 30\n86150 232\n67144 76\n",
"output": "47933\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n46403 17\n54955 61\n74185 12\n5141 2\n48606 729\n68203 73\n73631 118\n79515 577\n51004 20\n68430 16\n82547 4\n39436 56\n59971 2\n13164 543\n16471 7\n86520 42\n47054 264\n69354 8\n84857 8\n71801 45\n41099 8\n94095 8\n24142 1\n25537 6\n59382 3\n62270 32\n2989 48\n14329 354\n152 8\n450 10\n91698 20\n17145 6\n37249 63\n96026 20\n24555 2\n99362 588\n21434 3\n29806 217\n57636 5\n24354 22\n",
"output": "46585\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n88825 16\n42009 4\n12536 6\n27456 2\n97947 64\n",
"output": "51045\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n1635 8\n33823 61\n5721 646\n48628 1504\n74630 49\n75538 1163\n57979 176\n10592 6\n49836 8\n13039 1427\n",
"output": "46506\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n96994 121\n52505 16\n39110 4\n550 203\n60219 6\n19241 443\n33570 7\n48536 1\n42760 61\n45069 4\n38141 17\n60419 50\n98857 9\n73167 66\n17284 96\n38049 1061\n12937 15\n8136 2\n29734 185\n31184 19\n",
"output": "47971\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n97514 53\n80797 379\n84354 292\n79244 2\n50047 431\n44535 1989\n55021 15\n73792 98\n6532 185\n24440 1986\n11045 54\n95293 24\n83588 1129\n80713 4\n36999 837\n33125 1\n81815 4\n6354 2\n11472 2\n47815 178\n24587 339\n44181 2\n52337 521\n76224 47\n51300 241\n45542 87\n38184 1398\n92802 8\n60559 70\n6458 54\n35620 3\n57750 11\n57175 4\n65095 8\n10390 387\n13810 182\n88779 1\n30393 1\n67934 35\n65584 11\n",
"output": "41284\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n66409 12\n63802 2\n95034 9\n82818 1288\n45078 227\n",
"output": "49807\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n3219 7\n12223 56\n90921 27\n71142 1398\n87964 839\n16499 8\n72444 32\n67739 130\n93403 4\n3846 3\n",
"output": "51101\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n55345 8\n65637 356\n70322 88\n16632 31\n10631 854\n76026 12\n38962 8\n26462 1\n11676 122\n76312 4\n89117 687\n57003 11\n70170 266\n64422 46\n16054 2\n93472 877\n15206 24\n39406 1149\n99456 889\n76963 2\n",
"output": "45965\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n82729 23\n20257 23\n35728 2\n25011 12\n4960 71\n21761 33\n44761 14\n71668 843\n98965 53\n80881 535\n28561 404\n61276 999\n97500 851\n19183 245\n78699 876\n63107 4\n2802 478\n62470 148\n28013 26\n350 1529\n70579 8\n71417 797\n33173 1\n19413 25\n38142 191\n72645 260\n35515 2\n28804 16\n41640 2\n21600 16\n893 437\n7071 368\n75545 395\n98218 1005\n97927 3\n43976 1\n76398 2\n10460 632\n36563 38\n37813 1254\n",
"output": "43774\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n13264 13\n67967 581\n9017 12\n22564 4\n75202 981\n",
"output": "51652\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n31514 7\n43285 4660\n39669 3899\n60022 838\n33584 643\n78825 16\n824 32\n51664 31\n15433 476\n14295 591\n",
"output": "44144\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n76900 749\n4459 3\n94269 2\n82747 213\n4707 2\n25269 4510\n20680 975\n76445 105\n69770 26\n98437 138\n9149 1727\n542 1\n4528 956\n99559 3050\n16375 86\n2140 1295\n59410 15\n25894 7727\n48176 1251\n75691 962\n",
"output": "34689\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n97318 1810\n83374 13\n5633 437\n88352 47\n95345 59\n17545 249\n24102 22\n51457 1\n76529 1\n37126 18\n49452 16\n57843 23\n9831 18\n1455 3\n11806 86\n37145 2\n88995 14\n68601 14\n43229 6\n1611 3\n30150 1479\n55553 2\n13132 50\n16914 13\n25556 63\n89903 6883\n56210 1\n53913 3747\n21131 798\n46002 13\n95645 2\n87403 3155\n34836 8\n12090 61\n13655 25\n33060 54\n42493 258\n90629 3899\n30302 2\n95065 78\n",
"output": "35469\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n37011 9701\n74984 679\n18318 55\n92053 173\n26429 12487\n",
"output": "38278\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n11670 1339\n79595 481\n53274 401\n14356 102\n96605 13\n2355 233\n54983 6904\n47863 49\n27611 11\n96114 336\n",
"output": "41632\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n61697 2\n97163 1\n45531 2964\n41121 1\n55732 4965\n12614 10451\n48412 185\n834 4\n53784 337\n27676 61\n31448 120\n73540 9753\n51358 3568\n31327 4576\n69903 2048\n48288 8116\n54268 41\n89314 10612\n32624 16\n83135 62\n",
"output": "7753\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n3459 2\n86272 5148\n24317 160\n44251 1415\n26597 1\n1319 256\n92116 4\n38907 3\n60128 6673\n71018 2\n35857 936\n97060 2\n4950 6165\n63923 4\n75390 2346\n83335 2\n57524 6\n99812 3\n32248 206\n48786 3185\n69204 16143\n55261 7\n67356 2\n86284 148\n19119 3\n45733 369\n85011 73\n73772 106\n64294 33\n53040 26\n86208 12520\n77019 1573\n52972 2928\n9979 352\n39446 303\n51300 3353\n49439 639\n53349 620\n37475 1303\n53218 12257\n",
"output": "15210\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n89743 8\n64030 13\n33057 439\n69697 34\n28568 11302\n",
"output": "40041\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n308 1\n27837 235\n74223 8762\n25432 10\n62498 5795\n65172 3223\n39762 48\n74347 1\n6364 1523\n73376 8\n",
"output": "41919\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n32216 25\n1771 1876\n29601 4397\n65385 2\n75865 1\n97013 28\n60770 1816\n17137 32\n32943 15\n5320 5\n10846 7383\n77785 13\n62852 369\n78343 7\n86849 14387\n80901 546\n42168 3254\n99786 32092\n93242 24\n14005 53\n",
"output": "20505\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n8644 429\n97881 2766\n98955 25663\n8679 187\n54897 23213\n64306 4647\n46280 23471\n31464 3\n35532 2\n95998 1352\n28824 3\n99405 3856\n47271 13832\n66959 7\n50599 11\n70318 293\n84159 236\n10893 1914\n54437 15065\n4468 3\n91940 32106\n87980 50\n81589 378\n8783 23\n11417 690\n2733 259\n84915 26\n15315 2880\n60017 3214\n58220 1\n17160 185\n60640 10496\n46075 143\n12251 2938\n6582 12\n7234 827\n32344 830\n3330 18\n48612 290\n47531 14241\n",
"output": "7924\n",
"type": "stdin_stdout"
},
{
"input": "5 100000\n54710 49\n23118 497\n25124 113\n8533 204\n6259 78\n",
"output": "51421\n",
"type": "stdin_stdout"
},
{
"input": "10 100000\n17296 29\n91310 2\n57522 122\n3226 3493\n56545 798\n34449 65176\n52982 57\n63054 20\n85401 26\n35366 40\n",
"output": "375\n",
"type": "stdin_stdout"
},
{
"input": "20 100000\n48315 147\n18844 54412\n53410 113\n47381 299\n47399 4\n43189 2182\n44092 269\n86931 4\n69501 21297\n7463 152\n748 3195\n21275 2\n91263 2853\n70156 4\n94007 11073\n73642 27\n10505 88\n48437 56\n45377 3297\n44125 328\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "40 100000\n97613 14\n21950 98\n79071 6\n17398 4\n52818 26\n86382 74\n45221 20\n34027 4550\n37075 16\n64440 15989\n16227 277\n55118 887\n89050 678\n14236 3\n23333 24\n95767 7042\n76449 294\n34947 62\n93092 3916\n10791 1852\n10371 84\n11819 36794\n3774 22\n20470 574\n69834 216\n86866 21\n48346 11\n79493 27990\n54723 4\n7406 963\n21932 18679\n98450 13060\n28964 915\n86494 14\n6303 392\n865 3624\n31750 23\n65411 241\n8209 312\n15896 17139\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 100000\n3 1200\n1205 0\n80000 78793\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 100000\n20001 78793\n98796 0\n99998 1200\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "8 100000\n1217 0\n1208 0\n1220 0\n3 1200\n1205 0\n1214 0\n1211 0\n80000 78778\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "8 100000\n98796 0\n20001 78778\n98790 0\n98781 0\n98787 0\n98793 0\n98784 0\n99998 1200\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1253/E"
} | vfc_10314 |
apps | verifiable_code | 142 | Solve the following coding problem using the programming language python:
A New Year party is not a New Year party without lemonade! As usual, you are expecting a lot of guests, and buying lemonade has already become a pleasant necessity.
Your favorite store sells lemonade in bottles of n different volumes at different costs. A single bottle of type i has volume 2^{i} - 1 liters and costs c_{i} roubles. The number of bottles of each type in the store can be considered infinite.
You want to buy at least L liters of lemonade. How many roubles do you have to spend?
-----Input-----
The first line contains two integers n and L (1 ≤ n ≤ 30; 1 ≤ L ≤ 10^9) — the number of types of bottles in the store and the required amount of lemonade in liters, respectively.
The second line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^9) — the costs of bottles of different types.
-----Output-----
Output a single integer — the smallest number of roubles you have to pay in order to buy at least L liters of lemonade.
-----Examples-----
Input
4 12
20 30 70 90
Output
150
Input
4 3
10000 1000 100 10
Output
10
Input
4 3
10 100 1000 10000
Output
30
Input
5 787787787
123456789 234567890 345678901 456789012 987654321
Output
44981600785557577
-----Note-----
In the first example you should buy one 8-liter bottle for 90 roubles and two 2-liter bottles for 30 roubles each. In total you'll get 12 liters of lemonade for just 150 roubles.
In the second example, even though you need only 3 liters, it's cheaper to buy a single 8-liter bottle for 10 roubles.
In the third example it's best to buy three 1-liter bottles for 10 roubles each, getting three liters for 30 roubles.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
3
# Copyright (C) 2017 Sayutin Dmitry.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License as
# published by the Free Software Foundation; version 3
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; If not, see <http://www.gnu.org/licenses/>.
def solve(a, l):
if l == 0:
return 0
if l == 1:
return a[0]
k = 0
while (2 ** k) < l:
k += 1
return min(a[k], a[k - 1] + solve(a, l - (2 ** (k - 1))))
def main():
n, l = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n - 2, -1, -1):
if a[i] > a[i + 1]:
a[i] = a[i + 1]
for i in range(1, n):
if a[i] > 2 * a[i - 1]:
a[i] = 2 * a[i - 1]
while len(a) < 35:
a.append(2 * a[len(a) - 1])
#print(a)
print(solve(a, l))
main()
``` | {
"language": "python",
"test_cases": [
{
"input": "4 12\n20 30 70 90\n",
"output": "150\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n10000 1000 100 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n10 100 1000 10000\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "5 787787787\n123456789 234567890 345678901 456789012 987654321\n",
"output": "44981600785557577\n",
"type": "stdin_stdout"
},
{
"input": "30 792520535\n528145579 682850171 79476920 178914057 180053263 538638086 433143781 299775597 723428544 177615223 959893339 639448861 506106572 807471834 42398440 347390133 65783782 988164990 606389825 877178711 513188067 609539702 558894975 271129128 956393790 981348376 608410525 61890513 991440277 682151552\n",
"output": "371343078\n",
"type": "stdin_stdout"
},
{
"input": "30 719520853\n1 3 7 9 21 44 81 49 380 256 1592 1523 4711 6202 1990 48063 112547 210599 481862 1021025 2016280 643778 4325308 3603826 20964534 47383630 100267203 126018116 187142230 604840362\n",
"output": "87393281\n",
"type": "stdin_stdout"
},
{
"input": "30 604179824\n501412684 299363783 300175300 375965822 55881706 96888084 842141259 269152598 954400269 589424644 244226611 443088309 914941214 856763895 380059734 9424058 97467018 912446445 609122261 773853033 728987202 239388430 617092754 182847275 385882428 86295843 416876980 952408652 399750639 326299418\n",
"output": "564859510\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000\n1000000000\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "30 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "2000000000\n",
"type": "stdin_stdout"
},
{
"input": "5 25\n52 91 84 66 93\n",
"output": "186\n",
"type": "stdin_stdout"
},
{
"input": "10 660\n2316 3782 9667 4268 4985 2256 6854 9312 4388 9913\n",
"output": "13164\n",
"type": "stdin_stdout"
},
{
"input": "20 807689532\n499795319 630489472 638483114 54844847 209402053 71113129 931903630 213385792 726471950 950559532 396028074 711222849 458354548 937511907 247071934 160971961 333550064 4453536 857363099 464797922\n",
"output": "27447142368\n",
"type": "stdin_stdout"
},
{
"input": "30 842765745\n2 2 2 4 6 8 12 12 18 28 52 67 92 114 191 212 244 459 738 1078 1338 1716 1860 1863 2990 4502 8575 11353 12563 23326\n",
"output": "42251\n",
"type": "stdin_stdout"
},
{
"input": "1 1\n1000000000\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000\n1\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "30 1\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "30 1000000000\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": "2\n",
"type": "stdin_stdout"
},
{
"input": "30 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\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 570846883\n300888960\n",
"output": "171761524945111680\n",
"type": "stdin_stdout"
},
{
"input": "2 245107323\n357416000 761122471\n",
"output": "87605278957368000\n",
"type": "stdin_stdout"
},
{
"input": "3 624400466\n824008448 698922561 760128125\n",
"output": "118656089186285061\n",
"type": "stdin_stdout"
},
{
"input": "5 972921345\n496871039 134331253 959524096 747165691 981088452\n",
"output": "59657618590751221\n",
"type": "stdin_stdout"
},
{
"input": "8 700735368\n931293374 652764228 183746499 853268148 653623691 684604018 902322304 186452621\n",
"output": "1020734127854016\n",
"type": "stdin_stdout"
},
{
"input": "13 695896744\n495801986 946818643 421711713 151976207 616318787 713653645 893406153 42255449 871957806 865208878 547381951 478062469 516417162\n",
"output": "87737726572314\n",
"type": "stdin_stdout"
},
{
"input": "21 186982676\n261355063 273322266 663309548 981847874 432074163 204617748 86151188 381783810 725544703 947880176 870951660 226330358 680228931 959825764 972157951 874066182 208942221 587976360 749662969 377541340 841644620\n",
"output": "134782258380\n",
"type": "stdin_stdout"
},
{
"input": "29 140874704\n948286516 335531500 165926134 633474522 606947099 21370216 16126534 254131475 624116869 824903957 541685498 351709345 925541565 253434732 759289345 168754543 993046389 636985579 332772332 103110829 311797311 739860627 233674609 950017614 387656468 939870312 161573356 176555912 592529105\n",
"output": "338129268\n",
"type": "stdin_stdout"
},
{
"input": "6 566613866\n1 3 3 16 11 13\n",
"output": "230186887\n",
"type": "stdin_stdout"
},
{
"input": "11 435675771\n2 2 2 4 4 5 5 8 10 18 21\n",
"output": "8934765\n",
"type": "stdin_stdout"
},
{
"input": "13 688240686\n2 4 1 15 7 1 34 129 295 905 1442 1198 3771\n",
"output": "21507522\n",
"type": "stdin_stdout"
},
{
"input": "15 645491742\n2 2 2 2 3 3 4 8 10 14 19 37 42 74 84\n",
"output": "3309432\n",
"type": "stdin_stdout"
},
{
"input": "29 592983020\n2 3 7 8 30 45 125 132 124 61 1231 1626 7470 14538 18828 35057 34820 219967 359159 362273 1577550 2434174 1736292 15104217 17689384 39467552 50809520 13580992 414752454\n",
"output": "61009202\n",
"type": "stdin_stdout"
},
{
"input": "29 42473833\n13 18 21 32 45 72 134 203 320 342 400 565 1039 1093 2142 3383 5360 7894 13056 17053 26524 38453 63285 102775 156618 252874 304854 600862 857837\n",
"output": "304854\n",
"type": "stdin_stdout"
},
{
"input": "28 48504243\n1 1 6 1 32 37 125 212 187 676 1679 771 485 9030 1895 26084 109430 96769 257473 383668 645160 1550917 6195680 6309095 16595706 13231037 99591007 255861473\n",
"output": "5610124\n",
"type": "stdin_stdout"
},
{
"input": "28 17734553\n13 22 33 59 93 164 166 308 454 532 771 898 1312 2256 3965 5207 6791 13472 13793 26354 47030 68133 118082 199855 221897 257395 417525 536230\n",
"output": "257395\n",
"type": "stdin_stdout"
},
{
"input": "27 358801274\n2 3 6 10 2 30 124 35 249 268 79 4013 1693 3522 17730 17110 52968 235714 155787 405063 1809923 667660 2266461 14291190 15502027 54103386 14154765\n",
"output": "27680968\n",
"type": "stdin_stdout"
},
{
"input": "27 437705674\n13 13 21 21 25 31 49 83 148 243 246 263 268 282 475 867 1709 3333 4587 5947 11467 22629 25843 31715 34392 45690 47657\n",
"output": "333599\n",
"type": "stdin_stdout"
},
{
"input": "26 519355202\n2 2 6 3 4 23 124 115 312 883 526 3158 2901 14398 797 8137 127577 112515 54101 426458 877533 3978708 6725849 5496068 14408348 27866871\n",
"output": "25264103\n",
"type": "stdin_stdout"
},
{
"input": "26 707933691\n13 17 31 44 69 70 89 158 246 320 605 934 1635 2364 4351 8660 10262 11664 14090 18908 35845 51033 59963 78775 117479 179510\n",
"output": "3829673\n",
"type": "stdin_stdout"
},
{
"input": "25 269843721\n1 4 5 12 6 16 123 195 374 475 974 2303 4109 8890 16632 64699 71115 251461 476703 447854 2042296 3095451 2796629 13478163 13314670\n",
"output": "101191398\n",
"type": "stdin_stdout"
},
{
"input": "25 978161707\n13 22 24 34 66 73 145 287 289 521 693 996 1230 1486 1517 2663 3770 3776 5286 7953 15775 30877 42848 84850 114828\n",
"output": "6718647\n",
"type": "stdin_stdout"
},
{
"input": "5 304398130\n328619601 758941829 198270024 713154224 371680309\n",
"output": "7071174590398871\n",
"type": "stdin_stdout"
},
{
"input": "10 354651161\n676522959 11809337 625434179 312329830 399019943 545095979 566206452 292370104 819250687 361397475\n",
"output": "250332233709431\n",
"type": "stdin_stdout"
},
{
"input": "10 907948615\n369010656 907829481 622481545 200317148 960270397 26028213 655060035 796833494 123373353 324969455\n",
"output": "437565141462561\n",
"type": "stdin_stdout"
},
{
"input": "10 590326547\n540224591 578261545 271951966 787805881 165741203 795359732 547118852 746648763 284153835 602102300\n",
"output": "655248513971940\n",
"type": "stdin_stdout"
},
{
"input": "20 264504887\n256244331 292829612 807171068 120710 900798902 214013876 575261859 40214283 293542999 366877272 353675296 705322168 205009788 86530854 620744650 766826836 240331588 700218303 406369581 649737981\n",
"output": "327898333295\n",
"type": "stdin_stdout"
},
{
"input": "20 749478720\n148277091 195065491 92471169 473441125 104827125 387256363 959435633 241640 395794406 734016994 107553118 129783960 812331272 999596018 837854100 215240378 598412225 653614923 933185587 845929351\n",
"output": "1209345077739\n",
"type": "stdin_stdout"
},
{
"input": "20 628134337\n706690396 73852246 47785764 655257266 217430459 211108098 623632685 631391825 628008556 962083938 616573502 326152383 7023992 288143889 264733804 886206130 342256543 779010688 657787839 476634612\n",
"output": "571078505096\n",
"type": "stdin_stdout"
},
{
"input": "20 708413057\n985177466 224645388 772550594 994150052 856456221 65855795 599129505 903908498 200612104 575185982 507918207 574454347 607410366 738301336 274020952 556522307 665003603 363184479 760246523 952436964\n",
"output": "1287105522843\n",
"type": "stdin_stdout"
},
{
"input": "20 228553575\n966247381 207786628 69006100 269956897 359963312 510868514 95130877 473280024 180071136 34097367 898985854 981155909 369570614 803892852 773207504 603654899 500850166 632114017 442730466 348136258\n",
"output": "151787408488\n",
"type": "stdin_stdout"
},
{
"input": "25 975185569\n680624205 925575600 711019438 10306 879760994 355425133 204004301 536007340 585477874 216944098 296555029 104013726 892946593 309410720 689188172 687796636 375461496 689356349 680367324 137692780 879054435 925597905 677631315 592123801 742526898\n",
"output": "43630079726\n",
"type": "stdin_stdout"
},
{
"input": "30 16804972\n38413642 603358594 93465125 772633637 516421484 75369617 249460374 6747 89975200 3230679 944379663 407211965 820471861 763861258 4711346 787274019 447412797 861015104 104795044 430023687 445411345 316560503 908322702 232775431 33149898 101978638 453254685 587956325 920401353 237657930\n",
"output": "34613997\n",
"type": "stdin_stdout"
},
{
"input": "30 939625169\n799744449 316941501 911543330 868167665 272876554 951480855 826347879 102948940 684991931 833689399 277289558 186462 220073415 602419892 22234767 320279157 908288280 357866038 758158565 784960311 772460297 956631291 623631325 328145434 76400621 637950037 63094834 358429163 210185094 824743978\n",
"output": "766068050\n",
"type": "stdin_stdout"
},
{
"input": "30 649693919\n523756282 905125099 661420695 854128708 504404014 33547776 632846834 593955985 19432317 644543651 552904895 988070696 321825330 923971248 718082642 900061181 310986828 14810582 525301 623288859 578749693 424452633 901712228 411022879 757920556 825042513 796572495 544557755 747250675 987028137\n",
"output": "1213432868\n",
"type": "stdin_stdout"
},
{
"input": "30 941342434\n719914212 905507045 191898825 570606628 687781371 937025497 673960221 557202851 29071681 518803370 894863536 212709126 614432746 924724833 699415275 748075226 796159664 198063404 56538360 649136911 46540367 337023198 45896775 548611961 777908744 873523820 99863819 335685200 503317538 894159729\n",
"output": "1443990241\n",
"type": "stdin_stdout"
},
{
"input": "30 810430346\n807519316 377786333 874568334 100500951 872031247 252690899 923103133 769288634 300502982 184749135 481527896 932556233 978317077 980235169 677287 308980653 527243473 763242606 219639015 712288933 901059456 30978091 127839849 9946626 456644060 226102694 611552752 816642473 434613587 723611518\n",
"output": "964822722\n",
"type": "stdin_stdout"
},
{
"input": "30 187125289\n660214771 614231774 943973836 50780694 214277957 695192266 425421684 100830325 236002350 233594142 318777769 611117973 758216803 141783036 487402819 42225289 132824573 354540681 64152506 838447015 853800951 605421421 151364012 455396619 928950961 236389207 47829341 743089941 577129072 792900471\n",
"output": "143488023\n",
"type": "stdin_stdout"
},
{
"input": "30 129428748\n954910836 756938357 407311375 992660029 134837594 230127140 815239978 545145316 559077075 373018190 923169774 981420723 349998683 971610245 428903049 879106876 229199860 842029694 817413103 141736569 236414627 263122579 394309719 946134085 550877425 544748100 732982715 933907937 67960170 145090225\n",
"output": "67960170\n",
"type": "stdin_stdout"
},
{
"input": "30 12544876\n528459681 350718911 432940853 266976578 679316371 959899124 158423966 471112176 136348553 752311334 979696813 624253517 374825117 338804760 506350966 717644199 528671610 10427712 256677344 288800318 711338213 778230088 616184102 968447942 275963441 257842321 753599064 812398057 815035849 207576747\n",
"output": "207576747\n",
"type": "stdin_stdout"
},
{
"input": "30 7\n476599619 58464676 796410905 224866489 780155470 404375041 576176595 767831428 598766545 225605178 819316136 781962412 217423411 484904923 194288977 597593185 181464481 65918422 225080972 53705844 584415879 463767806 845989273 434760924 477902363 145682570 721445310 803966515 927906514 191883417\n",
"output": "53705844\n",
"type": "stdin_stdout"
},
{
"input": "30 9324\n205304890 806562207 36203756 437374231 230840114 828741258 227108614 937997270 74150322 673068857 353683258 757136864 274921753 418595773 638411312 307919005 304470011 439118457 402187013 371389195 981316766 26764964 293610954 177952828 49223547 718589642 982551043 395151318 564895171 138874187\n",
"output": "26764964\n",
"type": "stdin_stdout"
},
{
"input": "30 512443535\n2 10 30 20 26 9 2 4 24 25 4 27 27 9 13 30 30 5 3 24 10 4 14 14 8 3 2 22 25 25\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "30 553648256\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913\n",
"output": "553648259\n",
"type": "stdin_stdout"
},
{
"input": "30 536870912\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913\n",
"output": "536870913\n",
"type": "stdin_stdout"
},
{
"input": "30 504365056\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913\n",
"output": "504365061\n",
"type": "stdin_stdout"
},
{
"input": "30 536870913\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913\n",
"output": "536870915\n",
"type": "stdin_stdout"
},
{
"input": "30 536870911\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913\n",
"output": "536870913\n",
"type": "stdin_stdout"
},
{
"input": "30 571580555\n2 3 5 9 17 33 65 129 257 513 1025 2049 4097 8193 16385 32769 65537 131073 262145 524289 1048577 2097153 4194305 8388609 16777217 33554433 67108865 134217729 268435457 536870913\n",
"output": "571580565\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000\n1\n",
"output": "1000000000\n",
"type": "stdin_stdout"
},
{
"input": "4 8\n8 4 4 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n10 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "30 915378355\n459233266 779915330 685344552 78480977 949046834 774589421 94223415 727865843 464996500 268056254 591348850 753027575 142328565 174597246 47001711 810641112 130836837 251339580 624876035 850690451 290550467 119641933 998066976 791349365 549089363 492937533 140746908 265213422 27963549 109184295\n",
"output": "111854196\n",
"type": "stdin_stdout"
},
{
"input": "3 7\n20 20 30\n",
"output": "60\n",
"type": "stdin_stdout"
},
{
"input": "1 1000000000\n1000000000\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "5 787787787\n1 2 3 4 5\n",
"output": "246183685\n",
"type": "stdin_stdout"
},
{
"input": "2 3\n10 5\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "28 146201893\n79880639 962577454 837935105 770531287 992949199 401766756 805281924 931353274 246173135 378375823 456356972 120503545 811958850 126793843 720341477 413885800 272086545 758855930 979214555 491838924 465216943 706180852 786946242 646685999 436847726 625436 360241773 620056496\n",
"output": "3127180\n",
"type": "stdin_stdout"
},
{
"input": "5 9\n2 100 100 10 13\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "1 134217728\n1000000000\n",
"output": "134217728000000000\n",
"type": "stdin_stdout"
},
{
"input": "1 536870912\n1000000000\n",
"output": "536870912000000000\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n34 22 21 20 30\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "1 787787787\n1\n",
"output": "787787787\n",
"type": "stdin_stdout"
},
{
"input": "7 7\n34 22 21 20 30 20 20\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "5 5\n34 22 21 25 30\n",
"output": "25\n",
"type": "stdin_stdout"
},
{
"input": "5 787787787\n123456789 234567890 345678901 456789012 1\n",
"output": "49236737\n",
"type": "stdin_stdout"
},
{
"input": "6 6\n34 22 21 25 30 35\n",
"output": "25\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/913/C"
} | vfc_10322 |
apps | verifiable_code | 143 | Solve the following coding problem using the programming language python:
Someone gave Alyona an array containing n positive integers a_1, a_2, ..., a_{n}. In one operation, Alyona can choose any element of the array and decrease it, i.e. replace with any positive integer that is smaller than the current one. Alyona can repeat this operation as many times as she wants. In particular, she may not apply any operation to the array at all.
Formally, after applying some operations Alyona will get an array of n positive integers b_1, b_2, ..., b_{n} such that 1 ≤ b_{i} ≤ a_{i} for every 1 ≤ i ≤ n. Your task is to determine the maximum possible value of mex of this array.
Mex of an array in this problem is the minimum positive integer that doesn't appear in this array. For example, mex of the array containing 1, 3 and 4 is equal to 2, while mex of the array containing 2, 3 and 2 is equal to 1.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of elements in the Alyona's array.
The second line of the input contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) — the elements of the array.
-----Output-----
Print one positive integer — the maximum possible value of mex of the array after Alyona applies some (possibly none) operations.
-----Examples-----
Input
5
1 3 3 3 6
Output
5
Input
2
2 1
Output
3
-----Note-----
In the first sample case if one will decrease the second element value to 2 and the fifth element value to 4 then the mex value of resulting array 1 2 3 3 4 will be equal to 5.
To reach the answer to the second sample case one must not decrease any of the array elements.
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())
l=list(map(int, input().split(' ')))
l.sort()
a=1
for i in l:
if i>=a:
a+=1
print(a)
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n1 3 3 3 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1\n1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n1000000000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1\n2\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2\n1 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2\n2 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2\n3 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 4 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 3 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 1 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 2 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n2 3 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 4 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n3 3 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 3 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n4 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 3 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 4 1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 3 2 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 1 4 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 3 1 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 3 4 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 4 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 2 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 2 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 4 1 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 3 1 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 3 4 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 4 2 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 1 3 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 4 3 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 4 4 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 1 4 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 3 2\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 2 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 3 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 3 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 4 4 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 3 3 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 4 3 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 4 2 3\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 4 4 2\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 3 3 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n3 3 3 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 3 3 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 4 3 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n4 4 4 4\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "11\n1 1 1 1 1 1 1 1 1 3 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "20\n1 1 1 1 1 1 1 1 1 1 8 8 8 8 8 8 8 8 8 8\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "4\n2 2 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "3\n1 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "15\n1 2 2 20 23 25 28 60 66 71 76 77 79 99 100\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "7\n1 2 2 2 5 5 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 1 1 10000\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 1 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "7\n1 3 3 3 3 3 6\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 1 3\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10\n1 1 1 1 1 1 1 1 1 100\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4\n1 1 2 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 1 3 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "8\n1 1 1 1 2 2 3 40\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5\n1 1 1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7\n1 2 2 2 2 2 4\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "10\n1 1 1 10000000 10000000 10000000 10000000 10000000 10000000 10000000\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "10\n1 1 1 1 1 1 1 1 2 3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4\n8 8 8 8\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5\n5 6 6 6 7\n",
"output": "6\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/682/B"
} | vfc_10326 |
apps | verifiable_code | 144 | Solve the following coding problem using the programming language python:
Recently Vasya found a golden ticket — a sequence which consists of $n$ digits $a_1a_2\dots a_n$. Vasya considers a ticket to be lucky if it can be divided into two or more non-intersecting segments with equal sums. For example, ticket $350178$ is lucky since it can be divided into three segments $350$, $17$ and $8$: $3+5+0=1+7=8$. Note that each digit of sequence should belong to exactly one segment.
Help Vasya! Tell him if the golden ticket he found is lucky or not.
-----Input-----
The first line contains one integer $n$ ($2 \le n \le 100$) — the number of digits in the ticket.
The second line contains $n$ digits $a_1 a_2 \dots a_n$ ($0 \le a_i \le 9$) — the golden ticket. Digits are printed without spaces.
-----Output-----
If the golden ticket is lucky then print "YES", otherwise print "NO" (both case insensitive).
-----Examples-----
Input
5
73452
Output
YES
Input
4
1248
Output
NO
-----Note-----
In the first example the ticket can be divided into $7$, $34$ and $52$: $7=3+4=5+2$.
In the second example it is impossible to divide ticket into segments with equal sum.
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 = list(map(int, list(input())))
for i in range(n - 1):
sm = sum(a[:i + 1])
tn = 0
res = True
has = False
for j in range(i + 1, n):
tn += a[j]
if (tn == sm):
tn = 0
has = True
elif tn > sm:
res = False
break
if (tn == 0 and res and has):
print("YES")
break
else:
print("NO")
``` | {
"language": "python",
"test_cases": [
{
"input": "5\n73452\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n1248\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n00\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n555\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8\n00020200\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n7435\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "99\n999999999999999999999999999999999999999999999918888888888888888888888888888888888888888888888888887\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n11980\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n2680\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "15\n333703919182090\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8\n54174760\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "84\n123608423980567916563149282633127550576921328162851174479585123236498689270768303090\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "11\n24954512677\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "89\n48529517761848681629105032446942740017666077684799424820853864981046129532307202343543879\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "14\n34732091671571\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n30213\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7\n0010120\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "75\n701550968134602984948768446130093645674414572984517902437769409395298622678\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10\n7232095599\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n5541514\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n303030\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n810214\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10\n9410491089\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n0760\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "11\n77741223101\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "12\n196493527920\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "93\n422951129271016503700234397427203319704940397318938157846153922624198061914374358965386132849\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "95\n98283499944967186695990624831960528372353708412534683491931125807866037495977770567651207842390\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "93\n745805743007484239743029351125106816821581657001902307029649638908353562984680888269297002308\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "95\n63839630788973501705593955617737116537536256623669215818613983033319316372125831199446308351430\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "91\n2051541782278415888842119452926140047121264880418474037041217527775760373306969266517205174\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "94\n7034965617675188707622087662902669462864299620896813095196728648483805681846217732949974650779\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "92\n14066331375782869025116943746607349076775655572332728568031635806727426324069498971915382378\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "90\n170996575076655992395856243508145635272750429329255192493277000774678782094281745394590857\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n0809740931424957283280264749151125408689778966769781910603952566405858112111930579193115510555198933\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n4360837235306857829226262079948050131795231482102447137288804547991971660484969090651046154392003840\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n4818858843973413173925628155746968198939484726544502550668299768135121284562358161389491805498328723\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100\n1481434020093151013248488915859811727012058656675018437252629813973080568161159615248610583559902826\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n5492768358492023832426755085884370126192363497614837472363037754120965150617427992655444750828994630\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100\n7876460771493995217591961791564105527925397369693556696278466376824002802517154352401808638978375899\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n44\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n55\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n514\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n1088\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n6619\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n4939\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "15\n771125622965333\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "15\n876799033969943\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "15\n923556472267622\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "20\n69325921242281090228\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "20\n62452246020300774037\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "20\n48279781257539808651\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n1233321\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n111\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n010\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n343\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n2351\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n102\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n3013\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n11111\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4\n3345\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n001\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n221\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "2\n02\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n77777\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5\n00000\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n36\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n100\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n552\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n3331\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "8\n11111111\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6\n235555\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n222\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n131\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n1112111\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5\n53781\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n1213\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "3\n101\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "2\n11\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9\n122222211\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "31\n1111111111111111111111111111111\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "3\n300\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4\n1001\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7\n1111119\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7\n0120110\n",
"output": "NO\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1030/C"
} | vfc_10330 |
apps | verifiable_code | 145 | Solve the following coding problem using the programming language python:
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked very often and eventually they became a couple in the network.
But yesterday, he came to see "her" in the real world and found out "she" is actually a very strong man! Our hero is very sad and he is too tired to love again now. So he came up with a way to recognize users' genders by their user names.
This is his method: if the number of distinct characters in one's user name is odd, then he is a male, otherwise she is a female. You are given the string that denotes the user name, please help our hero to determine the gender of this user by his method.
-----Input-----
The first line contains a non-empty string, that contains only lowercase English letters — the user name. This string contains at most 100 letters.
-----Output-----
If it is a female by our hero's method, print "CHAT WITH HER!" (without the quotes), otherwise, print "IGNORE HIM!" (without the quotes).
-----Examples-----
Input
wjmzbmr
Output
CHAT WITH HER!
Input
xiaodao
Output
IGNORE HIM!
Input
sevenkplus
Output
CHAT WITH HER!
-----Note-----
For the first example. There are 6 distinct characters in "wjmzbmr". These characters are: "w", "j", "m", "z", "b", "r". So wjmzbmr is a female and you should print "CHAT WITH HER!".
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
q = set()
for i in range(0, len(s)):
q.add(s[i])
print("IGNORE HIM!" if len(q) % 2 == 1 else "CHAT WITH HER!")
``` | {
"language": "python",
"test_cases": [
{
"input": "wjmzbmr\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "xiaodao\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "sevenkplus\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "pezu\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "wnemlgppy\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "zcinitufxoldnokacdvtmdohsfdjepyfioyvclhmujiqwvmudbfjzxjfqqxjmoiyxrfsbvseawwoyynn\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "qsxxuoynwtebujwpxwpajitiwxaxwgbcylxneqiebzfphugwkftpaikixmumkhfbjiswmvzbtiyifbx\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "qwbdfzfylckctudyjlyrtmvbidfatdoqfmrfshsqqmhzohhsczscvwzpwyoyswhktjlykumhvaounpzwpxcspxwlgt\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "nuezoadauueermoeaabjrkxttkatspjsjegjcjcdmcxgodowzbwuqncfbeqlhkk\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "lggvdmulrsvtuagoavstuyufhypdxfomjlzpnduulukszqnnwfvxbvxyzmleocmofwclmzz\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "tgcdptnkc\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "wvfgnfrzabgibzxhzsojskmnlmrokydjoexnvi\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "sxtburpzskucowowebgrbovhadrrayamuwypmmxhscrujkmcgvyinp\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "pjqxhvxkyeqqvyuujxhmbspatvrckhhkfloottuybjivkkhpyivcighxumavrxzxslfpggnwbtalmhysyfllznphzia\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "fpellxwskyekoyvrfnuf\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "xninyvkuvakfbs\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "vnxhrweyvhqufpfywdwftoyrfgrhxuamqhblkvdpxmgvphcbeeqbqssresjifwyzgfhurmamhkwupymuomak\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "kmsk\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "lqonogasrkzhryjxppjyriyfxmdfubieglthyswz\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "ndormkufcrkxlihdhmcehzoimcfhqsmombnfjrlcalffq\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "zqzlnnuwcfufwujygtczfakhcpqbtxtejrbgoodychepzdphdahtxyfpmlrycyicqthsgm\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "ppcpbnhwoizajrl\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "sgubujztzwkzvztitssxxxwzanfmddfqvv\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "ptkyaxycecpbrjnvxcjtbqiocqcswnmicxbvhdsptbxyxswbw\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "yhbtzfppwcycxqjpqdfmjnhwaogyuaxamwxpnrdrnqsgdyfvxu\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "ojjvpnkrxibyevxk\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "wjweqcrqfuollfvfbiyriijovweg\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "hkdbykboclchfdsuovvpknwqr\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "stjvyfrfowopwfjdveduedqylerqugykyu\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "rafcaanqytfclvfdegak\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "xczn\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "arcoaeozyeawbveoxpmafxxzdjldsielp\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "smdfafbyehdylhaleevhoggiurdgeleaxkeqdixyfztkuqsculgslheqfafxyghyuibdgiuwrdxfcitojxika\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "vbpfgjqnhfazmvtkpjrdasfhsuxnpiepxfrzvoh\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "dbdokywnpqnotfrhdbrzmuyoxfdtrgrzcccninbtmoqvxfatcqg\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "udlpagtpq\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "zjurevbytijifnpfuyswfchdzelxheboruwjqijxcucylysmwtiqsqqhktexcynquvcwhbjsipy\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "qagzrqjomdwhagkhrjahhxkieijyten\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "achhcfjnnfwgoufxamcqrsontgjjhgyfzuhklkmiwybnrlsvblnsrjqdytglipxsulpnphpjpoewvlusalsgovwnsngb\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "qbkjsdwpahdbbohggbclfcufqelnojoehsxxkr\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "cpvftiwgyvnlmbkadiafddpgfpvhqqvuehkypqjsoibpiudfvpkhzlfrykc\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "lnpdosnceumubvk\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "efrk\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "temnownneghnrujforif\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "ottnneymszwbumgobazfjyxewkjakglbfflsajuzescplpcxqta\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "eswpaclodzcwhgixhpyzvhdwsgneqidanbzdzszquefh\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "gwntwbpj\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "wuqvlbblkddeindiiswsinkfrnkxghhwunzmmvyovpqapdfbolyim\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "swdqsnzmzmsyvktukaoyqsqzgfmbzhezbfaqeywgwizrwjyzquaahucjchegknqaioliqd\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "vlhrpzezawyolhbmvxbwhtjustdbqggexmzxyieihjlelvwjosmkwesfjmramsikhkupzvfgezmrqzudjcalpjacmhykhgfhrjx\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "lxxwbkrjgnqjwsnflfnsdyxihmlspgivirazsbveztnkuzpaxtygidniflyjheejelnjyjvgkgvdqks\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "wpxbxzfhtdecetpljcrvpjjnllosdqirnkzesiqeukbedkayqx\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "vmzxgacicvweclaodrunmjnfwtimceetsaoickarqyrkdghcmyjgmtgsqastcktyrjgvjqimdc\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "yzlzmesxdttfcztooypjztlgxwcr\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "qpbjwzwgdzmeluheirjrvzrhbmagfsjdgvzgwumjtjzecsfkrfqjasssrhhtgdqqfydlmrktlgfc\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "aqzftsvezdgouyrirsxpbuvdjupnzvbhguyayeqozfzymfnepvwgblqzvmxxkxcilmsjvcgyqykpoaktjvsxbygfgsalbjoq\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "znicjjgijhrbdlnwmtjgtdgziollrfxroabfhadygnomodaembllreorlyhnehijfyjbfxucazellblegyfrzuraogadj\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "qordzrdiknsympdrkgapjxokbldorpnmnpucmwakklmqenpmkom\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "wqfldgihuxfktzanyycluzhtewmwvnawqlfoavuguhygqrrxtstxwouuzzsryjqtfqo\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "vujtrrpshinkskgyknlcfckmqdrwtklkzlyipmetjvaqxdsslkskschbalmdhzsdrrjmxdltbtnxbh\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "zioixjibuhrzyrbzqcdjbbhhdmpgmqykixcxoqupggaqajuzonrpzihbsogjfsrrypbiphehonyhohsbybnnukqebopppa\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "oh\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "kxqthadqesbpgpsvpbcbznxpecqrzjoilpauttzlnxvaczcqwuri\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "zwlunigqnhrwirkvufqwrnwcnkqqonebrwzcshcbqqwkjxhymjjeakuzjettebciadjlkbfp\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "fjuldpuejgmggvvigkwdyzytfxzwdlofrpifqpdnhfyroginqaufwgjcbgshyyruwhofctsdaisqpjxqjmtpp\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "xiwntnheuitbtqxrmzvxmieldudakogealwrpygbxsbluhsqhtwmdlpjwzyafckrqrdduonkgo\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "mnmbupgo\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "mcjehdiygkbmrbfjqwpwxidbdfelifwhstaxdapigbymmsgrhnzsdjhsqchl\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "yocxrzspinchmhtmqo\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "vasvvnpymtgjirnzuynluluvmgpquskuaafwogeztfnvybblajvuuvfomtifeuzpikjrolzeeoftv\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "ecsdicrznvglwggrdbrvehwzaenzjutjydhvimtqegweurpxtjkmpcznshtrvotkvrghxhacjkedidqqzrduzad\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "ubvhyaebyxoghakajqrpqpctwbrfqzli\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "gogbxfeqylxoummvgxpkoqzsmobasesxbqjjktqbwqxeiaagnnhbvepbpy\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "nheihhxkbbrmlpxpxbhnpofcjmxemyvqqdbanwd\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "acrzbavz\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "drvzznznvrzskftnrhvvzxcalwutxmdza\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "oacwxipdfcoabhkwxqdbtowiekpnflnqhlrkustgzryvws\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "tpnwfmfsibnccvdwjvzviyvjfljupinfigfunyff\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "gavaihhamfolcndgytcsgucqdqngxkrlovpthvteacmmthoglxu\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "hsfcfvameeupldgvchmogrvwxrvsmnwxxkxoawwodtsahqvehlcw\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "sbkydrscoojychxchqsuciperfroumenelgiyiwlqfwximrgdbyvkmacy\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "rhh\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "zhdouqfmlkenjzdijxdfxnlegxeuvhelo\n",
"output": "IGNORE HIM!\n",
"type": "stdin_stdout"
},
{
"input": "yufkkfwyhhvcjntsgsvpzbhqtmtgyxifqoewmuplphykmptfdebjxuaxigomjtwgtljwdjhjernkitifbomifbhysnmadtnyn\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
},
{
"input": "urigreuzpxnej\n",
"output": "CHAT WITH HER!\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/236/A"
} | vfc_10334 |
apps | verifiable_code | 146 | Solve the following coding problem using the programming language python:
This morning, Roman woke up and opened the browser with $n$ opened tabs numbered from $1$ to $n$. There are two kinds of tabs: those with the information required for the test and those with social network sites. Roman decided that there are too many tabs open so he wants to close some of them.
He decided to accomplish this by closing every $k$-th ($2 \leq k \leq n - 1$) tab. Only then he will decide whether he wants to study for the test or to chat on the social networks. Formally, Roman will choose one tab (let its number be $b$) and then close all tabs with numbers $c = b + i \cdot k$ that satisfy the following condition: $1 \leq c \leq n$ and $i$ is an integer (it may be positive, negative or zero).
For example, if $k = 3$, $n = 14$ and Roman chooses $b = 8$, then he will close tabs with numbers $2$, $5$, $8$, $11$ and $14$.
After closing the tabs Roman will calculate the amount of remaining tabs with the information for the test (let's denote it $e$) and the amount of remaining social network tabs ($s$). Help Roman to calculate the maximal absolute value of the difference of those values $|e - s|$ so that it would be easy to decide what to do next.
-----Input-----
The first line contains two integers $n$ and $k$ ($2 \leq k < n \leq 100$) — the amount of tabs opened currently and the distance between the tabs closed.
The second line consists of $n$ integers, each of them equal either to $1$ or to $-1$. The $i$-th integer denotes the type of the $i$-th tab: if it is equal to $1$, this tab contains information for the test, and if it is equal to $-1$, it's a social network tab.
-----Output-----
Output a single integer — the maximum absolute difference between the amounts of remaining tabs of different types $|e - s|$.
-----Examples-----
Input
4 2
1 1 -1 1
Output
2
Input
14 3
-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1
Output
9
-----Note-----
In the first example we can choose $b = 1$ or $b = 3$. We will delete then one tab of each type and the remaining tabs are then all contain test information. Thus, $e = 2$ and $s = 0$ and $|e - s| = 2$.
In the second example, on the contrary, we can leave opened only tabs that have social networks opened in them.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, k = list(map(int, input().split()))
t = list(map(int, input().split()))
d = [0 for _ in range(n)]
for _ in range(n):
for i in range(n):
if i % k != _ % k:
d[_] += t[i]
print(max(abs(d[_]) for _ in range(n)))
``` | {
"language": "python",
"test_cases": [
{
"input": "4 2\n1 1 -1 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "14 3\n-1 1 -1 -1 1 -1 -1 1 -1 -1 1 -1 -1 1\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n1 1 1 -1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "4 2\n-1 1 -1 -1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n1 1 -1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "20 2\n-1 1 -1 1 -1 -1 -1 1 -1 -1 -1 1 -1 -1 1 -1 -1 -1 1 1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "20 19\n-1 -1 1 1 -1 1 1 -1 1 1 -1 1 -1 1 1 1 -1 1 -1 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "20 7\n-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": "100 17\n-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 1\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "20 12\n-1 1 1 1 1 1 1 -1 1 1 -1 1 -1 -1 -1 -1 1 1 1 -1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "20 17\n-1 1 -1 1 1 1 -1 -1 -1 -1 -1 -1 1 -1 1 1 1 -1 1 -1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "36 2\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\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "36 35\n-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": "6\n",
"type": "stdin_stdout"
},
{
"input": "36 7\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\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "36 12\n-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": "5\n",
"type": "stdin_stdout"
},
{
"input": "36 17\n-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": "6\n",
"type": "stdin_stdout"
},
{
"input": "36 22\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\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "36 27\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\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "36 32\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\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "52 2\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\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "52 51\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\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "52 7\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\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "52 12\n-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": "5\n",
"type": "stdin_stdout"
},
{
"input": "52 17\n-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": "11\n",
"type": "stdin_stdout"
},
{
"input": "52 22\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\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "52 27\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\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "52 32\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\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "52 37\n-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": "16\n",
"type": "stdin_stdout"
},
{
"input": "52 42\n-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": "10\n",
"type": "stdin_stdout"
},
{
"input": "52 47\n-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": "6\n",
"type": "stdin_stdout"
},
{
"input": "68 2\n-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": "10\n",
"type": "stdin_stdout"
},
{
"input": "68 67\n-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": "5\n",
"type": "stdin_stdout"
},
{
"input": "68 7\n-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": "14\n",
"type": "stdin_stdout"
},
{
"input": "68 12\n-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": "12\n",
"type": "stdin_stdout"
},
{
"input": "68 17\n-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": "4\n",
"type": "stdin_stdout"
},
{
"input": "68 22\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\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "68 27\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\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "68 32\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\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "68 37\n-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": "12\n",
"type": "stdin_stdout"
},
{
"input": "68 42\n-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": "18\n",
"type": "stdin_stdout"
},
{
"input": "68 47\n-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": "26\n",
"type": "stdin_stdout"
},
{
"input": "68 52\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\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "68 57\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\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "68 62\n-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": "5\n",
"type": "stdin_stdout"
},
{
"input": "84 2\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\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "84 83\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\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "84 7\n-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": "6\n",
"type": "stdin_stdout"
},
{
"input": "84 12\n-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": "11\n",
"type": "stdin_stdout"
},
{
"input": "84 17\n-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": "9\n",
"type": "stdin_stdout"
},
{
"input": "84 22\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\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "84 27\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\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "84 32\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\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "84 37\n-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": "7\n",
"type": "stdin_stdout"
},
{
"input": "84 42\n-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": "10\n",
"type": "stdin_stdout"
},
{
"input": "84 47\n-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": "4\n",
"type": "stdin_stdout"
},
{
"input": "84 52\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\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "84 57\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\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "84 62\n-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": "2\n",
"type": "stdin_stdout"
},
{
"input": "84 67\n-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": "4\n",
"type": "stdin_stdout"
},
{
"input": "84 72\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\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "84 77\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\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "84 82\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\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "100 2\n-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 -1\n",
"output": "14\n",
"type": "stdin_stdout"
},
{
"input": "100 99\n-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 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100 7\n-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 1\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "100 12\n-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 -1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "100 22\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": "18\n",
"type": "stdin_stdout"
},
{
"input": "100 27\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": "15\n",
"type": "stdin_stdout"
},
{
"input": "100 32\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": "7\n",
"type": "stdin_stdout"
},
{
"input": "100 37\n-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 -1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100 42\n-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 1\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "100 47\n-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 -1\n",
"output": "19\n",
"type": "stdin_stdout"
},
{
"input": "100 52\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": "10\n",
"type": "stdin_stdout"
},
{
"input": "100 57\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": "18\n",
"type": "stdin_stdout"
},
{
"input": "100 62\n-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 -1\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "100 67\n-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 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "100 72\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": "16\n",
"type": "stdin_stdout"
},
{
"input": "100 77\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": "12\n",
"type": "stdin_stdout"
},
{
"input": "100 82\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": "4\n",
"type": "stdin_stdout"
},
{
"input": "100 87\n-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 -1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "100 92\n-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 1\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "100 97\n-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 -1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n-1 1 -1 -1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 3\n1 1 -1 1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3 2\n1 1 1\n",
"output": "2\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1100/A"
} | vfc_10338 |
apps | verifiable_code | 147 | Solve the following coding problem using the programming language python:
R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met another robot for whom he was sure is the love of his life. Well, his summer, at least. Anyway, R3D3 was too shy to approach his potential soulmate, so he decided to write her a love letter. However, he stumbled upon a problem. Due to a terrorist threat, the Intergalactic Space Police was monitoring all letters sent in the area. Thus, R3D3 decided to invent his own alphabet, for which he was sure his love would be able to decipher.
There are n letters in R3D3’s alphabet, and he wants to represent each letter as a sequence of '0' and '1', so that no letter’s sequence is a prefix of another letter's sequence. Since the Intergalactic Space Communications Service has lately introduced a tax for invented alphabets, R3D3 must pay a certain amount of money for each bit in his alphabet’s code (check the sample test for clarifications). He is too lovestruck to think clearly, so he asked you for help.
Given the costs c_0 and c_1 for each '0' and '1' in R3D3’s alphabet, respectively, you should come up with a coding for the alphabet (with properties as above) with minimum total cost.
-----Input-----
The first line of input contains three integers n (2 ≤ n ≤ 10^8), c_0 and c_1 (0 ≤ c_0, c_1 ≤ 10^8) — the number of letters in the alphabet, and costs of '0' and '1', respectively.
-----Output-----
Output a single integer — minimum possible total a cost of the whole alphabet.
-----Example-----
Input
4 1 2
Output
12
-----Note-----
There are 4 letters in the alphabet. The optimal encoding is "00", "01", "10", "11". There are 4 zeroes and 4 ones used, so the total cost is 4·1 + 4·2 = 12.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n,a,b=map(int,input().split())
if a<b: a,b=b,a
if b==0:
# 1 01 001 0001 ... is optimal, plus a long series of 0's
print((n-1)*a)
else:
# pascal's triangle thing
pascal=[[1]*20005]
for i in range(20004):
newrow=[1]
for j in range(1,20005):
newrow.append(newrow[-1]+pascal[-1][j])
if newrow[-1]>n: break
pascal.append(newrow)
def getcom(a,b):
# return a+b choose b
# if larger than n, return infinite
if len(pascal[a])>b: return pascal[a][b]
if b==0: return 1
if b==1: return a
return 100000005
# start with the null node (prefix cost 0)
# can split a node into two other nodes with added cost c+a+b
# new nodes have prefix costs c+a, c+b
# want n-1 splits in total
n-=1 # now represents number of splits needed
# binary search the last cost added
lo=0
hi=a*int((n**0.5)*2+5)
while 1:
mid=(lo+hi)//2
# count stuff
c0=0 # < mid
c1=0 # = mid
for i in range(mid//a+1):
j=(mid-i*a)//b
if (mid-i*a)%b!=0:
# c0 += iC0 + (i+1)C1 + (i+2)C2 + ... + (i+j)Cj
for k in range(j+1):
#print(mid,i,k)
c0+=getcom(i,k)
if c0>n: break
else:
for k in range(j):
#print(mid,i,k)
c0+=getcom(i,k)
if c0>n: break
#print(mid,i,j,"c1")
c1+=getcom(i,j)
#print(mid,"is",c0,c1)
if n<c0:
hi=mid-1
elif c0+c1<n:
lo=mid+1
else:
# mid is correct cutoff
lowcost=0 # sum of all cost, where cost < mid
for i in range(mid//a+1):
j=(mid-i*a)//b
if (mid-i*a)%b!=0:
for k in range(j+1):
lowcost+=getcom(i,k)*(i*a+k*b)
else:
for k in range(j):
lowcost+=getcom(i,k)*(i*a+k*b)
temp=lowcost+(n-c0)*mid
print(temp+n*(a+b))
break
``` | {
"language": "python",
"test_cases": [
{
"input": "4 1 2\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "2 1 5\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "3 1 1\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "5 5 5\n",
"output": "60\n",
"type": "stdin_stdout"
},
{
"input": "4 0 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6 0 6\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "6 6 0\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "2 1 2\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "100000000 1 0\n",
"output": "99999999\n",
"type": "stdin_stdout"
},
{
"input": "2 0 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 100000000 100000000\n",
"output": "200000000\n",
"type": "stdin_stdout"
},
{
"input": "2 100000000 0\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "2 0 100000000\n",
"output": "100000000\n",
"type": "stdin_stdout"
},
{
"input": "100000000 0 0\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100000000 100000000 100000000\n",
"output": "266578227200000000\n",
"type": "stdin_stdout"
},
{
"input": "100000000 100000000 0\n",
"output": "9999999900000000\n",
"type": "stdin_stdout"
},
{
"input": "100000000 0 100000000\n",
"output": "9999999900000000\n",
"type": "stdin_stdout"
},
{
"input": "2 50000000 0\n",
"output": "50000000\n",
"type": "stdin_stdout"
},
{
"input": "2 50000000 100000000\n",
"output": "150000000\n",
"type": "stdin_stdout"
},
{
"input": "2 50000000 0\n",
"output": "50000000\n",
"type": "stdin_stdout"
},
{
"input": "2 50000000 100000000\n",
"output": "150000000\n",
"type": "stdin_stdout"
},
{
"input": "100000000 50000000 0\n",
"output": "4999999950000000\n",
"type": "stdin_stdout"
},
{
"input": "100000000 50000000 100000000\n",
"output": "191720992950000000\n",
"type": "stdin_stdout"
},
{
"input": "100000000 50000000 0\n",
"output": "4999999950000000\n",
"type": "stdin_stdout"
},
{
"input": "100000000 50000000 100000000\n",
"output": "191720992950000000\n",
"type": "stdin_stdout"
},
{
"input": "96212915 66569231 66289469\n",
"output": "170023209909758400\n",
"type": "stdin_stdout"
},
{
"input": "39969092 91869601 91924349\n",
"output": "93003696194821620\n",
"type": "stdin_stdout"
},
{
"input": "26854436 29462638 67336233\n",
"output": "30373819153055635\n",
"type": "stdin_stdout"
},
{
"input": "39201451 80233602 30662934\n",
"output": "50953283386656312\n",
"type": "stdin_stdout"
},
{
"input": "92820995 96034432 40568102\n",
"output": "158135215198065044\n",
"type": "stdin_stdout"
},
{
"input": "81913246 61174868 31286889\n",
"output": "96084588586645841\n",
"type": "stdin_stdout"
},
{
"input": "74790405 66932852 48171076\n",
"output": "111690840882243696\n",
"type": "stdin_stdout"
},
{
"input": "88265295 26984472 18821097\n",
"output": "52835608063500861\n",
"type": "stdin_stdout"
},
{
"input": "39858798 77741429 44017779\n",
"output": "59709461677488470\n",
"type": "stdin_stdout"
},
{
"input": "70931513 41663344 29095671\n",
"output": "64816798089350400\n",
"type": "stdin_stdout"
},
{
"input": "68251617 52232534 34187120\n",
"output": "75694251898945158\n",
"type": "stdin_stdout"
},
{
"input": "44440915 82093126 57268128\n",
"output": "77907273273831800\n",
"type": "stdin_stdout"
},
{
"input": "61988457 90532323 72913492\n",
"output": "130757350538583270\n",
"type": "stdin_stdout"
},
{
"input": "13756397 41019327 86510346\n",
"output": "19895886795999000\n",
"type": "stdin_stdout"
},
{
"input": "84963589 37799442 20818727\n",
"output": "63754887412974663\n",
"type": "stdin_stdout"
},
{
"input": "99338896 62289589 49020203\n",
"output": "146320678028775569\n",
"type": "stdin_stdout"
},
{
"input": "1505663 3257962 1039115\n",
"output": "60023256524142\n",
"type": "stdin_stdout"
},
{
"input": "80587587 25402325 8120971\n",
"output": "32044560697691212\n",
"type": "stdin_stdout"
},
{
"input": "64302230 83635846 22670768\n",
"output": "77790985833197594\n",
"type": "stdin_stdout"
},
{
"input": "6508457 32226669 8706339\n",
"output": "2645634460061466\n",
"type": "stdin_stdout"
},
{
"input": "1389928 84918086 54850899\n",
"output": "1953921305304795\n",
"type": "stdin_stdout"
},
{
"input": "37142108 10188690 35774598\n",
"output": "19009588918065432\n",
"type": "stdin_stdout"
},
{
"input": "86813943 11824369 38451380\n",
"output": "51645349299460766\n",
"type": "stdin_stdout"
},
{
"input": "14913475 61391038 9257618\n",
"output": "9761450207212562\n",
"type": "stdin_stdout"
},
{
"input": "25721978 63666459 14214946\n",
"output": "20847031763747988\n",
"type": "stdin_stdout"
},
{
"input": "73363656 63565575 76409698\n",
"output": "133919836504944416\n",
"type": "stdin_stdout"
},
{
"input": "34291060 92893503 64680754\n",
"output": "66960630525688676\n",
"type": "stdin_stdout"
},
{
"input": "85779772 26434899 86820336\n",
"output": "114681463889615136\n",
"type": "stdin_stdout"
},
{
"input": "7347370 2098650 66077918\n",
"output": "3070602135161752\n",
"type": "stdin_stdout"
},
{
"input": "28258585 6194848 49146833\n",
"output": "14441957862691571\n",
"type": "stdin_stdout"
},
{
"input": "9678 133 5955\n",
"output": "196970292\n",
"type": "stdin_stdout"
},
{
"input": "9251 4756 2763\n",
"output": "448302621\n",
"type": "stdin_stdout"
},
{
"input": "1736 5628 2595\n",
"output": "73441521\n",
"type": "stdin_stdout"
},
{
"input": "5195 1354 2885\n",
"output": "130236572\n",
"type": "stdin_stdout"
},
{
"input": "1312 5090 9909\n",
"output": "98808420\n",
"type": "stdin_stdout"
},
{
"input": "8619 6736 9365\n",
"output": "900966230\n",
"type": "stdin_stdout"
},
{
"input": "151 7023 3093\n",
"output": "5267919\n",
"type": "stdin_stdout"
},
{
"input": "5992 2773 6869\n",
"output": "340564941\n",
"type": "stdin_stdout"
},
{
"input": "3894 9921 3871\n",
"output": "299508763\n",
"type": "stdin_stdout"
},
{
"input": "1006 9237 1123\n",
"output": "38974261\n",
"type": "stdin_stdout"
},
{
"input": "9708 3254 2830\n",
"output": "391502526\n",
"type": "stdin_stdout"
},
{
"input": "1504 1123 626\n",
"output": "13538132\n",
"type": "stdin_stdout"
},
{
"input": "8642 5709 51\n",
"output": "135655830\n",
"type": "stdin_stdout"
},
{
"input": "8954 4025 7157\n",
"output": "641304164\n",
"type": "stdin_stdout"
},
{
"input": "4730 8020 8722\n",
"output": "484587068\n",
"type": "stdin_stdout"
},
{
"input": "2500 5736 4002\n",
"output": "136264140\n",
"type": "stdin_stdout"
},
{
"input": "6699 4249 1068\n",
"output": "196812772\n",
"type": "stdin_stdout"
},
{
"input": "4755 6759 4899\n",
"output": "336456318\n",
"type": "stdin_stdout"
},
{
"input": "8447 1494 4432\n",
"output": "298387478\n",
"type": "stdin_stdout"
},
{
"input": "6995 4636 8251\n",
"output": "561476311\n",
"type": "stdin_stdout"
},
{
"input": "4295 9730 4322\n",
"output": "346320888\n",
"type": "stdin_stdout"
},
{
"input": "8584 4286 9528\n",
"output": "738058224\n",
"type": "stdin_stdout"
},
{
"input": "174 6826 355\n",
"output": "2889605\n",
"type": "stdin_stdout"
},
{
"input": "5656 7968 3400\n",
"output": "379249528\n",
"type": "stdin_stdout"
},
{
"input": "2793 175 3594\n",
"output": "36405762\n",
"type": "stdin_stdout"
},
{
"input": "2888 9056 3931\n",
"output": "204521173\n",
"type": "stdin_stdout"
},
{
"input": "6222 7124 6784\n",
"output": "547839384\n",
"type": "stdin_stdout"
},
{
"input": "8415 8714 2475\n",
"output": "545452719\n",
"type": "stdin_stdout"
},
{
"input": "2179 7307 8608\n",
"output": "192281235\n",
"type": "stdin_stdout"
},
{
"input": "1189 1829 6875\n",
"output": "46521099\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/717/B"
} | vfc_10342 |
apps | verifiable_code | 148 | Solve the following coding problem using the programming language python:
The circle line of the Roflanpolis subway has $n$ stations.
There are two parallel routes in the subway. The first one visits stations in order $1 \to 2 \to \ldots \to n \to 1 \to 2 \to \ldots$ (so the next stop after station $x$ is equal to $(x+1)$ if $x < n$ and $1$ otherwise). The second route visits stations in order $n \to (n-1) \to \ldots \to 1 \to n \to (n-1) \to \ldots$ (so the next stop after station $x$ is equal to $(x-1)$ if $x>1$ and $n$ otherwise). All trains depart their stations simultaneously, and it takes exactly $1$ minute to arrive at the next station.
Two toads live in this city, their names are Daniel and Vlad.
Daniel is currently in a train of the first route at station $a$ and will exit the subway when his train reaches station $x$.
Coincidentally, Vlad is currently in a train of the second route at station $b$ and he will exit the subway when his train reaches station $y$.
Surprisingly, all numbers $a,x,b,y$ are distinct.
Toad Ilya asks you to check if Daniel and Vlad will ever be at the same station at the same time during their journey. In other words, check if there is a moment when their trains stop at the same station. Note that this includes the moments when Daniel or Vlad enter or leave the subway.
-----Input-----
The first line contains five space-separated integers $n$, $a$, $x$, $b$, $y$ ($4 \leq n \leq 100$, $1 \leq a, x, b, y \leq n$, all numbers among $a$, $x$, $b$, $y$ are distinct) — the number of stations in Roflanpolis, Daniel's start station, Daniel's finish station, Vlad's start station and Vlad's finish station, respectively.
-----Output-----
Output "YES" if there is a time moment when Vlad and Daniel are at the same station, and "NO" otherwise. You can print each letter in any case (upper or lower).
-----Examples-----
Input
5 1 4 3 2
Output
YES
Input
10 2 1 9 10
Output
NO
-----Note-----
In the first example, Daniel and Vlad start at the stations $(1, 3)$. One minute later they are at stations $(2, 2)$. They are at the same station at this moment. Note that Vlad leaves the subway right after that.
Consider the second example, let's look at the stations Vlad and Daniel are at. They are: initially $(2, 9)$, after $1$ minute $(3, 8)$, after $2$ minutes $(4, 7)$, after $3$ minutes $(5, 6)$, after $4$ minutes $(6, 5)$, after $5$ minutes $(7, 4)$, after $6$ minutes $(8, 3)$, after $7$ minutes $(9, 2)$, after $8$ minutes $(10, 1)$, after $9$ minutes $(1, 10)$.
After that, they both leave the subway because they are at their finish stations, so there is no moment when they both are at the same station.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, a, x, b, y = map(int, input().split())
while a != x and b != y and a != b:
if a == b:
break
a = a % n + 1
b = b - 1 if b - 1 else n
print("YNEOS"[a != b::2])
``` | {
"language": "python",
"test_cases": [
{
"input": "5 1 4 3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 2 1 9 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 3 4 2 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "100 2 97 84 89\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 43 55 42 15\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "47 15 45 28 38\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "17 14 2 12 10\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "82 9 11 15 79\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "53 10 34 1 48\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "55 55 27 45 50\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "33 15 6 1 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "45 26 22 39 10\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 3 2 4 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "20 19 10 17 8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 26 63 60 23\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 2 5 6 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "50 22 39 33 9\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "50 40 10 4 34\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 3 1 2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 1 2 3 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 1 2 4 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 1 3 2 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 1 3 4 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 1 4 2 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 1 4 3 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 2 1 3 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 2 1 4 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 2 3 1 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 2 3 4 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 2 4 1 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 2 4 3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 3 1 2 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 3 1 4 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 3 2 1 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 3 2 4 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 3 4 1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 4 1 2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "4 4 1 3 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 4 2 1 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 4 2 3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 4 3 1 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "4 4 3 2 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 9 10 3 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "60 1 50 51 49\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 1 4 3 9\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "9 7 2 6 8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 4 2 1 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 4 2 1 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 3 1 2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 4 3 6 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 10 9 6 7\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 1 3 2 5\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 5 4 1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 5 10 3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7 5 3 2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 4 1 2 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 2 1 4 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 1 6 5 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "13 1 9 2 13\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 1 4 5 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 3 1 5 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "43 41 39 40 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 7 2 3 5\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 2 5 8 4\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "8 1 4 5 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "100 1 5 20 2\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 5 6 3 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "10 9 10 5 8\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 5 6 3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "7 7 1 2 6\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 2 4 7 3\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "6 3 2 5 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "6 5 2 3 1\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "91 36 25 5 91\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "90 1 2 5 4\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 4 5 3 1\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "5 5 4 1 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 5 3 1 2\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 5 1 2 3\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "24 14 23 18 21\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "10 9 10 1 8\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "20 19 2 1 20\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "7 1 5 4 7\n",
"output": "NO\n",
"type": "stdin_stdout"
},
{
"input": "20 19 2 1 18\n",
"output": "YES\n",
"type": "stdin_stdout"
},
{
"input": "5 5 1 2 4\n",
"output": "YES\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1169/A"
} | vfc_10346 |
apps | verifiable_code | 149 | Solve the following coding problem using the programming language python:
Unlucky year in Berland is such a year that its number n can be represented as n = x^{a} + y^{b}, where a and b are non-negative integer numbers.
For example, if x = 2 and y = 3 then the years 4 and 17 are unlucky (4 = 2^0 + 3^1, 17 = 2^3 + 3^2 = 2^4 + 3^0) and year 18 isn't unlucky as there is no such representation for it.
Such interval of years that there are no unlucky years in it is called The Golden Age.
You should write a program which will find maximum length of The Golden Age which starts no earlier than the year l and ends no later than the year r. If all years in the interval [l, r] are unlucky then the answer is 0.
-----Input-----
The first line contains four integer numbers x, y, l and r (2 ≤ x, y ≤ 10^18, 1 ≤ l ≤ r ≤ 10^18).
-----Output-----
Print the maximum length of The Golden Age within the interval [l, r].
If all years in the interval [l, r] are unlucky then print 0.
-----Examples-----
Input
2 3 1 10
Output
1
Input
3 5 10 22
Output
8
Input
2 3 3 5
Output
0
-----Note-----
In the first example the unlucky years are 2, 3, 4, 5, 7, 9 and 10. So maximum length of The Golden Age is achived in the intervals [1, 1], [6, 6] and [8, 8].
In the second example the longest Golden Age is the interval [15, 22].
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
x,y,l,r=list(map(int,input().split()))
b=set()
a=0
b.add(l-1)
b.add(r+1)
for i in range(100):
xx=x**i
if xx>r: break
for j in range(100):
rr=xx+(y**j)
if rr>r: break
if rr>=l:
b.add(rr)
b=sorted(list(b))
for i in range(1,len(b)):
a=max(a,b[i]-b[i-1]-1)
print(a)
``` | {
"language": "python",
"test_cases": [
{
"input": "2 3 1 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 5 10 22\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "2 3 3 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1 10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1 1000000\n",
"output": "213568\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1 1000000000000000000\n",
"output": "144115188075855871\n",
"type": "stdin_stdout"
},
{
"input": "2 3 1 1000000\n",
"output": "206415\n",
"type": "stdin_stdout"
},
{
"input": "2 3 1 1000000000000000000\n",
"output": "261485717957290893\n",
"type": "stdin_stdout"
},
{
"input": "12345 54321 1 1000000\n",
"output": "933334\n",
"type": "stdin_stdout"
},
{
"input": "54321 12345 1 1000000000000000000\n",
"output": "976614248345331214\n",
"type": "stdin_stdout"
},
{
"input": "2 3 100000000 1000000000000\n",
"output": "188286357653\n",
"type": "stdin_stdout"
},
{
"input": "2 14 732028847861235712 732028847861235712\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "14 2 732028847861235713 732028847861235713\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 2 6 7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "16 5 821690667 821691481\n",
"output": "815\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 2 1 1000000000000000000\n",
"output": "423539247696576511\n",
"type": "stdin_stdout"
},
{
"input": "2 1000000000000000000 1000000000000000 1000000000000000000\n",
"output": "423539247696576511\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1000000000000000000 1000000000000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3 3 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 3 626492297402423196 726555387600422608\n",
"output": "100063090197999413\n",
"type": "stdin_stdout"
},
{
"input": "4 4 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "304279187938024110 126610724244348052 78460471576735729 451077737144268785\n",
"output": "177668463693676057\n",
"type": "stdin_stdout"
},
{
"input": "510000000000 510000000000 1 1000000000000000000\n",
"output": "999998980000000000\n",
"type": "stdin_stdout"
},
{
"input": "2 10000000000000000 1 1000000000000000000\n",
"output": "413539247696576512\n",
"type": "stdin_stdout"
},
{
"input": "84826654960259 220116531311479700 375314289098080160 890689132792406667\n",
"output": "515374843694326508\n",
"type": "stdin_stdout"
},
{
"input": "1001 9999 1 1000000000000000000\n",
"output": "988998989390034998\n",
"type": "stdin_stdout"
},
{
"input": "106561009498593483 3066011339919949 752858505287719337 958026822891358781\n",
"output": "205168317603639445\n",
"type": "stdin_stdout"
},
{
"input": "650233444262690661 556292951587380938 715689923804218376 898772439356652923\n",
"output": "183082515552434548\n",
"type": "stdin_stdout"
},
{
"input": "4294967297 4294967297 1 1000000000000000000\n",
"output": "999999991410065406\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000000000000 1000000000000000000 1000000000000000000\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 2 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "73429332516742239 589598864615747534 555287238606698050 981268715519611449\n",
"output": "318240518387121676\n",
"type": "stdin_stdout"
},
{
"input": "282060925969693883 446418005951342865 709861829378794811 826972744183396568\n",
"output": "98493812262359820\n",
"type": "stdin_stdout"
},
{
"input": "97958277744315833 443452631396066615 33878596673318768 306383421710156519\n",
"output": "208425143965840685\n",
"type": "stdin_stdout"
},
{
"input": "40975442958818854 7397733549114401 299774870238987084 658001214206968260\n",
"output": "358226343967981177\n",
"type": "stdin_stdout"
},
{
"input": "699 700 1 1000\n",
"output": "697\n",
"type": "stdin_stdout"
},
{
"input": "483076744475822225 425097332543006422 404961220953110704 826152774360856248\n",
"output": "343076029885034022\n",
"type": "stdin_stdout"
},
{
"input": "4294967297 4294967297 1 999999999999999999\n",
"output": "999999991410065405\n",
"type": "stdin_stdout"
},
{
"input": "702012794 124925148 2623100012 1000000000000000000\n",
"output": "491571744457491660\n",
"type": "stdin_stdout"
},
{
"input": "433333986179614514 1000000000000000000 433333986179614515 726628630292055493\n",
"output": "293294644112440978\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999 364973116927770629 4 4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 2 40 812\n",
"output": "191\n",
"type": "stdin_stdout"
},
{
"input": "2 3 1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1556368728 1110129598 120230736 1258235681\n",
"output": "989898863\n",
"type": "stdin_stdout"
},
{
"input": "7 9 164249007852879073 459223650245359577\n",
"output": "229336748650748455\n",
"type": "stdin_stdout"
},
{
"input": "324693328712373699 541961409169732375 513851377473048715 873677521504257312\n",
"output": "324693328712373697\n",
"type": "stdin_stdout"
},
{
"input": "370083000139673112 230227213530985315 476750241623737312 746365058930029530\n",
"output": "146054845259371103\n",
"type": "stdin_stdout"
},
{
"input": "4 3 584 899\n",
"output": "146\n",
"type": "stdin_stdout"
},
{
"input": "4 3 286 581\n",
"output": "161\n",
"type": "stdin_stdout"
},
{
"input": "304045744870965151 464630021384225732 142628934177558000 844155070300317027\n",
"output": "304045744870965149\n",
"type": "stdin_stdout"
},
{
"input": "195627622825327857 666148746663834172 1 1000000000000000000\n",
"output": "470521123838506314\n",
"type": "stdin_stdout"
},
{
"input": "459168731438725410 459955118458373596 410157890472128901 669197645706452507\n",
"output": "209242527248078910\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999 999999999999999999 1 1000000000000000000\n",
"output": "999999999999999997\n",
"type": "stdin_stdout"
},
{
"input": "752299248283963354 680566564599126819 73681814274367577 960486443362068685\n",
"output": "606884750324759243\n",
"type": "stdin_stdout"
},
{
"input": "20373217421623606 233158243228114207 97091516440255589 395722640217125926\n",
"output": "142191179567388113\n",
"type": "stdin_stdout"
},
{
"input": "203004070900 20036005000 1 1000000000000000000\n",
"output": "999999776959924100\n",
"type": "stdin_stdout"
},
{
"input": "565269817339236857 318270460838647700 914534538271870694 956123707310168659\n",
"output": "41589169038297966\n",
"type": "stdin_stdout"
},
{
"input": "2 5 330 669\n",
"output": "131\n",
"type": "stdin_stdout"
},
{
"input": "9 9 91 547\n",
"output": "385\n",
"type": "stdin_stdout"
},
{
"input": "9 4 866389615074294253 992899492208527253\n",
"output": "126509877134233001\n",
"type": "stdin_stdout"
},
{
"input": "3037000500 3037000500 1 1000000000000000000\n",
"output": "999999993925999000\n",
"type": "stdin_stdout"
},
{
"input": "4294967297 4294967297 12 1000000000000000000\n",
"output": "999999991410065406\n",
"type": "stdin_stdout"
},
{
"input": "5 3 78510497842978003 917156799600023483\n",
"output": "238418579101562499\n",
"type": "stdin_stdout"
},
{
"input": "749206377024033575 287723056504284448 387669391392789697 931234393488075794\n",
"output": "361536985631243879\n",
"type": "stdin_stdout"
},
{
"input": "999999999999999999 454135 1000000000000000000 1000000000000000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "759826429841877401 105086867783910112 667080043736858072 797465019478234768\n",
"output": "92746386105019330\n",
"type": "stdin_stdout"
},
{
"input": "1000000000000000000 1000000000000000000 5 7\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "440968000218771383 43378854522801881 169393324037146024 995429539593716237\n",
"output": "511082684852142973\n",
"type": "stdin_stdout"
},
{
"input": "15049917793417622 113425474361704411 87565655389309185 803955352361026671\n",
"output": "675479960205904638\n",
"type": "stdin_stdout"
},
{
"input": "4 6 264626841724745187 925995096479842591\n",
"output": "369878143059623936\n",
"type": "stdin_stdout"
},
{
"input": "4294967297 4294967297 13 1000000000000000000\n",
"output": "999999991410065406\n",
"type": "stdin_stdout"
},
{
"input": "315729630349763416 22614591055604717 66895291338255006 947444311481017774\n",
"output": "609100090075649641\n",
"type": "stdin_stdout"
},
{
"input": "3 10 173 739\n",
"output": "386\n",
"type": "stdin_stdout"
},
{
"input": "161309010783040325 128259041753158864 5843045875031294 854024306926137845\n",
"output": "564456254389938656\n",
"type": "stdin_stdout"
},
{
"input": "239838434825939759 805278168279318096 202337849919104640 672893754916863788\n",
"output": "433055320090924028\n",
"type": "stdin_stdout"
},
{
"input": "9 9 435779695685310822 697902619874412541\n",
"output": "262122924189101720\n",
"type": "stdin_stdout"
},
{
"input": "967302429573451368 723751675006196376 143219686319239751 266477897142546404\n",
"output": "123258210823306654\n",
"type": "stdin_stdout"
},
{
"input": "10 8 139979660652061677 941135332855173888\n",
"output": "697020144779318016\n",
"type": "stdin_stdout"
},
{
"input": "4294967297 1000000000000000000 4294967296 17179869184\n",
"output": "12884901886\n",
"type": "stdin_stdout"
},
{
"input": "100914030314340517 512922595840756536 812829791042966971 966156272123068006\n",
"output": "153326481080101036\n",
"type": "stdin_stdout"
},
{
"input": "288230376151711744 288230376151711744 1 1000000000000000000\n",
"output": "423539247696576512\n",
"type": "stdin_stdout"
},
{
"input": "6 9 681 750\n",
"output": "49\n",
"type": "stdin_stdout"
},
{
"input": "880356874212472951 178538501711453307 162918237570625233 224969951233811739\n",
"output": "46431449522358431\n",
"type": "stdin_stdout"
},
{
"input": "2 7 405373082004080437 771991379629433514\n",
"output": "153172782079203571\n",
"type": "stdin_stdout"
},
{
"input": "10 11 10 11\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/813/B"
} | vfc_10350 |
apps | verifiable_code | 150 | Solve the following coding problem using the programming language python:
Mr. Funt now lives in a country with a very specific tax laws. The total income of mr. Funt during this year is equal to n (n ≥ 2) burles and the amount of tax he has to pay is calculated as the maximum divisor of n (not equal to n, of course). For example, if n = 6 then Funt has to pay 3 burles, while for n = 25 he needs to pay 5 and if n = 2 he pays only 1 burle.
As mr. Funt is a very opportunistic person he wants to cheat a bit. In particular, he wants to split the initial n in several parts n_1 + n_2 + ... + n_{k} = n (here k is arbitrary, even k = 1 is allowed) and pay the taxes for each part separately. He can't make some part equal to 1 because it will reveal him. So, the condition n_{i} ≥ 2 should hold for all i from 1 to k.
Ostap Bender wonders, how many money Funt has to pay (i.e. minimal) if he chooses and optimal way to split n in parts.
-----Input-----
The first line of the input contains a single integer n (2 ≤ n ≤ 2·10^9) — the total year income of mr. Funt.
-----Output-----
Print one integer — minimum possible number of burles that mr. Funt has to pay as a tax.
-----Examples-----
Input
4
Output
2
Input
27
Output
3
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
def is_izi(k):
i = 2
while (i * i <= k):
if (k % i == 0):
return 0
i += 1
return 1
n = int(input())
if (is_izi(n)):
print(1)
elif n % 2 == 0:
print(2)
elif n % 2 == 1:
if (is_izi(n - 2)):
print(2)
else:
print(3)
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "27\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2000000000\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "26\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000007\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1000000009\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1999999999\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1000000011\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "101\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "103\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1001\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1003\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10001\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "10003\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "129401294\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "234911024\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "192483501\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1234567890\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "719241201\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "33\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "25\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "15\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "147\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "60119912\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "45\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "9975\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "17\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "99\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "49\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "243\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "43\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "39\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "12\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "13\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "14\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "16\n",
"output": "2\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": "2\n",
"type": "stdin_stdout"
},
{
"input": "22\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "23\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "24\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "962\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "29\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "55\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "125\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1999999929\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "493\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10000021\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "541\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "187\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "95\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "999991817\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "37998938\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1847133842\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1000000005\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "19828\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "998321704\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "370359\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "115\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "200000015\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "479001600\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "536870912\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "10759922\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1999999927\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "123\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "200743933\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "949575615\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "99990001\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "715827883\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5592406\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "8388609\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1908903481\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "1076153021\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "344472101\n",
"output": "3\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/735/D"
} | vfc_10354 |
apps | verifiable_code | 151 | Solve the following coding problem using the programming language python:
Beroffice text editor has a wide range of features that help working with text. One of the features is an automatic search for typos and suggestions of how to fix them.
Beroffice works only with small English letters (i.e. with 26 letters from a to z). Beroffice thinks that a word is typed with a typo if there are three or more consonants in a row in the word. The only exception is that if the block of consonants has all letters the same, then this block (even if its length is greater than three) is not considered a typo. Formally, a word is typed with a typo if there is a block of not less that three consonants in a row, and there are at least two different letters in this block.
For example:
the following words have typos: "hellno", "hackcerrs" and "backtothefutttture"; the following words don't have typos: "helllllooooo", "tobeornottobe" and "oooooo".
When Beroffice editor finds a word with a typo, it inserts as little as possible number of spaces in this word (dividing it into several words) in such a way that each of the resulting words is typed without any typos.
Implement this feature of Beroffice editor. Consider the following letters as the only vowels: 'a', 'e', 'i', 'o' and 'u'. All the other letters are consonants in this problem.
-----Input-----
The only line contains a non-empty word consisting of small English letters. The length of the word is between 1 and 3000 letters.
-----Output-----
Print the given word without any changes if there are no typos.
If there is at least one typo in the word, insert the minimum number of spaces into the word so that each of the resulting words doesn't have any typos. If there are multiple solutions, print any of them.
-----Examples-----
Input
hellno
Output
hell no
Input
abacaba
Output
abacaba
Input
asdfasdf
Output
asd fasd f
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
s = input()
st = {'a', 'e', 'i', 'o', 'u', ' '}
res = ""
def check(s):
if (len(s) < 3):
return True
if (s[-1] not in st and s[-2] not in st and s[-3] not in st) and (s[-1] != s[-2] or s[-2] != s[-3] or s[-1] != s[-3]):
return False
return True
for item in s:
if not check(res + item):
res += " "
res += item
print(res)
``` | {
"language": "python",
"test_cases": [
{
"input": "hellno\n",
"output": "hell no \n",
"type": "stdin_stdout"
},
{
"input": "abacaba\n",
"output": "abacaba \n",
"type": "stdin_stdout"
},
{
"input": "asdfasdf\n",
"output": "asd fasd f \n",
"type": "stdin_stdout"
},
{
"input": "ooo\n",
"output": "ooo \n",
"type": "stdin_stdout"
},
{
"input": "moyaoborona\n",
"output": "moyaoborona \n",
"type": "stdin_stdout"
},
{
"input": "jxegxxx\n",
"output": "jxegx xx \n",
"type": "stdin_stdout"
},
{
"input": "orfyaenanabckumulsboloyhljhacdgcmnooxvxrtuhcslxgslfpnfnyejbxqisxjyoyvcvuddboxkqgbogkfz\n",
"output": "orf yaenanabc kumuls boloyh lj hacd gc mnooxv xr tuhc sl xg sl fp nf nyejb xqisx jyoyv cvudd boxk qg bogk fz \n",
"type": "stdin_stdout"
},
{
"input": "zxdgmhsjotvajkwshjpvzcuwehpeyfhakhtlvuoftkgdmvpafmxcliqvrztloocziqdkexhzcbdgxaoyvte\n",
"output": "zx dg mh sjotvajk ws hj pv zcuwehpeyf hakh tl vuoft kg dm vpafm xc liqv rz tloocziqd kexh zc bd gxaoyv te \n",
"type": "stdin_stdout"
},
{
"input": "niblehmwtycadhbfuginpyafszjbucaszihijndzjtuyuaxkrovotshtsajmdcflnfdmahzbvpymiczqqleedpofcnvhieknlz\n",
"output": "niblehm wt ycadh bfuginp yafs zj bucaszihijn dz jtuyuaxk rovots ht sajm dc fl nf dmahz bv py micz qq leedpofc nv hiekn lz \n",
"type": "stdin_stdout"
},
{
"input": "pqvtgtctpkgjgxnposjqedofficoyznxlerxyqypyzpoehejtjvyafjxjppywwgeakf\n",
"output": "pq vt gt ct pk gj gx nposj qedofficoyz nx lerx yq yp yz poehejt jv yafj xj pp yw wgeakf \n",
"type": "stdin_stdout"
},
{
"input": "mvjajoyeg\n",
"output": "mv jajoyeg \n",
"type": "stdin_stdout"
},
{
"input": "dipxocwjosvdaillxolmthjhzhsxskzqslebpixpuhpgeesrkedhohisdsjsrkiktbjzlhectrfcathvewzficirqbdvzq\n",
"output": "dipxocw josv daill xolm th jh zh sx sk zq slebpixpuhp geesr kedhohisd sj sr kikt bj zl hect rf cath vewz ficirq bd vz q \n",
"type": "stdin_stdout"
},
{
"input": "ibbtvelwjirxqermucqrgmoauonisgmarjxxybllktccdykvef\n",
"output": "ibb tvelw jirx qermucq rg moauonisg marj xx yb ll kt cc dy kvef \n",
"type": "stdin_stdout"
},
{
"input": "jxevkmrwlomaaahaubvjzqtyfqhqbhpqhomxqpiuersltohinvfyeykmlooujymldjqhgqjkvqknlyj\n",
"output": "jxevk mr wlomaaahaubv jz qt yf qh qb hp qhomx qpiuers ltohinv fyeyk mlooujy ml dj qh gq jk vq kn ly j \n",
"type": "stdin_stdout"
},
{
"input": "hzxkuwqxonsulnndlhygvmallghjerwp\n",
"output": "hz xkuwq xonsuln nd lh yg vmall gh jerw p \n",
"type": "stdin_stdout"
},
{
"input": "jbvcsjdyzlzmxwcvmixunfzxidzvwzaqqdhguvelwbdosbd\n",
"output": "jb vc sj dy zl zm xw cv mixunf zxidz vw zaqq dh guvelw bdosb d \n",
"type": "stdin_stdout"
},
{
"input": "uyrsxaqmtibbxpfabprvnvbinjoxubupvfyjlqnfrfdeptipketwghr\n",
"output": "uyr sxaqm tibb xp fabp rv nv binjoxubupv fy jl qn fr fdeptipketw gh r \n",
"type": "stdin_stdout"
},
{
"input": "xfcftysljytybkkzkpqdzralahgvbkxdtheqrhfxpecdjqofnyiahggnkiuusalu\n",
"output": "xf cf ty sl jy ty bk kz kp qd zralahg vb kx dt heqr hf xpecd jqofn yiahg gn kiuusalu \n",
"type": "stdin_stdout"
},
{
"input": "a\n",
"output": "a \n",
"type": "stdin_stdout"
},
{
"input": "b\n",
"output": "b \n",
"type": "stdin_stdout"
},
{
"input": "aa\n",
"output": "aa \n",
"type": "stdin_stdout"
},
{
"input": "ab\n",
"output": "ab \n",
"type": "stdin_stdout"
},
{
"input": "ba\n",
"output": "ba \n",
"type": "stdin_stdout"
},
{
"input": "bb\n",
"output": "bb \n",
"type": "stdin_stdout"
},
{
"input": "aaa\n",
"output": "aaa \n",
"type": "stdin_stdout"
},
{
"input": "aab\n",
"output": "aab \n",
"type": "stdin_stdout"
},
{
"input": "aba\n",
"output": "aba \n",
"type": "stdin_stdout"
},
{
"input": "abb\n",
"output": "abb \n",
"type": "stdin_stdout"
},
{
"input": "baa\n",
"output": "baa \n",
"type": "stdin_stdout"
},
{
"input": "bab\n",
"output": "bab \n",
"type": "stdin_stdout"
},
{
"input": "bba\n",
"output": "bba \n",
"type": "stdin_stdout"
},
{
"input": "bbb\n",
"output": "bbb \n",
"type": "stdin_stdout"
},
{
"input": "bbc\n",
"output": "bb c \n",
"type": "stdin_stdout"
},
{
"input": "bcb\n",
"output": "bc b \n",
"type": "stdin_stdout"
},
{
"input": "cbb\n",
"output": "cb b \n",
"type": "stdin_stdout"
},
{
"input": "bababcdfabbcabcdfacbbabcdfacacabcdfacbcabcdfaccbabcdfacaaabcdfabacabcdfabcbabcdfacbaabcdfabaaabcdfabbaabcdfacababcdfabbbabcdfabcaabcdfaaababcdfabccabcdfacccabcdfaacbabcdfaabaabcdfaabcabcdfaaacabcdfaccaabcdfaabbabcdfaaaaabcdfaacaabcdfaacc\n",
"output": "bababc dfabb cabc dfacb babc dfacacabc dfacb cabc dfacc babc dfacaaabc dfabacabc dfabc babc dfacbaabc dfabaaabc dfabbaabc dfacababc dfabbbabc dfabcaabc dfaaababc dfabc cabc dfacccabc dfaacbabc dfaabaabc dfaabcabc dfaaacabc dfaccaabc dfaabbabc dfaaaaabc dfaacaabc dfaacc \n",
"type": "stdin_stdout"
},
{
"input": "bddabcdfaccdabcdfadddabcdfabbdabcdfacddabcdfacdbabcdfacbbabcdfacbcabcdfacbdabcdfadbbabcdfabdbabcdfabdcabcdfabbcabcdfabccabcdfabbbabcdfaddcabcdfaccbabcdfadbdabcdfacccabcdfadcdabcdfadcbabcdfabcbabcdfadbcabcdfacdcabcdfabcdabcdfadccabcdfaddb\n",
"output": "bd dabc dfacc dabc dfadddabc dfabb dabc dfacd dabc dfacd babc dfacb babc dfacb cabc dfacb dabc dfadb babc dfabd babc dfabd cabc dfabb cabc dfabc cabc dfabbbabc dfadd cabc dfacc babc dfadb dabc dfacccabc dfadc dabc dfadc babc dfabc babc dfadb cabc dfacd cabc dfabc dabc dfadc cabc dfadd b \n",
"type": "stdin_stdout"
},
{
"input": "helllllooooo\n",
"output": "helllllooooo \n",
"type": "stdin_stdout"
},
{
"input": "bbbzxxx\n",
"output": "bbb zx xx \n",
"type": "stdin_stdout"
},
{
"input": "ffff\n",
"output": "ffff \n",
"type": "stdin_stdout"
},
{
"input": "cdddddddddddddddddd\n",
"output": "cd ddddddddddddddddd \n",
"type": "stdin_stdout"
},
{
"input": "bbbc\n",
"output": "bbb c \n",
"type": "stdin_stdout"
},
{
"input": "lll\n",
"output": "lll \n",
"type": "stdin_stdout"
},
{
"input": "bbbbb\n",
"output": "bbbbb \n",
"type": "stdin_stdout"
},
{
"input": "llll\n",
"output": "llll \n",
"type": "stdin_stdout"
},
{
"input": "bbbbbbccc\n",
"output": "bbbbbb ccc \n",
"type": "stdin_stdout"
},
{
"input": "lllllb\n",
"output": "lllll b \n",
"type": "stdin_stdout"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\n",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzz \n",
"type": "stdin_stdout"
},
{
"input": "lllll\n",
"output": "lllll \n",
"type": "stdin_stdout"
},
{
"input": "bbbbbbbbbc\n",
"output": "bbbbbbbbb c \n",
"type": "stdin_stdout"
},
{
"input": "helllllno\n",
"output": "helllll no \n",
"type": "stdin_stdout"
},
{
"input": "nnnnnnnnnnnn\n",
"output": "nnnnnnnnnnnn \n",
"type": "stdin_stdout"
},
{
"input": "bbbbbccc\n",
"output": "bbbbb ccc \n",
"type": "stdin_stdout"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz\n",
"output": "zzzzzzzzzzzzzzzzzzzzzzzzzzzzz \n",
"type": "stdin_stdout"
},
{
"input": "nnnnnnnnnnnnnnnnnn\n",
"output": "nnnnnnnnnnnnnnnnnn \n",
"type": "stdin_stdout"
},
{
"input": "zzzzzzzzzzzzzzzzzzzzzzz\n",
"output": "zzzzzzzzzzzzzzzzzzzzzzz \n",
"type": "stdin_stdout"
},
{
"input": "hhhh\n",
"output": "hhhh \n",
"type": "stdin_stdout"
},
{
"input": "nnnnnnnnnnnnnnnnnnnnnnnnn\n",
"output": "nnnnnnnnnnnnnnnnnnnnnnnnn \n",
"type": "stdin_stdout"
},
{
"input": "zzzzzzzzzz\n",
"output": "zzzzzzzzzz \n",
"type": "stdin_stdout"
},
{
"input": "dddd\n",
"output": "dddd \n",
"type": "stdin_stdout"
},
{
"input": "heffffffgggggghhhhhh\n",
"output": "heffffff gggggg hhhhhh \n",
"type": "stdin_stdout"
},
{
"input": "bcddd\n",
"output": "bc ddd \n",
"type": "stdin_stdout"
},
{
"input": "x\n",
"output": "x \n",
"type": "stdin_stdout"
},
{
"input": "nnn\n",
"output": "nnn \n",
"type": "stdin_stdout"
},
{
"input": "xxxxxxxx\n",
"output": "xxxxxxxx \n",
"type": "stdin_stdout"
},
{
"input": "cclcc\n",
"output": "cc lc c \n",
"type": "stdin_stdout"
},
{
"input": "tttttttttttttt\n",
"output": "tttttttttttttt \n",
"type": "stdin_stdout"
},
{
"input": "xxxxxxx\n",
"output": "xxxxxxx \n",
"type": "stdin_stdout"
},
{
"input": "ccccb\n",
"output": "cccc b \n",
"type": "stdin_stdout"
},
{
"input": "bcecccc\n",
"output": "bcecccc \n",
"type": "stdin_stdout"
},
{
"input": "jjja\n",
"output": "jjja \n",
"type": "stdin_stdout"
},
{
"input": "zzz\n",
"output": "zzz \n",
"type": "stdin_stdout"
},
{
"input": "xxxxxxxxxzzzzzzzzzzzz\n",
"output": "xxxxxxxxx zzzzzzzzzzzz \n",
"type": "stdin_stdout"
},
{
"input": "alllewww\n",
"output": "alllewww \n",
"type": "stdin_stdout"
},
{
"input": "bbbbbbbbb\n",
"output": "bbbbbbbbb \n",
"type": "stdin_stdout"
},
{
"input": "jjj\n",
"output": "jjj \n",
"type": "stdin_stdout"
},
{
"input": "bbbbbbbbbbbbbbbbbbbbbbbbb\n",
"output": "bbbbbbbbbbbbbbbbbbbbbbbbb \n",
"type": "stdin_stdout"
},
{
"input": "kkkkkkkkkklllllllllllllll\n",
"output": "kkkkkkkkkk lllllllllllllll \n",
"type": "stdin_stdout"
},
{
"input": "helllllllllllo\n",
"output": "helllllllllllo \n",
"type": "stdin_stdout"
},
{
"input": "ttttsttttt\n",
"output": "tttt st tttt \n",
"type": "stdin_stdout"
},
{
"input": "tttttttsssssss\n",
"output": "ttttttt sssssss \n",
"type": "stdin_stdout"
},
{
"input": "assstttttatsfatsfdjfdhtsjdsaatttssssststsss\n",
"output": "asss tttttats fats fd jf dh ts jd saattt sssss ts ts ss \n",
"type": "stdin_stdout"
},
{
"input": "xxxxx\n",
"output": "xxxxx \n",
"type": "stdin_stdout"
},
{
"input": "bbbhbbb\n",
"output": "bbb hb bb \n",
"type": "stdin_stdout"
},
{
"input": "bbbbbbbb\n",
"output": "bbbbbbbb \n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/858/C"
} | vfc_10358 |
apps | verifiable_code | 152 | Solve the following coding problem using the programming language python:
Anton is playing a very interesting computer game, but now he is stuck at one of the levels. To pass to the next level he has to prepare n potions.
Anton has a special kettle, that can prepare one potions in x seconds. Also, he knows spells of two types that can faster the process of preparing potions. Spells of this type speed up the preparation time of one potion. There are m spells of this type, the i-th of them costs b_{i} manapoints and changes the preparation time of each potion to a_{i} instead of x. Spells of this type immediately prepare some number of potions. There are k such spells, the i-th of them costs d_{i} manapoints and instantly create c_{i} potions.
Anton can use no more than one spell of the first type and no more than one spell of the second type, and the total number of manapoints spent should not exceed s. Consider that all spells are used instantly and right before Anton starts to prepare potions.
Anton wants to get to the next level as fast as possible, so he is interested in the minimum number of time he needs to spent in order to prepare at least n potions.
-----Input-----
The first line of the input contains three integers n, m, k (1 ≤ n ≤ 2·10^9, 1 ≤ m, k ≤ 2·10^5) — the number of potions, Anton has to make, the number of spells of the first type and the number of spells of the second type.
The second line of the input contains two integers x and s (2 ≤ x ≤ 2·10^9, 1 ≤ s ≤ 2·10^9) — the initial number of seconds required to prepare one potion and the number of manapoints Anton can use.
The third line contains m integers a_{i} (1 ≤ a_{i} < x) — the number of seconds it will take to prepare one potion if the i-th spell of the first type is used.
The fourth line contains m integers b_{i} (1 ≤ b_{i} ≤ 2·10^9) — the number of manapoints to use the i-th spell of the first type.
There are k integers c_{i} (1 ≤ c_{i} ≤ n) in the fifth line — the number of potions that will be immediately created if the i-th spell of the second type is used. It's guaranteed that c_{i} are not decreasing, i.e. c_{i} ≤ c_{j} if i < j.
The sixth line contains k integers d_{i} (1 ≤ d_{i} ≤ 2·10^9) — the number of manapoints required to use the i-th spell of the second type. It's guaranteed that d_{i} are not decreasing, i.e. d_{i} ≤ d_{j} if i < j.
-----Output-----
Print one integer — the minimum time one has to spent in order to prepare n potions.
-----Examples-----
Input
20 3 2
10 99
2 4 3
20 10 40
4 15
10 80
Output
20
Input
20 3 2
10 99
2 4 3
200 100 400
4 15
100 800
Output
200
-----Note-----
In the first sample, the optimum answer is to use the second spell of the first type that costs 10 manapoints. Thus, the preparation time of each potion changes to 4 seconds. Also, Anton should use the second spell of the second type to instantly prepare 15 potions spending 80 manapoints. The total number of manapoints used is 10 + 80 = 90, and the preparation time is 4·5 = 20 seconds (15 potions were prepared instantly, and the remaining 5 will take 4 seconds each).
In the second sample, Anton can't use any of the spells, so he just prepares 20 potions, spending 10 seconds on each of them and the answer is 20·10 = 200.
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 = list(map(int, input().split()))
x, s = list(map(int, input().split()))
t = list(map(int, input().split()))
pr = list(map(int, input().split()))
t2 = list(map(int, input().split()))
pr2 = list(map(int, input().split()))
mass1 = []
minans = 10**20
for i in range(m):
mass1.append((pr[i], t[i]))
mass1.sort()
mass1 = [(0, x)] + mass1
pr2 = [0] + pr2
t2 = [0] + t2
uk1 = len(mass1) - 1
uk2 = 0
maxw = 0
for uk1 in range(len(mass1) - 1, -1, -1):
if (s < mass1[uk1][0]):
continue
while (uk2 < len(pr2) and mass1[uk1][0] + pr2[uk2] <= s):
maxw = max(maxw, t2[uk2])
uk2 += 1
uk2 -= 1
minans = min(minans, (n - maxw) * mass1[uk1][1])
print(minans)
``` | {
"language": "python",
"test_cases": [
{
"input": "20 3 2\n10 99\n2 4 3\n20 10 40\n4 15\n10 80\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "20 3 2\n10 99\n2 4 3\n200 100 400\n4 15\n100 800\n",
"output": "200\n",
"type": "stdin_stdout"
},
{
"input": "10 3 3\n10 33\n1 7 6\n17 25 68\n2 9 10\n78 89 125\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "94 1 1\n26 324\n7\n236\n77\n5\n",
"output": "119\n",
"type": "stdin_stdout"
},
{
"input": "3 4 5\n5 9\n1 2 1 1\n3 5 4 1\n1 1 1 1 3\n1 2 3 4 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 4 2\n3 10\n2 1 1 1\n1 5 3 5\n1 1\n1 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5 3 3\n4 4\n2 3 1\n1 3 1\n1 2 2\n2 2 5\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 3 2\n2 7\n1 1 1\n2 4 1\n1 4\n1 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 1999999999\n1\n2000000000\n1\n2000000000\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "3 1 1\n2 1\n1\n1\n1\n1\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "379 5 8\n758 10000\n512 512 512 512 512\n500 500 500 500 500\n123 123 123 123 123 123 123 123\n500 500 500 500 500 500 500 500\n",
"output": "131072\n",
"type": "stdin_stdout"
},
{
"input": "256 22 22\n45 42\n21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42\n21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42\n21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42\n21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42\n",
"output": "4935\n",
"type": "stdin_stdout"
},
{
"input": "20 3 2\n1000 99\n1 2 3\n100 200 300\n1 2\n3 4\n",
"output": "18000\n",
"type": "stdin_stdout"
},
{
"input": "20 3 2\n10 99\n2 4 3\n200 100 400\n4 15\n10 80\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 1\n1\n100\n1\n100\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "100 1 1\n100 1\n1\n1000\n100\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 1 1\n100 1\n1\n1000\n99\n1\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1\n10 10\n2\n11\n1\n2\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 3 2\n1000000000 99\n2 4 3\n100 100 100\n4 15\n100 100\n",
"output": "2000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 1\n2\n2\n2\n2\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 2 2\n2000000000 1\n1 2\n100 100\n1 2\n100 100\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 1\n1\n2\n1\n2\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 3 2\n10 1\n2 4 3\n200 100 400\n4 15\n100 800\n",
"output": "20000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000 1 1\n10 10\n1\n1000\n500\n10\n",
"output": "5000\n",
"type": "stdin_stdout"
},
{
"input": "4 2 2\n4 3\n1 1\n8 8\n1 1\n1 1\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "20 3 2\n10 99\n2 4 3\n200 100 400\n20 20\n1 1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2000 1 1\n2000 1\n2\n2\n1\n1\n",
"output": "3998000\n",
"type": "stdin_stdout"
},
{
"input": "20 3 2\n10 99\n2 4 3\n20 20 40\n4 20\n10 80\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 1 1\n10 50\n1\n50\n1\n50\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 3 2\n1000000000 99\n2 4 3\n200 100 400\n4 15\n100 100\n",
"output": "2000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "10 1 1\n10 10\n9\n100\n10\n10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "50 1 1\n3 10\n2\n100\n50\n10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20 1 1\n10 99\n1\n100\n4\n10\n",
"output": "160\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 3 2\n1000000000 99\n2 4 3\n200 100 400\n4 15\n100 800\n",
"output": "2000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "100 1 1\n100 2\n1\n2\n1\n2\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "10 1 1\n10 50\n1\n51\n10\n50\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20 3 2\n10 10\n2 4 3\n10 90 90\n1 2\n999 1000\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "5 1 1\n5 10\n3\n10\n5\n10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20 1 1\n100 1\n2\n2\n20\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 1 1\n200 10\n10\n11\n100\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20 3 2\n10 99\n2 4 3\n200 100 400\n4 15\n1 8\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "20 3 1\n5 40\n2 3 4\n40 40 40\n20\n40\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 1 1\n10 50\n1\n51\n9\n50\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 1\n1\n5\n1\n5\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "100 1 1\n1000 5\n1\n6\n100\n4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 1\n1000000000 1\n1\n10000\n1\n10000\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 1\n1\n10\n2\n10\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "20 1 1\n10 100\n5\n200\n10\n1\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 1\n1999999999\n1\n1\n1\n",
"output": "3999999998000000000\n",
"type": "stdin_stdout"
},
{
"input": "20 3 2\n10 10\n2 4 3\n10 10 10\n20 20\n999 999\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "20 2 2\n10 100\n1 1\n1000 2000\n4 15\n100 800\n",
"output": "160\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1\n5 5\n2\n10\n2\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20 3 2\n10 2\n1 1 1\n3 4 5\n1 2\n1 3\n",
"output": "190\n",
"type": "stdin_stdout"
},
{
"input": "20 3 1\n10 10\n9 9 9\n10 10 10\n20\n10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 3 2\n1000000000 1\n2 4 3\n20 10 40\n4 15\n10 80\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "10 1 1\n10 10\n1\n20\n5\n9\n",
"output": "50\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n1000 1000\n1\n1000\n1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 1\n1000000000 1\n1\n10000\n1000000000\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20 1 1\n10 10\n4\n100\n20\n10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100 1 1\n100 10000\n99\n10001\n100\n10000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20 1 1\n10 100\n5\n200\n10\n100\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "52 2 3\n50 101\n15 13\n10 20\n20 50 51\n20 100 200\n",
"output": "100\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 10\n5\n15\n5\n15\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "20 3 2\n10 99\n2 4 3\n99 100 400\n4 15\n100 800\n",
"output": "40\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n1000 1\n1\n1000\n1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "100000000 1 1\n100000000 1\n10\n10\n10\n10\n",
"output": "10000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 3 2\n1000000000 99\n2 4 3\n20 10 40\n4 15\n10 80\n",
"output": "1999999992\n",
"type": "stdin_stdout"
},
{
"input": "100 1 1\n1000 5\n1\n6\n95\n4\n",
"output": "5000\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n2 1\n1\n10\n1\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "50 1 1\n10 10\n8\n11\n50\n10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 1\n1\n10\n1\n10\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "10 1 1\n10 10\n5\n5\n7\n10\n",
"output": "30\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 1\n200000000\n2000000000\n2000000000\n2000000000\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 1\n4\n100\n20\n100\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "100 1 1\n1000 5\n2\n6\n95\n4\n",
"output": "5000\n",
"type": "stdin_stdout"
},
{
"input": "10 1 2\n10 10\n5\n6\n5 7\n4 4\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 1\n1000000000 1\n1\n1000000\n1\n100000000\n",
"output": "1000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 5\n2\n6\n2\n6\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "2000000000 1 1\n2000000000 1\n100\n100\n100\n100\n",
"output": "4000000000000000000\n",
"type": "stdin_stdout"
},
{
"input": "20 3 2\n10 99\n2 4 3\n20 10 40\n20 20\n99 99\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10 2 2\n10 15\n5 7\n16 16\n5 10\n5 10\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 1\n1000000000 10\n999999991\n1\n1\n10000\n",
"output": "999999991000000000\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1 1\n1000000000 2\n999999999\n1\n1\n1\n",
"output": "999999998000000001\n",
"type": "stdin_stdout"
},
{
"input": "20 3 2\n2000000000 99\n2 4 3\n200 100 400\n4 15\n100 800\n",
"output": "40000000000\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/734/C"
} | vfc_10362 |
apps | verifiable_code | 153 | Solve the following coding problem using the programming language python:
Polycarp takes part in a math show. He is given n tasks, each consists of k subtasks, numbered 1 through k. It takes him t_{j} minutes to solve the j-th subtask of any task. Thus, time required to solve a subtask depends only on its index, but not on the task itself. Polycarp can solve subtasks in any order.
By solving subtask of arbitrary problem he earns one point. Thus, the number of points for task is equal to the number of solved subtasks in it. Moreover, if Polycarp completely solves the task (solves all k of its subtasks), he recieves one extra point. Thus, total number of points he recieves for the complete solution of the task is k + 1.
Polycarp has M minutes of time. What is the maximum number of points he can earn?
-----Input-----
The first line contains three integer numbers n, k and M (1 ≤ n ≤ 45, 1 ≤ k ≤ 45, 0 ≤ M ≤ 2·10^9).
The second line contains k integer numbers, values t_{j} (1 ≤ t_{j} ≤ 1000000), where t_{j} is the time in minutes required to solve j-th subtask of any task.
-----Output-----
Print the maximum amount of points Polycarp can earn in M minutes.
-----Examples-----
Input
3 4 11
1 2 3 4
Output
6
Input
5 5 10
1 2 4 8 16
Output
7
-----Note-----
In the first example Polycarp can complete the first task and spend 1 + 2 + 3 + 4 = 10 minutes. He also has the time to solve one subtask of the second task in one minute.
In the second example Polycarp can solve the first subtask of all five tasks and spend 5·1 = 5 minutes. Also he can solve the second subtasks of two tasks and spend 2·2 = 4 minutes. Thus, he earns 5 + 2 = 7 points in total.
The input will be stdin and you should print your solution to stdout
Now solve the problem and return the code. | ```python
n, k, m = list(map(int, input().split()))
l = list(map(int, input().split()))
l.sort()
s = sum(l)
ans = 0
for i in range(n + 1):
mi = m - s * i
if mi < 0:
break
cnt = (k + 1) * i
for j in range(k):
x = min(mi // l[j], n - i)
cnt += x
mi -= l[j] * x
ans = max(ans, cnt)
print(ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "3 4 11\n1 2 3 4\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5 5 10\n1 2 4 8 16\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "1 1 0\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1 1\n1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 1 0\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2\n2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 2 15\n1 4\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "24 42 126319796\n318996 157487 174813 189765 259136 406743 138997 377982 244813 16862 95438 346702 454882 274633 67361 387756 61951 448901 427272 288847 316578 416035 56608 211390 187241 191538 299856 294995 442139 95784 410894 439744 455044 301002 196932 352004 343622 73438 325186 295727 21130 32856\n",
"output": "677\n",
"type": "stdin_stdout"
},
{
"input": "5 3 10\n1 3 6\n",
"output": "6\n",
"type": "stdin_stdout"
},
{
"input": "5 3 50\n1 3 6\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "5 3 2000000000\n1 3 6\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "5 3 49\n1 3 6\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "3 4 16\n1 2 3 4\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "11 2 20\n1 9\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "11 3 38\n1 9 9\n",
"output": "15\n",
"type": "stdin_stdout"
},
{
"input": "5 3 11\n1 1 2\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "5 4 36\n1 3 7 7\n",
"output": "13\n",
"type": "stdin_stdout"
},
{
"input": "1 13 878179\n103865 43598 180009 528483 409585 449955 368163 381135 713512 645876 241515 20336 572091\n",
"output": "5\n",
"type": "stdin_stdout"
},
{
"input": "1 9 262522\n500878 36121 420012 341288 139726 362770 462113 261122 394426\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "45 32 252252766\n282963 74899 446159 159106 469932 288063 297289 501442 241341 240108 470371 316076 159136 72720 37365 108455 82789 529789 303825 392553 153053 389577 327929 277446 505280 494678 159006 505007 328366 460640 18354 313300\n",
"output": "1094\n",
"type": "stdin_stdout"
},
{
"input": "44 41 93891122\n447 314862 48587 198466 73450 166523 247421 50078 14115 229926 11070 53089 73041 156924 200782 53225 290967 219349 119034 88726 255048 59778 287298 152539 55104 170525 135722 111341 279873 168400 267489 157697 188015 94306 231121 304553 27684 46144 127122 166022 150941\n",
"output": "1084\n",
"type": "stdin_stdout"
},
{
"input": "12 45 2290987\n50912 189025 5162 252398 298767 154151 164139 185891 121047 227693 93549 284244 312843 313833 285436 131672 135248 324541 194905 205729 241315 32044 131902 305884 263 27717 173077 81428 285684 66470 220938 282471 234921 316283 30485 244283 170631 224579 72899 87066 6727 161661 40556 89162 314616\n",
"output": "95\n",
"type": "stdin_stdout"
},
{
"input": "42 9 4354122\n47443 52983 104606 84278 5720 55971 100555 90845 91972\n",
"output": "124\n",
"type": "stdin_stdout"
},
{
"input": "45 28 33631968\n5905 17124 64898 40912 75855 53868 27056 18284 63975 51975 27182 94373 52477 260 87551 50223 73798 77430 17510 15226 6269 43301 39592 27043 15546 60047 83400 63983\n",
"output": "979\n",
"type": "stdin_stdout"
},
{
"input": "18 3 36895\n877 2054 4051\n",
"output": "28\n",
"type": "stdin_stdout"
},
{
"input": "13 30 357\n427 117 52 140 162 58 5 149 438 327 103 357 202 1 148 238 442 200 438 97 414 301 224 166 254 322 378 422 90 312\n",
"output": "31\n",
"type": "stdin_stdout"
},
{
"input": "44 11 136\n77 38 12 71 81 15 66 47 29 22 71\n",
"output": "11\n",
"type": "stdin_stdout"
},
{
"input": "32 6 635\n3 4 2 1 7 7\n",
"output": "195\n",
"type": "stdin_stdout"
},
{
"input": "30 19 420\n2 2 1 2 2 1 1 2 1 2 2 2 1 2 2 2 2 1 2\n",
"output": "309\n",
"type": "stdin_stdout"
},
{
"input": "37 40 116\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\n",
"output": "118\n",
"type": "stdin_stdout"
},
{
"input": "7 37 133\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\n",
"output": "136\n",
"type": "stdin_stdout"
},
{
"input": "40 1 8\n3\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1 28 1\n3 3 2 2 1 1 3 1 1 2 2 1 1 3 3 1 1 1 1 1 3 1 3 3 3 2 2 3\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "12 1 710092\n145588\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "1 7 47793\n72277 45271 85507 39251 45440 101022 105165\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1 0\n4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 3\n2 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 1 0\n5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1 3\n5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 3 0\n6 3 4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 2 0\n1 2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1 3\n5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1 0\n5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 2 3\n7 2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "2 4 5\n1 2 8 6\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "2 1 0\n3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 3 3\n16 4 5\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 1 0\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 2 2\n6 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "3 2 1\n1 1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 3 19\n12 15 6\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "2 2 8\n12 1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1 6 14\n15 2 6 13 14 4\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "4 1 0\n1\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1 0\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1 1 0\n2\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 2 5\n5 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1 3 8\n5 4 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1 5 44\n2 19 18 6 8\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "1 1 0\n4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "3 2 7\n5 1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "4 2 9\n8 6\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "4 3 3\n6 12 7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "4 1 2\n1\n",
"output": "4\n",
"type": "stdin_stdout"
},
{
"input": "2 4 15\n8 3 7 8\n",
"output": "3\n",
"type": "stdin_stdout"
},
{
"input": "6 1 2\n4\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 1 1\n1\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "1 1 2\n3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2\n1 4\n",
"output": "2\n",
"type": "stdin_stdout"
},
{
"input": "6 2 78\n12 10\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "1 3 10\n17 22 15\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6 3 13\n1 2 3\n",
"output": "10\n",
"type": "stdin_stdout"
},
{
"input": "21 3 26\n1 2 3\n",
"output": "24\n",
"type": "stdin_stdout"
},
{
"input": "3 7 20012\n1 1 1 1 1 1 10000\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "5 4 40\n4 2 3 3\n",
"output": "17\n",
"type": "stdin_stdout"
},
{
"input": "4 5 40\n4 1 3 2 4\n",
"output": "18\n",
"type": "stdin_stdout"
},
{
"input": "3 5 22\n1 1 4 1 1\n",
"output": "16\n",
"type": "stdin_stdout"
},
{
"input": "5 2 17\n3 4\n",
"output": "7\n",
"type": "stdin_stdout"
},
{
"input": "5 4 32\n4 2 1 1\n",
"output": "21\n",
"type": "stdin_stdout"
},
{
"input": "5 5 34\n4 1 1 2 4\n",
"output": "20\n",
"type": "stdin_stdout"
},
{
"input": "3 3 15\n1 2 1\n",
"output": "12\n",
"type": "stdin_stdout"
},
{
"input": "3 2 11\n1 2\n",
"output": "9\n",
"type": "stdin_stdout"
},
{
"input": "5 4 11\n2 1 3 4\n",
"output": "8\n",
"type": "stdin_stdout"
},
{
"input": "45 45 2000000000\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\n",
"output": "2070\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/846/B"
} | vfc_10366 |
apps | verifiable_code | 154 | Solve the following coding problem using the programming language python:
Recall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be greater than any key stored in the left subtree, and less than any key stored in the right subtree.
The depth of a vertex is the number of edges on the simple path from the vertex to the root. In particular, the depth of the root is $0$.
Let's call a binary search tree perfectly balanced if there doesn't exist a binary search tree with the same number of vertices that has a strictly smaller sum of depths of its vertices.
Let's call a binary search tree with integer keys striped if both of the following conditions are satisfied for every vertex $v$: If $v$ has a left subtree whose root is $u$, then the parity of the key of $v$ is different from the parity of the key of $u$. If $v$ has a right subtree whose root is $w$, then the parity of the key of $v$ is the same as the parity of the key of $w$.
You are given a single integer $n$. Find the number of perfectly balanced striped binary search trees with $n$ vertices that have distinct integer keys between $1$ and $n$, inclusive. Output this number modulo $998\,244\,353$.
-----Input-----
The only line contains a single integer $n$ ($1 \le n \le 10^6$), denoting the required number of vertices.
-----Output-----
Output the number of perfectly balanced striped binary search trees with $n$ vertices and distinct integer keys between $1$ and $n$, inclusive, modulo $998\,244\,353$.
-----Examples-----
Input
4
Output
1
Input
3
Output
0
-----Note-----
In the first example, this is the only tree that satisfies the conditions: $\left. \begin{array}{l}{\text{perfectly balanced}} \\{\text{striped}} \\{\text{binary search tree}} \end{array} \right.$
In the second example, here are various trees that don't satisfy some condition: [Image]
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())
if N in [1, 2, 4, 5, 9, 10, 20, 21, 41, 42, 84, 85, 169, 170, 340, 341, 681, 682, 1364, 1365, 2729, 2730, 5460, 5461, 10921, 10922, 21844, 21845, 43689, 43690, 87380, 87381, 174761, 174762, 349524, 349525, 699049, 699050]:
print(1)
else:
print(0)
``` | {
"language": "python",
"test_cases": [
{
"input": "4\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "3\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "5\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "7\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "8\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "9\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "1\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "21\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "14\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "360561\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "25\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "85\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "699049\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "699047\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "6\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "699050\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "699048\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1000000\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "786432\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "750096\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "10922\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "699051\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "87380\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "308545\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "16\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "20\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "170\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "22\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "84\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "174762\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "341\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "17\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "530259\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "181407\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5461\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "21844\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "472032\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "325193\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "43689\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "43690\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "31\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "524288\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "546029\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "5460\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "26\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "682\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "621012\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "19\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "334846\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "549836\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "797049\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "174761\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "320507\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "699046\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "681\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "28\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "87381\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "27\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "503375\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "557479\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "11\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "13156\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "349525\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "10921\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "259060\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "21845\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "175466\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "796867\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "527730\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "737480\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "740812\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "631649\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "1365\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "581472\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "622262\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "42\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "629191\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "12\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "2730\n",
"output": "1\n",
"type": "stdin_stdout"
},
{
"input": "988727\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "999999\n",
"output": "0\n",
"type": "stdin_stdout"
},
{
"input": "169\n",
"output": "1\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/1237/E"
} | vfc_10370 |
apps | verifiable_code | 155 | Solve the following coding problem using the programming language python:
You might have heard about the next game in Lara Croft series coming out this year. You also might have watched its trailer. Though you definitely missed the main idea about its plot, so let me lift the veil of secrecy.
Lara is going to explore yet another dangerous dungeon. Game designers decided to use good old 2D environment. The dungeon can be represented as a rectangle matrix of n rows and m columns. Cell (x, y) is the cell in the x-th row in the y-th column. Lara can move between the neighbouring by side cells in all four directions.
Moreover, she has even chosen the path for herself to avoid all the traps. She enters the dungeon in cell (1, 1), that is top left corner of the matrix. Then she goes down all the way to cell (n, 1) — the bottom left corner. Then she starts moving in the snake fashion — all the way to the right, one cell up, then to the left to the cell in 2-nd column, one cell up. She moves until she runs out of non-visited cells. n and m given are such that she always end up in cell (1, 2).
Lara has already moved to a neighbouring cell k times. Can you determine her current position?
-----Input-----
The only line contains three integers n, m and k (2 ≤ n, m ≤ 10^9, n is always even, 0 ≤ k < n·m). Note that k doesn't fit into 32-bit integer type!
-----Output-----
Print the cell (the row and the column where the cell is situated) where Lara ends up after she moves k times.
-----Examples-----
Input
4 3 0
Output
1 1
Input
4 3 11
Output
1 2
Input
4 3 7
Output
3 2
-----Note-----
Here is her path on matrix 4 by 3: [Image]
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 = map(int, input().split())
ans = 0, 0
if k < n:
ans = k + 1, 1
else:
k -= n
r = n - k // (m - 1)
if r % 2:
c = m - k % (m - 1)
else:
c = 2 + k % (m - 1)
ans = r, c
print(*ans)
``` | {
"language": "python",
"test_cases": [
{
"input": "4 3 0\n",
"output": "1 1\n",
"type": "stdin_stdout"
},
{
"input": "4 3 11\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "4 3 7\n",
"output": "3 2\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 2 1999999999\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 999999999999999999\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 999999999\n",
"output": "1000000000 1\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 2000000500\n",
"output": "999999999 999999499\n",
"type": "stdin_stdout"
},
{
"input": "2 2 2\n",
"output": "2 2\n",
"type": "stdin_stdout"
},
{
"input": "28 3 1\n",
"output": "2 1\n",
"type": "stdin_stdout"
},
{
"input": "2 3 3\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "4 6 8\n",
"output": "4 6\n",
"type": "stdin_stdout"
},
{
"input": "6 6 18\n",
"output": "4 4\n",
"type": "stdin_stdout"
},
{
"input": "4 3 8\n",
"output": "2 2\n",
"type": "stdin_stdout"
},
{
"input": "4 3 4\n",
"output": "4 2\n",
"type": "stdin_stdout"
},
{
"input": "4 4 10\n",
"output": "2 2\n",
"type": "stdin_stdout"
},
{
"input": "4 5 4\n",
"output": "4 2\n",
"type": "stdin_stdout"
},
{
"input": "4 3 9\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "4 3 6\n",
"output": "3 3\n",
"type": "stdin_stdout"
},
{
"input": "4 5 5\n",
"output": "4 3\n",
"type": "stdin_stdout"
},
{
"input": "6 4 8\n",
"output": "6 4\n",
"type": "stdin_stdout"
},
{
"input": "4 4 12\n",
"output": "2 4\n",
"type": "stdin_stdout"
},
{
"input": "10 6 15\n",
"output": "9 6\n",
"type": "stdin_stdout"
},
{
"input": "6666 969696 6667\n",
"output": "6666 3\n",
"type": "stdin_stdout"
},
{
"input": "4 5 13\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "84 68 4248\n",
"output": "22 12\n",
"type": "stdin_stdout"
},
{
"input": "6 6 9\n",
"output": "6 5\n",
"type": "stdin_stdout"
},
{
"input": "4 5 17\n",
"output": "1 4\n",
"type": "stdin_stdout"
},
{
"input": "2 3 4\n",
"output": "1 3\n",
"type": "stdin_stdout"
},
{
"input": "4 3 5\n",
"output": "4 3\n",
"type": "stdin_stdout"
},
{
"input": "2 3 2\n",
"output": "2 2\n",
"type": "stdin_stdout"
},
{
"input": "4 5 12\n",
"output": "2 2\n",
"type": "stdin_stdout"
},
{
"input": "6 6 16\n",
"output": "4 2\n",
"type": "stdin_stdout"
},
{
"input": "4 4 6\n",
"output": "4 4\n",
"type": "stdin_stdout"
},
{
"input": "10 3 18\n",
"output": "6 2\n",
"type": "stdin_stdout"
},
{
"input": "2 4 5\n",
"output": "1 4\n",
"type": "stdin_stdout"
},
{
"input": "6 9 43\n",
"output": "2 7\n",
"type": "stdin_stdout"
},
{
"input": "4 7 8\n",
"output": "4 6\n",
"type": "stdin_stdout"
},
{
"input": "500 100 800\n",
"output": "497 97\n",
"type": "stdin_stdout"
},
{
"input": "2 5 5\n",
"output": "2 5\n",
"type": "stdin_stdout"
},
{
"input": "4 6 15\n",
"output": "2 3\n",
"type": "stdin_stdout"
},
{
"input": "9213788 21936127 8761236\n",
"output": "8761237 1\n",
"type": "stdin_stdout"
},
{
"input": "2 5 6\n",
"output": "1 5\n",
"type": "stdin_stdout"
},
{
"input": "43534 432423 53443\n",
"output": "43534 9911\n",
"type": "stdin_stdout"
},
{
"input": "999999998 999999998 999999995000000005\n",
"output": "2 999999997\n",
"type": "stdin_stdout"
},
{
"input": "999999924 999999983 999999906999879972\n",
"output": "1 121321\n",
"type": "stdin_stdout"
},
{
"input": "6 5 18\n",
"output": "3 5\n",
"type": "stdin_stdout"
},
{
"input": "4 4 5\n",
"output": "4 3\n",
"type": "stdin_stdout"
},
{
"input": "6 6 6\n",
"output": "6 2\n",
"type": "stdin_stdout"
},
{
"input": "99999998 8888888 77777777777\n",
"output": "99991260 6683175\n",
"type": "stdin_stdout"
},
{
"input": "6 5 6\n",
"output": "6 2\n",
"type": "stdin_stdout"
},
{
"input": "6 5 17\n",
"output": "4 5\n",
"type": "stdin_stdout"
},
{
"input": "6 4 12\n",
"output": "4 2\n",
"type": "stdin_stdout"
},
{
"input": "999995712 999993076 999988788028978212\n",
"output": "1 711901\n",
"type": "stdin_stdout"
},
{
"input": "999994900 999993699 999988599028973300\n",
"output": "1 3161801\n",
"type": "stdin_stdout"
},
{
"input": "978642410 789244500 12348616164\n",
"output": "978642396 320550770\n",
"type": "stdin_stdout"
},
{
"input": "999993774 999998283 999992057010529542\n",
"output": "1 160501\n",
"type": "stdin_stdout"
},
{
"input": "4 7 10\n",
"output": "3 7\n",
"type": "stdin_stdout"
},
{
"input": "6 4 9\n",
"output": "5 4\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 789 788999999000\n",
"output": "2 578\n",
"type": "stdin_stdout"
},
{
"input": "978642410 789244500 1234861616400\n",
"output": "978640847 495422447\n",
"type": "stdin_stdout"
},
{
"input": "999999596 999999631 999999226999090676\n",
"output": "1 1058401\n",
"type": "stdin_stdout"
},
{
"input": "4 7 16\n",
"output": "2 2\n",
"type": "stdin_stdout"
},
{
"input": "2 2 3\n",
"output": "1 2\n",
"type": "stdin_stdout"
},
{
"input": "21726 5447 14771\n",
"output": "14772 1\n",
"type": "stdin_stdout"
},
{
"input": "4 2 6\n",
"output": "2 2\n",
"type": "stdin_stdout"
},
{
"input": "621282132 311996010 98597740967720109\n",
"output": "305259691 311996002\n",
"type": "stdin_stdout"
},
{
"input": "803521870 958373820 689637244594465863\n",
"output": "83930798 27\n",
"type": "stdin_stdout"
},
{
"input": "887584278 701990442 578292377747447929\n",
"output": "63794746 41\n",
"type": "stdin_stdout"
},
{
"input": "656369902 872526042 566305269065863364\n",
"output": "7328794 36\n",
"type": "stdin_stdout"
},
{
"input": "839664176 535164910 441498526835463771\n",
"output": "14687578 15\n",
"type": "stdin_stdout"
},
{
"input": "636553724 546535019 115079316355948443\n",
"output": "425992073 546535018\n",
"type": "stdin_stdout"
},
{
"input": "2182 23967 52288026\n",
"output": "1 7969\n",
"type": "stdin_stdout"
},
{
"input": "548492800 434105920 179638683192075937\n",
"output": "134679777 434105920\n",
"type": "stdin_stdout"
},
{
"input": "4 4 4\n",
"output": "4 2\n",
"type": "stdin_stdout"
},
{
"input": "6 8 15\n",
"output": "5 6\n",
"type": "stdin_stdout"
},
{
"input": "6 3 7\n",
"output": "6 3\n",
"type": "stdin_stdout"
},
{
"input": "949547590 305226065 138144146668766087\n",
"output": "496951426 3\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 3000000000\n",
"output": "999999998 4\n",
"type": "stdin_stdout"
},
{
"input": "999999998 1000000000 1000000998999999\n",
"output": "998999998 3\n",
"type": "stdin_stdout"
},
{
"input": "999381438 840037557 128928432510450944\n",
"output": "845902072 12\n",
"type": "stdin_stdout"
},
{
"input": "742860584 671970249 260211607929646490\n",
"output": "355623786 4\n",
"type": "stdin_stdout"
},
{
"input": "1000000000 1000000000 1999999998\n",
"output": "1000000000 1000000000\n",
"type": "stdin_stdout"
},
{
"input": "993142186 628701115 555947810764442157\n",
"output": "108862204 25\n",
"type": "stdin_stdout"
},
{
"input": "595261150 794915864 332353903994901365\n",
"output": "177161677 794915848\n",
"type": "stdin_stdout"
}
]
} | {
"difficulty": "interview",
"problem_url": "https://codeforces.com/problemset/problem/976/B"
} | vfc_10374 |
Subsets and Splits