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
2096
Solve the following coding problem using the programming language python: You are given a sequence a_1, a_2, ..., a_{n} consisting of different integers. It is required to split this sequence into the maximum number of subsequences such that after sorting integers in each of them in increasing order, the total sequenc...
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline n=int(input()) b=list(map(int,input().split())) bb=sorted(b) c={bb[i]:i for i in range(n)} a=[c[b[i]] for i in range(n)] vis=[0]*n out=[] for i in range(n): if vis[i]: continue vis[i]=1 newlist=[i] while a[newlist[-1]]!=i: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '6\n3 2 1 6 5 4\n', 'output': '4\n2 1 3\n1 2\n2 4 6\n1 5\n'}, {'type': 'stdin_stdout', 'input': '6\n83 -75 -49 11 37 62\n', 'output': '1\n6 1 2 3 4 5 6\n'}, {'type': 'stdin_stdout', 'input': '1\n1\n', 'output': '1\n1 1\n'}, {'type': 'stdin_stdout', 'input': '2\n1 2\n', ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/843/A'}
vfc_5930
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline n=int(input()) b=list(map(int,input().split())) bb=sorted(b) c={bb[i]:i for i in range(n)} a=[c[b[i]] for i in range(n)] vis=[0]*n out=[] for i in range(n): if vis[i]: continue vis[i]=1 newlist=[i] while a[newlist[-1]]!=i: ...
6 3 2 1 6 5 4
4 2 1 3 1 2 2 4 6 1 5
4 2 1 3 1 2 2 4 6 1 5
true
1,292
apps
verifiable_code
2097
Solve the following coding problem using the programming language python: DZY loves planting, and he enjoys solving tree problems. DZY has a weighted tree (connected undirected graph without cycles) containing n nodes (they are numbered from 1 to n). He defines the function g(x, y) (1 ≤ x, y ≤ n) as the longest edge ...
```python n = int(input()) edges = [[int(x) for x in input().split()] for i in range(n-1)] edges = sorted(edges) use_count = [0]+[int(input()) for i in range(n)] lo,hi = 0,10000 def getpar(par,u): if par[par[u]] == par[u]: return par[u] par[u] = getpar(par,par[u]) return par[u] def unite(par,sz,use,...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n1 2 1\n2 3 2\n3 4 3\n1\n1\n1\n1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4\n1 2 1\n2 3 2\n3 4 3\n4\n4\n4\n4\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '10\n2 1 8760\n3 1 3705\n4 1 1862\n5 2 7332\n6 3 7015\n7 5 4866\n8 3 4465\n9 7 8886\n1...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/444/E'}
vfc_5934
```python n = int(input()) edges = [[int(x) for x in input().split()] for i in range(n-1)] edges = sorted(edges) use_count = [0]+[int(input()) for i in range(n)] lo,hi = 0,10000 def getpar(par,u): if par[par[u]] == par[u]: return par[u] par[u] = getpar(par,par[u]) return par[u] def unite(par,sz,use,...
4 1 2 1 2 3 2 3 4 3 1 1 1 1
2
2
true
1,293
apps
verifiable_code
2098
Solve the following coding problem using the programming language python: As you know, majority of students and teachers of Summer Informatics School live in Berland for the most part of the year. Since corruption there is quite widespread, the following story is not uncommon. Elections are coming. You know the numbe...
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline n,m=list(map(int,input().split())) party=[[] for _ in range(m+5)] pc=sorted([list(map(int,input().split())) for _ in range(n)],key=lambda x:x[1]) choose=[0]*n for i in range(n): party[pc[i][0]].append(i) want=10**18 for i in range(1,n+...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1 2\n1 100\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '5 5\n2 100\n3 200\n4 300\n5 400\n5 900\n', 'output': '500\n'}, {'type': 'stdin_stdout', 'input': '5 5\n2 100\n3 200\n4 300\n5 800\n5 900\n', 'output': '600\n'}, {'type': 'stdin_stdout', 'input': '5 5\n...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1019/A'}
vfc_5938
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline n,m=list(map(int,input().split())) party=[[] for _ in range(m+5)] pc=sorted([list(map(int,input().split())) for _ in range(n)],key=lambda x:x[1]) choose=[0]*n for i in range(n): party[pc[i][0]].append(i) want=10**18 for i in range(1,n+...
1 2 1 100
0
0
true
1,294
apps
verifiable_code
2099
Solve the following coding problem using the programming language python: Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p_1, p_2, ..., p_{n}. Your task is to find such permutation ...
```python 3 import sys def __starting_point(): n, k = list(map(int, sys.stdin.readline().split())) l = [] i = 1 j = k + 1 while i <= j: l.append(str(i)) i += 1 if j > i: l.append(str(j)) j -= 1 for i in range(k+2, n+1): l.append(str(...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 2\n', 'output': '1 3 2\n'}, {'type': 'stdin_stdout', 'input': '3 1\n', 'output': '1 2 3\n'}, {'type': 'stdin_stdout', 'input': '5 2\n', 'output': '1 3 2 4 5\n'}, {'type': 'stdin_stdout', 'input': '5 4\n', 'output': '1 5 2 4 3\n'}, {'type': 'stdin_stdout', 'input': '1...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/482/A'}
vfc_5942
```python 3 import sys def __starting_point(): n, k = list(map(int, sys.stdin.readline().split())) l = [] i = 1 j = k + 1 while i <= j: l.append(str(i)) i += 1 if j > i: l.append(str(j)) j -= 1 for i in range(k+2, n+1): l.append(str(...
3 2
1 3 2
1 3 2
true
1,295
apps
verifiable_code
2101
Solve the following coding problem using the programming language python: Ujan has a lot of useless stuff in his drawers, a considerable part of which are his math notebooks: it is time to sort them out. This time he found an old dusty graph theory notebook with a description of a graph. It is an undirected weighted ...
```python import sys input = lambda: sys.stdin.readline().rstrip() N, M = list(map(int, input().split())) D = [{} for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 D[a][b] = 1 D[b][a] = 1 L = [i-1 for i in range(N)] R = [i+1 for i in range(N)] F = [0] * N ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '6 11\n1 3\n1 4\n1 5\n1 6\n2 3\n2 4\n2 5\n2 6\n3 4\n3 5\n3 6\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3 0\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '2 0\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '1 0\n', 'output': '0\n'}, {'ty...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1242/B'}
vfc_5950
```python import sys input = lambda: sys.stdin.readline().rstrip() N, M = list(map(int, input().split())) D = [{} for _ in range(N)] for _ in range(M): a, b = list(map(int, input().split())) a -= 1 b -= 1 D[a][b] = 1 D[b][a] = 1 L = [i-1 for i in range(N)] R = [i+1 for i in range(N)] F = [0] * N ...
6 11 1 3 1 4 1 5 1 6 2 3 2 4 2 5 2 6 3 4 3 5 3 6
2
2
true
1,297
apps
verifiable_code
2102
Solve the following coding problem using the programming language python: John Doe started thinking about graphs. After some thought he decided that he wants to paint an undirected graph, containing exactly k cycles of length 3. A cycle of length 3 is an unordered group of three distinct graph vertices a, b and c, s...
```python k = int(input()) p = [['0'] * 100 for j in range(100)] g = lambda n: n * (n * n - 1) // 6 i = n = 0 while g(n + 1) <= k: n += 1 while i < n + 1: for j in range(i): p[i][j] = p[j][i] = '1' i += 1 k -= g(n) g = lambda n: n * n - n >> 1 while k: n = 0 while g(n + 1) <= k: n += 1 for j in rang...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1\n', 'output': '3\n011\n101\n110\n'}, {'type': 'stdin_stdout', 'input': '10\n', 'output': '5\n01111\n10111\n11011\n11101\n11110\n'}, {'type': 'stdin_stdout', 'input': '2\n', 'output': '4\n0111\n1011\n1100\n1100\n'}, {'type': 'stdin_stdout', 'input': '3\n', 'output': '...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/232/A'}
vfc_5954
```python k = int(input()) p = [['0'] * 100 for j in range(100)] g = lambda n: n * (n * n - 1) // 6 i = n = 0 while g(n + 1) <= k: n += 1 while i < n + 1: for j in range(i): p[i][j] = p[j][i] = '1' i += 1 k -= g(n) g = lambda n: n * n - n >> 1 while k: n = 0 while g(n + 1) <= k: n += 1 for j in rang...
1
3 011 101 110
3 011 101 110
true
1,298
apps
verifiable_code
2103
Solve the following coding problem using the programming language python: Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of n narrow islands located in a row. For more com...
```python #!/usr/bin/env python # 556D_fug.py - Codeforces.com 556D Fug quiz # # Copyright (C) 2015 Sergey # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8\n', 'output': 'Yes\n2 3 1 \n'}, {'type': 'stdin_stdout', 'input': '2 2\n11 14\n17 18\n2 9\n', 'output': 'No\n'}, {'type': 'stdin_stdout', 'input': '2 1\n1 1\n1000000000000000000 1000000000000000000\n999999999999999999\n', 'output': '...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/555/B'}
vfc_5958
```python #!/usr/bin/env python # 556D_fug.py - Codeforces.com 556D Fug quiz # # Copyright (C) 2015 Sergey # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses...
4 4 1 4 7 8 9 10 12 14 4 5 3 8
Yes 2 3 1
Yes 2 3 1
true
1,299
apps
verifiable_code
2105
Solve the following coding problem using the programming language python: Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry. He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1. ...
```python 3 n = int(input()) a = [True] * (n + 2) for i in range(2, n + 2): if not a[i]: continue j = i * i while j < n + 2: a[j] = False j += i if n <= 2: print(1) else: print(2) print(' '.join('1' if x else '2' for x in a[2:])) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n', 'output': '2\n1 1 2 \n'}, {'type': 'stdin_stdout', 'input': '4\n', 'output': '2\n1 1 2 1 \n'}, {'type': 'stdin_stdout', 'input': '17\n', 'output': '2\n1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 \n'}, {'type': 'stdin_stdout', 'input': '25\n', 'output': '2\n1 1 2 1 2 1 2 2 ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/776/B'}
vfc_5966
```python 3 n = int(input()) a = [True] * (n + 2) for i in range(2, n + 2): if not a[i]: continue j = i * i while j < n + 2: a[j] = False j += i if n <= 2: print(1) else: print(2) print(' '.join('1' if x else '2' for x in a[2:])) ```
3
2 1 1 2
2 1 1 2
true
1,300
apps
verifiable_code
2106
Solve the following coding problem using the programming language python: Fox Ciel is playing a card game with her friend Fox Jiro. There are n piles of cards on the table. And there is a positive integer on each card. The players take turns and Ciel takes the first turn. In Ciel's turn she takes a card from the top ...
```python p, n = [], int(input()) a = b = 0 for i in range(n): t = list(map(int, input().split())) k = t[0] // 2 + 1 a += sum(t[1: k]) if t[0] & 1: p.append(t[k]) b += sum(t[k + 1: ]) else: b += sum(t[k: ]) p.sort(reverse = True) print(a + sum(p[0 :: 2]), b + sum(p[1 :: 2])) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1 100\n2 1 10\n', 'output': '101 10\n'}, {'type': 'stdin_stdout', 'input': '1\n9 2 8 6 5 9 4 7 1 3\n', 'output': '30 15\n'}, {'type': 'stdin_stdout', 'input': '3\n3 1 3 2\n3 5 4 6\n2 8 7\n', 'output': '18 18\n'}, {'type': 'stdin_stdout', 'input': '3\n3 1000 1000 100...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/388/C'}
vfc_5970
```python p, n = [], int(input()) a = b = 0 for i in range(n): t = list(map(int, input().split())) k = t[0] // 2 + 1 a += sum(t[1: k]) if t[0] & 1: p.append(t[k]) b += sum(t[k + 1: ]) else: b += sum(t[k: ]) p.sort(reverse = True) print(a + sum(p[0 :: 2]), b + sum(p[1 :: 2])) ```
2 1 100 2 1 10
101 10
101 10
true
1,301
apps
verifiable_code
2107
Solve the following coding problem using the programming language python: As Will is stuck in the Upside Down, he can still communicate with his mom, Joyce, through the Christmas lights (he can turn them on and off with his mind). He can't directly tell his mom where he is, because the monster that took him to the Ups...
```python def main(): s = input() l = len(s) pretty_count = 0 for i in range(l): left_paren_count = 0 right_paren_count = 0 wild_count = 0 for j in range(i, l): if s[j] == '(': left_paren_count += 1 elif s[j] == ')': ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '((?))\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '??()??\n', 'output': '7\n'}, {'type': 'stdin_stdout', 'input': '?????)(???\n', 'output': '21\n'}, {'type': 'stdin_stdout', 'input': '()()((?(()(((()()(())(((()((())))(()))(()(((((())))()))(((()()()))))))(((...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/917/A'}
vfc_5974
```python def main(): s = input() l = len(s) pretty_count = 0 for i in range(l): left_paren_count = 0 right_paren_count = 0 wild_count = 0 for j in range(i, l): if s[j] == '(': left_paren_count += 1 elif s[j] == ')': ...
((?))
4
4
true
1,302
apps
verifiable_code
2108
Solve the following coding problem using the programming language python: Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim. The killer starts with two po...
```python import sys s1, s2 = input().split() n = int(input()) for _ in range(n): print(s1, s2) killed, new = input().split() if s1 == killed: s1 = new else: s2 = new print(s1, s2) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': 'ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n', 'output': 'ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n'}, {'type': 'stdin_stdout', 'input': 'icm codeforces\n1\ncodeforces technex\n', 'output': 'icm codeforces\nicm te...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/776/A'}
vfc_5978
```python import sys s1, s2 = input().split() n = int(input()) for _ in range(n): print(s1, s2) killed, new = input().split() if s1 == killed: s1 = new else: s2 = new print(s1, s2) ```
ross rachel 4 ross joey rachel phoebe phoebe monica monica chandler
ross rachel joey rachel joey phoebe joey monica joey chandler
ross rachel joey rachel joey phoebe joey monica joey chandler
true
1,303
apps
verifiable_code
2109
Solve the following coding problem using the programming language python: 10^{10^{10}} participants, including Takahashi, competed in two programming contests. In each contest, all participants had distinct ranks from first through 10^{10^{10}}-th. The score of a participant is the product of his/her ranks in the two ...
```python def i1(): return int(input()) def i2(): return [int(i) for i in input().split()] q=i1() import math y=[] for i in range(q): y.append(i2()) for a,b in y: x=a*b c=int(math.sqrt(x)) if c**2==x: c-=1 z=2*c if c>0 and (x//c)==c: z-=1 if c>0 and x%c==0 and (x//c-1)==c: z-=1 if a<=c: z-=1 if...
{'test_cases': [{'type': 'stdin_stdout', 'input': '8\n1 4\n10 5\n3 3\n4 11\n8 9\n22 40\n8 36\n314159265 358979323\n', 'output': '1\n12\n4\n11\n14\n57\n31\n671644785\n'}, {'type': 'stdin_stdout', 'input': '99\n207579013 207579013\n376140463 376140463\n186969586 186969586\n326402540 326402540\n158176573 158176573\n127860...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc094/tasks/arc094_b'}
vfc_5982
```python def i1(): return int(input()) def i2(): return [int(i) for i in input().split()] q=i1() import math y=[] for i in range(q): y.append(i2()) for a,b in y: x=a*b c=int(math.sqrt(x)) if c**2==x: c-=1 z=2*c if c>0 and (x//c)==c: z-=1 if c>0 and x%c==0 and (x//c-1)==c: z-=1 if a<=c: z-=1 if...
8 1 4 10 5 3 3 4 11 8 9 22 40 8 36 314159265 358979323
1 12 4 11 14 57 31 671644785
1 12 4 11 14 57 31 671644785
true
1,304
apps
verifiable_code
2110
Solve the following coding problem using the programming language python: Recently, Duff has been practicing weight lifting. As a hard practice, Malek gave her a task. He gave her a sequence of weights. Weight of i-th of them is 2^{w}_{i} pounds. In each step, Duff can lift some of the remaining weights and throw them...
```python n = int(input()) a = [int(x) for x in input().split()] l = [0] * (10**6 + 100) for x in a: l[x] += 1 cur = 0 ans = 0 for x in l: cur += x if cur % 2: ans += 1 cur //= 2 print(ans) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n1 1 2 3 3\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4\n0 1 2 3\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '1\n120287\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '2\n28288 0\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/587/A'}
vfc_5986
```python n = int(input()) a = [int(x) for x in input().split()] l = [0] * (10**6 + 100) for x in a: l[x] += 1 cur = 0 ans = 0 for x in l: cur += x if cur % 2: ans += 1 cur //= 2 print(ans) ```
5 1 1 2 3 3
2
2
true
1,305
apps
verifiable_code
2111
Solve the following coding problem using the programming language python: Lesha plays the recently published new version of the legendary game hacknet. In this version character skill mechanism was introduced. Now, each player character has exactly n skills. Each skill is represented by a non-negative integer a_{i} — ...
```python import itertools import bisect n, A, cf, cm, m = [int(x) for x in input().split()] skills = [int(x) for x in input().split()] sorted_skills = list(sorted((k, i) for i, k in enumerate(skills))) bottom_lift = [0 for i in range(n)] for i in range(1, n): bottom_lift[i] = bottom_lift[i-1] + i * (sorted_skills...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 5 10 1 5\n1 3 1\n', 'output': '12\n2 5 2 \n'}, {'type': 'stdin_stdout', 'input': '3 5 10 1 339\n1 3 1\n', 'output': '35\n5 5 5 \n'}, {'type': 'stdin_stdout', 'input': '2 6 0 1 4\n5 1\n', 'output': '5\n5 5 \n'}, {'type': 'stdin_stdout', 'input': '1 1000000000 1000 100...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/613/B'}
vfc_5990
```python import itertools import bisect n, A, cf, cm, m = [int(x) for x in input().split()] skills = [int(x) for x in input().split()] sorted_skills = list(sorted((k, i) for i, k in enumerate(skills))) bottom_lift = [0 for i in range(n)] for i in range(1, n): bottom_lift[i] = bottom_lift[i-1] + i * (sorted_skills...
3 5 10 1 5 1 3 1
12 2 5 2
12 2 5 2
true
1,306
apps
verifiable_code
2112
Solve the following coding problem using the programming language python: You are given an array $a$ consisting of $n$ non-negative integers. You have to choose a non-negative integer $x$ and form a new array $b$ of size $n$ according to the following rule: for all $i$ from $1$ to $n$, $b_i = a_i \oplus x$ ($\oplus$ d...
```python n = int(input()) l = list(map(int, input().split())) inv = 0 out = 0 mult = 1 for i in range(32): curr = dict() opp = 0 same = 0 for v in l: if v ^ 1 in curr: if v & 1: opp += curr[v ^ 1] else: same += curr[v ^ 1] ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n0 1 3 2\n', 'output': '1 0\n'}, {'type': 'stdin_stdout', 'input': '9\n10 7 9 10 7 5 5 3 5\n', 'output': '4 14\n'}, {'type': 'stdin_stdout', 'input': '3\n8 10 3\n', 'output': '0 8\n'}, {'type': 'stdin_stdout', 'input': '5\n1000000000 1000000000 1000000000 0 0\n', 'ou...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1416/C'}
vfc_5994
```python n = int(input()) l = list(map(int, input().split())) inv = 0 out = 0 mult = 1 for i in range(32): curr = dict() opp = 0 same = 0 for v in l: if v ^ 1 in curr: if v & 1: opp += curr[v ^ 1] else: same += curr[v ^ 1] ...
4 0 1 3 2
1 0
1 0
true
1,307
apps
verifiable_code
2113
Solve the following coding problem using the programming language python: Jeff has become friends with Furik. Now these two are going to play one quite amusing game. At the beginning of the game Jeff takes a piece of paper and writes down a permutation consisting of n numbers: p_1, p_2, ..., p_{n}. Then the guys take...
```python 3 import sys class CumTree: def __init__(self, a, b): self.a = a self.b = b self.count = 0 if a == b: return mid = (a + b) // 2 self.levo = CumTree(a, mid) self.desno = CumTree(mid+1, b) def manjsi(self, t): if...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1 2\n', 'output': '0.000000\n'}, {'type': 'stdin_stdout', 'input': '5\n3 5 2 4 1\n', 'output': '13.000000\n'}, {'type': 'stdin_stdout', 'input': '16\n6 15 3 8 7 11 9 10 2 13 4 14 1 16 5 12\n', 'output': '108.000000\n'}, {'type': 'stdin_stdout', 'input': '9\n1 7 8 5 ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/351/B'}
vfc_5998
```python 3 import sys class CumTree: def __init__(self, a, b): self.a = a self.b = b self.count = 0 if a == b: return mid = (a + b) // 2 self.levo = CumTree(a, mid) self.desno = CumTree(mid+1, b) def manjsi(self, t): if...
2 1 2
0.000000
0.000000
true
1,308
apps
verifiable_code
2115
Solve the following coding problem using the programming language python: Little Petya likes points a lot. Recently his mom has presented him n points lying on the line OX. Now Petya is wondering in how many ways he can choose three distinct points so that the distance between the two farthest of them doesn't exceed d...
```python def Search(L,aa,x): a=aa b=len(L) while(b-a>1): i=(b+a)//2 if(L[i]>x): b=i elif(L[i]<x): a=i else: return (i+1)-aa-1 return b-aa-1 import math n,d=list(map(int,input().split())) P=list(map(int,input().split())) ans=0 for i ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 3\n1 2 3 4\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '4 2\n-3 -2 -1 0\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '5 19\n1 10 20 30 50\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '10 5\n31 36 43 47 48 50 56 69 71 86\n', 'output':...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/251/A'}
vfc_6006
```python def Search(L,aa,x): a=aa b=len(L) while(b-a>1): i=(b+a)//2 if(L[i]>x): b=i elif(L[i]<x): a=i else: return (i+1)-aa-1 return b-aa-1 import math n,d=list(map(int,input().split())) P=list(map(int,input().split())) ans=0 for i ...
4 3 1 2 3 4
4
4
true
1,310
apps
verifiable_code
2116
Solve the following coding problem using the programming language python: You are given a string s, consisting of lowercase English letters, and the integer m. One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose ...
```python m = int(input()) s = input().strip() sa = [0] * len(s) for i in range(len(s)): sa[i] = ord(s[i]) - ord('a') sa = [-1] + sa + [-1] def check_value(sa, m, threshold): prev_ind = 0 for i in range(len(sa)): if sa[i] <= threshold: if i - prev_ind <= m: prev_ind = i else: return False return ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\ncbabc\n', 'output': 'a\n'}, {'type': 'stdin_stdout', 'input': '2\nabcab\n', 'output': 'aab\n'}, {'type': 'stdin_stdout', 'input': '3\nbcabcbaccba\n', 'output': 'aaabb\n'}, {'type': 'stdin_stdout', 'input': '5\nimmaydobun\n', 'output': 'ab\n'}, {'type': 'stdin_stdout...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/724/D'}
vfc_6010
```python m = int(input()) s = input().strip() sa = [0] * len(s) for i in range(len(s)): sa[i] = ord(s[i]) - ord('a') sa = [-1] + sa + [-1] def check_value(sa, m, threshold): prev_ind = 0 for i in range(len(sa)): if sa[i] <= threshold: if i - prev_ind <= m: prev_ind = i else: return False return ...
3 cbabc
a
a
true
1,311
apps
verifiable_code
2117
Solve the following coding problem using the programming language python: Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly a_{i} feet high. [Image...
```python def read_data(): n = int(input()) hs = list(map(int, input().split())) return n, hs def solve(n, hs): left = get_left_index(n, hs) right = get_right_index(n, hs) vals = [[] for i in range(n)] for h, l, r in zip(hs, left, right): vals[r - l - 2].append(h) min_hs = [] ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '10\n1 2 3 4 5 4 3 2 1 6\n', 'output': '6 4 4 3 3 2 2 1 1 1 \n'}, {'type': 'stdin_stdout', 'input': '3\n524125987 923264237 374288891\n', 'output': '923264237 524125987 374288891 \n'}, {'type': 'stdin_stdout', 'input': '5\n585325539 365329221 412106895 291882089 5647186...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/547/B'}
vfc_6014
```python def read_data(): n = int(input()) hs = list(map(int, input().split())) return n, hs def solve(n, hs): left = get_left_index(n, hs) right = get_right_index(n, hs) vals = [[] for i in range(n)] for h, l, r in zip(hs, left, right): vals[r - l - 2].append(h) min_hs = [] ...
10 1 2 3 4 5 4 3 2 1 6
6 4 4 3 3 2 2 1 1 1
6 4 4 3 3 2 2 1 1 1
true
1,312
apps
verifiable_code
2118
Solve the following coding problem using the programming language python: Sam has been teaching Jon the Game of Stones to sharpen his mind and help him devise a strategy to fight the white walkers. The rules of this game are quite simple: The game starts with n piles of stones indexed from 1 to n. The i-th pile conta...
```python n = int(input()) arr = [int(input()) for i in range(n)] b = [0 for i in range(n)] s = 0 for i in range(n): j = int((arr[i] << 1) ** 0.5) if j * (j + 1) > (arr[i] << 1): j -= 1 s ^= j if s != 0: print('NO') else: print('YES') ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '1\n5\n', 'output': 'NO'}, {'type': 'stdin_stdout', 'input': '2\n1\n2\n', 'output': 'YES'}, {'type': 'stdin_stdout', 'input': '3\n34\n44\n21\n', 'output': 'NO'}, {'type': 'stdin_stdout', 'input': '6\n34\n44\n21\n55\n1\n36\n', 'output': 'NO'}, {'type': 'stdin_stdout', 'i...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/768/E'}
vfc_6018
```python n = int(input()) arr = [int(input()) for i in range(n)] b = [0 for i in range(n)] s = 0 for i in range(n): j = int((arr[i] << 1) ** 0.5) if j * (j + 1) > (arr[i] << 1): j -= 1 s ^= j if s != 0: print('NO') else: print('YES') ```
1 5
NO
NO
true
1,313
apps
verifiable_code
2119
Solve the following coding problem using the programming language python: You are given an array consisting of n non-negative integers a_1, a_2, ..., a_{n}. You are going to destroy integers in the array one by one. Thus, you are given the permutation of integers from 1 to n defining the order elements of the array a...
```python __author__ = 'Think' n=int(input()) aints=[int(i) for i in input().split()] permutes=[int(i)-1 for i in input().split()] results=[0] rebuilt={} m=0 for numby in range(n-1, 0, -1): p=permutes[numby] below=False above=False if p-1 in rebuilt: below=True if p+1 in rebuilt: above=True if above and belo...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n1 3 2 5\n3 4 1 2\n', 'output': '5\n4\n3\n0\n'}, {'type': 'stdin_stdout', 'input': '5\n1 2 3 4 5\n4 2 3 5 1\n', 'output': '6\n5\n5\n1\n0\n'}, {'type': 'stdin_stdout', 'input': '8\n5 5 4 4 6 6 5 5\n5 2 8 7 1 3 4 6\n', 'output': '18\n16\n11\n8\n8\n6\n6\n0\n'}, {'type':...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/722/C'}
vfc_6022
```python __author__ = 'Think' n=int(input()) aints=[int(i) for i in input().split()] permutes=[int(i)-1 for i in input().split()] results=[0] rebuilt={} m=0 for numby in range(n-1, 0, -1): p=permutes[numby] below=False above=False if p-1 in rebuilt: below=True if p+1 in rebuilt: above=True if above and belo...
4 1 3 2 5 3 4 1 2
5 4 3 0
5 4 3 0
true
1,314
apps
verifiable_code
2121
Solve the following coding problem using the programming language python: There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is h...
```python # -*- coding: utf-8 -*- from time import perf_counter from sys import stdin def run(n, s): m = 0 small = n // 2 for big in range(n-1, (n+1)//2-1, -1): while small >= 0 and s[small] > s[big] / 2: small -= 1 if small == -1: break #print(small, big) ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '8\n2\n5\n7\n6\n9\n8\n4\n2\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '8\n9\n1\n6\n2\n6\n5\n8\n3\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '12\n3\n99\n24\n46\n75\n63\n57\n55\n10\n62\n34\n52\n', 'output': '7\n'}, {'type': 'stdin_stdout', 'input...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/372/A'}
vfc_6030
```python # -*- coding: utf-8 -*- from time import perf_counter from sys import stdin def run(n, s): m = 0 small = n // 2 for big in range(n-1, (n+1)//2-1, -1): while small >= 0 and s[small] > s[big] / 2: small -= 1 if small == -1: break #print(small, big) ...
8 2 5 7 6 9 8 4 2
5
5
true
1,316
apps
verifiable_code
2122
Solve the following coding problem using the programming language python: Polycarp starts his own business. Tomorrow will be the first working day of his car repair shop. For now the car repair shop is very small and only one car can be repaired at a given time. Polycarp is good at marketing, so he has already collec...
```python from bisect import bisect_left, insort_left a = [] n = int(input()) for _ in range(n): #print(a) s, d = list(map(int, input().split())) if len(a) == 0: print(s, s+d - 1) a.append((s, s + d - 1)) continue p = bisect_left(a, (s, s + d - 1)) #print('p', p) ok = Tru...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n9 2\n7 3\n2 4\n', 'output': '9 10\n1 3\n4 7\n'}, {'type': 'stdin_stdout', 'input': '4\n1000000000 1000000\n1000000000 1000000\n100000000 1000000\n1000000000 1000000\n', 'output': '1000000000 1000999999\n1 1000000\n100000000 100999999\n1000001 2000000\n'}, {'type': '...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/730/G'}
vfc_6034
```python from bisect import bisect_left, insort_left a = [] n = int(input()) for _ in range(n): #print(a) s, d = list(map(int, input().split())) if len(a) == 0: print(s, s+d - 1) a.append((s, s + d - 1)) continue p = bisect_left(a, (s, s + d - 1)) #print('p', p) ok = Tru...
3 9 2 7 3 2 4
9 10 1 3 4 7
9 10 1 3 4 7
true
1,317
apps
verifiable_code
2123
Solve the following coding problem using the programming language python: Oleg the bank client and Igor the analyst are arguing again. This time, they want to pick a gift as a present for their friend, ZS the coder. After a long thought, they decided that their friend loves to eat carrots the most and thus they want t...
```python def evens(A): n = len(A) l = n//2-1; r = n//2 if len(A)%2 == 1: l+= 1 ans = [max(A[l], A[r])] while r < n-1: l-= 1; r+= 1 ans.append(max(ans[-1], A[l], A[r])) return ans def interleave(A, B): q = [] for i in range(len(B)): q+= [A[i], B[i]] if len(A) != len(...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n1 2 3 5\n', 'output': '3 3 5 5\n'}, {'type': 'stdin_stdout', 'input': '5\n1000000000 1000000000 1000000000 1000000000 1\n', 'output': '1000000000 1000000000 1000000000 1000000000 1000000000\n'}, {'type': 'stdin_stdout', 'input': '4\n1 12 3 5\n', 'output': '12 3 12 1...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/794/E'}
vfc_6038
```python def evens(A): n = len(A) l = n//2-1; r = n//2 if len(A)%2 == 1: l+= 1 ans = [max(A[l], A[r])] while r < n-1: l-= 1; r+= 1 ans.append(max(ans[-1], A[l], A[r])) return ans def interleave(A, B): q = [] for i in range(len(B)): q+= [A[i], B[i]] if len(A) != len(...
4 1 2 3 5
3 3 5 5
3 3 5 5
true
1,318
apps
verifiable_code
2125
Solve the following coding problem using the programming language python: Wherever the destination is, whoever we meet, let's render this song together. On a Cartesian coordinate plane lies a rectangular stage of size w × h, represented by a rectangle with corners (0, 0), (w, 0), (w, h) and (0, h). It can be seen tha...
```python # http://codeforces.com/problemset/problem/848/B from collections import defaultdict def get_dest(start, w, h): if start[0] == 1: return (str(start[1]), str(h)) else: return (str(w), str(start[1])) n, w, h = [int(x) for x in input().split()] dancers = [] groups = defaultdict(list) ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '8 10 8\n1 1 10\n1 4 13\n1 7 1\n1 8 2\n2 2 0\n2 5 14\n2 6 0\n2 6 1\n', 'output': '4 8\n10 5\n8 8\n10 6\n10 2\n1 8\n7 8\n10 6\n'}, {'type': 'stdin_stdout', 'input': '3 2 3\n1 1 2\n2 1 1\n1 1 5\n', 'output': '1 3\n2 1\n1 3\n'}, {'type': 'stdin_stdout', 'input': '1 10 10\n...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/848/B'}
vfc_6046
```python # http://codeforces.com/problemset/problem/848/B from collections import defaultdict def get_dest(start, w, h): if start[0] == 1: return (str(start[1]), str(h)) else: return (str(w), str(start[1])) n, w, h = [int(x) for x in input().split()] dancers = [] groups = defaultdict(list) ...
8 10 8 1 1 10 1 4 13 1 7 1 1 8 2 2 2 0 2 5 14 2 6 0 2 6 1
4 8 10 5 8 8 10 6 10 2 1 8 7 8 10 6
4 8 10 5 8 8 10 6 10 2 1 8 7 8 10 6
true
1,320
apps
verifiable_code
2126
Solve the following coding problem using the programming language python: For the multiset of positive integers $s=\{s_1,s_2,\dots,s_k\}$, define the Greatest Common Divisor (GCD) and Least Common Multiple (LCM) of $s$ as follow: $\gcd(s)$ is the maximum positive integer $x$, such that all integers in $s$ are divisibl...
```python def Sieve(n): ret = [] divlis = [-1] * (n+1) flag = [True] * (n+1) flag[0] = False flag[1] = False ind = 2 while ind <= n: if flag[ind]: ret.append(ind) ind2 = ind ** 2 while ind2 <= n: flag[ind2] = False ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1 1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '4\n10 24 40 80\n', 'output': '40\n'}, {'type': 'stdin_stdout', 'input': '10\n540 648 810 648 720 540 594 864 972 648\n', 'output': '54\n'}, {'type': 'stdin_stdout', 'input': '2\n199999 200000\n', 'output':...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1349/A'}
vfc_6050
```python def Sieve(n): ret = [] divlis = [-1] * (n+1) flag = [True] * (n+1) flag[0] = False flag[1] = False ind = 2 while ind <= n: if flag[ind]: ret.append(ind) ind2 = ind ** 2 while ind2 <= n: flag[ind2] = False ...
2 1 1
1
1
true
1,321
apps
verifiable_code
2127
Solve the following coding problem using the programming language python: There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are labeled from 1 to n. Every pair of two char...
```python class DisjointSet(object): def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n self.num = n # number of disjoint sets def union(self, x, y): self._link(self.find_set(x), self.find_set(y)) def _link(self, x, y): if x == y: r...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 0\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 0\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '4 4\n1 2 1\n2 3 1\n3 4 0\n4 1 1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '100000 0\n', 'output': '303861...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/553/C'}
vfc_6054
```python class DisjointSet(object): def __init__(self, n): self.parent = list(range(n)) self.rank = [0] * n self.num = n # number of disjoint sets def union(self, x, y): self._link(self.find_set(x), self.find_set(y)) def _link(self, x, y): if x == y: r...
3 0
4
4
true
1,322
apps
verifiable_code
2128
Solve the following coding problem using the programming language python: Iahub helps his grandfather at the farm. Today he must milk the cows. There are n cows sitting in a row, numbered from 1 to n from left to right. Each cow is either facing to the left or facing to the right. When Iahub milks a cow, all the cows ...
```python __author__ = 'Pavel Mavrin' n = int(input()) a = [int(x) for x in input().split()] s = 0 res = 0 for i in a: if i == 0: res += s else: s += 1 print(res) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n0 0 1 0\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': '5\n1 0 1 0 1\n', 'output': '3'}, {'type': 'stdin_stdout', 'input': '50\n1 1 0 1 1 1 1 1 1 0 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 0 0 1 1 0 1 0 0 1 0\n', 'output': '416'}, {'type': ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/383/A'}
vfc_6058
```python __author__ = 'Pavel Mavrin' n = int(input()) a = [int(x) for x in input().split()] s = 0 res = 0 for i in a: if i == 0: res += s else: s += 1 print(res) ```
4 0 0 1 0
1
1
true
1,323
apps
verifiable_code
2129
Solve the following coding problem using the programming language python: Alice received a set of Toy Train™ from Bob. It consists of one train and a connected railway network of $n$ stations, enumerated from $1$ through $n$. The train occupies one station at a time and travels around the network of stations in a circ...
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline mii=lambda:list(map(int,input().split())) n,m=mii() a=[0 for _ in range(n)] c=[123456 for _ in range(n)] for _ in range(m): u,v=mii() u%=n v%=n if v<u: v+=n a[u]+=1 if c[u]>v: c[u]=v ans=[] for i in list(range(1,n))+[0]...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n', 'output': '10 9 10 10 9 \n'}, {'type': 'stdin_stdout', 'input': '2 3\n1 2\n1 2\n1 2\n', 'output': '5 6 \n'}, {'type': 'stdin_stdout', 'input': '5 3\n2 4\n5 4\n3 2\n', 'output': '8 7 6 8 7 \n'}, {'type': 'stdin_stdout', 'input'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1129/A2'}
vfc_6062
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline mii=lambda:list(map(int,input().split())) n,m=mii() a=[0 for _ in range(n)] c=[123456 for _ in range(n)] for _ in range(m): u,v=mii() u%=n v%=n if v<u: v+=n a[u]+=1 if c[u]>v: c[u]=v ans=[] for i in list(range(1,n))+[0]...
5 7 2 4 5 1 2 3 3 4 4 1 5 3 3 5
10 9 10 10 9
10 9 10 10 9
true
1,324
apps
verifiable_code
2130
Solve the following coding problem using the programming language python: Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed th...
```python 3 import sys from functools import lru_cache MOD = 1000000007 cnk = [[1 for i in range(1001)] for j in range(1001)] for i in range(1, 1001): for j in range(1, i): cnk[i][j] = cnk[i - 1][j - 1] + cnk[i - 1][j] k = int(input()) cs = [int(input()) for i in range(k)] ans = 1 sm = 0 for c in cs: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n2\n2\n1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '4\n1\n2\n3\n4\n', 'output': '1680\n'}, {'type': 'stdin_stdout', 'input': '10\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n', 'output': '12520708\n'}, {'type': 'stdin_stdout', 'input': '5\n10\n10\...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/553/A'}
vfc_6066
```python 3 import sys from functools import lru_cache MOD = 1000000007 cnk = [[1 for i in range(1001)] for j in range(1001)] for i in range(1, 1001): for j in range(1, i): cnk[i][j] = cnk[i - 1][j - 1] + cnk[i - 1][j] k = int(input()) cs = [int(input()) for i in range(k)] ans = 1 sm = 0 for c in cs: ...
3 2 2 1
3
3
true
1,325
apps
verifiable_code
2131
Solve the following coding problem using the programming language python: There are $n$ startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An...
```python m = 1000000007 n = int(input()) a = list(map(int, input().split())) print(pow(2,n-1,m)-1 - sum(pow(2,a.count(x),m)-1 for x in set(a) if x != -1) % m) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n-1 -1 -1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '2\n2 -1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '40\n3 3 -1 -1 4 4 -1 -1 -1 -1 -1 10 10 10 10 10 10 4 20 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 3 3 3 3 3 3 3\n', 'output': '755808950...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1025/G'}
vfc_6070
```python m = 1000000007 n = int(input()) a = list(map(int, input().split())) print(pow(2,n-1,m)-1 - sum(pow(2,a.count(x),m)-1 for x in set(a) if x != -1) % m) ```
3 -1 -1 -1
3
3
true
1,326
apps
verifiable_code
2132
Solve the following coding problem using the programming language python: Nauuo is a girl who loves drawing circles. One day she has drawn a circle and wanted to draw a tree on it. The tree is a connected undirected graph consisting of $n$ nodes and $n-1$ edges. The nodes are numbered from $1$ to $n$. Nauuo wants t...
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 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, sys.stdin.rea...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n1 2\n1 3\n2 4\n', 'output': '16'}, {'type': 'stdin_stdout', 'input': '4\n1 2\n1 3\n1 4\n', 'output': '24'}, {'type': 'stdin_stdout', 'input': '6\n2 1\n3 2\n4 1\n5 4\n1 6\n', 'output': '144'}, {'type': 'stdin_stdout', 'input': '2\n2 1\n', 'output': '2'}, {'type': 'st...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1172/B'}
vfc_6074
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 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, sys.stdin.rea...
4 1 2 1 3 2 4
16
16
true
1,327
apps
verifiable_code
2133
Solve the following coding problem using the programming language python: There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slot...
```python strings = int(input()) count = [0 for x in range(7)] for k in range(strings): s = input() for index in range(7): if s[index] == '1': count[index] += 1 print(max(count)) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n0101010\n1010101\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3\n0101011\n0011001\n0110111\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '1\n0111000\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1\n0000000\n', 'output': '0\n'}, {'typ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/847/G'}
vfc_6078
```python strings = int(input()) count = [0 for x in range(7)] for k in range(strings): s = input() for index in range(7): if s[index] == '1': count[index] += 1 print(max(count)) ```
2 0101010 1010101
1
1
true
1,328
apps
verifiable_code
2134
Solve the following coding problem using the programming language python: Mitya has a rooted tree with $n$ vertices indexed from $1$ to $n$, where the root has index $1$. Each vertex $v$ initially had an integer number $a_v \ge 0$ written on it. For every vertex $v$ Mitya has computed $s_v$: the sum of all values writ...
```python from collections import defaultdict, deque n = int(input()) adj = [[] for _ in range(n)] v = [0] * n l = list(map(int, input().split())) for i, f in enumerate(l): adj[f - 1].append(i + 1) s = list(map(int, input().split())) Q = deque([(0, s[0], s[0])]) ans = 0 flag = False possible = True while Q and p...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n1 1 1 1\n1 -1 -1 -1 -1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '5\n1 2 3 1\n1 -1 2 -1 -1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3\n1 2\n2 -1 1\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '2\n1\n0 -1\n', 'output': '0\n'}...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1098/A'}
vfc_6082
```python from collections import defaultdict, deque n = int(input()) adj = [[] for _ in range(n)] v = [0] * n l = list(map(int, input().split())) for i, f in enumerate(l): adj[f - 1].append(i + 1) s = list(map(int, input().split())) Q = deque([(0, s[0], s[0])]) ans = 0 flag = False possible = True while Q and p...
5 1 1 1 1 1 -1 -1 -1 -1
1
1
true
1,329
apps
verifiable_code
2135
Solve the following coding problem using the programming language python: In the spirit of the holidays, Saitama has given Genos two grid paths of length n (a weird gift even by Saitama's standards). A grid path is an ordered sequence of neighbouring squares in an infinite grid. Two squares are neighbouring if they sh...
```python from time import time opposite = { 'N': 'S', 'S': 'N', 'E': 'W', 'W': 'E' } otr = str.maketrans(opposite) bits = { 'N': 0, 'S': 1, 'E': 2, 'W': 3, } Q = 4294967291 def combine(h, v, q): return (h<<2 | v) % q def combinel(h, v, q, s): return (v*s + h) % q def f...
{'test_cases': [{'type': 'stdin_stdout', 'input': '7\nNNESWW\nSWSWSW\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '3\nNN\nSS\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '3\nES\nNW\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '5\nWSSE\nWNNE\n', 'output': 'NO\n'}, {'type': 'stdin_std...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/607/C'}
vfc_6086
```python from time import time opposite = { 'N': 'S', 'S': 'N', 'E': 'W', 'W': 'E' } otr = str.maketrans(opposite) bits = { 'N': 0, 'S': 1, 'E': 2, 'W': 3, } Q = 4294967291 def combine(h, v, q): return (h<<2 | v) % q def combinel(h, v, q, s): return (v*s + h) % q def f...
7 NNESWW SWSWSW
YES
YES
true
1,330
apps
verifiable_code
2136
Solve the following coding problem using the programming language python: You are given a Young diagram. Given diagram is a histogram with $n$ columns of lengths $a_1, a_2, \ldots, a_n$ ($a_1 \geq a_2 \geq \ldots \geq a_n \geq 1$). [Image] Young diagram for $a=[3,2,2,2,1]$. Your goal is to find the largest number ...
```python import sys readline = sys.stdin.readline N = int(readline()) A = list(map(int, readline().split())) BW = [0, 0] for i in range(N): a = A[i] BW[i%2] += a//2 BW[(i+1)%2] += -(-a//2) print(min(BW)) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n3 2 2 2 1\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '5\n1 1 1 1 1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3\n3 3 3\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '1\n1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '1...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1268/B'}
vfc_6090
```python import sys readline = sys.stdin.readline N = int(readline()) A = list(map(int, readline().split())) BW = [0, 0] for i in range(N): a = A[i] BW[i%2] += a//2 BW[(i+1)%2] += -(-a//2) print(min(BW)) ```
5 3 2 2 2 1
4
4
true
1,331
apps
verifiable_code
2137
Solve the following coding problem using the programming language python: Vasya's got a birthday coming up and his mom decided to give him an array of positive integers a of length n. Vasya thinks that an array's beauty is the greatest common divisor of all its elements. His mom, of course, wants to give him as beaut...
```python n, k = map(int, input().split()) t = set(map(int, input().split())) y = x = min(t) t = list(t) while True: for i in t: if i % x > k: x = i // (i // x + 1) if y == x: break y = x print(y) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '6 1\n3 6 10 12 13 16\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '5 3\n8 21 52 15 77\n', 'output': '7\n'}, {'type': 'stdin_stdout', 'input': '13 11\n55 16 26 40 84 80 48 52 25 43 75 21 58\n', 'output': '16\n'}, {'type': 'stdin_stdout', 'input': '18 9\n85 29...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/354/C'}
vfc_6094
```python n, k = map(int, input().split()) t = set(map(int, input().split())) y = x = min(t) t = list(t) while True: for i in t: if i % x > k: x = i // (i // x + 1) if y == x: break y = x print(y) ```
6 1 3 6 10 12 13 16
3
3
true
1,332
apps
verifiable_code
2138
Solve the following coding problem using the programming language python: You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") a and b. Then ...
```python print('YES' if input().count('1')+1>>1<<1 >= input().count('1') else 'NO') ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '01011\n0110\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '0011\n1110\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '11111\n111111\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '0110011\n01100110\n', 'output': 'YES\n'}, {'type': 'stdi...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/297/A'}
vfc_6098
```python print('YES' if input().count('1')+1>>1<<1 >= input().count('1') else 'NO') ```
01011 0110
YES
YES
true
1,333
apps
verifiable_code
2139
Solve the following coding problem using the programming language python: You are given an array $a$ of length $2n$. Consider a partition of array $a$ into two subsequences $p$ and $q$ of length $n$ each (each element of array $a$ should be in exactly one subsequence: either in $p$ or in $q$). Let's sort $p$ in non-d...
```python import sys from sys import stdin def modfac(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m in...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1\n1 4\n', 'output': '6'}, {'type': 'stdin_stdout', 'input': '2\n2 1 2 1\n', 'output': '12'}, {'type': 'stdin_stdout', 'input': '3\n2 2 2 2 2 2\n', 'output': '0'}, {'type': 'stdin_stdout', 'input': '5\n13 8 35 94 9284 34 54 69 123 846\n', 'output': '2588544'}, {'type':...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1444/B'}
vfc_6102
```python import sys from sys import stdin def modfac(n, MOD): f = 1 factorials = [1] for m in range(1, n + 1): f *= m f %= MOD factorials.append(f) inv = pow(f, MOD - 2, MOD) invs = [1] * (n + 1) invs[n] = inv for m in range(n, 1, -1): inv *= m in...
1 1 4
6
6
true
1,334
apps
verifiable_code
2140
Solve the following coding problem using the programming language python: While discussing a proper problem A for a Codeforces Round, Kostya created a cyclic array of positive integers $a_1, a_2, \ldots, a_n$. Since the talk was long and not promising, Kostya created a new cyclic array $b_1, b_2, \ldots, b_{n}$ so tha...
```python n = int(input()) b = list(map(int, input().split())) m, M = min(b), max(b) if m == M: if M == 0: print('YES') print(' '.join(['1' for i in range(n)])) else: print('NO') else: print('YES') pos = list([i for i in range(n) if b[i] == M and b[i - 1] < M])[0] a = [0 ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n1 3 1 0\n', 'output': 'YES\n7 3 8 7 \n'}, {'type': 'stdin_stdout', 'input': '2\n4 4\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '5\n5 4 3 2 1\n', 'output': 'YES\n5 20 16 13 11 \n'}, {'type': 'stdin_stdout', 'input': '10\n3 3 3 5 6 9 3 1 7 3\n', 'output'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1028/E'}
vfc_6106
```python n = int(input()) b = list(map(int, input().split())) m, M = min(b), max(b) if m == M: if M == 0: print('YES') print(' '.join(['1' for i in range(n)])) else: print('NO') else: print('YES') pos = list([i for i in range(n) if b[i] == M and b[i - 1] < M])[0] a = [0 ...
4 1 3 1 0
YES 7 3 8 7
YES 7 3 8 7
true
1,335
apps
verifiable_code
2141
Solve the following coding problem using the programming language python: Evlampiy was gifted a rooted tree. The vertices of the tree are numbered from $1$ to $n$. Each of its vertices also has an integer $a_i$ written on it. For each vertex $i$, Evlampiy calculated $c_i$ — the number of vertices $j$ in the subtree of...
```python import sys readline = sys.stdin.readline def parorder(Edge, p): N = len(Edge) par = [0]*N par[p] = -1 stack = [p] order = [] visited = set([p]) ast = stack.append apo = order.append while stack: vn = stack.pop() apo(vn) for vf in Edge[vn]: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n2 0\n0 2\n2 0\n', 'output': 'YES\n1 3 2 \n'}, {'type': 'stdin_stdout', 'input': '5\n0 1\n1 3\n2 1\n3 0\n2 0\n', 'output': 'YES\n2 5 3 1 4 \n'}, {'type': 'stdin_stdout', 'input': '1\n0 0\n', 'output': 'YES\n1 \n'}, {'type': 'stdin_stdout', 'input': '2\n0 1\n1 0\n', '...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1286/B'}
vfc_6110
```python import sys readline = sys.stdin.readline def parorder(Edge, p): N = len(Edge) par = [0]*N par[p] = -1 stack = [p] order = [] visited = set([p]) ast = stack.append apo = order.append while stack: vn = stack.pop() apo(vn) for vf in Edge[vn]: ...
3 2 0 0 2 2 0
YES 1 3 2
YES 1 3 2
true
1,336
apps
verifiable_code
2142
Solve the following coding problem using the programming language python: Recently Polycarpus has learned the "bitwise AND" operation (which is also called "AND") of non-negative integers. Now he wants to demonstrate the school IT teacher his superb manipulation with the learned operation. For that Polycarpus came to...
```python n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) ans = [0]*n for i in range(n): for j in range(n): if j!=i: ans[i] |= a[i][j] print(ans[i],end = ' ') ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '1\n-1\n', 'output': '0 '}, {'type': 'stdin_stdout', 'input': '3\n-1 18 0\n18 -1 0\n0 0 -1\n', 'output': '18 18 0 '}, {'type': 'stdin_stdout', 'input': '4\n-1 128 128 128\n128 -1 148 160\n128 148 -1 128\n128 160 128 -1\n', 'output': '128 180 148 160 '}, {'type': 'stdin_...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/245/D'}
vfc_6114
```python n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) ans = [0]*n for i in range(n): for j in range(n): if j!=i: ans[i] |= a[i][j] print(ans[i],end = ' ') ```
1 -1
0
0
true
1,337
apps
verifiable_code
2143
Solve the following coding problem using the programming language python: Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can b...
```python from bisect import * n, tc, td = [int(i) for i in input().split()] fc = [] fd = [] mbc = 0 mbd = 0 for _ in range(n): b, p, ft = input().split() b, p = int(b), int(p) f = (p, b) if ft == 'C': if p <= tc: fc.append(f) mbc = max(mbc, b) else: if p <= ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 7 6\n10 8 C\n4 3 C\n5 6 D\n', 'output': '9\n'}, {'type': 'stdin_stdout', 'input': '2 4 5\n2 5 C\n2 1 D\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '3 10 10\n5 5 C\n5 5 C\n10 11 D\n', 'output': '10\n'}, {'type': 'stdin_stdout', 'input': '6 68 40\n1 18 D\n6...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/799/C'}
vfc_6118
```python from bisect import * n, tc, td = [int(i) for i in input().split()] fc = [] fd = [] mbc = 0 mbd = 0 for _ in range(n): b, p, ft = input().split() b, p = int(b), int(p) f = (p, b) if ft == 'C': if p <= tc: fc.append(f) mbc = max(mbc, b) else: if p <= ...
3 7 6 10 8 C 4 3 C 5 6 D
9
9
true
1,338
apps
verifiable_code
2144
Solve the following coding problem using the programming language python: Ujan has a lot of numbers in his boxes. He likes order and balance, so he decided to reorder the numbers. There are $k$ boxes numbered from $1$ to $k$. The $i$-th box contains $n_i$ integer numbers. The integers can be negative. All of the inte...
```python def main(): k = int(input()) n = [] a = [] for i in range(k): line = [int(x) for x in input().split()] ni = line[0] ai = [] n.append(ni) a.append(ai) for j in range(ni): ai.append(line[1 + j]) answer, c, p = solve(k, n, a) if...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n3 1 7 4\n2 3 2\n2 8 5\n1 10\n', 'output': 'Yes\n7 2\n2 3\n5 1\n10 4\n'}, {'type': 'stdin_stdout', 'input': '2\n2 3 -2\n2 -1 5\n', 'output': 'No\n'}, {'type': 'stdin_stdout', 'input': '2\n2 -10 10\n2 0 -20\n', 'output': 'Yes\n-10 2\n-20 1\n'}, {'type': 'stdin_stdout'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1242/C'}
vfc_6122
```python def main(): k = int(input()) n = [] a = [] for i in range(k): line = [int(x) for x in input().split()] ni = line[0] ai = [] n.append(ni) a.append(ai) for j in range(ni): ai.append(line[1 + j]) answer, c, p = solve(k, n, a) if...
4 3 1 7 4 2 3 2 2 8 5 1 10
Yes 7 2 2 3 5 1 10 4
Yes 7 2 2 3 5 1 10 4
true
1,339
apps
verifiable_code
2145
Solve the following coding problem using the programming language python: Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following problem. Given a string...
```python s = input() t = input() n = len(s) m = len(t) t = t + '$' + s p = [0] * (n + m + 1) k = 0 for i in range(1, n + m + 1): while k > 0 and t[k] != t[i]: k = p[k - 1] if t[k] == t[i]: k += 1 p[i] = k ans = [0] * n sums = [0] * (n + 1) curs = 0 was = False j = 0 MOD = 10 ** 9 + 7 fo...
{'test_cases': [{'type': 'stdin_stdout', 'input': 'ababa\naba\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': 'welcometoroundtwohundredandeightytwo\nd\n', 'output': '274201\n'}, {'type': 'stdin_stdout', 'input': 'ddd\nd\n', 'output': '12\n'}, {'type': 'stdin_stdout', 'input': 'vnssnssnssnssnssnssnssnssnssnssnss...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/494/B'}
vfc_6126
```python s = input() t = input() n = len(s) m = len(t) t = t + '$' + s p = [0] * (n + m + 1) k = 0 for i in range(1, n + m + 1): while k > 0 and t[k] != t[i]: k = p[k - 1] if t[k] == t[i]: k += 1 p[i] = k ans = [0] * n sums = [0] * (n + 1) curs = 0 was = False j = 0 MOD = 10 ** 9 + 7 fo...
ababa aba
5
5
true
1,340
apps
verifiable_code
2146
Solve the following coding problem using the programming language python: Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days. In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day. Du will chat in the group fo...
```python import sys readline = sys.stdin.readline N, D, M = map(int, readline().split()) A = list(map(int, readline().split())) Am = [a for a in A if a > M] Ao = [a for a in A if a <= M] Am.sort(reverse = True) Ao.sort(reverse = True) Cam = Am[:] Cao = Ao[:] for i in range(1, len(Cam)): Cam[i] += Cam[i-1] for i ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 2 11\n8 10 15 23 5\n', 'output': '48\n'}, {'type': 'stdin_stdout', 'input': '20 2 16\n20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7\n', 'output': '195\n'}, {'type': 'stdin_stdout', 'input': '1 1 0\n0\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '100 61...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1394/A'}
vfc_6130
```python import sys readline = sys.stdin.readline N, D, M = map(int, readline().split()) A = list(map(int, readline().split())) Am = [a for a in A if a > M] Ao = [a for a in A if a <= M] Am.sort(reverse = True) Ao.sort(reverse = True) Cam = Am[:] Cao = Ao[:] for i in range(1, len(Cam)): Cam[i] += Cam[i-1] for i ...
5 2 11 8 10 15 23 5
48
48
true
1,341
apps
verifiable_code
2147
Solve the following coding problem using the programming language python: Ziota found a video game called "Monster Invaders". Similar to every other shooting RPG game, "Monster Invaders" involves killing monsters and bosses with guns. For the sake of simplicity, we only consider two different types of monsters and t...
```python n,r1,r2,r3,D = map(int,input().split()) state = [0,0] # after odd number of 2 (1st), or not (2nd) a = list(map(int,input().split())) # First element # Choosing P~P + A state[0] = r1 * a[0] + r3 # Choosing L + P later or all P state[1] = min(r2 + r1 + D, r1 * (a[0] + 2) + D) # Second to Second Last ele...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 1 3 4 3\n3 2 5 1\n', 'output': '34'}, {'type': 'stdin_stdout', 'input': '4 2 4 4 1\n4 5 1 2\n', 'output': '31'}, {'type': 'stdin_stdout', 'input': '2 2 5 7 3\n4 5\n', 'output': '23'}, {'type': 'stdin_stdout', 'input': '100 4 8 9 1\n1 8 1 8 7 8 1 8 10 4 7 7 3 2 6 7 3 ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1396/C'}
vfc_6134
```python n,r1,r2,r3,D = map(int,input().split()) state = [0,0] # after odd number of 2 (1st), or not (2nd) a = list(map(int,input().split())) # First element # Choosing P~P + A state[0] = r1 * a[0] + r3 # Choosing L + P later or all P state[1] = min(r2 + r1 + D, r1 * (a[0] + 2) + D) # Second to Second Last ele...
4 1 3 4 3 3 2 5 1
34
34
true
1,342
apps
verifiable_code
2148
Solve the following coding problem using the programming language python: You are given several queries. Each query consists of three integers $p$, $q$ and $b$. You need to answer whether the result of $p/q$ in notation with base $b$ is a finite fraction. A fraction in notation with base $b$ is finite if it contains ...
```python import sys def binpow(a, n, p): res = 1 while n > 0: if n % 2 == 1: res = (res * a) % p a = (a * a) % p n >>= 1 return res def main(): result = [] t = int(sys.stdin.readline()) for line in sys.stdin.readlines(): p, q, b = list(map(int,...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n6 12 10\n4 3 10\n', 'output': 'Finite\nInfinite\n'}, {'type': 'stdin_stdout', 'input': '4\n1 1 2\n9 36 2\n4 12 3\n3 5 4\n', 'output': 'Finite\nFinite\nFinite\nInfinite\n'}, {'type': 'stdin_stdout', 'input': '10\n10 5 3\n1 7 10\n7 5 7\n4 4 9\n6 5 2\n6 7 5\n9 9 7\n7 5...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/983/A'}
vfc_6138
```python import sys def binpow(a, n, p): res = 1 while n > 0: if n % 2 == 1: res = (res * a) % p a = (a * a) % p n >>= 1 return res def main(): result = [] t = int(sys.stdin.readline()) for line in sys.stdin.readlines(): p, q, b = list(map(int,...
2 6 12 10 4 3 10
Finite Infinite
Finite Infinite
true
1,343
apps
verifiable_code
2149
Solve the following coding problem using the programming language python: You are given a set of size $m$ with integer elements between $0$ and $2^{n}-1$ inclusive. Let's build an undirected graph on these integers in the following way: connect two integers $x$ and $y$ with an edge if and only if $x \& y = 0$. Here $\...
```python n, m = map(int, input().split()) a = set(map(int, input().split())) y = 2 ** n mk = [0] * (2 * y) cur = 0 for x in a: if mk[x]: continue mk[x] = 1 st = [x] while st: u = st.pop() if u < y: if not mk[y + u]: mk[y + u] = 1 st.append(y...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 3\n1 2 3\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '5 5\n5 19 10 20 12\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3 5\n3 5 0 6 7\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '0 1\n0\n', 'output': '1\n'}, {'type': 'stdin_stdout',...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/986/C'}
vfc_6142
```python n, m = map(int, input().split()) a = set(map(int, input().split())) y = 2 ** n mk = [0] * (2 * y) cur = 0 for x in a: if mk[x]: continue mk[x] = 1 st = [x] while st: u = st.pop() if u < y: if not mk[y + u]: mk[y + u] = 1 st.append(y...
2 3 1 2 3
2
2
true
1,344
apps
verifiable_code
2150
Solve the following coding problem using the programming language python: In this problem, we will deal with binary strings. Each character of a binary string is either a 0 or a 1. We will also deal with substrings; recall that a substring is a contiguous subsequence of a string. We denote the substring of string $s$ ...
```python import sys input = sys.stdin.readline MOD = 987654103 n = int(input()) t = input() place = [] f1 = [] e1 = [] s = [] curr = 0 count1 = 0 for i in range(n): c = t[i] if c == '0': if count1: e1.append(i - 1) if count1 & 1: s.append(1) c...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n11011\n3\n1 3 3\n1 4 2\n1 2 3\n', 'output': 'Yes\nYes\nNo\n'}, {'type': 'stdin_stdout', 'input': '1\n0\n1\n1 1 1\n', 'output': 'Yes\n'}, {'type': 'stdin_stdout', 'input': '3\n010\n3\n1 3 1\n1 3 1\n3 2 1\n', 'output': 'Yes\nYes\nNo\n'}, {'type': 'stdin_stdout', 'inpu...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1320/D'}
vfc_6146
```python import sys input = sys.stdin.readline MOD = 987654103 n = int(input()) t = input() place = [] f1 = [] e1 = [] s = [] curr = 0 count1 = 0 for i in range(n): c = t[i] if c == '0': if count1: e1.append(i - 1) if count1 & 1: s.append(1) c...
5 11011 3 1 3 3 1 4 2 1 2 3
Yes Yes No
Yes Yes No
true
1,345
apps
verifiable_code
2151
Solve the following coding problem using the programming language python: You are given an array $a$ of $n$ integers and an integer $s$. It is guaranteed that $n$ is odd. In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the med...
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline n,s=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() med=a[n//2] ans=0 if med>s: for i in range(n//2+1): if a[i]>s: ans+=a[i]-s elif med<s: for i in range(n//2,n): if s>a[i]: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 8\n6 5 8\n', 'output': '2'}, {'type': 'stdin_stdout', 'input': '7 20\n21 15 12 11 20 19 12\n', 'output': '6'}, {'type': 'stdin_stdout', 'input': '3 1\n1 2 5\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': '1 100\n105\n', 'output': '5'}, {'type': 'stdin_stdout',...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1037/B'}
vfc_6150
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline n,s=list(map(int,input().split())) a=list(map(int,input().split())) a.sort() med=a[n//2] ans=0 if med>s: for i in range(n//2+1): if a[i]>s: ans+=a[i]-s elif med<s: for i in range(n//2,n): if s>a[i]: ...
3 8 6 5 8
2
2
true
1,346
apps
verifiable_code
2153
Solve the following coding problem using the programming language python: In order to fly to the Moon Mister B just needs to solve the following problem. There is a complete indirected graph with n vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles. W...
```python #!/usr/bin/env python3 from collections import defaultdict DEBUG = False def main(): if DEBUG: test() n = int(input()) paths = cycles(n) print(len(paths)) for p in paths: print('%d %s' % (len(p), ' '.join([str(v) for v in p]))) def cycles(n): """Builds a set of...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n', 'output': '2\n3 1 2 3\n3 1 2 3\n'}, {'type': 'stdin_stdout', 'input': '5\n', 'output': '6\n3 1 2 3\n3 2 3 4\n3 3 4 5\n3 4 5 1\n4 2 1 3 5\n4 5 1 4 2\n'}, {'type': 'stdin_stdout', 'input': '4\n', 'output': '4\n3 4 1 2\n3 2 3 4\n3 1 2 3\n3 3 4 1\n'}, {'type': 'stdin...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/819/E'}
vfc_6158
```python #!/usr/bin/env python3 from collections import defaultdict DEBUG = False def main(): if DEBUG: test() n = int(input()) paths = cycles(n) print(len(paths)) for p in paths: print('%d %s' % (len(p), ' '.join([str(v) for v in p]))) def cycles(n): """Builds a set of...
3
2 3 1 2 3 3 1 2 3
2 3 1 2 3 3 1 2 3
true
1,347
apps
verifiable_code
2154
Solve the following coding problem using the programming language python: Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this ...
```python k, q = list(map(int, input().split())) t = [0] * (k + 1) t[1] = 1 d = [0] n = i = 1 while i < 1001: if 2000 * t[k] > i - 1e-7: d.append(n) i += 1 else: t = [0] + [(j * t[j] + (k - j + 1) * t[j - 1]) / k for j in range(1, k + 1)] n += 1 for i in range(q): print(d[int(inp...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1 1\n1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '2 2\n1\n2\n', 'output': '2\n2\n'}, {'type': 'stdin_stdout', 'input': '3 5\n1\n4\n20\n50\n300\n', 'output': '3\n3\n3\n3\n3\n'}, {'type': 'stdin_stdout', 'input': '4 5\n2\n4\n30\n100\n1000\n', 'output': '4\n...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/768/D'}
vfc_6162
```python k, q = list(map(int, input().split())) t = [0] * (k + 1) t[1] = 1 d = [0] n = i = 1 while i < 1001: if 2000 * t[k] > i - 1e-7: d.append(n) i += 1 else: t = [0] + [(j * t[j] + (k - j + 1) * t[j - 1]) / k for j in range(1, k + 1)] n += 1 for i in range(q): print(d[int(inp...
1 1 1
1
1
true
1,348
apps
verifiable_code
2155
Solve the following coding problem using the programming language python: Summer is coming! It's time for Iahub and Iahubina to work out, as they both want to look hot at the beach. The gym where they go is a matrix a with n lines and m columns. Let number a[i][j] represents the calories burned by performing workout a...
```python def main(): n, m = list(map(int, input().split())) aa = [] for _ in range(n): row = list(map(int, input().split())) row.append(0) aa.append(row) aa.append([0] * (m + 1)) d1, d2, d3, d4 = ([[0] * (m + 1) for _ in range(n + 1)] for _ in (1, 2, 3, 4)) for i in rang...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\n100 100 100\n100 1 100\n100 100 100\n', 'output': '800'}, {'type': 'stdin_stdout', 'input': '4 5\n87882 40786 3691 85313 46694\n28884 16067 3242 97367 78518\n4250 35501 9780 14435 19004\n64673 65438 56977 64495 27280\n', 'output': '747898'}, {'type': 'stdin_stdout...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/429/B'}
vfc_6166
```python def main(): n, m = list(map(int, input().split())) aa = [] for _ in range(n): row = list(map(int, input().split())) row.append(0) aa.append(row) aa.append([0] * (m + 1)) d1, d2, d3, d4 = ([[0] * (m + 1) for _ in range(n + 1)] for _ in (1, 2, 3, 4)) for i in rang...
3 3 100 100 100 100 1 100 100 100 100
800
800
true
1,349
apps
verifiable_code
2159
Solve the following coding problem using the programming language python: Polycarp is making a quest for his friends. He has already made n tasks, for each task the boy evaluated how interesting it is as an integer q_{i}, and the time t_{i} in minutes needed to complete the task. An interesting feature of his quest ...
```python from collections import defaultdict def __starting_point(): n, T = [int(_) for _ in input().split()] data = defaultdict(list) for i in range(n): t, q = [int(_) for _ in input().split()] data[T - t].append(q) prev_level = [] for level_id in range(1, T + 1): level ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 5\n1 1\n1 1\n2 2\n3 3\n4 4\n', 'output': '11\n'}, {'type': 'stdin_stdout', 'input': '5 5\n4 1\n4 2\n4 3\n4 4\n4 5\n', 'output': '9\n'}, {'type': 'stdin_stdout', 'input': '2 2\n1 1\n2 10\n', 'output': '10\n'}, {'type': 'stdin_stdout', 'input': '10 1\n1 732\n1 649\n1 8...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/542/F'}
vfc_6182
```python from collections import defaultdict def __starting_point(): n, T = [int(_) for _ in input().split()] data = defaultdict(list) for i in range(n): t, q = [int(_) for _ in input().split()] data[T - t].append(q) prev_level = [] for level_id in range(1, T + 1): level ...
5 5 1 1 1 1 2 2 3 3 4 4
11
11
true
1,353
apps
verifiable_code
2161
Solve the following coding problem using the programming language python: Just to remind, girls in Arpa's land are really nice. Mehrdad wants to invite some Hoses to the palace for a dancing party. Each Hos has some weight w_{i} and some beauty b_{i}. Also each Hos may have some friends. Hoses are divided in some fri...
```python f = lambda: map(int, input().split()) n, m, w = f() wb = [(0, 0)] + list(zip(f(), f())) t = list(range(n + 1)) def g(x): if x == t[x]: return x t[x] = g(t[x]) return t[x] for i in range(m): x, y = f() x, y = g(x), g(y) if x != y: t[y] = x p = [[] for j in range(n + 1)] for i in ra...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 1 5\n3 2 5\n2 4 2\n1 2\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '4 2 11\n2 4 6 6\n6 4 2 1\n1 2\n2 3\n', 'output': '7\n'}, {'type': 'stdin_stdout', 'input': '10 5 100\n70 67 8 64 28 82 18 61 82 7\n596434 595982 237932 275698 361351 850374 936914 877996 ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/741/B'}
vfc_6190
```python f = lambda: map(int, input().split()) n, m, w = f() wb = [(0, 0)] + list(zip(f(), f())) t = list(range(n + 1)) def g(x): if x == t[x]: return x t[x] = g(t[x]) return t[x] for i in range(m): x, y = f() x, y = g(x), g(y) if x != y: t[y] = x p = [[] for j in range(n + 1)] for i in ra...
3 1 5 3 2 5 2 4 2 1 2
6
6
true
1,354
apps
verifiable_code
2163
Solve the following coding problem using the programming language python: Koa the Koala has a binary string $s$ of length $n$. Koa can perform no more than $n-1$ (possibly zero) operations of the following form: In one operation Koa selects positions $i$ and $i+1$ for some $i$ with $1 \le i < |s|$ and sets $s_i$ to $...
```python import sys readline = sys.stdin.readline MOD = 10**9+7 S = readline().strip().split('1') if len(S) == 1: print(len(S[0])) else: S = [len(s)+1 for s in S] ans = S[0]*S[-1] S = S[1:-1] dp = [0]*(max(S)+2) dp[0] = 1 for ai in S: res = 0 rz = 0 for i in ra...
{'test_cases': [{'type': 'stdin_stdout', 'input': '000\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '0101\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '0001111\n', 'output': '16\n'}, {'type': 'stdin_stdout', 'input': '00101100011100\n', 'output': '477\n'}, {'type': 'stdin_stdout', 'input': '0\n', ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1383/E'}
vfc_6198
```python import sys readline = sys.stdin.readline MOD = 10**9+7 S = readline().strip().split('1') if len(S) == 1: print(len(S[0])) else: S = [len(s)+1 for s in S] ans = S[0]*S[-1] S = S[1:-1] dp = [0]*(max(S)+2) dp[0] = 1 for ai in S: res = 0 rz = 0 for i in ra...
000
3
3
true
1,355
apps
verifiable_code
2164
Solve the following coding problem using the programming language python: Everybody seems to think that the Martians are green, but it turns out they are metallic pink and fat. Ajs has two bags of distinct nonnegative integers. The bags are disjoint, and the union of the sets of numbers in the bags is $\{0,1,…,M-1\}$,...
```python import sys input = sys.stdin.readline def main(): n, m = map(int, input().split()) a = list(map(int, input().split())) + [0]*500000 ans_S = 0 a[n] = a[0] + m s = [0]*600600 for i in range(n): s[i] = a[i + 1] - a[i] s[n] = -1 for i in range(n): s[2*n - i] = s[i]...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 5\n3 4\n', 'output': '1\n2\n'}, {'type': 'stdin_stdout', 'input': '4 1000000000\n5 25 125 625\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '2 4\n1 3\n', 'output': '2\n0 2\n'}, {'type': 'stdin_stdout', 'input': '1 2\n1\n', 'output': '1\n0\n'}, {'type': 'std...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1045/B'}
vfc_6202
```python import sys input = sys.stdin.readline def main(): n, m = map(int, input().split()) a = list(map(int, input().split())) + [0]*500000 ans_S = 0 a[n] = a[0] + m s = [0]*600600 for i in range(n): s[i] = a[i + 1] - a[i] s[n] = -1 for i in range(n): s[2*n - i] = s[i]...
2 5 3 4
1 2
1 2
true
1,356
apps
verifiable_code
2165
Solve the following coding problem using the programming language python: Giant chess is quite common in Geraldion. We will not delve into the rules of the game, we'll just say that the game takes place on an h × w field, and it is painted in two colors, but not like in chess. Almost all cells of the field are white a...
```python def init_factorials(N, mod): f = 1 fac = [1] * N for i in range(1, N): f *= i f %= mod fac[i] = f return fac def init_inv(N, mod, fac): b = bin(mod-2)[2:][-1::-1] ret = 1 tmp = fac[N] if b[0] == '1': ret = fac[N] for bi in b[1:]: tmp...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 4 2\n2 2\n2 3\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '100 100 3\n15 16\n16 15\n99 88\n', 'output': '545732279\n'}, {'type': 'stdin_stdout', 'input': '1000 1000 4\n50 50\n51 50\n50 51\n51 51\n', 'output': '899660737\n'}, {'type': 'stdin_stdout', 'inpu...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/559/C'}
vfc_6206
```python def init_factorials(N, mod): f = 1 fac = [1] * N for i in range(1, N): f *= i f %= mod fac[i] = f return fac def init_inv(N, mod, fac): b = bin(mod-2)[2:][-1::-1] ret = 1 tmp = fac[N] if b[0] == '1': ret = fac[N] for bi in b[1:]: tmp...
3 4 2 2 2 2 3
2
2
true
1,357
apps
verifiable_code
2166
Solve the following coding problem using the programming language python: Rick and Morty are playing their own version of Berzerk (which has nothing in common with the famous Berzerk game). This game needs a huge space, so they play it with a computer. In this game there are n objects numbered from 1 to n arranged in...
```python f = lambda: list(map(int, input().split()))[1:] n = int(input()) s, p, q = [], [], [] for x in [0, 1]: r = f() s.append(r) t = [len(r)] * n t[0] = 0 p.append(t) q.append((x, 0)) while q: x, i = q.pop() y = 1 - x for d in s[y]: j = (i - d) % n if p[y][j] < 1:...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n2 3 2\n3 1 2 3\n', 'output': 'Lose Win Win Loop\nLoop Win Win Win\n'}, {'type': 'stdin_stdout', 'input': '8\n4 6 2 3 4\n2 3 6\n', 'output': 'Win Win Win Win Win Win Win\nLose Win Lose Lose Win Lose Lose\n'}, {'type': 'stdin_stdout', 'input': '10\n3 4 7 5\n2 8 5\n', ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/786/A'}
vfc_6210
```python f = lambda: list(map(int, input().split()))[1:] n = int(input()) s, p, q = [], [], [] for x in [0, 1]: r = f() s.append(r) t = [len(r)] * n t[0] = 0 p.append(t) q.append((x, 0)) while q: x, i = q.pop() y = 1 - x for d in s[y]: j = (i - d) % n if p[y][j] < 1:...
5 2 3 2 3 1 2 3
Lose Win Win Loop Loop Win Win Win
Lose Win Win Loop Loop Win Win Win
true
1,358
apps
verifiable_code
2167
Solve the following coding problem using the programming language python: A function $f : R \rightarrow R$ is called Lipschitz continuous if there is a real constant K such that the inequality |f(x) - f(y)| ≤ K·|x - y| holds for all $x, y \in R$. We'll deal with a more... discrete version of this term. For an array $...
```python def read_data(): n, q = map(int, input().split()) As = list(map(int, input().split())) LRs = [] for i in range(q): L, R = list(map(int, input().split())) LRs.append((L, R)) return n, q, As, LRs def solve(n, q, As, LRs): difs = calc_difs(As) Ls = get_Ls(difs) Rs...
{'test_cases': [{'type': 'stdin_stdout', 'input': '10 4\n1 5 2 9 1 3 4 2 1 7\n2 4\n3 8\n7 10\n1 9\n', 'output': '17\n82\n23\n210\n'}, {'type': 'stdin_stdout', 'input': '7 6\n5 7 7 4 6 6 2\n1 2\n2 3\n2 6\n1 7\n4 7\n3 5\n', 'output': '2\n0\n22\n59\n16\n8\n'}, {'type': 'stdin_stdout', 'input': '2 2\n0 0\n1 2\n1 2\n', 'out...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/601/B'}
vfc_6214
```python def read_data(): n, q = map(int, input().split()) As = list(map(int, input().split())) LRs = [] for i in range(q): L, R = list(map(int, input().split())) LRs.append((L, R)) return n, q, As, LRs def solve(n, q, As, LRs): difs = calc_difs(As) Ls = get_Ls(difs) Rs...
10 4 1 5 2 9 1 3 4 2 1 7 2 4 3 8 7 10 1 9
17 82 23 210
17 82 23 210
true
1,359
apps
verifiable_code
2168
Solve the following coding problem using the programming language python: Greg has a weighed directed graph, consisting of n vertices. In this graph any pair of distinct vertices has an edge between them in both directions. Greg loves playing with the graph and now he has invented a new game: The game consists of n s...
```python import sys from array import array # noqa: F401 n = int(input()) matrix = [array('i', list(map(int, input().split()))) for _ in range(n)] aa = tuple([int(x) - 1 for x in input().split()]) ans = [''] * n for i in range(n-1, -1, -1): x = aa[i] for a in range(n): for b in range(n): ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1\n0\n1\n', 'output': '0 '}, {'type': 'stdin_stdout', 'input': '2\n0 5\n4 0\n1 2\n', 'output': '9 0 '}, {'type': 'stdin_stdout', 'input': '4\n0 3 1 1\n6 0 400 1\n2 4 0 1\n1 1 1 0\n4 1 2 3\n', 'output': '17 23 404 0 '}, {'type': 'stdin_stdout', 'input': '4\n0 57148 5100...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/295/B'}
vfc_6218
```python import sys from array import array # noqa: F401 n = int(input()) matrix = [array('i', list(map(int, input().split()))) for _ in range(n)] aa = tuple([int(x) - 1 for x in input().split()]) ans = [''] * n for i in range(n-1, -1, -1): x = aa[i] for a in range(n): for b in range(n): ...
1 0 1
0
0
true
1,360
apps
verifiable_code
2169
Solve the following coding problem using the programming language python: You are given a prime number $p$, $n$ integers $a_1, a_2, \ldots, a_n$, and an integer $k$. Find the number of pairs of indexes $(i, j)$ ($1 \le i < j \le n$) for which $(a_i + a_j)(a_i^2 + a_j^2) \equiv k \bmod p$. -----Input----- The firs...
```python def check(num1, num2, p, k): v = num1 + num2 v *= num1 * num1 + num2 * num2 v %= p v += p v %= p return v == k % p def __starting_point(): n, p, k = (int(x) for x in input().split()) idx___number = [int(x) for x in input().split()] idx___precount = [((pow(x, 4, p) - k * ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3 0\n0 1 2\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': '6 7 2\n1 2 3 4 5 6\n', 'output': '3'}, {'type': 'stdin_stdout', 'input': '5 5 3\n3 0 4 1 2\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': '7 7 3\n4 0 5 3 1 2 6\n', 'output': '0'}, {'type': 'stdi...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1188/B'}
vfc_6222
```python def check(num1, num2, p, k): v = num1 + num2 v *= num1 * num1 + num2 * num2 v %= p v += p v %= p return v == k % p def __starting_point(): n, p, k = (int(x) for x in input().split()) idx___number = [int(x) for x in input().split()] idx___precount = [((pow(x, 4, p) - k * ...
3 3 0 0 1 2
1
1
true
1,361
apps
verifiable_code
2170
Solve the following coding problem using the programming language python: There are some rabbits in Singapore Zoo. To feed them, Zookeeper bought $n$ carrots with lengths $a_1, a_2, a_3, \ldots, a_n$. However, rabbits are very fertile and multiply very quickly. Zookeeper now has $k$ rabbits and does not have enough ca...
```python import heapq def sum_sqaure(a, k): q, r = divmod(a, k) return q**2 * (k-r) + (q+1)**2 * r def diff(a, k): return sum_sqaure(a, k+1) - sum_sqaure(a, k) n, k = map(int, input().split()) nums = list(map(int, input().split())) curr = sum(sum_sqaure(a, 1) for a in nums) Q = [(diff(a, 1), a, 1) for ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 6\n5 3 1\n', 'output': '15\n'}, {'type': 'stdin_stdout', 'input': '1 4\n19\n', 'output': '91\n'}, {'type': 'stdin_stdout', 'input': '1 3\n1000000\n', 'output': '333333333334\n'}, {'type': 'stdin_stdout', 'input': '1 1\n1\n', 'output': '1\n'}, {'type': 'stdin_stdout',...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1428/E'}
vfc_6226
```python import heapq def sum_sqaure(a, k): q, r = divmod(a, k) return q**2 * (k-r) + (q+1)**2 * r def diff(a, k): return sum_sqaure(a, k+1) - sum_sqaure(a, k) n, k = map(int, input().split()) nums = list(map(int, input().split())) curr = sum(sum_sqaure(a, 1) for a in nums) Q = [(diff(a, 1), a, 1) for ...
3 6 5 3 1
15
15
true
1,362
apps
verifiable_code
2172
Solve the following coding problem using the programming language python: Let's assume that v(n) is the largest prime number, that does not exceed n; u(n) is the smallest prime number strictly greater than n. Find $\sum_{i = 2}^{n} \frac{1}{v(i) u(i)}$. -----Input----- The first line contains integer t (1 ≤ t...
```python def prime(n): m = int(n ** 0.5) + 1 t = [1] * (n + 1) for i in range(3, m): if t[i]: t[i * i :: 2 * i] = [0] * ((n - i * i) // (2 * i) + 1) return [2] + [i for i in range(3, n + 1, 2) if t[i]] def gcd(a, b): c = a % b return gcd(b, c) if c else b p = prime(31650) def g(n): ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n2\n3\n', 'output': '1/6\n7/30\n'}, {'type': 'stdin_stdout', 'input': '1\n1000000000\n', 'output': '999999941999999673/1999999887999999118\n'}, {'type': 'stdin_stdout', 'input': '5\n3\n6\n9\n10\n5\n', 'output': '7/30\n5/14\n61/154\n9/22\n23/70\n'}, {'type': 'stdin_st...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/396/B'}
vfc_6234
```python def prime(n): m = int(n ** 0.5) + 1 t = [1] * (n + 1) for i in range(3, m): if t[i]: t[i * i :: 2 * i] = [0] * ((n - i * i) // (2 * i) + 1) return [2] + [i for i in range(3, n + 1, 2) if t[i]] def gcd(a, b): c = a % b return gcd(b, c) if c else b p = prime(31650) def g(n): ...
2 2 3
1/6 7/30
1/6 7/30
true
1,364
apps
verifiable_code
2173
Solve the following coding problem using the programming language python: Appleman has a very big sheet of paper. This sheet has a form of rectangle with dimensions 1 × n. Your task is help Appleman with folding of such a sheet. Actually, you need to perform q queries. Each query will have one of the following types: ...
```python from itertools import starmap def main(): n, q = list(map(int, input().split())) a = list(range(n + 1)) flipped = False start = 0 end = n for _ in range(q): cmd, *args = list(map(int, input().split())) if cmd == 1: p = args[0] if p > end-sta...
{'test_cases': [{'type': 'stdin_stdout', 'input': '7 4\n1 3\n1 2\n2 0 1\n2 1 2\n', 'output': '4\n3\n'}, {'type': 'stdin_stdout', 'input': '10 9\n2 2 9\n1 1\n2 0 1\n1 8\n2 0 8\n1 2\n2 1 3\n1 4\n2 2 4\n', 'output': '7\n2\n10\n4\n5\n'}, {'type': 'stdin_stdout', 'input': '10 5\n2 1 9\n2 4 10\n1 1\n2 0 1\n2 0 1\n', 'output'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/461/C'}
vfc_6238
```python from itertools import starmap def main(): n, q = list(map(int, input().split())) a = list(range(n + 1)) flipped = False start = 0 end = n for _ in range(q): cmd, *args = list(map(int, input().split())) if cmd == 1: p = args[0] if p > end-sta...
7 4 1 3 1 2 2 0 1 2 1 2
4 3
4 3
true
1,365
apps
verifiable_code
2174
Solve the following coding problem using the programming language python: Polycarpus has a sequence, consisting of n non-negative integers: a_1, a_2, ..., a_{n}. Let's define function f(l, r) (l, r are integer, 1 ≤ l ≤ r ≤ n) for sequence a as an operation of bitwise OR of all the sequence elements with indexes from ...
```python n, p, q = input(), set(), set() for i in map(int, input().split()): q = set(i | j for j in q) q.add(i) p.update(q) print(len(p)) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 2 0\n', 'output': '4'}, {'type': 'stdin_stdout', 'input': '10\n1 2 3 4 5 6 1 2 9 10\n', 'output': '11'}, {'type': 'stdin_stdout', 'input': '1\n123\n', 'output': '1'}, {'type': 'stdin_stdout', 'input': '10\n6 8 4 5 1 9 10 2 3 7\n', 'output': '15'}, {'type': 'stdin_...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/243/A'}
vfc_6242
```python n, p, q = input(), set(), set() for i in map(int, input().split()): q = set(i | j for j in q) q.add(i) p.update(q) print(len(p)) ```
3 1 2 0
4
4
true
1,366
apps
verifiable_code
2177
Solve the following coding problem using the programming language python: Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do...
```python n = int(input()) s = list(map(int,input().split(' '))) a = [] for i in range(max(s)): a.append([]) for i in range(len(s)): a[s[i]-1].append(i) a = list([x for x in a if x != []]) if len(a) > 1: for i in range(1,len(a)): if len(a[i]) > 1: s = a[i-1][-1] if s > a[...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n6 3 1 2\n', 'output': '7\n'}, {'type': 'stdin_stdout', 'input': '1\n1000\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '7\n3 3 3 3 3 3 3\n', 'output': '7\n'}, {'type': 'stdin_stdout', 'input': '64\n826 142 89 337 897 891 1004 704 281 644 910 852 147 193 28...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/830/B'}
vfc_6254
```python n = int(input()) s = list(map(int,input().split(' '))) a = [] for i in range(max(s)): a.append([]) for i in range(len(s)): a[s[i]-1].append(i) a = list([x for x in a if x != []]) if len(a) > 1: for i in range(1,len(a)): if len(a[i]) > 1: s = a[i-1][-1] if s > a[...
4 6 3 1 2
7
7
true
1,368
apps
verifiable_code
2179
Solve the following coding problem using the programming language python: A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes. Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from ...
```python q, b, c = list(map(int, input().split())) n = int(input()) a = list(map(int, input().split())) ans = 0 for i in a: if b < i < c: ans += 1 print(ans) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 3 7\n8\n4 7 5 5 3 6 2 8\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '6 5 7\n5\n1 5 7 92 3\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '3 2 4\n1\n3\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '5 3 8\n12\n8 3 4 5 7 6 8 3 5 4 7 6\n', ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/794/A'}
vfc_6262
```python q, b, c = list(map(int, input().split())) n = int(input()) a = list(map(int, input().split())) ans = 0 for i in a: if b < i < c: ans += 1 print(ans) ```
5 3 7 8 4 7 5 5 3 6 2 8
4
4
true
1,370
apps
verifiable_code
2180
Solve the following coding problem using the programming language python: There is an automatic door at the entrance of a factory. The door works in the following way: when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, when o...
```python def solve(): n1, m, a, d = list(map(int, input().split())) t = list(map(int, input().split())) from bisect import insort from math import floor insort(t, a * n1) pred = 0 k = 0 kpred = 0 n = 0 step = d // a + 1 sol = 0 fl = 0 for i in t: if (i > pred...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1 1 3 4\n7\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '4 3 4 2\n7 9 11\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '10 10 51 69\n154 170 170 183 251 337 412 426 445 452\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '70 10 26 17\n361 3...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/883/A'}
vfc_6266
```python def solve(): n1, m, a, d = list(map(int, input().split())) t = list(map(int, input().split())) from bisect import insort from math import floor insort(t, a * n1) pred = 0 k = 0 kpred = 0 n = 0 step = d // a + 1 sol = 0 fl = 0 for i in t: if (i > pred...
1 1 3 4 7
1
1
true
1,371
apps
verifiable_code
2181
Solve the following coding problem using the programming language python: Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will...
```python n = int(input()) a = list(map(int, input().split())) lp,rp = [0 for i in range(n)],[0 for i in range(n)] lnr, rnr = [a[i] for i in range(n)],[a[i] for i in range(n)] mx = a[0] for i in range(1,n): if a[i] > mx: mx = a[i] lp[i] = lp[i-1] else: mx += 1 lp[i] = lp[i-1] +...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n1 4 3 2 5\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '5\n1 2 2 2 1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '7\n10 20 40 50 70 90 30\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '1\n1\n', 'output': '0\n'}, {'type': 'stdin_stdou...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/847/H'}
vfc_6270
```python n = int(input()) a = list(map(int, input().split())) lp,rp = [0 for i in range(n)],[0 for i in range(n)] lnr, rnr = [a[i] for i in range(n)],[a[i] for i in range(n)] mx = a[0] for i in range(1,n): if a[i] > mx: mx = a[i] lp[i] = lp[i-1] else: mx += 1 lp[i] = lp[i-1] +...
5 1 4 3 2 5
6
6
true
1,372
apps
verifiable_code
2182
Solve the following coding problem using the programming language python: Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company. To settle this problem, they've decided t...
```python oleg = input() igor = input() oleg = sorted(list(oleg)) igor = sorted(list(igor)) n = len(oleg) oleg_turns = (n + 1) // 2 igor_turns = n // 2 min_oleg_id = 0 min_igor_id = n - igor_turns ans = ['?'] * n max_oleg_id = oleg_turns - 1 max_igor_id = n - 1 curr_turn = 'o' next_turn = {'o' : 'i', 'i' : 'o'} l_ans ...
{'test_cases': [{'type': 'stdin_stdout', 'input': 'tinkoff\nzscoder\n', 'output': 'fzfsirk\n'}, {'type': 'stdin_stdout', 'input': 'xxxxxx\nxxxxxx\n', 'output': 'xxxxxx\n'}, {'type': 'stdin_stdout', 'input': 'ioi\nimo\n', 'output': 'ioi\n'}, {'type': 'stdin_stdout', 'input': 'abc\naaa\n', 'output': 'aab\n'}, {'type': 's...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/794/C'}
vfc_6274
```python oleg = input() igor = input() oleg = sorted(list(oleg)) igor = sorted(list(igor)) n = len(oleg) oleg_turns = (n + 1) // 2 igor_turns = n // 2 min_oleg_id = 0 min_igor_id = n - igor_turns ans = ['?'] * n max_oleg_id = oleg_turns - 1 max_igor_id = n - 1 curr_turn = 'o' next_turn = {'o' : 'i', 'i' : 'o'} l_ans ...
tinkoff zscoder
fzfsirk
fzfsirk
true
1,373
apps
verifiable_code
2183
Solve the following coding problem using the programming language python: We start with a string $s$ consisting only of the digits $1$, $2$, or $3$. The length of $s$ is denoted by $|s|$. For each $i$ from $1$ to $|s|$, the $i$-th character of $s$ is denoted by $s_i$. There is one cursor. The cursor's location $\ell...
```python import sys mod = 10**9 + 7 for _ in range(int(input())): x = int(input()) s = list(map(int, input())) ans = len(s) for i in range(1, x+1): ans = (i + (ans-i) * s[i-1]) % mod r = len(s) for _ in range(s[i-1]-1): if len(s) < x: s += s[i:r] ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n5\n231\n7\n2323\n6\n333\n24\n133321333\n', 'output': '25\n1438\n1101\n686531475\n'}, {'type': 'stdin_stdout', 'input': '9\n1500\n1212\n1500\n1221\n1500\n122\n1500\n12121\n1500\n22\n1500\n1111112111111112\n1500\n1111111111221111111\n1500\n111111122\n1500\n11111121111...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1280/A'}
vfc_6278
```python import sys mod = 10**9 + 7 for _ in range(int(input())): x = int(input()) s = list(map(int, input())) ans = len(s) for i in range(1, x+1): ans = (i + (ans-i) * s[i-1]) % mod r = len(s) for _ in range(s[i-1]-1): if len(s) < x: s += s[i:r] ...
4 5 231 7 2323 6 333 24 133321333
25 1438 1101 686531475
25 1438 1101 686531475
true
1,374
apps
verifiable_code
2184
Solve the following coding problem using the programming language python: This is an easier version of the next problem. In this version, $q = 0$. A sequence of integers is called nice if its elements are arranged in blocks like in $[3, 3, 3, 4, 1, 1]$. Formally, if two elements are equal, everything in between must ...
```python n, _q = map(int, input().split()) mni = [-1] * 200001 mxi = [-1] * 200001 cnt = [0] * 200001 nd = 0 a = list(map(int, input().split())) for i, v in enumerate(a): if mni[v] == -1: mni[v] = i; nd += 1 mxi[v] = i cnt[v] += 1 r = 0 z = 0 currmax = 0 for i, v in enumerate(a): if i == mni[v]: z += 1...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 0\n3 7 3 7 3\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '10 0\n1 2 1 2 3 1 1 1 50 1\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '6 0\n6 6 3 3 4 4\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '7 0\n3 3 1 3 2 1 2\n', 'output': '4\n'}...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1209/G1'}
vfc_6282
```python n, _q = map(int, input().split()) mni = [-1] * 200001 mxi = [-1] * 200001 cnt = [0] * 200001 nd = 0 a = list(map(int, input().split())) for i, v in enumerate(a): if mni[v] == -1: mni[v] = i; nd += 1 mxi[v] = i cnt[v] += 1 r = 0 z = 0 currmax = 0 for i, v in enumerate(a): if i == mni[v]: z += 1...
5 0 3 7 3 7 3
2
2
true
1,375
apps
verifiable_code
2186
Solve the following coding problem using the programming language python: Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white. Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree,...
```python MOD = 1000000007 n = int(input()) p = [int(x) for x in input().split()] x = [int(x) for x in input().split()] children = [[] for x in range(n)] for i in range(1,n): children[p[i-1]].append(i) #print(children) count = [(0,0) for i in range(n)] for i in reversed(list(range(n))): prod = 1 for ch...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n0 0\n0 1 1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '6\n0 1 1 0 4\n1 1 0 0 1 0\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '10\n0 1 2 1 4 4 4 0 8\n0 0 0 1 0 1 1 0 0 1\n', 'output': '27\n'}, {'type': 'stdin_stdout', 'input': '5\n0 1 1 3\n0 ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/461/B'}
vfc_6290
```python MOD = 1000000007 n = int(input()) p = [int(x) for x in input().split()] x = [int(x) for x in input().split()] children = [[] for x in range(n)] for i in range(1,n): children[p[i-1]].append(i) #print(children) count = [(0,0) for i in range(n)] for i in reversed(list(range(n))): prod = 1 for ch...
3 0 0 0 1 1
2
2
true
1,376
apps
verifiable_code
2188
Solve the following coding problem using the programming language python: Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her t queries, each of one of the following type: + a_{i} — add non-negative integer a_{i}...
```python from sys import stdin def main(): cnt = [0] * 2 ** 18 t = str.maketrans("0123456789", "0101010101") _, *l = stdin.read().splitlines() for sign, s in map(str.split, l): if sign == '?': print(cnt[int(s, 2)]) else: cnt[int(s.translate(t), 2)] += 1 if sign...
{'test_cases': [{'type': 'stdin_stdout', 'input': '12\n+ 1\n+ 241\n? 1\n+ 361\n- 241\n? 0101\n+ 101\n? 101\n- 101\n? 101\n+ 4000\n? 0\n', 'output': '2\n1\n2\n1\n1\n'}, {'type': 'stdin_stdout', 'input': '4\n+ 200\n+ 200\n- 200\n? 0\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '20\n+ 61\n+ 99\n+ 51\n+ 70\n+ 7\...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/713/A'}
vfc_6298
```python from sys import stdin def main(): cnt = [0] * 2 ** 18 t = str.maketrans("0123456789", "0101010101") _, *l = stdin.read().splitlines() for sign, s in map(str.split, l): if sign == '?': print(cnt[int(s, 2)]) else: cnt[int(s.translate(t), 2)] += 1 if sign...
12 + 1 + 241 ? 1 + 361 - 241 ? 0101 + 101 ? 101 - 101 ? 101 + 4000 ? 0
2 1 2 1 1
2 1 2 1 1
true
1,378
apps
verifiable_code
2189
Solve the following coding problem using the programming language python: T is playing a game with his friend, HL. There are $n$ piles of stones, the $i$-th pile initially has $a_i$ stones. T and HL will take alternating turns, with T going first. In each turn, a player chooses a non-empty pile and then removes a s...
```python t = int(input()) for _ in range(t): n = int(input()) a = list(map(int,input().split())) sumA = sum(a) TWins = False for elem in a: if elem > sumA // 2: TWins = True break if TWins or sumA % 2 != 0: print("T") else: print("HL") ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1\n2\n2\n1 1\n', 'output': 'T\nHL\n'}, {'type': 'stdin_stdout', 'input': '1\n4\n2 3 1 2\n', 'output': 'HL\n'}, {'type': 'stdin_stdout', 'input': '2\n2\n1 4\n3\n3 1 3\n', 'output': 'T\nT\n'}, {'type': 'stdin_stdout', 'input': '3\n2\n4 3\n4\n2 2 2 3\n3\n1 4 1\n', 'out...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1396/B'}
vfc_6302
```python t = int(input()) for _ in range(t): n = int(input()) a = list(map(int,input().split())) sumA = sum(a) TWins = False for elem in a: if elem > sumA // 2: TWins = True break if TWins or sumA % 2 != 0: print("T") else: print("HL") ```
2 1 2 2 1 1
T HL
T HL
true
1,379
apps
verifiable_code
2190
Solve the following coding problem using the programming language python: There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might...
```python n = int(input()) ans = 0 stk = [] for v in map(int, input().split()): last = 0 while len(stk) and stk[-1][0] < v and stk[-1][1]: last = max(last, stk[-1][1]) del stk[-1] if not len(stk) or stk[-1][0] < v: stk.append((v, 0)) else: stk.append((v, last + 1)); ans ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '10\n10 9 7 8 6 5 3 4 2 1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '6\n1 2 3 4 5 6\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '6\n6 5 4 3 2 1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '10\n10 7 4 2 5 8 9 6 3 1\n', 'output': '4\n...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/319/B'}
vfc_6306
```python n = int(input()) ans = 0 stk = [] for v in map(int, input().split()): last = 0 while len(stk) and stk[-1][0] < v and stk[-1][1]: last = max(last, stk[-1][1]) del stk[-1] if not len(stk) or stk[-1][0] < v: stk.append((v, 0)) else: stk.append((v, last + 1)); ans ...
10 10 9 7 8 6 5 3 4 2 1
2
2
true
1,380
apps
verifiable_code
2191
Solve the following coding problem using the programming language python: You are given a sequence a consisting of n integers. Find the maximum possible value of $a_{i} \operatorname{mod} a_{j}$ (integer remainder of a_{i} divided by a_{j}), where 1 ≤ i, j ≤ n and a_{i} ≥ a_{j}. -----Input----- The first line conta...
```python def main(): input() aa = sorted(map(int, input().split())) maxa = max(aa) m = [False] * (maxa + 1) x = [] b = 0 for a in aa: if b != a: m[a] = True for i in range(b, a): x.append(b) b = a x.append(b) ans = 0 fo...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n3 4 5\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3\n1 2 4\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '1\n1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '1\n1000000\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '2\n1000...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/484/B'}
vfc_6310
```python def main(): input() aa = sorted(map(int, input().split())) maxa = max(aa) m = [False] * (maxa + 1) x = [] b = 0 for a in aa: if b != a: m[a] = True for i in range(b, a): x.append(b) b = a x.append(b) ans = 0 fo...
3 3 4 5
2
2
true
1,381
apps
verifiable_code
2192
Solve the following coding problem using the programming language python: There are n beacons located at distinct positions on a number line. The i-th beacon has position a_{i} and power level b_{i}. When the i-th beacon is activated, it destroys all beacons to its left (direction of decreasing coordinates) within dis...
```python n = int(input()) pos_blast = [list(map(int, input().split())) for _ in range(n)] MAX_N = max(pos_blast, key=lambda x: x[0])[0] + 2 power = [0 for _ in range(MAX_N)] tower = [False for _ in range(MAX_N)] can_destroy = [0 for _ in range(MAX_N)] for pos, blast in pos_blast: pos += 1 tower[pos] = True ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n1 9\n3 1\n6 1\n7 4\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '7\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '1\n0 1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '1\n0 1000000\n', 'output': '0\n'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/607/A'}
vfc_6314
```python n = int(input()) pos_blast = [list(map(int, input().split())) for _ in range(n)] MAX_N = max(pos_blast, key=lambda x: x[0])[0] + 2 power = [0 for _ in range(MAX_N)] tower = [False for _ in range(MAX_N)] can_destroy = [0 for _ in range(MAX_N)] for pos, blast in pos_blast: pos += 1 tower[pos] = True ...
4 1 9 3 1 6 1 7 4
1
1
true
1,382
apps
verifiable_code
2193
Solve the following coding problem using the programming language python: John Smith knows that his son, Thomas Smith, is among the best students in his class and even in his school. After the students of the school took the exams in English, German, Math, and History, a table of results was formed. There are $n$ stu...
```python def main(): n = int(input()) scores = [] for i in range(n): a = list(map(int, input().split())) tot = sum(a) scores.append((-tot, i)) scores.sort() for i in range(n): if scores[i][1] == 0: print(i + 1) main() ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n100 98 100 100\n100 100 100 100\n100 100 99 99\n90 99 90 100\n100 98 60 99\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '6\n100 80 90 99\n60 60 60 60\n90 60 100 60\n60 100 60 80\n100 100 0 100\n0 0 0 0\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1017/A'}
vfc_6318
```python def main(): n = int(input()) scores = [] for i in range(n): a = list(map(int, input().split())) tot = sum(a) scores.append((-tot, i)) scores.sort() for i in range(n): if scores[i][1] == 0: print(i + 1) main() ```
5 100 98 100 100 100 100 100 100 100 100 99 99 90 99 90 100 100 98 60 99
2
2
true
1,383
apps
verifiable_code
2194
Solve the following coding problem using the programming language python: Barney lives in country USC (United States of Charzeh). USC has n cities numbered from 1 through n and n - 1 roads between them. Cities and roads of USC form a rooted tree (Barney's not sure why it is rooted). Root of the tree is the city number...
```python n = int(input()) pos,tree,ans,sz = list(map(int,input().split())) if n > 1 else [],[],[],[] for i in range(n): tree.append([]) ans.append(0.0) sz.append(0) for i in range(n-1): tree[pos[i]-1].append(i+1) for i in range(n)[::-1]: sz[i] = 1 for to in tree[i]: sz[i] += sz[to] for i in range(n)...
{'test_cases': [{'type': 'stdin_stdout', 'input': '7\n1 2 1 1 4 4\n', 'output': '1.0 4.0 5.0 3.5 4.5 5.0 5.0 \n'}, {'type': 'stdin_stdout', 'input': '12\n1 1 2 2 4 4 3 3 1 10 8\n', 'output': '1.0 5.0 5.5 6.5 7.5 8.0 8.0 7.0 7.5 6.5 7.5 8.0 \n'}, {'type': 'stdin_stdout', 'input': '3\n1 2\n', 'output': '1.0 2.0 3.0 \n'},...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/696/B'}
vfc_6322
```python n = int(input()) pos,tree,ans,sz = list(map(int,input().split())) if n > 1 else [],[],[],[] for i in range(n): tree.append([]) ans.append(0.0) sz.append(0) for i in range(n-1): tree[pos[i]-1].append(i+1) for i in range(n)[::-1]: sz[i] = 1 for to in tree[i]: sz[i] += sz[to] for i in range(n)...
7 1 2 1 1 4 4
1.0 4.0 5.0 3.5 4.5 5.0 5.0
1.0 4.0 5.0 3.5 4.5 5.0 5.0
true
1,384
apps
verifiable_code
2195
Solve the following coding problem using the programming language python: You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such in...
```python from collections import Counter n = int(input()) a = list(map(int, input().split())) c = Counter(a) res = 0 cur = 0 for i in sorted(c.keys()): d = min(c[i], cur) cur -= d res += d cur += c[i] print(res) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '7\n10 1 1 1 5 5 3\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '5\n1 1 1 1 1\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '6\n300000000 200000000 300000000 200000000 1000000000 300000000\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '10\...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1007/A'}
vfc_6326
```python from collections import Counter n = int(input()) a = list(map(int, input().split())) c = Counter(a) res = 0 cur = 0 for i in sorted(c.keys()): d = min(c[i], cur) cur -= d res += d cur += c[i] print(res) ```
7 10 1 1 1 5 5 3
4
4
true
1,385
apps
verifiable_code
2196
Solve the following coding problem using the programming language python: You are given a string S of length n with each character being one of the first m lowercase English letters. Calculate how many different strings T of length n composed from the first m lowercase English letters exist such that the length of L...
```python n, m = list(map(int, input().split())) s = input() p = c = 0 for i in range(1, n): if s[i] == s[i - 1]: c += n * (m - 1) p = i elif s[i] != s[i - 2]: p = i - 1 c += i - p ans = n * n * (m - 1) - c print(ans) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\naaa\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '3 3\naab\n', 'output': '11\n'}, {'type': 'stdin_stdout', 'input': '1 2\na\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '10 9\nabacadefgh\n', 'output': '789\n'}, {'type': 'stdin_stdout', 'input...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/578/D'}
vfc_6330
```python n, m = list(map(int, input().split())) s = input() p = c = 0 for i in range(1, n): if s[i] == s[i - 1]: c += n * (m - 1) p = i elif s[i] != s[i - 2]: p = i - 1 c += i - p ans = n * n * (m - 1) - c print(ans) ```
3 3 aaa
6
6
true
1,386
apps
verifiable_code
2197
Solve the following coding problem using the programming language python: You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the ord...
```python a = input() b = a[::-1] print(a + b) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': 'aba\n', 'output': 'abaaba'}, {'type': 'stdin_stdout', 'input': 'ab\n', 'output': 'abba'}, {'type': 'stdin_stdout', 'input': 'abcab\n', 'output': 'abcabbacba'}, {'type': 'stdin_stdout', 'input': 'baaaaaaa\n', 'output': 'baaaaaaaaaaaaaab'}, {'type': 'stdin_stdout', 'inpu...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/932/A'}
vfc_6334
```python a = input() b = a[::-1] print(a + b) ```
aba
abaaba
abaaba
true
1,387
apps
verifiable_code
2198
Solve the following coding problem using the programming language python: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "...
```python n = int(input()) s = set() for a in range(n): name = input() name = name.replace('u', 'oo') while (name.count('kh') > 0): name = name.replace('kh', 'h') s.add(name) print(len(s)) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/883/F'}
vfc_6338
```python n = int(input()) s = set() for a in range(n): name = input() name = name.replace('u', 'oo') while (name.count('kh') > 0): name = name.replace('kh', 'h') s.add(name) print(len(s)) ```
10 mihail oolyana kooooper hoon ulyana koouper mikhail khun kuooper kkkhoon
4
4
true
1,388
apps
verifiable_code
2199
Solve the following coding problem using the programming language python: Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it. [Image]  T...
```python import sys input = sys.stdin.readline n, k = list(map(int, input().split())) begin = [-1] * n end = [-1] * n hurt = [-1] * n adj = [[] for i in range(n)] for _ in range(n-1): u ,v = list(map(int, input().split())) adj[u-1].append(v-1) adj[v-1].append(u-1) hurt[0] = 1 begin[0] = 0 stack = [0] c...
{'test_cases': [{'type': 'stdin_stdout', 'input': '7 4\n1 2\n1 3\n1 4\n3 5\n3 6\n4 7\n', 'output': '7'}, {'type': 'stdin_stdout', 'input': '4 1\n1 2\n1 3\n2 4\n', 'output': '2'}, {'type': 'stdin_stdout', 'input': '8 5\n7 5\n1 7\n6 1\n3 7\n8 3\n2 1\n4 5\n', 'output': '9'}, {'type': 'stdin_stdout', 'input': '2 1\n1 2\n',...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1336/A'}
vfc_6342
```python import sys input = sys.stdin.readline n, k = list(map(int, input().split())) begin = [-1] * n end = [-1] * n hurt = [-1] * n adj = [[] for i in range(n)] for _ in range(n-1): u ,v = list(map(int, input().split())) adj[u-1].append(v-1) adj[v-1].append(u-1) hurt[0] = 1 begin[0] = 0 stack = [0] c...
7 4 1 2 1 3 1 4 3 5 3 6 4 7
7
7
true
1,389
apps
verifiable_code
2200
Solve the following coding problem using the programming language python: Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with ...
```python import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) b = a ans = 0 for k in range(29): a0 = [] a1 = [] a0a = a0.append a1a = a1.append b0 = [] b1 = [] b0a = b0.append b1a = b1.append for i in a: if i&(1<<k): a1a(i) ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1 2\n', 'output': '3'}, {'type': 'stdin_stdout', 'input': '3\n1 2 3\n', 'output': '2'}, {'type': 'stdin_stdout', 'input': '2\n1 1\n', 'output': '2'}, {'type': 'stdin_stdout', 'input': '100\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 2...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1322/B'}
vfc_6346
```python import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) b = a ans = 0 for k in range(29): a0 = [] a1 = [] a0a = a0.append a1a = a1.append b0 = [] b1 = [] b0a = b0.append b1a = b1.append for i in a: if i&(1<<k): a1a(i) ...
2 1 2
3
3
true
1,390
apps
verifiable_code
2202
Solve the following coding problem using the programming language python: An array of integers $p_{1},p_{2}, \ldots,p_{n}$ is called a permutation if it contains each number from $1$ to $n$ exactly once. For example, the following arrays are permutations: $[3,1,2], [1], [1,2,3,4,5]$ and $[4,3,1,2]$. The following arra...
```python import sys input = sys.stdin.readline n=int(input()) A=list(map(int,input().split())) BIT=[0]*(n+1) def update(v,w): while v<=n: BIT[v]+=w v+=(v&(-v)) def getvalue(v): ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v)) return ANS for i in range(1,n+1): update(i,...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n0 0 0\n', 'output': '3 2 1\n'}, {'type': 'stdin_stdout', 'input': '2\n0 1\n', 'output': '1 2\n'}, {'type': 'stdin_stdout', 'input': '5\n0 1 1 1 10\n', 'output': '1 4 3 2 5\n'}, {'type': 'stdin_stdout', 'input': '1\n0\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'i...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1208/D'}
vfc_6354
```python import sys input = sys.stdin.readline n=int(input()) A=list(map(int,input().split())) BIT=[0]*(n+1) def update(v,w): while v<=n: BIT[v]+=w v+=(v&(-v)) def getvalue(v): ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v)) return ANS for i in range(1,n+1): update(i,...
3 0 0 0
3 2 1
3 2 1
true
1,392
apps
verifiable_code
2204
Solve the following coding problem using the programming language python: You are given a directed graph of $n$ vertices and $m$ edges. Vertices are numbered from $1$ to $n$. There is a token in vertex $1$. The following actions are allowed: Token movement. To move the token from vertex $u$ to vertex $v$ if there i...
```python import sys input = sys.stdin.readline import heapq mod=998244353 n,m=list(map(int,input().split())) E=[[] for i in range(n+1)] E2=[[] for i in range(n+1)] for i in range(m): x,y=list(map(int,input().split())) E[x].append(y) E2[y].append(x) TIME=[1<<29]*(n+1) TIME[1]=0 def shuku(x,y): ret...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 4\n1 2\n2 3\n3 4\n4 1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4 3\n2 1\n2 3\n4 3\n', 'output': '10\n'}, {'type': 'stdin_stdout', 'input': '10 20\n2 1\n7 9\n10 2\n4 9\n3 1\n6 4\n3 6\n2 9\n5 2\n3 9\n6 8\n8 7\n10 4\n7 4\n8 5\n3 4\n6 7\n2 6\n10 6\n3 8\n'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1442/C'}
vfc_6362
```python import sys input = sys.stdin.readline import heapq mod=998244353 n,m=list(map(int,input().split())) E=[[] for i in range(n+1)] E2=[[] for i in range(n+1)] for i in range(m): x,y=list(map(int,input().split())) E[x].append(y) E2[y].append(x) TIME=[1<<29]*(n+1) TIME[1]=0 def shuku(x,y): ret...
4 4 1 2 2 3 3 4 4 1
2
2
true
1,394
apps
verifiable_code
2205
Solve the following coding problem using the programming language python: Please notice the unusual memory limit of this problem. Orac likes games. Recently he came up with the new game, "Game of Life". You should play this game on a black and white grid with $n$ rows and $m$ columns. Each cell is either black or wh...
```python def main(): import sys from array import array from collections import deque input = sys.stdin.readline H, W, Q = list(map(int, input().split())) grid = array('b', [0] * (H*W)) #flg_0 = 0 #flg_1 = 0 for h in range(H): line = input().rstrip('\n') """ ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3 3\n000\n111\n000\n1 1 1\n2 2 2\n3 3 3\n', 'output': '1\n1\n1\n'}, {'type': 'stdin_stdout', 'input': '5 2 2\n01\n10\n01\n10\n01\n1 1 4\n5 1 4\n', 'output': '0\n0\n'}, {'type': 'stdin_stdout', 'input': '5 5 3\n01011\n10110\n01101\n11010\n10101\n1 1 4\n1 2 3\n5 5 3\n'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1349/C'}
vfc_6366
```python def main(): import sys from array import array from collections import deque input = sys.stdin.readline H, W, Q = list(map(int, input().split())) grid = array('b', [0] * (H*W)) #flg_0 = 0 #flg_1 = 0 for h in range(H): line = input().rstrip('\n') """ ...
3 3 3 000 111 000 1 1 1 2 2 2 3 3 3
1 1 1
1 1 1
true
1,395
apps
verifiable_code
2206
Solve the following coding problem using the programming language python: Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged ...
```python n = int(input()) a = list(map(int, input().split())) p = [0] * (n + 1) ans = [1] * (n + 1) ind = n for i in range(n): p[a[i] - 1] = 1 while ind > 0 and p[ind - 1] == 1: ind -= 1 ans[i + 1] = 1 + (i + 1) - (n - ind) print(' '.join(map(str, ans))) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n1 3 4 2\n', 'output': '1 2 3 2 1\n'}, {'type': 'stdin_stdout', 'input': '8\n6 8 3 4 7 2 1 5\n', 'output': '1 2 2 3 4 3 4 5 1\n'}, {'type': 'stdin_stdout', 'input': '1\n1\n', 'output': '1 1\n'}, {'type': 'stdin_stdout', 'input': '11\n10 8 9 4 6 3 5 1 11 7 2\n', 'outp...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/875/B'}
vfc_6370
```python n = int(input()) a = list(map(int, input().split())) p = [0] * (n + 1) ans = [1] * (n + 1) ind = n for i in range(n): p[a[i] - 1] = 1 while ind > 0 and p[ind - 1] == 1: ind -= 1 ans[i + 1] = 1 + (i + 1) - (n - ind) print(' '.join(map(str, ans))) ```
4 1 3 4 2
1 2 3 2 1
1 2 3 2 1
true
1,396
apps
verifiable_code
2207
Solve the following coding problem using the programming language python: Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to ...
```python n=int(input()) ta,tb,da,db=[0]*4 for i in range (n): t,x,y=list(map(int,input().split())) if t==1: ta+=(x+y) da+=y if (t==2): tb+=(x+y) db+=y if (ta-da>=0.5*ta): print ('LIVE') else : print ('DEAD') if (tb-db>=0.5*tb): print ('LIVE') else : pr...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1 5 5\n2 6 4\n', 'output': 'LIVE\nLIVE\n'}, {'type': 'stdin_stdout', 'input': '3\n1 0 10\n2 0 10\n1 10 0\n', 'output': 'LIVE\nDEAD\n'}, {'type': 'stdin_stdout', 'input': '10\n1 3 7\n2 4 6\n1 2 8\n2 5 5\n2 10 0\n2 10 0\n1 8 2\n2 2 8\n2 10 0\n1 1 9\n', 'output': 'DEAD...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/245/A'}
vfc_6374
```python n=int(input()) ta,tb,da,db=[0]*4 for i in range (n): t,x,y=list(map(int,input().split())) if t==1: ta+=(x+y) da+=y if (t==2): tb+=(x+y) db+=y if (ta-da>=0.5*ta): print ('LIVE') else : print ('DEAD') if (tb-db>=0.5*tb): print ('LIVE') else : pr...
2 1 5 5 2 6 4
LIVE LIVE
LIVE LIVE
true
1,397
apps
verifiable_code
2208
Solve the following coding problem using the programming language python: The legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring out the snacks! Moo! There are $n$ snacks flavors, numbered wit...
```python #!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 4\n1 2\n4 3\n1 4\n3 4\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '6 5\n2 3\n2 1\n3 4\n6 5\n4 5\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '2 1\n1 2\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '100000 12\n8 7\n1 9\n5 4\n11 12\n7 8...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1209/D'}
vfc_6378
```python #!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def...
5 4 1 2 4 3 1 4 3 4
1
1
true
1,398
apps
verifiable_code
2209
Solve the following coding problem using the programming language python: You have unweighted tree of $n$ vertices. You have to assign a positive weight to each edge so that the following condition would hold: For every two different leaves $v_{1}$ and $v_{2}$ of this tree, bitwise XOR of weights of all edges on th...
```python n = int(input()) g = [[] for i in range(n)] for i in range(n-1): u,v = [int(i)-1 for i in input().split()] g[u].append(v) g[v].append(u) leaf = [len(i)==1 for i in g] root = -1 mx = n-1 for i in range(n): if leaf[i]: root = i leafs = 0 for j in g[i]: if leaf[j]: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '6\n1 3\n2 3\n3 4\n4 5\n5 6\n', 'output': '1 4\n'}, {'type': 'stdin_stdout', 'input': '6\n1 3\n2 3\n3 4\n4 5\n4 6\n', 'output': '3 3\n'}, {'type': 'stdin_stdout', 'input': '7\n1 2\n2 7\n3 4\n4 7\n5 6\n6 7\n', 'output': '1 6\n'}, {'type': 'stdin_stdout', 'input': '3\n1 2...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1338/B'}
vfc_6382
```python n = int(input()) g = [[] for i in range(n)] for i in range(n-1): u,v = [int(i)-1 for i in input().split()] g[u].append(v) g[v].append(u) leaf = [len(i)==1 for i in g] root = -1 mx = n-1 for i in range(n): if leaf[i]: root = i leafs = 0 for j in g[i]: if leaf[j]: ...
6 1 3 2 3 3 4 4 5 5 6
1 4
1 4
true
1,399
apps
verifiable_code
2210
Solve the following coding problem using the programming language python: You are given a sequence a = \{a_1, ..., a_N\} with all zeros, and a sequence b = \{b_1, ..., b_N\} consisting of 0 and 1. The length of both is N. You can perform Q kinds of operations. The i-th operation is as follows: - Replace each of a_{l_...
```python import sys input=sys.stdin.readline n=int(input()) b=list(map(int,input().split())) ope=[[] for i in range(n)] Q=int(input()) for i in range(Q): l,r=list(map(int,input().split())) ope[r-1].append(l-1) res=b.count(0) Data=[(-1)**((b[i]==1)+1) for i in range(n)] for i in range(1,n): Data[i]+=Dat...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 0 1\n1\n1 3\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3\n1 0 1\n2\n1 1\n3 3\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '3\n1 0 1\n2\n1 1\n2 3\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '5\n0 1 0 1 0\n1\n1 5\n', 'output': '2...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc085/tasks/arc085_d'}
vfc_6386
```python import sys input=sys.stdin.readline n=int(input()) b=list(map(int,input().split())) ope=[[] for i in range(n)] Q=int(input()) for i in range(Q): l,r=list(map(int,input().split())) ope[r-1].append(l-1) res=b.count(0) Data=[(-1)**((b[i]==1)+1) for i in range(n)] for i in range(1,n): Data[i]+=Dat...
3 1 0 1 1 1 3
1
1
true
1,400
apps
verifiable_code
2211
Solve the following coding problem using the programming language python: Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play! More specifically, he wants to get from $(0,0)$ to $(x,0)$ by making multiple hops. He is only willing to hop...
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline mii=lambda:list(map(int,input().split())) for _ in range(int(input())): n,x=mii() has=0 a=0 for i in mii(): if x==i: has=1 a=max(a,i) if has: print(1) else: print(max(2,(x-1)//a+1)) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n2 4\n1 3\n3 12\n3 4 5\n1 5\n5\n2 10\n15 4\n', 'output': '2\n3\n1\n2\n'}, {'type': 'stdin_stdout', 'input': '1\n10 999999733\n25 68 91 55 36 29 96 4 63 3\n', 'output': '10416664\n'}, {'type': 'stdin_stdout', 'input': '1\n19 1000000000\n15 8 22 12 10 16 2 17 14 7 20 2...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1307/B'}
vfc_6390
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline mii=lambda:list(map(int,input().split())) for _ in range(int(input())): n,x=mii() has=0 a=0 for i in mii(): if x==i: has=1 a=max(a,i) if has: print(1) else: print(max(2,(x-1)//a+1)) ```
4 2 4 1 3 3 12 3 4 5 1 5 5 2 10 15 4
2 3 1 2
2 3 1 2
true
1,401
apps
verifiable_code
2212
Solve the following coding problem using the programming language python: Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he h...
```python import sys [n, q] = map(int, sys.stdin.readline().strip().split()) qis = [int(sys.stdin.readline().strip()) for _ in range(q)] def query(n, q): d = 2 * n - q while d % 2 == 0: d //= 2 return (n - d // 2) for qi in qis: print (query(n, qi)) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 3\n2\n3\n4\n', 'output': '3\n2\n4\n'}, {'type': 'stdin_stdout', 'input': '13 4\n10\n5\n4\n8\n', 'output': '13\n3\n8\n9\n'}, {'type': 'stdin_stdout', 'input': '2 2\n1\n2\n', 'output': '1\n2\n'}, {'type': 'stdin_stdout', 'input': '1 1\n1\n', 'output': '1\n'}, {'type': ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/949/B'}
vfc_6394
```python import sys [n, q] = map(int, sys.stdin.readline().strip().split()) qis = [int(sys.stdin.readline().strip()) for _ in range(q)] def query(n, q): d = 2 * n - q while d % 2 == 0: d //= 2 return (n - d // 2) for qi in qis: print (query(n, qi)) ```
4 3 2 3 4
3 2 4
3 2 4
true
1,402
apps
verifiable_code
2213
Solve the following coding problem using the programming language python: Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $f(0...
```python T = int(input()) for t in range(T): a, b, n = [int(i) for i in input().split()] if n%3 == 2: print(a^b) elif n%3 == 1: print(b) else: print(a) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n3 4 2\n4 5 0\n325 265 1231232\n', 'output': '7\n4\n76\n'}, {'type': 'stdin_stdout', 'input': '10\n0 0 1000000000\n1002 2003 36523\n233 5656 898989\n0 2352 0\n21132 23256 2323256\n12313 454878 11000\n1213 0 21\n11 1 1\n1 1 98532\n1000000000 1000000000 1000000000\n', ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1208/A'}
vfc_6398
```python T = int(input()) for t in range(T): a, b, n = [int(i) for i in input().split()] if n%3 == 2: print(a^b) elif n%3 == 1: print(b) else: print(a) ```
3 3 4 2 4 5 0 325 265 1231232
7 4 76
7 4 76
true
1,403
apps
verifiable_code
2214
Solve the following coding problem using the programming language python: The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive. All the roads are initially bad, but t...
```python class Graph: def __init__(self, n_vertices, edges, directed=True, weighted=False): self.n_vertices = n_vertices self.edges = edges self.directed = directed self.weighted = weighted @property def adj(self): try: return self._adj except ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 1\n', 'output': '4 3 3'}, {'type': 'stdin_stdout', 'input': '5\n1 2 3 4\n', 'output': '5 8 9 8 5'}, {'type': 'stdin_stdout', 'input': '31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n', 'output': '73741817 536870913 536870913 536870913 536870913 5...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/543/D'}
vfc_6402
```python class Graph: def __init__(self, n_vertices, edges, directed=True, weighted=False): self.n_vertices = n_vertices self.edges = edges self.directed = directed self.weighted = weighted @property def adj(self): try: return self._adj except ...
3 1 1
4 3 3
4 3 3
true
1,404