source
stringclasses
1 value
task_type
stringclasses
1 value
in_source_id
stringlengths
1
4
problem
stringlengths
488
6.07k
gold_standard_solution
stringlengths
19
30.1k
verification_info
dict
metadata
dict
problem_id
stringlengths
5
9
apps
verifiable_code
2190
Solve the following coding problem using the programming language python: There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might...
```python n = int(input()) ans = 0 stk = [] for v in map(int, input().split()): last = 0 while len(stk) and stk[-1][0] < v and stk[-1][1]: last = max(last, stk[-1][1]) del stk[-1] if not len(stk) or stk[-1][0] < v: stk.append((v, 0)) else: stk.append((v, last + 1)); ans ...
{ "language": "python", "test_cases": [ { "input": "10\n10 9 7 8 6 5 3 4 2 1\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "6\n1 2 3 4 5 6\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "6\n6 5 4 3 2 1\n", "output": "1\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/319/B" }
vfc_6306
apps
verifiable_code
2191
Solve the following coding problem using the programming language python: You are given a sequence a consisting of n integers. Find the maximum possible value of $a_{i} \operatorname{mod} a_{j}$ (integer remainder of a_{i} divided by a_{j}), where 1 ≤ i, j ≤ n and a_{i} ≥ a_{j}. -----Input----- The first line conta...
```python def main(): input() aa = sorted(map(int, input().split())) maxa = max(aa) m = [False] * (maxa + 1) x = [] b = 0 for a in aa: if b != a: m[a] = True for i in range(b, a): x.append(b) b = a x.append(b) ans = 0 fo...
{ "language": "python", "test_cases": [ { "input": "3\n3 4 5\n", "output": "2\n", "type": "stdin_stdout" }, { "input": "3\n1 2 4\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "1\n1\n", "output": "0\n", "type": "stdin_stdout" }...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/484/B" }
vfc_6310
apps
verifiable_code
2195
Solve the following coding problem using the programming language python: You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such in...
```python from collections import Counter n = int(input()) a = list(map(int, input().split())) c = Counter(a) res = 0 cur = 0 for i in sorted(c.keys()): d = min(c[i], cur) cur -= d res += d cur += c[i] print(res) ```
{ "language": "python", "test_cases": [ { "input": "7\n10 1 1 1 5 5 3\n", "output": "4\n", "type": "stdin_stdout" }, { "input": "5\n1 1 1 1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "6\n300000000 200000000 300000000 200000000 1000000000...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1007/A" }
vfc_6326
apps
verifiable_code
2197
Solve the following coding problem using the programming language python: You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the ord...
```python a = input() b = a[::-1] print(a + b) ```
{ "language": "python", "test_cases": [ { "input": "aba\n", "output": "abaaba", "type": "stdin_stdout" }, { "input": "ab\n", "output": "abba", "type": "stdin_stdout" }, { "input": "abcab\n", "output": "abcabbacba", "type": "stdin_stdout" ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/932/A" }
vfc_6334
apps
verifiable_code
2198
Solve the following coding problem using the programming language python: There are some ambiguities when one writes Berland names with the letters of the Latin alphabet. For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "...
```python n = int(input()) s = set() for a in range(n): name = input() name = name.replace('u', 'oo') while (name.count('kh') > 0): name = name.replace('kh', 'h') s.add(name) print(len(s)) ```
{ "language": "python", "test_cases": [ { "input": "10\nmihail\noolyana\nkooooper\nhoon\nulyana\nkoouper\nmikhail\nkhun\nkuooper\nkkkhoon\n", "output": "4\n", "type": "stdin_stdout" }, { "input": "9\nhariton\nhkariton\nbuoi\nkkkhariton\nboooi\nbui\nkhariton\nboui\nboi\n", "...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/883/F" }
vfc_6338
apps
verifiable_code
2199
Solve the following coding problem using the programming language python: Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it. [Image]  T...
```python import sys input = sys.stdin.readline n, k = list(map(int, input().split())) begin = [-1] * n end = [-1] * n hurt = [-1] * n adj = [[] for i in range(n)] for _ in range(n-1): u ,v = list(map(int, input().split())) adj[u-1].append(v-1) adj[v-1].append(u-1) hurt[0] = 1 begin[0] = 0 stack = [0] c...
{ "language": "python", "test_cases": [ { "input": "7 4\n1 2\n1 3\n1 4\n3 5\n3 6\n4 7\n", "output": "7", "type": "stdin_stdout" }, { "input": "4 1\n1 2\n1 3\n2 4\n", "output": "2", "type": "stdin_stdout" }, { "input": "8 5\n7 5\n1 7\n6 1\n3 7\n8 3\n2 1\n...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1336/A" }
vfc_6342
apps
verifiable_code
2200
Solve the following coding problem using the programming language python: Catherine received an array of integers as a gift for March 8. Eventually she grew bored with it, and she started calculated various useless characteristics for it. She succeeded to do it for each one she came up with. But when she came up with ...
```python import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) b = a ans = 0 for k in range(29): a0 = [] a1 = [] a0a = a0.append a1a = a1.append b0 = [] b1 = [] b0a = b0.append b1a = b1.append for i in a: if i&(1<<k): a1a(i) ...
{ "language": "python", "test_cases": [ { "input": "2\n1 2\n", "output": "3", "type": "stdin_stdout" }, { "input": "3\n1 2 3\n", "output": "2", "type": "stdin_stdout" }, { "input": "2\n1 1\n", "output": "2", "type": "stdin_stdout" }, ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1322/B" }
vfc_6346
apps
verifiable_code
2201
Solve the following coding problem using the programming language python: You are given a sequence of n integers a_1, a_2, ..., a_{n}. Determine a real number x such that the weakness of the sequence a_1 - x, a_2 - x, ..., a_{n} - x is as small as possible. The weakness of a sequence is defined as the maximum value...
```python import sys n = int(sys.stdin.readline()) a = [int(x) for x in sys.stdin.readline().split()] eps = 1e-12 def f(x): mx = a[0] - x tsmx = 0.0 mn = a[0] - x tsmn = 0.0 for ai in a: tsmx = max(tsmx + ai - x, ai - x) mx = max(tsmx, mx) tsmn = min(tsmn + ai - x, ai - x) ...
{ "language": "python", "test_cases": [ { "input": "3\n1 2 3\n", "output": "1.000000000000000\n", "type": "stdin_stdout" }, { "input": "4\n1 2 3 4\n", "output": "2.000000000000000\n", "type": "stdin_stdout" }, { "input": "10\n1 10 2 9 3 8 4 7 5 6\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/578/C" }
vfc_6350
apps
verifiable_code
2202
Solve the following coding problem using the programming language python: An array of integers $p_{1},p_{2}, \ldots,p_{n}$ is called a permutation if it contains each number from $1$ to $n$ exactly once. For example, the following arrays are permutations: $[3,1,2], [1], [1,2,3,4,5]$ and $[4,3,1,2]$. The following arra...
```python import sys input = sys.stdin.readline n=int(input()) A=list(map(int,input().split())) BIT=[0]*(n+1) def update(v,w): while v<=n: BIT[v]+=w v+=(v&(-v)) def getvalue(v): ANS=0 while v!=0: ANS+=BIT[v] v-=(v&(-v)) return ANS for i in range(1,n+1): update(i,...
{ "language": "python", "test_cases": [ { "input": "3\n0 0 0\n", "output": "3 2 1\n", "type": "stdin_stdout" }, { "input": "2\n0 1\n", "output": "1 2\n", "type": "stdin_stdout" }, { "input": "5\n0 1 1 1 10\n", "output": "1 4 3 2 5\n", "type":...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1208/D" }
vfc_6354
apps
verifiable_code
2203
Solve the following coding problem using the programming language python: Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as p_{i}. For all pairs of distinct integers i, j between 1 and n, he wrote the number a_{i}, j = min(p_{i}, p_{j}). He writes a_{...
```python def main(): n = int(input()) a = [[int(i) for i in input().split()] for j in range(n)] result = [-1] * n for i in range(n - 1): for j in range(n): d = set(a[j][k] for k in range(n) if result[k] == -1 and j != k) if len(d) == 1: result[j] = d...
{ "language": "python", "test_cases": [ { "input": "2\n0 1\n1 0\n", "output": "2 1\n", "type": "stdin_stdout" }, { "input": "5\n0 2 2 1 2\n2 0 4 1 3\n2 4 0 1 3\n1 1 1 0 1\n2 3 3 1 0\n", "output": "2 5 4 1 3\n", "type": "stdin_stdout" }, { "input": "10\n0...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/618/B" }
vfc_6358
apps
verifiable_code
2205
Solve the following coding problem using the programming language python: Please notice the unusual memory limit of this problem. Orac likes games. Recently he came up with the new game, "Game of Life". You should play this game on a black and white grid with $n$ rows and $m$ columns. Each cell is either black or wh...
```python def main(): import sys from array import array from collections import deque input = sys.stdin.readline H, W, Q = list(map(int, input().split())) grid = array('b', [0] * (H*W)) #flg_0 = 0 #flg_1 = 0 for h in range(H): line = input().rstrip('\n') """ ...
{ "language": "python", "test_cases": [ { "input": "3 3 3\n000\n111\n000\n1 1 1\n2 2 2\n3 3 3\n", "output": "1\n1\n1\n", "type": "stdin_stdout" }, { "input": "5 2 2\n01\n10\n01\n10\n01\n1 1 4\n5 1 4\n", "output": "0\n0\n", "type": "stdin_stdout" }, { "in...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1349/C" }
vfc_6366
apps
verifiable_code
2206
Solve the following coding problem using the programming language python: Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged ...
```python n = int(input()) a = list(map(int, input().split())) p = [0] * (n + 1) ans = [1] * (n + 1) ind = n for i in range(n): p[a[i] - 1] = 1 while ind > 0 and p[ind - 1] == 1: ind -= 1 ans[i + 1] = 1 + (i + 1) - (n - ind) print(' '.join(map(str, ans))) ```
{ "language": "python", "test_cases": [ { "input": "4\n1 3 4 2\n", "output": "1 2 3 2 1\n", "type": "stdin_stdout" }, { "input": "8\n6 8 3 4 7 2 1 5\n", "output": "1 2 2 3 4 3 4 5 1\n", "type": "stdin_stdout" }, { "input": "1\n1\n", "output": "1 1\...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/875/B" }
vfc_6370
apps
verifiable_code
2207
Solve the following coding problem using the programming language python: Polycarpus is a system administrator. There are two servers under his strict guidance — a and b. To stay informed about the servers' performance, Polycarpus executes commands "ping a" and "ping b". Each ping command sends exactly ten packets to ...
```python n=int(input()) ta,tb,da,db=[0]*4 for i in range (n): t,x,y=list(map(int,input().split())) if t==1: ta+=(x+y) da+=y if (t==2): tb+=(x+y) db+=y if (ta-da>=0.5*ta): print ('LIVE') else : print ('DEAD') if (tb-db>=0.5*tb): print ('LIVE') else : pr...
{ "language": "python", "test_cases": [ { "input": "2\n1 5 5\n2 6 4\n", "output": "LIVE\nLIVE\n", "type": "stdin_stdout" }, { "input": "3\n1 0 10\n2 0 10\n1 10 0\n", "output": "LIVE\nDEAD\n", "type": "stdin_stdout" }, { "input": "10\n1 3 7\n2 4 6\n1 2 8\...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/245/A" }
vfc_6374
apps
verifiable_code
2208
Solve the following coding problem using the programming language python: The legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring out the snacks! Moo! There are $n$ snacks flavors, numbered wit...
```python #!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline().split()] def...
{ "language": "python", "test_cases": [ { "input": "5 4\n1 2\n4 3\n1 4\n3 4\n", "output": "1\n", "type": "stdin_stdout" }, { "input": "6 5\n2 3\n2 1\n3 4\n6 5\n4 5\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "2 1\n1 2\n", "output": "0...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1209/D" }
vfc_6378
apps
verifiable_code
2211
Solve the following coding problem using the programming language python: Bessie has way too many friends because she is everyone's favorite cow! Her new friend Rabbit is trying to hop over so they can play! More specifically, he wants to get from $(0,0)$ to $(x,0)$ by making multiple hops. He is only willing to hop...
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline mii=lambda:list(map(int,input().split())) for _ in range(int(input())): n,x=mii() has=0 a=0 for i in mii(): if x==i: has=1 a=max(a,i) if has: print(1) else: print(max(2,(x-1)//a+1)) ```
{ "language": "python", "test_cases": [ { "input": "4\n2 4\n1 3\n3 12\n3 4 5\n1 5\n5\n2 10\n15 4\n", "output": "2\n3\n1\n2\n", "type": "stdin_stdout" }, { "input": "1\n10 999999733\n25 68 91 55 36 29 96 4 63 3\n", "output": "10416664\n", "type": "stdin_stdout" }, ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1307/B" }
vfc_6390
apps
verifiable_code
2212
Solve the following coding problem using the programming language python: Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he h...
```python import sys [n, q] = map(int, sys.stdin.readline().strip().split()) qis = [int(sys.stdin.readline().strip()) for _ in range(q)] def query(n, q): d = 2 * n - q while d % 2 == 0: d //= 2 return (n - d // 2) for qi in qis: print (query(n, qi)) ```
{ "language": "python", "test_cases": [ { "input": "4 3\n2\n3\n4\n", "output": "3\n2\n4\n", "type": "stdin_stdout" }, { "input": "13 4\n10\n5\n4\n8\n", "output": "13\n3\n8\n9\n", "type": "stdin_stdout" }, { "input": "2 2\n1\n2\n", "output": "1\n2\n...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/949/B" }
vfc_6394
apps
verifiable_code
2213
Solve the following coding problem using the programming language python: Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows: $f(0...
```python T = int(input()) for t in range(T): a, b, n = [int(i) for i in input().split()] if n%3 == 2: print(a^b) elif n%3 == 1: print(b) else: print(a) ```
{ "language": "python", "test_cases": [ { "input": "3\n3 4 2\n4 5 0\n325 265 1231232\n", "output": "7\n4\n76\n", "type": "stdin_stdout" }, { "input": "10\n0 0 1000000000\n1002 2003 36523\n233 5656 898989\n0 2352 0\n21132 23256 2323256\n12313 454878 11000\n1213 0 21\n11 1 1\n1 1 9...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1208/A" }
vfc_6398
apps
verifiable_code
2214
Solve the following coding problem using the programming language python: The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive. All the roads are initially bad, but t...
```python class Graph: def __init__(self, n_vertices, edges, directed=True, weighted=False): self.n_vertices = n_vertices self.edges = edges self.directed = directed self.weighted = weighted @property def adj(self): try: return self._adj except ...
{ "language": "python", "test_cases": [ { "input": "3\n1 1\n", "output": "4 3 3", "type": "stdin_stdout" }, { "input": "5\n1 2 3 4\n", "output": "5 8 9 8 5", "type": "stdin_stdout" }, { "input": "31\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/543/D" }
vfc_6402
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 ...
{ "language": "python", "test_cases": [ { "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\n...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/367/A" }
vfc_6410
apps
verifiable_code
2217
Solve the following coding problem using the programming language python: Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer d_{i}, which can be equal to 0, 1 or - 1. To...
```python import sys n, m = list(map(int, sys.stdin.readline().split())) d = list(map(int, sys.stdin.readline().split())) gph = [[] for _ in range(n)] for _ in range(m): u, v = list(map(int, sys.stdin.readline().split())) u -= 1 v -= 1 gph[u].append((v, _)) gph[v].append((u, _)) t = -1 if d.c...
{ "language": "python", "test_cases": [ { "input": "1 0\n1\n", "output": "-1\n", "type": "stdin_stdout" }, { "input": "4 5\n0 0 0 -1\n1 2\n2 3\n3 4\n1 4\n2 4\n", "output": "0\n", "type": "stdin_stdout" }, { "input": "2 1\n1 1\n1 2\n", "output": "1\...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/840/B" }
vfc_6414
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...
{ "language": "python", "test_cases": [ { "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"...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1198/B" }
vfc_6418
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 = ...
{ "language": "python", "test_cases": [ { "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...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1149/B" }
vfc_6422
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*...
{ "language": "python", "test_cases": [ { "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\n...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1179/C" }
vfc_6426
apps
verifiable_code
2222
Solve the following coding problem using the programming language python: The mobile application store has a new game called "Subway Roller". The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and n c...
```python def dfs(x, y): vis.append((x, y)) y += 1 nonlocal flag if flag or str.isalpha(grid[x][y]): return if y >= n - 1: flag = True return # stay idle if not str.isalpha(grid[x][y + 1]) and not str.isalpha(grid[x][y + 2]) and (x, y + 2) not in vis: dfs...
{ "language": "python", "test_cases": [ { "input": "2\n16 4\n...AAAAA........\ns.BBB......CCCCC\n........DDDDD...\n16 4\n...AAAAA........\ns.BBB....CCCCC..\n.......DDDDD....\n", "output": "YES\nNO\n", "type": "stdin_stdout" }, { "input": "2\n10 4\ns.ZZ......\n.....AAABB\n.YYYYYY....
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/585/B" }
vfc_6434
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...
{ "language": "python", "test_cases": [ { "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", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/245/F" }
vfc_6438
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 += ...
{ "language": "python", "test_cases": [ { "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...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1017/B" }
vfc_6442
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 *...
{ "language": "python", "test_cases": [ { "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": "st...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1428/F" }
vfc_6450
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: ...
{ "language": "python", "test_cases": [ { "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" }, ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1037/E" }
vfc_6458
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: ...
{ "language": "python", "test_cases": [ { "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...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/778/A" }
vfc_6462
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): ...
{ "language": "python", "test_cases": [ { "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":...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/799/B" }
vfc_6466
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...
{ "language": "python", "test_cases": [ { "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" }, ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1280/B" }
vfc_6470
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...
{ "language": "python", "test_cases": [ { "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...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/715/A" }
vfc_6474
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...
{ "language": "python", "test_cases": [ { "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": "st...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1423/J" }
vfc_6478
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)...
{ "language": "python", "test_cases": [ { "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" ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/613/D" }
vfc_6482
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] ...
{ "language": "python", "test_cases": [ { "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": "s...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1060/E" }
vfc_6486
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)...
{ "language": "python", "test_cases": [ { "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": ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1268/C" }
vfc_6494
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(...
{ "language": "python", "test_cases": [ { "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...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/484/A" }
vfc_6498
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): ...
{ "language": "python", "test_cases": [ { "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...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/917/B" }
vfc_6502
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...
{ "language": "python", "test_cases": [ { "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...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1218/F" }
vfc_6530
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...
{ "language": "python", "test_cases": [ { "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\n1737884207920...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1444/A" }
vfc_6538
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]...
{ "language": "python", "test_cases": [ { "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" }, { ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1229/C" }
vfc_6550
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...
{ "language": "python", "test_cases": [ { "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...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1045/I" }
vfc_6554
apps
verifiable_code
2253
Solve the following coding problem using the programming language python: ZS the Coder loves mazes. Your job is to create one so that he can play with it. A maze consists of n × m rooms, and the rooms are arranged in n rows (numbered from the top to the bottom starting from 1) and m columns (numbered from the left to ...
```python corr = lambda x, y: 1 <= x <= n and 1 <= y <= m T = int(input()) a = [] while T: a.append(T % 6) T //= 6 L = len(a) n = m = L * 2 + 2 ans = [(1, 2, 2, 2), (2, 1, 2, 2)] f = [[1] * 9 for i in range(7)] f[1][2] = f[2][2] = f[2][6] = f[3][5] = 0 f[4][5] = f[4][6] = f[5][2] = f[5][5] = f[5][6] = 0 p = [0...
{ "language": "python", "test_cases": [ { "input": "3\n", "output": "4 4\n5\n1 2 2 2\n1 3 2 3\n1 4 2 4\n2 1 2 2\n4 1 4 2\n", "type": "stdin_stdout" }, { "input": "4\n", "output": "4 4\n4\n1 2 2 2\n1 3 2 3\n2 1 2 2\n4 1 4 2\n", "type": "stdin_stdout" }, { ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/715/D" }
vfc_6558
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...
{ "language": "python", "test_cases": [ { "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...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/704/A" }
vfc_6562
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) ```
{ "language": "python", "test_cases": [ { "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": "stdi...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1109/A" }
vfc_6566
apps
verifiable_code
2256
Solve the following coding problem using the programming language python: This morning Tolik has understood that while he was sleeping he had invented an incredible problem which will be a perfect fit for Codeforces! But, as a "Discuss tasks" project hasn't been born yet (in English, well), he decides to test a proble...
```python import sys input = sys.stdin.readline n,m=list(map(int,input().split())) ANS=[] for i in range(1,n//2+1): for j in range(1,m+1): sys.stdout.write("".join((str(i)," ",str(j),"\n"))) sys.stdout.write("".join((str(n-i+1)," ",str(m-j+1),"\n"))) if n%2==1: for j in range(1,m//2+1): ...
{ "language": "python", "test_cases": [ { "input": "2 3\n", "output": "1 1\n1 3\n1 2\n2 2\n2 3\n2 1", "type": "stdin_stdout" }, { "input": "1 1\n", "output": "1 1\n", "type": "stdin_stdout" }, { "input": "8 8\n", "output": "1 1\n8 8\n1 2\n8 7\n1 3\...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1179/B" }
vfc_6570
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...
{ "language": "python", "test_cases": [ { "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\n...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1383/A" }
vfc_6574
apps
verifiable_code
2258
Solve the following coding problem using the programming language python: You are given a rectangular parallelepiped with sides of positive integer lengths $A$, $B$ and $C$. Find the number of different groups of three integers ($a$, $b$, $c$) such that $1\leq a\leq b\leq c$ and parallelepiped $A\times B\times C$ ca...
```python N=100001 fac=[0 for i in range(N)] for i in range(1,N): for j in range(i,N,i): fac[j]+=1 def gcd(a,b): if a<b: a,b=b,a while b>0: a,b=b,a%b return a def ctt(A,B,C): la=fac[A] lb=fac[B] lc=fac[C] ab=gcd(A,B) ac=gcd(A,C) bc=gcd(...
{ "language": "python", "test_cases": [ { "input": "4\n1 1 1\n1 6 1\n2 2 2\n100 100 100\n", "output": "1\n4\n4\n165\n", "type": "stdin_stdout" }, { "input": "10\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n1 1 1\n", "output": "1\n1\n1\n1\n1\n1\n1\n1\n1\n1...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1007/B" }
vfc_6578
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): ...
{ "language": "python", "test_cases": [ { "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" }, {...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1404/C" }
vfc_6582
apps
verifiable_code
2260
Solve the following coding problem using the programming language python: There are $n$ football teams in the world. The Main Football Organization (MFO) wants to host at most $m$ games. MFO wants the $i$-th game to be played between the teams $a_i$ and $b_i$ in one of the $k$ stadiums. Let $s_{ij}$ be the numbers...
```python import random import math def set_color(game, color): color_count[game[0]][game[2]] -= 1 color_count[game[1]][game[2]] -= 1 game[2] = color color_count[game[0]][game[2]] += 1 color_count[game[1]][game[2]] += 1 def fix(node): minimum = math.inf maximum = 0 for i in range(k): ...
{ "language": "python", "test_cases": [ { "input": "7 11 3\n4 7 8 10 10 9 3\n6 2\n6 1\n7 6\n4 3\n4 6\n3 1\n5 3\n7 5\n7 3\n4 2\n1 4\n", "output": "3\n1\n3\n2\n2\n2\n1\n2\n3\n1\n1\n", "type": "stdin_stdout" }, { "input": "100 0 1\n629 909 904 632 485 339 719 758 724 769 180 866 743...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1240/F" }
vfc_6586
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...
{ "language": "python", "test_cases": [ { "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 6...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/372/C" }
vfc_6590
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") ```
{ "language": "python", "test_cases": [ { "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\n...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1344/A" }
vfc_6638
apps
verifiable_code
2274
Solve the following coding problem using the programming language python: Allen and Bessie are playing a simple number game. They both know a function $f: \{0, 1\}^n \to \mathbb{R}$, i. e. the function takes $n$ binary arguments and returns a real value. At the start of the game, the variables $x_1, x_2, \dots, x_n$ a...
```python n, r = [int(x) for x in input().split()] n = 2 ** n xs = [int(x) for x in input().split()] s = sum(xs) res = [0 for _ in range(r+1)] for i in range(r): res[i] = s / n i, val = [int(x) for x in input().split()] s += val - xs[i] xs[i] = val res[r] = s / n print("\n".join(map(str, res))) ```
{ "language": "python", "test_cases": [ { "input": "2 2\n0 1 2 3\n2 5\n0 4\n", "output": "1.500000\n2.250000\n3.250000\n", "type": "stdin_stdout" }, { "input": "1 0\n2 3\n", "output": "2.500000\n", "type": "stdin_stdout" }, { "input": "2 0\n1 1 1 1\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/995/D" }
vfc_6642
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 ...
{ "language": "python", "test_cases": [ { "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" }, ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1361/B" }
vfc_6646
apps
verifiable_code
2276
Solve the following coding problem using the programming language python: This is an easier version of the next problem. The difference is only in constraints. You are given a rectangular $n \times m$ matrix $a$. In one move you can choose any column and cyclically shift elements in this column. You can perform this ...
```python rnd_mod = 1234567890133 rnd_x = 987654321098 def rnd(): nonlocal rnd_x rnd_x = rnd_x**2 % rnd_mod return (rnd_x>>5) % (1<<20) def randrange(a): return rnd() % a T = int(input()) for _ in range(T): N, M = list(map(int, input().split())) X = [] for __ in range(N): X.append([...
{ "language": "python", "test_cases": [ { "input": "2\n2 3\n2 5 7\n4 2 4\n3 6\n4 1 5 2 10 4\n8 6 6 4 9 10\n5 4 9 5 8 7\n", "output": "12\n29\n", "type": "stdin_stdout" }, { "input": "40\n2 2\n5 2\n1 5\n1 1\n3\n1 2\n1 1\n1 2\n1 1\n1 2\n2 3\n2 1\n1\n1\n1 1\n1\n2 1\n1\n1\n1 2\n2 3\n...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1209/E1" }
vfc_6650
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): """ ...
{ "language": "python", "test_cases": [ { "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", "outp...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1142/C" }
vfc_6658
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...
{ "language": "python", "test_cases": [ { "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 ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1423/K" }
vfc_6662
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) ...
{ "language": "python", "test_cases": [ { "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" }, {...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1264/C" }
vfc_6666
apps
verifiable_code
2282
Solve the following coding problem using the programming language python: A rectangle with sides $A$ and $B$ is cut into rectangles with cuts parallel to its sides. For example, if $p$ horizontal and $q$ vertical cuts were made, $(p + 1) \cdot (q + 1)$ rectangles were left after the cutting. After the cutting, rectang...
```python n =int(input()) w=[] h=[] c=[] cntw={} cnth={} gcdC=0 cntC=0 def insert1(a,b,c): if not a in b : b[a]=c else : b[a]=b[a]+c def gcd(a,b): if a % b == 0 : return b else : return gcd(b,a%b) for i in range(0, n): a,b,d = map(int,input().split()) w.append(a) h.append(b) c.append(d) insert1(a,cn...
{ "language": "python", "test_cases": [ { "input": "1\n1 1 9\n", "output": "3\n", "type": "stdin_stdout" }, { "input": "2\n2 3 20\n2 4 40\n", "output": "6\n", "type": "stdin_stdout" }, { "input": "2\n1 2 5\n2 3 5\n", "output": "0\n", "type": ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/963/C" }
vfc_6674
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...
{ "language": "python", "test_cases": [ { "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_st...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1404/B" }
vfc_6678
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...
{ "language": "python", "test_cases": [ { "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" }, ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1290/B" }
vfc_6682
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): ...
{ "language": "python", "test_cases": [ { "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...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1209/C" }
vfc_6686
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 >...
{ "language": "python", "test_cases": [ { "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", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1208/E" }
vfc_6778
apps
verifiable_code
2309
Solve the following coding problem using the programming language python: Masha and Grisha like studying sets of positive integers. One day Grisha has written a set A containing n different integers a_{i} on a blackboard. Now he asks Masha to create a set B containing n different integers b_{j} such that all n^2 inte...
```python d = [-1] * 1000001 for t in range(int(input())): n, a = int(input()), list(map(int, input().split())) a.sort() for i in range(n): for j in range(i + 1, n): d[a[j] - a[i]] = t i = 1 while any(d[i * j] == t for j in range(1, n)): i += 1 print("YES\n" + ' '.join(str(j * i + 1) fo...
{ "language": "python", "test_cases": [ { "input": "3\n3\n1 10 100\n1\n1\n2\n2 4\n", "output": "YES\n1 2 3 \nYES\n1 \nYES\n1 2 \n", "type": "stdin_stdout" }, { "input": "1\n100\n74 14 24 45 22 9 49 78 79 20 60 1 31 91 32 39 90 5 42 57 30 58 64 68 12 11 86 8 3 38 76 17 98 26 85 92...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/856/A" }
vfc_6782
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...
{ "language": "python", "test_cases": [ { "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", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/329/D" }
vfc_6786
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): ...
{ "language": "python", "test_cases": [ { "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", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/932/B" }
vfc_6790
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 =...
{ "language": "python", "test_cases": [ { "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", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1168/C" }
vfc_6794
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...
{ "language": "python", "test_cases": [ { "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", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/319/C" }
vfc_6798
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][...
{ "language": "python", "test_cases": [ { "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", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/983/B" }
vfc_6802
apps
verifiable_code
2315
Solve the following coding problem using the programming language python: Vasya has written some permutation $p_1, p_2, \ldots, p_n$ of integers from $1$ to $n$, so for all $1 \leq i \leq n$ it is true that $1 \leq p_i \leq n$ and all $p_1, p_2, \ldots, p_n$ are different. After that he wrote $n$ numbers $next_1, next...
```python import sys input = sys.stdin.readline T = int(input()) for _ in range(T): n = int(input()) l = list(map(int, input().split())) stack = [] out = [-1] * n curr = 0 works = True for i in range(n): while stack and stack[-1][0] == i: _, j = stack.pop() ...
{ "language": "python", "test_cases": [ { "input": "6\n3\n2 3 4\n2\n3 3\n3\n-1 -1 -1\n3\n3 4 -1\n1\n2\n4\n4 -1 4 5\n", "output": "1 2 3 \n2 1 \n1 2 3 \n-1\n1 \n3 1 2 4 \n", "type": "stdin_stdout" }, { "input": "10\n4\n2 4 4 5\n4\n2 -1 4 -1\n4\n4 5 5 5\n4\n2 3 4 5\n4\n2 3 4 5\n4\n...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1158/C" }
vfc_6806
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]: ...
{ "language": "python", "test_cases": [ { "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", "type": "stdin_stdout" ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1383/B" }
vfc_6810
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,...
{ "language": "python", "test_cases": [ { "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-1000...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1338/A" }
vfc_6814
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) ```
{ "language": "python", "test_cases": [ { "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", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/314/A" }
vfc_6818
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...
{ "language": "python", "test_cases": [ { "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 ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1442/B" }
vfc_6822
apps
verifiable_code
2320
Solve the following coding problem using the programming language python: Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element am...
```python """ Author : Arif Ahmad Date : Algo : Difficulty : """ from sys import stdin, stdout, setrecursionlimit import threading def main(): m = int(stdin.readline().strip()) a = [int(_) for _ in stdin.readline().strip().split()] b = [int(_) for _ in stdin.readline...
{ "language": "python", "test_cases": [ { "input": "5\n7 3 5 3 4\n2 1 3 2 3\n", "output": "4 7 3 5 3\n", "type": "stdin_stdout" }, { "input": "7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2\n", "output": "2 6 4 5 8 8 6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/840/A" }
vfc_6826
apps
verifiable_code
2322
Solve the following coding problem using the programming language python: You are working for the Gryzzl company, headquartered in Pawnee, Indiana. The new national park has been opened near Pawnee recently and you are to implement a geolocation system, so people won't get lost. The concept you developed is innovativ...
```python import sys import math n = int(input()) x = [0]*n y = [0]*n for i in range(n): x[i], y[i] = list(map(int, input().split())) sx = sum(x) sy = sum(y) for i in range(n): x[i] = n * x[i] - sx y[i] = n * y[i] - sy m = int(input()) d = [0]*n e = [0]*n HD = 0 def check(a, b): nonlocal HD...
{ "language": "python", "test_cases": [ { "input": "3\n0 0\n0 1\n1 0\n1\n1 1 2\n", "output": "1 1 1 \n", "type": "stdin_stdout" }, { "input": "4\n0 0\n0 1\n1 0\n1 1\n2\n0 1 1 2\n2 5 5 8\n", "output": "4 0 0 0 1 1 0 1 1 \n4 -1 -1 -1 2 2 -1 2 2 \n", "type": "stdin_stdou...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1220/G" }
vfc_6834
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...
{ "language": "python", "test_cases": [ { "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...
{ "difficulty": "competition", "problem_url": "https://www.codechef.com/OCT15/problems/MGCHGYM" }
vfc_6858
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 ...
{ "language": "python", "test_cases": [ { "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", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://www.codechef.com/LTIME34/problems/ARRAYSUM" }
vfc_6862
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(...
{ "language": "python", "test_cases": [ { "input": "3\nAAA\nBABA\nAABBBABBBB\n", "output": "3\n2\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1428/C" }
vfc_6882
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...
{ "language": "python", "test_cases": [ { "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", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1340/A" }
vfc_6886
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...
{ "language": "python", "test_cases": [ { "input": "5\n2 4 5 1 3\n", "output": "Petr\n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/986/B" }
vfc_6890
apps
verifiable_code
2338
Solve the following coding problem using the programming language python: This is the hard version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and...
```python import sys input = sys.stdin.readline from collections import deque t=int(input()) for tests in range(t): n=int(input()) a=input().strip() b=input().strip() Q=deque(a) L=[] while Q: L.append(Q.popleft()) if Q: L.append(Q.pop()) ANS=[] for i in...
{ "language": "python", "test_cases": [ { "input": "5\n2\n01\n10\n5\n01011\n11100\n2\n01\n01\n10\n0110011011\n1000110100\n1\n0\n1\n", "output": "3 1 2 1 \n8 1 5 1 4 1 3 2 1 \n3 2 1 1 \n19 1 10 1 9 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 \n1 1 \n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1381/A2" }
vfc_6898
apps
verifiable_code
2339
Solve the following coding problem using the programming language python: This is the easy version of the problem. The difference between the versions is the constraint on $n$ and the required number of operations. You can make hacks only if all versions of the problem are solved. There are two binary strings $a$ and...
```python import sys input = sys.stdin.readline from collections import deque t=int(input()) for tests in range(t): n=int(input()) a=input().strip() b=input().strip() Q=deque(a) L=[] while Q: L.append(Q.popleft()) if Q: L.append(Q.pop()) ANS=[] for i in...
{ "language": "python", "test_cases": [ { "input": "5\n2\n01\n10\n5\n01011\n11100\n2\n01\n01\n10\n0110011011\n1000110100\n1\n0\n1\n", "output": "3 1 2 1 \n8 1 5 1 4 1 3 2 1 \n3 2 1 1 \n19 1 10 1 9 1 8 1 7 1 6 1 5 1 4 1 3 1 2 1 \n1 1 \n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1381/A1" }
vfc_6902
apps
verifiable_code
2340
Solve the following coding problem using the programming language python: Let $a$ and $b$ be two arrays of lengths $n$ and $m$, respectively, with no elements in common. We can define a new array $\mathrm{merge}(a,b)$ of length $n+m$ recursively as follows: If one of the arrays is empty, the result is the other array...
```python t = int(input()) for _ in range(t): n = int(input()) l = [int(x) for x in input().split()] cur = l[0] cll = 1 blocks = [] for x in l[1:]: if x > cur: blocks.append(cll) cur = x cll = 1 else: cll += 1 blocks.append(cll...
{ "language": "python", "test_cases": [ { "input": "6\n2\n2 3 1 4\n2\n3 1 2 4\n4\n3 2 6 1 5 7 8 4\n3\n1 2 3 4 5 6\n4\n6 1 3 7 4 5 8 2\n6\n4 3 2 5 1 11 9 12 8 6 10 7\n", "output": "YES\nNO\nYES\nYES\nNO\nNO\n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1381/B" }
vfc_6906
apps
verifiable_code
2341
Solve the following coding problem using the programming language python: You and your $n - 1$ friends have found an array of integers $a_1, a_2, \dots, a_n$. You have decided to share it in the following way: All $n$ of you stand in a line in a particular order. Each minute, the person at the front of the line choose...
```python import sys readline = sys.stdin.readline class Segtree: def __init__(self, A, intv, initialize = True, segf = max): self.N = len(A) self.N0 = 2**(self.N-1).bit_length() self.intv = intv self.segf = segf if initialize: self.data = [intv]*self.N0 + A + [i...
{ "language": "python", "test_cases": [ { "input": "4\n6 4 2\n2 9 2 3 8 5\n4 4 1\n2 13 60 4\n4 1 3\n1 2 2 1\n2 2 0\n1 2\n", "output": "8\n4\n1\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1290/A" }
vfc_6910
apps
verifiable_code
2342
Solve the following coding problem using the programming language python: You are given an array $a$ of $n$ positive integers. You can use the following operation as many times as you like: select any integer $1 \le k \le n$ and do one of two things: decrement by one $k$ of the first elements of the array. decreme...
```python import sys input = sys.stdin.readline for _ in range(int(input())): n = int(input()) a = list(map(int,input().split())) for i in range(n-1,0,-1): a[i] -= a[i-1] minus = 0 for i in range(1,n): if a[i]<0: minus -= a[i] if a[0] - minus >=0: print("Y...
{ "language": "python", "test_cases": [ { "input": "4\n3\n1 2 1\n5\n11 7 9 6 8\n5\n1 3 1 3 1\n4\n5 2 1 10\n", "output": "YES\nYES\nNO\nYES\n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1442/A" }
vfc_6914
apps
verifiable_code
2343
Solve the following coding problem using the programming language python: Dreamoon likes sequences very much. So he created a problem about the sequence that you can't find in OEIS: You are given two integers $d, m$, find the number of arrays $a$, satisfying the following constraints: The length of $a$ is $n$, $n \...
```python t = int(input()) for _ in range(t): d, m = list(map(int, input().split())) d += 1 out = 1 curr = 2 while curr < d: out *= (curr // 2) + 1 out %= m curr *= 2 out *= (d - curr // 2 + 1) print((out - 1) % m) ```
{ "language": "python", "test_cases": [ { "input": "10\n1 1000000000\n2 999999999\n3 99999998\n4 9999997\n5 999996\n6 99995\n7 9994\n8 993\n9 92\n10 1\n", "output": "1\n3\n5\n11\n17\n23\n29\n59\n89\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1329/B" }
vfc_6918
apps
verifiable_code
2346
Solve the following coding problem using the programming language python: The USA Construction Operation (USACO) recently ordered Farmer John to arrange a row of $n$ haybale piles on the farm. The $i$-th pile contains $a_i$ haybales. However, Farmer John has just left for vacation, leaving Bessie all on her own. Eve...
```python import sys #sys.stdin=open("data.txt") input=sys.stdin.readline mii=lambda:list(map(int,input().split())) for _ in range(int(input())): n,d=mii() a=list(mii()) ans=0 for i in range(n): while d>=i and a[i]: a[i]-=1 ans+=1 d-=i print(ans) ```
{ "language": "python", "test_cases": [ { "input": "3\n4 5\n1 0 3 2\n2 2\n100 1\n1 8\n0\n", "output": "3\n101\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1307/A" }
vfc_6930
apps
verifiable_code
2347
Solve the following coding problem using the programming language python: A bitstring is a string consisting only of the characters 0 and 1. A bitstring is called $k$-balanced if every substring of size $k$ of this bitstring has an equal amount of 0 and 1 characters ($\frac{k}{2}$ of each). You are given an integer $...
```python import sys input = sys.stdin.readline t = int(input()) for _ in range(t): n, k = list(map(int, input().split())) s = input() l = ['']*k works = True for i in range(n): c = s[i] if c != '?': if l[i%k] == c or l[i%k] == '': l[i%k] = c ...
{ "language": "python", "test_cases": [ { "input": "9\n6 4\n100110\n3 2\n1?1\n3 2\n1?0\n4 4\n????\n7 4\n1?0??1?\n10 10\n11??11??11\n4 2\n1??1\n4 4\n?0?0\n6 2\n????00\n", "output": "YES\nYES\nNO\nYES\nYES\nNO\nNO\nYES\nNO\n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/1404/A" }
vfc_6934
apps
verifiable_code
2349
Solve the following coding problem using the programming language python: The Chef has one long loaf of bread of length 1. He wants to cut it into as many little loaves as he can. But he wants to adhere to the following rule: At any moment, the length of the longest loaf which he possesses may not be larger than the l...
```python import sys from math import log k = float(sys.stdin.readline()) answer = int(log(2.0, 2.0/k)) print(2*answer) m = 2 ** (1.0/answer) # m = 2.0/k thesum = 0 for i in range(answer): thesum += m**i # print [m**i/thesum for i in xrange(answer)] loaves = [1] def maxIndex(list): max = -1 mi = -1 for i, x in e...
{ "language": "python", "test_cases": [ { "input": "1.5\n", "output": "4\n0 0.4\n0 0.3\n1 0.2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://www.codechef.com/AUG09/problems/F6" }
vfc_6942
apps
verifiable_code
2350
Solve the following coding problem using the programming language python: A hypergraph is a generalization of a graph, where an edge can connect any number of vertices. A k-uniform hypergraph is a hypergraph such that all its hyperedges have size k. For more information, see Wikipedia. Let's call a particular hypergr...
```python """ #this code is a precomputation part. #it takes about 2 hours. class Graph: def __init__(self,n): self.edge=[[0 for j in xrange(n)] for i in xrange(n)] self.n=n def addedge(self,i,j,m=1): assert i!=j and 0<=i<self.n and 0<=j<self.n self.edge[i][j]+=m self.edge[j][i]+=m def dele...
{ "language": "python", "test_cases": [ { "input": "4\n3\n4\n5\n8\n\n\n", "output": "1\n6\n25\n93268\n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://www.codechef.com/DEC11/problems/HYPER" }
vfc_6946
apps
verifiable_code
2351
Solve the following coding problem using the programming language python: The Chef has been kidnapped by aliens ( they want to utilize his excellent cooking skills :P ) and has been transported to the alien planet "ZX532". Interestingly, "ZX532" uses a different time scale which has Y AlienHours on the face of a clock...
```python import decimal; from decimal import *; def solve(a, b, min1, min2, min3, min4, x, y): if a > b: return []; solMin1 = (a/y+b)/(y-1/y); solMin2 = (b/y+a)/(y-1/y); solMin1 *= (x*y); solMin2 *= (x*y); if solMin1 >= min1 and solMin1 <= min2 and solMin2 >= min3 and solMin2 <= min4: # Solution found re...
{ "language": "python", "test_cases": [ { "input": "3\n5 12\n1 0 2 0 4 0 5 0\n5 12\n3 30 4 0 5 0 6 0\n5 12\n3 0 4 0 5 0 6 0\n\n\n", "output": "1:20.56\n-1\n3:26.43\n", "type": "stdin_stdout" } ] }
{ "difficulty": "competition", "problem_url": "https://www.codechef.com/JUNE09/problems/D7" }
vfc_6950
apps
verifiable_code
2352
Solve the following coding problem using the programming language python: Vasya is an active Internet user. One day he came across an Internet resource he liked, so he wrote its address in the notebook. We know that the address of the written resource has format: <protocol>://<domain>.ru[/<context>] where: <protoco...
```python s="" L=[] s=input() k=0 r=0 c=0 if s[0]=='h': L.append('http://') c=4 s=s[c:] elif s[0]=='f': L.append('ftp://') c=3 s=s[c:] r=s.find('ru',1) L.append(s[:r]) L.append('.ru') k=r+2 if k<len(s): L.append('/') L.append(s[k:]) print(''.join(L)) ```
{ "language": "python", "test_cases": [ { "input": "httpsunrux\n", "output": "http://sun.ru/x\n", "type": "stdin_stdout" }, { "input": "ftphttprururu\n", "output": "ftp://http.ru/ruru\n", "type": "stdin_stdout" }, { "input": "httpuururrururruruurururrrrr...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/245/B" }
vfc_6954
apps
verifiable_code
2353
Solve the following coding problem using the programming language python: You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x_1, x_2, ..., x_{k}} (1 ≤ x_{i} ≤ n, 0 < k < n) the sums of elements on that positions in a and b are di...
```python n, a = int(input()), [int(i) for i in input().split()] b, m = a[:], dict() b.sort() for i in range(len(b) - 1): m[b[i]] = b[i + 1] m[b[-1]] = b[0] for i in range(len(a)): a[i] = m[a[i]] if len(set(b)) == n: print(*a) else: print(-1) ```
{ "language": "python", "test_cases": [ { "input": "2\n1 2\n", "output": "2 1 \n", "type": "stdin_stdout" }, { "input": "4\n1000 100 10 1\n", "output": "100 1 1000 10\n", "type": "stdin_stdout" }, { "input": "5\n1 3 4 5 2\n", "output": "5 2 3 4 1 \...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/891/B" }
vfc_6958
apps
verifiable_code
2354
Solve the following coding problem using the programming language python: As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lo...
```python s = input() n = int(input()) a = [input() for i in range(n)] for i in range(n): for j in range(n): if a[i] == s or a[i][1] + a[j][0] == s: print("YES") return print("NO") ```
{ "language": "python", "test_cases": [ { "input": "ya\n4\nah\noy\nto\nha\n", "output": "YES\n", "type": "stdin_stdout" }, { "input": "hp\n2\nht\ntp\n", "output": "NO\n", "type": "stdin_stdout" }, { "input": "ah\n1\nha\n", "output": "YES\n", ...
{ "difficulty": "competition", "problem_url": "https://codeforces.com/problemset/problem/868/A" }
vfc_6962
apps
verifiable_code
2361
Solve the following coding problem using the programming language python: You are given an array $a$ of length $n$ consisting of zeros. You perform $n$ actions with this array: during the $i$-th action, the following sequence of operations appears: Choose the maximum by length subarray (continuous subsegment) consist...
```python from collections import defaultdict as dd from collections import deque import bisect import heapq def ri(): return int(input()) def rl(): return list(map(int, input().split())) def solve(): n = ri() output = [0] * (n) Q = [(-n, 0 ,n - 1)] for i in range(1, n + 1): prev = ...
{ "language": "python", "test_cases": [ { "input": "6\n1\n2\n3\n4\n5\n6\n", "output": "1 \n1 2 \n2 1 3 \n3 1 2 4 \n2 4 1 3 5 \n3 4 1 5 2 6 \n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1353/D" }
vfc_6990
apps
verifiable_code
2362
Solve the following coding problem using the programming language python: $n$ robots have escaped from your laboratory! You have to find them as soon as possible, because these robots are experimental, and their behavior is not tested yet, so they may be really dangerous! Fortunately, even though your robots have esc...
```python def main(): import sys input = sys.stdin.readline def solve(): n = int(input()) maxx = 10**5 minx = -10**5 maxy = 10**5 miny = -10**5 for _ in range(n): x, y, f1, f2, f3, f4 = map(int, input().split()) if not f1:...
{ "language": "python", "test_cases": [ { "input": "4\n2\n-1 -2 0 0 0 0\n-1 -2 0 0 0 0\n3\n1 5 1 1 1 1\n2 5 0 1 0 1\n3 5 1 0 0 0\n2\n1337 1337 0 1 1 1\n1336 1337 1 1 0 1\n1\n3 5 1 1 1 1\n", "output": "1 -1 -2\n1 2 5\n0\n1 -100000 -100000\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1196/C" }
vfc_6994
apps
verifiable_code
2363
Solve the following coding problem using the programming language python: There are $n$ athletes in front of you. Athletes are numbered from $1$ to $n$ from left to right. You know the strength of each athlete — the athlete number $i$ has the strength $s_i$. You want to split all athletes into two teams. Each team mu...
```python T = int(input()) for _ in range(T): a = int(input()) hh = sorted(map(int, input().split())) ans = 10**10 for h1, h2 in zip(hh[:-1], hh[1:]): ans = min(ans, h2 - h1) print(ans) ```
{ "language": "python", "test_cases": [ { "input": "5\n5\n3 1 2 6 4\n6\n2 1 3 2 4 3\n4\n7 9 3 1\n2\n1 1000\n3\n100 150 200\n", "output": "1\n0\n2\n999\n50\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1360/B" }
vfc_6998
apps
verifiable_code
2364
Solve the following coding problem using the programming language python: You are given an undirected unweighted graph consisting of $n$ vertices and $m$ edges (which represents the map of Bertown) and the array of prices $p$ of length $m$. It is guaranteed that there is a path between each pair of vertices (districts...
```python import sys from collections import deque input = sys.stdin.readline t = int(input()) for _ in range(t): n, m, a, b, c = list(map(int,input().split())) p = list(map(int, input().split())) p.sort() pref = [0] curr = 0 for i in range(m): curr += p[i] pref.append(curr...
{ "language": "python", "test_cases": [ { "input": "2\n4 3 2 3 4\n1 2 3\n1 2\n1 3\n1 4\n7 9 1 5 7\n2 10 4 8 5 6 7 3 3\n1 2\n1 3\n1 4\n3 2\n3 5\n4 2\n5 6\n1 7\n6 7\n", "output": "7\n12\n", "type": "stdin_stdout" } ] }
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1343/E" }
vfc_7002
apps
verifiable_code
2365
Solve the following coding problem using the programming language python: We guessed a permutation $p$ consisting of $n$ integers. The permutation of length $n$ is the array of length $n$ where each element from $1$ to $n$ appears exactly once. This permutation is a secret for you. For each position $r$ from $2$ to $...
```python import sys input = sys.stdin.readline def dfs(x,S): #print(x,S) for i in range(len(S)): if x in S[i]: S[i].remove(x) #print(x,S) LEN1=0 for s in S: if len(s)==1: LEN1+=1 ne=list(s)[0] if LEN1==2: return [-1]...
{ "language": "python", "test_cases": [ { "input": "5\n6\n3 2 5 6\n2 4 6\n3 1 3 4\n2 1 3\n4 1 2 4 6\n5\n2 2 3\n2 1 2\n2 1 4\n2 4 5\n7\n3 1 2 6\n4 1 3 5 6\n2 1 2\n3 4 5 7\n6 1 2 3 4 5 6\n3 1 3 6\n2\n2 1 2\n5\n2 2 5\n3 2 3 5\n4 2 3 4 5\n5 1 2 3 4 5\n", "output": "3 1 4 6 2 5 \n3 2 1 4 5 \n2 1 6 3 5 4 ...
{ "difficulty": "introductory", "problem_url": "https://codeforces.com/problemset/problem/1343/F" }
vfc_7006