source stringclasses 4
values | task_type stringclasses 1
value | in_source_id stringlengths 0 112 | prompt stringlengths 219 13.2k | gold_standard_solution stringlengths 22 413k | verification_info stringlengths 91 74M | metadata stringlengths 19 190 | problem_id stringlengths 5 10 | program stringlengths 22 413k | inputs stringlengths 0 889k | output stringlengths 0 168k | actual_output stringlengths 0 168k | execution_success bool 1
class | sample_index int64 2 31.8k |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
apps | verifiable_code | 908 | Solve the following coding problem using the programming language python:
Vasiliy is fond of solving different tasks. Today he found one he wasn't able to solve himself, so he asks you to help.
Vasiliy is given n strings consisting of lowercase English letters. He wants them to be sorted in lexicographical order (as ... | ```python
n = int(input())
c = list(map(int, input().split(" ")))
nodes = dict()
nodes[""] = 0
# print(nodes)
depth = 0
while depth < n:
# expand
new_nodes = dict()
s = input()
for node in nodes.keys():
if s >= node:
# not reverse
if s in new_nodes:
new_nodes[s] = min(new_nodes[s], nodes[node])
els... | {'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1 2\nba\nac\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3\n1 3 1\naa\nba\nac\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '2\n5 5\nbbb\naaa\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '2\n3 3\naaa\naa\n', 'output': '-1\n'}, {'typ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/706/C'} | vfc_13386 | ```python
n = int(input())
c = list(map(int, input().split(" ")))
nodes = dict()
nodes[""] = 0
# print(nodes)
depth = 0
while depth < n:
# expand
new_nodes = dict()
s = input()
for node in nodes.keys():
if s >= node:
# not reverse
if s in new_nodes:
new_nodes[s] = min(new_nodes[s], nodes[node])
els... | 2
1 2
ba
ac
| 1
| 1
| true | 2,380 |
apps | verifiable_code | 909 | Solve the following coding problem using the programming language python:
Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and... | ```python
a = int(input())
b = int(input())
c = int(input())
print(max(a*b*c, a+b*c, a*b+c, a*(b+c), (a+b)*c, a+b+c))
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '1\n2\n3\n', 'output': '9\n'}, {'type': 'stdin_stdout', 'input': '2\n10\n3\n', 'output': '60\n'}, {'type': 'stdin_stdout', 'input': '1\n1\n1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '1\n2\n1\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '10\n10\... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/479/A'} | vfc_13390 | ```python
a = int(input())
b = int(input())
c = int(input())
print(max(a*b*c, a+b*c, a*b+c, a*(b+c), (a+b)*c, a+b+c))
``` | 1
2
3
| 9
| 9
| true | 2,381 |
apps | verifiable_code | 910 | Solve the following coding problem using the programming language python:
There are n parliamentarians in Berland. They are numbered with integers from 1 to n. It happened that all parliamentarians with odd indices are Democrats and all parliamentarians with even indices are Republicans.
New parliament assembly hall ... | ```python
# You lost the game.
n, a, b = map(int, input().split())
dem = n//2 + n%2
i = 1
while dem > 0 and i <= a:
dem -= b//2 + (i%2)*(b%2)
i += 1
if dem > 0:
print(-1)
else:
dem = n//2 + n%2
demo = [2*k+1 for k in range(dem)]
rep = [2*k for k in range(1,n//2+1)]
d = 0
r = 0
l = 0
... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 2 2\n', 'output': '1 2 \n0 3 \n'}, {'type': 'stdin_stdout', 'input': '8 4 3\n', 'output': '1 2 3 \n4 5 6 \n7 8 0 \n0 0 0 \n'}, {'type': 'stdin_stdout', 'input': '10 2 2\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '1 1 1\n', 'output': '1 \n'}, {'type': 's... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/644/A'} | vfc_13394 | ```python
# You lost the game.
n, a, b = map(int, input().split())
dem = n//2 + n%2
i = 1
while dem > 0 and i <= a:
dem -= b//2 + (i%2)*(b%2)
i += 1
if dem > 0:
print(-1)
else:
dem = n//2 + n%2
demo = [2*k+1 for k in range(dem)]
rep = [2*k for k in range(1,n//2+1)]
d = 0
r = 0
l = 0
... | 3 2 2
| 1 2
0 3
| 1 2
0 3
| true | 2,382 |
apps | verifiable_code | 911 | Solve the following coding problem using the programming language python:
Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.
There will be n problems. The i-th problem has initial score p_{i} and it... | ```python
n,c = list(map(int, input().split()))
P = list(map(int, input().split()))
T = list(map(int, input().split()))
a = 0
t = 0
for i in range(n):
t += T[i]
a += max(0,P[i]-c*t)
t = 0
b = 0
for i in range(n-1,-1,-1):
t += T[i]
b += max(0,P[i]-c*t)
if a > b:
print("Limak")
elif a < b:
print("... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 2\n50 85 250\n10 15 25\n', 'output': 'Limak\n'}, {'type': 'stdin_stdout', 'input': '3 6\n50 85 250\n10 15 25\n', 'output': 'Radewoosh\n'}, {'type': 'stdin_stdout', 'input': '8 1\n10 20 30 40 50 60 70 80\n8 10 58 63 71 72 75 76\n', 'output': 'Tie\n'}, {'type': 'stdin_... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/658/A'} | vfc_13398 | ```python
n,c = list(map(int, input().split()))
P = list(map(int, input().split()))
T = list(map(int, input().split()))
a = 0
t = 0
for i in range(n):
t += T[i]
a += max(0,P[i]-c*t)
t = 0
b = 0
for i in range(n-1,-1,-1):
t += T[i]
b += max(0,P[i]-c*t)
if a > b:
print("Limak")
elif a < b:
print("... | 3 2
50 85 250
10 15 25
| Limak
| Limak
| true | 2,383 |
apps | verifiable_code | 912 | Solve the following coding problem using the programming language python:
Sakuzyo - Imprinting
A.R.C. Markland-N is a tall building with $n$ floors numbered from $1$ to $n$. Between each two adjacent floors in the building, there is a staircase connecting them.
It's lunchtime for our sensei Colin "ConneR" Neumann Jr... | ```python
t=int(input())
for i in range(t):
n,s,k=list(map(int,input().split()))
a=list(map(int,input().split()))
s=s-1
for i in range(n):
if (s-i)>-1:
if not (s-i+1) in a:
print(i)
break
if (s+i)<n:
if not (s+i+1) in a:
... | {'test_cases': [{'type': 'stdin_stdout', 'input': '5\n5 2 3\n1 2 3\n4 3 3\n4 1 2\n10 2 6\n1 2 3 4 5 7\n2 1 1\n2\n100 76 8\n76 75 36 67 41 74 10 77\n', 'output': '2\n0\n4\n0\n2\n'}, {'type': 'stdin_stdout', 'input': '2\n5 1 4\n3 2 1 4\n5 5 4\n4 5 2 3\n', 'output': '4\n4\n'}, {'type': 'stdin_stdout', 'input': '1\n10 3 3\... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1293/A'} | vfc_13402 | ```python
t=int(input())
for i in range(t):
n,s,k=list(map(int,input().split()))
a=list(map(int,input().split()))
s=s-1
for i in range(n):
if (s-i)>-1:
if not (s-i+1) in a:
print(i)
break
if (s+i)<n:
if not (s+i+1) in a:
... | 5
5 2 3
1 2 3
4 3 3
4 1 2
10 2 6
1 2 3 4 5 7
2 1 1
2
100 76 8
76 75 36 67 41 74 10 77
| 2
0
4
0
2
| 2
0
4
0
2
| true | 2,384 |
apps | verifiable_code | 913 | Solve the following coding problem using the programming language python:
Polycarp is preparing the first programming contest for robots. There are $n$ problems in it, and a lot of robots are going to participate in it. Each robot solving the problem $i$ gets $p_i$ points, and the score of each robot in the competitio... | ```python
n=int(input())
r = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
a=0
b=0
for i in range(n):
if r[i]==1 and s[i]==0:
a+=1
if r[i]==0 and s[i]==1:
b+=1
if a==0:
print(-1)
else:
print((b)//a+1)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '5\n1 1 1 0 0\n0 1 1 1 1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '3\n0 0 0\n0 0 0\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '4\n1 1 1 1\n1 1 1 1\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '9\n1 0 0 0 0 0 0 0 1\n0 1 1 0 1 1 1 ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1321/A'} | vfc_13406 | ```python
n=int(input())
r = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
a=0
b=0
for i in range(n):
if r[i]==1 and s[i]==0:
a+=1
if r[i]==0 and s[i]==1:
b+=1
if a==0:
print(-1)
else:
print((b)//a+1)
``` | 5
1 1 1 0 0
0 1 1 1 1
| 3
| 3
| true | 2,385 |
apps | verifiable_code | 914 | Solve the following coding problem using the programming language python:
Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Pie... | ```python
from collections import Counter
s = input()
n = int(input())
d = Counter()
for c in s:
d[c] += 1
if len(d) > n:
print(-1)
else:
left = 0
right = 10**10
s = ""
lastok = ("", 0)
while left + 1 < right:
mid = (left + right) // 2
s = ""
for (c, cnt) in list(... | {'test_cases': [{'type': 'stdin_stdout', 'input': 'banana\n4\n', 'output': '2\nbaan\n'}, {'type': 'stdin_stdout', 'input': 'banana\n3\n', 'output': '3\nnab\n'}, {'type': 'stdin_stdout', 'input': 'banana\n2\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': 'b\n1\n', 'output': '1\nb\n'}, {'type': 'stdin_stdout', '... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/335/A'} | vfc_13410 | ```python
from collections import Counter
s = input()
n = int(input())
d = Counter()
for c in s:
d[c] += 1
if len(d) > n:
print(-1)
else:
left = 0
right = 10**10
s = ""
lastok = ("", 0)
while left + 1 < right:
mid = (left + right) // 2
s = ""
for (c, cnt) in list(... | banana
4
| 2
baan
| 2
baan
| true | 2,386 |
apps | verifiable_code | 915 | Solve the following coding problem using the programming language python:
Karl likes Codeforces and subsequences. He wants to find a string of lowercase English letters that contains at least $k$ subsequences codeforces. Out of all possible strings, Karl wants to find a shortest one.
Formally, a codeforces subsequenc... | ```python
k = int(input())
codeforces = "codeforces"
ans = [1 for _ in range(len(codeforces))]
i = 0
tot = 1
while tot < k:
tot //= ans[i]
ans[i] += 1
tot *= ans[i]
i += 1
i %= len(codeforces)
for i in range(len(codeforces)):
print(codeforces[i] * ans[i], end = "")
print()
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '1\n', 'output': 'codeforces\n'}, {'type': 'stdin_stdout', 'input': '3\n', 'output': 'ccoodeforces\n'}, {'type': 'stdin_stdout', 'input': '421654016\n', 'output': 'ccccccccooooooooddddddddeeeeeeefffffffooooooorrrrrrrccccccceeeeeeesssssss\n'}, {'type': 'stdin_stdout', 'i... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1368/B'} | vfc_13414 | ```python
k = int(input())
codeforces = "codeforces"
ans = [1 for _ in range(len(codeforces))]
i = 0
tot = 1
while tot < k:
tot //= ans[i]
ans[i] += 1
tot *= ans[i]
i += 1
i %= len(codeforces)
for i in range(len(codeforces)):
print(codeforces[i] * ans[i], end = "")
print()
``` | 1
| codeforces
| codeforces
| true | 2,387 |
apps | verifiable_code | 916 | Solve the following coding problem using the programming language python:
Sagheer is playing a game with his best friend Soliman. He brought a tree with n nodes numbered from 1 to n and rooted at node 1. The i-th node has a_{i} apples. This tree has a special property: the lengths of all paths from the root to any lea... | ```python
def coloring(i, ancestors, color):
while i != 0 and color[ancestors[i - 1]] is None:
color[ancestors[i - 1]] = not color[i]
i = ancestors[i - 1]
def main():
n = int(input())
a = list(map(int, input().split()))
ancestors = list([int(x) - 1 for x in input().split()])
descen... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n2 2 3\n1 1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3\n1 2 3\n1 1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '8\n7 2 2 5 4 3 1 1\n1 1 1 4 4 5 6\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '6\n7 7 7 7 7 7\n1 1 1 1 1\n', 'outpu... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/812/E'} | vfc_13418 | ```python
def coloring(i, ancestors, color):
while i != 0 and color[ancestors[i - 1]] is None:
color[ancestors[i - 1]] = not color[i]
i = ancestors[i - 1]
def main():
n = int(input())
a = list(map(int, input().split()))
ancestors = list([int(x) - 1 for x in input().split()])
descen... | 3
2 2 3
1 1
| 1
| 1
| true | 2,388 |
apps | verifiable_code | 917 | Solve the following coding problem using the programming language python:
You are planning to build housing on a street. There are $n$ spots available on the street on which you can build a house. The spots are labeled from $1$ to $n$ from left to right. In each spot, you can build a house with an integer height betwe... | ```python
n, h, m = map(int, input().split())
a = [h] * n
for i in range(m):
l, r, x = map(int, input().split())
for i in range(l - 1, r):
a[i] = min(a[i], x)
s = 0
for i in range(n):
s += a[i] ** 2
print(s)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 3 3\n1 1 1\n2 2 3\n3 3 2\n', 'output': '14\n'}, {'type': 'stdin_stdout', 'input': '4 10 2\n2 3 8\n3 4 7\n', 'output': '262\n'}, {'type': 'stdin_stdout', 'input': '50 50 1\n1 50 0\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '50 50 50\n17 40 12\n33 36 47\n8... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1162/A'} | vfc_13422 | ```python
n, h, m = map(int, input().split())
a = [h] * n
for i in range(m):
l, r, x = map(int, input().split())
for i in range(l - 1, r):
a[i] = min(a[i], x)
s = 0
for i in range(n):
s += a[i] ** 2
print(s)
``` | 3 3 3
1 1 1
2 2 3
3 3 2
| 14
| 14
| true | 2,389 |
apps | verifiable_code | 918 | Solve the following coding problem using the programming language python:
Very soon Berland will hold a School Team Programming Olympiad. From each of the m Berland regions a team of two people is invited to participate in the olympiad. The qualifying contest to form teams was held and it was attended by n Berland stu... | ```python
from collections import defaultdict
n, m = list(map(int, input().split()))
data = defaultdict(dict)
for _ in range(n):
name, region, score = input().split()
region = int(region)
score = int(score)
if region not in data:
data[region] = defaultdict(list)
data[region][score].append(... | {'test_cases': [{'type': 'stdin_stdout', 'input': '5 2\nIvanov 1 763\nAndreev 2 800\nPetrov 1 595\nSidorov 1 790\nSemenov 2 503\n', 'output': 'Sidorov Ivanov\nAndreev Semenov\n'}, {'type': 'stdin_stdout', 'input': '5 2\nIvanov 1 800\nAndreev 2 763\nPetrov 1 800\nSidorov 1 800\nSemenov 2 503\n', 'output': '?\nAndreev Se... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/659/B'} | vfc_13426 | ```python
from collections import defaultdict
n, m = list(map(int, input().split()))
data = defaultdict(dict)
for _ in range(n):
name, region, score = input().split()
region = int(region)
score = int(score)
if region not in data:
data[region] = defaultdict(list)
data[region][score].append(... | 5 2
Ivanov 1 763
Andreev 2 800
Petrov 1 595
Sidorov 1 790
Semenov 2 503
| Sidorov Ivanov
Andreev Semenov
| Sidorov Ivanov
Andreev Semenov
| true | 2,390 |
apps | verifiable_code | 919 | Solve the following coding problem using the programming language python:
Natasha is going to fly to Mars. She needs to build a rocket, which consists of several stages in some order. Each of the stages is defined by a lowercase Latin letter. This way, the rocket can be described by the string — concatenation of lette... | ```python
n, k = map(int, input().split())
s = sorted(list(input()))
prev = 0
w = 0
for el in s:
if k == 0:
break
if ord(el) >= prev + 2:
k -= 1
w += ord(el) - ord('a') + 1
prev = ord(el)
if k == 0:
print(w)
else:
print(-1)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '5 3\nxyabd\n', 'output': '29'}, {'type': 'stdin_stdout', 'input': '7 4\nproblem\n', 'output': '34'}, {'type': 'stdin_stdout', 'input': '2 2\nab\n', 'output': '-1'}, {'type': 'stdin_stdout', 'input': '12 1\nabaabbaaabbb\n', 'output': '1'}, {'type': 'stdin_stdout', 'inpu... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1011/A'} | vfc_13430 | ```python
n, k = map(int, input().split())
s = sorted(list(input()))
prev = 0
w = 0
for el in s:
if k == 0:
break
if ord(el) >= prev + 2:
k -= 1
w += ord(el) - ord('a') + 1
prev = ord(el)
if k == 0:
print(w)
else:
print(-1)
``` | 5 3
xyabd
| 29 | 29
| true | 2,391 |
apps | verifiable_code | 920 | Solve the following coding problem using the programming language python:
Nothing has changed since the last round. Dima and Inna still love each other and want to be together. They've made a deal with Seryozha and now they need to make a deal with the dorm guards...
There are four guardposts in Dima's dorm. Each pos... | ```python
L = lambda: list(map(int, input().split()))
I = lambda: int(input())
n, t = I(), [L() for i in range(4)]
p = [min(i[0], i[1]) + min(i[2], i[3]) for i in t]
x = min(p)
if x > n: print(-1)
else:
k = p.index(x)
p = min(t[k][0], t[k][1])
print(k + 1, p, n - p)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '10\n5 6 5 6\n6 6 7 7\n5 8 6 6\n9 9 9 9\n', 'output': '1 5 5\n'}, {'type': 'stdin_stdout', 'input': '10\n6 6 6 6\n7 7 7 7\n4 4 4 4\n8 8 8 8\n', 'output': '3 4 6\n'}, {'type': 'stdin_stdout', 'input': '5\n3 3 3 3\n3 3 3 3\n3 3 3 3\n3 3 3 3\n', 'output': '-1\n'}, {'type':... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/366/A'} | vfc_13434 | ```python
L = lambda: list(map(int, input().split()))
I = lambda: int(input())
n, t = I(), [L() for i in range(4)]
p = [min(i[0], i[1]) + min(i[2], i[3]) for i in t]
x = min(p)
if x > n: print(-1)
else:
k = p.index(x)
p = min(t[k][0], t[k][1])
print(k + 1, p, n - p)
``` | 10
5 6 5 6
6 6 7 7
5 8 6 6
9 9 9 9
| 1 5 5
| 1 5 5
| true | 2,392 |
apps | verifiable_code | 921 | Solve the following coding problem using the programming language python:
Polycarp invited all his friends to the tea party to celebrate the holiday. He has n cups, one for each of his n friends, with volumes a_1, a_2, ..., a_{n}. His teapot stores w milliliters of tea (w ≤ a_1 + a_2 + ... + a_{n}). Polycarp wants to ... | ```python
n, w = list(map(int, input().split()))
Cup = list(map(int, input().split()))
Water = []
for a in Cup:
Water.append((a + 1) // 2)
res = w - sum(Water)
if res < 0:
print(-1)
else:
while res > 0:
i = Cup.index(max(Cup))
num = min(res, Cup[i] - Water[i])
Water[i] += num
... | {'test_cases': [{'type': 'stdin_stdout', 'input': '2 10\n8 7\n', 'output': '6 4 \n'}, {'type': 'stdin_stdout', 'input': '4 4\n1 1 1 1\n', 'output': '1 1 1 1 \n'}, {'type': 'stdin_stdout', 'input': '3 10\n9 8 10\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '1 1\n1\n', 'output': '1 \n'}, {'type': 'stdin_stdou... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/808/C'} | vfc_13438 | ```python
n, w = list(map(int, input().split()))
Cup = list(map(int, input().split()))
Water = []
for a in Cup:
Water.append((a + 1) // 2)
res = w - sum(Water)
if res < 0:
print(-1)
else:
while res > 0:
i = Cup.index(max(Cup))
num = min(res, Cup[i] - Water[i])
Water[i] += num
... | 2 10
8 7
| 6 4
| 6 4
| true | 2,393 |
apps | verifiable_code | 922 | Solve the following coding problem using the programming language python:
Polycarp has n dice d_1, d_2, ..., d_{n}. The i-th dice shows numbers from 1 to d_{i}. Polycarp rolled all the dice and the sum of numbers they showed is A. Agrippina didn't see which dice showed what number, she knows only the sum A and the val... | ```python
n, s = list(map(int, input().split()))
a = list(map(int, input().split()))
total = sum(a)
ans = []
for i in range(n):
high = s - (total - a[i])
low = s - (n - 1)
cur = 0
if low <= a[i]:
cur += a[i] - low
if high > 0:
cur += high - 1
ans.append(cur)
print(' '.jo... | {'test_cases': [{'type': 'stdin_stdout', 'input': '2 8\n4 4\n', 'output': '3 3 '}, {'type': 'stdin_stdout', 'input': '1 3\n5\n', 'output': '4 '}, {'type': 'stdin_stdout', 'input': '2 3\n2 3\n', 'output': '0 1 '}, {'type': 'stdin_stdout', 'input': '1 1\n3\n', 'output': '2 '}, {'type': 'stdin_stdout', 'input': '1 2\n3\n'... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/534/C'} | vfc_13442 | ```python
n, s = list(map(int, input().split()))
a = list(map(int, input().split()))
total = sum(a)
ans = []
for i in range(n):
high = s - (total - a[i])
low = s - (n - 1)
cur = 0
if low <= a[i]:
cur += a[i] - low
if high > 0:
cur += high - 1
ans.append(cur)
print(' '.jo... | 2 8
4 4
| 3 3 | 3 3
| true | 2,394 |
apps | verifiable_code | 925 | Solve the following coding problem using the programming language python:
Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by t... | ```python
# -*- coding: utf-8 -*-
ngoods = {
'0': 2,
'1': 7,
'2': 2,
'3': 3,
'4': 3,
'5': 4,
'6': 2,
'7': 5,
'8': 1,
'9': 2
}
digits = input().strip()
print(ngoods[digits[0]] * ngoods[digits[1]])
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '89\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '00\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '73\n', 'output': '15\n'}, {'type': 'stdin_stdout', 'input': '08\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '26\n', 'output': '4\n'}, {'t... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/495/A'} | vfc_13454 | ```python
# -*- coding: utf-8 -*-
ngoods = {
'0': 2,
'1': 7,
'2': 2,
'3': 3,
'4': 3,
'5': 4,
'6': 2,
'7': 5,
'8': 1,
'9': 2
}
digits = input().strip()
print(ngoods[digits[0]] * ngoods[digits[1]])
``` | 89
| 2
| 2
| true | 2,395 |
apps | verifiable_code | 926 | Solve the following coding problem using the programming language python:
Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble f... | ```python
n = int(input())
mv = 0
mn = []
data = {}
for i in range (n):
cur = list(sorted(map(int, input().split())))
key = (cur[1], cur[2])
if key in data:
old, k = data[key]
res = [old + cur[0], cur[1], cur[2]]
m = min(res)
if m > mv:
mv = m
mn = [k, i]
if old < cur[0]:
da... | {'test_cases': [{'type': 'stdin_stdout', 'input': '6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4\n', 'output': '1\n1\n'}, {'type': 'stdin_stdout', 'input': '7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7\n', 'output': '2\n1 5\n'}, {'type': 'stdin_stdout', 'input': '1\n1 1 1\n', 'output': '1\n1\n'}, {'type': 'stdin... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/733/D'} | vfc_13458 | ```python
n = int(input())
mv = 0
mn = []
data = {}
for i in range (n):
cur = list(sorted(map(int, input().split())))
key = (cur[1], cur[2])
if key in data:
old, k = data[key]
res = [old + cur[0], cur[1], cur[2]]
m = min(res)
if m > mv:
mv = m
mn = [k, i]
if old < cur[0]:
da... | 6
5 5 5
3 2 4
1 4 1
2 1 3
3 2 4
3 3 4
| 1
1
| 1
1
| true | 2,396 |
apps | verifiable_code | 927 | Solve the following coding problem using the programming language python:
Find the largest integer that can be formed with exactly N matchsticks, under the following conditions:
- Every digit in the integer must be one of the digits A_1, A_2, ..., A_M (1 \leq A_i \leq 9).
- The number of matchsticks used to form dig... | ```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]+[-1]*(9*n)
l=[0,2,5,5,4,5,6,3,7,6]
for i in range(n):
for j in a:
if dp[i]>=0:
dp[i+l[j]]=max(dp[i+l[j]],dp[i]*10+j)
print(dp[n])
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '20 4\n3 7 8 4\n', 'output': '777773\n'}, {'type': 'stdin_stdout', 'input': '101 9\n9 8 7 6 5 4 3 2 1\n', 'output': '71111111111111111111111111111111111111111111111111\n'}, {'type': 'stdin_stdout', 'input': '15 3\n5 4 6\n', 'output': '654\n'}, {'type': 'stdin_stdout', '... | {'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc118/tasks/abc118_d'} | vfc_13462 | ```python
n,m=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]+[-1]*(9*n)
l=[0,2,5,5,4,5,6,3,7,6]
for i in range(n):
for j in a:
if dp[i]>=0:
dp[i+l[j]]=max(dp[i+l[j]],dp[i]*10+j)
print(dp[n])
``` | 20 4
3 7 8 4
| 777773
| 777773
| true | 2,397 |
apps | verifiable_code | 928 | Solve the following coding problem using the programming language python:
You are given a sequence of positive integers of length N, A=a_1,a_2,…,a_{N}, and an integer K.
How many contiguous subsequences of A satisfy the following condition?
- (Condition) The sum of the elements in the contiguous subsequence is at lea... | ```python
N,K=map(int,input().split())
A=list(map(int,input().split()))
l=0
r=0
s=A[0]
ans=0
while True:
if s>=K:
ans+=N-r
s-=A[l]
l+=1
else:
if r<N-1:
r+=1
s+=A[r]
else:
break
print(ans)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '4 10\n6 1 2 7\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3 5\n3 3 3\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '10 53462\n103 35322 232 342 21099 90000 18843 9010 35221 19352\n', 'output': '36\n'}, {'type': 'stdin_stdout', 'input': '1 4\n3\n'... | {'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc130/tasks/abc130_d'} | vfc_13466 | ```python
N,K=map(int,input().split())
A=list(map(int,input().split()))
l=0
r=0
s=A[0]
ans=0
while True:
if s>=K:
ans+=N-r
s-=A[l]
l+=1
else:
if r<N-1:
r+=1
s+=A[r]
else:
break
print(ans)
``` | 4 10
6 1 2 7
| 2
| 2
| true | 2,398 |
apps | verifiable_code | 930 | Solve the following coding problem using the programming language python:
There is a building with n rooms, numbered 1 to n.
We can move from any room to any other room in the building.
Let us call the following event a move: a person in some room i goes to another room j~ (i \neq j).
Initially, there was one person i... | ```python
mod = int(1e9) + 7 # <-- input modulo
maxf = 500000 # <-- input factional limitation
def make_fact(n, k):
tmp = n
perm = [i for i in range(k)]
L = [0 for _ in range(k)]
for i in range(k):
L[i] = tmp % (i + 1)
tmp //= i + 1
LL = [0 for _ in range(k)]
for i in ... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 2\n', 'output': '10\n'}, {'type': 'stdin_stdout', 'input': '200000 1000000000\n', 'output': '607923868\n'}, {'type': 'stdin_stdout', 'input': '15 6\n', 'output': '22583772\n'}, {'type': 'stdin_stdout', 'input': '200000 2\n', 'output': '55718971\n'}, {'type': 'stdin_s... | {'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc156/tasks/abc156_e'} | vfc_13474 | ```python
mod = int(1e9) + 7 # <-- input modulo
maxf = 500000 # <-- input factional limitation
def make_fact(n, k):
tmp = n
perm = [i for i in range(k)]
L = [0 for _ in range(k)]
for i in range(k):
L[i] = tmp % (i + 1)
tmp //= i + 1
LL = [0 for _ in range(k)]
for i in ... | 3 2
| 10
| 10
| true | 2,400 |
apps | verifiable_code | 931 | Solve the following coding problem using the programming language python:
Inna and Dima decided to surprise Sereja. They brought a really huge candy matrix, it's big even for Sereja! Let's number the rows of the giant matrix from 1 to n from top to bottom and the columns — from 1 to m, from left to right. We'll repres... | ```python
n, m, x, y, z, p = list(map(int, input().split()))
n, m, x, y, z = n + 1, m + 1, x % 4, y % 2, (4 - z) % 4
def a(i, j, n, m, k):
if k == 0: return i, j, n, m
if k == 1: return j, n - i, m, n
if k == 2: return n - i, m - j, n, m
return m - j, i, m, n
def b(i, j, m, k):
if k == 0: return i... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 3 3 1 1 9\n1 1\n1 2\n1 3\n2 1\n2 2\n2 3\n3 1\n3 2\n3 3\n', 'output': '1 3\n1 2\n1 1\n2 3\n2 2\n2 1\n3 3\n3 2\n3 1\n'}, {'type': 'stdin_stdout', 'input': '5 5 0 0 0 1\n1 4\n', 'output': '1 4\n'}, {'type': 'stdin_stdout', 'input': '14 76 376219315 550904689 16684615 24... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/400/C'} | vfc_13478 | ```python
n, m, x, y, z, p = list(map(int, input().split()))
n, m, x, y, z = n + 1, m + 1, x % 4, y % 2, (4 - z) % 4
def a(i, j, n, m, k):
if k == 0: return i, j, n, m
if k == 1: return j, n - i, m, n
if k == 2: return n - i, m - j, n, m
return m - j, i, m, n
def b(i, j, m, k):
if k == 0: return i... | 3 3 3 1 1 9
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
| 1 3
1 2
1 1
2 3
2 2
2 1
3 3
3 2
3 1
| 1 3
1 2
1 1
2 3
2 2
2 1
3 3
3 2
3 1
| true | 2,401 |
apps | verifiable_code | 934 | Solve the following coding problem using the programming language python:
Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau".
To play Mau-Mau, you need a pack ... | ```python
c = input()
s = list(input().split())
print('YES' if any(c[0] == x[0] or c[1] == x[1] for x in s) else 'NO')
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': 'AS\n2H 4C TH JH AD\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '2H\n3D 4C AC KD AS\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '4D\nAS AC AD AH 5H\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '3D\n8S 4S 2C AS 6H\n', 'output': 'NO... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1097/A'} | vfc_13490 | ```python
c = input()
s = list(input().split())
print('YES' if any(c[0] == x[0] or c[1] == x[1] for x in s) else 'NO')
``` | AS
2H 4C TH JH AD
| YES
| YES
| true | 2,402 |
apps | verifiable_code | 935 | Solve the following coding problem using the programming language python:
After winning gold and silver in IOI 2014, Akshat and Malvika want to have some fun. Now they are playing a game on a grid made of n horizontal and m vertical sticks.
An intersection point is any point on the grid which is formed by the interse... | ```python
a, b = list(map(int, input().split()))
print('Malvika' if min(a, b) % 2 == 0 else 'Akshat')
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '2 2\n', 'output': 'Malvika\n'}, {'type': 'stdin_stdout', 'input': '2 3\n', 'output': 'Malvika\n'}, {'type': 'stdin_stdout', 'input': '3 3\n', 'output': 'Akshat\n'}, {'type': 'stdin_stdout', 'input': '20 68\n', 'output': 'Malvika\n'}, {'type': 'stdin_stdout', 'input': '... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/451/A'} | vfc_13494 | ```python
a, b = list(map(int, input().split()))
print('Malvika' if min(a, b) % 2 == 0 else 'Akshat')
``` | 2 2
| Malvika
| Malvika
| true | 2,403 |
apps | verifiable_code | 936 | Solve the following coding problem using the programming language python:
After celebrating the midcourse the students of one of the faculties of the Berland State University decided to conduct a vote for the best photo. They published the photos in the social network and agreed on the rules to choose a winner: the ph... | ```python
n = int(input())
a = [int(x) for x in input().split()]
score = dict()
sup, winner = -2**31, None
for v in a:
score[v] = score[v] + 1 if v in score else 1
if score[v] > sup:
sup, winner = score[v], v
print(winner)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '5\n1 3 2 2 1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '9\n100 200 300 200 100 300 300 100 200\n', 'output': '300\n'}, {'type': 'stdin_stdout', 'input': '1\n5\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '1\n1000000\n', 'output': '1000000\n'}, ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/637/A'} | vfc_13498 | ```python
n = int(input())
a = [int(x) for x in input().split()]
score = dict()
sup, winner = -2**31, None
for v in a:
score[v] = score[v] + 1 if v in score else 1
if score[v] > sup:
sup, winner = score[v], v
print(winner)
``` | 5
1 3 2 2 1
| 2
| 2
| true | 2,404 |
apps | verifiable_code | 937 | Solve the following coding problem using the programming language python:
Your friend Mishka and you attend a calculus lecture. Lecture lasts n minutes. Lecturer tells a_{i} theorems during the i-th minute.
Mishka is really interested in calculus, though it is so hard to stay awake for all the time of lecture. You ar... | ```python
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
mask = list(map(int, input().split()))
result = sum(a[i] if mask[i] == 1 else 0 for i in range(n))
h = [a[i] if mask[i] == 0 else 0 for i in range(len(a))]
best_awake = sum(h[:k])
curr = best_awake
for j in range(k, n):
curr += h... | {'test_cases': [{'type': 'stdin_stdout', 'input': '6 3\n1 3 5 2 5 4\n1 1 0 1 0 0\n', 'output': '16\n'}, {'type': 'stdin_stdout', 'input': '5 3\n1 9999 10000 10000 10000\n0 0 0 0 0\n', 'output': '30000\n'}, {'type': 'stdin_stdout', 'input': '3 3\n10 10 10\n1 1 0\n', 'output': '30\n'}, {'type': 'stdin_stdout', 'input': '... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/961/B'} | vfc_13502 | ```python
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
mask = list(map(int, input().split()))
result = sum(a[i] if mask[i] == 1 else 0 for i in range(n))
h = [a[i] if mask[i] == 0 else 0 for i in range(len(a))]
best_awake = sum(h[:k])
curr = best_awake
for j in range(k, n):
curr += h... | 6 3
1 3 5 2 5 4
1 1 0 1 0 0
| 16
| 16
| true | 2,405 |
apps | verifiable_code | 940 | Solve the following coding problem using the programming language python:
Masha has three sticks of length $a$, $b$ and $c$ centimeters respectively. In one minute Masha can pick one arbitrary stick and increase its length by one centimeter. She is not allowed to break sticks.
What is the minimum number of minutes sh... | ```python
a, b, c = sorted(map(int, input().split()))
print(max(0, c - a - b + 1))
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 4 5\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '2 5 3\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '100 10 10\n', 'output': '81\n'}, {'type': 'stdin_stdout', 'input': '1 1 1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '100 100 100\... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1064/A'} | vfc_13514 | ```python
a, b, c = sorted(map(int, input().split()))
print(max(0, c - a - b + 1))
``` | 3 4 5
| 0
| 0
| true | 2,408 |
apps | verifiable_code | 941 | Solve the following coding problem using the programming language python:
You are given an integer $n$ ($n \ge 0$) represented with $k$ digits in base (radix) $b$. So,
$$n = a_1 \cdot b^{k-1} + a_2 \cdot b^{k-2} + \ldots a_{k-1} \cdot b + a_k.$$
For example, if $b=17, k=3$ and $a=[11, 15, 7]$ then $n=11\cdot17^2+15\... | ```python
b,k = map(int, input().split())
a = list(map(int, input().split()))
r = 0
for x in a:
r = (r*b+x) % 2
if r == 0:
print('even')
else:
print('odd')
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '13 3\n3 2 7\n', 'output': 'even\n'}, {'type': 'stdin_stdout', 'input': '10 9\n1 2 3 4 5 6 7 8 9\n', 'output': 'odd\n'}, {'type': 'stdin_stdout', 'input': '99 5\n32 92 85 74 4\n', 'output': 'odd\n'}, {'type': 'stdin_stdout', 'input': '2 2\n1 0\n', 'output': 'even\n'}, {... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1110/A'} | vfc_13518 | ```python
b,k = map(int, input().split())
a = list(map(int, input().split()))
r = 0
for x in a:
r = (r*b+x) % 2
if r == 0:
print('even')
else:
print('odd')
``` | 13 3
3 2 7
| even
| even
| true | 2,409 |
apps | verifiable_code | 943 | Solve the following coding problem using the programming language python:
Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from t... | ```python
def main():
n = int(input())
a = [int(i) for i in input().split()]
cnt = 0
mi = 10 ** 9
for i in a:
if i % 2 == 1:
cnt ^= 1
mi = min(mi, i)
if not cnt:
mi = 0
print(sum(a) - mi)
main()
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 2 3\n', 'output': '6'}, {'type': 'stdin_stdout', 'input': '5\n999999999 999999999 999999999 999999999 999999999\n', 'output': '3999999996'}, {'type': 'stdin_stdout', 'input': '1\n1\n', 'output': '0'}, {'type': 'stdin_stdout', 'input': '15\n39 52 88 78 46 95 84 98 ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/621/A'} | vfc_13526 | ```python
def main():
n = int(input())
a = [int(i) for i in input().split()]
cnt = 0
mi = 10 ** 9
for i in a:
if i % 2 == 1:
cnt ^= 1
mi = min(mi, i)
if not cnt:
mi = 0
print(sum(a) - mi)
main()
``` | 3
1 2 3
| 6 | 6
| true | 2,410 |
apps | verifiable_code | 945 | Solve the following coding problem using the programming language python:
Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework.
The teacher gave Seryozha the coordinates of n d... | ```python
def Intersect(aa,bb,xx,yy):
a=min(aa,bb)
b=max(aa,bb)
x=min(xx,yy)
y=max(xx,yy)
if(a>=x and b<=y):
return False
if(x>=a and y<=b):
return False
if(b<=x):
return False
if(y<=a):
return False
return True
N=int(input())
case=False
L=list... | {'test_cases': [{'type': 'stdin_stdout', 'input': '4\n0 10 5 15\n', 'output': 'yes\n'}, {'type': 'stdin_stdout', 'input': '4\n0 15 5 10\n', 'output': 'no\n'}, {'type': 'stdin_stdout', 'input': '5\n0 1000 2000 3000 1500\n', 'output': 'yes\n'}, {'type': 'stdin_stdout', 'input': '5\n-724093 710736 -383722 -359011 439613\n... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/358/A'} | vfc_13534 | ```python
def Intersect(aa,bb,xx,yy):
a=min(aa,bb)
b=max(aa,bb)
x=min(xx,yy)
y=max(xx,yy)
if(a>=x and b<=y):
return False
if(x>=a and y<=b):
return False
if(b<=x):
return False
if(y<=a):
return False
return True
N=int(input())
case=False
L=list... | 4
0 10 5 15
| yes
| yes
| true | 2,411 |
apps | verifiable_code | 946 | Solve the following coding problem using the programming language python:
When preparing a tournament, Codeforces coordinators try treir best to make the first problem as easy as possible. This time the coordinator had chosen some problem and asked $n$ people about their opinions. Each person answered whether this pro... | ```python
input()
l = list(map(int, input().split()))
if 1 in l:
print('HARD')
else:
print('EASY')
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n0 0 1\n', 'output': 'HARD\n'}, {'type': 'stdin_stdout', 'input': '1\n0\n', 'output': 'EASY\n'}, {'type': 'stdin_stdout', 'input': '1\n1\n', 'output': 'HARD\n'}, {'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... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1030/A'} | vfc_13538 | ```python
input()
l = list(map(int, input().split()))
if 1 in l:
print('HARD')
else:
print('EASY')
``` | 3
0 0 1
| HARD
| HARD
| true | 2,412 |
apps | verifiable_code | 947 | Solve the following coding problem using the programming language python:
In Omkar's last class of math, he learned about the least common multiple, or $LCM$. $LCM(a, b)$ is the smallest positive integer $x$ which is divisible by both $a$ and $b$.
Omkar, having a laudably curious mind, immediately thought of a proble... | ```python
from math import sqrt
def solve():
n = int(input())
for i in range(2, int(sqrt(n)) + 1):
if n % i == 0:
x = n // i
print(x, x * (i-1))
return
print(n-1,1)
for i in range(int(input())):
solve()
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n4\n6\n9\n', 'output': '2 2\n3 3\n3 6\n'}, {'type': 'stdin_stdout', 'input': '3\n4\n5\n2\n', 'output': '2 2\n1 4\n1 1\n'}, {'type': 'stdin_stdout', 'input': '8\n527\n622\n63\n423\n147\n791\n838\n903\n', 'output': '31 496\n311 311\n21 42\n141 282\n49 98\n113 678\n419 ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1372/B'} | vfc_13542 | ```python
from math import sqrt
def solve():
n = int(input())
for i in range(2, int(sqrt(n)) + 1):
if n % i == 0:
x = n // i
print(x, x * (i-1))
return
print(n-1,1)
for i in range(int(input())):
solve()
``` | 3
4
6
9
| 2 2
3 3
3 6
| 2 2
3 3
3 6
| true | 2,413 |
apps | verifiable_code | 948 | Solve the following coding problem using the programming language python:
The developers of Looksery have to write an efficient algorithm that detects faces on a picture. Unfortunately, they are currently busy preparing a contest for you, so you will have to do it for them.
In this problem an image is a rectangular ... | ```python
n, m = list(map(int, input().split()))
field = []
for i in range(n):
field.append(input())
ans = 0
for i in range(n - 1):
for j in range(m - 1):
t = set()
t.add(field[i][j])
t.add(field[i + 1][j + 1])
t.add(field[i + 1][j])
t.add(field[i][j + 1])
if t... | {'test_cases': [{'type': 'stdin_stdout', 'input': '4 4\nxxxx\nxfax\nxcex\nxxxx\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '4 2\nxx\ncf\nae\nxx\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '2 3\nfac\ncef\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '1 4\nface\n', 'output': '0\n'}, {'ty... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/549/A'} | vfc_13546 | ```python
n, m = list(map(int, input().split()))
field = []
for i in range(n):
field.append(input())
ans = 0
for i in range(n - 1):
for j in range(m - 1):
t = set()
t.add(field[i][j])
t.add(field[i + 1][j + 1])
t.add(field[i + 1][j])
t.add(field[i][j + 1])
if t... | 4 4
xxxx
xfax
xcex
xxxx
| 1
| 1
| true | 2,414 |
apps | verifiable_code | 949 | Solve the following coding problem using the programming language python:
Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, ... | ```python
a,b = input().split()
if (a==b):
print(a)
else:
print(1)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '1 2\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '61803398874989484820458683436563811772030917980576 61803398874989484820458683436563811772030917980576\n', 'output': '61803398874989484820458683436563811772030917980576\n'}, {'type': 'stdin_stdout', 'input': '... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/664/A'} | vfc_13550 | ```python
a,b = input().split()
if (a==b):
print(a)
else:
print(1)
``` | 1 2
| 1
| 1
| true | 2,415 |
apps | verifiable_code | 950 | Solve the following coding problem using the programming language python:
After overcoming the stairs Dasha came to classes. She needed to write a password to begin her classes. The password is a string of length n which satisfies the following requirements: There is at least one digit in the string, There is at lea... | ```python
import math, re, itertools as it;prime = lambda n: len([i for i in range(2, int(math.sqrt(n) + 1)) if n % i == 0]) == 0;gcd = lambda a, b: gcd(b, a % b) if b else a;fact = lambda x: x * fact(x - 1) if x else 1;bino = lambda n, k: fact(n) / fact(k) / fact(n - k);fib11 = lambda n: 1 if n < 2 else fib11(n - 1) +... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 4\n1**2\na3*0\nc4**\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '5 5\n#*&#*\n*a1c&\n&q2w*\n#a3c#\n*&#*&\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '5 2\n&l\n*0\n*9\n*#\n#o\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '25 16\nvza**o... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/761/C'} | vfc_13554 | ```python
import math, re, itertools as it;prime = lambda n: len([i for i in range(2, int(math.sqrt(n) + 1)) if n % i == 0]) == 0;gcd = lambda a, b: gcd(b, a % b) if b else a;fact = lambda x: x * fact(x - 1) if x else 1;bino = lambda n, k: fact(n) / fact(k) / fact(n - k);fib11 = lambda n: 1 if n < 2 else fib11(n - 1) +... | 3 4
1**2
a3*0
c4**
| 1
| 1
| true | 2,416 |
apps | verifiable_code | 951 | Solve the following coding problem using the programming language python:
Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change.
... | ```python
k = int(input())
n = input()
digit = [0]*10
for c in n:
digit[int(c)]+= 1
dsum = sum(i*digit[i] for i in range(10))
i = 0
change = 0
while dsum < k:
if digit[i] == 0:
i+= 1
continue
digit[i]-= 1
digit[9]+= 1
change+= 1
dsum+= 9-i
print(change)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n11\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3\n99\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '10\n5205602270\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '70\n3326631213\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/835/B'} | vfc_13558 | ```python
k = int(input())
n = input()
digit = [0]*10
for c in n:
digit[int(c)]+= 1
dsum = sum(i*digit[i] for i in range(10))
i = 0
change = 0
while dsum < k:
if digit[i] == 0:
i+= 1
continue
digit[i]-= 1
digit[9]+= 1
change+= 1
dsum+= 9-i
print(change)
``` | 3
11
| 1
| 1
| true | 2,417 |
apps | verifiable_code | 952 | Solve the following coding problem using the programming language python:
Andrew prefers taxi to other means of transport, but recently most taxi drivers have been acting inappropriately. In order to earn more money, taxi drivers started to drive in circles. Roads in Andrew's city are one-way, and people are not neces... | ```python
# problem http://codeforces.com/contest/1100/problem/E
import copy
import sys
def find_loop(g, w, k, n):
visited = [False] * n
visited_int = [False] * n
for i in range(n):
if visited[i]:
continue
stack = [g[i][:]]
path = [i]
visited[i] = True
v... | {'test_cases': [{'type': 'stdin_stdout', 'input': '5 6\n2 1 1\n5 2 6\n2 3 2\n3 4 3\n4 5 5\n1 5 4\n', 'output': '2 2\n1 3 '}, {'type': 'stdin_stdout', 'input': '5 7\n2 1 5\n3 2 3\n1 3 3\n2 4 1\n4 3 5\n5 4 1\n1 5 3\n', 'output': '3 3\n3 4 7 '}, {'type': 'stdin_stdout', 'input': '10 45\n5 6 8\n9 4 8\n7 1 1\n9 7 1\n7 2 1\n... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1100/E'} | vfc_13562 | ```python
# problem http://codeforces.com/contest/1100/problem/E
import copy
import sys
def find_loop(g, w, k, n):
visited = [False] * n
visited_int = [False] * n
for i in range(n):
if visited[i]:
continue
stack = [g[i][:]]
path = [i]
visited[i] = True
v... | 5 6
2 1 1
5 2 6
2 3 2
3 4 3
4 5 5
1 5 4
| 2 2
1 3 | 2 2
1 3
| true | 2,418 |
apps | verifiable_code | 953 | Solve the following coding problem using the programming language python:
User ainta has a permutation p_1, p_2, ..., p_{n}. As the New Year is coming, he wants to make his permutation as pretty as possible.
Permutation a_1, a_2, ..., a_{n} is prettier than permutation b_1, b_2, ..., b_{n}, if and only if there exist... | ```python
"""
Codeforces Contest Good Bye 2014 Contest Problem B
Author : chaotic_iak
Language: Python 3.4.2
"""
################################################### SOLUTION
def main():
n, = read()
p = read()
dsu = DSU()
for i in range(n):
a = read(0)
dsu.make()
for j in rang... | {'test_cases': [{'type': 'stdin_stdout', 'input': '7\n5 2 4 3 6 7 1\n0001001\n0000000\n0000010\n1000001\n0000000\n0010000\n1001000\n', 'output': '1 2 4 3 6 7 5\n'}, {'type': 'stdin_stdout', 'input': '5\n4 2 1 5 3\n00100\n00011\n10010\n01101\n01010\n', 'output': '1 2 3 4 5\n'}, {'type': 'stdin_stdout', 'input': '7\n1 7 ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/500/B'} | vfc_13566 | ```python
"""
Codeforces Contest Good Bye 2014 Contest Problem B
Author : chaotic_iak
Language: Python 3.4.2
"""
################################################### SOLUTION
def main():
n, = read()
p = read()
dsu = DSU()
for i in range(n):
a = read(0)
dsu.make()
for j in rang... | 7
5 2 4 3 6 7 1
0001001
0000000
0000010
1000001
0000000
0010000
1001000
| 1 2 4 3 6 7 5
| 1 2 4 3 6 7 5 | true | 2,419 |
apps | verifiable_code | 954 | Solve the following coding problem using the programming language python:
Hongcow is learning to spell! One day, his teacher gives him a word that he needs to learn to spell. Being a dutiful student, he immediately learns how to spell the word.
Hongcow has decided to try to make new words from this one. He starts by ... | ```python
s = input()
res = set()
for i in range(len(s) + 5):
s = s[1:] + s[0]
res.add(s)
print(len(list(res)))
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': 'abcd\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': 'bbb\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': 'yzyz\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': 'abcdefghijklmnopqrstuvwxyabcdefghijklmnopqrstuvwxy\n', 'output': '25\n'}, {'type': '... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/745/A'} | vfc_13570 | ```python
s = input()
res = set()
for i in range(len(s) + 5):
s = s[1:] + s[0]
res.add(s)
print(len(list(res)))
``` | abcd
| 4
| 4
| true | 2,420 |
apps | verifiable_code | 955 | Solve the following coding problem using the programming language python:
Berland shop sells $n$ kinds of juices. Each juice has its price $c_i$. Each juice includes some set of vitamins in it. There are three types of vitamins: vitamin "A", vitamin "B" and vitamin "C". Each juice can contain one, two or all three typ... | ```python
n = int(input())
def func(v):
res = 0
if "A" in v: res |= 1
if "B" in v: res |= 2
if "C" in v: res |= 4
return res
cost = [10 ** 10] * 8
cost[0] = 0
for _ in range(n):
c, v = input().split()
c = int(c)
v = func(v)
for i in range(8):
cost[i | v] = min(cost[i | v], ... | {'test_cases': [{'type': 'stdin_stdout', 'input': '4\n5 C\n6 B\n16 BAC\n4 A\n', 'output': '15\n'}, {'type': 'stdin_stdout', 'input': '2\n10 AB\n15 BA\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '5\n10 A\n9 BC\n11 CA\n4 A\n5 B\n', 'output': '13\n'}, {'type': 'stdin_stdout', 'input': '6\n100 A\n355 BCA\n150 ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1042/B'} | vfc_13574 | ```python
n = int(input())
def func(v):
res = 0
if "A" in v: res |= 1
if "B" in v: res |= 2
if "C" in v: res |= 4
return res
cost = [10 ** 10] * 8
cost[0] = 0
for _ in range(n):
c, v = input().split()
c = int(c)
v = func(v)
for i in range(8):
cost[i | v] = min(cost[i | v], ... | 4
5 C
6 B
16 BAC
4 A
| 15
| 15
| true | 2,421 |
apps | verifiable_code | 956 | Solve the following coding problem using the programming language python:
Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если a является другом b, то b также является другом a.
В этой же сети есть... | ```python
m, k = [int(x) for x in input().split()]
seen = 0
users = set()
friendsof = {}
for i in range(m):
a, b = [int(x) for x in input().split()]
users.add(a)
users.add(b)
if a in friendsof:
friendsof[a].add(b)
else:
friendsof[a] = set((b,))
if b in friendsof:
friendsof[b].add(a)
else:
friendsof[b] =... | {'test_cases': [{'type': 'stdin_stdout', 'input': '5 51\n10 23\n23 42\n39 42\n10 39\n39 58\n', 'output': '10: 1 42\n23: 1 39\n39: 1 23\n42: 1 10\n58: 2 10 42\n'}, {'type': 'stdin_stdout', 'input': '5 100\n1 2\n1 3\n1 4\n2 3\n2 4\n', 'output': '1: 0\n2: 0\n3: 1 4\n4: 1 3\n'}, {'type': 'stdin_stdout', 'input': '4 1\n1 2\... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/524/A'} | vfc_13578 | ```python
m, k = [int(x) for x in input().split()]
seen = 0
users = set()
friendsof = {}
for i in range(m):
a, b = [int(x) for x in input().split()]
users.add(a)
users.add(b)
if a in friendsof:
friendsof[a].add(b)
else:
friendsof[a] = set((b,))
if b in friendsof:
friendsof[b].add(a)
else:
friendsof[b] =... | 5 51
10 23
23 42
39 42
10 39
39 58
| 10: 1 42
23: 1 39
39: 1 23
42: 1 10
58: 2 10 42
| 10: 1 42
23: 1 39
39: 1 23
42: 1 10
58: 2 10 42
| true | 2,422 |
apps | verifiable_code | 957 | Solve the following coding problem using the programming language python:
As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi ass... | ```python
string = input()
now = 0
for i in range(len(string)):
if now == 0 and string[i] == "h":
now += 1
if now == 1 and string[i] == "e":
now += 1
if now == 2 and string[i] == "i":
now += 1
if now == 3 and string[i] == "d":
now += 1
if now == 4 and string[i] == "i"... | {'test_cases': [{'type': 'stdin_stdout', 'input': 'abcheaibcdi\n', 'output': 'YES'}, {'type': 'stdin_stdout', 'input': 'hiedi\n', 'output': 'NO'}, {'type': 'stdin_stdout', 'input': 'ihied\n', 'output': 'NO'}, {'type': 'stdin_stdout', 'input': 'diehi\n', 'output': 'NO'}, {'type': 'stdin_stdout', 'input': 'deiih\n', 'out... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/802/G'} | vfc_13582 | ```python
string = input()
now = 0
for i in range(len(string)):
if now == 0 and string[i] == "h":
now += 1
if now == 1 and string[i] == "e":
now += 1
if now == 2 and string[i] == "i":
now += 1
if now == 3 and string[i] == "d":
now += 1
if now == 4 and string[i] == "i"... | abcheaibcdi
| YES | YES
| true | 2,423 |
apps | verifiable_code | 960 | Solve the following coding problem using the programming language python:
Vasya likes to solve equations. Today he wants to solve $(x~\mathrm{div}~k) \cdot (x \bmod k) = n$, where $\mathrm{div}$ and $\mathrm{mod}$ stand for integer division and modulo operations (refer to the Notes below for exact definition). In this... | ```python
n, k = list(map(int, input().split()))
result = 10 ** 26
for i in range(1, k):
if n % i == 0:
t = n // i
result = min(result, t * k + i)
print(result)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '6 3\n', 'output': '11\n'}, {'type': 'stdin_stdout', 'input': '1 2\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '4 6\n', 'output': '10\n'}, {'type': 'stdin_stdout', 'input': '1000000 1000\n', 'output': '1250800\n'}, {'type': 'stdin_stdout', 'input': '999983 1... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1085/B'} | vfc_13594 | ```python
n, k = list(map(int, input().split()))
result = 10 ** 26
for i in range(1, k):
if n % i == 0:
t = n // i
result = min(result, t * k + i)
print(result)
``` | 6 3
| 11
| 11
| true | 2,424 |
apps | verifiable_code | 961 | Solve the following coding problem using the programming language python:
Vladik often travels by trains. He remembered some of his trips especially well and I would like to tell you about one of these trips:
Vladik is at initial train station, and now n people (including Vladik) want to get on the train. They are al... | ```python
def dp():
dparr = [0] * len(sections)
for i in range(len(sections) - 1, -1, -1):
_, curend, curcomfort = sections[i]
nextsection = i + 1
try:
while sections[nextsection][0] <= curend:
nextsection += 1
except IndexError:
# Loop til end
inc = curcomfort
else:
inc = curcomfort + dparr... | {'test_cases': [{'type': 'stdin_stdout', 'input': '6\n4 4 2 5 2 3\n', 'output': '14\n'}, {'type': 'stdin_stdout', 'input': '9\n5 1 3 1 5 2 4 2 5\n', 'output': '9\n'}, {'type': 'stdin_stdout', 'input': '5\n1558 4081 3591 1700 3232\n', 'output': '14162\n'}, {'type': 'stdin_stdout', 'input': '10\n3838 1368 4825 2068 4755 ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/811/C'} | vfc_13598 | ```python
def dp():
dparr = [0] * len(sections)
for i in range(len(sections) - 1, -1, -1):
_, curend, curcomfort = sections[i]
nextsection = i + 1
try:
while sections[nextsection][0] <= curend:
nextsection += 1
except IndexError:
# Loop til end
inc = curcomfort
else:
inc = curcomfort + dparr... | 6
4 4 2 5 2 3
| 14
| 14
| true | 2,425 |
apps | verifiable_code | 963 | Solve the following coding problem using the programming language python:
There are N cells arranged in a row, numbered 1, 2, \ldots, N from left to right.
Tak lives in these cells and is currently on Cell 1. He is trying to reach Cell N by using the procedure described below.
You are given an integer K that is less t... | ```python
n, k = map(int, input().split())
l = [(0, 0) for i in range(k)]
for i in range(k):
start, end = map(int, input().split())
l[i] = start, end
dp = [0 for i in range(n+1)]
prefixSum = [0 for i in range(n+1)]
dp[1] = 1
prefixSum[1] = 1
for i in range(2, n + 1):
for j in range(k):
start, end... | {'test_cases': [{'type': 'stdin_stdout', 'input': '5 2\n1 1\n3 4\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '5 2\n3 3\n5 5\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '5 1\n1 2\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '60 3\n5 8\n1 3\n10 15\n', 'output': '221823067\n'}, {'type': ... | {'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc179/tasks/abc179_d'} | vfc_13606 | ```python
n, k = map(int, input().split())
l = [(0, 0) for i in range(k)]
for i in range(k):
start, end = map(int, input().split())
l[i] = start, end
dp = [0 for i in range(n+1)]
prefixSum = [0 for i in range(n+1)]
dp[1] = 1
prefixSum[1] = 1
for i in range(2, n + 1):
for j in range(k):
start, end... | 5 2
1 1
3 4
| 4
| 4
| true | 2,427 |
apps | verifiable_code | 965 | Solve the following coding problem using the programming language python:
There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED... | ```python
n=int(input())
a=input()
cnt=0
A=0
for i in range(0,n):
if(a[i]=='I'): cnt+=1
if(a[i]=='A'): A+=1
if(cnt==0):
print(A)
elif(cnt==1):
print(1)
else :print(0)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '6\nAFFAAA\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '3\nAFI\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3\nFFF\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '3\nFIF\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3\nAAA\n',... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/284/B'} | vfc_13614 | ```python
n=int(input())
a=input()
cnt=0
A=0
for i in range(0,n):
if(a[i]=='I'): cnt+=1
if(a[i]=='A'): A+=1
if(cnt==0):
print(A)
elif(cnt==1):
print(1)
else :print(0)
``` | 6
AFFAAA
| 4
| 4
| true | 2,429 |
apps | verifiable_code | 966 | Solve the following coding problem using the programming language python:
It seems like the year of 2013 came only yesterday. Do you know a curious fact? The year of 2013 is the first year after the old 1987 with only distinct digits.
Now you are suggested to solve the following problem: given a year number, find the... | ```python
def find(ins):
ins += 1
test = [int(i) for i in str(ins)]
inlist = []
for i in test:
if i in inlist:
test = find(ins)
break
else:
inlist.append(i)
return ''.join(str(x) for x in test)
ins = int(input())
print(find(ins))
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '1987\n', 'output': '2013\n'}, {'type': 'stdin_stdout', 'input': '2013\n', 'output': '2014\n'}, {'type': 'stdin_stdout', 'input': '1000\n', 'output': '1023\n'}, {'type': 'stdin_stdout', 'input': '1001\n', 'output': '1023\n'}, {'type': 'stdin_stdout', 'input': '1234\n', ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/271/A'} | vfc_13618 | ```python
def find(ins):
ins += 1
test = [int(i) for i in str(ins)]
inlist = []
for i in test:
if i in inlist:
test = find(ins)
break
else:
inlist.append(i)
return ''.join(str(x) for x in test)
ins = int(input())
print(find(ins))
``` | 1987
| 2013
| 2013
| true | 2,430 |
apps | verifiable_code | 967 | Solve the following coding problem using the programming language python:
Emuskald is addicted to Codeforces, and keeps refreshing the main page not to miss any changes in the "recent actions" list. He likes to read thread conversations where each thread consists of multiple messages.
Recent actions shows a list of n... | ```python
n, ar = int(input()), [int(x) for x in input().split()][::-1]
ans = 0
for i in range(1, n):
if ar[i] > ar[i - 1]:
ans = n - i
break
print(ans)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '5\n5 2 1 3 4\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3\n1 2 3\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '4\n4 3 2 1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '5\n1 2 5 3 4\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'inpu... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/270/B'} | vfc_13622 | ```python
n, ar = int(input()), [int(x) for x in input().split()][::-1]
ans = 0
for i in range(1, n):
if ar[i] > ar[i - 1]:
ans = n - i
break
print(ans)
``` | 5
5 2 1 3 4
| 2
| 2
| true | 2,431 |
apps | verifiable_code | 968 | Solve the following coding problem using the programming language python:
A way to make a new task is to make it nondeterministic or probabilistic. For example, the hard task of Topcoder SRM 595, Constellation, is the probabilistic version of a convex hull.
Let's try to make a new task. Firstly we will use the follow... | ```python
"""
Codeforces Contest 270 Problem C
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
n, = read()
names = []
for i in range(n): names.extend([(x,i+1) for x in read(1)])
names.sort()
p = read()
i = 0
j = 0
while i < n and j < 2*n:
if names[j][1] == p[i]:
... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n1 2 3\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '3\ngennady korotkevich\npetr mitrichev\ngaoyuan chen\n3 1 2\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '2\ngalileo galilei\nnicolaus cop... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/472/C'} | vfc_13626 | ```python
"""
Codeforces Contest 270 Problem C
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
n, = read()
names = []
for i in range(n): names.extend([(x,i+1) for x in read(1)])
names.sort()
p = read()
i = 0
j = 0
while i < n and j < 2*n:
if names[j][1] == p[i]:
... | 3
gennady korotkevich
petr mitrichev
gaoyuan chen
1 2 3
| NO
| NO
| true | 2,432 |
apps | verifiable_code | 969 | Solve the following coding problem using the programming language python:
A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art.
First, he wants to construct ... | ```python
def solve(s,t):
hash_s = [False] * 256
hash_t = [False] * 256
arr = []
n = len(s)
for c in s:
hash_s[ord(c)] = True
for c in t:
hash_t[ord(c)] = True
for i in range(256):
if not hash_s[i] and hash_t[i]:
print(-1)
return
rev = s[::... | {'test_cases': [{'type': 'stdin_stdout', 'input': 'abc\ncbaabc\n', 'output': '2\n3 1\n1 3\n'}, {'type': 'stdin_stdout', 'input': 'aaabrytaaa\nayrat\n', 'output': '3\n1 1\n6 5\n8 7\n'}, {'type': 'stdin_stdout', 'input': 'ami\nno\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': 'r\nr\n', 'output': '1\n1 1\n'}, {'... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/615/C'} | vfc_13630 | ```python
def solve(s,t):
hash_s = [False] * 256
hash_t = [False] * 256
arr = []
n = len(s)
for c in s:
hash_s[ord(c)] = True
for c in t:
hash_t[ord(c)] = True
for i in range(256):
if not hash_s[i] and hash_t[i]:
print(-1)
return
rev = s[::... | abc
cbaabc
| 2
3 1
1 3
| 2
3 1
1 3
| true | 2,433 |
apps | verifiable_code | 970 | Solve the following coding problem using the programming language python:
You are given a chessboard of size 1 × n. It is guaranteed that n is even. The chessboard is painted like this: "BWBW...BW".
Some cells of the board are occupied by the chess pieces. Each cell contains no more than one chess piece. It is known ... | ```python
def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
n = ii()
a = li()
a.sort()
c1 = 0
p = 1
for ai in a:
c1 += abs(ai - p)
p += 2
c2 = 0
p = 2
for ai in a:
c2 += abs(ai - p)
p += 2
ans = min(c1, c2)
print(ans)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '6\n1 2 6\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '10\n1 2 3 4 5\n', 'output': '10\n'}, {'type': 'stdin_stdout', 'input': '2\n2\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '100\n2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/985/A'} | vfc_13634 | ```python
def ii():
return int(input())
def mi():
return map(int, input().split())
def li():
return list(mi())
n = ii()
a = li()
a.sort()
c1 = 0
p = 1
for ai in a:
c1 += abs(ai - p)
p += 2
c2 = 0
p = 2
for ai in a:
c2 += abs(ai - p)
p += 2
ans = min(c1, c2)
print(ans)
``` | 6
1 2 6
| 2
| 2
| true | 2,434 |
apps | verifiable_code | 971 | Solve the following coding problem using the programming language python:
Kolya is going to make fresh orange juice. He has n oranges of sizes a_1, a_2, ..., a_{n}. Kolya will put them in the juicer in the fixed order, starting with orange of size a_1, then orange of size a_2 and so on. To be put in the juicer the ora... | ```python
# You lost the game.
n,b,d = list(map(int, input().split()))
L = list(map(int, input().split()))
r = 0
c = 0
for i in range(n):
if L[i] <= b:
c += L[i]
if c > d:
r += 1
c = 0
print(r)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '2 7 10\n5 6\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1 5 10\n7\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '3 10 10\n5 7 7\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1 1 1\n1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'inpu... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/709/A'} | vfc_13638 | ```python
# You lost the game.
n,b,d = list(map(int, input().split()))
L = list(map(int, input().split()))
r = 0
c = 0
for i in range(n):
if L[i] <= b:
c += L[i]
if c > d:
r += 1
c = 0
print(r)
``` | 2 7 10
5 6
| 1
| 1
| true | 2,435 |
apps | verifiable_code | 972 | Solve the following coding problem using the programming language python:
Consider an n × m grid. Initially all the cells of the grid are colored white. Lenny has painted some of the cells (at least one) black. We call a painted grid convex if one can walk from any black cell to any another black cell using a path of ... | ```python
def f():
n, m = map(int, input().split())
t = [input() for j in range(n)]
p = [''.join(i) for i in zip(*t)]
if h(p): return 1
i = 0
while i < n and not 'B' in t[i]: i += 1
while i < n:
a = t[i].find('B')
if a < 0:
i += 1
break
b = ... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 4\nWWBW\nBWWW\nWWWB\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '3 1\nB\nB\nW\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '1 1\nB\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '1 2\nBB\n', 'output': 'YES\n'}, {'type': 'stdin_std... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/275/B'} | vfc_13642 | ```python
def f():
n, m = map(int, input().split())
t = [input() for j in range(n)]
p = [''.join(i) for i in zip(*t)]
if h(p): return 1
i = 0
while i < n and not 'B' in t[i]: i += 1
while i < n:
a = t[i].find('B')
if a < 0:
i += 1
break
b = ... | 3 4
WWBW
BWWW
WWWB
| NO
| NO
| true | 2,436 |
apps | verifiable_code | 973 | Solve the following coding problem using the programming language python:
Bob is a farmer. He has a large pasture with many sheep. Recently, he has lost some of them due to wolf attacks. He thus decided to place some shepherd dogs in such a way that all his sheep are protected.
The pasture is a rectangle consisting o... | ```python
r, c = list(map(int, input().split()))
ls = [[c for c in input()] for i in range(r)]
for i in range(r):
dead = False
for j in range(c):
if ls[i][j] == 'W':
if i != 0 and ls[i - 1][j] == 'S': dead = True
if i != r - 1 and ls[i + 1][j] == 'S': dead = True
if j... | {'test_cases': [{'type': 'stdin_stdout', 'input': '6 6\n..S...\n..S.W.\n.S....\n..W...\n...W..\n......\n', 'output': 'Yes\nDDSDDD\nDDSDWD\nDSDDDD\nDDWDDD\nDDDWDD\nDDDDDD\n'}, {'type': 'stdin_stdout', 'input': '1 2\nSW\n', 'output': 'No\n'}, {'type': 'stdin_stdout', 'input': '5 5\n.S...\n...S.\nS....\n...S.\n.S...\n', '... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/948/A'} | vfc_13646 | ```python
r, c = list(map(int, input().split()))
ls = [[c for c in input()] for i in range(r)]
for i in range(r):
dead = False
for j in range(c):
if ls[i][j] == 'W':
if i != 0 and ls[i - 1][j] == 'S': dead = True
if i != r - 1 and ls[i + 1][j] == 'S': dead = True
if j... | 6 6
..S...
..S.W.
.S....
..W...
...W..
......
| Yes
DDSDDD
DDSDWD
DSDDDD
DDWDDD
DDDWDD
DDDDDD
| Yes
DDSDDD
DDSDWD
DSDDDD
DDWDDD
DDDWDD
DDDDDD
| true | 2,437 |
apps | verifiable_code | 974 | Solve the following coding problem using the programming language python:
Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack.
Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the ... | ```python
import sys
def main():
n = int(input())
n = n*2
u = 0
res = 0
x = []
for i in range(n):
s = sys.stdin.readline()
if s[0] == 'r':
u+=1
if len(x)==0:
continue
if x[-1] == u:
x.pop()
else:
... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\nadd 1\nremove\nadd 2\nadd 3\nremove\nremove\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/821/C'} | vfc_13650 | ```python
import sys
def main():
n = int(input())
n = n*2
u = 0
res = 0
x = []
for i in range(n):
s = sys.stdin.readline()
if s[0] == 'r':
u+=1
if len(x)==0:
continue
if x[-1] == u:
x.pop()
else:
... | 3
add 1
remove
add 2
add 3
remove
remove
| 1
| 1
| true | 2,438 |
apps | verifiable_code | 975 | Solve the following coding problem using the programming language python:
After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards.
Rules of this game are simple: each player bring his favour... | ```python
n = int(input())
a = list(input())
b = list(input())
a = [int(i) for i in a]
b = [int(i) for i in b]
a.sort()
b.sort()
c = a[::]
d = b[::]
ans1 = 0
ans2 = 0
for i in a:
for j in range(len(b)):
if b[j] > i:
del b[j]
ans2 += 1
break
for i in c:
for j in range(... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n123\n321\n', 'output': '0\n2\n'}, {'type': 'stdin_stdout', 'input': '2\n88\n00\n', 'output': '2\n0\n'}, {'type': 'stdin_stdout', 'input': '1\n4\n5\n', 'output': '0\n1\n'}, {'type': 'stdin_stdout', 'input': '1\n8\n7\n', 'output': '1\n0\n'}, {'type': 'stdin_stdout', '... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/777/B'} | vfc_13654 | ```python
n = int(input())
a = list(input())
b = list(input())
a = [int(i) for i in a]
b = [int(i) for i in b]
a.sort()
b.sort()
c = a[::]
d = b[::]
ans1 = 0
ans2 = 0
for i in a:
for j in range(len(b)):
if b[j] > i:
del b[j]
ans2 += 1
break
for i in c:
for j in range(... | 3
123
321
| 0
2
| 0
2
| true | 2,439 |
apps | verifiable_code | 976 | Solve the following coding problem using the programming language python:
You have decided to watch the best moments of some movie. There are two buttons on your player: Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to ... | ```python
n, x = list(map(int, input().split()))
result = 0
cur = 1
for i in range(n):
l, r = list(map(int, input().split()))
result += r - l + 1
result += (l - cur) % x
cur = r + 1
print(result)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '2 3\n5 6\n10 12\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '1 1\n1 100000\n', 'output': '100000\n'}, {'type': 'stdin_stdout', 'input': '10 1\n2156 3497\n4784 7775\n14575 31932\n33447 35902\n36426 47202\n48772 60522\n63982 68417\n78537 79445\n90081 90629\n9... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/499/A'} | vfc_13658 | ```python
n, x = list(map(int, input().split()))
result = 0
cur = 1
for i in range(n):
l, r = list(map(int, input().split()))
result += r - l + 1
result += (l - cur) % x
cur = r + 1
print(result)
``` | 2 3
5 6
10 12
| 6
| 6
| true | 2,440 |
apps | verifiable_code | 977 | Solve the following coding problem using the programming language python:
This is the easy version of the problem. The difference between versions is the constraints on $n$ and $a_i$. You can make hacks only if all versions of the problem are solved.
First, Aoi came up with the following idea for the competitive prog... | ```python
import sys
from bisect import bisect_right as br
input = sys.stdin.readline
n, p = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
table = [0] * (10 ** 5 + 1)
for x in range(10 ** 5 + 1):
r = br(a, x)
table[x] = r
res = []
#print(table[: 100])
for x in range(1, 2001):
t = 1
q = ... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 2\n3 4 5\n', 'output': '1\n3\n'}, {'type': 'stdin_stdout', 'input': '4 3\n2 3 5 6\n', 'output': '2\n3 4\n'}, {'type': 'stdin_stdout', 'input': '4 3\n9 1 1 1\n', 'output': '0\n\n'}, {'type': 'stdin_stdout', 'input': '2 2\n654 1162\n', 'output': '1\n1161\n'}, {'type': ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1371/E1'} | vfc_13662 | ```python
import sys
from bisect import bisect_right as br
input = sys.stdin.readline
n, p = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
table = [0] * (10 ** 5 + 1)
for x in range(10 ** 5 + 1):
r = br(a, x)
table[x] = r
res = []
#print(table[: 100])
for x in range(1, 2001):
t = 1
q = ... | 3 2
3 4 5
| 1
3
| 1
3
| true | 2,441 |
apps | verifiable_code | 978 | Solve the following coding problem using the programming language python:
Cucumber boy is fan of Kyubeat, a famous music game.
Kyubeat has 16 panels for playing arranged in 4 × 4 table. When a panel lights up, he has to press that panel.
Each panel has a timing to press (the preffered time when a player should press... | ```python
k=int(input())
L={}
s=".123456789"
for item in s:
L[item]=0
for i in range(4):
s=input()
for item in s:
L[item]+=1
s="123456789"
done=True
for item in s:
if(L[item]>2*k):
print("NO")
done=False
break
if(done):
print("YES")
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '1\n.135\n1247\n3468\n5789\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '5\n..1.\n1111\n..1.\n..1.\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '1\n....\n12.1\n.2..\n.2..\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '1\n....\n....\n... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/373/A'} | vfc_13666 | ```python
k=int(input())
L={}
s=".123456789"
for item in s:
L[item]=0
for i in range(4):
s=input()
for item in s:
L[item]+=1
s="123456789"
done=True
for item in s:
if(L[item]>2*k):
print("NO")
done=False
break
if(done):
print("YES")
``` | 1
.135
1247
3468
5789
| YES
| YES
| true | 2,442 |
apps | verifiable_code | 979 | Solve the following coding problem using the programming language python:
To become the king of Codeforces, Kuroni has to solve the following problem.
He is given $n$ numbers $a_1, a_2, \dots, a_n$. Help Kuroni to calculate $\prod_{1\le i<j\le n} |a_i - a_j|$. As result can be very big, output it modulo $m$.
If you ... | ```python
from sys import stdin
input = stdin.readline
n,m = map(int,input().split())
l = list(map(int,input().split()))
if n > m:
print(0)
else:
res = 1
for i in range(n-1):
for j in range(i+1,n):
res = ((res*abs(l[i]-l[j])) % m)
print(res%m)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '2 10\n8 5\n', 'output': '3'}, {'type': 'stdin_stdout', 'input': '3 12\n1 4 5\n', 'output': '0'}, {'type': 'stdin_stdout', 'input': '3 7\n1 4 9\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': '4 13\n714767937 343185412 397497741 947006223\n', 'output': '2'}, {'typ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1305/C'} | vfc_13670 | ```python
from sys import stdin
input = stdin.readline
n,m = map(int,input().split())
l = list(map(int,input().split()))
if n > m:
print(0)
else:
res = 1
for i in range(n-1):
for j in range(i+1,n):
res = ((res*abs(l[i]-l[j])) % m)
print(res%m)
``` | 2 10
8 5
| 3 | 3
| true | 2,443 |
apps | verifiable_code | 982 | Solve the following coding problem using the programming language python:
You got a job as a marketer in a pet shop, and your current task is to boost sales of cat food. One of the strategies is to sell cans of food in packs with discounts.
Suppose you decided to sell packs with $a$ cans in a pack with a discount an... | ```python
import sys
def main():
#n = int(sys.stdin.readline().strip())
n, m = map(int, sys.stdin.readline().split())
#q = list(map(int, sys.stdin.readline().split()))
if n * 2 > m:
print("YES")
else:
print("NO")
... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n3 4\n1 2\n120 150\n', 'output': 'YES\nNO\nYES\n'}, {'type': 'stdin_stdout', 'input': '1\n500000000 1000000000\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '1\n100000001 200000002\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '1\n1000000000 100... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1437/A'} | vfc_13682 | ```python
import sys
def main():
#n = int(sys.stdin.readline().strip())
n, m = map(int, sys.stdin.readline().split())
#q = list(map(int, sys.stdin.readline().split()))
if n * 2 > m:
print("YES")
else:
print("NO")
... | 3
3 4
1 2
120 150
| YES
NO
YES
| YES
NO
YES
| true | 2,444 |
apps | verifiable_code | 983 | Solve the following coding problem using the programming language python:
Professor Dumbledore is helping Harry destroy the Horcruxes. He went to Gaunt Shack as he suspected a Horcrux to be present there. He saw Marvolo Gaunt's Ring and identified it as a Horcrux. Although he destroyed it, he is still affected by its ... | ```python
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n,p,q,r=map(int,input().split())
a=list(map(int,input().split()))
s1=[a[i]*p for i in range(n)]
s2=[]
m=s1[0]
for i in range(n):
m=max(m,s1[i])
s2.append(m+a[i]*q)
s3=[]
m=s2[0]
for i in range(n):
m=max(m,s2[i])
s3.append(m+... | {'test_cases': [{'type': 'stdin_stdout', 'input': '5 1 2 3\n1 2 3 4 5\n', 'output': '30\n'}, {'type': 'stdin_stdout', 'input': '5 1 2 -3\n-1 -2 -3 -4 -5\n', 'output': '12\n'}, {'type': 'stdin_stdout', 'input': '5 886327859 82309257 -68295239\n-731225382 354766539 -48222231 -474691998 360965777\n', 'output': '3760592406... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/855/B'} | vfc_13686 | ```python
import sys
#sys.stdin=open("data.txt")
input=sys.stdin.readline
n,p,q,r=map(int,input().split())
a=list(map(int,input().split()))
s1=[a[i]*p for i in range(n)]
s2=[]
m=s1[0]
for i in range(n):
m=max(m,s1[i])
s2.append(m+a[i]*q)
s3=[]
m=s2[0]
for i in range(n):
m=max(m,s2[i])
s3.append(m+... | 5 1 2 3
1 2 3 4 5
| 30
| 30
| true | 2,445 |
apps | verifiable_code | 984 | Solve the following coding problem using the programming language python:
Let T be arbitrary binary tree — tree, every vertex of which has no more than two children. Given tree is rooted, so there exists only one vertex which doesn't have a parent — it's the root of a tree. Every vertex has an integer number written o... | ```python
from collections import deque
nodes = []
parents = []
values = []
broken = []
upperBound = []
lowerBound = []
n = int(input())
for _ in range(n):
v, l, r = map(int, input().split())
nodes.append((v, l - 1, r - 1))
parents.append(-1)
values.append(v)
broken.append(False)
upperBound.a... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n15 -1 -1\n10 1 3\n5 -1 -1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '8\n6 2 3\n3 4 5\n12 6 7\n1 -1 8\n4 -1 -1\n5 -1 -1\n14 -1 -1\n2 -1 -1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1\n493041212 -1 -1\n', 'output': '0\n'}, {'type': 'stdin_... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/797/D'} | vfc_13690 | ```python
from collections import deque
nodes = []
parents = []
values = []
broken = []
upperBound = []
lowerBound = []
n = int(input())
for _ in range(n):
v, l, r = map(int, input().split())
nodes.append((v, l - 1, r - 1))
parents.append(-1)
values.append(v)
broken.append(False)
upperBound.a... | 3
15 -1 -1
10 1 3
5 -1 -1
| 2
| 2
| true | 2,446 |
apps | verifiable_code | 985 | Solve the following coding problem using the programming language python:
Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right.
Wet Shark thinks that two bishops at... | ```python
a=[0]*2222
b=[0]*2222
r=0
for _ in range(int(input())):
x,y=map(int,input().split())
r+=a[x+y]+b[x-y+1111]
a[x+y]+=1
b[x-y+1111]+=1
print(r)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '5\n1 1\n1 5\n3 3\n5 1\n5 5\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '3\n1 1\n2 3\n3 5\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '3\n859 96\n634 248\n808 72\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '3\n987 237\n891 429\n358 14... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/621/B'} | vfc_13694 | ```python
a=[0]*2222
b=[0]*2222
r=0
for _ in range(int(input())):
x,y=map(int,input().split())
r+=a[x+y]+b[x-y+1111]
a[x+y]+=1
b[x-y+1111]+=1
print(r)
``` | 5
1 1
1 5
3 3
5 1
5 5
| 6
| 6
| true | 2,447 |
apps | verifiable_code | 986 | Solve the following coding problem using the programming language python:
Your search for Heidi is over – you finally found her at a library, dressed up as a human. In fact, she has spent so much time there that she now runs the place! Her job is to buy books and keep them at the library so that people can borrow and ... | ```python
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
library = []
money = 0
for i in range(len(a)):
if a[i] not in library:
money += 1
if len(library) < k:
library.append(a[i])
else:
curmin = n
curindex = 0
found... | {'test_cases': [{'type': 'stdin_stdout', 'input': '4 80\n1 2 2 1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4 1\n1 2 2 1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '4 2\n1 2 3 1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '11 1\n1 2 3 5 1 10 10 1 1 3 5\n', 'output': '9\n'}, {'type... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/802/A'} | vfc_13698 | ```python
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
library = []
money = 0
for i in range(len(a)):
if a[i] not in library:
money += 1
if len(library) < k:
library.append(a[i])
else:
curmin = n
curindex = 0
found... | 4 80
1 2 2 1
| 2
| 2
| true | 2,448 |
apps | verifiable_code | 987 | Solve the following coding problem using the programming language python:
You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (a_{j}, b_{j}).
At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutati... | ```python
from collections import defaultdict
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
parent = [i for i in range(N)]
rank = [0] * N
def find(i):
if parent[i] == i:
return i
else:
parent[i] = find(parent[i])
return parent[i]
def same(x, y):
r... | {'test_cases': [{'type': 'stdin_stdout', 'input': '9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n', 'output': '7 8 9 4 5 6 1 2 3\n'}, {'type': 'stdin_stdout', 'input': '1 1\n1\n1 1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '2 10\n2 1\n2 1\n1 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 1\n2 1\n2 1\n', 'output': ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/691/D'} | vfc_13702 | ```python
from collections import defaultdict
import sys
input = sys.stdin.readline
N, M = list(map(int, input().split()))
parent = [i for i in range(N)]
rank = [0] * N
def find(i):
if parent[i] == i:
return i
else:
parent[i] = find(parent[i])
return parent[i]
def same(x, y):
r... | 9 6
1 2 3 4 5 6 7 8 9
1 4
4 7
2 5
5 8
3 6
6 9
| 7 8 9 4 5 6 1 2 3
| 7 8 9 4 5 6 1 2 3
| true | 2,449 |
apps | verifiable_code | 989 | Solve the following coding problem using the programming language python:
You are given a sequence $a_1, a_2, \dots, a_n$ consisting of $n$ integers.
You may perform the following operation on this sequence: choose any element and either increase or decrease it by one.
Calculate the minimum possible difference betwe... | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt = {}
for elem in a:
if elem in cnt:
cnt[elem] += 1
else:
cnt[elem] = 1
cnt = sorted(list(cnt.items()))
for i in range(len(cnt)):
cnt[i] = list(cnt[i])
left = 0
right = len(cnt) - 1
while k > 0:
if k < cnt... | {'test_cases': [{'type': 'stdin_stdout', 'input': '4 5\n3 1 7 5\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3 10\n100 100 100\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '10 9\n4 5 5 7 5 4 5 2 4 3\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3 3\n7 12 8\n', 'output': '2\n'}, {'type'... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1244/E'} | vfc_13710 | ```python
n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt = {}
for elem in a:
if elem in cnt:
cnt[elem] += 1
else:
cnt[elem] = 1
cnt = sorted(list(cnt.items()))
for i in range(len(cnt)):
cnt[i] = list(cnt[i])
left = 0
right = len(cnt) - 1
while k > 0:
if k < cnt... | 4 5
3 1 7 5
| 2
| 2
| true | 2,451 |
apps | verifiable_code | 990 | Solve the following coding problem using the programming language python:
We have a tree with N vertices numbered 1 to N.
The i-th edge in this tree connects Vertex a_i and Vertex b_i.
Consider painting each of these edges white or black. There are 2^{N-1} such ways to paint the edges. Among them, how many satisfy al... | ```python
from collections import defaultdict
def dfs(s, t):
visited = 0
q = [(s, 0)]
while q:
v, used = q.pop()
if v == t:
return used
visited |= used
for lb, u in graph[v]:
if lb & visited:
continue
q.append((u, used | l... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 2\n2 3\n1\n1 3\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '2\n1 2\n1\n1 2\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '5\n1 2\n3 2\n3 4\n5 3\n3\n1 3\n2 4\n2 5\n', 'output': '9\n'}, {'type': 'stdin_stdout', 'input': '8\n1 2\n2 3\n4 3\n2 5\n... | {'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc152/tasks/abc152_f'} | vfc_13714 | ```python
from collections import defaultdict
def dfs(s, t):
visited = 0
q = [(s, 0)]
while q:
v, used = q.pop()
if v == t:
return used
visited |= used
for lb, u in graph[v]:
if lb & visited:
continue
q.append((u, used | l... | 3
1 2
2 3
1
1 3
| 3
| 3
| true | 2,452 |
apps | verifiable_code | 991 | Solve the following coding problem using the programming language python:
There are N cities numbered 1 to N, connected by M railroads.
You are now at City 1, with 10^{100} gold coins and S silver coins in your pocket.
The i-th railroad connects City U_i and City V_i bidirectionally, and a one-way trip costs A_i silve... | ```python
import heapq
city_num, road_num, init_silver = map(int, input().split())
MAX_COST = 2500
init_silver = min(MAX_COST, init_silver)
G = [[] for _ in range(city_num)]
for _ in range(road_num):
A, B, cost, time_cost = map(int, input().split())
A, B = A-1, B-1
G[B].append([A, cost, time_cost])
G... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 2 1\n1 2 1 2\n1 3 2 4\n1 11\n1 2\n2 5\n', 'output': '2\n14\n'}, {'type': 'stdin_stdout', 'input': '4 4 1\n1 2 1 5\n1 3 4 4\n2 4 2 2\n3 4 1 1\n3 1\n3 1\n5 2\n6 4\n', 'output': '5\n5\n7\n'}, {'type': 'stdin_stdout', 'input': '6 5 1\n1 2 1 1\n1 3 2 1\n2 4 5 1\n3 5 11 1\... | {'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc164/tasks/abc164_e'} | vfc_13718 | ```python
import heapq
city_num, road_num, init_silver = map(int, input().split())
MAX_COST = 2500
init_silver = min(MAX_COST, init_silver)
G = [[] for _ in range(city_num)]
for _ in range(road_num):
A, B, cost, time_cost = map(int, input().split())
A, B = A-1, B-1
G[B].append([A, cost, time_cost])
G... | 3 2 1
1 2 1 2
1 3 2 4
1 11
1 2
2 5
| 2
14
| 2
14
| true | 2,453 |
apps | verifiable_code | 992 | Solve the following coding problem using the programming language python:
Given are a sequence of N positive integers A_1, A_2, \ldots, A_N and another positive integer S.
For a non-empty subset T of the set \{1, 2, \ldots , N \}, let us define f(T) as follows:
- f(T) is the number of different non-empty subsets \{... | ```python
import numpy as np
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
dp=np.zeros([n+1,s+1],int)
dp[0][0]=1
for i in range(1,n+1):
dp[i][:]=dp[i-1][:]*2
dp[i][a[i-1]:]+=dp[i-1][:-a[i-1]]
dp[i][:]%=mod
print(dp[n][s])
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 4\n2 2 4\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '5 8\n9 9 9 9 9\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '10 10\n3 1 4 1 5 9 2 6 5 3\n', 'output': '3296\n'}, {'type': 'stdin_stdout', 'input': '22 575\n426 445 772 81 447 629 497 202 775... | {'difficulty': 'interview', 'problem_url': 'https://atcoder.jp/contests/abc169/tasks/abc169_f'} | vfc_13722 | ```python
import numpy as np
n,s=map(int,input().split())
a=list(map(int,input().split()))
mod=998244353
dp=np.zeros([n+1,s+1],int)
dp[0][0]=1
for i in range(1,n+1):
dp[i][:]=dp[i-1][:]*2
dp[i][a[i-1]:]+=dp[i-1][:-a[i-1]]
dp[i][:]%=mod
print(dp[n][s])
``` | 3 4
2 2 4
| 6
| 6
| true | 2,454 |
apps | verifiable_code | 995 | Solve the following coding problem using the programming language python:
SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in th... | ```python
#!/usr/bin/env python3
from math import sqrt
primes = [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,
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 2... | {'test_cases': [{'type': 'stdin_stdout', 'input': '2\n5 5\n', 'output': '3 0\n'}, {'type': 'stdin_stdout', 'input': '5\n5 -4 2 1 8\n', 'output': '5 5 3 2 0\n'}, {'type': 'stdin_stdout', 'input': '1\n0\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3\n-10 -5 7\n', 'output': '3 2 1\n'}, {'type': 'stdin_stdout',... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/980/D'} | vfc_13734 | ```python
#!/usr/bin/env python3
from math import sqrt
primes = [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,
101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193,
197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 2... | 2
5 5
| 3 0
| 3 0
| true | 2,455 |
apps | verifiable_code | 996 | Solve the following coding problem using the programming language python:
A super computer has been built in the Turtle Academy of Sciences. The computer consists of n·m·k CPUs. The architecture was the paralellepiped of size n × m × k, split into 1 × 1 × 1 cells, each cell contains exactly one CPU. Thus, each CPU can... | ```python
def main():
s = input().split()
n, m, k = int(s[0]), int(s[1]), int(s[2])
processor = []
for x in range(n):
for y in range(m):
s = input()
for z in s:
processor.append(int(z) == 1)
if x < n - 1:
emptyLine = input()
counter... | {'test_cases': [{'type': 'stdin_stdout', 'input': '2 2 3\n000\n000\n\n111\n111\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3 3 3\n111\n111\n111\n\n111\n111\n111\n\n111\n111\n111\n', 'output': '19\n'}, {'type': 'stdin_stdout', 'input': '1 1 10\n0101010101\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'inpu... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/638/D'} | vfc_13738 | ```python
def main():
s = input().split()
n, m, k = int(s[0]), int(s[1]), int(s[2])
processor = []
for x in range(n):
for y in range(m):
s = input()
for z in s:
processor.append(int(z) == 1)
if x < n - 1:
emptyLine = input()
counter... | 2 2 3
000
000
111
111
| 2
| 2
| true | 2,456 |
apps | verifiable_code | 997 | Solve the following coding problem using the programming language python:
You are given string s. Let's call word any largest sequence of consecutive symbols without symbols ',' (comma) and ';' (semicolon). For example, there are four words in string "aba,123;1a;0": "aba", "123", "1a", "0". A word can be empty: for ex... | ```python
#!/usr/bin/env python3
import re
try:
while True:
a = [ ]
b = [ ]
for word in re.split(R"[,;]", input()):
(a if re.match(R"^(0|[1-9][0-9]*)$", word) else b).append(word)
print('"%s"' % ','.join(a) if a else '-')
print('"%s"' % ','.join(b) if b else '-'... | {'test_cases': [{'type': 'stdin_stdout', 'input': 'aba,123;1a;0\n', 'output': '"123,0"\n"aba,1a"\n'}, {'type': 'stdin_stdout', 'input': '1;;01,a0,\n', 'output': '"1"\n",01,a0,"\n'}, {'type': 'stdin_stdout', 'input': '1\n', 'output': '"1"\n-\n'}, {'type': 'stdin_stdout', 'input': 'a\n', 'output': '-\n"a"\n'}, {'type': '... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/600/A'} | vfc_13742 | ```python
#!/usr/bin/env python3
import re
try:
while True:
a = [ ]
b = [ ]
for word in re.split(R"[,;]", input()):
(a if re.match(R"^(0|[1-9][0-9]*)$", word) else b).append(word)
print('"%s"' % ','.join(a) if a else '-')
print('"%s"' % ','.join(b) if b else '-'... | aba,123;1a;0
| "123,0"
"aba,1a"
| "123,0"
"aba,1a"
| true | 2,457 |
apps | verifiable_code | 999 | Solve the following coding problem using the programming language python:
Anton likes to play chess. Also he likes to do programming. No wonder that he decided to attend chess classes and programming classes.
Anton has n variants when he will attend chess classes, i-th variant is given by a period of time (l_{1, }i, ... | ```python
import math
import itertools
def ria():
return [int(i) for i in input().split()]
mx = 0
sz = ria()[0]
mx1 = 0
mn1 = 2000000000
for i in range(sz):
l, r = ria()
mx1 = max(l, mx1)
mn1 = min(r, mn1)
sz = ria()[0]
mx2 = 0
mn2 = 2000000000
for i in range(sz):
l, r = ria()
mx2 = max(... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 5\n2 6\n2 3\n2\n2 4\n6 8\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '3\n1 5\n2 6\n3 7\n2\n2 4\n1 4\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '20\n13 141\n57 144\n82 124\n16 23\n18 44\n64 65\n117 133\n84 117\n77 142\n40 119\n105 120\n71 9... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/785/B'} | vfc_13750 | ```python
import math
import itertools
def ria():
return [int(i) for i in input().split()]
mx = 0
sz = ria()[0]
mx1 = 0
mn1 = 2000000000
for i in range(sz):
l, r = ria()
mx1 = max(l, mx1)
mn1 = min(r, mn1)
sz = ria()[0]
mx2 = 0
mn2 = 2000000000
for i in range(sz):
l, r = ria()
mx2 = max(... | 3
1 5
2 6
2 3
2
2 4
6 8
| 3
| 3
| true | 2,459 |
apps | verifiable_code | 1000 | Solve the following coding problem using the programming language python:
Sasha is a very happy guy, that's why he is always on the move. There are $n$ cities in the country where Sasha lives. They are all located on one straight line, and for convenience, they are numbered from $1$ to $n$ in increasing order. The dis... | ```python
n,v = map(int,input().split())
req = n-1
if req<=v:
print (req)
else:
total = v
remaining = req-v
for x in range(remaining):
total += 2+x
print (total)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '4 2\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '7 6\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '10 3\n', 'output': '30\n'}, {'type': 'stdin_stdout', 'input': '12 89\n', 'output': '11\n'}, {'type': 'stdin_stdout', 'input': '32 15\n', 'output': ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1113/A'} | vfc_13754 | ```python
n,v = map(int,input().split())
req = n-1
if req<=v:
print (req)
else:
total = v
remaining = req-v
for x in range(remaining):
total += 2+x
print (total)
``` | 4 2
| 4
| 4
| true | 2,460 |
apps | verifiable_code | 1001 | Solve the following coding problem using the programming language python:
Once upon a time Petya and Gena gathered after another programming competition and decided to play some game. As they consider most modern games to be boring, they always try to invent their own games. They have only stickers and markers, but th... | ```python
n = int(input())
a = [0] * n
a = list(map(int, input().split()))
for i in range(1, len(a)):
a[i] += a[i - 1]
ans = a[-1]
for i in range(n - 2, 0, -1):
ans = max(ans, a[i] - ans)
print(ans)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n2 4 8\n', 'output': '14\n'}, {'type': 'stdin_stdout', 'input': '4\n1 -7 -2 3\n', 'output': '-3\n'}, {'type': 'stdin_stdout', 'input': '10\n35 11 35 28 48 25 2 43 23 10\n', 'output': '260\n'}, {'type': 'stdin_stdout', 'input': '100\n437 89 481 95 29 326 10 304 97 414... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/731/E'} | vfc_13758 | ```python
n = int(input())
a = [0] * n
a = list(map(int, input().split()))
for i in range(1, len(a)):
a[i] += a[i - 1]
ans = a[-1]
for i in range(n - 2, 0, -1):
ans = max(ans, a[i] - ans)
print(ans)
``` | 3
2 4 8
| 14
| 14
| true | 2,461 |
apps | verifiable_code | 1002 | Solve the following coding problem using the programming language python:
Devu is a renowned classical singer. He is invited to many big functions/festivals. Recently he was invited to "All World Classical Singing Festival". Other than Devu, comedian Churu was also invited.
Devu has provided organizers a list of the ... | ```python
"""
Codeforces Round 251 Div 2 Problem A
Author : chaotic_iak
Language: Python 3.3.4
"""
def read(mode=2):
# 0: String
# 1: List of strings
# 2: List of integers
inputs = input().strip()
if mode == 0:
return inputs
if mode == 1:
return inputs.split()
if mode == 2... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 30\n2 2 1\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '3 20\n2 1 1\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '50 10000\n5 4 10 9 9 6 7 7 7 3 3 7 7 4 7 4 10 10 1 7 10 3 1 4 5 7 2 10 10 10 2 3 4 7 6 1 8 4 7 3 8 8 4 10 1 1 9 2 6 1\n', 'output'... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/439/A'} | vfc_13762 | ```python
"""
Codeforces Round 251 Div 2 Problem A
Author : chaotic_iak
Language: Python 3.3.4
"""
def read(mode=2):
# 0: String
# 1: List of strings
# 2: List of integers
inputs = input().strip()
if mode == 0:
return inputs
if mode == 1:
return inputs.split()
if mode == 2... | 3 30
2 2 1
| 5
| 5
| true | 2,462 |
apps | verifiable_code | 1003 | Solve the following coding problem using the programming language python:
Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, ... | ```python
"""
Codeforces Contest 262 Div 2 Problem A
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
n,m = read()
i = 0
while n:
n -= 1
i += 1
if not i%m: n += 1
print(i)
################################### NON-SOLUTION STUFF BELOW
def read(mode=2):
# 0: Stri... | {'test_cases': [{'type': 'stdin_stdout', 'input': '2 2\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '9 3\n', 'output': '13\n'}, {'type': 'stdin_stdout', 'input': '1 2\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '2 3\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '1 99\n', 'output': '1\n'... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/460/A'} | vfc_13766 | ```python
"""
Codeforces Contest 262 Div 2 Problem A
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
n,m = read()
i = 0
while n:
n -= 1
i += 1
if not i%m: n += 1
print(i)
################################### NON-SOLUTION STUFF BELOW
def read(mode=2):
# 0: Stri... | 2 2
| 3
| 3
| true | 2,463 |
apps | verifiable_code | 1004 | Solve the following coding problem using the programming language python:
The Central Company has an office with a sophisticated security system. There are $10^6$ employees, numbered from $1$ to $10^6$.
The security system logs entrances and departures. The entrance of the $i$-th employee is denoted by the integer $i... | ```python
import sys
from collections import Counter
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
S = set()
ans = True
Ans = []
cnt = 0
for a in A:
cnt += 1
if a > 0:
S.add(a)
else:
a = -a
if a not in S:
ans = False
... | {'test_cases': [{'type': 'stdin_stdout', 'input': '6\n1 7 -7 3 -1 -3\n', 'output': '1\n6\n'}, {'type': 'stdin_stdout', 'input': '8\n1 -1 1 2 -1 -2 3 -3\n', 'output': '3\n2 4 2\n'}, {'type': 'stdin_stdout', 'input': '6\n2 5 -5 5 -5 -2\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '3\n-8 1 1\n', 'output': '-1\... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1253/B'} | vfc_13770 | ```python
import sys
from collections import Counter
readline = sys.stdin.readline
N = int(readline())
A = list(map(int, readline().split()))
S = set()
ans = True
Ans = []
cnt = 0
for a in A:
cnt += 1
if a > 0:
S.add(a)
else:
a = -a
if a not in S:
ans = False
... | 6
1 7 -7 3 -1 -3
| 1
6
| 1
6
| true | 2,464 |
apps | verifiable_code | 1005 | Solve the following coding problem using the programming language python:
The only difference between easy and hard versions is constraints.
The BerTV channel every day broadcasts one episode of one of the $k$ TV shows. You know the schedule for the next $n$ days: a sequence of integers $a_1, a_2, \dots, a_n$ ($1 \le... | ```python
for i in range(int(input())):
n, k, d = map(int, input().split())
a = list(map(int, input().split()))
ans = d
for day in range(n - d + 1):
ans = min(ans, len(set(a[day:day + d])))
print(ans)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '4\n5 2 2\n1 2 1 2 1\n9 3 3\n3 3 3 2 2 2 1 1 1\n4 10 4\n10 8 6 4\n16 9 8\n3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3\n', 'output': '2\n1\n4\n5\n'}, {'type': 'stdin_stdout', 'input': '30\n4 4 1\n3 3 1 2\n4 4 1\n4 1 4 1\n1 1 1\n1\n3 2 1\n2 1 2\n4 4 2\n3 2 2 2\n4 2 4\n1 2 2 2\n1 4 1\... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1225/B1'} | vfc_13774 | ```python
for i in range(int(input())):
n, k, d = map(int, input().split())
a = list(map(int, input().split()))
ans = d
for day in range(n - d + 1):
ans = min(ans, len(set(a[day:day + d])))
print(ans)
``` | 4
5 2 2
1 2 1 2 1
9 3 3
3 3 3 2 2 2 1 1 1
4 10 4
10 8 6 4
16 9 8
3 1 4 1 5 9 2 6 5 3 5 8 9 7 9 3
| 2
1
4
5
| 2
1
4
5
| true | 2,465 |
apps | verifiable_code | 1006 | Solve the following coding problem using the programming language python:
Fox Ciel has a board with n rows and n columns. So, the board consists of n × n cells. Each cell contains either a symbol '.', or a symbol '#'.
A cross on the board is a connected set of exactly five cells of the board that looks like a cross. ... | ```python
n = int(input())
arr = []
for i in range(n):
arr.append(list(input()))
k = 1
for i in range(n):
for j in range(n):
if arr[i][j] == '#':
if i+2<=n-1 and j-1>=0 and j+1<=n-1:
if arr[i+1][j-1] == '#' and arr[i+1][j] == '#' and arr[i+1][j+1] == '#' and arr[i+2][j] == '#... | {'test_cases': [{'type': 'stdin_stdout', 'input': '5\n.#...\n####.\n.####\n...#.\n.....\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '4\n####\n####\n####\n####\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '6\n.#....\n####..\n.####.\n.#.##.\n######\n.#..#.\n', 'output': 'YES\n'}, {'type': 'stdin... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/389/B'} | vfc_13778 | ```python
n = int(input())
arr = []
for i in range(n):
arr.append(list(input()))
k = 1
for i in range(n):
for j in range(n):
if arr[i][j] == '#':
if i+2<=n-1 and j-1>=0 and j+1<=n-1:
if arr[i+1][j-1] == '#' and arr[i+1][j] == '#' and arr[i+1][j+1] == '#' and arr[i+2][j] == '#... | 5
.#...
####.
.####
...#.
.....
| YES
| YES
| true | 2,466 |
apps | verifiable_code | 1007 | Solve the following coding problem using the programming language python:
— Thanks a lot for today.
— I experienced so many great things.
— You gave me memories like dreams... But I have to leave now...
— One last request, can you...
— Help me solve a Codeforces problem?
— ......
— What?
Chtholly has been think... | ```python
from itertools import *
k, p = list(map(int, input().split()))
ss = 0
for i in range(1, k + 1):
s = str(i)
num = int(s + ''.join(reversed(s)))
ss += num
ss %= p
print(ss)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '2 100\n', 'output': '33\n'}, {'type': 'stdin_stdout', 'input': '5 30\n', 'output': '15\n'}, {'type': 'stdin_stdout', 'input': '42147 412393322\n', 'output': '251637727\n'}, {'type': 'stdin_stdout', 'input': '77809 868097296\n', 'output': '440411873\n'}, {'type': 'stdin... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/897/B'} | vfc_13782 | ```python
from itertools import *
k, p = list(map(int, input().split()))
ss = 0
for i in range(1, k + 1):
s = str(i)
num = int(s + ''.join(reversed(s)))
ss += num
ss %= p
print(ss)
``` | 2 100
| 33
| 33
| true | 2,467 |
apps | verifiable_code | 1008 | Solve the following coding problem using the programming language python:
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s.
[Image]
He is not sure if this is his... | ```python
def check(pali):
for i in range(len(pali) // 2):
if pali[i] != pali[-i - 1]:
return False
return True
def __starting_point():
s = input()
k = int(input())
if len(s) % k != 0:
print('NO')
return
step = len(s) // k
for i in range(k):
i... | {'test_cases': [{'type': 'stdin_stdout', 'input': 'saba\n2\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': 'saddastavvat\n2\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': 'aaaaaaaaaa\n3\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': 'aaaaaa\n3\n', 'output': 'YES\n'}, {'type': 'stdin_stdout... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/548/A'} | vfc_13786 | ```python
def check(pali):
for i in range(len(pali) // 2):
if pali[i] != pali[-i - 1]:
return False
return True
def __starting_point():
s = input()
k = int(input())
if len(s) % k != 0:
print('NO')
return
step = len(s) // k
for i in range(k):
i... | saba
2
| NO
| NO
| true | 2,468 |
apps | verifiable_code | 1009 | Solve the following coding problem using the programming language python:
Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into k boxes of a fixed size. In order to keep his collection safe ... | ```python
n, k = list(map(int,input().split()))
L = list(map(int,input().split()))
i = 0
p = 0
z = 1
R = [0 for _ in range(k)]
while i<n:
R[p] += L[n-1-i]
p = p + z
i+=1
if p == k or p == -1:
z = z*(-1)
if p == k:
p = p - 1
else:
p = p + 1
print(max(R))
... | {'test_cases': [{'type': 'stdin_stdout', 'input': '2 1\n2 5\n', 'output': '7\n'}, {'type': 'stdin_stdout', 'input': '4 3\n2 3 5 9\n', 'output': '9\n'}, {'type': 'stdin_stdout', 'input': '3 2\n3 5 7\n', 'output': '8\n'}, {'type': 'stdin_stdout', 'input': '20 11\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n', 'output': '2\n... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/604/B'} | vfc_13790 | ```python
n, k = list(map(int,input().split()))
L = list(map(int,input().split()))
i = 0
p = 0
z = 1
R = [0 for _ in range(k)]
while i<n:
R[p] += L[n-1-i]
p = p + z
i+=1
if p == k or p == -1:
z = z*(-1)
if p == k:
p = p - 1
else:
p = p + 1
print(max(R))
... | 2 1
2 5
| 7
| 7
| true | 2,469 |
apps | verifiable_code | 1010 | Solve the following coding problem using the programming language python:
Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between... | ```python
x = int(input())
y = list(map(int, input().split(' ')))
if y == [0] * x:
print(0)
quit()
for i in range(x):
if y[i] == 1:
y = y[i:]
break
y.reverse()
for i in range(len(y)):
if y[i] == 1:
y = y[i:]
break
y.reverse()
l = []
ct = 0
for i in y:
if i == 0:
... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n0 1 0\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '5\n1 0 1 0 1\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '10\n0 0 1 0 0 0 1 1 0 1\n', 'output': '8\n'}, {'type': 'stdin_stdout', 'input': '20\n0 0 0 0 1 1 1 0 1 0 0 1 0 1 1 0 1 1 1 0\n', 'out... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/617/B'} | vfc_13794 | ```python
x = int(input())
y = list(map(int, input().split(' ')))
if y == [0] * x:
print(0)
quit()
for i in range(x):
if y[i] == 1:
y = y[i:]
break
y.reverse()
for i in range(len(y)):
if y[i] == 1:
y = y[i:]
break
y.reverse()
l = []
ct = 0
for i in y:
if i == 0:
... | 3
0 1 0
| 1
| 1
| true | 2,470 |
apps | verifiable_code | 1011 | Solve the following coding problem using the programming language python:
Vasya follows a basketball game and marks the distances from which each team makes a throw. He knows that each successful throw has value of either 2 or 3 points. A throw is worth 2 points if the distance it was made from doesn't exceed some val... | ```python
"""
Codeforces Contest 281 Div 2 Problem C
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
n, = read()
a = read()
res = [(i,0) for i in a]
m, = read()
b = read()
res.extend((i,1) for i in b)
res.sort()
mxa = 3*n
mnb = 3*m
cra = 3*n
crb = 3*m
for _... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 2 3\n2\n5 6\n', 'output': '9:6\n'}, {'type': 'stdin_stdout', 'input': '5\n6 7 8 9 10\n5\n1 2 3 4 5\n', 'output': '15:10\n'}, {'type': 'stdin_stdout', 'input': '5\n1 2 3 4 5\n5\n6 7 8 9 10\n', 'output': '15:15\n'}, {'type': 'stdin_stdout', 'input': '3\n1 2 3\n3\n6 ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/493/C'} | vfc_13798 | ```python
"""
Codeforces Contest 281 Div 2 Problem C
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
n, = read()
a = read()
res = [(i,0) for i in a]
m, = read()
b = read()
res.extend((i,1) for i in b)
res.sort()
mxa = 3*n
mnb = 3*m
cra = 3*n
crb = 3*m
for _... | 3
1 2 3
2
5 6
| 9:6
| 9:6
| true | 2,471 |
apps | verifiable_code | 1012 | Solve the following coding problem using the programming language python:
You are given a string $s$ consisting only of lowercase Latin letters.
You can rearrange all letters of this string as you wish. Your task is to obtain a good string by rearranging the letters of the given string or report that it is impossible... | ```python
# map(int, input())
t = int(input())
for i in range(t):
s = sorted(input())
if s[0] == s[-1]:
print(-1)
continue
print(''.join(s))
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\naa\nabacaba\nxdd\n', 'output': '-1\naaaabbc\nddx\n'}, {'type': 'stdin_stdout', 'input': '100\naa\nb\ncbc\nc\nbab\nc\nbdb\ndd\nhfh\nebe\nb\nf\ngg\na\nm\nkkk\nqq\ni\noo\nss\ntt\nere\njgj\nqiq\nkk\nn\naaa\nb\naa\nb\nc\na\nf\ne\na\naa\nff\ne\na\nafa\no\nmom\nqq\nf\niii\... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1093/B'} | vfc_13802 | ```python
# map(int, input())
t = int(input())
for i in range(t):
s = sorted(input())
if s[0] == s[-1]:
print(-1)
continue
print(''.join(s))
``` | 3
aa
abacaba
xdd
| -1
aaaabbc
ddx
| -1
aaaabbc
ddx
| true | 2,472 |
apps | verifiable_code | 1013 | Solve the following coding problem using the programming language python:
Simon has a rectangular table consisting of n rows and m columns. Simon numbered the rows of the table from top to bottom starting from one and the columns — from left to right starting from one. We'll represent the cell on the x-th row and the ... | ```python
n, m = list(map(int, input().split()))
A = [input().split() for i in range(n)]
T = False
for i in range(n):
for j in range(m):
if A[i][j] == '1' and (i == 0 or j == 0 or i == n - 1 or j == m - 1):
T = True
if T:
print(2)
else:
print(4)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\n0 0 0\n0 1 0\n0 0 0\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '4 3\n0 0 0\n0 0 1\n1 0 0\n0 0 0\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '50 4\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 0 0 0\n0 ... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/359/A'} | vfc_13806 | ```python
n, m = list(map(int, input().split()))
A = [input().split() for i in range(n)]
T = False
for i in range(n):
for j in range(m):
if A[i][j] == '1' and (i == 0 or j == 0 or i == n - 1 or j == m - 1):
T = True
if T:
print(2)
else:
print(4)
``` | 3 3
0 0 0
0 1 0
0 0 0
| 4
| 4
| true | 2,473 |
apps | verifiable_code | 1014 | Solve the following coding problem using the programming language python:
Vasya decided to learn to play chess. Classic chess doesn't seem interesting to him, so he plays his own sort of chess.
The queen is the piece that captures all squares on its vertical, horizontal and diagonal lines. If the cell is located on t... | ```python
"""
Codeforces Contest 281 Div 2 Problem D
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
n, = read()
if n%2:
print("black")
else:
print("white")
print("1 2")
################################### NON-SOLUTION STUFF BELOW
def read(mode=2):
# 0: String
... | {'test_cases': [{'type': 'stdin_stdout', 'input': '2\n', 'output': 'white\n1 2\n'}, {'type': 'stdin_stdout', 'input': '3\n', 'output': 'black\n'}, {'type': 'stdin_stdout', 'input': '4\n', 'output': 'white\n1 2\n'}, {'type': 'stdin_stdout', 'input': '6\n', 'output': 'white\n1 2\n'}, {'type': 'stdin_stdout', 'input': '10... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/493/D'} | vfc_13810 | ```python
"""
Codeforces Contest 281 Div 2 Problem D
Author : chaotic_iak
Language: Python 3.3.4
"""
def main():
n, = read()
if n%2:
print("black")
else:
print("white")
print("1 2")
################################### NON-SOLUTION STUFF BELOW
def read(mode=2):
# 0: String
... | 2
| white
1 2
| white
1 2
| true | 2,474 |
apps | verifiable_code | 1015 | Solve the following coding problem using the programming language python:
A lighthouse keeper Peter commands an army of $n$ battle lemmings. He ordered his army to stand in a line and numbered the lemmings from $1$ to $n$ from left to right. Some of the lemmings hold shields. Each lemming cannot hold more than one shi... | ```python
# import numpy as npy
# idx=sorted(idx,key=functools.cmp_to_key(cmpx))
import bisect
import array
import functools
import math
n=int(input())
a=array.array('i',map(int,input().split()))
s=0
q=[]
q.append(0)
for i in range(n):
if a[i]==1:
q.append(i+1)
s=s+1
q.append(n+1)
m=n*(n-1)//2
f=[[... | {'test_cases': [{'type': 'stdin_stdout', 'input': '5\n1 0 0 0 1\n', 'output': '0 2 3 3 3 3 3 3 3 3 3 \n'}, {'type': 'stdin_stdout', 'input': '12\n0 0 0 0 1 1 1 1 0 1 1 0\n', 'output': '9 12 13 14 14 14 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 15 1... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1420/E'} | vfc_13814 | ```python
# import numpy as npy
# idx=sorted(idx,key=functools.cmp_to_key(cmpx))
import bisect
import array
import functools
import math
n=int(input())
a=array.array('i',map(int,input().split()))
s=0
q=[]
q.append(0)
for i in range(n):
if a[i]==1:
q.append(i+1)
s=s+1
q.append(n+1)
m=n*(n-1)//2
f=[[... | 5
1 0 0 0 1
| 0 2 3 3 3 3 3 3 3 3 3
| 0 2 3 3 3 3 3 3 3 3 3 | true | 2,475 |
apps | verifiable_code | 1017 | Solve the following coding problem using the programming language python:
Little Artem got n stones on his birthday and now wants to give some of them to Masha. He knows that Masha cares more about the fact of receiving the present, rather than the value of that present, so he wants to give her stones as many times as... | ```python
n = int(input())
if n % 3 == 0:
print(2 * (n // 3))
else:
print(2 * (n // 3) + 1)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '2\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '100\n', 'output': '67\n'}, {'type... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/669/A'} | vfc_13822 | ```python
n = int(input())
if n % 3 == 0:
print(2 * (n // 3))
else:
print(2 * (n // 3) + 1)
``` | 1
| 1
| 1
| true | 2,476 |
apps | verifiable_code | 1018 | Solve the following coding problem using the programming language python:
Stepan has n pens. Every day he uses them, and on the i-th day he uses the pen number i. On the (n + 1)-th day again he uses the pen number 1, on the (n + 2)-th — he uses the pen number 2 and so on.
On every working day (from Monday to Saturday... | ```python
import sys
def Min(x, y):
if x > y:
return y
else:
return x
def Gcd(x, y):
if x == 0:
return y
else:
return Gcd(y % x, x)
def Lcm(x, y):
return x * y // Gcd(x, y)
n = int(input())
a = [int(i) for i in input().split()]
d = [int(0) for i in range(0, n)]
o... | {'test_cases': [{'type': 'stdin_stdout', 'input': '3\n3 3 3\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '5\n5 4 5 4 4\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '28\n2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033 2033... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/774/F'} | vfc_13826 | ```python
import sys
def Min(x, y):
if x > y:
return y
else:
return x
def Gcd(x, y):
if x == 0:
return y
else:
return Gcd(y % x, x)
def Lcm(x, y):
return x * y // Gcd(x, y)
n = int(input())
a = [int(i) for i in input().split()]
d = [int(0) for i in range(0, n)]
o... | 3
3 3 3
| 2
| 2
| true | 2,477 |
apps | verifiable_code | 1020 | Solve the following coding problem using the programming language python:
You have a plate and you want to add some gilding to it. The plate is a rectangle that we split into $w\times h$ cells. There should be $k$ gilded rings, the first one should go along the edge of the plate, the second one — $2$ cells away from t... | ```python
w, h, k = map(int, input().split())
ans = 0
for i in range(k):
ans += w * 2 + (h - 2) * 2
#print(ans, h, w)
w -= 4
h -= 4
print(ans)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '3 3 1\n', 'output': '8\n'}, {'type': 'stdin_stdout', 'input': '7 9 1\n', 'output': '28\n'}, {'type': 'stdin_stdout', 'input': '7 9 2\n', 'output': '40\n'}, {'type': 'stdin_stdout', 'input': '18 26 3\n', 'output': '204\n'}, {'type': 'stdin_stdout', 'input': '63 34 8\n',... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1031/A'} | vfc_13834 | ```python
w, h, k = map(int, input().split())
ans = 0
for i in range(k):
ans += w * 2 + (h - 2) * 2
#print(ans, h, w)
w -= 4
h -= 4
print(ans)
``` | 3 3 1
| 8
| 8
| true | 2,478 |
apps | verifiable_code | 1021 | Solve the following coding problem using the programming language python:
Grigory has $n$ magic stones, conveniently numbered from $1$ to $n$. The charge of the $i$-th stone is equal to $c_i$.
Sometimes Grigory gets bored and selects some inner stone (that is, some stone with index $i$, where $2 \le i \le n - 1$), an... | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
def dif(x):
c = []
for i in range(n-1):
c.append(x[i+1] - x[i])
return c
if list(sorted(dif(a))) == list(sorted(dif(b))) and a[0] == b[0] and a[n-1] == b[n-1]:
print('Yes')
else:
print('No')
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '4\n7 2 4 12\n7 15 10 12\n', 'output': 'Yes\n'}, {'type': 'stdin_stdout', 'input': '3\n4 4 4\n1 2 3\n', 'output': 'No\n'}, {'type': 'stdin_stdout', 'input': '10\n707645074 7978468 456945316 474239945 262709403 240934546 113271669 851586694 388901819 787182236\n707645074... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1110/E'} | vfc_13838 | ```python
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
def dif(x):
c = []
for i in range(n-1):
c.append(x[i+1] - x[i])
return c
if list(sorted(dif(a))) == list(sorted(dif(b))) and a[0] == b[0] and a[n-1] == b[n-1]:
print('Yes')
else:
print('No')
``` | 4
7 2 4 12
7 15 10 12
| Yes
| Yes
| true | 2,479 |
apps | verifiable_code | 1022 | Solve the following coding problem using the programming language python:
There are $n$ children numbered from $1$ to $n$ in a kindergarten. Kindergarten teacher gave $a_i$ ($1 \leq a_i \leq n$) candies to the $i$-th child. Children were seated in a row in order from $1$ to $n$ from left to right and started eating ca... | ```python
n=int(input())
#x,y,z,t1,t2,t3=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=[0]*n
ans=True
for i in range(n):
ans=ans and a[i]<=i and b[i]<=(n-i-1)
s[i]=n-a[i]-b[i]
def qwe(s,j):
l,r=0,0
for i in range(len(s)):
if i<j and s[i]>s[j]: l... | {'test_cases': [{'type': 'stdin_stdout', 'input': '5\n0 0 1 1 2\n2 0 1 0 0\n', 'output': 'YES\n3 5 3 4 3 '}, {'type': 'stdin_stdout', 'input': '4\n0 0 2 0\n1 1 1 1\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '3\n0 0 0\n0 0 0\n', 'output': 'YES\n3 3 3 '}, {'type': 'stdin_stdout', 'input': '1\n0\n0\n', 'outp... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1054/C'} | vfc_13842 | ```python
n=int(input())
#x,y,z,t1,t2,t3=map(int,input().split())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
s=[0]*n
ans=True
for i in range(n):
ans=ans and a[i]<=i and b[i]<=(n-i-1)
s[i]=n-a[i]-b[i]
def qwe(s,j):
l,r=0,0
for i in range(len(s)):
if i<j and s[i]>s[j]: l... | 5
0 0 1 1 2
2 0 1 0 0
| YES
3 5 3 4 3 | YES
3 5 3 4 3 | true | 2,480 |
apps | verifiable_code | 1023 | Solve the following coding problem using the programming language python:
Arkady bought an air ticket from a city A to a city C. Unfortunately, there are no direct flights, but there are a lot of flights from A to a city B, and from B to C.
There are $n$ flights from A to B, they depart at time moments $a_1$, $a_2$, ... | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, s... | {'test_cases': [{'type': 'stdin_stdout', 'input': '4 5 1 1 2\n1 3 5 7\n1 2 3 9 10\n', 'output': '11\n'}, {'type': 'stdin_stdout', 'input': '2 2 4 4 2\n1 10\n10 20\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '4 3 2 3 1\n1 999999998 999999999 1000000000\n3 4 1000000000\n', 'output': '1000000003\n'}, {'type':... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1148/B'} | vfc_13846 | ```python
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
import random
sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
def LI(): return list(map(int, s... | 4 5 1 1 2
1 3 5 7
1 2 3 9 10
| 11
| 11
| true | 2,481 |
apps | verifiable_code | 1026 | Solve the following coding problem using the programming language python:
Tanya wants to go on a journey across the cities of Berland. There are $n$ cities situated along the main railroad line of Berland, and these cities are numbered from $1$ to $n$.
Tanya plans her journey as follows. First of all, she will choos... | ```python
n = int(input())
B = list(map(int, input().split()))
pp = {}
for i in range(n):
if B[i] - (i + 1) not in pp:
pp[B[i] - (i + 1)] = 0
pp[B[i] - (i + 1)] += B[i]
ans = 0
for c in pp:
ans = max(ans, pp[c])
print(ans)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '6\n10 7 1 9 10 15\n', 'output': '26\n'}, {'type': 'stdin_stdout', 'input': '1\n400000\n', 'output': '400000\n'}, {'type': 'stdin_stdout', 'input': '7\n8 9 26 11 12 29 14\n', 'output': '55\n'}, {'type': 'stdin_stdout', 'input': '10\n10 60 12 13 14 15 16 66 18 130\n', 'o... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/1319/B'} | vfc_13858 | ```python
n = int(input())
B = list(map(int, input().split()))
pp = {}
for i in range(n):
if B[i] - (i + 1) not in pp:
pp[B[i] - (i + 1)] = 0
pp[B[i] - (i + 1)] += B[i]
ans = 0
for c in pp:
ans = max(ans, pp[c])
print(ans)
``` | 6
10 7 1 9 10 15
| 26
| 26
| true | 2,483 |
apps | verifiable_code | 1027 | Solve the following coding problem using the programming language python:
Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes. [Image]
Initially, each hole has $a_i$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes ... | ```python
def f(a, ind):
if a[ind] == 0:
return -1
k = a[ind] // 14
x = a[ind] % 14
b = a[:]
b[ind] = 0
for j in range(14):
b[j] += k
for j in range(ind + 1, ind + x + 1):
j1 = j % 14
b[j1] += 1
res = 0
for j in range(14):
if b[j] % 2 == 0:
... | {'test_cases': [{'type': 'stdin_stdout', 'input': '0 1 1 0 0 0 0 0 0 7 0 0 0 0\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '5 1 1 1 1 0 0 0 0 0 0 0 0 0\n', 'output': '8\n'}, {'type': 'stdin_stdout', 'input': '10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 10001 1\n', 'output': '5429... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/975/B'} | vfc_13862 | ```python
def f(a, ind):
if a[ind] == 0:
return -1
k = a[ind] // 14
x = a[ind] % 14
b = a[:]
b[ind] = 0
for j in range(14):
b[j] += k
for j in range(ind + 1, ind + x + 1):
j1 = j % 14
b[j1] += 1
res = 0
for j in range(14):
if b[j] % 2 == 0:
... | 0 1 1 0 0 0 0 0 0 7 0 0 0 0
| 4
| 4
| true | 2,484 |
apps | verifiable_code | 1028 | Solve the following coding problem using the programming language python:
n participants of the competition were split into m teams in some manner so that each team has at least one participant. After the competition each pair of participants from the same team became friends.
Your task is to write a program that wil... | ```python
"""
Codeforces Contest 273 Div 2 Problem B
Author : chaotic_iak
Language: Python 3.3.4
"""
def comb2(n):
return n*(n-1)//2
def main():
n,m = read()
k = n // m
p = n % m
mn = p * comb2(k+1) + (m-p) * comb2(k)
mx = comb2(n-m+1)
print(mn, mx)
################################### N... | {'test_cases': [{'type': 'stdin_stdout', 'input': '5 1\n', 'output': '10 10\n'}, {'type': 'stdin_stdout', 'input': '3 2\n', 'output': '1 1\n'}, {'type': 'stdin_stdout', 'input': '6 3\n', 'output': '3 6\n'}, {'type': 'stdin_stdout', 'input': '5 3\n', 'output': '2 3\n'}, {'type': 'stdin_stdout', 'input': '10 2\n', 'outpu... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/478/B'} | vfc_13866 | ```python
"""
Codeforces Contest 273 Div 2 Problem B
Author : chaotic_iak
Language: Python 3.3.4
"""
def comb2(n):
return n*(n-1)//2
def main():
n,m = read()
k = n // m
p = n % m
mn = p * comb2(k+1) + (m-p) * comb2(k)
mx = comb2(n-m+1)
print(mn, mx)
################################### N... | 5 1
| 10 10
| 10 10
| true | 2,485 |
apps | verifiable_code | 1029 | Solve the following coding problem using the programming language python:
George is a cat, so he really likes to play. Most of all he likes to play with his array of positive integers b. During the game, George modifies the array by using special changes. Let's mark George's current array as b_1, b_2, ..., b_{|}b| (re... | ```python
s=input().strip()
n=len(s)
i=0
k=1
j=0
while i<n:
#print(i,j)
j=i
i+=1
while i<n and s[i]=='0':
i+=1
if j>i-j:
k+=1
elif j==i-j:
if s[:j]>=s[j:i]:
k+=1
else:
k=1
else:
k=1
print(k)
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '9555\n', 'output': '4'}, {'type': 'stdin_stdout', 'input': '10000000005\n', 'output': '2'}, {'type': 'stdin_stdout', 'input': '800101\n', 'output': '3'}, {'type': 'stdin_stdout', 'input': '45\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': '1000000000000001223300... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/387/C'} | vfc_13870 | ```python
s=input().strip()
n=len(s)
i=0
k=1
j=0
while i<n:
#print(i,j)
j=i
i+=1
while i<n and s[i]=='0':
i+=1
if j>i-j:
k+=1
elif j==i-j:
if s[:j]>=s[j:i]:
k+=1
else:
k=1
else:
k=1
print(k)
``` | 9555
| 4 | 4
| true | 2,486 |
apps | verifiable_code | 1030 | Solve the following coding problem using the programming language python:
User ainta is making a web site. This time he is going to make a navigation of the pages. In his site, there are n pages numbered by integers from 1 to n. Assume that somebody is on the p-th page now. The navigation will look like this: << p - k... | ```python
n, p, k = map(int, input().split())
if (p - k) > 1:
print('<<', end = ' ')
for i in range(p - k, p):
if (i > 0):
print(i, end = ' ')
print('(' + str(p) + ')', end = ' ')
for i in range(p + 1, p + k + 1):
if (i < (n + 1)):
print(i, end = ' ')
if (p + k) < n:
print('>>', end = ' ')
``` | {'test_cases': [{'type': 'stdin_stdout', 'input': '17 5 2\n', 'output': '<< 3 4 (5) 6 7 >> '}, {'type': 'stdin_stdout', 'input': '6 5 2\n', 'output': '<< 3 4 (5) 6 '}, {'type': 'stdin_stdout', 'input': '6 1 2\n', 'output': '(1) 2 3 >> '}, {'type': 'stdin_stdout', 'input': '6 2 2\n', 'output': '1 (2) 3 4 >> '}, {'type':... | {'difficulty': 'interview', 'problem_url': 'https://codeforces.com/problemset/problem/399/A'} | vfc_13874 | ```python
n, p, k = map(int, input().split())
if (p - k) > 1:
print('<<', end = ' ')
for i in range(p - k, p):
if (i > 0):
print(i, end = ' ')
print('(' + str(p) + ')', end = ' ')
for i in range(p + 1, p + k + 1):
if (i < (n + 1)):
print(i, end = ' ')
if (p + k) < n:
print('>>', end = ' ')
``` | 17 5 2
| << 3 4 (5) 6 7 >> | << 3 4 (5) 6 7 >> | true | 2,487 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.