source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
code_contests
verifiable_code
215_E. Periodical Numbers
Solve the following coding problem using the programming language python: A non-empty string s is called binary, if it consists only of characters "0" and "1". Let's number the characters of binary string s from 1 to the string's length and let's denote the i-th character in string s as si. Binary string s with lengt...
```python from itertools import combinations from fractions import gcd #Numeros primos hasta el 59 primos = [2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59] #Para obtener la cadena binaria de x. def ToBinary(x): if x == 0: return "0" if x == 1: return "1" if x % 2 == 0: return ToBi...
vfc_67649
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "25 38\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3011...
code_contests
verifiable_code
239_E. World Eater Brothers
Solve the following coding problem using the programming language python: You must have heard of the two brothers dreaming of ruling the world. With all their previous plans failed, this time they decided to cooperate with each other in order to rule the world. As you know there are n countries in the world. These c...
vfc_67653
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 1\n3 1\n4 1\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
264_C. Choosing Balls
Solve the following coding problem using the programming language python: There are n balls. They are arranged in a row. Each ball has a color (for convenience an integer) and an integer value. The color of the i-th ball is ci and the value of the i-th ball is vi. Squirrel Liss chooses some balls and makes a new sequ...
```python import sys range = xrange input = raw_input inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 n = inp[ii]; ii += 1 q = inp[ii]; ii += 1 V = [float(x) for x in inp[ii:ii + n]]; ii += n C = [c - 1 for c in inp[ii:ii + n]]; ii += n A = inp[ii::2] B = inp[ii+1::2] inf = 1e30 out = [] for _ in range(...
vfc_67657
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1\n-3 6 -1 2\n1 2 3 1\n1 -1\n", "output": " 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3\n1 -2 3 4 0 -1\n1 2 1 2 1 ...
code_contests
verifiable_code
288_C. Polo the Penguin and XOR operation
Solve the following coding problem using the programming language python: Little penguin Polo likes permutations. But most of all he likes permutations of integers from 0 to n, inclusive. For permutation p = p0, p1, ..., pn, Polo has defined its beauty — number <image>. Expression <image> means applying the operatio...
```python from bisect import insort,bisect_right,bisect_left from sys import stdout, stdin, setrecursionlimit from math import sqrt,ceil,floor,factorial,gcd,log2,log10 from io import BytesIO, IOBase from collections import * from itertools import * from random import * from string import * from queue import * from hea...
vfc_67661
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "20\n0 2 1 4 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "17\n", "output": "306\n1 0 13 12 11 10 9 8 7 6 5 4 3 2 17 16 15 14 ", "type": "stdin_stdout" }...
code_contests
verifiable_code
313_C. Ilya and Matrix
Solve the following coding problem using the programming language python: Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve. He's got a square 2n × 2n-sized matrix and 4n integers. You need to arr...
```python import os import sys from io import BytesIO, IOBase 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 self.write = self.buffer.wri...
vfc_67665
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n13\n", "output": "13", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 3 4\n", "output": "14", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
335_F. Buy One, Get One Free
Solve the following coding problem using the programming language python: A nearby pie shop is having a special sale. For each pie you pay full price for, you may select one pie of a strictly lesser value to get for free. Given the prices of all the pies you wish to acquire, determine the minimum total amount you must...
```python #https://codeforces.com/problemset/problem/335/F h = [i for i in range(500001)] t = [i for i in range(500001)] ans = 0 len = 0 nw = 0 tot = 0 cnt = 0 a = [] def work(x): y = x >> 1 while y and h[y] > h[x]: tmp = h[x] h[x] = h[y] h[y] = tmp x = y y = x >> 1 de...
vfc_67669
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n309999 6000 2080 2080\n", "output": "314159\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n5 5 5 5 5\n", "output": "25\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
381_E. Sereja and Brackets
Solve the following coding problem using the programming language python: Sereja has a bracket sequence s1, s2, ..., sn, or, in other words, a string s of length n, consisting of characters "(" and ")". Sereja needs to answer m queries, each of them is described by two integers li, ri (1 ≤ li ≤ ri ≤ n). The answer to...
vfc_67677
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "())(())(())(\n7\n1 1\n2 3\n1 2\n1 12\n8 12\n5 11\n2 10\n", "output": "0\n0\n2\n10\n4\n6\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "))(()))))())())))))())((()()))))()))))))))))))\n9...
code_contests
verifiable_code
402_D. Upgrading Array
Solve the following coding problem using the programming language python: You have an array of positive integers a[1], a[2], ..., a[n] and a set of bad prime numbers b1, b2, ..., bm. The prime numbers that do not occur in the set b are considered good. The beauty of array a is the sum <image>, where function f(s) is d...
```python from sys import stdin from collections import * from fractions import gcd def lowest_prime(x): if mem[x]: return mem[x] for i in primes: if i * i > x: mem[x] = x return x elif x % i == 0: mem[x] = i return i # mem[x] = x ...
vfc_67681
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5\n2 4 8 16\n3 5 7 11 17\n", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n4 20 34 10 10\n2 5\n", "output": "-2", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
42_E. Baldman and the military
Solve the following coding problem using the programming language python: Baldman is a warp master. He possesses a unique ability — creating wormholes! Given two positions in space, Baldman can make a wormhole which makes it possible to move between them in both directions. Unfortunately, such operation isn't free for...
vfc_67685
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n1 2 3\n2\n1 2\n1 3\n", "output": "-1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n1 2 3\n1\n1 2\n", "output": "0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
452_C. Magic Trick
Solve the following coding problem using the programming language python: Alex enjoys performing magic tricks. He has a trick that requires a deck of n cards. He has m identical decks of n different cards each, which have been mixed together. When Alex wishes to perform the trick, he grabs n cards at random and perfor...
```python import sys import os n,m = map(float, sys.stdin.readline().split()) res = 0 if (n == 1): res = 1 else: res = (1+(n-1)*(m-1)/(n*m-1))/n print(res) ```
vfc_67689
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n", "output": "0.399999999999999967\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
475_A. Bayan Bus
Solve the following coding problem using the programming language python: The final round of Bayan Programming Contest will be held in Tehran, and the participants will be carried around with a yellow bus. The bus has 34 passenger seats: 4 seats in the last row and 3 seats in remaining rows. <image> The event coord...
```python def main(): n = int(input()) print("+------------------------+") b1 = 0 if n == 0: b1 = 0 elif 1 <= n <= 4: b1 = 1 else: b1 = (n + 1) // 3 if 0 <= n <= 1: b2 = 0 elif 2 <= n <= 5: b2 = 1 else: b2 = n // 3 b3 = 0 if n <...
vfc_67693
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n", "output": "+------------------------+\n|O.O.O.#.#.#.#.#.#.#.#.|D|)\n|O.O.O.#.#.#.#.#.#.#.#.|.|\n|O.......................|\n|O.O.#.#.#.#.#.#.#.#.#.|.|)\n+------------------------+\n", "type": "stdin_stdout" },...
code_contests
verifiable_code
499_A. Watching a movie
Solve the following coding problem using the programming language python: You have decided to watch the best moments of some movie. There are two buttons on your player: 1. Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceed...
```python class CodeforcesTask499ASolution: def __init__(self): self.result = '' self.n_x = [] self.best_moments = [] def read_input(self): self.n_x = [int(x) for x in input().split(" ")] for x in range(self.n_x[0]): self.best_moments.append([int(j) for j in ...
vfc_67697
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n5 6\n10 12\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1 100000\n", "output": "100000\n", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
522_B. Photo to Remember
Solve the following coding problem using the programming language python: One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend...
```python h,w=[],[] n=int(input()) for i in range(n): a,b=map(int,input().split()) w.append(a) h.append(b) maxh=max(h) maxh2=-1 if h.count(maxh)>1: maxh2=maxh else: for i in h: if i<maxh: maxh2=max(maxh2,i) sumw=sum(w) for i in range(n): W=sumw-w[i] if h[i]==maxh: H=maxh2 ...
vfc_67701
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 10\n5 5\n10 1\n", "output": "75 110 60 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 1\n1 2\n2 1\n", "output": "6 4 6 ", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
549_D. Haar Features
Solve the following coding problem using the programming language python: The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified m...
```python n,m=map(int,input().strip().split()) s=[] for i in range(n): s.append(input()) f=[[0 for i in range(m+1)] for j in range(n+1)] ans=0 for k in range(n+m,1,-1): for i in range(n,0,-1): j=k-i if (j>m or j<1): continue #print(str(i)+" "+str(j)+s[i-1][j-1]) tmp=0...
vfc_67705
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\nWBW\nBWW\nWWW\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 6\nWWBBWW\nWWBBWW\nWWBBWW\n", "output": "3\n", "type": "stdin_stdout" }, { "...
code_contests
verifiable_code
575_F. Bulbo
Solve the following coding problem using the programming language python: Bananistan is a beautiful banana republic. Beautiful women in beautiful dresses. Beautiful statues of beautiful warlords. Beautiful stars in beautiful nights. In Bananistan people play this crazy game – Bulbo. There’s an array of bulbs and play...
```python import sys range = xrange input = raw_input inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 n = inp[ii]; ii += 1 xl = xr = inp[ii]; ii += 1 cost = 0 for _ in range(n): l = inp[ii]; ii += 1 r = inp[ii]; ii += 1 # overlap if (max(r, xr) - min(l, xl) + 1) < (xr - xl + 1) + (r - l + ...
vfc_67709
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n2 7\n9 16\n8 10\n9 17\n1 6\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n1 1\n1 1\n1 1\n1 1\n1 1\n", "output": "0\n", "type": "stdin_stdout" },...
code_contests
verifiable_code
598_A. Tricky Sum
Solve the following coding problem using the programming language python: In this problem you are to calculate the sum of all integers from 1 to n, but you should take all powers of two with minus in the sum. For example, for n = 4 the sum is equal to - 1 - 2 + 3 - 4 = - 4, because 1, 2 and 4 are 20, 21 and 22 respe...
```python t = int(input()) while(t): n = int(input()) s = n*(n+1) // 2 k = len(format(n, "b")) s_pair = 2**k - 1 print(s - 2*s_pair) t-=1 ```
vfc_67713
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n1000000000\n", "output": "-4\n499999998352516354\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n414232\n", "output": "85793233454\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
618_F. Double Knapsack
Solve the following coding problem using the programming language python: You are given two multisets A and B. Each multiset has exactly n integers each between 1 and n inclusive. Multisets may contain multiple copies of the same number. You would like to find a nonempty subset of A and a nonempty subset of B such th...
vfc_67717
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 4 3 3 3\n2 2 2 2 5\n", "output": "1\n1 \n2\n1 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n10 10 10 10 10 10 10 10 10 10\n10 9 8 7 6 5 4 3 2 1\n", "output": "1\n1 \n1\...
code_contests
verifiable_code
639_D. Bear and Contribution
Solve the following coding problem using the programming language python: Codeforces is a wonderful platform and one its feature shows how much someone contributes to the community. Every registered user has contribution — an integer number, not necessarily positive. There are n registered users and the i-th of them h...
vfc_67721
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2 987 789\n-8 42 -4 -65 -8 -8\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 30 100\n12 2 6 1\n", "output": "190", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
667_A. Pouring Rain
Solve the following coding problem using the programming language python: A lot of people in Berland hates rain, but you do not. Rain pacifies, puts your thoughts in order. By these years you have developed a good tradition — when it rains, you go on the street and stay silent for a moment, contemplate all around you,...
```python from math import pi d,h,v,e=map(int,input().split()) v=v/(pi*((d/2)**2)) d=h/(v-e) if v-e>0 and d<=10000: print('YES') print(d) else: print('NO') ```
vfc_67725
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 1 1\n", "output": "YES\n3.6597923663254868\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 3 100\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_nam...
code_contests
verifiable_code
690_B2. Recover Polygon (medium)
Solve the following coding problem using the programming language python: Now that Heidi has made sure her Zombie Contamination level checker works, it's time to strike! This time, the zombie lair is a strictly convex polygon on the lattice. Each vertex of the polygon occupies a point on the lattice. For each cell of ...
```python import math def lexComp(a, b): if a[0] != b[0]: return -1 if a[0] < b[0] else 1 if a[1] != b[1]: return -1 if a[1] < b[1] else 1 return 0 def turn(a, b, c): return (b[0] - a[0]) * (c[1] - b[1]) - (b[1] - a[1]) * (c[0] - b[0]) def dist2(a, b): return (a[0] - b[0]) ** ...
vfc_67729
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n00000000\n00000110\n00012210\n01234200\n02444200\n01223200\n00001100\n00000000\n5\n00000\n01210\n02420\n01210\n00000\n7\n0000000\n0122100\n0134200\n0013200\n0002200\n0001100\n0000000\n0\n", "output": "4\n2 3\n2 4\n6 6\n5 2...
code_contests
verifiable_code
713_C. Sonya and Problem Wihtout a Legend
Solve the following coding problem using the programming language python: Sonya was unable to think of a story for this problem, so here comes the formal description. You are given the array containing n positive integers. At one turn you can pick any element and increase or decrease it by 1. The goal is the make the...
```python # Idea: # convert the problem to making array a non decreasing by decreasing each ai by i # Now we can argue that the optimal final array must have # each element equal to some element of the array a. # Proof is to assume optimal solution does not satisfy this then you can # always increase or decrease one e...
vfc_67733
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5 4 3 2 1\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n2 1 5 11 5 9 11\n", "output": "9\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
734_A. Anton and Danik
Solve the following coding problem using the programming language python: Anton likes to play chess, and so does his friend Danik. Once they have played n games in a row. For each game it's known who was the winner — Anton or Danik. None of the games ended with a tie. Now Anton wonders, who won more games, he or Dan...
```python n=int(input()) s=input() c=0 c1=0 for i in s: if i=="D": c=c+1 else: c1=c1+1 if c>c1: print("Danik") elif c<c1: print("Anton") else: print("Friendship") ```
vfc_67737
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\nDDDAADA\n", "output": "Danik\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\nDADADA\n", "output": "Friendship\n", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
758_A. Holiday Of Equality
Solve the following coding problem using the programming language python: In Berland it is the holiday of equality. In honor of the holiday the king decided to equalize the welfare of all citizens in Berland by the expense of the state treasury. Totally in Berland there are n citizens, the welfare of each of them is...
```python n = int(input()) s = 0 mx = 0 a = list((map(int,input().split()))) for i in range(n): s+=a[i] mx = max(mx,a[i]) print(mx*n-s) ```
vfc_67741
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n12\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
779_E. Bitwise Formula
Solve the following coding problem using the programming language python: Bob recently read about bitwise operations used in computers: AND, OR and XOR. He have studied their properties and invented a new game. Initially, Bob chooses integer m, bit depth of the game, which means that all numbers in the game will cons...
```python n, m = map(int, input().split()) v = [('?', '')] temp = [(0, 1)] d = {} d['?'] = 0 mn, mx = '', '' for i in range(n): name, val = input().split(' := ') v.append((name, val.split())) temp.append((-1, -1)) d[name] = i + 1 def eval(expr, bit1, bit2): if expr == 'OR': return bit1 |...
vfc_67745
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\na := 101\nb := 011\nc := ? XOR b\n", "output": "011\n100\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\na := 1\nbb := 0\ncx := ? OR a\nd := ? XOR ?\ne := d AND bb\n", "out...
code_contests
verifiable_code
827_B. High Load
Solve the following coding problem using the programming language python: Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of n nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly k...
```python import os import sys from io import BytesIO, IOBase 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 self.write = self.buffer.write if s...
vfc_67753
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n", "output": "3\n1 2\n1 3\n1 4\n2 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n", "output": "2\n1 2\n1 3\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
849_B. Tell Your World
Solve the following coding problem using the programming language python: Connect the countless points with lines, till we reach the faraway yonder. There are n points on a coordinate plane, the i-th of which being (i, yi). Determine whether it's possible to draw two parallel and non-overlapping lines, such that eve...
```python def run(): n = int(input()) a = [int(x) for x in input().split()] _s = set(a) if len(_s) == 1: print('No') return if len(_s) == 2: print('Yes') return def check(dy, base): st = [False] * n for i in range(n): if (a[i] - a[ba...
vfc_67757
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n7 5 8 6 9\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n-1 -2 0 0 -5\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
897_D. Ithea Plays With Chtholly
Solve the following coding problem using the programming language python: This is an interactive problem. Refer to the Interaction section below for better understanding. Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight. <image> Initially, Ithea puts n clear sheets of pap...
```python import sys n, m, c = map(int, input().split()) free = n nums = [0] * n for i in range(m): pi = int(input()) if(pi > c//2): current = n - 1 while(nums[current] > 0 and nums[current] >= pi and current >= 0):current -= 1 if(current == -1):current = 0 if(nums[current] == ...
vfc_67765
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4 4\n2\n1\n3\n", "output": "1\n1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4 2\n2\n2\n2\n1\n", "output": "4\n3\n2\n1\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
918_E. Pollywog
Solve the following coding problem using the programming language python: As we all know, Dart is some kind of creature from Upside Down world. For simplicity, we call their kind pollywogs. Dart and x - 1 other pollywogs are playing a game. There are n stones in a row, numbered from 1 through n from left to right. At ...
vfc_67769
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3 10 2\n1 2 3\n5 -10\n6 1000\n", "output": "6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
940_E. Cashback
Solve the following coding problem using the programming language python: Since you are the best Wraith King, Nizhniy Magazin «Mir» at the centre of Vinnytsia is offering you a discount. You are given an array a of length n and an integer c. The value of some array b of length k is the sum of its elements except fo...
```python from heapq import * f = lambda: map(int, input().split()) n, c = f() a = list(f()) + [0] * c b = [0] * (n + c) s = 0 h = [(0, -1)] for i in range(n): s += a[i] - a[i - c] heappush(h, (a[i], i)) while h[0][1] <= i - c: heappop(h) b[i] = min(b[i - 1] + a[i], b[i - c] + s - h[0][0]) print(b[n - 1...
vfc_67773
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n1 2 3\n", "output": "6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
96_B. Lucky Numbers (easy)
Solve the following coding problem using the programming language python: Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn't contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Lucky number is super lucky...
```python gh=set() def rep(n,four,seven): global gh if n>10000000000 :return if (four==seven):gh|={n} rep(n*10+4,four+1,seven) rep(n*10+7,four,seven+1) rep(0,0,0) gh=sorted(gh) def bin_s(a): lo=0;hi=len(gh);ans=0 while lo<=hi: mid=(lo+hi)//2 if gh[mid]>=a:ans=gh[mid];hi=mid-1...
vfc_67777
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4500\n", "output": "4747\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
994_B. Knights of a Polygonal Table
Solve the following coding problem using the programming language python: Unlike Knights of a Round Table, Knights of a Polygonal Table deprived of nobility and happy to kill each other. But each knight has some power and a knight can kill another knight if and only if his power is greater than the power of victim. Ho...
```python n,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) d={} l=[] for i in range(n): x=a[i] y=b[i] l.append((x,y)) l.sort() ans=[] j=0 if k==0: print(*b) else: for i in range(n): if i<k: ans.append(l[i][1]) ans.sort() ...
vfc_67781
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1\n1 2 3 4 5\n1 2 3 4 5\n", "output": "1 3 5 7 9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0\n2\n3\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
averages-1
Solve the following coding problem using the programming language python: You are given a array of integers. Find the diff between the maximum average value and minimum average value of sub-sequences of array. Input: First line contains a single integer denoting N, the number of elements of array. Next line contains...
```python t = input() arr = list(map(int,raw_input().split())) data = [] for x in arr: temp = 0 for y in arr: temp = float(x+y)/2 if(temp - int(temp)== 0): temp = int(temp) data.append(temp) print max(data)-min(data) ```
vfc_67785
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 2 1 2\n\nSAMPLE", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "500\n36308 70764 60902 33691 31478 48806 82230 46468 79089 81186 20562 22885 3744 29268 66899 44875 8625...
code_contests
verifiable_code
dummy3
Solve the following coding problem using the programming language python: Now after having the event list, all the participants wanted to know where to go for their respective events, for this purpose they are given a piece of paper with an n x n grid of numbers printed on it. They are told that their event would be h...
```python N=input(); matrix = [map(int,raw_input().strip().split()) for x in xrange(N)] n, m = len(matrix), len(matrix[0]) cost = [matrix[i][-1] for i in xrange(n)] for i in xrange(m-2, -1, -1): cost[0] += matrix[0][i] for j in xrange(1, n): cost[j] = min(cost[j], cost[j-1]) + matrix[j][i] for j in xrange(n-2, -...
vfc_67793
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\n921 884 423 93 887 553 723 325 991 129 1 951 554 715 515 903 717 353 945 651 181 997 912 981 778 240 532 569 312 258 843 418 895 130 326 572 215 44 25 108 802 880 985 76 363 322 784 922 675 965 986 948 397 838 218 529 342 394 ...
code_contests
verifiable_code
longest-increasing-path-9
Solve the following coding problem using the programming language python: There is a 2D matrix of N rows and M columns. Rows are number 1 to N from top to bottom and columns 1 to M from left to right. You are standing at (1,1). From, A [ i ] [ j ] you can move to A [ i + 1 ] [ j ] if A [ i + 1 ] [ j ] > A [ i ] [ ...
```python def process(mat, n, m): sol = [[1 for j in range(m)] for i in range(n)] for i in reversed(range(n-1)): if mat[i+1][m-1] > mat[i][m-1]: sol[i][m-1] = sol[i+1][m-1] + 1 for j in reversed(range(m-1)): if mat[n-1][j+1] > mat[n-1][j]: sol[n-1][j] = sol[n-1][j+1] + 1 #print sol for i in ...
vfc_67801
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1\n1\n4 4\n1 2 3 4\n2 2 3 4\n3 2 3 4\n4 5 6 7\n2 2\n1 2\n3 4\n\nSAMPLE", "output": "1\n7\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1\n1\n4 4\n1 2 5 4\n2 2 3 4\n3 2 3 4\n...
code_contests
verifiable_code
mystery-3
Solve the following coding problem using the programming language python: Continuing the trend, this year too we present a 'Mystery' for you to solve! You will be given two numbers: a and b; and you have to output a single integer. See the sample test cases for hints. Input: The first line of the input will contain...
```python for tc in range(int(raw_input())): a,b=map(int,raw_input().split()) print a%b ```
vfc_67805
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 5\n6 5\n138 9\n9 13\n\nSAMPLE", "output": "0\n1\n3\n9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n0 5\n0 3\n5 10\n1 10\n9 10\n999 10\n999 22\n65 65\n66 65\n222 222\n652 999\n1...
code_contests
verifiable_code
problem-1-46
Solve the following coding problem using the programming language python: Karan and Akshay love challenging each other with awesome algorithmic questions. Today, Karan decided to give Akshay a relatively easy question. Karan has string s of length N consisting entirely of lowercase latin characters and he loves double...
```python from string import ascii_lowercase A = ord("a") ad = {} for c in ascii_lowercase: i = ord(c) - A ad[c] = 2 ** i n = int(raw_input()) t = (n + 1) * [0] s = raw_input().strip() for i in range(n): t[i+1] = t[i] ^ ad[s[i]] for _ in range(int(raw_input())): l, r = map(int, raw_input().split()) if r - l < 1: ...
vfc_67809
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\nabcdabcd\n2\n1 8\n3 5\n\nSAMPLE", "output": "YES\nNO", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
search-engine
Solve the following coding problem using the programming language python: Let us see how search engines work. Consider the following simple auto complete feature. When you type some characters in the text bar, the engine automatically gives best matching options among it's database. Your job is simple. Given an incomp...
```python def solution(): n, q = map(int, raw_input().strip().split(' ')) tr = Trie() for i in range(n): string, weight = raw_input().strip().split(' ') tr.add(string, int(weight)) for j in range(q): string = raw_input().strip() values = tr.search(string) if value...
vfc_67813
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1\nhackerearth 10\nhackerrank 9\nhacker\n\nSAMPLE", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\nhackerearth 10\nhackerrank 11\nhacker\n\nSAMPLE", "output": "...
code_contests
verifiable_code
terminator
Solve the following coding problem using the programming language python: Slugtera is a town where three types of people lives which are criminals , terminator and life saver . Criminals are represented by o and terminator are represented by x and saver are represented by * . So in this story x function is to kill al...
```python tc=int(raw_input()) for case in range(tc): s=raw_input() c=0 ans="" q=0 for i in range(len(s)): if s[i]=="*": if "x" in s[q:i]: for k in s[q:i]: if k=="x": ans=ans+k else: for k in s[q:i]: ans=ans+k ans=ans+"*" q=i+1 if "x" in s[q:]: for k in s[q:]: if k=="x": ...
vfc_67817
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\noxox\nxo*oooooooo*xo\nooooooooo*xooo***xxxxooooo\n\nSAMPLE", "output": "xx\nx*oooooooo*x\nooooooooo*x***xxxx\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
without-statement-easy-contest
Solve the following coding problem using the programming language python: Unfortunately someone has come and eaten the problem statement. Are you good enough to solve it without the statement? Input The first line contains T denoting the number of test cases. The next T lines describe test cases and contain two inte...
```python for _ in xrange(int(raw_input())): n, m = map(int, raw_input().split()) arr = [sum([int(x)**2 for x in str(n)])] arrset = set(arr) for x in xrange(m - 1): arr.append(sum([int(x)**2 for x in str(arr[-1])])) if arr[-1] in arrset: # arr.pop() break ...
vfc_67821
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n28 1\n39 1\n90 1\n15 2\n123 2\n114514 1919\n\nSAMPLE", "output": "68\n90\n81\n40\n17\n16\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00058 Orthogonal
Solve the following coding problem using the programming language python: Read the coordinates of four different points on the plane, $ A (x_A, y_A) $, $ B (x_B, y_B) $, $ C (x_C, y_C) $, $ D (x_D, y_D) $, and straight line $ Create a program that outputs YES if AB $ and $ CD $ are orthogonal, and NO if they are not o...
```python E = 10 ** -10 while True: try: xa, ya, xb, yb, xc, yc, xd, yd = map(float, input().split()) vabx, vaby = xb - xa, yb - ya vcdx, vcdy = xd - xc, yd - yc print("YES" if abs(vabx * vcdx + vaby * vcdy) < E else "NO") except EOFError: break ```
vfc_67865
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1.0 1.0 2.0 2.0 0.0 0.0 1.0 -1.0\n0.0 0.0 2.0 0.0 -1.0 2.0 2.0 2.0\n10.0 6.0 3.4 5.2 6.8 9.5 4.3 2.1\n2.5 3.5 2.5 4.5 -3.3 -2.3 6.8 -2.3", "output": "YES\nNO\nNO\nYES", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
p00189 Convenient Location
Solve the following coding problem using the programming language python: Mr. A, who will graduate next spring, decided to move when he got a job. The company that finds a job has offices in several towns, and the offices that go to work differ depending on the day. So Mr. A decided to live in a town where he had a sh...
```python INF = 10 ** 10 while True: n = int(input()) if n == 0: break costs = [[INF] * 10 for _ in range(10)] for i in range(10): costs[i][i] = 0 city = set() for _ in range(n): a, b, c = map(int, input().split()) city = city | {a, b} costs[a][b] = c costs[b][a] = c city =...
vfc_67869
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n0 1 80\n1 2 20\n0 2 60\n2 3 50\n3 4 60\n1 4 90\n2\n0 1 1\n1 2 1\n0", "output": "2 240\n1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n0 1 80\n1 2 20\n0 2 60\n2 3 50\n3 4 66\n1 4 9...
code_contests
verifiable_code
p00540 Ball
Solve the following coding problem using the programming language python: Ball In the Kingdom of IOI, a ball will be held to celebrate the birthday of Princess JOI, the princess. N aristocrats will participate in the ball. N is an odd number. Aristocrats are numbered from 1 to N. Each aristocrat has an integer of go...
vfc_67877
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 3\n5 2\n5 5\n8 6\n6\n2\n8\n9", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 3\n5 2\n5 5\n4 6\n6\n2\n8\n9", "output": "6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00703 What is the Number in my Mind ?
Solve the following coding problem using the programming language python: Let us enjoy a number guess game. A number containing L digits is in my mind (where 4 <= L <= 10). You should guess what number it is. It is composed of any of the following ten digits: "0","1","2","3","4","5","6","7","8", and "9". No di...
vfc_67881
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4\n160348 0 4\n913286 2 3\n431289 3 1\n671283 3 3\n10 8\n3827690415 2 8\n0482691573 1 9\n1924730586 3 7\n1378490256 1 9\n6297830541 1 9\n4829531706 3 7\n4621570983 1 9\n9820147536 6 4\n4 4\n2713 0 3\n1247 2 0\n1230 1 1\n1387 2 1\...
code_contests
verifiable_code
p00975 Four-Coloring
Solve the following coding problem using the programming language python: Four-Coloring You are given a planar embedding of a connected graph. Each vertex of the graph corresponds to a distinct point with integer coordinates. Each edge between two vertices corresponds to a straight line segment connecting the two poi...
vfc_67889
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 8\n0 0\n2 0\n0 2\n2 2\n1 1\n1 2\n1 3\n1 5\n2 4\n2 5\n3 4\n3 5\n4 5", "output": "1\n2\n2\n1\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 9\n0 0\n2 0\n0 2\n2 2\n1 1\n1 2\n1 3\n1 5\n2...
code_contests
verifiable_code
p01107 Go around the Labyrinth
Solve the following coding problem using the programming language python: Go around the Labyrinth Explorer Taro got a floor plan of a labyrinth. The floor of this labyrinth is in the form of a two-dimensional grid. Each of the cells on the floor plan corresponds to a room and is indicated whether it can be entered or...
```python #!/usr/bin/env python3 # -*- coding: utf-8 -*- import copy def rdp_connect() -> bool: global n, m, c n, m = map(int, input().split()) if n == m == 0: return False c = [list(input()) for _ in range(n)] return True def rdp_check() -> bool: DY = (0, 1, 0, -1) DX = (1, 0, -1...
vfc_67893
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n...\n.#.\n...\n5 5\n..#..\n.....\n#....\n.....\n.....\n3 8\n..#.....\n........\n.....#..\n3 5\n..#..\n.....\n..#..\n4 4\n....\n....\n..##\n..#.\n0 0", "output": "YES\nNO\nYES\nNO\nNO", "type": "stdin_stdout" } ...
code_contests
verifiable_code
p01245 Magical Dungeon
Solve the following coding problem using the programming language python: Arthur C. Malory is a wandering valiant fighter (in a game world). One day, he visited a small village and stayed overnight. Next morning, the village mayor called on him. The mayor said a monster threatened the village and requested him to def...
vfc_67897
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 8\n0 2 3\n2 3 -20\n3 4 3\n4 1 -5\n1 5 1\n5 4 5\n1 3 2\n3 6 -2\n0 6 30\n7 8\n0 2 3\n2 3 -20\n3 4 3\n4 1 -5\n1 5 1\n5 4 5\n1 3 2\n3 6 -2\n0 6 20\n4 4\n0 1 -10\n1 2 -50\n2 1 51\n1 3 1\n0 3 20\n11 14\n0 1 -49\n1 2 1\n2 3 40\n3 1 -40\...
code_contests
verifiable_code
p01406 Custom Painting Master
Solve the following coding problem using the programming language python: Problem I: Custom paint craftsman slip likes a video of a racing game. That said, I don't like videos of cars running, but I like videos of customizing the car body with the custom paint car creation feature of this game. This is a function tha...
vfc_67901
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n17 12 7 340 180\n26 22 10 150 270\n27 13 5 100 230\n3\n0 0 8 0 90\n10 10 8 180 0\n50 50 5 180 270\n2\n10 10 5 0 270\n0 0 30 0 90", "output": "3\n2\n2", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p01860 Shopping
Solve the following coding problem using the programming language python: C: Shopping-Shopping- story Isono's older sister, Sazoe, decided to cook dinner for Isono and Nakajima, who are playing "that" and "that". Unfortunately, there are only a few ingredients left in the refrigerator, so Sazoe decided to go shoppin...
vfc_67913
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 9 3 2 3\n1 2 3\n1 1 2\n2 3 1\n3 4 2\n4 1 3\n4 1 1\n5 1 1\n6 2 3\n7 2 2", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 9 3 2 3\n1 2 3\n1 2 2\n2 3 1\n3 4 2\n4 1 3\n4 1 1\n5...
code_contests
verifiable_code
p01995 Palindromic Subsequences
Solve the following coding problem using the programming language python: G: Palindromic Subsequences problem Given a string S consisting only of lowercase letters, find out how many subsequences of this string S are not necessarily continuous and are palindromes. Here, a subsequence that is not necessarily continu...
```python def main(): from bisect import bisect_left as bl from bisect import bisect_right as br s=input() alpha="abcdefghijklmnopqrstuvwxyz" l=len(s) alpha2={j:i for i,j in enumerate(alpha)} memo=[[] for _ in [0]*26] mod=10**9+7 for i in range(l): memo[alpha2[s[i]]].append(i...
vfc_67917
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "acpc", "output": "5", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02282 Reconstruction of a Tree
Solve the following coding problem using the programming language python: Write a program which reads two sequences of nodes obtained by the preorder tree walk and the inorder tree walk on a binary tree respectively, and prints a sequence of the nodes obtained by the postorder tree walk on the binary tree. Constraint...
```python class BinaryTree: class Node: def __init__(self, nid, left, right): self.id = nid self.left = left self.right = right def has_left(self): return self.left is not None def has_right(self): return self.right is not None ...
vfc_67925
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5\n3 2 4 1 5", "output": "3 4 2 5 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 3 4\n1 2 3 4", "output": "4 3 2 1", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
chapd
Solve the following coding problem using the programming language python: You are given two positive integers – A and B. You have to check whether A is divisible by all the prime divisors of B. Input The first line of the input contains an integer T denoting the number of test cases. The description of T test cases f...
```python t=input() while (t): a,b=raw_input().split() a=eval(a) b=eval(b) print 'Yes' if (a**65)%b==0 else 'No' t-=1 ```
vfc_67933
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n120 75\n128 16\n7 8", "output": "Yes\nYes\nNo\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
destroy
Solve the following coding problem using the programming language python: Arrays have fallen out of Chef's good books, and he plans to destroy all arrays he possesses. He is left with the last array A, consisting of N positive integers. In order to destroy the array, he can perform the following 2 types of operations...
```python # this is implementation of moors algorithm, where we have to find out whether there is an element whose frequency is more than half of the length of array. # Answer of this problem can not be less than half of the length of array. T = int(raw_input()); while T > 0: T = T-1; N = int(raw_input()); ...
vfc_67937
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n1 2\n2\n1 1\n3\n1 2 3", "output": "1\n2\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\n1 2\n2\n1 1\n3\n1 4 3", "output": "1\n2\n2\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
iitk1p11
Solve the following coding problem using the programming language python: Devu is a little boy. He does not know how to take carries while adding two numbers in decimal base. eg. He will struggle in adding numbers 83 and 19, because 3 + 9 = 12 and he needs to take a carry of 1. You are given an integer n. Can you wri...
```python t = int(raw_input()) for i in range(t): n = int(raw_input()) if n == 1 or n == 10 or n == 100 or n == 1000 or n == 10000 or n == 100000: print "NO" else: print "YES" ```
vfc_67941
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n9", "output": "NO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n12", "output": "NO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
ncc3
Solve the following coding problem using the programming language python: Problem description: Faizaan and Sejal were playing Mathematics games. Faizaan gave Sejal three numbers: N, M and K. Sejal has to find out a number X such that X = (N^M)%K Sejal initially thought that the problem was very easy, but she soon re...
```python t = int(raw_input()) for i in range(t) : n = int(raw_input()) m = int(raw_input()) k = int(raw_input()) print pow(n,m,k) ```
vfc_67945
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n4\n5", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n4\n5", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
rrstone
Solve the following coding problem using the programming language python: Roman has no idea, why this problem is called Stone. He also has no idea on how to solve the followong problem: given array of N integers A and a number K. During a turn the maximal value over all Ai is chosen, let's call it MAX. Then Ai = MAX -...
```python fr=raw_input().split() n=int(fr[0]) k=int(fr[1]) raw=raw_input().split() l=[] for i in range(0,n): l.append(int(raw[i])) if k==0: for i in l: print i, print "" me=max(l) for i in range(0,n): l[i]=me-l[i] if k%2==1: for i in l: print i, print "" if k%2==0 and k!=0: me=max(l) for i in range(0,n)...
vfc_67949
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1\n5 -1 7 0", "output": "2 8 0 7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n5 -1 7 1", "output": "2 8 0 6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
wprob
Solve the following coding problem using the programming language python: Olya works as a warehouse keeper for a T-Shirt factory. Now the factory is facing hard times, so currently they produce only the T-shirts of three kinds: red, green and blue T-Shirts. All the T-shirts are stored in the containers, each of the co...
```python for _ in xrange(input()): s = raw_input() n = len(s) rs = [0 for i in xrange(n)] gs = [0 for i in xrange(n)] bs = [0 for i in xrange(n)] r, g, b = 0, 0, 0 for i in xrange(n): rs[i] = r gs[i] = g bs[i] = b if s[i] == 'r': r += 1 if...
vfc_67953
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nrgr\nrrr\nrgb\nrgbr", "output": "1\n0\n0\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nrfr\nrrr\nrgb\nrgbr", "output": "0\n0\n0\n2\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1023_B. Pair of Toys
Solve the following coding problem using the programming language python: Tanechka is shopping in the toy shop. There are exactly n toys in the shop for sale, the cost of the i-th toy is i burles. She wants to choose two toys in such a way that their total cost is k burles. How many ways to do that does she have? Eac...
```python n,k = [int(x) for x in input().split()] if k>n: if k>=2*n: print(0) else: print((2*n-k+1)//2) else: if k%2==0: k-=1 print(k//2) ```
vfc_67957
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 15\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000000 1000000000001\n", "output": "500000000000\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
1044_C. Optimal Polygon Perimeter
Solve the following coding problem using the programming language python: You are given n points on the plane. The polygon formed from all the n points is strictly convex, that is, the polygon is convex, and there are no three collinear points (i.e. lying in the same straight line). The points are numbered from 1 to n...
```python n = int(input()) north = -100000000 south = 100000000 east = -100000000 west = 100000000 ne = -200000000 nw = -200000000 se = -200000000 sw = -200000000 for i in range(n): x,y = map(int,input().split()) north = max(north,y) east = max(east,x) south = min(south,y) west = min(west,x) ne ...
vfc_67961
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 4\n4 3\n3 0\n1 3\n", "output": "12 14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 0\n0 2\n2 0\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
1067_B. Multihedgehog
Solve the following coding problem using the programming language python: Someone give a strange birthday present to Ivan. It is hedgehog — connected undirected graph in which one vertex has degree at least 3 (we will call it center) and all other vertices has degree 1. Ivan thought that hedgehog is too boring and dec...
```python from sys import stdin from collections import deque n, k = map(int, stdin.readline().split()) graph = [[] for _ in range(n)] leaf = -1 for _ in range(n-1): a,b = map(int,stdin.readline().split()) graph[a - 1].append(b - 1) graph[b - 1].append(a - 1) def bfs(G, s): # la cola comienza con e...
vfc_67965
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n1 3\n2 3\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "14 2\n1 4\n2 4\n3 4\n4 13\n10 5\n11 5\n12 5\n14 5\n5 13\n6 7\n8 6\n13 6\n9 6\n", "output": "Yes\n", ...
code_contests
verifiable_code
1089_L. Lazyland
Solve the following coding problem using the programming language python: The kingdom of Lazyland is the home to n idlers. These idlers are incredibly lazy and create many problems to their ruler, the mighty King of Lazyland. Today k important jobs for the kingdom (k ≤ n) should be performed. Every job should be don...
```python n,k = map(int,input().split()) s = list(map(int,input().split())) p = list(map(int,input().split())) r = {} r2 = [] for i in range(n): if s[i] in r: if r[s[i]]>p[i]: r2.append(p[i]) else: r2.append(r[s[i]]) r[s[i]] = p[i] else: r[s[i]] = p[i]...
vfc_67969
{ "difficulty": "19", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n3 1 2\n5 3 4\n", "output": "0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1108_E2. Array and Segments (Hard version)
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is a number of elements in the array. You are given an array a consisting of n integers. The value of the i-th element of the array is a_i. You are also given a set of m segments. The j-th seg...
```python def main(): n, m = map(int, input().split()) aa = list(map(int, input().split())) res = max(aa) - min(aa) ll, rr = [n + 1], [n + 1] segments = res_segments = [False] * (m + 1) bounds = {0, n, n + 1} for _ in range(m): l, r = map(int, input().split()) l -= 1 ...
vfc_67973
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n2 -2 3 1 4\n3 5\n3 4\n2 4\n2 5\n", "output": "7\n2\n3 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0\n1000000\n", "output": "0\n0\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1138_B. Circus
Solve the following coding problem using the programming language python: Polycarp is a head of a circus troupe. There are n — an even number — artists in the troupe. It is known whether the i-th artist can perform as a clown (if yes, then c_i = 1, otherwise c_i = 0), and whether they can perform as an acrobat (if yes...
```python import sys import random N = int(input()) C = list(map(int, input())) A = list(map(int, input())) # N = random.randint(20, 40) * 2 # C = [random.randint(0, 1) for i in range(N)] # A = [random.randint(0, 1) for i in range(N)] def build_solution(i, j, x, y): I = (0, 0) J = (0, 1) X = (1, 0) Y = (1, 1) a...
vfc_67977
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0011\n1100\n", "output": "1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0011\n0101\n", "output": "1 4 ", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1178_F2. Long Colorful Strip
Solve the following coding problem using the programming language python: This is the second subtask of problem F. The only differences between this and the first subtask are the constraints on the value of m and the time limit. It is sufficient to solve this subtask in order to hack it, but you need to solve both sub...
```python import sys range = xrange input = raw_input MOD = 998244353 m,n = [int(x) for x in input().split()] C = [int(x) - 1 for x in input().split()] C2 = [C[0]] for c in C: if C2[-1] != c: C2.append(c) C = C2 n = len(C) if n > 2*m: print 0 sys.exit() pos = [[] for _ in range(n)] for i in r...
vfc_67985
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 17\n1 3 2 2 7 8 2 5 5 4 4 4 1 1 6 1 1\n", "output": "20", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n2 1 2\n", "output": "0", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1196_F. K-th Path
Solve the following coding problem using the programming language python: You are given a connected undirected weighted graph consisting of n vertices and m edges. You need to print the k-th smallest shortest path in this graph (paths from the vertex to itself are not counted, paths from i to j and from j to i are co...
```python import sys input = sys.stdin.readline N, M, K = map(int, input().split()) X = [] for _ in range(M): x, y, w = map(int, input().split()) X.append([min(x,y), max(x,y), w]) X = (sorted(X, key = lambda x: x[2])+[[0, 0, 10**20] for _ in range(K)])[:K] D = {} for x, y, w in X: if x: D[x*10**6+y] = w fl...
vfc_67989
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 15 18\n2 6 3\n5 7 4\n6 5 4\n3 6 9\n6 7 7\n1 6 4\n7 1 6\n7 2 1\n4 3 2\n3 2 8\n5 3 6\n2 5 5\n3 7 9\n4 1 8\n2 1 1\n", "output": "9\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1214_A. Optimal Currency Exchange
Solve the following coding problem using the programming language python: Andrew was very excited to participate in Olympiad of Metropolises. Days flew by quickly, and Andrew is already at the airport, ready to go home. He has n rubles left, and would like to exchange them to euro and dollar bills. Andrew can mix doll...
```python n=int(input()) d=int(input()) e=int(input()) arr=100 a,b=min(d,5*e),max(d,5*e) for i in range(0,n//b+1): arr=min(arr,(n-i*b)%a) print(arr) ```
vfc_67993
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "410\n55\n70\n", "output": "5\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1255_C. League of Leesins
Solve the following coding problem using the programming language python: Bob is an avid fan of the video game "League of Leesins", and today he celebrates as the League of Leesins World Championship comes to an end! The tournament consisted of n (n ≥ 5) teams around the world. Before the tournament starts, Bob has ...
```python def zip_sorted(a,b): # sorted by a a,b = zip(*sorted(zip(a,b))) # sorted by b sorted(zip(a, b), key=lambda x: x[1]) return a,b def return_nxt(i,a,b): visited.add(i) c = (set(mem2[i])-set([a,b])).pop() final.append(c) if len(final)==n: return -1,b,c new_idx = ((set(mem1[b])-visited)&(se...
vfc_68001
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 3 2\n2 3 5\n4 1 2\n", "output": "1 4 2 3 5\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1299_E. So Mean
Solve the following coding problem using the programming language python: This problem is interactive. We have hidden a permutation p_1, p_2, ..., p_n of numbers from 1 to n from you, where n is even. You can try to guess it using the following queries: ? k a_1 a_2 ... a_k. In response, you will learn if the averag...
vfc_68009
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2\n", "output": "? 1 2 \n? 1 1 \n! 1 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 9 1\n321376743 64146243 670700897 575471266 303438330 113152943 114637600 468461998 86885931...
code_contests
verifiable_code
1341_B. Nastya and Door
Solve the following coding problem using the programming language python: On February 14 Denis decided to give Valentine to Nastya and did not come up with anything better than to draw a huge red heart on the door of the length k (k ≥ 3). Nastya was very confused by this present, so she decided to break the door, thro...
```python from sys import stdin, stdout def find(A,N,K): arr=[0]*N for i in range(1,N-1): if A[i-1]<A[i]>A[i+1]: arr[i]=1 i,j=0,2 c=0 # print(arr) while(j<K): if arr[j-1]: c+=1 # print(j,c) j+=1 m=[c,i] # print(c,i,j) while(j<N): if arr[i+1]:...
vfc_68017
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n8 6\n1 2 4 1 2 4 1 2\n5 3\n3 2 3 2 1\n10 4\n4 3 4 3 2 3 2 1 0 1\n15 7\n3 7 4 8 2 3 4 5 21 2 3 4 2 1 3\n7 5\n1 2 3 4 5 6 1\n", "output": "3 2\n2 2\n2 1\n3 1\n2 3\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
1383_D. Rearrange
Solve the following coding problem using the programming language python: Koa the Koala has a matrix A of n rows and m columns. Elements of this matrix are distinct integers from 1 to n ⋅ m (each number from 1 to n ⋅ m appears exactly once in the matrix). For any matrix M of n rows and m columns let's define the foll...
vfc_68025
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n3 5 6\n1 7 9\n4 8 2\n", "output": "9 5 1 \n7 8 2 \n3 6 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n12 10 8 6\n3 4 5 7\n2 11 9 1\n", "output": "12 8 6 1 \n10 11 9 2 \...
code_contests
verifiable_code
1404_D. Game of Pairs
Solve the following coding problem using the programming language python: This is an interactive problem. Consider a fixed positive integer n. Two players, First and Second play a game as follows: 1. First considers the 2n numbers 1, 2, ..., 2n, and partitions them as he wants into n disjoint pairs. 2. Then, Sec...
```python import sys n = int(input()) if n % 2: print('Second') sys.stdout.flush() l = list(map(lambda x: int(x)-1,input().split())) rev1 = [-1]*n rev2 = [-1]*n revs = [0]*n for i in range(2 * n): revs[l[i]] += i if rev1[l[i]] == -1: rev1[l[i]] = i else: ...
vfc_68029
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n\n\n0", "output": "First\n1 2 1 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n\n1 1 2 2\n\n0\n", "output": "First\n1 2 1 2 \n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1472_G. Moving to the Capital
Solve the following coding problem using the programming language python: There are n cities in Berland. The city numbered 1 is the capital. Some pairs of cities are connected by a one-way road of length 1. Before the trip, Polycarp for each city found out the value of d_i — the shortest distance from the capital (th...
```python import sys 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[...
vfc_68041
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n\n6 7\n1 2\n1 3\n2 5\n2 4\n5 1\n3 6\n6 2\n\n2 2\n1 2\n2 1\n\n6 8\n1 2\n1 5\n2 6\n6 1\n2 3\n3 4\n4 2\n5 4\n", "output": "\n0 0 1 2 0 1 \n0 0 \n0 0 2 1 1 0 \n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
1499_B. Binary Removals
Solve the following coding problem using the programming language python: You are given a string s, consisting only of characters '0' or '1'. Let |s| be the length of s. You are asked to choose some integer k (k > 0) and find a sequence a of length k such that: * 1 ≤ a_1 < a_2 < ... < a_k ≤ |s|; * a_{i-1} + 1 ...
```python for q in range(int(input())): n=input() s=0 s1=0 p=0 l=len(n) for i in range(l-1,0,-1): if(n[i]=='0' and n[i-1]=='0' ): s=1 p=i-1 break for i in range(p,0,-1): if(n[i]=='1' and n[i-1]=='1'): s1=1 break ...
vfc_68045
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n10101011011\n0000\n11111\n110\n1100\n", "output": "\nYES\nYES\nYES\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n11\n11\n11\n11\n11\n11\n11\n11\n11\n", "output": "YE...
code_contests
verifiable_code
1520_G. To Go Or Not To Go?
Solve the following coding problem using the programming language python: Dima overslept the alarm clock, which was supposed to raise him to school. Dima wonders if he will have time to come to the first lesson. To do this, he needs to know the minimum time it will take him to get from home to school. The city where...
```python #!/usr/bin/env python3 import io import os from collections import deque # input = sys.stdin.readline # to read input quickly from math import inf input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline # available on Google, AtCoder Python3, not available on Codeforces # import numpy as np # import sc...
vfc_68049
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5 1\n0 -1 0 1 -1\n0 20 0 0 -1\n-1 -1 -1 -1 -1\n3 0 0 0 0\n-1 0 0 0 0\n", "output": "\n14", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 1000000000\n0 0 0\n0 0 0\n", "output": "3...
code_contests
verifiable_code
154_E. Martian Colony
Solve the following coding problem using the programming language python: The first ship with the Earth settlers landed on Mars. The colonists managed to build n necessary structures on the surface of the planet (which can be regarded as a plane, and the construction can be regarded as points on it). But one day the s...
vfc_68053
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1000\n0.0 0.0\n0 2.00\n2.00 2\n2.0 0.00\n", "output": "4.0026666675\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n0.00 0.000\n0.0 8.00\n6 8.00\n", "output": "78.5398163397\n...
code_contests
verifiable_code
176_C. Playing with Superglue
Solve the following coding problem using the programming language python: Two players play a game. The game is played on a rectangular board with n × m squares. At the beginning of the game two different squares of the board have two chips. The first player's goal is to shift the chips to the same square. The second p...
```python n,m,X,Y,x,y=map(int,input().split()) a=[abs(X-x),abs(Y-y)] a.sort() print("First" if a[1]<5 and a[0]+a[1]<7 else "Second") # Made By Mostafa_Khaled ```
vfc_68057
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 5 4 3 2 1\n", "output": "First\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10 1 1 10 10\n", "output": "Second\n", "type": "stdin_stdout" }, { "fn_name": ...
code_contests
verifiable_code
220_A. Little Elephant and Problem
Solve the following coding problem using the programming language python: The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he ...
```python def main(): n = int(input()) arr = list(map(int, input().split())) copy = arr[:] copy.sort() missed = 0 for i in range(n): if arr[i] != copy[i]: missed += 1 if missed == 2: print('YES') elif missed == 0: print('YES') else: pri...
vfc_68065
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 3 2 1\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
244_B. Undoubtedly Lucky Numbers
Solve the following coding problem using the programming language python: Polycarpus loves lucky numbers. Everybody knows that lucky numbers are positive integers, whose decimal representation (without leading zeroes) contain only the lucky digits x and y. For example, if x = 4, and y = 7, then numbers 47, 744, 4 are ...
```python def func(num): if 0 < num <= n: result.add(num) num *= 10 func(num+x) func(num+y) if __name__ == "__main__": n = int(input()) result = set() for x in range(10): for y in range(10): func(x) print(len(result)) ...
vfc_68069
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "123\n", "output": "113\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "78426...
code_contests
verifiable_code
269_E. String Theory
Solve the following coding problem using the programming language python: Emuskald is an innovative musician and always tries to push the boundaries of music production. Now he has come up with an idea for a revolutionary musical instrument — a rectangular harp. A rectangular harp is a rectangle n × m consisting of n...
vfc_68073
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\nL T 1 1\nT R 3 1\nR B 3 3\nB L 1 3\nL R 2 2\nT B 2 2\n", "output": "No solution\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\nL T 1 3\nL B 2 2\nL B 3 3\nT R 1 2\nT B 2 1\nT R 4...
code_contests
verifiable_code
33_E. Helper
Solve the following coding problem using the programming language python: It's unbelievable, but an exam period has started at the OhWord University. It's even more unbelievable, that Valera got all the tests before the exam period for excellent work during the term. As now he's free, he wants to earn money by solving...
vfc_68085
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 1\nmatan\ncodeforces\n2 2\n00:00-08:00\n09:00-09:00\n12:00-12:00\n18:00-18:00\ncodeforces 1 08:04 2\nmatan 1 08:03 1\n", "output": "2\n1\n1 1 08:01 1 08:02\n", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
363_B. Fence
Solve the following coding problem using the programming language python: There is a fence in front of Polycarpus's home. The fence consists of n planks of the same width which go one after another from left to right. The height of the i-th plank is hi meters, distinct planks can have distinct heights. <image> Fence ...
```python n,k=map(int,input().split()) A = list(map(int,input().split())) B = [0] for i in range(k): B[0]+=A[i] for i in range(1,n-k+1): B.append(B[i-1]-A[i-1]+A[i+k-1]) print(B.index(min(B))+1) ```
vfc_68089
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 3\n1 2 6 1 1 7 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n10 20\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
387_A. George and Sleep
Solve the following coding problem using the programming language python: George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t. Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George coul...
```python def tmins(): sh, sm = map(int, input().split(':')) return 60 * sh + sm t = tmins() - tmins() if t < 0: t += 60*24 print('%02d:%02d' % (t//60, t%60)) ```
vfc_68093
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "00:01\n00:00\n", "output": "00:01\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "05:50\n05:44\n", "output": "00:06\n", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
407_D. Largest Submatrix 3
Solve the following coding problem using the programming language python: You are given matrix a of size n × m, its elements are integers. We will assume that the rows of the matrix are numbered from top to bottom from 1 to n, the columns are numbered from left to right from 1 to m. We will denote the element on the i...
vfc_68097
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 6\n1 2 3 4 5 6\n8 6 7 8 9 1\n", "output": "8\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
434_E. Furukawa Nagisa's Tree
Solve the following coding problem using the programming language python: One day, Okazaki Tomoya has bought a tree for Furukawa Nagisa's birthday. The tree is so strange that every node of the tree has a value. The value of the i-th node is vi. Now Furukawa Nagisa and Okazaki Tomoya want to play a game on the tree. ...
vfc_68101
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 13 8 12\n0 12 7 4 12 0 8 12\n1 8\n8 4\n4 6\n6 2\n2 3\n8 5\n2 7\n", "output": "341\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 1 0\n1\n", "output": "1\n", "type": "std...
code_contests
verifiable_code
457_B. Distributed Join
Solve the following coding problem using the programming language python: Piegirl was asked to implement two table join operation for distributed database system, minimizing the network traffic. Suppose she wants to join two tables, A and B. Each of them has certain number of rows which are distributed on different n...
```python n, m = list(map(int, input().split())) A = list(map(int, input().split())) B = list(map(int, input().split())) A.sort(reverse=True) B.sort(reverse=True) sumA = sum(A) sumB = sum(B) ansA = sumB ansB = sumA for i in range(1, n): ansA += min(A[i],sumB) for i in range(1, m): ansB += min(B[i], sumA) print...
vfc_68105
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n2 6\n3 100\n", "output": "11\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
501_E. Misha and Palindrome Degree
Solve the following coding problem using the programming language python: Misha has an array of n integers indexed by integers from 1 to n. Let's define palindrome degree of array a as the number of such index pairs (l, r)(1 ≤ l ≤ r ≤ n), that the elements from the l-th to the r-th one inclusive can be rearranged in s...
vfc_68113
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 2 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n5 5 2 5 2\n", "output": "4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
527_C. Glass Carving
Solve the following coding problem using the programming language python: Leonid wants to become a glass carver (the person who creates beautiful artworks by cutting the glass). He already has a rectangular w mm × h mm sheet of glass, a diamond glass cutter and lots of enthusiasm. What he lacks is understanding of w...
```python w,h,n=map(int,input().split()) l=[-1]*(w+1) r=[-1]*(w+1) t=[-1]*(h+1) b=[-1]*(h+1) l[0]=0 b[0]=0 t[h]=h r[w]=w V=[0]*(n) H=[0]*(n) for i in range(n): line,index=input().split() index=int(index) if line=="V": r[index]=w V[i]=index else: t[index]=h H[i]=index ...
vfc_68117
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3 4\nH 2\nV 2\nV 3\nV 1\n", "output": "8\n4\n4\n2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
553_A. Kyoya and Colored Balls
Solve the following coding problem using the programming language python: Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are labeled from 1 to k. Balls of the same color are indistinguishable. He draws balls from the bag one by one until the bag is empty. He noticed th...
```python #!/usr/bin/python3 import sys from functools import lru_cache MOD = 1000000007 cnk = [[1 for i in range(1001)] for j in range(1001)] for i in range(1, 1001): for j in range(1, i): cnk[i][j] = cnk[i - 1][j - 1] + cnk[i - 1][j] k = int(input()) cs = [int(input()) for i in range(k)] ans = 1 sm ...
vfc_68121
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n2\n3\n4\n", "output": "1680\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\n2\n1\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
600_E. Lomsat gelral
Solve the following coding problem using the programming language python: You are given a rooted tree with root in vertex 1. Each vertex is coloured in some colour. Let's call colour c dominating in the subtree of vertex v if there are no other colours that appear in the subtree of vertex v more times than colour c. ...
```python import sys input = sys.stdin.buffer.readline class SegmentTree: def __init__(self, n, op, e): self.n = n self.op = op self.e = e self.size = 2 ** ((n - 1).bit_length()) self.node = [self.e] * (2 * self.size) def __getitem__(self, i): return self.node[...
vfc_68129
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 2 3 4\n1 2\n2 3\n2 4\n", "output": "10 9 3 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n1 2 3 1 2 3 3 1 1 3 2 2 1 2 3\n1 2\n1 3\n1 4\n1 14\n1 15\n2 5\n2 6\n2 7\n3 8\n3 9\n3 ...
code_contests
verifiable_code
623_B. Array GCD
Solve the following coding problem using the programming language python: You are given array ai of length n. You may consecutively apply two operations to this array: * remove some subsegment (continuous subsequence) of length m < n and pay for it m·a coins; * change some elements of the array by at most 1, and...
vfc_68133
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3 2\n5 17 13 5 6\n", "output": " 8\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
645_A. Amity Assessment
Solve the following coding problem using the programming language python: Bessie the cow and her best friend Elsie each received a sliding puzzle on Pi Day. Their puzzles consist of a 2 × 2 grid and three tiles labeled 'A', 'B', and 'C'. The three tiles sit on top of the grid, leaving one grid cell empty. To make a mo...
```python def read_ints(): return [int(x) for x in input(' ').split()] def evaluate(top, bot): res = 1 if 'X' in top else 2 perm = top + bot perm = [x for x in perm if x != 'X'] for i in range(len(perm)): for j in range(i+1, len(perm)): if perm[i] > perm[j]: res...
vfc_68137
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "AB\nXC\nAC\nBX\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "AB\nXC\nXB\nAC\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
671_D. Roads in Yusland
Solve the following coding problem using the programming language python: Mayor of Yusland just won the lottery and decided to spent money on something good for town. For example, repair all the roads in the town. Yusland consists of n intersections connected by n - 1 bidirectional roads. One can travel from any inte...
vfc_68141
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 5\n1 2\n1 3\n3 4\n4 5\n4 6\n2 1 2\n3 1 4\n4 1 3\n5 3 1\n6 3 2\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 20\n4 8\n6 7\n4 10\n9 4\n8 1\n3 1\n5 10\n7 10\n6 2\n2 7 ...
code_contests
verifiable_code
697_A. Pineapple Incident
Solve the following coding problem using the programming language python: Ted has a pineapple. This pineapple is able to bark like a bulldog! At time t (in seconds) it barks for the first time. Then every s seconds after it, it barks twice with 1 second interval. Thus it barks at times t, t + s, t + s + 1, t + 2s, t +...
```python t,s,x=(int(z) for z in input().split()) x-=t if x>=0 and x%s in [0,1] and x!=1: print("YES") else: print("NO") ```
vfc_68145
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 10 4\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 8 52\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
739_D. Recover a functional graph
Solve the following coding problem using the programming language python: Functional graph is a directed graph in which all vertices have outdegree equal to 1. Loops are allowed. Some vertices of a functional graph lay on a cycle. From the others we can come to a cycle by making a finite number of steps along the edg...
vfc_68153
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n? ?\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1\n1 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
762_C. Two strings
Solve the following coding problem using the programming language python: You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need ...
```python from sys import stdin def main(): t = stdin.readline() s = stdin.readline() n = len(s) - 1 m = len(t) - 1 post = [-1] * n ss = n - 1 st = m - 1 while st >= 0 and ss >= 0: if t[st] == s[ss]: post[ss] = st ss -= 1 st -= 1 pre = [-1] *...
vfc_68157
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "hi\nbob\n", "output": "-", "type": "stdin_stdout" }, { "fn_name": null, "input": "abca\naccepted\n", "output": "ac", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
785_D. Anton and School - 2
Solve the following coding problem using the programming language python: As you probably know, Anton goes to school. One of the school subjects that Anton studies is Bracketology. On the Bracketology lessons students usually learn different sequences that consist of round brackets (characters "(" and ")" (without quo...
```python mod = 10 ** 9 + 7 fact, inv, invfact = [1, 1], [0, 1], [1, 1] for i in range(2, 200200): fact.append(fact[-1] * i % mod) inv.append(inv[mod % i] * (mod - mod // i) % mod) invfact.append(invfact[-1] * inv[-1] % mod) def C(n, k): if k < 0 or k > n: return 0 return fact[n] * invfact...
vfc_68161
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": ")(()()\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "()()()\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ")...
code_contests
verifiable_code
807_D. Dynamic Problem Scoring
Solve the following coding problem using the programming language python: Vasya and Petya take part in a Codeforces round. The round lasts for two hours and contains five problems. For this round the dynamic problem scoring is used. If you were lucky not to participate in any Codeforces round with dynamic problem sco...
```python import sys inf = 10**9 + 7 def solve(): n = int(sys.stdin.readline()) v = [int(vi) for vi in sys.stdin.readline().split()] # Vesya p = [int(pi) for pi in sys.stdin.readline().split()] # Petya cnt = [0]*5 for i in range(5): if v[i] != -1: cnt[i] += 1 if p[i]...
vfc_68165
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 15 40 70 115\n50 45 40 30 15\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n119 119 119 119 119\n0 0 0 0 -1\n20 65 12 73 77\n78 112 22 23 11\n1 78 60 111 62\n", ...
code_contests
verifiable_code
831_E. Cards Sorting
Solve the following coding problem using the programming language python: Vasily has a deck of cards consisting of n cards. There is an integer on each of the cards, this integer is between 1 and 100 000, inclusive. It is possible that some cards have the same integers on them. Vasily decided to sort the cards. To do...
```python # -*- coding: utf-8 -*- import sys # fout = open("output.txt", "w") fin = sys.stdin # fin = open("input.txt", "r") fout = sys.stdout n = int(fin.readline()) a = list(map(int, fin.readline().split())) def solution(n, a): sorted_arr = [(i, elem) for i, elem in enumerate(a)] sorted_arr.sort(key=lamb...
vfc_68169
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n6 3 1 2\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1000\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
852_F. Product transformation
Solve the following coding problem using the programming language python: Consider an array A with N elements, all being the same integer a. Define the product transformation as a simultaneous update Ai = Ai·Ai + 1, that is multiplying each element to the element right to it for <image>, with the last number AN remai...
vfc_68173
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 2 7\n", "output": "1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 490018 5 5880229\n", "output": "5 ", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
877_A. Alex and broken contest
Solve the following coding problem using the programming language python: One day Alex was creating a contest about his friends, but accidentally deleted it. Fortunately, all the problems were saved, but now he needs to find them among other problems. But there are too many problems, to do it manually. Alex asks you ...
```python judul = input() nama = ["Danil", "Olya", "Slava", "Ann", "Nikita"] cek = 0 ada = [] for i in range(0, 5): ada.append(judul.count(nama[i])) cek = cek + ada[i] if cek == 1: print("YES") else: print("NO") ```
vfc_68177
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Alex_and_broken_contest\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "NikitaAndString\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
900_B. Position in Fraction
Solve the following coding problem using the programming language python: You have a fraction <image>. You need to find the first occurrence of digit c into decimal notation of the fraction after decimal point. Input The first contains three single positive integers a, b, c (1 ≤ a < b ≤ 105, 0 ≤ c ≤ 9). Output Pri...
```python a,b,c = map(int, input().split()) t = a q, r = divmod(t, b) for i in range(1, 10**5+1): q, r = divmod(r*10, b) #print(q) if q == c: print(i) exit() else: print(-1) ```
vfc_68181
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3 7\n", "output": "-1\n", "type": "stdin_stdout" } ] }