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
2215
Solve the following coding problem using the programming language python: Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city u_{i} to v_{i} (and vise versa) using the i-th road, the ...
```python #=============================================================================================== #importing some useful libraries. from fractions import Fraction import sys import os from io import BytesIO, IOBase from functools import cmp_to_key # from itertools import * from heapq import * from math i...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 5 3\n1 2 1\n2 3 2\n1 3 3\n3 4 4\n1 5 5\n3 5\n4 5\n5 5\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '2 2 3\n1 2 2\n2 1 3\n2 1\n2 2\n2 3\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '5 4 3\n1 2 999999999\n2 3 1000000000\n3 4 529529529\n5 1 5245245...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/449/B'}
vfc_6406
```python #=============================================================================================== #importing some useful libraries. from fractions import Fraction import sys import os from io import BytesIO, IOBase from functools import cmp_to_key # from itertools import * from heapq import * from math i...
5 5 3 1 2 1 2 3 2 1 3 3 3 4 4 1 5 5 3 5 4 5 5 5
2
2
true
1,405
apps
verifiable_code
2216
Solve the following coding problem using the programming language python: Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as q = q_1q_2... q_{k}. The algorithm consists of two steps: Find any c...
```python import sys s=sys.stdin.readline().split()[0] m=int(sys.stdin.readline()) Numx=[] Numy=[] Numz=[] x=0 y=0 z=0 for i in range(len(s)): if(s[i]=='x'): x+=1 if(s[i]=='y'): y+=1 if(s[i]=='z'): z+=1 Numx.append(x) Numy.append(y) Numz.append(z) Ans="" for M in ...
{'test_cases': [{'type': 'stdin_stdout', 'input': 'zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 6\n', 'output': 'YES\nYES\nNO\nYES\nNO\n'}, {'type': 'stdin_stdout', 'input': 'yxzyzxzzxyyzzxxxzyyzzyzxxzxyzyyzxyzxyxxyzxyxzyzxyzxyyxzzzyzxyyxyzxxy\n10\n17 67\n6 35\n12 45\n56 56\n14 30\n25 54\n1 1\n46 54\n3 33\n19 40\n', 'output'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/367/A'}
vfc_6410
```python import sys s=sys.stdin.readline().split()[0] m=int(sys.stdin.readline()) Numx=[] Numy=[] Numz=[] x=0 y=0 z=0 for i in range(len(s)): if(s[i]=='x'): x+=1 if(s[i]=='y'): y+=1 if(s[i]=='z'): z+=1 Numx.append(x) Numy.append(y) Numz.append(z) Ans="" for M in ...
zyxxxxxxyyz 5 5 5 1 3 1 11 1 4 3 6
YES YES NO YES NO
YES YES NO YES NO
true
1,406
apps
verifiable_code
2218
Solve the following coding problem using the programming language python: There is a country with $n$ citizens. The $i$-th of them initially has $a_{i}$ money. The government strictly controls the wealth of its citizens. Whenever a citizen makes a purchase or earns some money, they must send a receipt to the social se...
```python n=int(input()) a=list(map(int,input().split())) q=int(input()) changes=[0]*q for i in range(q): changes[-i-1]=tuple(map(int,input().split())) final=[-1]*n curr=0 for guy in changes: if guy[0]==1: if final[guy[1]-1]==-1: final[guy[1]-1]=max(guy[2],curr) else: curr=max(cu...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n1 2 3 4\n3\n2 3\n1 2 2\n2 1\n', 'output': '3 2 3 4 \n'}, {'type': 'stdin_stdout', 'input': '5\n3 50 2 1 10\n3\n1 2 0\n2 8\n1 3 20\n', 'output': '8 8 20 8 10 \n'}, {'type': 'stdin_stdout', 'input': '10\n1 2 3 4 5 6 7 8 9 10\n10\n2 1\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1198/B'}
vfc_6418
```python n=int(input()) a=list(map(int,input().split())) q=int(input()) changes=[0]*q for i in range(q): changes[-i-1]=tuple(map(int,input().split())) final=[-1]*n curr=0 for guy in changes: if guy[0]==1: if final[guy[1]-1]==-1: final[guy[1]-1]=max(guy[2],curr) else: curr=max(cu...
4 1 2 3 4 3 2 3 1 2 2 2 1
3 2 3 4
3 2 3 4
true
1,407
apps
verifiable_code
2219
Solve the following coding problem using the programming language python: During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now wonder...
```python n, q = map(int, input().split()) s = '!' + input() nxt = [[n + 1] * (n + 2) for _ in range(26)] for i in range(n - 1, -1, -1): c = ord(s[i + 1]) - 97 for j in range(26): nxt[j][i] = nxt[j][i + 1] nxt[c][i] = i + 1 w = [[-1], [-1], [-1]] idx = lambda i, j, k: i * 65536 + j * 256 + k dp = ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '6 8\nabdabc\n+ 1 a\n+ 1 d\n+ 2 b\n+ 2 c\n+ 3 a\n+ 3 b\n+ 1 c\n- 2\n', 'output': 'YES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\n'}, {'type': 'stdin_stdout', 'input': '6 8\nabbaab\n+ 1 a\n+ 2 a\n+ 3 a\n+ 1 b\n+ 2 b\n+ 3 b\n- 1\n+ 2 z\n', 'output': 'YES\nYES\nYES\nYES\nYES\nNO\n...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1149/B'}
vfc_6422
```python n, q = map(int, input().split()) s = '!' + input() nxt = [[n + 1] * (n + 2) for _ in range(26)] for i in range(n - 1, -1, -1): c = ord(s[i + 1]) - 97 for j in range(26): nxt[j][i] = nxt[j][i + 1] nxt[c][i] = i + 1 w = [[-1], [-1], [-1]] idx = lambda i, j, k: i * 65536 + j * 256 + k dp = ...
6 8 abdabc + 1 a + 1 d + 2 b + 2 c + 3 a + 3 b + 1 c - 2
YES YES YES YES YES YES NO YES
YES YES YES YES YES YES NO YES
true
1,408
apps
verifiable_code
2220
Solve the following coding problem using the programming language python: Serge came to the school dining room and discovered that there is a big queue here. There are $m$ pupils in the queue. He's not sure now if he wants to wait until the queue will clear, so he wants to know which dish he will receive if he does. A...
```python import sys from itertools import accumulate class Lazysegtree: #RAQ def __init__(self, A, intv, initialize = True, segf = min): #区間は 1-indexed で管理 self.N = len(A) self.N0 = 2**(self.N-1).bit_length() self.intv = intv self.segf = segf self.lazy = [0]*(2*...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1 1\n1\n1\n1\n1 1 100\n', 'output': '100\n'}, {'type': 'stdin_stdout', 'input': '1 1\n1\n1\n1\n2 1 100\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '4 6\n1 8 2 4\n3 3 6 1 5 2\n3\n1 1 1\n2 5 10\n1 1 6\n', 'output': '8\n-1\n4\n'}, {'type': 'stdin_stdout', 'in...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1179/C'}
vfc_6426
```python import sys from itertools import accumulate class Lazysegtree: #RAQ def __init__(self, A, intv, initialize = True, segf = min): #区間は 1-indexed で管理 self.N = len(A) self.N0 = 2**(self.N-1).bit_length() self.intv = intv self.segf = segf self.lazy = [0]*(2*...
1 1 1 1 1 1 1 100
100
100
true
1,409
apps
verifiable_code
2221
Solve the following coding problem using the programming language python: Sereja loves number sequences very much. That's why he decided to make himself a new one following a certain algorithm. Sereja takes a blank piece of paper. Then he starts writing out the sequence in m stages. Each time he either adds a new num...
```python n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) m=int(input()) b=list(map(lambda x:int(x)-1,input().split())) c=[] now=0 k=0 ans=[] for i in range(n): t=a[i] last=now if t[0]==1: now+=1 if len(c)<100000: c.append(t[1]) if k<m and b[k]==no...
{'test_cases': [{'type': 'stdin_stdout', 'input': '6\n1 1\n1 2\n2 2 1\n1 3\n2 5 2\n1 4\n16\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16\n', 'output': '1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4\n'}, {'type': 'stdin_stdout', 'input': '2\n1 33085\n1 44638\n2\n1 2\n', 'output': '33085 44638\n'}, {'type': 'stdin_stdout', 'input': '10\n1 5...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/380/A'}
vfc_6430
```python n=int(input()) a=[] for i in range(n): a.append(list(map(int,input().split()))) m=int(input()) b=list(map(lambda x:int(x)-1,input().split())) c=[] now=0 k=0 ans=[] for i in range(n): t=a[i] last=now if t[0]==1: now+=1 if len(c)<100000: c.append(t[1]) if k<m and b[k]==no...
6 1 1 1 2 2 2 1 1 3 2 5 2 1 4 16 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4
1 2 1 2 3 1 2 1 2 3 1 2 1 2 3 4
true
1,410
apps
verifiable_code
2223
Solve the following coding problem using the programming language python: You've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes). String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters...
```python # import atexit # import io # import sys # # _INPUT_LINES = sys.stdin.read().splitlines() # input = iter(_INPUT_LINES).__next__ # _OUTPUT_BUFFER = io.StringIO() # sys.stdout = _OUTPUT_BUFFER # # # @atexit.register # def write(): # sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) import bisect from datetim...
{'test_cases': [{'type': 'stdin_stdout', 'input': '60 3\n2012-03-16 16:15:25: Disk size is\n2012-03-16 16:15:25: Network failute\n2012-03-16 16:16:29: Cant write varlog\n2012-03-16 16:16:42: Unable to start process\n2012-03-16 16:16:43: Disk size is too small\n2012-03-16 16:16:53: Timeout detected\n', 'output': '2012-0...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/245/F'}
vfc_6438
```python # import atexit # import io # import sys # # _INPUT_LINES = sys.stdin.read().splitlines() # input = iter(_INPUT_LINES).__next__ # _OUTPUT_BUFFER = io.StringIO() # sys.stdout = _OUTPUT_BUFFER # # # @atexit.register # def write(): # sys.__stdout__.write(_OUTPUT_BUFFER.getvalue()) import bisect from datetim...
60 3 2012-03-16 16:15:25: Disk size is 2012-03-16 16:15:25: Network failute 2012-03-16 16:16:29: Cant write varlog 2012-03-16 16:16:42: Unable to start process 2012-03-16 16:16:43: Disk size is too small 2012-03-16 16:16:53: Timeout detected
2012-03-16 16:16:43
2012-03-16 16:16:43
true
1,411
apps
verifiable_code
2224
Solve the following coding problem using the programming language python: Rudolf is on his way to the castle. Before getting into the castle, the security staff asked him a question: Given two binary numbers $a$ and $b$ of length $n$. How many different ways of swapping two digits in $a$ (only in $a$, not $b$) so tha...
```python n = int(input()) a = [int(x) for x in input().strip()] b = [int(x) for x in input().strip()] p, q, r, s = 0, 0, 0, 0 for i in range(n): if a[i] * 2 + b[i] == 0: p += 1 if a[i] * 2 + b[i] == 1: q += 1 if a[i] * 2 + b[i] == 2: r += 1 if a[i] * 2 + b[i] == 3: s += ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n01011\n11001\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '6\n011000\n010011\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '10\n0110101101\n1010000101\n', 'output': '21\n'}, {'type': 'stdin_stdout', 'input': '30\n011110110100010000011001000100\n...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1017/B'}
vfc_6442
```python n = int(input()) a = [int(x) for x in input().strip()] b = [int(x) for x in input().strip()] p, q, r, s = 0, 0, 0, 0 for i in range(n): if a[i] * 2 + b[i] == 0: p += 1 if a[i] * 2 + b[i] == 1: q += 1 if a[i] * 2 + b[i] == 2: r += 1 if a[i] * 2 + b[i] == 3: s += ...
5 01011 11001
4
4
true
1,412
apps
verifiable_code
2225
Solve the following coding problem using the programming language python: For strings s and t, we will say that s and t are prefix-free when neither is a prefix of the other. Let L be a positive integer. A set of strings S is a good string set when the following conditions hold true: - Each string in S has a length b...
```python import sys input=sys.stdin.readline sys.setrecursionlimit(10**9) from collections import deque class Node: def __init__(self,depth): self.depth=depth self.left=None self.right=None def insert(node,s): n=node for i in range(len(s)): t=s[i] if t=='0': ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 2\n00\n01\n', 'output': 'Alice\n'}, {'type': 'stdin_stdout', 'input': '2 2\n00\n11\n', 'output': 'Bob\n'}, {'type': 'stdin_stdout', 'input': '3 3\n0\n10\n110\n', 'output': 'Alice\n'}, {'type': 'stdin_stdout', 'input': '2 1\n0\n1\n', 'output': 'Bob\n'}, {'type': 'stdi...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc087/tasks/arc087_c'}
vfc_6446
```python import sys input=sys.stdin.readline sys.setrecursionlimit(10**9) from collections import deque class Node: def __init__(self,depth): self.depth=depth self.left=None self.right=None def insert(node,s): n=node for i in range(len(s)): t=s[i] if t=='0': ...
2 2 00 01
Alice
Alice
true
1,413
apps
verifiable_code
2226
Solve the following coding problem using the programming language python: Zookeeper is buying a carton of fruit to feed his pet wabbit. The fruits are a sequence of apples and oranges, which is represented by a binary string $s_1s_2\ldots s_n$ of length $n$. $1$ represents an apple and $0$ represents an orange. Since...
```python class SegmentTree: def __init__(self, data, default=0, func=max): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 *...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n0110\n', 'output': '12\n'}, {'type': 'stdin_stdout', 'input': '7\n1101001\n', 'output': '30\n'}, {'type': 'stdin_stdout', 'input': '12\n011100011100\n', 'output': '156\n'}, {'type': 'stdin_stdout', 'input': '100\n01101100110111110011100001100100100001111110011000010...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1428/F'}
vfc_6450
```python class SegmentTree: def __init__(self, data, default=0, func=max): """initialize the segment tree with data""" self._default = default self._func = func self._len = len(data) self._size = _size = 1 << (self._len - 1).bit_length() self.data = [default] * (2 *...
4 0110
12
12
true
1,414
apps
verifiable_code
2227
Solve the following coding problem using the programming language python: A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original charact...
```python n, k = map(int, input().split()) a = [0] * n b = ['0'] * n c = [] s = input() for i in range(n): if k != 0: if s[i] == '(': c.append(i) else: d = c.pop() a[i] = 1 a[d] = 1 k -= 2 for i in range(n): if a[i] == 1: print(...
{'test_cases': [{'type': 'stdin_stdout', 'input': '6 4\n()(())\n', 'output': '()()\n'}, {'type': 'stdin_stdout', 'input': '8 8\n(()(()))\n', 'output': '(()(()))\n'}, {'type': 'stdin_stdout', 'input': '20 10\n((()))()((()()(())))\n', 'output': '((()))()()\n'}, {'type': 'stdin_stdout', 'input': '40 30\n((((((((()()()))))...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1023/C'}
vfc_6454
```python n, k = map(int, input().split()) a = [0] * n b = ['0'] * n c = [] s = input() for i in range(n): if k != 0: if s[i] == '(': c.append(i) else: d = c.pop() a[i] = 1 a[d] = 1 k -= 2 for i in range(n): if a[i] == 1: print(...
6 4 ()(())
()()
()()
true
1,415
apps
verifiable_code
2228
Solve the following coding problem using the programming language python: There are $n$ persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends. We want to plan a trip for every evening of $m$ days. On each trip, you have to select a group of people that ...
```python from collections import deque def solve(adj, m, k, uv): n = len(adj) nn = [len(a) for a in adj] q = deque() for i in range(n): if nn[i] < k: q.append(i) while q: v = q.popleft() for u in adj[v]: nn[u] -= 1 if nn[u] == k-1: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 4 2\n2 3\n1 2\n1 3\n1 4\n', 'output': '0\n0\n3\n3\n'}, {'type': 'stdin_stdout', 'input': '5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n', 'output': '0\n0\n0\n3\n3\n4\n4\n5\n'}, {'type': 'stdin_stdout', 'input': '5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n', 'output'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1037/E'}
vfc_6458
```python from collections import deque def solve(adj, m, k, uv): n = len(adj) nn = [len(a) for a in adj] q = deque() for i in range(n): if nn[i] < k: q.append(i) while q: v = q.popleft() for u in adj[v]: nn[u] -= 1 if nn[u] == k-1: ...
4 4 2 2 3 1 2 1 3 1 4
0 0 3 3
0 0 3 3
true
1,416
apps
verifiable_code
2229
Solve the following coding problem using the programming language python: Little Nastya has a hobby, she likes to remove some letters from word, to obtain another word. But it turns out to be pretty hard for her, because she is too young. Therefore, her brother Sergey always helps her. Sergey gives Nastya the word t ...
```python def sub(a, s): pa = 0 ps = 0 while pa < len(a) and ps < len(s): if a[pa] == s[ps]: ps += 1 pa += 1 else: pa += 1 return ps == len(s) def subword(t, ord_ar, n): t_copy = [] for i in range(len(ord_ar)): if ord_ar[i] >= n: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': 'ababcba\nabb\n5 3 4 1 7 6 2\n', 'output': '3'}, {'type': 'stdin_stdout', 'input': 'bbbabb\nbb\n1 6 3 4 2 5\n', 'output': '4'}, {'type': 'stdin_stdout', 'input': 'cacaccccccacccc\ncacc\n10 9 14 5 1 7 15 3 6 12 4 8 11 13 2\n', 'output': '9'}, {'type': 'stdin_stdout', 'in...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/778/A'}
vfc_6462
```python def sub(a, s): pa = 0 ps = 0 while pa < len(a) and ps < len(s): if a[pa] == s[ps]: ps += 1 pa += 1 else: pa += 1 return ps == len(s) def subword(t, ord_ar, n): t_copy = [] for i in range(len(ord_ar)): if ord_ar[i] >= n: ...
ababcba abb 5 3 4 1 7 6 2
3
3
true
1,417
apps
verifiable_code
2230
Solve the following coding problem using the programming language python: A new pack of n t-shirts came to a shop. Each of the t-shirts is characterized by three integers p_{i}, a_{i} and b_{i}, where p_{i} is the price of the i-th t-shirt, a_{i} is front color of the i-th t-shirt and b_{i} is back color of the i-th t...
```python n = int(input()) p = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] s = [] for i in range(n): s.append([p[i], a[i], b[i]]) s = sorted(s) m = int(input()) c = [int(i) for i in input().split()] idx = [0]*4 ans = [] for i in range(m): ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n300 200 400 500 911\n1 2 1 2 3\n2 1 3 2 1\n6\n2 3 1 2 1 1\n', 'output': '200 400 300 500 911 -1 \n'}, {'type': 'stdin_stdout', 'input': '2\n1000000000 1\n1 1\n1 2\n2\n2 1\n', 'output': '1 1000000000 \n'}, {'type': 'stdin_stdout', 'input': '10\n251034796 163562337 99...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/799/B'}
vfc_6466
```python n = int(input()) p = [int(i) for i in input().split()] a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] s = [] for i in range(n): s.append([p[i], a[i], b[i]]) s = sorted(s) m = int(input()) c = [int(i) for i in input().split()] idx = [0]*4 ans = [] for i in range(m): ...
5 300 200 400 500 911 1 2 1 2 3 2 1 3 2 1 6 2 3 1 2 1 1
200 400 300 500 911 -1
200 400 300 500 911 -1
true
1,418
apps
verifiable_code
2231
Solve the following coding problem using the programming language python: You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a $r \times c$ grid. Each cell on the grid represents a country. Each country has a dominant religion. There ...
```python import sys input = sys.stdin.readline MOD = 10**9 + 7 t = int(input()) for _ in range(t): r, c = list(map(int, input().split())) s = [list(input()) for i in range(r)] cnt_a = 0 flag_kado = False flag_hen = False flag_hen2 = False if s[0][0] == "A" or s[0][c-1] == "A" or s[r-1][0...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n7 8\nAAPAAAAA\nPPPPAAAA\nPPPPAAAA\nAPAAPPPP\nAPAPPAPP\nAAAAPPAP\nAAAAPPAA\n6 5\nAAAAA\nAAAAA\nAAPAA\nAAPAP\nAAAPP\nAAAPP\n4 4\nPPPP\nPPPP\nPPPP\nPPPP\n3 4\nPPPP\nPAAP\nPPPP\n', 'output': '2\n1\nMORTAL\n4\n'}, {'type': 'stdin_stdout', 'input': '1\n1 1\nA\n', 'output'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1280/B'}
vfc_6470
```python import sys input = sys.stdin.readline MOD = 10**9 + 7 t = int(input()) for _ in range(t): r, c = list(map(int, input().split())) s = [list(input()) for i in range(r)] cnt_a = 0 flag_kado = False flag_hen = False flag_hen2 = False if s[0][0] == "A" or s[0][c-1] == "A" or s[r-1][0...
4 7 8 AAPAAAAA PPPPAAAA PPPPAAAA APAAPPPP APAPPAPP AAAAPPAP AAAAPPAA 6 5 AAAAA AAAAA AAPAA AAPAP AAAPP AAAPP 4 4 PPPP PPPP PPPP PPPP 3 4 PPPP PAAP PPPP
2 1 MORTAL 4
2 1 MORTAL 4
true
1,419
apps
verifiable_code
2232
Solve the following coding problem using the programming language python: ZS the Coder is playing a game. There is a number displayed on the screen and there are two buttons, ' + ' (plus) and '$\sqrt{}$' (square root). Initially, the number 2 is displayed on the screen. There are n + 1 levels in the game and ZS the Co...
```python """ Codeforces Round 372 Div 1 Problem A Author : chaotic_iak Language: Python 3.5.2 """ ################################################### SOLUTION def main(): n, = read() curr = 2 for lv in range(1, n+1): tgt = (lv*(lv+1))**2 print((tgt - curr) // lv) curr = lv*(lv+1...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n', 'output': '2\n17\n46\n'}, {'type': 'stdin_stdout', 'input': '2\n', 'output': '2\n17\n'}, {'type': 'stdin_stdout', 'input': '4\n', 'output': '2\n17\n46\n97\n'}, {'type': 'stdin_stdout', 'input': '1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '7\n', 'ou...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/715/A'}
vfc_6474
```python """ Codeforces Round 372 Div 1 Problem A Author : chaotic_iak Language: Python 3.5.2 """ ################################################### SOLUTION def main(): n, = read() curr = 2 for lv in range(1, n+1): tgt = (lv*(lv+1))**2 print((tgt - curr) // lv) curr = lv*(lv+1...
3
2 17 46
2 17 46
true
1,420
apps
verifiable_code
2233
Solve the following coding problem using the programming language python: The Bubble Cup hypothesis stood unsolved for $130$ years. Who ever proves the hypothesis will be regarded as one of the greatest mathematicians of our time! A famous mathematician Jerry Mao managed to reduce the hypothesis to this problem: Give...
```python import os import sys from io import BytesIO, IOBase def main(): pass # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mod...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n2 4\n', 'output': '2\n4\n'}, {'type': 'stdin_stdout', 'input': '1\n9\n', 'output': '9\n'}, {'type': 'stdin_stdout', 'input': '5\n4 1 8 3 9\n', 'output': '4\n1\n9\n2\n9\n'}, {'type': 'stdin_stdout', 'input': '6\n8 7 8 6 8 9\n', 'output': '9\n6\n9\n6\n9\n9\n'}, {'type...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1423/J'}
vfc_6478
```python import os import sys from io import BytesIO, IOBase def main(): pass # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mod...
2 2 4
2 4
2 4
true
1,421
apps
verifiable_code
2234
Solve the following coding problem using the programming language python: Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daughter's ...
```python import sys from collections import deque def solve(): sys.setrecursionlimit(10**6) readline = sys.stdin.readline writelines = sys.stdout.writelines N = int(readline()) G = [[] for i in range(N)] for i in range(N-1): u, v = map(int, readline().split()) G[u-1].append(v-1)...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n1 3\n2 3\n4 3\n4\n2 1 2\n3 2 3 4\n3 1 2 4\n4 1 2 3 4\n', 'output': '1\n-1\n1\n-1\n'}, {'type': 'stdin_stdout', 'input': '7\n1 2\n2 3\n3 4\n1 5\n5 6\n5 7\n1\n4 2 4 6 7\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '7\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n5\n4 1 3 ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/613/D'}
vfc_6482
```python import sys from collections import deque def solve(): sys.setrecursionlimit(10**6) readline = sys.stdin.readline writelines = sys.stdout.writelines N = int(readline()) G = [[] for i in range(N)] for i in range(N-1): u, v = map(int, readline().split()) G[u-1].append(v-1)...
4 1 3 2 3 4 3 4 2 1 2 3 2 3 4 3 1 2 4 4 1 2 3 4
1 -1 1 -1
1 -1 1 -1
true
1,422
apps
verifiable_code
2235
Solve the following coding problem using the programming language python: Sergey Semyonovich is a mayor of a county city N and he used to spend his days and nights in thoughts of further improvements of Nkers' lives. Unfortunately for him, anything and everything has been done already, and there are no more possible i...
```python def main(): def countchildren(graph,vert,memo,pard=None): dumi=0 for child in graph[vert]: if child!=pard: if len(graph[child])==1: memo[child]=0 else: memo[child]=countchildren(graph,child,memo,vert)[0] ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n1 2\n1 3\n1 4\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '4\n1 2\n2 3\n3 4\n', 'output': '7\n'}, {'type': 'stdin_stdout', 'input': '2\n2 1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '3\n2 1\n3 2\n', 'output': '3\n'}, {'type': 'stdin_stdout'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1060/E'}
vfc_6486
```python def main(): def countchildren(graph,vert,memo,pard=None): dumi=0 for child in graph[vert]: if child!=pard: if len(graph[child])==1: memo[child]=0 else: memo[child]=countchildren(graph,child,memo,vert)[0] ...
4 1 2 1 3 1 4
6
6
true
1,423
apps
verifiable_code
2236
Solve the following coding problem using the programming language python: There are $n$ lamps on a line, numbered from $1$ to $n$. Each one has an initial state off ($0$) or on ($1$). You're given $k$ subsets $A_1, \ldots, A_k$ of $\{1, 2, \dots, n\}$, such that the intersection of any three subsets is empty. In othe...
```python import sys readline = sys.stdin.readline class UF(): def __init__(self, num): self.par = [-1]*num self.weight = [0]*num def find(self, x): if self.par[x] < 0: return x else: stack = [] while self.par[x] >= 0: stack.app...
{'test_cases': [{'type': 'stdin_stdout', 'input': '7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n', 'output': '1\n2\n3\n3\n3\n3\n3\n'}, {'type': 'stdin_stdout', 'input': '8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n', 'output': '1\n1\n1\n1\n1\n1\n4\n4\n'}, {'type': 'stdin_stdout', 'input': '5 3\n00...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1290/C'}
vfc_6490
```python import sys readline = sys.stdin.readline class UF(): def __init__(self, num): self.par = [-1]*num self.weight = [0]*num def find(self, x): if self.par[x] < 0: return x else: stack = [] while self.par[x] >= 0: stack.app...
7 3 0011100 3 1 4 6 3 3 4 7 2 2 3
1 2 3 3 3 3 3
1 2 3 3 3 3 3
true
1,424
apps
verifiable_code
2237
Solve the following coding problem using the programming language python: You are given a permutation $p_1, p_2, \ldots, p_n$. In one move you can swap two adjacent values. You want to perform a minimum number of moves, such that in the end there will exist a subsegment $1,2,\ldots, k$, in other words in the end the...
```python import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ class Binary_Indexed_Tree(): def __init__(self, n): self.n = n self.data = [0]*(n+1) def add(self, i, x): while i <= self.n: self.data[i] += x i += i & -i def get(self, i)...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n5 4 3 2 1\n', 'output': '0 1 3 6 10 \n'}, {'type': 'stdin_stdout', 'input': '3\n1 2 3\n', 'output': '0 0 0 \n'}, {'type': 'stdin_stdout', 'input': '1\n1\n', 'output': '0 \n'}, {'type': 'stdin_stdout', 'input': '10\n5 1 6 2 8 3 4 10 9 7\n', 'output': '0 1 2 3 8 9 12 ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1268/C'}
vfc_6494
```python import sys reader = (s.rstrip() for s in sys.stdin) input = reader.__next__ class Binary_Indexed_Tree(): def __init__(self, n): self.n = n self.data = [0]*(n+1) def add(self, i, x): while i <= self.n: self.data[i] += x i += i & -i def get(self, i)...
5 5 4 3 2 1
0 1 3 6 10
0 1 3 6 10
true
1,425
apps
verifiable_code
2238
Solve the following coding problem using the programming language python: Let's denote as $\text{popcount}(x)$ the number of bits set ('1' bits) in the binary representation of the non-negative integer x. You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤...
```python def popcount(n): res = 0 while n > 0: res += n & 1 n >>= 2 def A(l, r): r += 1 t = 1 << 64 while t & (l ^ r) == 0: t >>= 1 res = l | (t - 1) #print(t, res) return res def __starting_point(): """assert(A(1, 2) == 1) assert(A(2, 4) == 3) assert(A(1, 10) == 7) assert(A(13, 13) == 13) assert(...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 2\n2 4\n1 10\n', 'output': '1\n3\n7\n'}, {'type': 'stdin_stdout', 'input': '55\n1 1\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 9\n1 10\n2 2\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n3 3\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n4 4\n4 5\n4 6\n4 7\n4 8\n4 9\n4 10\n5 5\n5 6\n...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/484/A'}
vfc_6498
```python def popcount(n): res = 0 while n > 0: res += n & 1 n >>= 2 def A(l, r): r += 1 t = 1 << 64 while t & (l ^ r) == 0: t >>= 1 res = l | (t - 1) #print(t, res) return res def __starting_point(): """assert(A(1, 2) == 1) assert(A(2, 4) == 3) assert(A(1, 10) == 7) assert(A(13, 13) == 13) assert(...
3 1 2 2 4 1 10
1 3 7
1 3 7
true
1,426
apps
verifiable_code
2239
Solve the following coding problem using the programming language python: As we all know, Max is the best video game player among her friends. Her friends were so jealous of hers, that they created an actual game just to prove that she's not the best at games. The game is played on a directed acyclic graph (a DAG) wit...
```python def mat(shape, inital_val=None): if len(shape) > 1: return [mat(shape[1:], inital_val) for _ in range(shape[0])] else: return [inital_val] * shape[0] def main(): n, m = [int(x) for x in input().split()] graph = [{} for _ in range(n)] for _ in range(m): ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 4\n1 2 b\n1 3 a\n2 4 c\n3 4 b\n', 'output': 'BAAA\nABAA\nBBBA\nBBBB\n'}, {'type': 'stdin_stdout', 'input': '5 8\n5 3 h\n1 2 c\n3 1 c\n3 2 r\n5 1 r\n4 3 z\n5 4 r\n5 2 h\n', 'output': 'BABBB\nBBBBB\nAABBB\nAAABA\nAAAAB\n'}, {'type': 'stdin_stdout', 'input': '2 1\n1 2 q...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/917/B'}
vfc_6502
```python def mat(shape, inital_val=None): if len(shape) > 1: return [mat(shape[1:], inital_val) for _ in range(shape[0])] else: return [inital_val] * shape[0] def main(): n, m = [int(x) for x in input().split()] graph = [{} for _ in range(n)] for _ in range(m): ...
4 4 1 2 b 1 3 a 2 4 c 3 4 b
BAAA ABAA BBBA BBBB
BAAA ABAA BBBA BBBB
true
1,427
apps
verifiable_code
2240
Solve the following coding problem using the programming language python: A tree is a graph with n vertices and exactly n - 1 edges; this graph should meet the following condition: there exists exactly one shortest (by number of edges) path between any pair of its vertices. A subtree of a tree T is a tree with both v...
```python n = int(input()) r = [[] for i in range(n + 1)] r[1] = [0] for i in range(n - 1): a, b = map(int, input().split()) r[a].append(b) r[b].append(a) t = list(map(int, input().split())) u, v = [0] * (n + 1), [0] * (n + 1) for i, j in enumerate(t, 1): if j < 0: u[i] = - j else: v[i] = j t, p = [...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 2\n1 3\n1 -1 1\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '5\n2 3\n4 5\n2 5\n1 3\n0 2 1 4 3\n', 'output': '8\n'}, {'type': 'stdin_stdout', 'input': '10\n5 6\n8 2\n9 3\n4 1\n6 10\n9 8\n7 10\n7 4\n5 2\n0 -6 -9 -1 -5 -4 -2 -7 -8 -3\n', 'output': '18\n'},...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/274/B'}
vfc_6506
```python n = int(input()) r = [[] for i in range(n + 1)] r[1] = [0] for i in range(n - 1): a, b = map(int, input().split()) r[a].append(b) r[b].append(a) t = list(map(int, input().split())) u, v = [0] * (n + 1), [0] * (n + 1) for i, j in enumerate(t, 1): if j < 0: u[i] = - j else: v[i] = j t, p = [...
3 1 2 1 3 1 -1 1
3
3
true
1,428
apps
verifiable_code
2241
Solve the following coding problem using the programming language python: 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable ca...
```python MOD=10**9+7 N,C=map(int, input().split()) A=list(map(int, input().split())) B=list(map(int, input().split())) P=[[1] for _ in range(401)] for _ in range(1,401): for i in range(1,401): P[i].append(P[i][-1]*i%MOD) R=[[] for _ in range(N)] for i,AB in enumerate(zip(A, B)): AA,BB=AB for a in r...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 3\n1 1\n1 1\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '1 2\n1\n3\n', 'output': '14\n'}, {'type': 'stdin_stdout', 'input': '2 3\n1 1\n2 2\n', 'output': '66\n'}, {'type': 'stdin_stdout', 'input': '4 8\n3 1 4 1\n3 1 4 1\n', 'output': '421749\n'}, {'type': ...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc059/tasks/arc059_c'}
vfc_6510
```python MOD=10**9+7 N,C=map(int, input().split()) A=list(map(int, input().split())) B=list(map(int, input().split())) P=[[1] for _ in range(401)] for _ in range(1,401): for i in range(1,401): P[i].append(P[i][-1]*i%MOD) R=[[] for _ in range(N)] for i,AB in enumerate(zip(A, B)): AA,BB=AB for a in r...
2 3 1 1 1 1
4
4
true
1,429
apps
verifiable_code
2242
Solve the following coding problem using the programming language python: There are 2N balls in the xy-plane. The coordinates of the i-th of them is (x_i, y_i). Here, x_i and y_i are integers between 1 and N (inclusive) for all i, and no two balls occupy the same coordinates. In order to collect these balls, Snuke pre...
```python import sys input = sys.stdin.readline MOD = 10**9 + 7 N = int(input()) ball = (tuple(int(x) for x in row.split()) for row in sys.stdin.readlines()) # x座標を1,2,...,N # y座標をN+1,N+2,...,N+N graph = [set() for _ in range(N+N+1)] for x,y in ball: graph[x].add(y+N) graph[y+N].add(x) visited = [False] * ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1 1\n1 2\n2 1\n2 2\n', 'output': '8\n'}, {'type': 'stdin_stdout', 'input': '4\n3 2\n1 2\n4 1\n4 2\n2 2\n4 4\n2 1\n1 3\n', 'output': '7392\n'}, {'type': 'stdin_stdout', 'input': '4\n1 1\n2 2\n3 3\n4 4\n1 2\n2 1\n3 4\n4 3\n', 'output': '4480\n'}, {'type': 'stdin_stdou...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc083/tasks/arc083_d'}
vfc_6514
```python import sys input = sys.stdin.readline MOD = 10**9 + 7 N = int(input()) ball = (tuple(int(x) for x in row.split()) for row in sys.stdin.readlines()) # x座標を1,2,...,N # y座標をN+1,N+2,...,N+N graph = [set() for _ in range(N+N+1)] for x,y in ball: graph[x].add(y+N) graph[y+N].add(x) visited = [False] * ...
2 1 1 1 2 2 1 2 2
8
8
true
1,430
apps
verifiable_code
2243
Solve the following coding problem using the programming language python: There are N robots and M exits on a number line. The N + M coordinates of these are all integers and all distinct. For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i. Also, for each j (1 \leq j \leq M), the coord...
```python from bisect import bisect from collections import defaultdict class Bit: def __init__(self, n, MOD): self.size = n self.tree = [0] * (n + 1) self.depth = n.bit_length() self.mod = MOD def sum(self, i): s = 0 while i > 0: s += self.tree[i] ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 2\n2 3\n1 4\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '3 4\n2 5 10\n1 3 7 13\n', 'output': '8\n'}, {'type': 'stdin_stdout', 'input': '4 1\n1 2 4 5\n3\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '4 5\n2 5 7 11\n1 3 6 9 13\n', 'output': '6\n'}...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc101/tasks/arc101_d'}
vfc_6518
```python from bisect import bisect from collections import defaultdict class Bit: def __init__(self, n, MOD): self.size = n self.tree = [0] * (n + 1) self.depth = n.bit_length() self.mod = MOD def sum(self, i): s = 0 while i > 0: s += self.tree[i] ...
2 2 2 3 1 4
3
3
true
1,431
apps
verifiable_code
2244
Solve the following coding problem using the programming language python: AtCoDeer the deer found N rectangle lying on the table, each with height 1. If we consider the surface of the desk as a two-dimensional plane, the i-th rectangle i(1≤i≤N) covers the vertical range of [i-1,i] and the horizontal range of [l_i,r_i]...
```python # seishin.py N = int(input()) P = [list(map(int, input().split())) for i in range(N)] from heapq import heappush, heappop l0, r0 = P[0] L = [-l0+1] R = [l0-1] s = t = 0 res = 0 for i in range(N-1): l0, r0 = P[i] l1, r1 = P[i+1] s += (r1 - l1); t += (r0 - l0) if -s-L[0] <= l1-1 <= t+R[0]: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 3\n5 7\n1 3\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3\n2 5\n4 6\n1 4\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '5\n999999999 1000000000\n1 2\n314 315\n500000 500001\n999999999 1000000000\n', 'output': '1999999680\n'}, {'type': 'stdin...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc070/tasks/arc070_c'}
vfc_6522
```python # seishin.py N = int(input()) P = [list(map(int, input().split())) for i in range(N)] from heapq import heappush, heappop l0, r0 = P[0] L = [-l0+1] R = [l0-1] s = t = 0 res = 0 for i in range(N-1): l0, r0 = P[i] l1, r1 = P[i+1] s += (r1 - l1); t += (r0 - l0) if -s-L[0] <= l1-1 <= t+R[0]: ...
3 1 3 5 7 1 3
2
2
true
1,432
apps
verifiable_code
2245
Solve the following coding problem using the programming language python: Greg has an array a = a_1, a_2, ..., a_{n} and m operations. Each operation looks as: l_{i}, r_{i}, d_{i}, (1 ≤ l_{i} ≤ r_{i} ≤ n). To apply operation i to the array means to increase all array elements with numbers l_{i}, l_{i} + 1, ..., r_{i} ...
```python from sys import stdin, stdout rd = lambda: list(map(int, stdin.readline().split())) n, m, k = rd() a = rd() b = [rd() for _ in range(m)] x = [0]*(m+1) y = [0]*(n+1) for _ in range(k): l, r = rd() x[l-1] += 1 x[r ] -= 1 s = 0 for i in range(m): l, r, d = b[i] s += x[i] y[l-1] += s*d y[r ] -...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3 3\n1 2 3\n1 2 1\n1 3 2\n2 3 4\n1 2\n1 3\n2 3\n', 'output': '9 18 17\n'}, {'type': 'stdin_stdout', 'input': '1 1 1\n1\n1 1 1\n1 1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '4 3 6\n1 2 3 4\n1 2 1\n2 3 2\n3 4 4\n1 2\n1 3\n2 3\n1 2\n1 3\n2 3\n', 'output':...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/295/A'}
vfc_6526
```python from sys import stdin, stdout rd = lambda: list(map(int, stdin.readline().split())) n, m, k = rd() a = rd() b = [rd() for _ in range(m)] x = [0]*(m+1) y = [0]*(n+1) for _ in range(k): l, r = rd() x[l-1] += 1 x[r ] -= 1 s = 0 for i in range(m): l, r, d = b[i] s += x[i] y[l-1] += s*d y[r ] -...
3 3 3 1 2 3 1 2 1 1 3 2 2 3 4 1 2 1 3 2 3
9 18 17
9 18 17
true
1,433
apps
verifiable_code
2246
Solve the following coding problem using the programming language python: Alan decided to get in shape for the summer, so he created a precise workout plan to follow. His plan is to go to a different gym every day during the next N days and lift $X[i]$ grams on day $i$. In order to improve his workout performance at t...
```python from sys import stdin from heapq import heappop,heappush def main(): n,k = map(int,stdin.readline().split()) X = list(map(int,stdin.readline().split())) A = int(stdin.readline().strip()) C = list(map(int,stdin.readline().split())) l = list() i = 0;g = k;ans = 0;flag = True while i < n and flag: heap...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 10000\n10000 30000 30000 40000 20000\n20000\n5 2 8 3 6\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '5 10000\n10000 40000 30000 30000 20000\n10000\n5 2 8 3 6\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '5 49\n22 23 11 17 49\n50\n102 55 77 34 9...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1218/F'}
vfc_6530
```python from sys import stdin from heapq import heappop,heappush def main(): n,k = map(int,stdin.readline().split()) X = list(map(int,stdin.readline().split())) A = int(stdin.readline().strip()) C = list(map(int,stdin.readline().split())) l = list() i = 0;g = k;ans = 0;flag = True while i < n and flag: heap...
5 10000 10000 30000 30000 40000 20000 20000 5 2 8 3 6
5
5
true
1,434
apps
verifiable_code
2248
Solve the following coding problem using the programming language python: Oleg's favorite subjects are History and Math, and his favorite branch of mathematics is division. To improve his division skills, Oleg came up with $t$ pairs of integers $p_i$ and $q_i$ and for each pair decided to find the greatest integer $x...
```python mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline def PrimeDecomposition(N): ret = {} n = int(N ** 0.5) for d in range(2, n + 1): while N % d == 0: if d not in ret: ret[d] = 1 e...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n10 4\n12 6\n179 822\n', 'output': '10\n4\n179\n'}, {'type': 'stdin_stdout', 'input': '10\n246857872446986130 713202678\n857754240051582063 933416507\n873935277189052612 530795521\n557307185726829409 746530097\n173788420792057536 769449696\n101626841876448103 1323457...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1444/A'}
vfc_6538
```python mod = 1000000007 eps = 10**-9 def main(): import sys input = sys.stdin.readline def PrimeDecomposition(N): ret = {} n = int(N ** 0.5) for d in range(2, n + 1): while N % d == 0: if d not in ret: ret[d] = 1 e...
3 10 4 12 6 179 822
10 4 179
10 4 179
true
1,436
apps
verifiable_code
2249
Solve the following coding problem using the programming language python: Wabbit is trying to move a box containing food for the rest of the zoo in the coordinate plane from the point $(x_1,y_1)$ to the point $(x_2,y_2)$. He has a rope, which he can use to pull the box. He can only pull the box if he stands exactly $...
```python for __ in range(int(input())): a, b, c, d = list(map(int, input().split())) if a == c or b == d: print(abs(a - c) + abs(b - d)) else: print(abs(a - c) + abs(b - d) + 2) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1 2 2 2\n1 1 2 2\n', 'output': '1\n4\n'}, {'type': 'stdin_stdout', 'input': '1\n69 69 69 69\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '5\n1 1 1000000000 1000000000\n1 1 1000000000 1000000000\n1 1 1000000000 1000000000\n1 1 1000000000 1000000000\n1 1 65...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1428/A'}
vfc_6542
```python for __ in range(int(input())): a, b, c, d = list(map(int, input().split())) if a == c or b == d: print(abs(a - c) + abs(b - d)) else: print(abs(a - c) + abs(b - d) + 2) ```
2 1 2 2 2 1 1 2 2
1 4
1 4
true
1,437
apps
verifiable_code
2250
Solve the following coding problem using the programming language python: There are k sensors located in the rectangular room of size n × m meters. The i-th sensor is located at point (x_{i}, y_{i}). All sensors are located at distinct points strictly inside the rectangle. Opposite corners of the room are located at...
```python n, m, k = list(map(int,input().split())) dm, dp = {}, {} vis = {} sensors = [] border = set() for el in [(0, m), (n, 0), (0, 0), (n, m)]: border.add(el) for _ in range(k): x, y = list(map(int, input().split())) if not (x - y) in dm: dm[x - y] = [] dm[x - y].append((x, y)) if not (...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3 4\n1 1\n1 2\n2 1\n2 2\n', 'output': '1\n-1\n-1\n2\n'}, {'type': 'stdin_stdout', 'input': '3 4 6\n1 1\n2 1\n1 2\n2 2\n1 3\n2 3\n', 'output': '1\n-1\n-1\n2\n5\n-1\n'}, {'type': 'stdin_stdout', 'input': '7 4 5\n1 3\n2 2\n5 1\n5 3\n4 3\n', 'output': '13\n2\n9\n5\n-1\n'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/724/C'}
vfc_6546
```python n, m, k = list(map(int,input().split())) dm, dp = {}, {} vis = {} sensors = [] border = set() for el in [(0, m), (n, 0), (0, 0), (n, m)]: border.add(el) for _ in range(k): x, y = list(map(int, input().split())) if not (x - y) in dm: dm[x - y] = [] dm[x - y].append((x, y)) if not (...
3 3 4 1 1 1 2 2 1 2 2
1 -1 -1 2
1 -1 -1 2
true
1,438
apps
verifiable_code
2251
Solve the following coding problem using the programming language python: Konrad is a Human Relations consultant working for VoltModder, a large electrical equipment producer. Today, he has been tasked with evaluating the level of happiness in the company. There are $n$ people working for VoltModder, numbered from $1...
```python import sys n, m = list(map(int, sys.stdin.readline().strip().split())) L = [0 for i in range (0, n)] H = [[] for i in range (0, n)] for i in range (0, m): x, y = list(map(int, sys.stdin.readline().strip().split())) x = x - 1 y = y - 1 if x > y: x, y = y, x L[y] = L[y] + 1 H[x]...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 5\n1 2\n2 4\n1 3\n3 4\n2 3\n2\n2\n3\n', 'output': '4\n3\n2\n'}, {'type': 'stdin_stdout', 'input': '3 3\n1 2\n2 3\n1 3\n5\n1\n2\n2\n1\n3\n', 'output': '1\n1\n1\n1\n1\n1\n'}, {'type': 'stdin_stdout', 'input': '1 0\n0\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'inpu...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1229/C'}
vfc_6550
```python import sys n, m = list(map(int, sys.stdin.readline().strip().split())) L = [0 for i in range (0, n)] H = [[] for i in range (0, n)] for i in range (0, m): x, y = list(map(int, sys.stdin.readline().strip().split())) x = x - 1 y = y - 1 if x > y: x, y = y, x L[y] = L[y] + 1 H[x]...
4 5 1 2 2 4 1 3 3 4 2 3 2 2 3
4 3 2
4 3 2
true
1,439
apps
verifiable_code
2252
Solve the following coding problem using the programming language python: After learning a lot about space exploration, a little girl named Ana wants to change the subject. Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whet...
```python #!/usr/bin/env python3 """ Created on Wed Feb 28 11:47:12 2018 @author: mikolajbinkowski """ import sys N = int(input()) string_count = {} for _ in range(N): s = str(input()) char_count = {} for c in s: char_count[c] = char_count.get(c, 0) + 1 s0 = [] for a in 'abcdefghijklmnopq...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\naa\nbb\ncd\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '6\naab\nabcac\ndffe\ned\naa\naade\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '20\niw\nix\nudb\nbg\noi\nuo\njsm\num\ns\nquy\nqo\nbxct\nng\nrmr\nnu\nps\nio\nkh\nw\nk\n', 'output': '5\n'},...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1045/I'}
vfc_6554
```python #!/usr/bin/env python3 """ Created on Wed Feb 28 11:47:12 2018 @author: mikolajbinkowski """ import sys N = int(input()) string_count = {} for _ in range(N): s = str(input()) char_count = {} for c in s: char_count[c] = char_count.get(c, 0) + 1 s0 = [] for a in 'abcdefghijklmnopq...
3 aa bb cd
1
1
true
1,440
apps
verifiable_code
2254
Solve the following coding problem using the programming language python: Thor is getting used to the Earth. As a gift Loki gave him a smartphone. There are n applications on this phone. Thor is fascinated by this phone. He has only one minor issue: he can't count the number of unread notifications generated by those ...
```python #!/usr/bin/env python #-*-coding:utf-8 -*- import sys,collections n,q=list(map(int,input().split())) M=collections.defaultdict(collections.deque) Q=collections.deque() L=[] s=n=m=0 for _ in range(q): y,x=list(map(int,input().split())) if 2>y: s+=1 Q.append(x) M[x].append(n) n+=1 elif 3>y: y=M.get...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 4\n1 3\n1 1\n1 2\n2 3\n', 'output': '1\n2\n3\n2\n'}, {'type': 'stdin_stdout', 'input': '4 6\n1 2\n1 4\n1 2\n3 3\n1 3\n1 3\n', 'output': '1\n2\n3\n0\n1\n2\n'}, {'type': 'stdin_stdout', 'input': '10 85\n2 2\n1 10\n1 1\n2 6\n1 2\n1 4\n1 7\n2 1\n1 1\n3 3\n1 9\n1 6\n1 8\n...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/704/A'}
vfc_6562
```python #!/usr/bin/env python #-*-coding:utf-8 -*- import sys,collections n,q=list(map(int,input().split())) M=collections.defaultdict(collections.deque) Q=collections.deque() L=[] s=n=m=0 for _ in range(q): y,x=list(map(int,input().split())) if 2>y: s+=1 Q.append(x) M[x].append(n) n+=1 elif 3>y: y=M.get...
3 4 1 3 1 1 1 2 2 3
1 2 3 2
1 2 3 2
true
1,442
apps
verifiable_code
2255
Solve the following coding problem using the programming language python: Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve uns...
```python ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) from collections import Counter as C n = ii() a = li() oe = [C(), C()] oe[1][0] = 1 x = 0 ans = 0 for i in range(n): x ^= a[i] ans += oe[i % 2][x] oe[i % 2][x] += 1 print(ans) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n1 2 3 4 5\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '6\n3 2 2 3 7 6\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '3\n42 4 2\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '2\n60202 951227\n', 'output': '0\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1109/A'}
vfc_6566
```python ii = lambda: int(input()) mi = lambda: map(int, input().split()) li = lambda: list(mi()) from collections import Counter as C n = ii() a = li() oe = [C(), C()] oe[1][0] = 1 x = 0 ans = 0 for i in range(n): x ^= a[i] ans += oe[i % 2][x] oe[i % 2][x] += 1 print(ans) ```
5 1 2 3 4 5
1
1
true
1,443
apps
verifiable_code
2257
Solve the following coding problem using the programming language python: Note that the only difference between String Transformation 1 and String Transformation 2 is in the move Koa does. In this version the letter $y$ Koa selects must be strictly greater alphabetically than $x$ (read statement for better understandi...
```python import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N = int(input()) A = [ord(a) - 97 for a in input()] B = [ord(a) - 97 for a in input()] X = [[0] * 20 for _ in range(20)] for a, b in zip(A, B): X[a][b] = 1 if a > b: pri...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n3\naab\nbcc\n4\ncabc\nabcb\n3\nabc\ntsr\n4\naabd\ncccd\n5\nabcbd\nbcdda\n', 'output': '2\n-1\n3\n2\n-1\n'}, {'type': 'stdin_stdout', 'input': '10\n1\na\nb\n1\nb\na\n3\nabc\ndef\n1\nt\nt\n2\nrt\ntr\n2\nrt\ntt\n2\nrt\nrr\n3\nasd\nqrt\n1\ns\nt\n1\nr\nt\n', 'output': '1...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1383/A'}
vfc_6574
```python import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N = int(input()) A = [ord(a) - 97 for a in input()] B = [ord(a) - 97 for a in input()] X = [[0] * 20 for _ in range(20)] for a, b in zip(A, B): X[a][b] = 1 if a > b: pri...
5 3 aab bcc 4 cabc abcb 3 abc tsr 4 aabd cccd 5 abcbd bcdda
2 -1 3 2 -1
2 -1 3 2 -1
true
1,445
apps
verifiable_code
2259
Solve the following coding problem using the programming language python: Let $a_1, \ldots, a_n$ be an array of $n$ positive integers. In one operation, you can choose an index $i$ such that $a_i = i$, and remove $a_i$ from the array (after the removal, the remaining parts are concatenated). The weight of $a$ is defi...
```python from sys import stdin def bitadd(a,w,bit): x = a while x <= (len(bit)-1): bit[x] += w x += x & (-1 * x) def bitsum(a,bit): ret = 0 x = a while x > 0: ret += bit[x] x -= x & (-1 * x) return ret class RangeBIT: def __init__(self,N,indexed): ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '13 5\n2 2 3 9 5 4 6 5 7 8 3 11 13\n3 1\n0 0\n2 4\n5 0\n0 12\n', 'output': '5\n11\n6\n1\n0\n'}, {'type': 'stdin_stdout', 'input': '5 2\n1 4 1 2 4\n0 0\n1 0\n', 'output': '2\n0\n'}, {'type': 'stdin_stdout', 'input': '1 1\n1\n0 0\n', 'output': '1\n'}, {'type': 'stdin_stdo...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1404/C'}
vfc_6582
```python from sys import stdin def bitadd(a,w,bit): x = a while x <= (len(bit)-1): bit[x] += w x += x & (-1 * x) def bitsum(a,bit): ret = 0 x = a while x > 0: ret += bit[x] x -= x & (-1 * x) return ret class RangeBIT: def __init__(self,N,indexed): ...
13 5 2 2 3 9 5 4 6 5 7 8 3 11 13 3 1 0 0 2 4 5 0 0 12
5 11 6 1 0
5 11 6 1 0
true
1,446
apps
verifiable_code
2261
Solve the following coding problem using the programming language python: A festival will be held in a town's main street. There are n sections in the main street. The sections are numbered 1 through n from left to right. The distance between each adjacent sections is 1. In the festival m fireworks will be launched. ...
```python from collections import deque def rollingmax(x, y, r, a): k = 2 * r + 1 d = deque() lx = len(x) for i in range(lx + r): if i < lx: while d and d[-1][1] <= x[i]: d.pop() d.append((i, x[i])) while d and d[0][0] <= i - k: d.popl...
{'test_cases': [{'type': 'stdin_stdout', 'input': '50 3 1\n49 1 1\n26 1 4\n6 1 10\n', 'output': '-31\n'}, {'type': 'stdin_stdout', 'input': '10 2 1\n1 1000 4\n9 1000 4\n', 'output': '1992\n'}, {'type': 'stdin_stdout', 'input': '30 8 2\n15 97 3\n18 64 10\n20 14 20\n16 18 36\n10 23 45\n12 60 53\n17 93 71\n11 49 85\n', 'o...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/372/C'}
vfc_6590
```python from collections import deque def rollingmax(x, y, r, a): k = 2 * r + 1 d = deque() lx = len(x) for i in range(lx + r): if i < lx: while d and d[-1][1] <= x[i]: d.pop() d.append((i, x[i])) while d and d[0][0] <= i - k: d.popl...
50 3 1 49 1 1 26 1 4 6 1 10
-31
-31
true
1,448
apps
verifiable_code
2262
Solve the following coding problem using the programming language python: Snuke is playing a puzzle game. In this game, you are given a rectangular board of dimensions R × C, filled with numbers. Each integer i from 1 through N is written twice, at the coordinates (x_{i,1},y_{i,1}) and (x_{i,2},y_{i,2}). The objective...
```python import sys input = sys.stdin.readline def main(): R, C, N = map(int, input().split()) xyxy = [list(map(int, input().split())) for i in range(N)] r = [] for i in range(N): x1, y1, x2, y2 = xyxy[i] # どちらも周上にある場合は周上の座標に変換してから記録 if ((x1 == 0 or x1 == R) or (y1 == 0 or y1...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 2 3\n0 1 3 1\n1 1 4 1\n2 0 2 2\n', 'output': 'YES\n'}, {'type': 'stdin_stdout', 'input': '2 2 4\n0 0 2 2\n2 0 0 1\n0 2 1 2\n1 1 2 1\n', 'output': 'NO\n'}, {'type': 'stdin_stdout', 'input': '5 5 7\n0 0 2 4\n2 3 4 5\n3 5 5 2\n5 5 5 4\n0 3 5 1\n2 2 4 4\n0 5 4 1\n', 'out...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc076/tasks/arc076_c'}
vfc_6594
```python import sys input = sys.stdin.readline def main(): R, C, N = map(int, input().split()) xyxy = [list(map(int, input().split())) for i in range(N)] r = [] for i in range(N): x1, y1, x2, y2 = xyxy[i] # どちらも周上にある場合は周上の座標に変換してから記録 if ((x1 == 0 or x1 == R) or (y1 == 0 or y1...
4 2 3 0 1 3 1 1 1 4 1 2 0 2 2
YES
YES
true
1,449
apps
verifiable_code
2263
Solve the following coding problem using the programming language python: You are given a string S consisting of a,b and c. Find the number of strings that can be possibly obtained by repeatedly performing the following operation zero or more times, modulo 998244353: - Choose an integer i such that 1\leq i\leq |S|-1 ...
```python #!/usr/bin/env python3 M = 998244353 def powmod(a, x, m = M): y = 1 while 0 < x: if x % 2 == 1: y *= a y %= m x //= 2 a = a ** 2 a %= m return y def solve(s): n = len(s) nb = nc = 0 ch = s[0] if ch == 'b': nb +=...
{'test_cases': [{'type': 'stdin_stdout', 'input': 'abc\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': 'abbac\n', 'output': '65\n'}, {'type': 'stdin_stdout', 'input': 'babacabac\n', 'output': '6310\n'}, {'type': 'stdin_stdout', 'input': 'ababacbcacbacacbcbbcbbacbaccacbacbacba\n', 'output': '148010497\n'}], 'lan...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc094/tasks/arc094_d'}
vfc_6598
```python #!/usr/bin/env python3 M = 998244353 def powmod(a, x, m = M): y = 1 while 0 < x: if x % 2 == 1: y *= a y %= m x //= 2 a = a ** 2 a %= m return y def solve(s): n = len(s) nb = nc = 0 ch = s[0] if ch == 'b': nb +=...
abc
3
3
true
1,450
apps
verifiable_code
2264
Solve the following coding problem using the programming language python: We have a graph with N vertices and M edges, and there are two people on the graph: Takahashi and Aoki. The i-th edge connects Vertex U_i and Vertex V_i. The time it takes to traverse this edge is D_i minutes, regardless of direction and who tra...
```python # ARC090E def hoge(): M = 10**9 + 7 import sys input = lambda : sys.stdin.readline().rstrip() n, m = map(int, input().split()) s, t = map(int, input().split()) s -= 1 t -= 1 from collections import defaultdict ns = defaultdict(set) for i in range(m): u, v, d =...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 4\n1 3\n1 2 1\n2 3 1\n3 4 1\n4 1 1\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3 3\n1 3\n1 2 1\n2 3 1\n3 1 2\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3 3\n1 3\n1 2 1\n2 3 1\n3 1 2\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '8...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc090/tasks/arc090_c'}
vfc_6602
```python # ARC090E def hoge(): M = 10**9 + 7 import sys input = lambda : sys.stdin.readline().rstrip() n, m = map(int, input().split()) s, t = map(int, input().split()) s -= 1 t -= 1 from collections import defaultdict ns = defaultdict(set) for i in range(m): u, v, d =...
4 4 1 3 1 2 1 2 3 1 3 4 1 4 1 1
2
2
true
1,451
apps
verifiable_code
2265
Solve the following coding problem using the programming language python: You are given a permutation of 1,2,...,N: p_1,p_2,...,p_N. Determine if the state where p_i=i for every i can be reached by performing the following operation any number of times: - Choose three elements p_{i-1},p_{i},p_{i+1} (2\leq i\leq N-1) ...
```python import sys def solve(ppp): section_start = -1 moved_left_max = 0 moved_right_max = 0 prev = True for i, p in enumerate(ppp, start=1): if i == p: if prev: moved_left_max = 0 moved_right_max = 0 section_start = -1 ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n5\n2\n1\n4\n3\n', 'output': 'Yes\n'}, {'type': 'stdin_stdout', 'input': '4\n3\n2\n4\n1\n', 'output': 'No\n'}, {'type': 'stdin_stdout', 'input': '7\n3\n2\n1\n6\n5\n4\n7\n', 'output': 'Yes\n'}, {'type': 'stdin_stdout', 'input': '6\n5\n3\n4\n1\n2\n6\n', 'output': 'No\n...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc102/tasks/arc102_d'}
vfc_6606
```python import sys def solve(ppp): section_start = -1 moved_left_max = 0 moved_right_max = 0 prev = True for i, p in enumerate(ppp, start=1): if i == p: if prev: moved_left_max = 0 moved_right_max = 0 section_start = -1 ...
5 5 2 1 4 3
Yes
Yes
true
1,452
apps
verifiable_code
2266
Solve the following coding problem using the programming language python: There are M chairs arranged in a line. The coordinate of the i-th chair (1 ≤ i ≤ M) is i. N people of the Takahashi clan played too much games, and they are all suffering from backaches. They need to sit in chairs and rest, but they are particul...
```python import sys input=sys.stdin.readline N,M=list(map(int,input().split())) # N: 処理する区間の長さ INF = 2**31-1 LV = (M+2-1).bit_length() N0 = 2**LV data = [0]*(2*N0) lazy = [0]*(2*N0) def gindex(l, r): L = (l + N0) >> 1; R = (r + N0) >> 1 lc = 0 if l & 1 else (L & -L).bit_length() rc = 0 if r & 1 else (...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 4\n0 3\n2 3\n1 3\n3 4\n', 'output': '0\n'}, {'type': 'stdin_stdout', 'input': '7 6\n0 7\n1 5\n3 6\n2 7\n1 6\n2 6\n3 7\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3 1\n1 2\n1 2\n1 2\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '6 6\n1 6\n1 6\n1...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc076/tasks/arc076_d'}
vfc_6610
```python import sys input=sys.stdin.readline N,M=list(map(int,input().split())) # N: 処理する区間の長さ INF = 2**31-1 LV = (M+2-1).bit_length() N0 = 2**LV data = [0]*(2*N0) lazy = [0]*(2*N0) def gindex(l, r): L = (l + N0) >> 1; R = (r + N0) >> 1 lc = 0 if l & 1 else (L & -L).bit_length() rc = 0 if r & 1 else (...
4 4 0 3 2 3 1 3 3 4
0
0
true
1,453
apps
verifiable_code
2270
Solve the following coding problem using the programming language python: Haiku is a short form of Japanese poetry. A Haiku consists of three phrases with 5, 7 and 5 syllables, in this order. Iroha is looking for X,Y,Z-Haiku (defined below) in integer sequences. Consider all integer sequences of length N whose element...
```python # coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline n,X,Y,Z = list(map(int,read().split())) N = 1<<(X+Y+Z) NX = 1<<X NY = 1<<(X+Y) NZ = 1<<(X+Y+Z) MX = (1<<X) - 1 MY = (1<<(Y+X)) - (1<<X) MZ = (1<<(X+Y+Z)) - (1<<(Y+X)) MMX = MX<<1 MMY = MY<<1 MMZ = MZ<<1 dp = ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 5 7 5\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '4 5 7 5\n', 'output': '34\n'}, {'type': 'stdin_stdout', 'input': '37 4 2 3\n', 'output': '863912418\n'}, {'type': 'stdin_stdout', 'input': '40 5 7 5\n', 'output': '562805100\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc058/tasks/arc058_c'}
vfc_6626
```python # coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline n,X,Y,Z = list(map(int,read().split())) N = 1<<(X+Y+Z) NX = 1<<X NY = 1<<(X+Y) NZ = 1<<(X+Y+Z) MX = (1<<X) - 1 MY = (1<<(Y+X)) - (1<<X) MZ = (1<<(X+Y+Z)) - (1<<(Y+X)) MMX = MX<<1 MMY = MY<<1 MMZ = MZ<<1 dp = ...
3 5 7 5
1
1
true
1,454
apps
verifiable_code
2271
Solve the following coding problem using the programming language python: We have a permutation of the integers from 1 through N, p_1, p_2, .., p_N. We also have M pairs of two integers between 1 and N (inclusive), represented as (x_1,y_1), (x_2,y_2), .., (x_M,y_M). AtCoDeer the deer is going to perform the following ...
```python import sys readline = sys.stdin.readline class UnionFind(object): def __init__(self, n): self._par = list(range(n)) self.size = [1]*n def root(self, v): if self._par[v] == v: return v self._par[v] = self.root(self._par[v]) return self._par[v] ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 2\n5 3 1 4 2\n1 3\n5 4\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3 2\n3 2 1\n1 2\n2 3\n', 'output': '3\n'}, {'type': 'stdin_stdout', 'input': '10 8\n5 3 6 8 7 10 9 1 2 4\n3 1\n4 1\n5 9\n2 5\n6 5\n3 5\n8 9\n7 9\n', 'output': '8\n'}, {'type': 'stdin_stdo...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc097/tasks/arc097_b'}
vfc_6630
```python import sys readline = sys.stdin.readline class UnionFind(object): def __init__(self, n): self._par = list(range(n)) self.size = [1]*n def root(self, v): if self._par[v] == v: return v self._par[v] = self.root(self._par[v]) return self._par[v] ...
5 2 5 3 1 4 2 1 3 5 4
2
2
true
1,455
apps
verifiable_code
2272
Solve the following coding problem using the programming language python: You are given two integer sequences, each of length N: a_1, ..., a_N and b_1, ..., b_N. There are N^2 ways to choose two integers i and j such that 1 \leq i, j \leq N. For each of these N^2 pairs, we will compute a_i + b_j and write it on a shee...
```python #!/usr/bin/env python3 def main(): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 for k in range(30): C = [x & ((1 << (k+1)) - 1) for x in A] D = [x & ((1 << (k+1)) - 1) for x in B] C.sort() D.sort() ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1 2\n3 4\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '6\n4 6 0 0 3 3\n0 5 6 5 0 3\n', 'output': '8\n'}, {'type': 'stdin_stdout', 'input': '5\n1 2 3 4 5\n1 2 3 4 5\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '1\n0\n0\n', 'output': '0\n'}], 'la...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc092/tasks/arc092_b'}
vfc_6634
```python #!/usr/bin/env python3 def main(): N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) ans = 0 for k in range(30): C = [x & ((1 << (k+1)) - 1) for x in A] D = [x & ((1 << (k+1)) - 1) for x in B] C.sort() D.sort() ...
2 1 2 3 4
2
2
true
1,456
apps
verifiable_code
2273
Solve the following coding problem using the programming language python: Hilbert's Hotel is a very unusual hotel since the number of rooms is infinite! In fact, there is exactly one room for every integer, including zero and negative integers. Even stranger, the hotel is currently at full capacity, meaning there is e...
```python t = int(input()) for _ in range(t): n = int(input()) l = [int(x) for x in input().split()] vals = [(x + i) % n for i, x in enumerate(l)] print("YES" if len(set(vals)) == n else "NO") ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '6\n1\n14\n2\n1 -1\n4\n5 5 5 1\n3\n3 2 1\n2\n0 1\n5\n-239 -2 -100 -3 -11\n', 'output': 'YES\nYES\nYES\nNO\nNO\nYES\n'}, {'type': 'stdin_stdout', 'input': '10\n1\n1000000000\n1\n-1000000000\n2\n1000000000 0\n2\n0 1000000000\n2\n1000000000 1\n2\n1 1000000000\n2\n-10000000...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1344/A'}
vfc_6638
```python t = int(input()) for _ in range(t): n = int(input()) l = [int(x) for x in input().split()] vals = [(x + i) % n for i, x in enumerate(l)] print("YES" if len(set(vals)) == n else "NO") ```
6 1 14 2 1 -1 4 5 5 5 1 3 3 2 1 2 0 1 5 -239 -2 -100 -3 -11
YES YES YES NO NO YES
YES YES YES NO NO YES
true
1,457
apps
verifiable_code
2275
Solve the following coding problem using the programming language python: Johnny has just found the new, great tutorial: "How to become a grandmaster?". The tutorial tells many strange and unexpected for Johnny things, such as you have to be patient or that very important is solving many harder and harder problems. ...
```python import sys input = sys.stdin.readline MOD = 10 ** 9 + 7 t = int(input()) for _ in range(t): n, p = list(map(int, input().split())) l = list(map(int, input().split())) if p == 1: print(n % 2) else: l.sort(reverse = True) curr = l[0] out = 0 real = True ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n5 2\n2 3 4 4 3\n3 1\n2 10 1000\n4 5\n0 1 1 100\n1 8\n89\n', 'output': '4\n1\n146981438\n747093407\n'}, {'type': 'stdin_stdout', 'input': '1\n1 2\n88\n', 'output': '140130951\n'}, {'type': 'stdin_stdout', 'input': '1\n20 22328\n2572 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1361/B'}
vfc_6646
```python import sys input = sys.stdin.readline MOD = 10 ** 9 + 7 t = int(input()) for _ in range(t): n, p = list(map(int, input().split())) l = list(map(int, input().split())) if p == 1: print(n % 2) else: l.sort(reverse = True) curr = l[0] out = 0 real = True ...
4 5 2 2 3 4 4 3 3 1 2 10 1000 4 5 0 1 1 100 1 8 89
4 1 146981438 747093407
4 1 146981438 747093407
true
1,459
apps
verifiable_code
2277
Solve the following coding problem using the programming language python: Recently Lynyrd and Skynyrd went to a shop where Lynyrd bought a permutation $p$ of length $n$, and Skynyrd bought an array $a$ of length $m$, consisting of integers from $1$ to $n$. Lynyrd and Skynyrd became bored, so they asked you $q$ queri...
```python import sys inp = [int(x) for x in sys.stdin.read().split()] n, m, q = inp[0], inp[1], inp[2] p = [inp[idx] for idx in range(3, n + 3)] index_arr = [0] * (n + 1) for i in range(n): index_arr[p[i]] = i a = [inp[idx] for idx in range(n + 3, n + 3 + m)] leftmost_pos = [m] * (n + 1) next = [-1] * m for ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 6 3\n2 1 3\n1 2 3 1 2 3\n1 5\n2 6\n3 5\n', 'output': '110\n'}, {'type': 'stdin_stdout', 'input': '2 4 3\n2 1\n1 1 2 2\n1 2\n2 3\n3 4\n', 'output': '010\n'}, {'type': 'stdin_stdout', 'input': '1 1 1\n1\n1\n1 1\n', 'output': '1\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1142/B'}
vfc_6654
```python import sys inp = [int(x) for x in sys.stdin.read().split()] n, m, q = inp[0], inp[1], inp[2] p = [inp[idx] for idx in range(3, n + 3)] index_arr = [0] * (n + 1) for i in range(n): index_arr[p[i]] = i a = [inp[idx] for idx in range(n + 3, n + 3 + m)] leftmost_pos = [m] * (n + 1) next = [-1] * m for ...
3 6 3 2 1 3 1 2 3 1 2 3 1 5 2 6 3 5
110
110
true
1,460
apps
verifiable_code
2278
Solve the following coding problem using the programming language python: Recently Vasya learned that, given two points with different $x$ coordinates, you can draw through them exactly one parabola with equation of type $y = x^2 + bx + c$, where $b$ and $c$ are reals. Let's call such a parabola an $U$-shaped one. Va...
```python n = int(input()) rows = [input().split() for _ in range(n)] rows = [(int(x),int(y)) for x,y in rows] points = {} for x,y in rows: if x in points: points[x] = max(y, points[x]) else: points[x] = y points = sorted(points.items(),key=lambda point: point[0]) def above(p,p1,p2): """ ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n-1 0\n0 2\n1 0\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '5\n1 0\n1 -1\n0 -1\n-1 0\n-1 -1\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '1\n-751115 -925948\n', 'output': '0\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1142/C'}
vfc_6658
```python n = int(input()) rows = [input().split() for _ in range(n)] rows = [(int(x),int(y)) for x,y in rows] points = {} for x,y in rows: if x in points: points[x] = max(y, points[x]) else: points[x] = y points = sorted(points.items(),key=lambda point: point[0]) def above(p,p1,p2): """ ...
3 -1 0 0 2 1 0
2
2
true
1,461
apps
verifiable_code
2279
Solve the following coding problem using the programming language python: In number world, two different numbers are friends if they have a lot in common, but also each one has unique perks. More precisely, two different numbers $a$ and $b$ are friends if $gcd(a,b)$, $\frac{a}{gcd(a,b)}$, $\frac{b}{gcd(a,b)}$ can for...
```python import os import sys from io import BytesIO, IOBase def main(): pass # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 5 10\n', 'output': '1\n3\n3\n'}, {'type': 'stdin_stdout', 'input': '6\n12 432 21 199 7 1\n', 'output': '4\n76\n7\n41\n4\n1\n'}, {'type': 'stdin_stdout', 'input': '7\n1 10 100 1000 10000 100000 1000000\n', 'output': '1\n3\n22\n158\n1205\n9528\n78331\n'}, {'type': '...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1423/K'}
vfc_6662
```python import os import sys from io import BytesIO, IOBase def main(): pass # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode...
3 1 5 10
1 3 3
1 3 3
true
1,462
apps
verifiable_code
2280
Solve the following coding problem using the programming language python: Creatnx has $n$ mirrors, numbered from $1$ to $n$. Every day, Creatnx asks exactly one mirror "Am I beautiful?". The $i$-th mirror will tell Creatnx that he is beautiful with probability $\frac{p_i}{100}$ for all $1 \le i \le n$. Some mirrors a...
```python import sys readline = sys.stdin.readline from itertools import accumulate from collections import Counter from bisect import bisect as br, bisect_left as bl class PMS: #1-indexed def __init__(self, A, B, issum = False): #Aに初期状態の要素をすべて入れる,Bは値域のリスト self.X, self.comp = self.compress(B) ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2 2\n50 50\n2\n2\n', 'output': '4\n6\n'}, {'type': 'stdin_stdout', 'input': '5 5\n10 20 30 40 50\n2\n3\n4\n5\n3\n', 'output': '117\n665496274\n332748143\n831870317\n499122211\n'}, {'type': 'stdin_stdout', 'input': '2 2\n38 4\n2\n2\n', 'output': '262695910\n577931032\n'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1264/C'}
vfc_6666
```python import sys readline = sys.stdin.readline from itertools import accumulate from collections import Counter from bisect import bisect as br, bisect_left as bl class PMS: #1-indexed def __init__(self, A, B, issum = False): #Aに初期状態の要素をすべて入れる,Bは値域のリスト self.X, self.comp = self.compress(B) ...
2 2 50 50 2 2
4 6
4 6
true
1,463
apps
verifiable_code
2281
Solve the following coding problem using the programming language python: Iahub likes trees very much. Recently he discovered an interesting tree named propagating tree. The tree consists of n nodes numbered from 1 to n, each node i having an initial value a_{i}. The root of the tree is node 1. This tree has a specia...
```python class BIT(): """区間加算、一点取得クエリをそれぞれO(logN)で応えるデータ構造を構築する add: 区間[begin, end)にvalを加える get_val: i番目(0-indexed)の値を求める """ def __init__(self, n): self.n = n self.bit = [0] * (n + 1) def get_val(self, i): i = i + 1 s = 0 while i <= self.n: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 5\n1 2 1 1 2\n1 2\n1 3\n2 4\n2 5\n1 2 3\n1 1 2\n2 1\n2 2\n2 4\n', 'output': '3\n3\n0\n'}, {'type': 'stdin_stdout', 'input': '10 10\n137 197 856 768 825 894 86 174 218 326\n7 8\n4 7\n8 9\n7 10\n1 2\n2 4\n3 6\n3 5\n2 3\n1 9 624\n2 1\n2 4\n1 6 505\n1 8 467\n1 3 643\n2 1...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/383/C'}
vfc_6670
```python class BIT(): """区間加算、一点取得クエリをそれぞれO(logN)で応えるデータ構造を構築する add: 区間[begin, end)にvalを加える get_val: i番目(0-indexed)の値を求める """ def __init__(self, n): self.n = n self.bit = [0] * (n + 1) def get_val(self, i): i = i + 1 s = 0 while i <= self.n: ...
5 5 1 2 1 1 2 1 2 1 3 2 4 2 5 1 2 3 1 1 2 2 1 2 2 2 4
3 3 0
3 3 0
true
1,464
apps
verifiable_code
2283
Solve the following coding problem using the programming language python: Alice and Bob are playing a fun game of tree tag. The game is played on a tree of $n$ vertices numbered from $1$ to $n$. Recall that a tree on $n$ vertices is an undirected, connected graph with $n-1$ edges. Initially, Alice is located at vert...
```python from sys import stdin from collections import deque def NC_Dij(lis,start): ret = [float("inf")] * len(lis) ret[start] = 0 q = deque([start]) plis = [i for i in range(len(lis))] while len(q) > 0: now = q.popleft() for nex in lis[now]: if ret[nex] > ret[n...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n4 3 2 1 2\n1 2\n1 3\n1 4\n6 6 1 2 5\n1 2\n6 5\n2 3\n3 4\n4 5\n9 3 9 2 5\n1 2\n1 6\n1 9\n1 3\n9 5\n7 9\n4 8\n4 3\n11 8 11 3 3\n1 2\n11 9\n4 9\n6 5\n2 10\n3 2\n5 9\n8 3\n7 4\n7 10\n', 'output': 'Alice\nBob\nAlice\nAlice\n'}, {'type': 'stdin_stdout', 'input': '1\n5 5 4...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1404/B'}
vfc_6678
```python from sys import stdin from collections import deque def NC_Dij(lis,start): ret = [float("inf")] * len(lis) ret[start] = 0 q = deque([start]) plis = [i for i in range(len(lis))] while len(q) > 0: now = q.popleft() for nex in lis[now]: if ret[nex] > ret[n...
4 4 3 2 1 2 1 2 1 3 1 4 6 6 1 2 5 1 2 6 5 2 3 3 4 4 5 9 3 9 2 5 1 2 1 6 1 9 1 3 9 5 7 9 4 8 4 3 11 8 11 3 3 1 2 11 9 4 9 6 5 2 10 3 2 5 9 8 3 7 4 7 10
Alice Bob Alice Alice
Alice Bob Alice Alice
true
1,465
apps
verifiable_code
2284
Solve the following coding problem using the programming language python: Let's call two strings $s$ and $t$ anagrams of each other if it is possible to rearrange symbols in the string $s$ to get a string, equal to $t$. Let's consider two strings $s$ and $t$ which are anagrams of each other. We say that $t$ is a redu...
```python import sys readline = sys.stdin.readline S = list([ord(x)-97 for x in readline().strip()]) N = len(S) table = [[0]*26 for _ in range(N)] for i in range(N): table[i][S[i]] = 1 for i in range(1, N): for j in range(26): table[i][j] += table[i-1][j] Q = int(readline()) Ans = [None]*Q for qu in r...
{'test_cases': [{'type': 'stdin_stdout', 'input': 'aaaaa\n3\n1 1\n2 4\n5 5\n', 'output': 'Yes\nNo\nYes\n'}, {'type': 'stdin_stdout', 'input': 'aabbbbbbc\n6\n1 2\n2 4\n2 2\n1 9\n5 7\n3 5\n', 'output': 'No\nYes\nYes\nYes\nNo\nNo\n'}, {'type': 'stdin_stdout', 'input': 'f\n1\n1 1\n', 'output': 'Yes\n'}], 'language': 'pytho...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1290/B'}
vfc_6682
```python import sys readline = sys.stdin.readline S = list([ord(x)-97 for x in readline().strip()]) N = len(S) table = [[0]*26 for _ in range(N)] for i in range(N): table[i][S[i]] = 1 for i in range(1, N): for j in range(26): table[i][j] += table[i-1][j] Q = int(readline()) Ans = [None]*Q for qu in r...
aaaaa 3 1 1 2 4 5 5
Yes No Yes
Yes No Yes
true
1,466
apps
verifiable_code
2285
Solve the following coding problem using the programming language python: You are given a sequence of $n$ digits $d_1d_2 \dots d_{n}$. You need to paint all the digits in two colors so that: each digit is painted either in the color $1$ or in the color $2$; if you write in a row from left to right all the digits pai...
```python for __ in range(int(input())): n = int(input()) s = list(map(int, input())) r = [0] * n for i in range(10): left_lim = 0 for j, c in enumerate(s): if c < i: left_lim = j + 1 prv = [-1, -1, -1] flg = True for j, c in enumerate(s): ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n12\n040425524644\n1\n0\n9\n123456789\n2\n98\n3\n987\n', 'output': '121212211211\n1\n222222222\n21\n-\n'}, {'type': 'stdin_stdout', 'input': '5\n4\n6148\n1\n7\n5\n49522\n3\n882\n2\n51\n', 'output': '2112\n2\n-\n221\n21\n'}, {'type': 'stdin_stdout', 'input': '5\n1\n3\...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1209/C'}
vfc_6686
```python for __ in range(int(input())): n = int(input()) s = list(map(int, input())) r = [0] * n for i in range(10): left_lim = 0 for j, c in enumerate(s): if c < i: left_lim = j + 1 prv = [-1, -1, -1] flg = True for j, c in enumerate(s): ...
5 12 040425524644 1 0 9 123456789 2 98 3 987
121212211211 1 222222222 21 -
121212211211 1 222222222 21 -
true
1,467
apps
verifiable_code
2286
Solve the following coding problem using the programming language python: In Finite Encyclopedia of Integer Sequences (FEIS), all integer sequences of lengths between 1 and N (inclusive) consisting of integers between 1 and K (inclusive) are listed. Let the total number of sequences listed in FEIS be X. Among those se...
```python k,n = map(int,input().split()) if k %2 ==0: ans = [] ans.append(k//2) for i in range(n-1): ans.append(k) print(*ans) else: ans = [] for i in range(n): ans.append(k//2+1) sage = (n)//2 for i in range(sage): if ans[-1] == 1: ans.pop() else: ans[-1] -= 1 while le...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 2\n', 'output': '2 1 \n'}, {'type': 'stdin_stdout', 'input': '2 4\n', 'output': '1 2 2 2\n'}, {'type': 'stdin_stdout', 'input': '5 14\n', 'output': '3 3 3 3 3 3 3 3 3 3 3 3 2 2 \n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc084/tasks/arc084_c'}
vfc_6690
```python k,n = map(int,input().split()) if k %2 ==0: ans = [] ans.append(k//2) for i in range(n-1): ans.append(k) print(*ans) else: ans = [] for i in range(n): ans.append(k//2+1) sage = (n)//2 for i in range(sage): if ans[-1] == 1: ans.pop() else: ans[-1] -= 1 while le...
3 2
2 1
2 1
true
1,468
apps
verifiable_code
2287
Solve the following coding problem using the programming language python: We have a tree with N vertices. The vertices are numbered 1, 2, ..., N. The i-th (1 ≦ i ≦ N - 1) edge connects the two vertices A_i and B_i. Takahashi wrote integers into K of the vertices. Specifically, for each 1 ≦ j ≦ K, he wrote the integer ...
```python import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque N = int(input()) X = [[] for i in range(N)] for i in range(N-1): x, y = map(int, input().split()) X[x-1].append(y-1) X[y-1].append(x-1) Y = [(-10**9, 10**9) for _ in range(N)] K = int(input()) for _ in range(K...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n1 2\n3 1\n4 3\n3 5\n2\n2 6\n5 7\n', 'output': 'Yes\n5\n6\n6\n5\n7\n'}, {'type': 'stdin_stdout', 'input': '5\n1 2\n3 1\n4 3\n3 5\n3\n2 6\n4 3\n5 7\n', 'output': 'No\n'}, {'type': 'stdin_stdout', 'input': '4\n1 2\n2 3\n3 4\n1\n1 0\n', 'output': 'Yes\n0\n-1\n-2\n-3\n'}...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc063/tasks/arc063_c'}
vfc_6694
```python import sys input = lambda: sys.stdin.readline().rstrip() from collections import deque N = int(input()) X = [[] for i in range(N)] for i in range(N-1): x, y = map(int, input().split()) X[x-1].append(y-1) X[y-1].append(x-1) Y = [(-10**9, 10**9) for _ in range(N)] K = int(input()) for _ in range(K...
5 1 2 3 1 4 3 3 5 2 2 6 5 7
Yes 5 6 6 5 7
Yes 5 6 6 5 7
true
1,469
apps
verifiable_code
2288
Solve the following coding problem using the programming language python: We have a sandglass consisting of two bulbs, bulb A and bulb B. These bulbs contain some amount of sand. When we put the sandglass, either bulb A or B lies on top of the other and becomes the upper bulb. The other bulb becomes the lower bulb. Th...
```python import bisect def inpl(): return [int(i) for i in input().split()] X = int(input()) K = int(input()) r = [0] + inpl() stu = [()]*(K+1) stu[0] = (X, 0, 0) for i, v in enumerate(r[1:], 1): s, t, u = stu[i-1] if i%2: rs = r[i-1] - r[i] ap = - rs - t if ap >= s: stu[i]...
{'test_cases': [{'type': 'stdin_stdout', 'input': '180\n3\n60 120 180\n3\n30 90\n61 1\n180 180\n', 'output': '60\n1\n120\n'}, {'type': 'stdin_stdout', 'input': '100\n1\n100000\n4\n0 100\n90 100\n100 100\n101 100\n', 'output': '100\n10\n0\n0\n'}, {'type': 'stdin_stdout', 'input': '100\n5\n48 141 231 314 425\n7\n0 19\n50...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc082/tasks/arc082_d'}
vfc_6698
```python import bisect def inpl(): return [int(i) for i in input().split()] X = int(input()) K = int(input()) r = [0] + inpl() stu = [()]*(K+1) stu[0] = (X, 0, 0) for i, v in enumerate(r[1:], 1): s, t, u = stu[i-1] if i%2: rs = r[i-1] - r[i] ap = - rs - t if ap >= s: stu[i]...
180 3 60 120 180 3 30 90 61 1 180 180
60 1 120
60 1 120
true
1,470
apps
verifiable_code
2289
Solve the following coding problem using the programming language python: A subsequence of a string S is a string that can be obtained by deleting zero or more characters from S without changing the order of the remaining characters. For example, arc, artistic and (an empty string) are all subsequences of artistic; ab...
```python A = [ord(a)-97 for a in input()] N = len(A) X = [0] * 26 Y = [0] * (N + 2) NE = [0] * N R = [N] * 26 s = 0 t = 1 for i in range(N)[::-1]: a = A[i] if X[a] == 0: X[a] = 1 s += 1 if s == 26: s = 0 X = [0] * 26 t += 1 Y[i] = t NE[i] = R[...
{'test_cases': [{'type': 'stdin_stdout', 'input': 'atcoderregularcontest\n', 'output': 'b\n'}, {'type': 'stdin_stdout', 'input': 'abcdefghijklmnopqrstuvwxyz\n', 'output': 'aa\n'}, {'type': 'stdin_stdout', 'input': 'frqnvhydscshfcgdemurlfrutcpzhopfotpifgepnqjxupnskapziurswqazdwnwbgdhyktfyhqqxpoidfhjdakoxraiedxskywuepzfn...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc081/tasks/arc081_c'}
vfc_6702
```python A = [ord(a)-97 for a in input()] N = len(A) X = [0] * 26 Y = [0] * (N + 2) NE = [0] * N R = [N] * 26 s = 0 t = 1 for i in range(N)[::-1]: a = A[i] if X[a] == 0: X[a] = 1 s += 1 if s == 26: s = 0 X = [0] * 26 t += 1 Y[i] = t NE[i] = R[...
atcoderregularcontest
b
b
true
1,471
apps
verifiable_code
2290
Solve the following coding problem using the programming language python: We have a board with an H \times W grid. Each square in the grid is painted in black or white. The square at the i-th row from the top and j-th column from the left is black if the j-th character in S_i is #, and white if that character is .. Sn...
```python import sys def input(): return sys.stdin.readline()[:-1] H, W = map(int, input().split()) s = [input() for _ in range(H)] ans = max(H, W) def max_rect(a): res = 0 stack = [a[0]] for i in range(1, W-1): new_pos = i while stack and stack[-1] % 10000 >= a[i]: pos, hght = stack[-1] // 10000, stack[-1...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\n..#\n##.\n.#.\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '4 4\n....\n....\n....\n....\n', 'output': '16\n'}, {'type': 'stdin_stdout', 'input': '10 8\n##...#.#\n##...#.#\n..###.#.\n#.##.#.#\n.#..#.#.\n..##.#.#\n##.#.#..\n...#.#..\n###.#.##\n###..###\n'...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc081/tasks/arc081_d'}
vfc_6706
```python import sys def input(): return sys.stdin.readline()[:-1] H, W = map(int, input().split()) s = [input() for _ in range(H)] ans = max(H, W) def max_rect(a): res = 0 stack = [a[0]] for i in range(1, W-1): new_pos = i while stack and stack[-1] % 10000 >= a[i]: pos, hght = stack[-1] // 10000, stack[-1...
3 3 ..# ##. .#.
6
6
true
1,472
apps
verifiable_code
2292
Solve the following coding problem using the programming language python: Let x be a string of length at least 1. We will call x a good string, if for any string y and any integer k (k \geq 2), the string obtained by concatenating k copies of y is different from x. For example, a, bbc and cdcdc are good strings, while...
```python w=list(input());n=len(w);t=-1 def Z(s): m=len(s);z=[0]*m;c=0;f=[1]*m; for i in range(1,m): if i+z[i-c]<c+z[c]:z[i]=z[i-c] else: j=max(0,c+z[c]-i) while i+j<n and s[j]==s[i+j]:j=j+1 z[i]=j;c=i for p in range(1,m): for k in range(2,z[p]//p+...
{'test_cases': [{'type': 'stdin_stdout', 'input': 'aab\n', 'output': '1\n1\n'}, {'type': 'stdin_stdout', 'input': 'bcbc\n', 'output': '2\n3\n'}, {'type': 'stdin_stdout', 'input': 'ddd\n', 'output': '3\n1\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc060/tasks/arc060_d'}
vfc_6714
```python w=list(input());n=len(w);t=-1 def Z(s): m=len(s);z=[0]*m;c=0;f=[1]*m; for i in range(1,m): if i+z[i-c]<c+z[c]:z[i]=z[i-c] else: j=max(0,c+z[c]-i) while i+j<n and s[j]==s[i+j]:j=j+1 z[i]=j;c=i for p in range(1,m): for k in range(2,z[p]//p+...
aab
1 1
1 1
true
1,474
apps
verifiable_code
2293
Solve the following coding problem using the programming language python: There is an integer sequence of length 2^N: A_0, A_1, ..., A_{2^N-1}. (Note that the sequence is 0-indexed.) For every integer K satisfying 1 \leq K \leq 2^N-1, solve the following problem: - Let i and j be integers. Find the maximum value of A...
```python j=n=1<<int(input()) a=[[0,int(s)]for s in input().split()] while j>1:j>>=1;a=[sorted(a[i]+a[i^j]*(i&j>0))[-2:]for i in range(n)] for s,f in a[1:]:j=max(j,s+f);print(j) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1 2 3 1\n', 'output': '3\n4\n5\n'}, {'type': 'stdin_stdout', 'input': '3\n10 71 84 33 6 47 23 25\n', 'output': '81\n94\n155\n155\n155\n155\n155\n'}, {'type': 'stdin_stdout', 'input': '4\n75 26 45 72 81 47 97 97 2 2 25 82 84 17 56 32\n', 'output': '101\n120\n147\n156...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc100/tasks/arc100_c'}
vfc_6718
```python j=n=1<<int(input()) a=[[0,int(s)]for s in input().split()] while j>1:j>>=1;a=[sorted(a[i]+a[i^j]*(i&j>0))[-2:]for i in range(n)] for s,f in a[1:]:j=max(j,s+f);print(j) ```
2 1 2 3 1
3 4 5
3 4 5
true
1,475
apps
verifiable_code
2294
Solve the following coding problem using the programming language python: There are N bags, each containing two white balls. The i-th box contains two balls with integers x_i and y_i written on them, respectively. For each of these bags, you will paint one of the balls red, and paint the other blue. Afterwards, the 2N...
```python import sys def input(): return sys.stdin.readline()[:-1] n = int(input()) d = [] M, m = 0, 10**30 M_of_m, m_of_M = 0, 10**30 for _ in range(n): x, y = map(int, input().split()) g, l = max(x, y), min(x, y) d.append([l, g]) M = max(M, g) m = min(m, l) M_of_m = max(M_of_m, l) m_of_M = min(m_of_M, g) ans...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n1 2\n3 4\n5 6\n', 'output': '15\n'}, {'type': 'stdin_stdout', 'input': '3\n1010 10\n1000 1\n20 1020\n', 'output': '380\n'}, {'type': 'stdin_stdout', 'input': '2\n1 1\n1000000000 1000000000\n', 'output': '999999998000000001\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc073/tasks/arc073_c'}
vfc_6722
```python import sys def input(): return sys.stdin.readline()[:-1] n = int(input()) d = [] M, m = 0, 10**30 M_of_m, m_of_M = 0, 10**30 for _ in range(n): x, y = map(int, input().split()) g, l = max(x, y), min(x, y) d.append([l, g]) M = max(M, g) m = min(m, l) M_of_m = max(M_of_m, l) m_of_M = min(m_of_M, g) ans...
3 1 2 3 4 5 6
15
15
true
1,476
apps
verifiable_code
2295
Solve the following coding problem using the programming language python: You are given sequences A and B consisting of non-negative integers. The lengths of both A and B are N, and the sums of the elements in A and B are equal. The i-th element in A is A_i, and the i-th element in B is B_i. Tozan and Gezan repeats th...
```python #from collections import deque,defaultdict printn = lambda x: print(x,end='') inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 #R = 998244353 def ddprint(...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1 2\n3 2\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '3\n8 3\n0 1\n4 8\n', 'output': '9\n'}, {'type': 'stdin_stdout', 'input': '1\n1 1\n', 'output': '0\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc094/tasks/arc094_c'}
vfc_6726
```python #from collections import deque,defaultdict printn = lambda x: print(x,end='') inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) ins = lambda : input().strip() DBG = True # and False BIG = 10**18 R = 10**9 + 7 #R = 998244353 def ddprint(...
2 1 2 3 2
2
2
true
1,477
apps
verifiable_code
2297
Solve the following coding problem using the programming language python: There is a simple undirected graph with N vertices and M edges. The vertices are numbered 1 through N, and the edges are numbered 1 through M. Edge i connects Vertex U_i and V_i. Also, Vertex i has two predetermined integers A_i and B_i. You wil...
```python class dsu: def __init__(self, n=0): self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: x = self.leader(a) y = self.leader(b) if x == y: return x if self.parent_or_size[x] > self.parent_or_size[y]: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 5\n3 1\n1 2\n4 1\n6 2\n1 2\n2 3\n2 4\n1 4\n3 4\n', 'output': '6\n'}, {'type': 'stdin_stdout', 'input': '5 8\n6 4\n15 13\n15 19\n15 1\n20 7\n1 3\n1 4\n1 5\n2 3\n2 4\n2 5\n3 5\n4 5\n', 'output': '44\n'}, {'type': 'stdin_stdout', 'input': '9 10\n131 2\n98 79\n242 32\n23...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc098/tasks/arc098_d'}
vfc_6734
```python class dsu: def __init__(self, n=0): self._n = n self.parent_or_size = [-1] * n def merge(self, a: int, b: int) -> int: x = self.leader(a) y = self.leader(b) if x == y: return x if self.parent_or_size[x] > self.parent_or_size[y]: ...
4 5 3 1 1 2 4 1 6 2 1 2 2 3 2 4 1 4 3 4
6
6
true
1,478
apps
verifiable_code
2298
Solve the following coding problem using the programming language python: There are N towns located in a line, conveniently numbered 1 through N. Takahashi the merchant is going on a travel from town 1 to town N, buying and selling apples. Takahashi will begin the travel at town 1, with no apple in his possession. The...
```python N,T = list(map(int,input().split())) A = list(map(int,input().split())) cummax = [A[-1]] for a in reversed(A[:-1]): cummax.append(max(cummax[-1], a)) cummax.reverse() maxgain = n = 0 for buy,sell in zip(A,cummax): gain = sell - buy if gain > maxgain: maxgain = gain n = 1 elif...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 2\n100 50 200\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '5 8\n50 30 40 10 20\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '10 100\n7 10 4 5 9 3 6 8 2 1\n', 'output': '2\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc063/tasks/arc063_b'}
vfc_6738
```python N,T = list(map(int,input().split())) A = list(map(int,input().split())) cummax = [A[-1]] for a in reversed(A[:-1]): cummax.append(max(cummax[-1], a)) cummax.reverse() maxgain = n = 0 for buy,sell in zip(A,cummax): gain = sell - buy if gain > maxgain: maxgain = gain n = 1 elif...
3 2 100 50 200
1
1
true
1,479
apps
verifiable_code
2299
Solve the following coding problem using the programming language python: Let N be a positive even number. We have a permutation of (1, 2, ..., N), p = (p_1, p_2, ..., p_N). Snuke is constructing another permutation of (1, 2, ..., N), q, following the procedure below. First, let q be an empty sequence. Then, perform t...
```python import sys input = sys.stdin.readline import numpy as np from heapq import heappush, heappop N = int(input()) A = np.array(input().split(), dtype=np.int32) a_to_i = {a:i for i,a in enumerate(A)} # sparse table を使ってRMQ # parityの同じところだけを見るようにしておく U = len(A).bit_length() sp = [None,A] for i in range(2,U): ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n3 2 4 1\n', 'output': '3 1 2 4\n'}, {'type': 'stdin_stdout', 'input': '2\n1 2\n', 'output': '1 2\n'}, {'type': 'stdin_stdout', 'input': '8\n4 6 3 2 8 5 7 1\n', 'output': '3 1 2 7 4 6 8 5\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc080/tasks/arc080_c'}
vfc_6742
```python import sys input = sys.stdin.readline import numpy as np from heapq import heappush, heappop N = int(input()) A = np.array(input().split(), dtype=np.int32) a_to_i = {a:i for i,a in enumerate(A)} # sparse table を使ってRMQ # parityの同じところだけを見るようにしておく U = len(A).bit_length() sp = [None,A] for i in range(2,U): ...
4 3 2 4 1
3 1 2 4
3 1 2 4
true
1,480
apps
verifiable_code
2300
Solve the following coding problem using the programming language python: Snuke has a rooted tree with N+1 vertices. The vertices are numbered 0 through N, and Vertex 0 is the root of the tree. The parent of Vertex i (1 \leq i \leq N) is Vertex p_i. Besides this tree, Snuke also has an box which is initially empty and...
```python # coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline n, = list(map(int, readline().split())) p = [-1] + [*list(map(int, readline().split()))] MOD = 10**9+7 child = [[] for i in range(n+1)] tot = [None for i in range(n+1)] one = [None for i in range(n+1)] dep = [0]...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n0 0\n', 'output': '8\n'}, {'type': 'stdin_stdout', 'input': '5\n0 1 1 0 4\n', 'output': '96\n'}, {'type': 'stdin_stdout', 'input': '31\n0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23\n', 'output': '730395550\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc086/tasks/arc086_c'}
vfc_6746
```python # coding: utf-8 # Your code here! import sys read = sys.stdin.read readline = sys.stdin.readline n, = list(map(int, readline().split())) p = [-1] + [*list(map(int, readline().split()))] MOD = 10**9+7 child = [[] for i in range(n+1)] tot = [None for i in range(n+1)] one = [None for i in range(n+1)] dep = [0]...
2 0 0
8
8
true
1,481
apps
verifiable_code
2302
Solve the following coding problem using the programming language python: Alice lives on a line. Today, she will travel to some place in a mysterious vehicle. Initially, the distance between Alice and her destination is D. When she input a number x to the vehicle, it will travel in the direction of the destination by ...
```python n, d = list(map(int, input().split())) D = list(map(int, input().split())) A = [0]*(n+1) P = [0]*(n+1) P[0] = pos = d for i, x in enumerate(D): if x <= 2*pos: pos = abs(x-pos) P[i+1] = pos if pos == 0: break for i in range(n-1, -1, -1): if D[i] <= 2*A[i+1]+1: A[i] = A...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 10\n3 4 3 3\n2\n4 3\n', 'output': 'NO\nYES\n'}, {'type': 'stdin_stdout', 'input': '5 9\n4 4 2 3 2\n5\n1 4 2 3 5\n', 'output': 'YES\nYES\nYES\nYES\nYES\n'}, {'type': 'stdin_stdout', 'input': '6 15\n4 3 5 4 2 1\n6\n1 2 3 4 5 6\n', 'output': 'NO\nNO\nYES\nNO\nNO\nYES\n'...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc072/tasks/arc072_c'}
vfc_6754
```python n, d = list(map(int, input().split())) D = list(map(int, input().split())) A = [0]*(n+1) P = [0]*(n+1) P[0] = pos = d for i, x in enumerate(D): if x <= 2*pos: pos = abs(x-pos) P[i+1] = pos if pos == 0: break for i in range(n-1, -1, -1): if D[i] <= 2*A[i+1]+1: A[i] = A...
4 10 3 4 3 3 2 4 3
NO YES
NO YES
true
1,483
apps
verifiable_code
2303
Solve the following coding problem using the programming language python: Snuke's town has a subway system, consisting of N stations and M railway lines. The stations are numbered 1 through N. Each line is operated by a company. Each company has an identification number. The i-th ( 1 \leq i \leq M ) line connects stat...
```python #!/usr/bin/env python3 import sys input = sys.stdin.readline from collections import deque INF = 10**9 n, m = map(int, input().split()) pqc = [] seen = set() for i in range(n): seen.add((i, 0)) for _ in range(m): p, q, c = map(int, input().split()) p -= 1; q -= 1 pqc.append((p, q, c)) se...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\n1 2 1\n2 3 1\n3 1 2\n', 'output': '1\n'}, {'type': 'stdin_stdout', 'input': '8 11\n1 3 1\n1 4 2\n2 3 1\n2 5 1\n3 4 3\n3 6 3\n3 7 3\n4 8 4\n5 6 1\n6 7 5\n7 8 5\n', 'output': '2\n'}, {'type': 'stdin_stdout', 'input': '2 0\n', 'output': '-1\n'}], 'language': 'python'...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc061/tasks/arc061_c'}
vfc_6758
```python #!/usr/bin/env python3 import sys input = sys.stdin.readline from collections import deque INF = 10**9 n, m = map(int, input().split()) pqc = [] seen = set() for i in range(n): seen.add((i, 0)) for _ in range(m): p, q, c = map(int, input().split()) p -= 1; q -= 1 pqc.append((p, q, c)) se...
3 3 1 2 1 2 3 1 3 1 2
1
1
true
1,484
apps
verifiable_code
2304
Solve the following coding problem using the programming language python: Sig has built his own keyboard. Designed for ultimate simplicity, this keyboard only has 3 keys on it: the 0 key, the 1 key and the backspace key. To begin with, he is using a plain text editor with this keyboard. This editor always displays one...
```python N=int(input()) M=len(input()) O=10**9+7 D=[pow(-~O//2,M,O)]+[0]*N for _ in'_'*N:D=[D[0]+D[1]]+[(i+2*j)%O for i,j in zip(D[2:]+[0],D[:-1])] print(D[M]) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n0\n', 'output': '5\n'}, {'type': 'stdin_stdout', 'input': '300\n1100100\n', 'output': '519054663\n'}, {'type': 'stdin_stdout', 'input': '5000\n01000001011101000100001101101111011001000110010101110010000\n', 'output': '500886057\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc059/tasks/arc059_d'}
vfc_6762
```python N=int(input()) M=len(input()) O=10**9+7 D=[pow(-~O//2,M,O)]+[0]*N for _ in'_'*N:D=[D[0]+D[1]]+[(i+2*j)%O for i,j in zip(D[2:]+[0],D[:-1])] print(D[M]) ```
3 0
5
5
true
1,485
apps
verifiable_code
2306
Solve the following coding problem using the programming language python: There are N pinholes on the xy-plane. The i-th pinhole is located at (x_i,y_i). We will denote the Manhattan distance between the i-th and j-th pinholes as d(i,j)(=|x_i-x_j|+|y_i-y_j|). You have a peculiar pair of compasses, called Manhattan Com...
```python N, a, b = list(map(int, input().split())); a -= 1; b -= 1 P = [] Q = [] for i in range(N): x, y = list(map(int, input().split())) P.append((x-y, x+y, i)) Q.append((x+y, x-y, i)) d = max(abs(P[a][0] - P[b][0]), abs(P[a][1] - P[b][1])) *parent, = list(range(N)) def root(x): if x == parent[x]: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 1 2\n1 1\n4 3\n6 1\n5 5\n4 8\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '6 2 3\n1 3\n5 3\n3 5\n8 4\n4 7\n2 5\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '8 1 2\n1 5\n4 3\n8 2\n4 7\n8 8\n3 3\n6 6\n4 8\n', 'output': '7\n'}], 'language': 'python...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc065/tasks/arc065_c'}
vfc_6770
```python N, a, b = list(map(int, input().split())); a -= 1; b -= 1 P = [] Q = [] for i in range(N): x, y = list(map(int, input().split())) P.append((x-y, x+y, i)) Q.append((x+y, x-y, i)) d = max(abs(P[a][0] - P[b][0]), abs(P[a][1] - P[b][1])) *parent, = list(range(N)) def root(x): if x == parent[x]: ...
5 1 2 1 1 4 3 6 1 5 5 4 8
4
4
true
1,486
apps
verifiable_code
2307
Solve the following coding problem using the programming language python: There are N towns on a line running east-west. The towns are numbered 1 through N, in order from west to east. Each point on the line has a one-dimensional coordinate, and a point that is farther east has a greater coordinate value. The coordina...
```python import sys stdin=sys.stdin ip=lambda: int(sp()) fp=lambda: float(sp()) lp=lambda:list(map(int,stdin.readline().split())) sp=lambda:stdin.readline().rstrip() yp=lambda:print('Yes') np=lambda:print('No') n,a,b=lp() x=lp() ans=0 for i in range(n-1): ans+=min(b,a*(x[i+1]-x[i])) print(ans) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '4 2 5\n1 2 5 7\n', 'output': '11\n'}, {'type': 'stdin_stdout', 'input': '7 1 100\n40 43 45 105 108 115 124\n', 'output': '84\n'}, {'type': 'stdin_stdout', 'input': '7 1 2\n24 35 40 68 72 99 103\n', 'output': '12\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc067/tasks/arc067_b'}
vfc_6774
```python import sys stdin=sys.stdin ip=lambda: int(sp()) fp=lambda: float(sp()) lp=lambda:list(map(int,stdin.readline().split())) sp=lambda:stdin.readline().rstrip() yp=lambda:print('Yes') np=lambda:print('No') n,a,b=lp() x=lp() ans=0 for i in range(n-1): ans+=min(b,a*(x[i+1]-x[i])) print(ans) ```
4 2 5 1 2 5 7
11
11
true
1,487
apps
verifiable_code
2308
Solve the following coding problem using the programming language python: You are given $n$ arrays that can have different sizes. You also have a table with $w$ columns and $n$ rows. The $i$-th array is placed horizontally in the $i$-th row. You can slide each array within its row as long as it occupies several consec...
```python import sys input = sys.stdin.readline from collections import deque def slidemax(X, k): q = deque([]) ret = [] for i in range(len(X)): while q and q[-1][1] <= X[i]: q.pop() deque.append(q, (i+k, X[i])) if q[0][0] == i: deque.popleft(q) if i >...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\n3 2 4 8\n2 2 5\n2 6 3\n', 'output': '10 15 16 \n'}, {'type': 'stdin_stdout', 'input': '2 2\n2 7 8\n1 -8\n', 'output': '7 8 \n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1208/E'}
vfc_6778
```python import sys input = sys.stdin.readline from collections import deque def slidemax(X, k): q = deque([]) ret = [] for i in range(len(X)): while q and q[-1][1] <= X[i]: q.pop() deque.append(q, (i+k, X[i])) if q[0][0] == i: deque.popleft(q) if i >...
3 3 3 2 4 8 2 2 5 2 6 3
10 15 16
10 15 16
true
1,488
apps
verifiable_code
2310
Solve the following coding problem using the programming language python: Important: All possible tests are in the pretest, so you shouldn't hack on this problem. So, if you passed pretests, you will also pass the system test. You are an adventurer currently journeying inside an evil temple. After defeating a couple ...
```python r, c = list(map(int, input().split())) if r == 3: print('>vv') print('^<.') print('^.<') print('1 3') elif r == 5: print('>...v') print('v.<..') print('..^..') print('>....') print('..^.<') print('1 1') elif r == 100: for i in range(25): print('>'*50+'.>'*24...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 5\n', 'output': '>...v\nv.<..\n..^..\n>....\n..^.<\n1 1\n'}, {'type': 'stdin_stdout', 'input': '3 2\n', 'output': '>vv\n^<.\n^.<\n1 3\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/329/D'}
vfc_6786
```python r, c = list(map(int, input().split())) if r == 3: print('>vv') print('^<.') print('^.<') print('1 3') elif r == 5: print('>...v') print('v.<..') print('..^..') print('>....') print('..^.<') print('1 1') elif r == 100: for i in range(25): print('>'*50+'.>'*24...
5 5
>...v v.<.. ..^.. >.... ..^.< 1 1
>...v v.<.. ..^.. >.... ..^.< 1 1
true
1,490
apps
verifiable_code
2311
Solve the following coding problem using the programming language python: Let us define two functions f and g on positive integer numbers. $f(n) = \text{product of non-zero digits of} n$ $g(n) = \left\{\begin{array}{ll}{n} & {\text{if} n < 10} \\{g(f(n))} & {\text{otherwise}} \end{array} \right.$ You need to proce...
```python import math import sys input = sys.stdin.readline def main(): MAX_N = int(1e6) + 1 dp = [0 for i in range(MAX_N)] vals = [[] for i in range(10)] for i in range(10): dp[i] = i vals[i].append(i) for i in range(10, MAX_N): prod = 1 for j in str(i): ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n22 73 9\n45 64 6\n47 55 7\n2 62 4\n', 'output': '1\n4\n0\n8\n'}, {'type': 'stdin_stdout', 'input': '4\n82 94 6\n56 67 4\n28 59 9\n39 74 4\n', 'output': '3\n1\n1\n5\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/932/B'}
vfc_6790
```python import math import sys input = sys.stdin.readline def main(): MAX_N = int(1e6) + 1 dp = [0 for i in range(MAX_N)] vals = [[] for i in range(10)] for i in range(10): dp[i] = i vals[i].append(i) for i in range(10, MAX_N): prod = 1 for j in str(i): ...
4 22 73 9 45 64 6 47 55 7 2 62 4
1 4 0 8
1 4 0 8
true
1,491
apps
verifiable_code
2312
Solve the following coding problem using the programming language python: Toad Pimple has an array of integers $a_1, a_2, \ldots, a_n$. We say that $y$ is reachable from $x$ if $x<y$ and there exists an integer array $p$ such that $x = p_1 < p_2 < \ldots < p_k=y$, and $a_{p_i}\, \&\, a_{p_{i+1}} > 0$ for all integers...
```python from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop,heapify import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline from itertools import accumulate from functools import lru_cache M = mod =...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 3\n1 3 0 2 1\n1 3\n2 4\n1 4\n', 'output': 'Fou\nShi\nShi\n'}, {'type': 'stdin_stdout', 'input': '2 1\n300000 300000\n1 2\n', 'output': 'Shi\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1168/C'}
vfc_6794
```python from bisect import bisect_left as bl from bisect import bisect_right as br from heapq import heappush,heappop,heapify import math from collections import * from functools import reduce,cmp_to_key import sys input = sys.stdin.readline from itertools import accumulate from functools import lru_cache M = mod =...
5 3 1 3 0 2 1 1 3 2 4 1 4
Fou Shi Shi
Fou Shi Shi
true
1,492
apps
verifiable_code
2313
Solve the following coding problem using the programming language python: Kalila and Dimna are two jackals living in a huge jungle. One day they decided to join a logging factory in order to make money. The manager of logging factory wants them to go to the jungle and cut n trees with heights a_1, a_2, ..., a_{n}. T...
```python n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [0] * n stk = [0] for i in range(1, n): while len(stk) > 1 and c[stk[1]] - c[stk[0]] <= a[i] * (b[stk[0]] - b[stk[1]]): del stk[0] c[i] = c[stk[0]] + a[i] * b[stk[0]] while len(stk) > 1...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n1 2 3 4 5\n5 4 3 2 0\n', 'output': '25\n'}, {'type': 'stdin_stdout', 'input': '6\n1 2 3 10 20 30\n6 5 4 3 2 0\n', 'output': '138\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/319/C'}
vfc_6798
```python n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = [0] * n stk = [0] for i in range(1, n): while len(stk) > 1 and c[stk[1]] - c[stk[0]] <= a[i] * (b[stk[0]] - b[stk[1]]): del stk[0] c[i] = c[stk[0]] + a[i] * b[stk[0]] while len(stk) > 1...
5 1 2 3 4 5 5 4 3 2 0
25
25
true
1,493
apps
verifiable_code
2314
Solve the following coding problem using the programming language python: For an array $b$ of length $m$ we define the function $f$ as $ f(b) = \begin{cases} b[1] & \quad \text{if } m = 1 \\ f(b[1] \oplus b[2],b[2] \oplus b[3],\dots,b[m-1] \oplus b[m]) & \quad \text{otherwise,} \end{cases} $ where $\oplus$ is bitwi...
```python n = int(input()) *a, = map(int, input().split()) dp = [[0 for i in range(n + 1)] for j in range(n + 1)] for i in range(n): dp[0][i] = a[i] for i in range(1, n): for j in range(n - i + 1): dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1] for i in range(1, n): for j in range(n - i): dp[i][...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n8 4 1\n2\n2 3\n1 2\n', 'output': '5\n12\n'}, {'type': 'stdin_stdout', 'input': '6\n1 2 4 8 16 32\n4\n1 6\n2 5\n3 4\n1 2\n', 'output': '60\n30\n12\n3\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/983/B'}
vfc_6802
```python n = int(input()) *a, = map(int, input().split()) dp = [[0 for i in range(n + 1)] for j in range(n + 1)] for i in range(n): dp[0][i] = a[i] for i in range(1, n): for j in range(n - i + 1): dp[i][j] = dp[i - 1][j] ^ dp[i - 1][j + 1] for i in range(1, n): for j in range(n - i): dp[i][...
3 8 4 1 2 2 3 1 2
5 12
5 12
true
1,494
apps
verifiable_code
2316
Solve the following coding problem using the programming language python: Koa the Koala and her best friend want to play a game. The game starts with an array $a$ of length $n$ consisting of non-negative integers. Koa and her best friend move in turns and each have initially a score equal to $0$. Koa starts. Let's d...
```python import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N = int(input()) A = [int(a) for a in input().split()] X = [0] * 30 for a in A: for i in range(30): if a & (1 << i): X[i] += 1 for i in range(30)[::-1]: ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n3\n1 2 2\n3\n2 2 3\n5\n0 0 0 2 2\n', 'output': 'WIN\nLOSE\nDRAW\n'}, {'type': 'stdin_stdout', 'input': '4\n5\n4 1 5 1 3\n4\n1 0 1 6\n1\n0\n2\n5 4\n', 'output': 'WIN\nWIN\nDRAW\nWIN\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1383/B'}
vfc_6810
```python import sys input = lambda: sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N = int(input()) A = [int(a) for a in input().split()] X = [0] * 30 for a in A: for i in range(30): if a & (1 << i): X[i] += 1 for i in range(30)[::-1]: ...
3 3 1 2 2 3 2 2 3 5 0 0 0 2 2
WIN LOSE DRAW
WIN LOSE DRAW
true
1,496
apps
verifiable_code
2317
Solve the following coding problem using the programming language python: You have an array $a$ of length $n$. For every positive integer $x$ you are going to perform the following operation during the $x$-th second: Select some distinct indices $i_{1}, i_{2}, \ldots, i_{k}$ which are between $1$ and $n$ inclusive,...
```python import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(n - 1): diff = a[i] - a[i + 1] if diff <= 0: continue else: ans = max(len(bin(diff)) - 2,...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n4\n1 7 6 5\n5\n1 2 3 4 5\n2\n0 -4\n', 'output': '2\n0\n3\n'}, {'type': 'stdin_stdout', 'input': '6\n3\n1000000000 0 -1000000000\n1\n6\n2\n-1000000000 1000000000\n2\n1000000000 -1000000000\n2\n1000000000 1000000000\n2\n-1000000000 -1000000000\n', 'output': '31\n0\n0\...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1338/A'}
vfc_6814
```python import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n = int(input()) a = list(map(int, input().split())) ans = 0 for i in range(n - 1): diff = a[i] - a[i + 1] if diff <= 0: continue else: ans = max(len(bin(diff)) - 2,...
3 4 1 7 6 5 5 1 2 3 4 5 2 0 -4
2 0 3
2 0 3
true
1,497
apps
verifiable_code
2318
Solve the following coding problem using the programming language python: During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants. Let's assume that n people took part in the contest. Let's assume that the participant who got the firs...
```python n, k = list(map(int, input().split())) c, m, l, r = 0, 0, [], 0 for e in [int(i) for i in input().split()]: d = m - c * (n - c - 1) * e r+= 1 if d < k: n -= 1 l += [r] else: m += c * e c += 1 l.sort() for e in l: print(e) ```
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 0\n5 3 4 1 2\n', 'output': '2\n3\n4\n'}, {'type': 'stdin_stdout', 'input': '10 -10\n5 5 1 7 5 1 2 4 9 2\n', 'output': '2\n4\n5\n7\n8\n9\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/314/A'}
vfc_6818
```python n, k = list(map(int, input().split())) c, m, l, r = 0, 0, [], 0 for e in [int(i) for i in input().split()]: d = m - c * (n - c - 1) * e r+= 1 if d < k: n -= 1 l += [r] else: m += c * e c += 1 l.sort() for e in l: print(e) ```
5 0 5 3 4 1 2
2 3 4
2 3 4
true
1,498
apps
verifiable_code
2319
Solve the following coding problem using the programming language python: We start with a permutation $a_1, a_2, \ldots, a_n$ and with an empty array $b$. We apply the following operation $k$ times. On the $i$-th iteration, we select an index $t_i$ ($1 \le t_i \le n-i+1$), remove $a_{t_i}$ from the array, and append ...
```python import sys readline = sys.stdin.readline T = int(readline()) MOD = 998244353 Ans = [None]*T for qu in range(T): N, K = map(int, readline().split()) A = [0] + list(map(int, readline().split())) + [0] B = list(map(int, readline().split())) C = [None]*(N+1) for i in range(1, N+1): C...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n5 3\n1 2 3 4 5\n3 2 5\n4 3\n4 3 2 1\n4 3 1\n7 4\n1 4 7 3 6 2 5\n3 2 4 5\n', 'output': '2\n0\n4\n'}, {'type': 'stdin_stdout', 'input': '6\n2 1\n2 1\n1\n3 2\n1 3 2\n1 3\n4 2\n4 1 3 2\n1 2\n5 3\n4 3 2 5 1\n1 4 5\n6 3\n2 4 5 6 1 3\n2 4 5\n7 3\n7 6 4 3 2 1 5\n1 2 6\n', '...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1442/B'}
vfc_6822
```python import sys readline = sys.stdin.readline T = int(readline()) MOD = 998244353 Ans = [None]*T for qu in range(T): N, K = map(int, readline().split()) A = [0] + list(map(int, readline().split())) + [0] B = list(map(int, readline().split())) C = [None]*(N+1) for i in range(1, N+1): C...
3 5 3 1 2 3 4 5 3 2 5 4 3 4 3 2 1 4 3 1 7 4 1 4 7 3 6 2 5 3 2 4 5
2 0 4
2 0 4
true
1,499
apps
verifiable_code
2323
Solve the following coding problem using the programming language python: There are N barbecue restaurants along a street. The restaurants are numbered 1 through N from west to east, and the distance between restaurant i and restaurant i+1 is A_i. Joisino has M tickets, numbered 1 through M. Every barbecue restaurant ...
```python def main(): import sys from array import array input = sys.stdin.readline class Bit: def __init__(self, n): self.size = n self.size_bit_length = n.bit_length() self.tree = array('h', [0] * (n+1)) def reset(self): self.tree = arr...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 4\n1 4\n2 2 5 1\n1 3 3 2\n2 2 5 1\n', 'output': '11\n'}, {'type': 'stdin_stdout', 'input': '5 3\n1 2 3 4\n10 1 1\n1 1 1\n1 10 1\n1 1 1\n1 1 10\n', 'output': '20\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc067/tasks/arc067_d'}
vfc_6838
```python def main(): import sys from array import array input = sys.stdin.readline class Bit: def __init__(self, n): self.size = n self.size_bit_length = n.bit_length() self.tree = array('h', [0] * (n+1)) def reset(self): self.tree = arr...
3 4 1 4 2 2 5 1 1 3 3 2 2 2 5 1
11
11
true
1,502
apps
verifiable_code
2324
Solve the following coding problem using the programming language python: Fennec and Snuke are playing a board game. On the board, there are N cells numbered 1 through N, and N-1 roads, each connecting two cells. Cell a_i is adjacent to Cell b_i through the i-th road. Every cell can be reached from every other cell by...
```python #!/usr/bin/env python3 import sys sys.setrecursionlimit(10 ** 6) def main(): n = int(input()) adj_list = [[] for i in range(n)] for i in range(n - 1): a1, b1 = list(map(int, sys.stdin.readline().split())) adj_list[a1 - 1].append(b1 - 1) adj_list[b1 - 1].append(a1 - 1) ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '7\n3 6\n1 2\n3 1\n7 4\n5 7\n1 4\n', 'output': 'Fennec\n'}, {'type': 'stdin_stdout', 'input': '4\n1 4\n4 2\n2 3\n', 'output': 'Snuke\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc078/tasks/arc078_b'}
vfc_6842
```python #!/usr/bin/env python3 import sys sys.setrecursionlimit(10 ** 6) def main(): n = int(input()) adj_list = [[] for i in range(n)] for i in range(n - 1): a1, b1 = list(map(int, sys.stdin.readline().split())) adj_list[a1 - 1].append(b1 - 1) adj_list[b1 - 1].append(a1 - 1) ...
7 3 6 1 2 3 1 7 4 5 7 1 4
Fennec
Fennec
true
1,503
apps
verifiable_code
2325
Solve the following coding problem using the programming language python: Let us consider the following operations on a string consisting of A and B: - Select a character in a string. If it is A, replace it with BB. If it is B, replace with AA. - Select a substring that is equal to either AAA or BBB, and delete it f...
```python S = input() SA = [0] n = 0 for c in S: if c=='A': n+=1 SA.append(n) T = input() TA = [0] n = 0 for c in T: if c=='A': n+=1 TA.append(n) q = int(input()) for _ in range(q): a, b, c, d = list(map(int, input().split())) nSA = SA[b]-SA[a-1] nSB = b-a+1-nSA nTA = TA[d]-TA[c-1] ...
{'test_cases': [{'type': 'stdin_stdout', 'input': 'BBBAAAABA\nBBBBA\n4\n7 9 2 5\n7 9 1 4\n1 7 2 5\n1 7 2 4\n', 'output': 'YES\nNO\nYES\nNO\n'}, {'type': 'stdin_stdout', 'input': 'AAAAABBBBAAABBBBAAAA\nBBBBAAABBBBBBAAAAABB\n10\n2 15 2 13\n2 13 6 16\n1 13 2 20\n4 20 3 20\n1 18 9 19\n2 14 1 11\n3 20 3 15\n6 16 1 17\n4 18 ...
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc071/tasks/arc071_c'}
vfc_6846
```python S = input() SA = [0] n = 0 for c in S: if c=='A': n+=1 SA.append(n) T = input() TA = [0] n = 0 for c in T: if c=='A': n+=1 TA.append(n) q = int(input()) for _ in range(q): a, b, c, d = list(map(int, input().split())) nSA = SA[b]-SA[a-1] nSB = b-a+1-nSA nTA = TA[d]-TA[c-1] ...
BBBAAAABA BBBBA 4 7 9 2 5 7 9 1 4 1 7 2 5 1 7 2 4
YES NO YES NO
YES NO YES NO
true
1,504
apps
verifiable_code
2326
Solve the following coding problem using the programming language python: Snuke loves constructing integer sequences. There are N piles of stones, numbered 1 through N. The pile numbered i consists of a_i stones. Snuke will construct an integer sequence s of length Σa_i, as follows: - Among the piles with the largest...
```python from collections import defaultdict N = int(input()) a = [int(i) for i in input().split()] b = defaultdict(lambda : [float('inf'), 0]) for i in range(N) : b[a[i]][0] = min(b[a[i]][0], i) b[a[i]][1] += 1 # [value, first_appearance, count] c = [(0, 0, 0)] for k, v in b.items() : c.append((k, v[0]...
{'test_cases': [{'type': 'stdin_stdout', 'input': '2\n1 2\n', 'output': '2\n1\n'}, {'type': 'stdin_stdout', 'input': '10\n1 2 1 3 2 4 2 5 8 1\n', 'output': '10\n7\n0\n4\n0\n3\n0\n2\n3\n0\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc069/tasks/arc069_c'}
vfc_6850
```python from collections import defaultdict N = int(input()) a = [int(i) for i in input().split()] b = defaultdict(lambda : [float('inf'), 0]) for i in range(N) : b[a[i]][0] = min(b[a[i]][0], i) b[a[i]][1] += 1 # [value, first_appearance, count] c = [(0, 0, 0)] for k, v in b.items() : c.append((k, v[0]...
2 1 2
2 1
2 1
true
1,505
apps
verifiable_code
2327
Solve the following coding problem using the programming language python: Snuke has decided to play a game, where the player runs a railway company. There are M+1 stations on Snuke Line, numbered 0 through M. A train on Snuke Line stops at station 0 and every d-th station thereafter, where d is a predetermined constan...
```python import sys input = sys.stdin.readline def main(): n, m = map(int, input().split()) LR = [list(map(int, input().split())) for _ in range(n)] BIT = [0]*(m+2) def add(i, a): while i <= m+1: BIT[i] += a i += i&(-i) def bit_sum(i): res = 0 while i > 0: res += BIT[i] ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3 3\n1 2\n2 3\n3 3\n', 'output': '3\n2\n2\n'}, {'type': 'stdin_stdout', 'input': '7 9\n1 7\n5 9\n5 7\n5 9\n1 1\n6 8\n3 4\n', 'output': '7\n6\n6\n5\n4\n5\n5\n3\n2\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc068/tasks/arc068_c'}
vfc_6854
```python import sys input = sys.stdin.readline def main(): n, m = map(int, input().split()) LR = [list(map(int, input().split())) for _ in range(n)] BIT = [0]*(m+2) def add(i, a): while i <= m+1: BIT[i] += a i += i&(-i) def bit_sum(i): res = 0 while i > 0: res += BIT[i] ...
3 3 1 2 2 3 3 3
3 2 2
3 2 2
true
1,506
apps
verifiable_code
2328
Solve the following coding problem using the programming language python: When Misha hits his favorite gym, he comes across an interesting problem with the barbell. In the gym, someone always leaves the weight plates in the strangest places you can imagine and sometime it's difficult to equip the barbell the way you w...
```python def fx(s,n,xsum): sub=[[None for x in range(n+2)]for y in range(xsum+2)] for i in range(n+1): sub[0][i]=True for i in range(1,xsum+1): sub[i][0]=False for i in range(1,xsum+1): for j in range(1,n+1): sub[i][j]=sub[i][j-1] if i>=s[j-1]: sub[i][j]=sub[i][j] or sub[i-s[j-1]][j-1] if sub[xsum...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 10\n1 2 3 5 6\n3 2 3 3\n3 2 3 4\n3 2 3 5\n2 2 5\n3 2 4 8\n1 2 1\n3 2 4 8\n2 1 4 \n3 2 4 3 \n3 1 5 7 \n', 'output': 'Yes\nNo\nYes\nYes\nYes\nNo\nYes\n'}, {'type': 'stdin_stdout', 'input': '3 4\n2013 2015 2017\n3 1 3 4030\n1 1 111\n3 1 3 4030\n3 1 2 111\n', 'output': '...
{'difficulty': 'competition', 'problem_url': 'https://www.codechef.com/OCT15/problems/MGCHGYM'}
vfc_6858
```python def fx(s,n,xsum): sub=[[None for x in range(n+2)]for y in range(xsum+2)] for i in range(n+1): sub[0][i]=True for i in range(1,xsum+1): sub[i][0]=False for i in range(1,xsum+1): for j in range(1,n+1): sub[i][j]=sub[i][j-1] if i>=s[j-1]: sub[i][j]=sub[i][j] or sub[i-s[j-1]][j-1] if sub[xsum...
5 10 1 2 3 5 6 3 2 3 3 3 2 3 4 3 2 3 5 2 2 5 3 2 4 8 1 2 1 3 2 4 8 2 1 4 3 2 4 3 3 1 5 7
Yes No Yes Yes Yes No Yes
Yes No Yes Yes Yes No Yes
true
1,507
apps
verifiable_code
2329
Solve the following coding problem using the programming language python: You are given an array A, consisting of N integers and an array B, consisting of M integers. The subsequence of A is the array that can be obtained by picking the elements at the arbitrary sorted set of positions from A. Your task is to count th...
```python mod =(10**9)+7 n,m = list(map(int,input().split())) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] dp = [] for i in range(n): dp += [[0]*m] dp[-1][-1]=1 for i in range(n-2,-1,-1): dp[i][-1]=1 for j in range(m-1): x = (a[i]+b[j])-(b[j+1]) temp = 0 ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5 3\n1 5 2 4 7\n7 9 6\n\n\n', 'output': '4\n'}, {'type': 'stdin_stdout', 'input': '4 2\n7 7 7 7\n3 4\n\n\n', 'output': '6\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://www.codechef.com/LTIME34/problems/ARRAYSUM'}
vfc_6862
```python mod =(10**9)+7 n,m = list(map(int,input().split())) a = [int(i) for i in input().split()] b = [int(i) for i in input().split()] dp = [] for i in range(n): dp += [[0]*m] dp[-1][-1]=1 for i in range(n-2,-1,-1): dp[i][-1]=1 for j in range(m-1): x = (a[i]+b[j])-(b[j+1]) temp = 0 ...
5 3 1 5 2 4 7 7 9 6
4
4
true
1,508
apps
verifiable_code
2330
Solve the following coding problem using the programming language python: You are given a string s of length n. Does a tree with n vertices that satisfies the following conditions exist? - The vertices are numbered 1,2,..., n. - The edges are numbered 1,2,..., n-1, and Edge i connects Vertex u_i and v_i. - If the i...
```python s = input() if s[0] == '0' or s[-2] == '0' or s[-1] == '1': # 's' should be like "1xx...x0" print((-1)) elif s[:-1] != s[-2::-1]: print((-1)) else: half = len(s) // 2 one_indices = [i+1 for i in range(1, half) if s[i] == '1'] # not including 0 or larger than n//2 parents = [0] * (len(s)...
{'test_cases': [{'type': 'stdin_stdout', 'input': '1111\n', 'output': '-1\n'}, {'type': 'stdin_stdout', 'input': '1110\n', 'output': '1 2\n2 3\n3 4\n'}, {'type': 'stdin_stdout', 'input': '1010\n', 'output': '1 2\n1 3\n1 4\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://atcoder.jp/contests/arc103/tasks/arc103_c'}
vfc_6866
```python s = input() if s[0] == '0' or s[-2] == '0' or s[-1] == '1': # 's' should be like "1xx...x0" print((-1)) elif s[:-1] != s[-2::-1]: print((-1)) else: half = len(s) // 2 one_indices = [i+1 for i in range(1, half) if s[i] == '1'] # not including 0 or larger than n//2 parents = [0] * (len(s)...
1111
-1
-1
true
1,509
apps
verifiable_code
2331
Solve the following coding problem using the programming language python: There is an undirected tree of $n$ vertices, connected by $n-1$ bidirectional edges. There is also a snake stuck inside of this tree. Its head is at vertex $a$ and its tail is at vertex $b$. The snake's body occupies all vertices on the unique s...
```python from sys import stdin import itertools input = stdin.readline def getint(): return int(input()) def getints(): return list(map(int, input().split())) def getint1(): return list([int(x) - 1 for x in input().split()]) def getstr(): return input()[:-1] def solve(): n, a, b = getint1() n += 1 adj = ...
{'test_cases': [{'type': 'stdin_stdout', 'input': '4\n8 4 7\n1 2\n2 3\n1 4\n4 5\n4 6\n1 7\n7 8\n4 3 2\n4 3\n1 2\n2 3\n9 3 5\n1 2\n2 3\n3 4\n1 5\n5 6\n6 7\n1 8\n8 9\n16 15 12\n1 2\n2 3\n1 4\n4 5\n5 6\n6 7\n4 8\n8 9\n8 10\n10 11\n11 12\n11 13\n13 14\n10 15\n15 16\n', 'output': 'YES\nNO\nNO\nYES\n'}], 'language': 'python'...
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1381/D'}
vfc_6870
```python from sys import stdin import itertools input = stdin.readline def getint(): return int(input()) def getints(): return list(map(int, input().split())) def getint1(): return list([int(x) - 1 for x in input().split()]) def getstr(): return input()[:-1] def solve(): n, a, b = getint1() n += 1 adj = ...
4 8 4 7 1 2 2 3 1 4 4 5 4 6 1 7 7 8 4 3 2 4 3 1 2 2 3 9 3 5 1 2 2 3 3 4 1 5 5 6 6 7 1 8 8 9 16 15 12 1 2 2 3 1 4 4 5 5 6 6 7 4 8 8 9 8 10 10 11 11 12 11 13 13 14 10 15 15 16
YES NO NO YES
YES NO NO YES
true
1,510
apps
verifiable_code
2332
Solve the following coding problem using the programming language python: There are $n$ cities in Berland and some pairs of them are connected by two-way roads. It is guaranteed that you can pass from any city to any other, moving along the roads. Cities are numerated from $1$ to $n$. Two fairs are currently taking p...
```python import sys input = sys.stdin.readline from collections import deque t=int(input()) for testcaess in range(t): n,m,a,b=list(map(int,input().split())) E=[[] for i in range(n+1)] for i in range(m): x,y=list(map(int,input().split())) E[x].append(y) E[y].append(x) USE1=[...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\n7 7 3 5\n1 2\n2 3\n3 4\n4 5\n5 6\n6 7\n7 5\n4 5 2 3\n1 2\n2 3\n3 4\n4 1\n4 2\n4 3 2 1\n1 2\n2 3\n4 1\n', 'output': '4\n0\n1\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1276/B'}
vfc_6874
```python import sys input = sys.stdin.readline from collections import deque t=int(input()) for testcaess in range(t): n,m,a,b=list(map(int,input().split())) E=[[] for i in range(n+1)] for i in range(m): x,y=list(map(int,input().split())) E[x].append(y) E[y].append(x) USE1=[...
3 7 7 3 5 1 2 2 3 3 4 4 5 5 6 6 7 7 5 4 5 2 3 1 2 2 3 3 4 4 1 4 2 4 3 2 1 1 2 2 3 4 1
4 0 1
4 0 1
true
1,511
apps
verifiable_code
2333
Solve the following coding problem using the programming language python: Consider the infinite sequence $s$ of positive integers, created by repeating the following steps: Find the lexicographically smallest triple of positive integers $(a, b, c)$ such that $a \oplus b \oplus c = 0$, where $\oplus$ denotes the b...
```python import sys input = sys.stdin.readline out = [] t = int(input()) for _ in range(t): n = int(input()) n -= 1 rem = n % 3 n //= 3 s = [] if n: n -= 1 while n >= 0: s.append([['00','00','00'],['01','10','11'],['10','11','01'],['11','01','10']][n % 4][rem])...
{'test_cases': [{'type': 'stdin_stdout', 'input': '9\n1\n2\n3\n4\n5\n6\n7\n8\n9\n', 'output': '1\n2\n3\n4\n8\n12\n5\n10\n15\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1338/C'}
vfc_6878
```python import sys input = sys.stdin.readline out = [] t = int(input()) for _ in range(t): n = int(input()) n -= 1 rem = n % 3 n //= 3 s = [] if n: n -= 1 while n >= 0: s.append([['00','00','00'],['01','10','11'],['10','11','01'],['11','01','10']][n % 4][rem])...
9 1 2 3 4 5 6 7 8 9
1 2 3 4 8 12 5 10 15
1 2 3 4 8 12 5 10 15
true
1,512
apps
verifiable_code
2334
Solve the following coding problem using the programming language python: Zookeeper is playing a game. In this game, Zookeeper must use bombs to bomb a string that consists of letters 'A' and 'B'. He can use bombs to bomb a substring which is either "AB" or "BB". When he bombs such a substring, the substring gets dele...
```python import sys readline = sys.stdin.readline T = int(readline()) Ans = [None]*T for qu in range(T): S = [1 if s == 'A' else 0 for s in readline().strip()] stack = [] for s in S: if s: stack.append(s) else: if stack and stack[-1] == 1: stack.pop(...
{'test_cases': [{'type': 'stdin_stdout', 'input': '3\nAAA\nBABA\nAABBBABBBB\n', 'output': '3\n2\n0\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1428/C'}
vfc_6882
```python import sys readline = sys.stdin.readline T = int(readline()) Ans = [None]*T for qu in range(T): S = [1 if s == 'A' else 0 for s in readline().strip()] stack = [] for s in S: if s: stack.append(s) else: if stack and stack[-1] == 1: stack.pop(...
3 AAA BABA AABBBABBBB
3 2 0
3 2 0
true
1,513
apps
verifiable_code
2335
Solve the following coding problem using the programming language python: Denis was very sad after Nastya rejected him. So he decided to walk through the gateways to have some fun. And luck smiled at him! When he entered the first courtyard, he met a strange man who was selling something. Denis bought a mysterious i...
```python import sys input= sys.stdin.readline t = int(input()) out = [] for _ in range(t): n = int(input()) l = list(map(int,input().split())) smol = l[0] works = True for i in range(1, n): if l[i] == l[i-1] + 1: pass else: if l[i] > smol: wo...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n5\n2 3 4 5 1\n1\n1\n3\n1 3 2\n4\n4 2 3 1\n5\n1 5 2 4 3\n', 'output': 'Yes\nYes\nNo\nYes\nNo\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/1340/A'}
vfc_6886
```python import sys input= sys.stdin.readline t = int(input()) out = [] for _ in range(t): n = int(input()) l = list(map(int,input().split())) smol = l[0] works = True for i in range(1, n): if l[i] == l[i-1] + 1: pass else: if l[i] > smol: wo...
5 5 2 3 4 5 1 1 1 3 1 3 2 4 4 2 3 1 5 1 5 2 4 3
Yes Yes No Yes No
Yes Yes No Yes No
true
1,514
apps
verifiable_code
2336
Solve the following coding problem using the programming language python: Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from $1$ to $n$ and then $3n$ times ...
```python n = int(input()) l = [int(x) - 1 for x in input().split()] parity = 0 explore = set(l) while len(explore) > 0: x = explore.pop() tmp = x found = [x] while l[tmp] != x: tmp = l[tmp] found.append(tmp) for i in found[1:]: explore.remove(i) parity ^= (len(found) - 1...
{'test_cases': [{'type': 'stdin_stdout', 'input': '5\n2 4 5 1 3\n', 'output': 'Petr\n'}], 'language': 'python'}
{'difficulty': 'competition', 'problem_url': 'https://codeforces.com/problemset/problem/986/B'}
vfc_6890
```python n = int(input()) l = [int(x) - 1 for x in input().split()] parity = 0 explore = set(l) while len(explore) > 0: x = explore.pop() tmp = x found = [x] while l[tmp] != x: tmp = l[tmp] found.append(tmp) for i in found[1:]: explore.remove(i) parity ^= (len(found) - 1...
5 2 4 5 1 3
Petr
Petr
true
1,515