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
1313_C2. Skyscrapers (hard version)
Solve the following coding problem using the programming language python: This is a harder version of the problem. In this version n ≤ 500 000 The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskv...
```python import sys input=sys.stdin.readline n=int(input()) m=[int(i) for i in input().split()] copy=m[:] def maxsumchecker(arr): stack,lr=[],[0]*(n) for i in range(n): while stack and stack[-1][1]>m[i]: stack.pop() if stack: j=stack[-1][0] lr[i]=lr[j]+(i-j)*...
vfc_63425
{ "difficulty": "9", "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\n1 2 3 2 1\n", "output": "1 2 3 2 1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n10 6 8\n", "output": "10 6 6 \n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
1336_A. Linova and Kingdom
Solve the following coding problem using the programming language python: Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it. <image> Th...
```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_63429
{ "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": "7 4\n1 2\n1 3\n1 4\n3 5\n3 6\n4 7\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n1 2\n1 3\n2 4\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1358_D. The Best Vacation
Solve the following coding problem using the programming language python: You've been in love with Coronavirus-chan for a long time, but you didn't know where she lived until now. And just now you found out that she lives in a faraway place called Naha. You immediately decided to take a vacation and visit Coronaviru...
```python def sm(a, b): val = (a + b) * (b - a + 1) // 2 return (val) n, x = [int(x) for x in input().split()] d = [int(x) for x in input().split()] * 2 mx, i, j, day, hug = 0, 0, 0, 0, 0 while(i < n): if day + d[j] <= x: day += d[j] hug += sm(1, d[j]) j += 1 else: mx =...
vfc_63433
{ "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": "5 6\n4 2 3 1 3\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 6\n3 3 3\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1399_E1. Weights Division (easy version)
Solve the following coding problem using the programming language python: Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a connected graph without cycles. A rooted tree has ...
```python import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log2, ceil from collections import defaultdict from bisect import bisect_left as bl, bisect_right as br from collections import Counter from collections import deque from heapq import heappush,heappop,heapify...
vfc_63441
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 20\n2 1 8\n3 1 7\n5 50\n1 3 100\n1 5 10\n2 3 123\n5 4 55\n2 100\n1 2 409\n", "output": "0\n8\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4 18\n2 1 9 2\n3 2 4 1\n4 1 1 2\n3 2...
code_contests
verifiable_code
1423_B. Valuable Paper
Solve the following coding problem using the programming language python: The pandemic is upon us, and the world is in shortage of the most important resource: toilet paper. As one of the best prepared nations for this crisis, BubbleLand promised to help all other world nations with this valuable resource. To do that,...
```python def hopcroft_karp(graph, n, m): """ Maximum bipartite matching using Hopcroft-Karp algorithm, running in O(|E| sqrt(|V|)) """ assert (n == len(graph)) match1 = [-1] * n match2 = [-1] * m # Find a greedy match for possible speed up for node in range(n): for nei in graph...
vfc_63445
{ "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 5\n1 2 1\n2 3 2\n3 3 3\n2 1 4\n2 2 5\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 9\n3 3 8\n2 4 7\n2 3 6\n2 1 9\n5 1 3\n1 1 6\n4 3 6\n4 1 2\n4 2 3\n", "output...
code_contests
verifiable_code
1468_C. Berpizza
Solve the following coding problem using the programming language python: Monocarp and Polycarp are working as waiters in Berpizza, a pizzeria located near the center of Bertown. Since they are waiters, their job is to serve the customers, but they choose whom they serve first differently. At the start of the working...
```python from sys import stdin from heapq import * Q = int(stdin.readline()) customer_id = 1 pq = [] first = 1 ans = [] served = set() for q in range(Q): args = stdin.readline().split() if args[0] == "1": heappush(pq, [-1*int(args[1]), customer_id]) customer_id += 1 elif args[0] == "2": ans.append...
vfc_63453
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n1 8\n1 10\n1 6\n3\n2\n1 9\n2\n3\n", "output": "\n2 1 3 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n1 103913\n3\n1 103913\n1 103913\n3\n1 103913\n1 103913\n2\n", "output": ...
code_contests
verifiable_code
1515_C. Phoenix and Towers
Solve the following coding problem using the programming language python: Phoenix has n blocks of height h_1, h_2, ..., h_n, and all h_i don't exceed some value x. He plans to stack all n blocks into m separate towers. The height of a tower is simply the sum of the heights of its blocks. For the towers to look beautif...
```python import heapq import sys input = iter(sys.stdin.read().splitlines()).__next__ def solve(): n, m, x = map(int, input().split()) h = list(map(int, input().split())) # greedy; put on shortest tower towers = [(0, i+1) for i in range(m)] y = [] for h_i in h: height, tower = heapq.h...
vfc_63461
{ "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": "2\n5 2 3\n1 2 3 1 2\n4 3 3\n1 1 2 3\n", "output": "\nYES\n1 1 1 2 2\nYES\n1 2 2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5 2 3\n1 2 3 1 2\n4 3 3\n1 1 2 3\n", "output": "YES...
code_contests
verifiable_code
1542_B. Plus and Multiply
Solve the following coding problem using the programming language python: There is an infinite set generated as follows: * 1 is in this set. * If x is in this set, x ⋅ a and x+b both are in this set. For example, when a=3 and b=6, the five smallest elements of the set are: * 1, * 3 (1 is in this set, s...
```python import sys input=sys.stdin.readline t=int(input()) for i in range(t): n,a,b=map(int,input().split()) if(a==1): if((n-1)%b==0): print('YES') else: print('NO') continue; t=1 flag=0 while(t<=n): if((n-t)%b==0): flag=1 ...
vfc_63465
{ "difficulty": "8", "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\n24 3 5\n10 3 6\n2345 1 4\n19260817 394 485\n19260817 233 264\n", "output": "Yes\nNo\nYes\nNo\nYes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n24 3 5\n10 5 6\n2345 1 4\n19260817 3...
code_contests
verifiable_code
16_B. Burglar and Matches
Solve the following coding problem using the programming language python: A burglar got into a matches warehouse and wants to steal as many matches as possible. In the warehouse there are m containers, in the i-th container there are ai matchboxes, and each matchbox contains bi matches. All the matchboxes are of the s...
```python """ read: 1:01 think: 2:46 code: 10:48 debug: --:-- status: TL """ n, m = map(int, input().split()) c = [list(map(int, input().split())) for i in range(m)] c.sort(key=lambda x: x[1], reverse=True) mx = 0 i = 0 while n > 0 and i < m: add = min(n, c[i][0]) mx += add * c[i][1] n -= add i += 1 ...
vfc_63469
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1 3\n2 2\n3 1\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 3\n5 10\n2 5\n3 6\n", "output": "62\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
18_E. Flag 2
Solve the following coding problem using the programming language python: According to a new ISO standard, a flag of every country should have, strangely enough, a chequered field n × m, each square should be wholly painted one of 26 colours. The following restrictions are set: * In each row at most two different ...
```python import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') n, m = map(int, input().split()) flag = [tuple(map(lambda c: ord(c) - 97, input().rstrip())) for _ in range(n)] dp = [[[m] * 26 for _ in range(26)] for _ in range(n)] for i in range(n): ...
vfc_63473
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 128000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\naba\naba\nzzz\n", "output": "4\nbab\naba\nzaz\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\naaaa\nbbbb\ncccc\n", "output": "6\nabab\nbaba\nacac\n", "type": "stdin_s...
code_contests
verifiable_code
213_E. Two Permutations
Solve the following coding problem using the programming language python: Rubik is very keen on number permutations. A permutation a with length n is a sequence, consisting of n different numbers from 1 to n. Element number i (1 ≤ i ≤ n) of this permutation will be denoted as ai. Furik decided to make a present to ...
vfc_63477
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n2 3 1\n1 2 3\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1\n1\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
237_E. Build String
Solve the following coding problem using the programming language python: You desperately need to build some string t. For that you've got n more strings s1, s2, ..., sn. To build string t, you are allowed to perform exactly |t| (|t| is the length of string t) operations on these strings. Each operation looks like tha...
```python class Edge: def __init__(self, to, cost, capacity, next_edge): self.to = to self.cost = cost self.origin_cost = cost self.capacity = capacity self.next_edge = next_edge self.pair = None class MinCostMaxFlow: def __init__(self, max_node): self.n...
vfc_63481
{ "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": "abacaba\n4\naba 2\nbcc 1\ncaa 2\nbbb 5\n", "output": "18\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "xyz\n4\naxx 8\nza 1\nefg 4\nt 1\n", "output": "-1\n", "type": "stdin_st...
code_contests
verifiable_code
262_C. Maxim and Discounts
Solve the following coding problem using the programming language python: Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are m types of discounts. We assume that the discounts are indexed from 1 to m. To use the discount number i, the customer tak...
```python m=int(input()) q=list(map(int,input().split())) n=int(input()) a=list(map(int,input().split())) q.sort() a.sort() j=n-1 i=0 ans=0 while j>=0: for i in range(q[0]): ans=ans+a[j] j=j-1 if j<0: break j=j-2 print(ans) ```
vfc_63485
{ "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": "1\n1\n7\n1 1 1 1 1 1 1\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 3\n5\n50 50 50 50 50\n", "output": "150", "type": "stdin_stdout" }, { "...
code_contests
verifiable_code
286_C. Main Sequence
Solve the following coding problem using the programming language python: As you know, Vova has recently become a new shaman in the city of Ultima Thule. So, he has received the shaman knowledge about the correct bracket sequences. The shamans of Ultima Thule have been using lots of different types of brackets since p...
```python import sys range = xrange input = raw_input n = int(input()) P = [int(x) for x in input().split()] for i in [int(x) - 1 for x in input().split()][1:]: P[i] *= -1 stack = [] for i in reversed(range(n)): p = P[i] if (not stack) or stack[-1] != p: stack.append(abs(p)) P[i] = -abs(p...
vfc_63489
{ "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": "2\n1 1\n0\n", "output": "YES\n1 -1 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
311_C. Fetch the Treasure
Solve the following coding problem using the programming language python: Rainbow built h cells in a row that are numbered from 1 to h from left to right. There are n cells with treasure. We call each of these n cells "Treasure Cell". The i-th "Treasure Cell" is the ai-th cell and the value of treasure in it is ci dol...
vfc_63493
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 3 5 2\n5 50\n7 60\n8 100\n2 2 5\n3\n1 3\n3\n3\n", "output": "55\n100\n50\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
334_A. Candy Bags
Solve the following coding problem using the programming language python: Gerald has n younger brothers and their number happens to be even. One day he bought n2 candy bags. One bag has one candy, one bag has two candies, one bag has three candies and so on. In fact, for each integer k from 1 to n2 he has exactly one ...
```python n=int(input())**2 k=0 for i in range(n//2): print(i+1,n-i,end=' ') k+=1 if k%2==0: print() ```
vfc_63497
{ "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\n", "output": "1 4\n2 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "68\n", "output": "1 4624 2 4623 3 4622 4 4621 5 4620 6 4619 7 4618 8 4617 9 4616 10 4615 11 4614 12 4613 13 ...
code_contests
verifiable_code
357_A. Group of Students
Solve the following coding problem using the programming language python: At the beginning of the school year Berland State University starts two city school programming groups, for beginners and for intermediate coders. The children were tested in order to sort them into groups. According to the results, each student...
```python m=int(input()) l=list(map(int,input().split())) x,y=map(int,input().split()) theI=0 for i in range(len(l)): first_sum=sum(l[0:i]) second_sum=sum(l[i:]) if (first_sum>=x and first_sum<=y) and (second_sum>=x and second_sum<=y): theI=i+1 print(theI) ```
vfc_63501
{ "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": "5\n3 4 3 2 1\n6 8\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 5\n3 6\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
37_E. Trial for Chief
Solve the following coding problem using the programming language python: Having unraveled the Berland Dictionary, the scientists managed to read the notes of the chroniclers of that time. For example, they learned how the chief of the ancient Berland tribe was chosen. As soon as enough pretenders was picked, the fol...
vfc_63505
{ "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\nBBB\nBWB\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\nWBW\nBWB\nWBW\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
400_D. Dima and Bacteria
Solve the following coding problem using the programming language python: Dima took up the biology of bacteria, as a result of his experiments, he invented k types of bacteria. Overall, there are n bacteria at his laboratory right now, and the number of bacteria of type i equals ci. For convenience, we will assume tha...
```python #!/usr/bin/env python3 from sys import stdin from bisect import bisect_left, bisect_right INF = int(1e9) def find(par, a): if par[a] == a: return a par[a] = find(par, par[a]) return par[a] def union(par, rnk, a, b): a = find(par,a) b = find(par,b) if a==b: return...
vfc_63509
{ "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": "3 2 2\n2 1\n1 2 0\n2 3 1\n", "output": "Yes\n0 1 \n1 0 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4 2\n1 3\n2 3 0\n3 4 0\n2 4 1\n2 1 2\n", "output": "Yes\n0 2 \n2 0 \n", ...
code_contests
verifiable_code
427_E. Police Patrol
Solve the following coding problem using the programming language python: Imagine that your city is an infinite 2D plane with Cartesian coordinate system. The only crime-affected road of your city is the x-axis. Currently, there are n criminals along the road. No police station has been built on this road yet, so the ...
```python # ------------------- fast io -------------------- 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...
vfc_63513
{ "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 6\n1 2 3\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 369\n0\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
450_C. Jzzhu and Chocolate
Solve the following coding problem using the programming language python: Jzzhu has a big rectangular chocolate bar that consists of n × m unit squares. He wants to cut this bar exactly k times. Each cut must meet the following requirements: * each cut should be straight (horizontal or vertical); * each cut shou...
```python #!/usr/bin/env python3 from itertools import * def read_ints(): return map(int, input().strip().split()) n, m, k = read_ints() def val(x, k, n, m): Y = x+1 Z = k-x+1 if Y>0 and Z>0: return (n//(x+1)) * (m//(k-x+1)) def sym(n, m, k): x = min(n-1, k) return val(x, k, n, m) def...
vfc_63517
{ "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": "6 4 2\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 4\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 ...
code_contests
verifiable_code
496_E. Distributing Parts
Solve the following coding problem using the programming language python: You are an assistant director in a new musical play. The play consists of n musical parts, each part must be performed by exactly one actor. After the casting the director chose m actors who can take part in the play. Your task is to assign the ...
vfc_63525
{ "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\n1 3\n2 4\n3 5\n2\n1 3 2\n2 5 1\n", "output": "NO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
520_B. Two Buttons
Solve the following coding problem using the programming language python: Vasya has found a strange device. On the front panel of a device there are: a red button, a blue button and a display showing some positive integer. After clicking the red button, device multiplies the displayed number by two. After clicking the...
```python n, m = [int(x) for x in input().split()] s = 0 while(n < m): s += 1 + (m % 2) m = (m + m % 2) // 2 print(s + n - m) ```
vfc_63529
{ "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": "4 6\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 1\n", "output": "9\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
574_A. Bear and Elections
Solve the following coding problem using the programming language python: Limak is a grizzly bear who desires power and adoration. He wants to win in upcoming elections and rule over the Bearland. There are n candidates, including Limak. We know how many citizens are going to vote for each candidate. Now i-th candida...
```python n=int(input()) a=list(map(int,input().split(" "))) lim=a[0] a[1:]=sorted(a[1:]) # print(a,a[-1]) t=0 while(a[0] <= a[-1]): a[0]=a[0]+1 a[-1]=a[-1]-1 t+=1 a[1:]=sorted(a[1:]) print(t) ```
vfc_63537
{ "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\n7 6\n", "output": "0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
617_A. Elephant
Solve the following coding problem using the programming language python: An elephant decided to visit his friend. It turned out that the elephant's house is located at point 0 and his friend's house is located at point x(x > 0) of the coordinate line. In one step the elephant can move 1, 2, 3, 4 or 5 positions forwar...
```python if __name__ == '__main__': c = int(input()) x = [5,4,3,2,1] count = 0 while x!=[]: m = max(x) while c>=max(x): c=c-m count+=1 x.pop(0) print (count) ```
vfc_63545
{ "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": "12\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
637_B. Chat Order
Solve the following coding problem using the programming language python: Polycarp is a big lover of killing time in social networks. A page with a chatlist in his favourite network is made so that when a message is sent to some friend, his friend's chat rises to the very top of the page. The relative order of the oth...
```python n = int(input()) chat_list = [] names = set() for i in range(n): name = input() if name not in names: names.add(name) chat_list.append(name) x = len(names) for i in chat_list[::-1]: if i in names: print(i) names.remove(i) x -= 1 if x == 0: br...
vfc_63549
{ "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": "4\nalex\nivan\nroman\nivan\n", "output": "ivan\nroman\nalex\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\nalina\nmaria\nekaterina\ndarya\ndarya\nekaterina\nmaria\nalina\n", "out...
code_contests
verifiable_code
665_B. Shopping
Solve the following coding problem using the programming language python: Ayush is a cashier at the shopping center. Recently his department has started a ''click and collect" service which allows users to shop online. The store contains k items. n customers have already used the above service. Each user paid for m ...
```python user,item,total=map(int,input().split()) items=list(map(int,input().split())) to=0 for i in range(user): a=list(map(int,input().split())) for j in a: to+=items.index(j)+1 items.pop(items.index(j)) items=[j]+items print(to) ```
vfc_63553
{ "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 5\n3 4 1 2 5\n1 5\n3 1\n", "output": "14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1\n1\n1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
689_E. Mike and Geometry Problem
Solve the following coding problem using the programming language python: Mike wants to prepare for IMO but he doesn't know geometry, so his teacher gave him an interesting geometry problem. Let's define f([l, r]) = r - l + 1 to be the number of integer points in the segment [l, r] with l ≤ r (say that <image>). You a...
```python MOD = 10**9 + 7 from sys import stderr def readints(): return [int(fld) for fld in input().strip().split()] def combk(n, k, MOD=MOD, tbl=[]): if len(tbl) < k: tbl += [0] * k + [1] while n >= len(tbl): tbl.append(tbl[-1] * len(tbl) * pow(len(tbl) - k, MOD-2, MOD) % MOD) retur...
vfc_63557
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1 3\n1 3\n1 3\n", "output": " 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n1 2\n2 3\n3 4\n", "output": " ...
code_contests
verifiable_code
711_C. Coloring Trees
Solve the following coding problem using the programming language python: ZS the Coder and Chris the Baboon has arrived at Udayland! They walked in the park where n trees grow. They decided to be naughty and color the trees in the park. The trees are numbered with integers from 1 to n from left to right. Initially, t...
```python import math dp=[[[math.inf for i in range(105)] for i in range(105)] for i in range(105)] #dp[x][y][z] denote index x , beauty y , using paint z #dp[x][y][z] denotes cost of it n,m,k=map(int,input().split()) k+=1 z=list(map(int,input().split())) matrix=[] for i in range(n): ans=list(map(int,input().spl...
vfc_63561
{ "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": "3 2 2\n2 1 2\n1 3\n2 4\n3 5\n", "output": " -1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 2\n0 0 0\n1 2\n3 4\n5 6\n", ...
code_contests
verifiable_code
732_C. Sanatorium
Solve the following coding problem using the programming language python: Vasiliy spent his vacation in a sanatorium, came back and found that he completely forgot details of his vacation! Every day there was a breakfast, a dinner and a supper in a dining room of the sanatorium (of course, in this order). The only t...
```python mod = 1000000007 ii = lambda : int(input()) si = lambda : input() dgl = lambda : list(map(int, input())) f = lambda : map(int, input().split()) il = lambda : list(map(int, input().split())) ls = lambda : list(input()) a,b,c=sorted(il(),reverse=True) sm=0 if a!=b: sm+=max(0,(a-b-1))+max(0,(a-c-1)) else: ...
vfc_63565
{ "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 0 0\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
756_D. Bacterial Melee
Solve the following coding problem using the programming language python: Julia is conducting an experiment in her lab. She placed several luminescent bacterial colonies in a horizontal testtube. Different types of bacteria can be distinguished by the color of light they emit. Julia marks types of bacteria with small ...
```python from sys import stdin, stdout rr = lambda: stdin.readline().strip() MOD = 10**9 + 7 from string import ascii_lowercase as alpha from itertools import groupby N = int(rr()) S = rr() A = [] for k,v in groupby(S): A.append(k) G = len(A) last = {c: -1 for c in alpha} prev = [0]*G for i, u in enumerate(A): ...
vfc_63569
{ "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": "7\nabacaba\n", "output": "589\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
777_E. Hanoi Factory
Solve the following coding problem using the programming language python: Of course you have heard the famous task about Hanoi Towers, but did you know that there is a special factory producing the rings for this wonderful game? Once upon a time, the ruler of the ancient Egypt ordered the workers of Hanoi Factory to c...
```python aux = [(9e9, 0, 0)] n = int(input()) for i in range(n): a, b, h = map(int, input().split()) aux.append((b, a, h)) #sort padrao eh pelo item 0 da tupla aux.sort(reverse=True) s, p = [0], [0] *(n + 1) for i in range(1, n + 1): while aux[s[-1]][1] >= aux[i][0]: s.pop() p[...
vfc_63573
{ "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\n1 2 1\n1 3 3\n4 6 2\n5 7 1\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 5 1\n2 6 2\n3 7 3\n", "output": "6", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
802_C. Heidi and Library (hard)
Solve the following coding problem using the programming language python: The good times at Heidi's library are over. Marmots finally got their internet connections and stopped coming to the library altogether. Not only that, but the bookstore has begun charging extortionate prices for some books. Namely, whereas in t...
vfc_63577
{ "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 1\n1 2 2 1\n1 1 1 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n1 2 3 1\n1 1 1 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
822_E. Liar
Solve the following coding problem using the programming language python: The first semester ended. You know, after the end of the first semester the holidays begin. On holidays Noora decided to return to Vičkopolis. As a modest souvenir for Leha, she brought a sausage of length m from Pavlopolis. Everyone knows that ...
vfc_63581
{ "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": "9\nhloyaygrt\n6\nloyyrt\n2\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\nhloyaygrt\n6\nloyyrt\n3\n", "output": "YES\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
847_J. Students Initiation
Solve the following coding problem using the programming language python: Soon the first year students will be initiated into students at the University of Berland. The organizers of the initiation come up with a program for this holiday. In their opinion, it would be good if the first-year students presented small so...
vfc_63585
{ "difficulty": "16", "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\n1 2\n1 3\n1 4\n", "output": "1\n1 2\n3 1\n4 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n1 2\n4 1\n4 2\n3 2\n4 3\n1 3\n", "output": "2\n1 2\n1 4\n2 4\n2 3\n3 4\n3 1\n"...
code_contests
verifiable_code
869_E. The Untended Antiquity
Solve the following coding problem using the programming language python: Adieu l'ami. Koyomi is helping Oshino, an acquaintance of his, to take care of an open space around the abandoned Eikou Cram School building, Oshino's makeshift residence. The space is represented by a rectangular grid of n × m cells, arranged...
vfc_63589
{ "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": "5 6 5\n1 2 2 4 5\n1 3 3 3 3\n3 4 4 1 1\n2 2 2 4 5\n3 1 1 4 4\n", "output": "No\nYes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2500 2500 8\n1 549 1279 1263 2189\n1 303 795 1888 2432\n...
code_contests
verifiable_code
895_D. String Mark
Solve the following coding problem using the programming language python: At the Byteland State University marks are strings of the same length. Mark x is considered better than y if string y is lexicographically smaller than x. Recently at the BSU was an important test work on which Vasya recived the mark a. It is v...
vfc_63593
{ "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": "abc\nddd\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "abcdef\nabcdeg\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
916_E. Jamie and Tree
Solve the following coding problem using the programming language python: To your surprise, Jamie is the final boss! Ehehehe. Jamie has given you a tree with n vertices, numbered from 1 to n. Initially, the root of the tree is the vertex with number 1. Also, each vertex has a value on it. Jamie also gives you three ...
vfc_63597
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 6\n4 3 5 6\n1 2\n2 3\n3 4\n3 1\n1 3\n2 2 4 3\n1 1\n2 2 4 -3\n3 1\n", "output": "18\n21\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 7\n1 4 2 8 5 7\n1 2\n3 1\n4 3\n4 5\n3 6\n3 1\n2 4...
code_contests
verifiable_code
939_F. Cutlet
Solve the following coding problem using the programming language python: Arkady wants to have a dinner. He has just returned from a shop where he has bought a semifinished cutlet. He only needs to fry it. The cutlet should be fried for 2n seconds, in particular, it should be fried for n seconds on one side and n seco...
vfc_63601
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 3\n3 5\n9 10\n11 13\n", "output": "Full\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 2\n3 5\n11 13\n", "output": "Full\n2\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
965_C. Greedy Arkady
Solve the following coding problem using the programming language python: k people want to split n candies between them. Each candy should be given to exactly one of them or be thrown away. The people are numbered from 1 to k, and Arkady is the first of them. To split the candies, Arkady will choose an integer x and ...
```python n, k, m, d = map(int, input().split()) ans = 0 for i in range(d + 1): w = 0 if i > 0: w = n // (k * i) if w > m: w = m res = w * i if n - k * i * w >= w and i + 1 <= d: res += w ans = max(ans, res) w = n // (k * i + 1) if w > m: w = m res =...
vfc_63605
{ "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": "20 4 5 2\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30 9 4 1\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
992_C. Nastya and a Wardrobe
Solve the following coding problem using the programming language python: Nastya received a gift on New Year — a magic wardrobe. It is magic because in the end of each month the number of dresses in it doubles (i.e. the number of dresses becomes twice as large as it is in the beginning of the month). Unfortunately, r...
```python #------------------------template--------------------------# import os import sys # from math import * from collections import * # from fractions import * from heapq import* from bisect import * from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output....
vfc_63609
{ "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": "2 0\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n",...
code_contests
verifiable_code
chemical-mixture
Solve the following coding problem using the programming language python: View Russian Translation A wild chemist wants to prepare his mysterious mixture. The recipe is very simple, he has already mixed all the necessary powders and the only remaining thing is to add exactly m nanoliters of any liquids. In his la...
```python import itertools def valid(m,S): W = [] for k in S: if (m >= k): m -= k W.append(k) return (m==0,W) def solve(): m,n,N = map(int,raw_input().split()) S = map(int,raw_input().split()); S.sort(); S.reverse() T = map(int,raw_input().split()) val = -1 for r in range(len(T)): for z in it...
vfc_63617
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n7 2 2\n2 4\n1 3\n11 2 2\n2 4\n1 3\n\nSAMPLE", "output": "YES\n2 4 \nNO", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n705 15 10\n38 9950 2485 154 79610 1241 4973 19902 76 620 39805 3...
code_contests
verifiable_code
double-or-divide-1
Solve the following coding problem using the programming language python: Omar loves problem solving very much and today he faces the following problem. Given a multiset A of N integers {a_1, a_2, \ldots, a_N} and an integer L, his task is to perform L operations indexed from 1 to L in the ascending order of their i...
```python from sys import stdin import math n,l = map(int,stdin.readline().split()) a = [0]*(l+5) b = [0] * (l+5) x = map(int,stdin.readline().split()) x.sort() y = [0]*n for i in xrange(2,l+1): if a[i]==0: cur = i while cur<=l: tm = cur co = 0 while tm%i==0: tm/=i co+=1 if co > b[cur]: b[c...
vfc_63621
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n2 4 5 8 10\n\nSAMPLE", "output": "4\n2 5 8 20", "type": "stdin_stdout" }, { "fn_name": null, "input": "39 7720\n21239 2438 8856 11798 8366 32286 10451 30613 5854 28101 1143 282 20538 15922 8946 ...
code_contests
verifiable_code
grey-worm-and-his-unsullied
Solve the following coding problem using the programming language python: More Unsullied army are joining Daenerys Stormborn of the House Targaryen, the First of Her Name, the Unburnt, Queen of Meereen, Queen of the Andals and the Rhoynar and the First Men, Khaleesi of the Great Grass Sea, Breaker of Chains, and Moth...
```python from sys import stdin t = int(stdin.readline()) for _ in xrange(t): n = int(stdin.readline()) a = [] for __ in xrange(n): m = int(stdin.readline()) b = map(int,stdin.readline().split()) for i in b: a.append(i) a.sort() for i in a: print i, print "" ```
vfc_63625
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n4\n1 4 7 10\n5\n3 8 12 16 19\n6\n2 6 9 14 18 25\n\nSAMPLE", "output": "1 2 3 4 6 7 8 9 10 12 14 16 18 19 25", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3\n746\n101 102 103 106 1...
code_contests
verifiable_code
little-jhool-the-devdas
Solve the following coding problem using the programming language python: "Not every love story has a happy ending!"- Little Jhool was certainly a con man, fooling people by telling them about their future, [The first problem!] but he loved his girl - truly! But, Big Jhool, his girlfriend, was shocked and had broken u...
```python noOfFlowers = input() flowers = sorted(map(int, raw_input().split())) petals = sum(flowers) if petals % 2 == 1: print petals else: for flower in flowers: if flower % 2 == 1: print petals - flower exit() print ":(" ```
vfc_63629
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n4\n\nSAMPLE", "output": ":(\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n4\n\nSAMQLE", "output": ":(\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
my-notepad
Solve the following coding problem using the programming language python: Students of Computer Science Department of SKIT have designed a basic Notepad for the purpose of studying the functioning and advance features in many other text editors. It is a simple text editor that supports only the following two commands: ...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' import sys T = int(sys.stdin.readline()) for i in xrange(T): N = int(sys.stdin.readline()) stack=[] for j in xrange(N): line = sys.stdin.readline().split() tup = (int(l...
vfc_63633
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n1 type a\n2 type b\n3 type c\n5 undo 3\n4\n1 type a\n2 type b\n3 undo 2\n4 undo 2\n\nSAMPLE", "output": "a\na", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
prefpref
Solve the following coding problem using the programming language python: You are given two string S and T. Find the maximal length of some prefix of the string S which occurs in strings T as subsequence. Input The first line contains string S. The second line contains string T. Both strings consist of lowecase Latin...
```python first = raw_input() second = raw_input() length=0 pos=0 while(length < len(first) and pos < len(second)): if (first[length] == second[pos]): length += 1 pos += 1 print length ```
vfc_63637
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "digger\nbiggerdiagram\n\nSAMPLE", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "digger\nmargaidreggib\n\nSAMPLE", "output": "2\n", "type": "stdin_stdout" } ...
code_contests
verifiable_code
samu-and-special-coprime-numbers
Solve the following coding problem using the programming language python: Samu had come up with new type of numbers, she named them Special Coprime numbers. Special Coprime numbers follow a property : A number N is said to be Special Coprime if sum of its digits as well as the sum of the squares of its digits are cop...
```python from fractions import gcd def solveDP(pos, sumD, sumSq, check): if pos == -1: return 1 if gcd(sumD, sumSq) == 1 else 0 if not check and dp[pos][sumD][sumSq] != -1: return dp[pos][sumD][sumSq] ans, endDig = 0, 0 endDig = digits[pos] if check else 9 for curDig in xrange(0...
vfc_63641
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5 15\n\nSAMPLE", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n5 19\n\nSAMPLE", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
super-two-letter-strings
Solve the following coding problem using the programming language python: Two letter strings are the strings consisting of only two letters "X" and "Y". A string is "super two letter string" if a) It does not have leading "X" letters. b) It does not contain P consecutive "X" letters. Your task is to find total numb...
```python mod = 1000000007 for tc in xrange(input()): N, P = map(int, raw_input().split()) X = [0] * N Y = [0] * N if P >= N: print 1 << N - 1 continue Y[0] = 1 for i in xrange(1, P): # until P length no consecutive X X[i] = X[i - 1] + Y[i - 1] Y[i] = X[i - 1] + Y[i - 1] for i in xrange(P, N): X[i]...
vfc_63645
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 1\n4 2\n\nSAMPLE", "output": "1\n5", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n42 8\n35 1\n70 5\n79 9\n63 5\n6 6\n82 8\n62 2\n96 3\n28 7\n92 5\n3 4\n93 3\n22 7\n19 6\n48 7\n72 ...
code_contests
verifiable_code
what-time-is-it
Solve the following coding problem using the programming language python: Given the time shown by a wall clock, you have to output the internal angle between the minute and hour hand of the clock. (Wall Clock displays a 12 hour format.) For instance, if the time shown is 01:00 , the angle between the hands is 30 degr...
```python [h,m]=[int(i) for i in raw_input().split(':')]; mangle=6.0*m; hangle=(h%12.0)*30+0.5*m; deg=mangle-hangle; if deg<0: deg*=(-1); print "%.6f"%min(deg,360-deg); ```
vfc_63649
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "04:00\n\nSAMPLE", "output": "120.000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "05:55", "output": "152.500000\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
p00519 Taxis
Solve the following coding problem using the programming language python: problem The IOI country consists of N towns from town 1 to town N, and the towns are connected by roads. The IOI country has K roads, all of which connect two different towns. Cars can move freely in both directions on the road, but they cannot...
```python from heapq import heappop as pop from heapq import heappush as push def main(): n, k = map(int, input().split()) clst = [] rlst = [] for i in range(n): c, r = map(int, input().split()) clst.append(c) rlst.append(r) edges = [[] * n for i in range(n)] for i in range(k): ...
vfc_63705
{ "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": "6 6\n400 2\n200 1\n600 3\n1000 1\n300 5\n700 4\n1 2\n2 3\n3 6\n4 6\n1 5\n2 4", "output": "700", "type": "stdin_stdout" }, { "fn_name": null, "input": "None", "output": "None", "type": "st...
code_contests
verifiable_code
p00692 Patience
Solve the following coding problem using the programming language python: As the proverb says, > "Patience is bitter, but its fruit is sweet." Writing programs within the limited time may impose some patience on you, but you enjoy it and win the contest, we hope. The word "patience" has the meaning of perseverance,...
```python # AOJ 1110: Patience # Python3 2018.7.8 bal4u pair = [[1,4,5], [2,4,5,6], [3,5,6,7], [6,7], [5,8,9], [6,8,9,10], [7,9,10,11], [10,11], [9,12,13], [10,12,13,14], [11,13,14,15], [14,15], [13,16,17], [14,16,17,18], [15,17,18,19], [18,19], [17], [18], [19]] def combi(cd, n): global ans ans = min(ans, n) i...
vfc_63709
{ "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": "4\n1 4 5 2\n3 1 4 3\n5 4 2 2\n4 5 2 3\n1 1 3 5\n5 1 5 1\n4 5 3 2\n3 2 1 4\n1 4 5 3\n2 3 4 2\n1 2 1 2\n5 4 5 4\n2 1 2 1\n3 5 3 4\n3 3 5 4\n4 2 3 1\n2 5 3 1\n3 5 4 2\n1 5 4 1\n4 5 3 2", "output": "0\n4\n12\n0", "type": "s...
code_contests
verifiable_code
p00833 Color the Map
Solve the following coding problem using the programming language python: You were lucky enough to get a map just before entering the legendary magical mystery world. The map shows the whole area of your planned exploration, including several countries with complicated borders. The map is clearly drawn, but in sepia i...
```python def main(): while 1: N = int(input()) if N == 0: break D = {} G = [set() for i in range(N)] cur = 0 K = [] PS = [] for i in range(N): ps = [] s = input() if s in D: k = D[s] ...
vfc_63713
{ "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\nBlizid\n0 0\n60 0\n60 60\n0 60\n0 50\n50 50\n50 10\n0 10\n-1\nBlizid\n0 10\n10 10\n10 50\n0 50\n-1\nWindom\n10 10\n50 10\n40 20\n20 20\n20 40\n10 50\n-1\nAccent\n50 10\n50 50\n35 50\n35 25\n-1\nPilot\n35 25\n35 50\n10 50\n-1\nBl...
code_contests
verifiable_code
p00965 Starting a Scenic Railroad Service
Solve the following coding problem using the programming language python: Problem I Starting a Scenic Railroad Service Jim, working for a railroad company, is responsible for planning a new tourist train service. He is sure that the train route along a scenic valley will arise a big boom, but not quite sure how big t...
```python n = int(input()) ab = [list(map(int, input().split())) for _ in range(n)] pol1 = 0 pol2 = 0 ft = [[0] * 2 for _ in range(100000)] for i in ab: ft[i[0] - 1][0] += 1 ft[i[1] - 1][1] += 1 ftsum = [[0] * 2 for _ in range(100000)] ftsum[0][0] = ft[0][0] for i in range(1, len(ft)): ftsum[i][0] = ft...
vfc_63717
{ "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": "4\n1 3\n1 3\n3 6\n3 6", "output": "2 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 3\n1 3\n3 6\n3 9", "output": "2 2\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
p01097 3D Printing
Solve the following coding problem using the programming language python: 3D Printing We are designing an installation art piece consisting of a number of cubes with 3D printing technology for submitting one to Installation art Contest with Printed Cubes (ICPC). At this time, we are trying to model a piece consisting...
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools input = sys.stdin.readline INF = 10**20 EPS = 1.0 / 10**10 MOD = 10**9 + 7 def LI(): return [int(x) for x in input().split()] def LF(): return [float(x) for x in input().split()] def LS(): return input().sp...
vfc_63721
{ "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": "1 1 100\n100 100 100\n6 4 10\n100 100 100\n106 102 102\n112 110 104\n104 116 102\n100 114 104\n92 107 100\n10 4 10\n-100 101 100\n-108 102 120\n-116 103 100\n-124 100 100\n-132 99 100\n-92 98 100\n-84 100 140\n-76 103 100\n-68 102 ...
code_contests
verifiable_code
p01233 Radio Base
Solve the following coding problem using the programming language python: In 20XX, many years of research have paid off, and wireless energy transmission and reception technology has been put into practical use. By using this technology, it has become possible to supply power to depopulated areas where it was not poss...
vfc_63725
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 1 3 2 0 1\n1 1 2 2 9 9\n0 0 1 4 5 5\n0 0 1 4 5 10", "output": "0\n1\n2\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 1 3 2 0 1\n1 1 2 2 9 9\n0 0 1 4 5 5\n1 0 1 4 5 10", ...
code_contests
verifiable_code
p01367 Operator
Solve the following coding problem using the programming language python: The customer telephone support center of the computer sales company called JAG is now in- credibly confused. There are too many customers who request the support, and they call the support center all the time. So, the company wants to figure out...
```python import sys readline = sys.stdin.readline write = sys.stdout.write def check(N, C, T, x): used = [0]*N S = [0]*(T+1) cap = x f = 0 for t in range(T): cap += S[t] if cap == 0: continue for i in range(f, N): if used[i]: continue ...
vfc_63729
{ "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": "3 300\n100 50 150\n100 50 150\n100 50 150\n3 300\n100 50 150\n100 50 150\n200 50 150\n9 18\n3 1 1\n3 1 1\n3 1 1\n4 100 1\n5 100 1\n5 100 1\n10 5 3\n10 5 3\n1 7 1000\n10 18\n1 2 3\n2 3 4\n3 4 5\n4 5 6\n5 6 7\n6 7 8\n7 8 9\n8 9 10\n9...
code_contests
verifiable_code
p01549 Zero Division Checker
Solve the following coding problem using the programming language python: Mr. Morishita was in trouble ... I had Mr. Anehara write a program, but the program crashed. Mr. Anehara wrote a program that reads the formula in Reverse Polish Notation and outputs the calculation result. According to the crash log, it seems ...
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in ...
vfc_63733
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 262144000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\na 0 255\n7\n1 a 2 * 1 + /", "output": "correct", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01705 Square in Circles
Solve the following coding problem using the programming language python: Problem Statement Circles Island is known for its mysterious shape: it is a completely flat island with its shape being a union of circles whose centers are on the $x$-axis and their inside regions. The King of Circles Island plans to build a ...
```python import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) if N == 0: return False C = [list(map(int, readline().split())) for i in range(N)] e = 2**.5/2 r_min = max(r*e for x, r in C) r_max = max(r for x, r in C) H = [] for i in ...
vfc_63737
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n0 8\n10 8\n2\n0 7\n10 7\n0", "output": "12.489995996796796\n9.899494936611665", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 8\n10 8\n0\n0 7\n10 7\n0", "output": "12.489996\n"...
code_contests
verifiable_code
p01849 The Most Powerful Bed
Solve the following coding problem using the programming language python: My futon You bought N futons in preparation for your new life. The i-th futon has the warmth supply capacity of si. From the temperature forecast for the next M days, the warmth demand of dj is expected on the jth day. If the warmth is not enou...
```python from collections import deque while 1: n, m = map(int, input().split()) if n == m == 0: break *S, = map(int, input().split()) D = sorted(map(int, input().split())) SA = sum(S) rest = sum(d-SA for d in D if SA <= d) memo = {2**n-1: rest} def dfs(state, su, idx): ...
vfc_63741
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1\n5\n6\n1 1\n5\n2\n1 1\n20\n5\n4 1\n2 4 5 9\n8\n4 3\n3 5 2 1\n10 4 7\n5 5\n2 2 2 2 2\n1 3 5 7 9\n2 5\n2 5\n2 5 2 5 2\n0 0", "output": "1\n2\n5\n1\n1\n5\n4", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p02419 Finding a Word
Solve the following coding problem using the programming language python: Write a program which reads a word W and a text T, and prints the number of word W which appears in text T T consists of string Ti separated by space characters and newlines. Count the number of Ti which equals to W. The word and text are case ...
```python A=0 W=str(input()) while True: t=str(input()) if t=='END_OF_TEXT': break t=(t.lower().split()) a=(t.count(W)) A=A+a print(A) ```
vfc_63757
{ "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": "computer\nNurtures computer scientists and highly-skilled computer engineers\nwho will create and exploit \"knowledge\" for the new era.\nProvides an outstanding computer environment.\nEND_OF_TEXT", "output": "3", "type...
code_contests
verifiable_code
cd1it3
Solve the following coding problem using the programming language python: In DDU's annual techno-cultural fest – Felicific, the Computer Engineering department is introducing a weird contest this time. In the contest, there are N registered participants, with heights h[1..N]. A coordinator speaks out a number K to all...
```python from sets import Set; def binsearch(arr,low,high,data) : mid=(low+high)/2; if low > high : return -1; if arr[mid] == data : return mid; elif arr[mid] < data : return binsearch(arr,mid+1,high,data); else : ...
vfc_63761
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 6\n2 9 5 2 2 1", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6\n3 9 5 2 2 1", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
cubesum
Solve the following coding problem using the programming language python: Suppose there is a X x Y x Z 3D matrix A of numbers having coordinates (i, j, k) where 0 ≤ i < X, 0 ≤ j < Y, 0 ≤ k < Z. Now another X x Y x Z matrix B is defined from A such that the (i, j, k) element of B is the sum of all the the numbers in A ...
```python def removeTop(i,j,k): return a[i-1][j][k] if i else 0 def removeBack(i,j,k): return (a[i][j-1][k] - removeTop(i,j-1,k)) if j else 0 def removeSide(i,j,k): return (a[i][j][k-1] - removeBack(i,j,k-1) - removeTop(i,j,k-1)) if k else 0 t = int(raw_input()) while t: (i,j,k) = map(int, raw_input().s...
vfc_63765
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 1 1\n1 \n8 \n22 \n1 2 3\n0 9 13 \n18 45 51", "output": "1 \n7 \n14 \n0 9 4 \n18 18 2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
hunaby
Solve the following coding problem using the programming language python: Zucky has a frog Abby. Abby is very hungry and Zucky decides to feed it by playing a little game. Abby is a special frog which can jump as far as it wants but has a special pattern: He starts at the point 0. In his first turn, he can make a jump...
```python t=input() for i in range(t): n=input() s=0 a=[] flag=0 a.append(1) while(s<n): for j in range(len(a)-1): s+=a[j] a.append(s) for i in range(len(a)-1): flag+=a[i] if n==flag: print True else: print False ```
vfc_63769
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1", "output": "True", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
moviewkn
Solve the following coding problem using the programming language python: Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he's not sure which movie he should watch. Ther...
```python for t in xrange(int(raw_input())): n = int(raw_input()) l = map(int, raw_input().split()) r = map(int, raw_input().split()) ans = 0 m = 0 for i in range(n): temp = l[i]*r[i] if ((temp == m and r[i]>r[ans]) or temp>m): m = temp ans = i print ans+1 ```
vfc_63773
{ "difficulty": "1", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 4 1 4", "output": "1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 5 1 4", "output": "1\n2\n", "type": "stdin_s...
code_contests
verifiable_code
resq
Solve the following coding problem using the programming language python: Our Chef is catering for a big corporate office party and is busy preparing different mouth watering dishes. The host has insisted that he serves his delicious cupcakes for dessert. On the day of the party, the Chef was over-seeing all the foo...
```python import sys import math t=int(input()) while t>0: t=t-1 num=int(input()) mini=100000007 for i in range(1,int(math.sqrt(num))+1): if num%i==0: dif=abs(i-num/i) if mini>dif : mini=dif dif=0 print(mini) ```
vfc_63777
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n20\n13\n8\n4", "output": "1\n12\n2\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n38\n13\n8\n4", "output": "17\n12\n2\n0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
twostr
Solve the following coding problem using the programming language python: Chef wants to implement wildcard pattern matching supporting only the wildcard '?'. The wildcard character '?' can be substituted by any single lower case English letter for matching. He has two strings X and Y of equal length, made up of lower ...
```python t=int(raw_input()) while t>0: rj=86 r=raw_input() s=raw_input() for i in xrange(len(r)): if r[i]!=s[i]: if r[i]!='?' and s[i]!='?': rj=0 break if rj==0: print "No" else: print "Yes" t=t-1 ```
vfc_63781
{ "difficulty": "1", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\ns?or?\nsco??\nstor?\nsco??", "output": "Yes\nNo\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\ns?o?r\nsco??\nstor?\nsco??", "output": "Yes\nNo\n", "type": "stdin_stdout"...
code_contests
verifiable_code
1017_H. The Films
Solve the following coding problem using the programming language python: In "The Man in the High Castle" world, there are m different film endings. Abendsen owns a storage and a shelf. At first, he has n ordered films on the shelf. In the i-th month he will do: 1. Empty the storage. 2. Put k_i ⋅ m films into t...
vfc_63785
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4 4\n1 2 3 4 4 4\n1 4 0\n1 3 2\n1 4 2\n1 5 2\n", "output": "6\n26730\n12150\n4860\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 3\n1 2 3 4 5\n1 2 100000\n1 4 4\n3 5 5\n", "ou...
code_contests
verifiable_code
1041_E. Tree Reconstruction
Solve the following coding problem using the programming language python: Monocarp has drawn a tree (an undirected connected acyclic graph) and then has given each vertex an index. All indices are distinct numbers from 1 to n. For every edge e of this tree, Monocarp has written two numbers: the maximum indices of the ...
```python # def solve(): n = int(input()) d = {} for _ in range(n-1): u, v = map(int, input().split()) min_ = min(u, v) max_ = max(u, v) if max_ != n: return False, None if min_ not in d: d[min_] = 0 d[min_] += ...
vfc_63789
{ "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\n1 2\n2 3\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n3 4\n1 4\n3 4\n", "output": "YES\n1 3\n3 2\n2 4\n", "type": "stdin_stdout" }, { "...
code_contests
verifiable_code
1064_D. Labyrinth
Solve the following coding problem using the programming language python: You are playing some computer game. One of its levels puts you in a maze consisting of n lines, each of which contains m cells. Each cell either is free or is occupied by an obstacle. The starting cell is in the row r and column c. In one step y...
```python #!/usr/bin/env python3 import sys from collections import deque from math import inf def rint(): return map(int, sys.stdin.readline().split()) #lines = stdin.readlines() def bfs(sr, sc): global ans q = deque() q.append((x, y, sr, sc)) visit[sr][sc] = 1 ans += 1 while q: l...
vfc_63793
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5\n3 2\n1 2\n.....\n.***.\n...**\n*....\n", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n2 2\n0 1\n....\n..*.\n....\n....\n", "output": "7", "type": "stdi...
code_contests
verifiable_code
1106_B. Lunar New Year and Food Ordering
Solve the following coding problem using the programming language python: Lunar New Year is approaching, and Bob is planning to go for a famous restaurant — "Alice's". The restaurant "Alice's" serves n kinds of food. The cost for the i-th kind is always c_i. Initially, the restaurant has enough ingredients for servin...
```python n, m = map(int, input().split()) dish = list(map(int, input().split())) cost = list(map(int, input().split())) scost = [] for i in range(n): scost.append([cost[i], dish[i], i]) scost = sorted(scost) # print(scost) cur = 0 for i in range(m): x, y = map(int, input().split()) x -= 1 # print(x, ...
vfc_63801
{ "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": "6 6\n6 6 6 6 6 6\n6 66 666 6666 66666 666666\n1 6\n2 13\n3 6\n4 11\n5 6\n6 6\n", "output": "36\n11058\n99996\n4333326\n0\n0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1133_C. Balanced Team
Solve the following coding problem using the programming language python: You are a coach at your local university. There are n students under your supervision, the programming skill of the i-th student is a_i. You have to create a team for a new programming competition. As you know, the more students some team has t...
```python n=int(input().strip()) numbers=list(map(int,input().strip().split(" "))) numbers.sort() start=0 current=0 l=[] tot=0 while (current<len(numbers) and start<len(numbers)): if(numbers[current]-numbers[start]>5): start=start+1 l.append(tot) tot-=1 else: tot+=1 curre...
vfc_63805
{ "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\n1 10 17 12 15 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1337 1337 1337 1337 1337 1337 1337 1337 1337 1337\n", "output": "10\n", "type": "stdin_s...
code_contests
verifiable_code
1153_F. Serval and Bonus Problem
Solve the following coding problem using the programming language python: Getting closer and closer to a mathematician, Serval becomes a university student on math major in Japari University. On the Calculus class, his teacher taught him how to calculate the expected length of a random subsegment of a given segment. T...
vfc_63809
{ "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": "7 5 3\n", "output": "223383352", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2 1\n", "output": "760234711", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
1194_D. 1-2-K Game
Solve the following coding problem using the programming language python: Alice and Bob play a game. There is a paper strip which is divided into n + 1 cells numbered from left to right starting from 0. There is a chip placed in the n-th cell (the last one). Players take turns, Alice is first. Each player during his ...
```python from sys import stdin, stdout from collections import Counter def rsingle_int(): return int(stdin.readline().rstrip()) def rmult_int(): return [ int(x) for x in stdin.readline().rstrip().split() ] def rmult_str(): return stdin.readline().rstrip().split() def r_str(): return stdin.readli...
vfc_63817
{ "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": "4\n0 3\n3 3\n3 4\n4 4\n", "output": "Bob\nAlice\nBob\nAlice\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n25 6\n", "output": "Alice\n", "type": "stdin_stdout" }, {...
code_contests
verifiable_code
1211_A. Three Problems
Solve the following coding problem using the programming language python: Polycarp is choosing three problems for creating a programming test. Totally he has n problems in his list. The complexity of the i-th problem equals r_i. All problems are numerated from 1 to n. Help Polycarp to choose such three problems a, b ...
vfc_63821
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3 1 4 1 5 9\n", "output": "\n4 1 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1000000000 1 1000000000 1\n", "output": "\n-1 -1 -1\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1252_J. Tiling Terrace
Solve the following coding problem using the programming language python: Talia has just bought an abandoned house in the outskirt of Jakarta. The house has a nice and long yard which can be represented as a one-dimensional grid containing 1 × N cells. To beautify the house, Talia is going to build a terrace on the ya...
vfc_63829
{ "difficulty": "16", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4 10 25 40\n..#...\n", "output": "\n75\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4 10 100 40\n..#...\n", "output": "\n210\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1296_D. Fight with Monsters
Solve the following coding problem using the programming language python: There are n monsters standing in a row numbered from 1 to n. The i-th monster has h_i health points (hp). You have your attack power equal to a hp and your opponent has his attack power equal to b hp. You and your opponent are fighting these mo...
```python n,a,b,k= map(int,input().split()) l=[int(x) for x in input().split()] power=[] for x in l: rem=x%(a+b) if rem==0: if b%a!=0: power.append((b//a)+1) else: power.append((b//a)) else: if rem<=a: power.append(0) else: if (rem-a)%a==0: power.append(((rem-a)//a)) else: power....
vfc_63837
{ "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": "7 4 2 1\n1 3 5 4 2 7 6\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2 3 3\n7 10 50 12 1 8\n", "output": "5\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
131_D. Subway
Solve the following coding problem using the programming language python: A subway scheme, classic for all Berland cities is represented by a set of n stations connected by n passages, each of which connects exactly two stations and does not pass through any others. Besides, in the classic scheme one can get from any ...
```python import sys from collections import deque sys.setrecursionlimit(30000) sz = 3333 cyclic = 0 begin = 0 end = 0 cycle = [] graph = [] used = [] parent = [] dist = [] def dfs(current,prev): global graph,begin,end,used,parent used[current] = 1 for nxt in graph[current]: if used[nxt] != 2 and n...
vfc_63841
{ "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": "6\n1 2\n3 4\n6 4\n2 3\n1 3\n3 5\n", "output": "0 0 0 1 1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 3\n4 3\n4 2\n1 2\n", "output": "0 0 0 0 ", "type": "stdin_stdout"...
code_contests
verifiable_code
1339_A. Filling Diamonds
Solve the following coding problem using the programming language python: You have integer n. Calculate how many ways are there to fully cover belt-like area of 4n-2 triangles with diamond shapes. Diamond shape consists of two triangles. You can move, rotate or flip the shape, but you cannot scale it. 2 coverings ...
```python n = int(input()) for _ in range(n): a = input() print(a) ```
vfc_63845
{ "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\n2\n1\n", "output": "2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1000000000\n", "output": "1000000000\n", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
1360_E. Polygon
Solve the following coding problem using the programming language python: Polygon is not only the best platform for developing problems but also a square matrix with side n, initially filled with the character 0. On the polygon, military training was held. The soldiers placed a cannon above each cell in the first row...
```python def solve(): n = int(input()) polygon = [None for i in range(n)] for i in range(n): polygon[i] = list(map(int, input())) for i in range(n - 2, -1, -1): for j in range(i, -1, -1): if polygon[i][j] == 1: if polygon[i][j + 1] == 0 and polygon[i + 1][...
vfc_63849
{ "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\n4\n0010\n0011\n0000\n0000\n2\n10\n01\n2\n00\n00\n4\n0101\n1111\n0101\n0111\n4\n0100\n1110\n0101\n0111\n", "output": "YES\nNO\nYES\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
1380_F. Strange Addition
Solve the following coding problem using the programming language python: Let a and b be some non-negative integers. Let's define strange addition of a and b as following: 1. write down the numbers one under another and align them by their least significant digit; 2. add them up digit by digit and concatenate th...
```python from sys import stdin import sys class LazySegTree: def __init__(self,N,first): self.LV = (N-1).bit_length() self.NO = 2**self.LV self.First = first self.data = [first] * (2*self.NO) self.lazy = [None] * (2*self.NO) def calc(self,l,r): retur...
vfc_63853
{ "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": "2 3\n14\n2 4\n2 1\n1 0\n", "output": "15\n12\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n139\n2 1\n", "output": "120\n", "type": "stdin_stdout" }, { "...
code_contests
verifiable_code
1400_F. x-prime Substrings
Solve the following coding problem using the programming language python: You are given an integer value x and a string s consisting of digits from 1 to 9 inclusive. A substring of a string is a contiguous subsequence of that string. Let f(l, r) be the sum of digits of a substring s[l..r]. Let's call substring s[l_...
vfc_63857
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "116285317\n8\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13\n13\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1424_F. Coins
Solve the following coding problem using the programming language python: A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them...
```python import os import sys from io import BytesIO, IOBase def main(): pass # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode...
vfc_63861
{ "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": "4 2\n1 2\n2 2\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\n2 3\n4 1\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
1445_B. Elimination
Solve the following coding problem using the programming language python: There is a famous olympiad, which has more than a hundred participants. The Olympiad consists of two stages: the elimination stage, and the final stage. At least a hundred participants will advance to the final stage. The elimination stage in tu...
```python for k in range(int(input())): a, b, c, d = input().split() a, b, c, d = int(a), int(b), int(c), int(d) if a+b >= c+d: print(a+b) else: print(c + d) ```
vfc_63865
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2 2 1\n4 8 9 2\n", "output": "3\n12\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
146_B. Lucky Mask
Solve the following coding problem using the programming language python: Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a mask of a...
```python s=input() a,b=(s.split()[0]),(s.split()[1]) dif=len(a)-len(b) mask='' tmp=int(a) tmp+=1 t=str(tmp) while(1): for i in t: if(i in ['4','7']): mask+=i if(mask==b): break else: tmp+=1 t=str(tmp) mask='' print(tmp) ```
vfc_63869
{ "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": "1 7\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 47\n", "output": "147\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "39...
code_contests
verifiable_code
1519_A. Red and Blue Beans
Solve the following coding problem using the programming language python: You have r red and b blue beans. You'd like to distribute them among several (maybe, one) packets in such a way that each packet: * has at least one red bean (or the number of red beans r_i ≥ 1); * has at least one blue bean (or the numbe...
```python def solve(): r, b, d = map(int, input().split(' ')) packets = min(r, b) ma = max(r, b) if d == 0: if r == b: return "YES" return "NO" needed = -1 if ma % packets == 0: needed = ma // packets else: needed = ma // packets + 1 if (n...
vfc_63877
{ "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": "4\n1 1 0\n2 7 3\n6 1 4\n5 4 0\n", "output": "\nYES\nYES\nNO\nNO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1546_A. AquaMoon and Two Arrays
Solve the following coding problem using the programming language python: AquaMoon and Cirno are playing an interesting game with arrays. Cirno has prepared two arrays a and b, both consist of n non-negative integers. AquaMoon can perform the following operation an arbitrary number of times (possibly zero): * She c...
```python cases=int(input()) for idx in range(cases): n=int(input()) a=list(map(int, input().split())) b=list(map(int, input().split())) if sum(a)!=sum(b): print(-1) elif a==b: print(0) else: tuples=[] count=0 for i in range(n): if a[i]==b[i]: continue ...
vfc_63881
{ "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": "4\n4\n1 2 3 4\n3 1 2 4\n2\n1 3\n2 1\n1\n0\n0\n5\n4 3 2 1 0\n0 1 2 3 4\n", "output": "2\n2 1\n3 1\n-1\n0\n6\n1 4\n1 4\n1 5\n1 5\n2 5\n2 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n...
code_contests
verifiable_code
173_B. Chamber of Secrets
Solve the following coding problem using the programming language python: "The Chamber of Secrets has been opened again" — this news has spread all around Hogwarts and some of the students have been petrified due to seeing the basilisk. Dumbledore got fired and now Harry is trying to enter the Chamber of Secrets. Thes...
```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 i...
vfc_63885
{ "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 3\n.#.\n...\n.#.\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n##.\n...\n.#.\n.#.\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
193_C. Hamming Distance
Solve the following coding problem using the programming language python: Hamming distance between strings a and b of equal length (denoted by h(a, b)) is equal to the number of distinct integers i (1 ≤ i ≤ |a|), such that ai ≠ bi, where ai is the i-th symbol of string a, bi is the i-th symbol of string b. For example...
```python def get_input(): a, b, d = map(int, input().split()) c, e = map(int, input().split()) f = int(input()) return [a, b, c, d, e, f] def check_condition(a, b, c, d, e, f): condition1 = (a + b + c) % 2 == 0 condition2 = (d + e + a) % 2 == 0 condition3 = (e + f + c) % 2 == 0 ...
vfc_63889
{ "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 4 4\n4 4\n4\n", "output": "6\naaaaaa\naabbbb\nbbaabb\nbbbbaa\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 3\n1 2\n3\n", "output": "4\naaaa\naaab\naabb\nbbab\n", "type"...
code_contests
verifiable_code
217_C. Formurosa
Solve the following coding problem using the programming language python: The Bytelandian Institute for Biological Research (BIBR) is investigating the properties of two species of bacteria, named simply 0 and 1. Even under a microscope, bacteria of those two species are very difficult to distinguish. In fact, the onl...
```python n = int(raw_input()) f = raw_input() ls = [] os = [] tmp = [[[0 for k in range(16)] for j in range(16)] for i in range(3)] # 0 # 1 # a # na """ def maeshori(): for i in range(3): for j in range(16): for k in range(16): tmp[i][j][k] = 0 for j in range(16): ...
vfc_63893
{ "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": "2\n(?^?)\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n?\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
241_B. Friends
Solve the following coding problem using the programming language python: You have n friends and you want to take m pictures of them. Exactly two of your friends should appear in each picture and no two pictures should contain the same pair of your friends. So if you have n = 3 friends you can take 3 different picture...
vfc_63897
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1 2 3\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 2 3\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
266_A. Stones on the Table
Solve the following coding problem using the programming language python: There are n stones on the table in a row, each of them can be red, green or blue. Count the minimum number of stones to take from the table so that any two neighboring stones had different colors. Stones in a row are considered neighboring if th...
```python n=int(input()) word=input() count=0 for i in range(0,n-1): if word[i]==word[i+1]: count+=1 print(count) ```
vfc_63901
{ "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": "5\nRRRRR\n", "output": "4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
28_A. Bender Problem
Solve the following coding problem using the programming language python: Robot Bender decided to make Fray a birthday present. He drove n nails and numbered them from 1 to n in some order. Bender decided to make a picture using metal rods. The picture is a closed polyline, which vertices should be nails (in the given...
```python from collections import defaultdict def main(): n, m = map(int, input().split()) tmp = list(tuple(map(int, input().split())) for _ in range(n)) nails = [abs(a - c) + abs(b - d) for (a, b), (c, d) in zip(tmp, tmp[2:] + tmp[:2])] segments = defaultdict(list) for i, s in enumerate(map(int, ...
vfc_63905
{ "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 2\n0 0\n0 2\n2 2\n2 0\n4 4\n", "output": "YES\n1 -1 2 -1 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
337_C. Quiz
Solve the following coding problem using the programming language python: Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on...
```python import os import sys from io import BytesIO, IOBase import math def main(): pass # region fastio BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not ...
vfc_63913
{ "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": "5 3 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "874...
code_contests
verifiable_code
35_E. Parade
Solve the following coding problem using the programming language python: No Great Victory anniversary in Berland has ever passed without the war parade. This year is not an exception. That’s why the preparations are on in full strength. Tanks are building a line, artillery mounts are ready to fire, soldiers are march...
vfc_63917
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 -3 0\n2 -1 1\n4 2 4\n2 3 7\n3 6 8\n", "output": "14\n-3 0\n-3 3\n0 3\n0 2\n1 2\n1 0\n2 0\n2 4\n4 4\n4 2\n6 2\n6 3\n8 3\n8 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 0 2\n4...
code_contests
verifiable_code
431_C. k-Tree
Solve the following coding problem using the programming language python: Quite recently a creative student Lesha had a lecture on trees. After the lecture Lesha was inspired and came up with the tree of his own which he called a k-tree. A k-tree is an infinite rooted tree where: * each vertex has exactly k childr...
```python n,k,d = input().split() n,k,d = int(n),int(k),int(d) ans1 = [0 for _ in range(101)] ans1[0] = 1 ans = [0 for _ in range(101)] for i in range(d): ans[i] = 0 for i in range(0,n + 1): j = 1 while j <= k and i - j >= 0: ans1[i] += ans1[i - j] j += 1 for i in range(d,n + 1)...
vfc_63929
{ "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 5 2\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3...
code_contests
verifiable_code
453_E. Little Pony and Lord Tirek
Solve the following coding problem using the programming language python: Lord Tirek is a centaur and the main antagonist in the season four finale episodes in the series "My Little Pony: Friendship Is Magic". In "Twilight's Kingdom" (Part 1), Tirek escapes from Tartarus and drains magic from ponies to grow stronger. ...
vfc_63933
{ "difficulty": "11", "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\n0 10 1\n0 12 1\n0 20 1\n0 12 1\n0 10 1\n2\n5 1 5\n19 1 5\n", "output": "25\n58\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n0 50 0\n0 4 0\n0 7 3\n0 16 4\n0 54 8\n0 24 0\n0 38 1\n...
code_contests
verifiable_code
476_C. Dreamoon and Sums
Solve the following coding problem using the programming language python: Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if <image> and <image>, where k is some integer number...
```python a, b = (input()).split(' ') a = int(a) b=int(b) result = a*b*(b-1)*(a*b+b+2)//4 #result = int(result) result = result % ( 10**9 +7) print((result)) ```
vfc_63937
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
49_D. Game
Solve the following coding problem using the programming language python: Vasya and Petya have invented a new game. Vasya takes a stripe consisting of 1 × n square and paints the squares black and white. After that Petya can start moves — during a move he may choose any two neighboring squares of one color and repaint...
```python n=int(input()) def hamming(a,b): global n ret=0 for i in range(n): ret+=int(a[i]!=b[i]) return ret s=input() a=['0' if q%2==0 else '1' for q in range(n)] b=['0' if q%2==1 else '1' for q in range(n)] print(min(hamming(s,a),hamming(s,b))) ```
vfc_63941
{ "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": "5\n00100\n", "output": "2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
524_D. Social Network
Solve the following coding problem using the programming language python: Polycarpus got an internship in one well-known social network. His test task is to count the number of unique users who have visited a social network during the day. Polycarpus was provided with information on all user requests for this time per...
```python def main(): mode="filee" if mode=="file":f=open("test.txt","r") get = lambda :[int(x) for x in (f.readline() if mode=="file" else input()).split()] gets = lambda :[str(x) for x in (f.readline()[:-1] if mode=="file" else input()).split(":")] [n,m,t]=get() [a,b]=[[0]*20002,[0]*20002] ...
vfc_63945
{ "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": "4 2 10\n17:05:53\n17:05:58\n17:06:01\n22:39:47\n", "output": "3\n1\n2\n2\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 86400\n00:00:00\n", "output": "No solution\n", "...