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
1075_C. The Tower is Going Home
Solve the following coding problem using the programming language python: On a chessboard with a width of 10^9 and a height of 10^9, the rows are numbered from bottom to top from 1 to 10^9, and the columns are numbered from left to right from 1 to 10^9. Therefore, for each cell of the chessboard you can assign the coo...
```python import bisect n, m = map(int, input().split()) ar1 = [1] + [int(input()) for _ in range(n)] ar1.append(10 ** 9) ar1.sort() ar2 = [list(map(int, input().split())) for _ in range(m)] kek = list() for x in ar2: j1 = bisect.bisect_left(ar1, x[0]) j2 = bisect.bisect_right(ar1, x[1]) if x[0] == 1: ...
vfc_45069
{ "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 3\n4\n1 5 3\n1 9 4\n4 6 6\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1117_E. Decypher the String
Solve the following coding problem using the programming language python: This is an interactive problem. Remember to flush your output while communicating with the testing program. You may use fflush(stdout) in C++, system.out.flush() in Java, stdout.flush() in Python or flush(output) in Pascal to flush the output. I...
```python from itertools import chain, cycle, islice, repeat from operator import itemgetter d = 26 a = ord('a') t = input() n = len(t) p = [0]*n for b in (d ** 2, d, 1): if n >= b: q = (repeat(chr(a + i), b) for i in range(d)) q = chain.from_iterable(q) q = cycle(q) q = islice(q, ...
vfc_45077
{ "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": "yzx\naab\nbaa\naba", "output": "? abc\n? aaa\n? aaa\n! axa\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1144_A. Diverse Strings
Solve the following coding problem using the programming language python: A string is called diverse if it contains consecutive (adjacent) letters of the Latin alphabet and each letter occurs exactly once. For example, the following strings are diverse: "fced", "xyz", "r" and "dabcef". The following string are not div...
```python import string alphabet = string.ascii_lowercase n = int(input()) for i in range(n): s = list(input()) if len(s) > 26 or len(s) > len(set(s)): print("No") else: s.sort() ind = alphabet.index(s[0]) if alphabet[ind+len(s)-1] == s[-1]: print("Yes") else: print("No") ```
vfc_45081
{ "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": "8\nfced\nxyz\nr\ndabcef\naz\naa\nbad\nbabc\n", "output": "YES\nYES\nYES\nYES\nNO\nNO\nNO\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nshh\n", "output": "NO\n", "type"...
code_contests
verifiable_code
1163_F. Indecisive Taxi Fee
Solve the following coding problem using the programming language python: In the city of Capypaland where Kuro and Shiro resides, there are n towns numbered from 1 to n and there are m bidirectional roads numbered from 1 to m connecting them. The i-th road connects towns u_i and v_i. Since traveling between the towns ...
vfc_45085
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4 4\n1 2 2\n1 2 3\n1 2 4\n1 2 5\n2 1\n3 2\n4 3\n1 5\n", "output": "1\n2\n2\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 1\n1 2 1\n1 3\n", "output": "3\n", "type": "...
code_contests
verifiable_code
1184_B2. The Doctor Meets Vader (Medium)
Solve the following coding problem using the programming language python: Thanks to the Doctor's help, the rebels managed to steal enough gold to launch a full-scale attack on the Empire! However, Darth Vader is looking for revenge and wants to take back his gold. The rebels have hidden the gold in various bases thro...
```python def naiveSolve(): return def floyd_warshall(n, edges): dist = [[0 if i == j else float("inf") for i in range(n)] for j in range(n)] # dist = [[float("inf") for i in range(n)] for j in range(n)] # if nodes are not directly connected to themselves # pred = [[None] * n for _ in r...
vfc_45089
{ "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": "6 7\n1 2\n2 3\n3 4\n4 6\n6 5\n4 4\n3 6\n4 2 7 3\n1 10 2\n3 8 2\n5 1 0\n6 5 4\n3 7\n5 2\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1 1\n2 1 657705832 300429230\n...
code_contests
verifiable_code
1202_B. You Are Given a Decimal String...
Solve the following coding problem using the programming language python: Suppose you have a special x-y-counter. This counter can store some value as a decimal number; at first, the counter has value 0. The counter performs the following algorithm: it prints its lowest digit and, after that, adds either x or y to i...
```python from collections import* s=input() c=Counter((ord(y)-ord(x))%10for x,y in zip(s,s[1:])) for i in range(100): a = [-1] * 10 for j in range(1, 11): for k in range(j+1): x = ((j - k) * (i//10) + k * (i%10)) % 10 if a[x] == -1: a[x] = j-1 z = 0 for x in c: if a[x] == -1: z = -1 break els...
vfc_45093
{ "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": "0840\n", "output": "-1 17 7 7 7 -1 2 17 2 7 \n17 17 7 5 5 5 2 7 2 7 \n7 7 7 4 3 7 1 7 2 5 \n7 5 4 7 3 3 2 5 2 3 \n7 5 3 3 7 7 1 7 2 7 \n-1 5 7 3 7 -1 2 9 2 7 \n2 2 1 2 1 2 2 2 0 1 \n17 7 7 5 7 9 2 17 2 3 \n2 2 2 2 2 2 0 2 2 2...
code_contests
verifiable_code
1219_G. Harvester
Solve the following coding problem using the programming language python: It is Bubble Cup finals season and farmer Johnny Bubbles must harvest his bubbles. The bubbles are in a rectangular bubblefield formed of N x M square parcels divided into N rows and M columns. The parcel in i^{th} row and j^{th} column yields A...
vfc_45097
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n0 9 2 7 0\n9 0 3 0 5\n0 8 0 3 1\n6 7 4 3 9\n3 6 4 1 0\n", "output": "80", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n1 2\n3 4\n", "output": "10", "type": "stdin_stdo...
code_contests
verifiable_code
1244_B. Rooms and Staircases
Solve the following coding problem using the programming language python: Nikolay lives in a two-storied house. There are n rooms on each floor, arranged in a row and numbered from one from left to right. So each room can be represented by the number of the floor and the number of the room on this floor (room number i...
```python def solve(n, s): is_stairs = [s[x] == '1' for x in range(n)] if not any(is_stairs): return n if is_stairs[0] or is_stairs[-1]: return n * 2 else: min_idx = max_idx = None for i in range(n): if not is_stairs[i]: continue if not min_idx: min_idx = i max_idx = i return max(max_idx...
vfc_45101
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5\n00100\n8\n00000000\n5\n11111\n3\n110\n", "output": "6\n8\n10\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n100\n00000000000000000000000000000000000000000000000000000000000000...
code_contests
verifiable_code
1263_F. Economic Difficulties
Solve the following coding problem using the programming language python: An electrical grid in Berland palaces consists of 2 grids: main and reserve. Wires in palaces are made of expensive material, so selling some of them would be a good idea! Each grid (main and reserve) has a head node (its number is 1). Every ot...
```python from __future__ import print_function,division import sys#log min est tolérable n=int(input()) def f(): global n co=[[0]*n for k in range(n)] a=int(input()) p=[0]+list(map(int,raw_input().split())) d=[0]*a s=[1]*a s[0]=0 mi=[n]*a#plus peit ma=[-1]*a#le plus tard for k i...
vfc_45105
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n14\n1 1 11 2 14 14 13 7 12 2 5 6 1\n9 8 3 10 4\n16\n1 1 9 9 2 5 10 1 14 3 7 11 6 12 2\n8 16 13 4 15\n", "output": "17\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n6\n4 1 1 4 2\n6 ...
code_contests
verifiable_code
1304_D. Shortest and Longest LIS
Solve the following coding problem using the programming language python: Gildong recently learned how to find the [longest increasing subsequence](https://en.wikipedia.org/wiki/Longest_increasing_subsequence) (LIS) in O(nlog{n}) time for a sequence of length n. He wants to test himself if he can implement it correctl...
```python def main(): t=int(input()) allans=[] for _ in range(t): n,s=input().split() n=int(n) s=s+'$' seq=[] # [isIncreasing,length] prev=None l=0 for c in s: if c!=prev: if l>0: # not first ...
vfc_45113
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 <<\n7 >><>><\n5 >>><\n", "output": "3 2 1 \n1 2 3 \n7 6 5 4 3 2 1 \n1 2 3 4 5 6 7 \n5 4 3 2 1 \n1 2 3 4 5 \n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
1348_E. Phoenix and Berries
Solve the following coding problem using the programming language python: Phoenix is picking berries in his backyard. There are n shrubs, and each shrub has a_i red berries and b_i blue berries. Each basket can contain k berries. But, Phoenix has decided that each basket may only contain berries from the same shrub o...
```python n,k=map(int,input().split()) totA=0 totB=0 A=[0] B=[0] dp=[] for i in range(n+1): h=[] for j in range(k): h.append(False) dp.append(h) dp[0][0]=True for i in range(n): a,b=map(int,input().split()) A.append(a) B.append(b) totA+=a totB+=b for i in range(1,n+1): ...
vfc_45121
{ "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": "1 5\n2 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\n1000000000 1\n", "output": "500000000\n", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
1369_C. RationalLee
Solve the following coding problem using the programming language python: Lee just became Master in Codeforces, and so, he went out to buy some gifts for his friends. He bought n integers, now it's time to distribute them between his friends rationally... Lee has n integers a_1, a_2, …, a_n in his backpack and he has...
```python import sys input = lambda:sys.stdin.readline().strip() t = int(input()) while t: t-=1 n,k = map(int,input().split()) a = list(map(int,input().split())) w = list(map(int,input().split())) adj = [[] for _ in range(k)] a.sort() w.sort() i = 0 for i in range(k): adj[i]...
vfc_45125
{ "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\n4 2\n1 13 7 17\n1 3\n6 2\n10 10 10 10 11 11\n3 3\n4 4\n1000000000 1000000000 1000000000 1000000000\n1 1 1 1\n", "output": "48\n42\n8000000000\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1413_E. Solo mid Oracle
Solve the following coding problem using the programming language python: Meka-Naruto plays a computer game. His character has the following ability: given an enemy hero, deal a instant damage to him, and then heal that enemy b health points at the end of every second, for exactly c seconds, starting one second after ...
```python # region fastio # from https://codeforces.com/contest/1333/submission/75948789 import sys, io, os BUFSIZE = 8192 class FastIO(io.IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = io.BytesIO() self.writable = "x" in file.mode or "r" not ...
vfc_45133
{ "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": "7\n1 1 1 1\n2 2 2 2\n1 2 3 4\n4 3 2 1\n228 21 11 3\n239 21 11 3\n1000000 1 1000000 1\n", "output": "1\n2\n1\n5\n534\n-1\n500000500000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n568...
code_contests
verifiable_code
1431_H. Rogue-like Game
Solve the following coding problem using the programming language python: Marina plays a new rogue-like game. In this game, there are n different character species and m different classes. The game is played in runs; for each run, Marina has to select a species and a class for her character. If she selects the i-th sp...
vfc_45137
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4 2\n0 5 7\n0 2 6 10\n2 5 5 2\n5 3 4 4\n3 4 2 4\n", "output": "\n3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1455_E. Four Points
Solve the following coding problem using the programming language python: You are given four different integer points p_1, p_2, p_3 and p_4 on XY grid. In one step you can choose one of the points p_i and move it in one of four directions by one. In other words, if you have chosen point p_i = (x, y) you can move it t...
```python import sys,os,io input = sys.stdin.readline #input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline from random import * T = int(input()) ans = [0]*T for t in range(T): X,Y = [0]*4,[0]*4 A = [0]*4 for i in range(4): X[i],Y[i] = map(int, input().split()) # X[i], Y[i] = choices(range(1,11),k=...
vfc_45141
{ "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\n0 2\n4 2\n2 0\n2 4\n1 0\n2 0\n4 0\n6 0\n1 6\n2 2\n2 5\n4 1\n", "output": "\n8\n7\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0 0\n5 5\n0 5\n5 0\n", "output": "0\n", ...
code_contests
verifiable_code
147_A. Punctuation
Solve the following coding problem using the programming language python: You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters. Your task is to add spaces to the text b...
```python import re s = input()+"a" s = re.sub('\s+', ' ', s) r = '.,?!' for i in r: t = s.split(i) s = "" for j in t: s += j.strip() + i + " " s = s[:-2] print(s[:-1]) ```
vfc_45145
{ "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": "galileo was born in pisa\n", "output": "galileo was born in pisa\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "galileo galilei was an italian physicist ,mathematician,astronomer\n...
code_contests
verifiable_code
152_D. Frames
Solve the following coding problem using the programming language python: One day Vasya got hold of a sheet of checkered paper n × m squares in size. Our Vasya adores geometrical figures, so he painted two rectangles on the paper. The rectangles' sides are parallel to the coordinates' axes, also the length of each sid...
vfc_45153
{ "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 5\n#####\n#.#.#\n###.#\n#####\n", "output": "YES\n1 1 3 3\n1 1 4 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n...###\n...###\n#####.\n#...#.\n#####.\n", "output": "NO\n",...
code_contests
verifiable_code
161_A. Dress'em in Vests!
Solve the following coding problem using the programming language python: The Two-dimensional kingdom is going through hard times... This morning the Three-Dimensional kingdom declared war on the Two-dimensional one. This (possibly armed) conflict will determine the ultimate owner of the straight line. The Two-dimens...
```python n, m, x, y = map(int, input().split()) a_n = [i for i in map(int, input().split())] b_m = [i for i in map(int, input().split())] count = 0 result = [] i = 0 j = 0 while j < m and i < n: if b_m[j] > a_n[i] + y: i += 1 elif b_m[j] < a_n[i] - x: j += 1 else: count += 1 ...
vfc_45157
{ "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": "5 3 0 0\n1 2 3 3 4\n1 3 5\n", "output": "2\n1 1\n3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 2 2\n1 5 9\n3 5 7\n", "output": "3\n1 1\n2 2\n3 3\n", "type": "stdin_st...
code_contests
verifiable_code
180_C. Letter
Solve the following coding problem using the programming language python: Patrick has just finished writing a message to his sweetheart Stacey when he noticed that the message didn't look fancy. Patrick was nervous while writing the message, so some of the letters there were lowercase and some of them were uppercase. ...
```python import os import sys from io import BytesIO, IOBase def main(): import bisect import math # import itertools # import heapq # from queue import PriorityQueue, LifoQueue, SimpleQueue # import sys.stdout.flush() use for interactive problems alpha = 'abcdefghijklmnopqrstuvwxyz' ...
vfc_45161
{ "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": "OYPROSTIYAOPECHATALSYAPRIVETSTASYA\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "helloworld\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
203_D. Hit Ball
Solve the following coding problem using the programming language python: When Valera was playing football on a stadium, it suddenly began to rain. Valera hid in the corridor under the grandstand not to get wet. However, the desire to play was so great that he decided to train his hitting the ball right in this corrid...
```python from fractions import Fraction from math import inf a, b, m = map(int, input().split(' ')) x, y, z = map(int, input().split(' ')) cx, cy, cz = Fraction(a / 2), Fraction(m), Fraction(0) while cy > 0: if cx == 0: x = abs(x) elif cx == a: x = -abs(x) if cz == 0: z = abs(z)...
vfc_45165
{ "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 2 11\n3 -11 2\n", "output": "6.5000000000 2.0000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 2 11\n4 -3 3\n", "output": "4.1666666667 1.0000000000\n", "type": "st...
code_contests
verifiable_code
228_C. Fractal Detector
Solve the following coding problem using the programming language python: Little Vasya likes painting fractals very much. He does it like this. First the boy cuts out a 2 × 2-cell square out of squared paper. Then he paints some cells black. The boy calls the cut out square a fractal pattern. Then he takes a clean sq...
vfc_45169
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n..**\n..**\n....\n....\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 11\n......*.***\n*.*.*....**\n.***....*.*\n..***.*....\n.*.*.....**\n......*.*..\n", "o...
code_contests
verifiable_code
252_A. Little Xor
Solve the following coding problem using the programming language python: Little Petya likes arrays that consist of non-negative integers a lot. Recently his mom has presented him one such array consisting of n elements. Petya immediately decided to find there a segment of consecutive elements, such that the xor of al...
```python import itertools import functools def allSubArrays(xs): n = len(xs) indices = list(range(n+1)) for i,j in itertools.combinations(indices,2): yield xs[i:j] n=int(input()) my_list=list(map(int,input().split(" "))) list_=list(allSubArrays(my_list)) for i in range(len(list_)): list_[i]=fun...
vfc_45173
{ "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\n1 2 1 1 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 7\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
277_B. Set of Points
Solve the following coding problem using the programming language python: Convexity of a set of points on the plane is the size of the largest subset of points that form a convex polygon. Your task is to build a set of n points with the convexity of exactly m. Your set of points should not contain three points that li...
```python def f(x): return int(x * x + 1e7) def g(x): return -f(x) n, m = map(int, input().split()) if(m == 3): if(n == 3): print('0 0') print('1 0') print('0 1') elif(n == 4): print('0 0') print('1 1') print('10000 0') print('0 10000') ...
vfc_45177
{ "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\n", "output": "0 10000000\n1 10000001\n2 10000004\n3 10000009\n4 10000016\n5 10000025\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 4\n", "output": "0 10000000\n1 10000001\n2...
code_contests
verifiable_code
29_D. Ant on the Tree
Solve the following coding problem using the programming language python: Connected undirected graph without cycles is called a tree. Trees is a class of graphs which is interesting not only for people, but for ants too. An ant stands at the root of some tree. He sees that there are n vertexes in the tree, and they a...
```python n = int(input()) adj = [[] for i in range(n)] adj2 = [[] for i in range(n)] for i in range(n-1): u,v = map(int,input().split()) adj[u-1].append(v-1) adj[v-1].append(u-1) leaf = {} a = list(map(int,input().split())) for i in range(len(a)): leaf[a[i]-1] = i inf = 200000 def dfs1(v,frm,adj2): ...
vfc_45181
{ "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\n1 3\n2 4\n4 5\n4 6\n5 6 3\n", "output": "1 2 4 5 4 6 4 2 1 3 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2\n2 3\n3\n", "output": "1 2 3 2 1 ", "type": "stdin_...
code_contests
verifiable_code
347_E. Number Transformation II
Solve the following coding problem using the programming language python: You are given a sequence of positive integers x1, x2, ..., xn and two non-negative integers a and b. Your task is to transform a into b. To do that, you can perform the following moves: * subtract 1 from the current a; * subtract a mod xi ...
vfc_45189
{ "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\n3 4 5\n30 17\n", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 6 7\n1000 200\n", "output": "206", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
371_A. K-Periodic Array
Solve the following coding problem using the programming language python: This task will exclusively concentrate only on the arrays where all elements equal 1 and/or 2. Array a is k-period if its length is divisible by k and there is such array b of length k, that a is represented by array b written exactly <image> t...
```python n, k = map(int, input().split()) a = list(map(int, input().split())) print(sum(min(x.count(1), x.count(2)) for x in (a[i::k] for i in range(k)))) ```
vfc_45193
{ "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": "9 3\n2 1 1 1 2 1 1 1 2\n", "output": "3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
392_C. Yet Another Number Sequence
Solve the following coding problem using the programming language python: Everyone knows what the Fibonacci sequence is. This sequence can be defined by the recurrence relation: F1 = 1, F2 = 2, Fi = Fi - 1 + Fi - 2 (i > 2). We'll define a new number sequence Ai(k) by the formula: Ai(k) = Fi × ik (i ≥ 1). In this...
vfc_45197
{ "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": "7 4\n", "output": "73825", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
415_D. Mashmokh and ACM
Solve the following coding problem using the programming language python: Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university and participate in ACM instead of finding a new job. He wants to become a member of Bamokh's team. In order to join he was given some programmin...
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 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 sys.stdin.re...
vfc_45201
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4\n", ...
code_contests
verifiable_code
442_B. Andrey and Problem
Solve the following coding problem using the programming language python: Andrey needs one more problem to conduct a programming contest. He has n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this...
```python n=int(input()) from itertools import combinations a = sorted(list(map(float, input().split())), reverse=True) #a=[0.01]*100 if max(a) == 1: print(1) quit() n=len(a) pre = [1]*100 pre[0] = 1 - a[0] for i in range(1, n): pre[i] = pre[i-1] * (1-a[i]) ans = 0 for i in range(1,n+1): anss=0 fo...
vfc_45205
{ "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": "2\n0.1 0.2\n", "output": "0.2600000000\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
464_C. Substitutes in Number
Solve the following coding problem using the programming language python: Andrew and Eugene are playing a game. Initially, Andrew has string s, consisting of digits. Eugene sends Andrew multiple queries of type "di → ti", that means "replace all digits di in string s with substrings equal to ti". For example, if s = 1...
```python mod=pow(10,9)+7 def sub_and_eval(n): if n=='': return 0 ans=v[int(n[0])] for i in range(1,len(n)): ans=(d[int(n[i])]*ans+v[int(n[i])])%mod return ans def prod_d(n): ans=1 for e in n: ans=ans*d[int(e)]%mod return ans s=input() v={i:i for i in range(10)} d={i:...
vfc_45209
{ "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": "123123\n1\n3-&gt;\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "222\n2\n2-&gt;0\n0-&gt;7\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
488_B. Candy Boxes
Solve the following coding problem using the programming language python: There is an old tradition of keeping 4 boxes of candies in the house in Cyberland. The numbers of candies are special if their arithmetic mean, their median and their range are all equal. By definition, for a set {x1, x2, x3, x4} (x1 ≤ x2 ≤ x3 ≤...
```python n=int(input()) if n==0: print('YES') print(1) print(1) print(3) print(3) else: lis=[] for i in range(n): lis.append(int(input())) lis.sort() if n==1: print('YES') print(lis[0]) print(3*lis[0]) print(3*lis[0]) if n==2: if...
vfc_45213
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n2\n2\n3\n", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1\n1\n1\n", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
512_A. Fox And Names
Solve the following coding problem using the programming language python: Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order. After checking some examples, she found out that ...
```python import sys import heapq n = int(sys.stdin.readline().strip()) w = [] g = {i:set({}) for i in "azertyuiopqsdfghjklmwxcvbn"} for i in range(n): w.append(sys.stdin.readline().strip()) for i in range(n-1): idx = 0 while idx < min(len(w[i]), len(w[i+1])) - 1 and w[i][idx] == w[i+1][idx]: idx += 1 if w[i][id...
vfc_45217
{ "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": "10\npetr\negor\nendagorion\nfeferivan\nilovetanyaromanova\nkostka\ndmitriyh\nmaratsnowbear\nbredorjaguarturnik\ncgyforever\n", "output": "zyxwvutsrqpoljhgnefikdmbca\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
536_B. Tavas and Malekas
Solve the following coding problem using the programming language python: Tavas is a strange creature. Usually "zzz" comes out of people's mouth while sleeping, but string s of length n comes out from Tavas' mouth instead. <image> Today Tavas fell asleep in Malekas' place. While he was sleeping, Malekas did a little...
```python import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write = self.buffer.write if se...
vfc_45221
{ "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 2\nioi\n1 3\n", "output": "26\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\nioi\n1 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
560_C. Gerald's Hexagon
Solve the following coding problem using the programming language python: Gerald got a very curious hexagon for his birthday. The boy found out that all the angles of the hexagon are equal to <image>. Then he measured the length of its sides, and found that each of them is equal to an integer number of centimeters. Th...
```python a,b,c,d,e,f=map(int,input().split()) print((a+b+c)**2-a**2-c**2-e**2) ```
vfc_45225
{ "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 2 1 2 1 2\n", "output": "13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1 1 1 1\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
586_E. Alice, Bob, Oranges and Apples
Solve the following coding problem using the programming language python: Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decid...
```python def gcd(x, y): while y > 0: x, y = y, x % y return x x, y = map(int, input().split()) if gcd(x, y) != 1: print ("Impossible") exit(0) res = "" while x > 0 and y > 0: if y > x: if x == 1: y -= 1 res = res + str(y // x) + "B" y = y % x else: ...
vfc_45229
{ "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 2\n", "output": "1A1B", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n", "output": "Impossible", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
609_A. USB Flash Drives
Solve the following coding problem using the programming language python: Sean is trying to save a large file to a USB flash drive. He has n USB flash drives with capacities equal to a1, a2, ..., an megabytes. The file size is equal to m megabytes. Find the minimum number of USB flash drives needed to write Sean's f...
```python n = int(input()) m = int(input()) a = [] for i in range(n): a.append(int(input())) a.sort(reverse=True) for i in range(n): m -= a[i] if m <= 0: print(i+1) exit() ```
vfc_45233
{ "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": "3\n5\n2\n1\n3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n6\n2\n3\n2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
62_E. World Evil
Solve the following coding problem using the programming language python: As a result of Pinky and Brain's mysterious experiments in the Large Hadron Collider some portals or black holes opened to the parallel dimension. And the World Evil has crept to the veil between their world and ours. Brain quickly evaluated the...
vfc_45237
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n4 4 4\n1 1 5\n5 5 3\n4 1 2\n1 3 1\n3 5 4\n1 4 3\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n9 2\n2 3\n6 1\n", "output": "11\n", "type": "stdin_st...
code_contests
verifiable_code
656_D. Rosetta Problem
Solve the following coding problem using the programming language python: ++++++++[>+>++>+++>++++>+++++>++++++>+++++++>++++++++>+++++++++>++++++++++>+ ++++++++++>++++++++++++>+++++++++++++>++++++++++++++>+++++++++++++++>+++++++ +++++++++<<<<<<<<<<<<<<<<-]>>>>>>>>>>.<<<<<<<<<<>>>>>>>>>>>>>>++.--<<<<<...
```python n=eval(input()) cnt=0 while n: a=n%8 n=n//8 if a==1: cnt+=1 print(cnt) ```
vfc_45241
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "129\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "398929\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2398...
code_contests
verifiable_code
67_D. Optical Experiment
Solve the following coding problem using the programming language python: Professor Phunsuk Wangdu has performed some experiments on rays. The setup for n rays is as follows. There is a rectangular box having exactly n holes on the opposite faces. All rays enter from the holes of the first side and exit from the hole...
```python from bisect import bisect_left as bl I=10000000 n=int(input())+1 c=[0]*n for i,x in enumerate(map(int,input().split())): c[x]=i d = [n-c[int(x)] for x in input().split()] c=[I]*n for i in d: c[bl(c,i)]=i print( c.index(I)) ```
vfc_45245
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 1 2\n2 3 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 4 5 2 3\n3 4 2 1 5\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
702_D. Road to Post Office
Solve the following coding problem using the programming language python: Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers. Vasiliy's car is not new — it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After...
```python import math d, k, a, b, t = map(int, input().split()) distance = a * t /((b -a )*b) + t /b time = 0 n = math.ceil((d-distance)/k) # print(distance) # print(n) if (k>d): print(d*a) exit(0) if (k<distance): time = k*a + (d-k)*b print(time) exit(0) if (n*k >=d): time = a*d + d//k*t ...
vfc_45249
{ "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": "5 2 1 4 10\n", "output": "14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2 1 4 5\n", "output": "13\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
724_E. Goods transportation
Solve the following coding problem using the programming language python: There are n cities located along the one-way road. Cities are numbered from 1 to n in the direction of the road. The i-th city had produced pi units of goods. No more than si units of goods can be sold in the i-th city. For each pair of cities...
vfc_45253
{ "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 0\n1 2 3\n3 2 1\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n7 4 2 1 0\n1 2 3 4 5\n", "output": "12\n", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
746_E. Numbers Exchange
Solve the following coding problem using the programming language python: Eugeny has n cards, each of them has exactly one integer written on it. Eugeny wants to exchange some cards with Nikolay so that the number of even integers on his cards would equal the number of odd integers, and that all these numbers would be...
```python n, m = map(int, input().split()) a = list(map(int, input().split())) counter = 0 s = set(a) nech = set() chet = set() for elem in a: if elem % 2: nech.add(elem) else: chet.add(elem) while len(nech) > n // 2: nech.pop() while len(chet) > n // 2: chet.pop() l_n = set([i for...
vfc_45257
{ "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 1\n4 2 1 10\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 6\n7 7 7 7 8 8 8 8\n", "output": "6\n7 1 3 5 8 2 4 6 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
76_A. Gift
Solve the following coding problem using the programming language python: The kingdom of Olympia consists of N cities and M bidirectional roads. Each road connects exactly two cities and two cities can be connected with more than one road. Also it possible that some roads connect city with itself making a loop. All r...
vfc_45261
{ "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": "3 3\n2 1\n1 2 10 15\n1 2 4 20\n1 3 5 1\n", "output": "30", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 1\n1 2 10 15\n1 2 4 20\n1 3 5 1\n", "output": "25\n", "type": "std...
code_contests
verifiable_code
793_E. Problem of offices
Solve the following coding problem using the programming language python: Earlier, when there was no Internet, each bank had a lot of offices all around Bankopolis, and it caused a lot of problems. Namely, each day the bank had to collect cash from all the offices. Once Oleg the bank client heard a dialogue of two ca...
```python n=int(input()) num=input().split(' ') l=[0]*4 for i in range(4): l[i]=int(num[i]) t=tuple(l) a,b,c,d=t p=[0]*(n+1) num=input().split(' ') mp=[list() for _ in range(n+1)] for i in range(2,n+1): p[i]=int(num[i-2]) mp[p[i]].append(i) s=[0]*(n+1) def sof(i): if s[i]!=0: return s[i] ...
vfc_45265
{ "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": "10\n3 8 9 10\n1 2 2 2 2 2 1 1 1\n", "output": "No\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 3 4 5\n1 1 1 1\n", "output": "Yes\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
814_B. An express train to reveries
Solve the following coding problem using the programming language python: Sengoku still remembers the mysterious "colourful meteoroids" she discovered with Lala-chan when they were little. In particular, one of the nights impressed her deeply, giving her the illusion that all her fancies would be realized. On that ni...
```python n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) # generate all 4 possibilities dupa = [] dupb = [] for i in range(len(a)): try: index = a[i+1:].index(a[i]) dupa.append(i) dupa.append(index+i+1) break except ValueError: ...
vfc_45269
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 3\n1 2 5 4 5\n", "output": "1 2 3 4 5 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1 3 4\n1 4 3 4\n", "output": "1 2 3 4\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
83_B. Doctor
Solve the following coding problem using the programming language python: There are n animals in the queue to Dr. Dolittle. When an animal comes into the office, the doctor examines him, gives prescriptions, appoints tests and may appoint extra examination. Doc knows all the forest animals perfectly well and therefore...
```python from sys import stdin, stdout n, k = map(int, stdin.readline().split()) values = list(map(int, stdin.readline().split())) if sum(values) < k: stdout.write('-1') elif sum(values) > k: l = 0 r = k + 1 while (r - l > 1): m = (r + l) // 2 cnt = 0 for i in range(n)...
vfc_45273
{ "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\n1 2 1\n", "output": "2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 10\n3 3 2 1\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
85_C. Petya and Tree
Solve the following coding problem using the programming language python: One night, having had a hard day at work, Petya saw a nightmare. There was a binary search tree in the dream. But it was not the actual tree that scared Petya. The horrifying thing was that Petya couldn't search for elements in this tree. Petya ...
```python import bisect import sys SW = [] List = [] L = [] R = [] ans = [] def dfs(u, cum, cnt): if L[u] != -1: pos = bisect.bisect_left(SW, (List[u][1], u)) dfs(L[u], cum + SW[pos - 1][0], cnt + 1) dfs(R[u], cum + SW[pos + 1][0], cnt + 1) else: ans[u] = cum * 1.0 /...
vfc_45277
{ "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": "7\n-1 8\n1 4\n1 12\n2 2\n2 6\n3 10\n3 14\n1\n1\n", "output": "8.0000000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n-1 5\n1 3\n1 7\n6\n1\n2\n4\n6\n8\n9\n", "output": "7....
code_contests
verifiable_code
886_C. Petya and Catacombs
Solve the following coding problem using the programming language python: A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs. Catacombs consist of several rooms and bidirectional passages between some pairs ...
```python c = int(input()) a = list(map(int, input().split())) res = 0 b = [] for i in range(len(a)): b.append(False) for i in range(len(a)): k = len(a) - i - 1 m = 0 while b[k] == False: b[k] = True k = a[k] - 1 m = 1 if (k == -1): break if m == 1: ...
vfc_45281
{ "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\n0 0\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
909_C. Python Indentation
Solve the following coding problem using the programming language python: In Python, code blocks don't have explicit begin/end or curly braces to mark beginning and end of the block. Instead, code blocks are defined by indentation. We will consider an extremely simplified subset of Python with only two types of state...
```python M=10**9+7 n=int(input()) a=[] for i in range(n): a.append(input()) dp=[[0]*(n+5) for i in range(n+2)] dp[0][0]=1 for i in range(1,n): count=0 if a[i-1]=='f': for j in range(n-2,-1,-1): if dp[i-1][j]>0: dp[i][j+1]=(dp[i][j+1]+dp[i-1][j])%M else: for j...
vfc_45285
{ "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\ns\nf\nf\ns\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nf\ns\nf\ns\n", "output": "2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
930_E. Coins Exhibition
Solve the following coding problem using the programming language python: Arkady and Kirill visited an exhibition of rare coins. The coins were located in a row and enumerated from left to right from 1 to k, each coin either was laid with its obverse (front) side up, or with its reverse (back) side up. Arkady and Kir...
vfc_45289
{ "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": "60 5 7\n1 3\n50 60\n1 60\n30 45\n20 40\n4 5\n6 37\n5 18\n50 55\n22 27\n25 31\n44 45\n", "output": "732658600", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2 2\n1 3\n3 5\n2 2\n4 5\n", ...
code_contests
verifiable_code
958_E1. Guard Duty (easy)
Solve the following coding problem using the programming language python: The Rebel fleet is afraid that the Empire might want to strike back again. Princess Heidi needs to know if it is possible to assign R Rebel spaceships to guard B bases so that every base has exactly one guardian and each spaceship has exactly on...
```python (R,B)=map(int,input().split()) for i in range(R+B): x=input() if R==B: print('Yes') else: print('No') ```
vfc_45293
{ "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": "2 1\n1 0\n2 2\n3 1\n", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n0 0\n2 0\n3 1\n-2 1\n0 3\n2 2\n", "output": "Yes", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
984_E. Elevator
Solve the following coding problem using the programming language python: You work in a big office. It is a 9 floor building with an elevator that can accommodate up to 4 people. It is your responsibility to manage this elevator. Today you are late, so there are queues on some floors already. For each person you know...
vfc_45297
{ "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": "2\n5 3\n3 5\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 5\n5 3\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
aaryan-subsequences-and-great-xor
Solve the following coding problem using the programming language python: Aaryan went to school like any usual day, The teacher asked his crush the following question. Given an array of numbers, First she had to compute the XOR of all the subsequences that can be formed. Suppose each subsequence had their following X...
```python from sys import stdin stdin.readline() a=map(int, stdin.readline().split()) b=a[0] for i in a[1:]: b|=i print b ```
vfc_45301
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n8 9 9 8\n\nSAMPLE", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n8 10 9 8\n\nSAMPLE", "output": "11\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
bob-and-lines
Solve the following coding problem using the programming language python: Problem Statement: Line segment intersection is one of the important part of mathematics. Bob will be given a set of n number of line segments, followed by set of q number of query lines. He is supposed to find how many line segments from se...
```python limit = 100005 for _ in range(input()): n, q = map(int, raw_input().split()) startx, starty, endx, endy, linex, liney=[0]*limit,[0]*limit,[0]*limit,[0]*limit,[0]*limit,[0]*limit for i in range(n): a, b, c, d = map(int, raw_input().split()) if a > c: a, c = c, a ...
vfc_45305
{ "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 83\n996 874 4 193\n611 166 630 317\n683 0\n0 415\n0 819\n0 771\n346 0\n100 0\n0 32\n0 281\n411 0\n0 837\n807 0\n0 795\n2 0\n0 751\n77 0\n0 37\n512 0\n0 377\n0 168\n0 903\n0 673\n428 0\n0 463\n631 0\n259 0\n642 0\n326 0\n0 706\...
code_contests
verifiable_code
cs-16-monmurder-1
Solve the following coding problem using the programming language python: Printf{}, Pappu Bhujia, mon_ki_onkh are playing Counter Strike 1.6 . Printf{} and Pappu Bhujia are in the same team (Counter Terrorists) and mon_ki_onkh is in the opposite team (Terrorists). It is a 2 on 1 round. The players playing have enough ...
```python def isprime(n): for i in range(2, int(pow(n,0.5)) + 1): if n % i == 0: return False return True p = dict() def factorization(n): if isprime(n): if n in p: p[n] += 1 else: p[n] = 1 else: for i in range(2, int(pow(n, 0.5)) + 1): if n % i == 0: factorization(i) factorization(n/i)...
vfc_45309
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2\n3\n4\n5\n6\n7\n\nSAMPLE", "output": "Printf{}\nPrintf{}\nPrintf{}\nPrintf{}\nPappu Bhujia\nPrintf{}\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "49\n663097\n388111\n671150\n554555...
code_contests
verifiable_code
free-free
Solve the following coding problem using the programming language python: In Pragyan, every shop has their own discount methods to attract the customers. One discount method called Buy 1 Get 1 caught your friend's attention. That is, if your friend buys one object, then your friend can get one additional object with t...
```python def main(): n = input() l = [] for i in range(n): str = raw_input() dict = {} for j in str: dict[j] = 0 for j in str: dict[j] += 1 sum = 0 for k in dict: if( dict.get(k) %2 == 1): ...
vfc_45313
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nasdasdqqqqqqQQQQQ\nasdQQQQqqqq\na\nas\nqas\nasdasdqqqqqqQQQQQasdasdqqqqqqQQQQQasdasdqqqqqqQQQQQasdasdqqqqqqQQQQQasdasdqqqqqqQQQQQasdasdqqqqqqQQQQQasdasdqqqqqqQQQQQasdasdqqqqqqQQQQQasdasdqqqqqqQQQQQ", "output": "9\n7\n1\n2\...
code_contests
verifiable_code
millys-rank-2
Solve the following coding problem using the programming language python: Milly is very much concern about her rank in her class. So to make her feel better , her friend Pranjul will give three numbers to her denoting N, X and Y. N represents the total number of students in the class. Now he has already described abou...
```python test_case = int(input()) str_out = '' while(test_case): rank_inp = [] rank_inp = raw_input().split() int_out = int(rank_inp[2]) + 1 if(int_out + int(rank_inp[1]) > int(rank_inp[0])): int_out = int(rank_inp[2]) str_out += str(int_out) test_case -= 1 str_out += "\n" print str...
vfc_45321
{ "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 1 2\n\nSAMPLE", "output": "3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
pairs-6
Solve the following coding problem using the programming language python: Motu and Chotu are Best-Friends. They both used to play CS-GO all the time. We know that there are two teams , they are CT and T .As Motu got bored of playing CS-GO whole day. He found a different game to play. Motu likes only if a CT guy sta...
```python for _ in xrange(input()): n = input() a, b = map(int, raw_input().split()) if max(a,b)>min(a,b)+1: print "Motu" else: print "Chotu" ```
vfc_45325
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n2 1\n4\n3 1\n\nSAMPLE", "output": "Chotu\nMotu", "type": "stdin_stdout" }, { "fn_name": null, "input": "30\n25\n23 2\n96\n96 0\n70\n17 53\n91\n47 44\n77\n62 15\n64\n7 57\n62\n15 47\n43\n19 24\n...
code_contests
verifiable_code
rev-dash
Solve the following coding problem using the programming language python: Sara and Tara were two young girls who had a really bad handwriting.So they decided to write down a word. Being highly passionate about improving their handwriting as well using there creative mind, they also wrote down the same word again but t...
```python import sys s=raw_input() rev=s[::-1] l=len(s) for i in range(0,l-1,1): sys.stdout.write(s[i]+"-") print s[i+1] for i in range(0,l-1,1): sys.stdout.write(rev[i]+"-") print rev[i+1] ```
vfc_45329
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Useful\n\nSAMPLE", "output": "U-s-e-f-u-l\nl-u-f-e-s-U\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "Architecture", "output": "A-r-c-h-i-t-e-c-t-u-r-e\ne-r-u-t-c-e-t-i-h-c-r-A\n", ...
code_contests
verifiable_code
trace-of-a-matrix-36
Solve the following coding problem using the programming language python: Given Two matrix A and B of some order ** RXC. Both matrix contains elements from 1 to *RC** . Matrix A contains elements in Row-major order while Matrix B contains elements in Column-major order .you are asked to answer a very simple question ...
```python t = int(raw_input()) counter =0 while counter< t: s= raw_input() L = s.split(' ') r = int(L[0]) c=int(L[1]) l = min(r,c) rc2 = c+r+2 print ((l*(l-1))/2)*(rc2) + l*2 counter+=1 ```
vfc_45337
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 3\n1 2\n\nSAMPLE", "output": "30\n2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00259 Finite Field Calculator
Solve the following coding problem using the programming language python: The reciprocal of all non-zero real numbers is real, but the reciprocal of an integer is not necessarily an integer. This is the reason why 3/2 * 2 = 2 even though 3.0 / 2.0 * 2.0 = 3.0 in C language. However, if you consider integers with the s...
```python import re p = 0 class N(int): def __add__(self,n): return N((int(self) + int(n)) % p) def __sub__(self,n): return N((int(self) - int(n)) % p) def __mul__(self,n): return N((int(self) * int(n)) % p) def __floordiv__(self,n): if not n: raise ZeroDivis...
vfc_45389
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5: 2 - 3\n17: 1 + 3 * (2 + 3 / 5 * 2) + 7\n11: 1 / 8 - 5 - 8 * 2\n19: 8 / (2 - 3 * 7)\n1153: 10 * 3 / 7 + ( 50 + 81 / 22 ) + 11\n0:", "output": "2-3 = 4 (mod 5)\n1+3*(2+3/5*2)+7 = 4 (mod 17)\n1/8-5-8*2 = 8 (mod 11)\nNG\n10*3/...
code_contests
verifiable_code
p00446 Card Game
Solve the following coding problem using the programming language python: problem There are the following two-player card games. * This game uses a total of 2n cards with each integer from 1 to 2n written on it. Here, n is an integer between 1 and 100. * Deal n cards to each of the two. * Put cards into play alterna...
```python # AOJ 0523: Card GameI # Python3 2018.6.30 bal4u while True: n = int(input()) if n == 0: break c = [1] * (2*n+1) for i in range(1, n+1): c[int(input())] = 0 m = [n]*2 t, ba = 0, 0 while m[0] > 0 and m[1] > 0: f = 1 for i in range(ba+1, 2*n+1): if t == c[i]: ba = i c[i] = 2 m[t] -= 1...
vfc_45393
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1\n7\n9\n6\n10\n10\n8\n7\n14\n18\n4\n11\n3\n17\n5\n19\n0", "output": "3\n0\n2\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1\n7\n9\n6\n10\n10\n8\n7\n14\n18\n2\n11\n3\n17\n5\n19\n...
code_contests
verifiable_code
p00637 Citation Format
Solve the following coding problem using the programming language python: To write a research paper, you should definitely follow the structured format. This format, in many cases, is strictly defined, and students who try to write their papers have a hard time with it. One of such formats is related to citations. If...
```python while True: n = int(input()) if n == 0: break pages = list(map(int, input().split())) ans = "" while pages: for i in range(len(pages) - 1): if pages[i + 1] - pages[i] != 1: s = pages[:i+1] if i == 0: ans += " " + str(s[0]) else: ans += " " + ...
vfc_45397
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 5 6\n3\n7 8 9\n0", "output": "1-3 5-6\n7-9", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 3 5 6\n3\n7 8 9\n0", "output": "1 1 3 5-6\n7-9\n", "type": "stdin_stdou...
code_contests
verifiable_code
p00780 Goldbach's Conjecture
Solve the following coding problem using the programming language python: Goldbach's Conjecture: For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 and p2 such that n = p1 + p2. This conjecture has not been proved nor refused yet. No one is sure whether this conjectur...
```python import sys import math def primes(n): sieve = [1] * (n + 1) rt = int(math.sqrt(n)) sieve[0] = sieve[1] = 0 for p in range(2, rt + 1): if sieve[p] == 0: continue k = p * 2 while k <= n: sieve[k] = 0 k += p r = [] for p in rang...
vfc_45401
{ "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\n10\n12\n0", "output": "1\n2\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1\n12\n0", "output": "1\n0\n1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p00913 Cubic Colonies
Solve the following coding problem using the programming language python: In AD 3456, the earth is too small for hundreds of billions of people to live in peace. Interstellar Colonization Project with Cubes (ICPC) is a project that tries to move people on the earth to space colonies to ameliorate the problem. ICPC obt...
vfc_45405
{ "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": "0 0 0 3 3 3\n###\n###\n###\n###\n###\n###\n###\n###\n###\n3 3 0 0 0 3\n#..\n###\n###\n###\n###\n###\n#.#\n###\n###\n0 0 2 2 2 2\n...\n...\n...\n.#.\n#..\n...\n##.\n##.\n...\n0 1 2 2 1 1\n...\n...\n...\n.#.\n#..\n...\n##.\n##.\n...\...
code_contests
verifiable_code
p01178 Ramen Shop
Solve the following coding problem using the programming language python: Ron is a master of a ramen shop. Recently, he has noticed some customers wait for a long time. This has been caused by lack of seats during lunch time. Customers loses their satisfaction if they waits for a long time, and even some of them will...
vfc_45413
{ "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": "1 4 100\n7\n10 1 50 50\n15 2 50 50\n25 1 50 50\n35 3 50 50\n1 2 100\n5\n30 3 20 50\n40 4 40 50\n1 2 100\n5\n49 3 20 50\n60 4 50 30\n1 2 100\n5\n50 3 20 50\n60 4 50 30\n2 3 100\n4 2\n10 4 20 20\n30 2 20 20\n40 4 20 20\n0 0 0", ...
code_contests
verifiable_code
p01315 Moonlight Farm
Solve the following coding problem using the programming language python: You are enthusiastic about the popular web game "Moonlight Ranch". The purpose of this game is to grow crops in the fields, sell them to earn income, and use that income to grow the ranch. You wanted to grow the field quickly. Therefore, we dec...
```python import sys sys.setrecursionlimit(10 ** 6) int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def main(): whil...
vfc_45417
{ "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": "5\napple 1 1 1 1 1 1 1 10 1\nbanana 1 2 2 2 2 2 1 10 1\ncarrot 1 2 2 2 2 2 1 10 2\ndurian 1 3 3 3 3 3 1 10 1\neggplant 1 3 3 3 3 3 1 100 1\n4\nenoki 1 3 3 3 3 3 1 10 1\ntomato 1 3 3 3 3 3 1 10 1\npotato 1 3 3 3 3 3 1 10 1\nonion 1 ...
code_contests
verifiable_code
p01644 Collector
Solve the following coding problem using the programming language python: * This story is fiction and has nothing to do with real people or groups. Social games have become very popular these days, and many companies are developing social games. You are infiltrating one of the competing social game developers as a s...
vfc_45425
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N (Sレアカードの種類)\nP_1 (カード1が好きな人の割合)\nP_2 (カード2が好きな人の割合)\n...\nP_N (カードNが好きな人の割合)", "output": "10000", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01796 JAG-channel II
Solve the following coding problem using the programming language python: Example Input 7 4 DEFG FEDA EFGB BGEA AGFD DABC CADE Output ABCDEFG The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
vfc_45429
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 4\nDEFG\nFEDA\nEFGB\nBGEA\nAGFD\nDABC\nCADE", "output": "ABCDEFG", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 4\nDEFG\nFEDA\nEFGB\nBGEA\nAGFD\nDABC\nCEDA", "output": "GABCDEF\n"...
code_contests
verifiable_code
p01930 Big Maze
Solve the following coding problem using the programming language python: Big Maze You work in the Jumbo Amusement Garden, a huge amusement park called "JAG" for short. The site of this amusement park is vast, and all the attractions are huge. This time, a new huge maze attraction "Big Maze" will be introduced to JA...
vfc_45433
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n#.#\n...\n#.#\n###\n...\n###\n3 2\n#.#\n...\n#.#\n###\n#.#\n###\n3 3\n#..\n..#\n###\n..#\n#.#\n#..\n#..\n..#\n###\n5 3\n.....\n#####\n##...\n##.##\n##...\n.....\n#####\n.....\n#####\n.....\n...##\n##.##\n...##\n#####\n.....\n3...
code_contests
verifiable_code
p02068 Non-trivial Common Divisor
Solve the following coding problem using the programming language python: Problem Statement You are given a positive integer sequence $A$ of length $N$. You can remove any numbers from the sequence to make the sequence “friendly". A sequence is called friendly if there exists an integer $k$ (>1) such that every numbe...
vfc_45437
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "", "output": "", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02364 Minimum Spanning Tree
Solve the following coding problem using the programming language python: Find the sum of weights of edges of the Minimum Spanning Tree for a given weighted undirected graph G = (V, E). Constraints * 1 ≤ |V| ≤ 10,000 * 0 ≤ |E| ≤ 100,000 * 0 ≤ wi ≤ 10,000 * The graph is connected * There are no parallel edges * There...
```python class Kruskal_UnionFind(): # 無向グラフであるという前提に注意 def __init__(self, N): self.edges = [] self.rank = [0] * N self.par = [i for i in range(N)] self.counter = [1] * N def add(self, u, v, d): """ :param u: 始点 :param v: 終点 :param d: コスト ...
vfc_45445
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 9\n0 1 1\n0 2 3\n1 2 1\n1 3 7\n2 4 1\n1 4 3\n3 4 1\n3 5 1\n4 5 6", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n0 1 2\n1 2 1\n2 3 1\n3 0 1\n0 2 3\n1 3 5", "outpu...
code_contests
verifiable_code
cb01
Solve the following coding problem using the programming language python: This is a very simple problem. Given the value of N and K, you need to tell us the value of the binomial coefficient C(N,K). You may rest assured that K ≤ N and the maximum value of N is 1,000,000,000,000,000. Since the value may be very large, ...
```python memo = {} def C(n, r, p): ''' {n choose r} modulo p (p is prime) ''' if r < 0 or r > n: return 0 if r == 0 or r == n: return 1 if n >= p: # Lucas theorem return C(n/p, r/p, p) * C(n%p, r%p, p) % p if (n, r, p) not in memo: memo[n, r, p] = (C(n-1, r-1, p) + C...
vfc_45449
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 1\n5 2\n10 3", "output": "3\n10\n120", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
crancrd
Solve the following coding problem using the programming language python: Little johny was working on the co-ordinate plane.As he is still a novice he calculates the distance between two points P1 and P2 in the wrong way.He calculates the distance between P1(x1,y1) and P2(x2,y2) as : D(P1,P2) = |x1 - x2| + |y1 - y2| H...
```python t=int(raw_input()) for asd in range(t): n=int(raw_input()) print 2*n*n ```
vfc_45453
{ "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": "2.", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n-1", ...
code_contests
verifiable_code
gshuff
Solve the following coding problem using the programming language python: Presti Digitator, the world-famous magician, is highly dissatisfied with his way of shuffling cards. Just yesterday, a perky guy in the audience demanded that he shuffle the cards once again, and he was aghast to see that the bottom card had not...
```python shuffle_list=[0,0,1] for i in xrange(3,21): shuffle_list.append((i-1)*(shuffle_list[-1]+shuffle_list[-2])) for i in xrange(input()): print shuffle_list[input()] ```
vfc_45457
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n4", "output": "1\n9", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
mdosa
Solve the following coding problem using the programming language python: Harish has decided to go to Arya's hotel this morning. We all know he is crazy for masala dosas. And as usual he is always hungry. He decided to order all the masala dosas at once. But then he realised that he did not have enough money to buy al...
```python # python3 if __name__ == "__main__": t = int(raw_input()) l = [] i = 0 while(i < t and t <= 10**6): ch = int(raw_input()) if(ch <= 10**18): l.append(ch) i = i + 1 for i in l: if(i % 2 == 0): print "YES" else: pr...
vfc_45461
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 \n16 \n27", "output": "YES\nNO", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
reciibks
Solve the following coding problem using the programming language python: Shrija's brother Vaibhav is a very mischievous boy . He has messed a lot of books of Shrija on floor . Now Shrija is very angry . Seeing her sister angry he promises to arrange them on N empty stacks numbered from 1 to N . Shrija also felt that ...
```python n,m=map(int,raw_input().split()) a=[0]*(n+2) #print a for i in range(m): left,right=map(int,raw_input().split()) a[left]+=1 a[right+1]-=1 for j in range(1,n+1): a[j]+=a[j-1] a=a[:n+1] a.sort() #print a print a[(n/2)+1] ```
vfc_45465
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n2 4\n1 3\n3 5", "output": "2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
tr004
Solve the following coding problem using the programming language python: Problem Statement Chef Diablo has set up a stall for selling his famous Modaks in the Trinity fest. He wants to earn as much profit as he can. So he has bought a chemical that increases the taste level of the Modaks. The tastier the Modaks the...
```python T=input() while T: T-=1 tl,n=[int(x) for x in raw_input().split()] if n==0: n=1 print pow(tl,n,pow(10,9)+7) ```
vfc_45469
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1\n2 2\n123123123123 2", "output": "1\n4\n293883007", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1062_C. Banh-mi
Solve the following coding problem using the programming language python: JATC loves Banh-mi (a Vietnamese food). His affection for Banh-mi is so much that he always has it for breakfast. This morning, as usual, he buys a Banh-mi and decides to enjoy it in a special way. First, he splits the Banh-mi into n parts, pla...
```python import sys MOD = 10 ** 9 + 7 r = sys.stdin.readlines() n, q = r[0].split(' ') n = int(n) q = int(q) s = r[1] c = [0] * (n + 1) for i in range(n): c[i + 1] = c[i] + (s[i] == '1') p2 = [1] * (2 * n + 1) for i in range(1, 2 * n + 1): p2[i] = p2[i - 1] * 2 % MOD out = [] for qq in range(q): a, b = r[q...
vfc_45481
{ "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": "3 2\n111\n1 2\n3 3\n", "output": "3\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n1011\n1 4\n3 4\n", "output": "14\n3\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
1084_B. Kvass and the Fair Nut
Solve the following coding problem using the programming language python: The Fair Nut likes kvass very much. On his birthday parents presented him n kegs of kvass. There are v_i liters of kvass in the i-th keg. Each keg has a lever. You can pour your glass by exactly 1 liter pulling this lever. The Fair Nut likes thi...
```python x,y=map(int,input().split()) s=list(map(int,input().split())) if sum(s)<y: print(-1) else: j=sum(s)-y if j<x: print(0) elif x==j: print(1) else: print(min(min(s),j//x)) ```
vfc_45485
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n5 3 4\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n4 3 5\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1103_D. Professional layer
Solve the following coding problem using the programming language python: Cardbluff is popular sport game in Telegram. Each Cardbluff player has ever dreamed about entrance in the professional layer. There are n judges now in the layer and you are trying to pass the entrance exam. You have a number k — your skill in C...
vfc_45489
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1000000\n1\n100\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n7 7 7\n1 1 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": ...
code_contests
verifiable_code
1131_D. Gourmet choice
Solve the following coding problem using the programming language python: Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review — in each resta...
```python r,c = map(int, input().split()) m = [] p = [i for i in range(0,r+c)] tree = [[] for i in range(0, r+c)] for i in range(0,r): s = input().split('\n')[0] m.append(list(s)) def find(i): if p[i] ==i: return i par = find(p[i]) p[i] = par return p[i] def join(i,j): p[find(i...
vfc_45493
{ "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 3\n&gt;&gt;&gt;\n&lt;&lt;&lt;\n&gt;&gt;&gt;\n", "output": "Yes\n1 1 1 \n1 1 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n==\n=&lt;\n==\n", "output": "Yes\n1 1 1 \n1 1 \n",...
code_contests
verifiable_code
1151_F. Sonya and Informatics
Solve the following coding problem using the programming language python: A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her. Given an array a of length n, consisting only of the numbers 0 and 1, and t...
```python N, T = map(int, input().split()) A = [int(a) for a in input().split()] if sum(A) > N//2: A = [1-a for a in A][::-1] K = sum(A) S = sum(A[-K:]) M = K + 1 P = 10**9+7 inv = pow(N*(N-1)//2, P-2, P) X = [[0]*M for _ in range(M)] for i in range(M): if i > 0: X[i-1][i] = ((K-i+1)**2*inv)%P if i < M-1: X...
vfc_45497
{ "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": "3 2\n0 1 0\n", "output": "333333336\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n1 1 1 0 0\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
1173_E1. Nauuo and Pictures (easy version)
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is constraints. Nauuo is a girl who loves random picture websites. One day she made a random picture website by herself which includes n pictures. When Nauuo visits the website, she sees exac...
```python import fileinput def D(a):print(a) def S(s,I):return int(s.split(" ")[I]) def inv(a):return pow(a,MOD-2,MOD) def main(): global MOD MOD=998244353 z=0 N=0 M=0 A=0 W=0 for l in fileinput.input(): z+=1 if(z<2): N=S(l,0) M=S(l,1) ...
vfc_45501
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n0 1 1\n4 3 5\n", "output": "160955686 185138929 974061117 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\n1\n1\n", "output": "3 \n", "type": "stdin_stdout" } ]...
code_contests
verifiable_code
1191_B. Tokitsukaze and Mahjong
Solve the following coding problem using the programming language python: Tokitsukaze is playing a game derivated from Japanese mahjong. In this game, she has three tiles in her hand. Each tile she owns is a suited tile, which means it has a suit (manzu, pinzu or souzu) and a number (a digit ranged from 1 to 9). In th...
```python string = input().split() first = string[0] second = string[1] third = string[2] string.sort(key=lambda x: int(x[0])) if first == second == third or first[1] == second[1] == third[1] and all(int(string[i][0]) == int(string[i - 1][0]) + 1 for i in range(1, 3)): print(0) elif (first == second or second == th...
vfc_45505
{ "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": "3p 9m 2p\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9m 9m 9m\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
120_B. Quiz League
Solve the following coding problem using the programming language python: A team quiz game called "What? Where? When?" is very popular in Berland. The game is centered on two teams competing. They are the team of six Experts versus the team of the Audience. A person from the audience asks a question and the experts ar...
vfc_45509
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n0 1 0 1 0\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n1 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
122_E. Lucky Permutation
Solve the following coding problem using the programming language python: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. One day Petya dreamt of a...
```python import math def good(x): while x > 0: if x % 10 != 4 and x % 10 != 7: return False x //=10 return True n, k = map(int, input().split()) l = 1 r = n if n >= 15: l = n-14 if n <= 15 and math.factorial(n) < k: print(-1) else: L = r - l + 1 a = [] for i i...
vfc_45513
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 7\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1251_D. Salary Changing
Solve the following coding problem using the programming language python: You are the head of a large enterprise. n people work at you, and n is odd (i. e. n is not divisible by 2). You have to distribute salaries to your employees. Initially, you have s dollars for it, and the i-th employee should get a salary from ...
```python import sys from bisect import bisect_left # inf = open('input.txt', 'r') # reader = (line.rstrip() for line in inf) reader = (line.rstrip() for line in sys.stdin) input = reader.__next__ t = int(input()) for _ in range(t): n, s = map(int, input().split()) mid = n >> 1 rl = [] for i in r...
vfc_45517
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 26\n10 12\n1 4\n10 11\n1 1337\n1 1000000000\n5 26\n4 4\n2 4\n6 8\n5 6\n2 7\n", "output": "11\n1337\n6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1271_B. Blocks
Solve the following coding problem using the programming language python: There are n blocks arranged in a row and numbered from left to right, starting from one. Each block is either black or white. You may perform the following operation zero or more times: choose two adjacent blocks and invert their colors (white...
```python n=int(input()) s=list(input()) s.append("B") b=s.count("B") w=len(s)-b if b==1 or w==0: print(0) exit(0) s.pop(n) b-=1 if b%2 and w%2: print("-1") exit(0) if b%2==0: p=[] for i in range(s.index('B'),n-1): if s[i]=="W": continue if s[i+1:].count('B')==0: ...
vfc_45521
{ "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": "8\nBWWWWWWB\n", "output": "3\n2 4 6 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nWWWWW\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1294_C. Product of Three Numbers
Solve the following coding problem using the programming language python: You are given one integer number n. Find three distinct integers a, b, c such that 2 ≤ a, b, c and a ⋅ b ⋅ c = n or say that it is impossible to do it. If there are several answers, you can print any. You have to answer t independent test case...
```python for _ in range(int(input())): n=int(input()) i=1 c=2 l=[] y=n while(i<=2): if n%c==0: n=n//c i=i+1 l.append(c) if c>=y**0.5: break c=c+1 if l==[] or len(l)==1: print("NO") elif y%(l[0]*l[1])==0: ...
vfc_45525
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n64\n32\n97\n2\n12345\n", "output": "YES\n2 4 8\nNO\nNO\nNO\nYES\n3 5 823\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1336_E2. Chiori and Doll Picking (hard version)
Solve the following coding problem using the programming language python: This is the hard version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> ...
vfc_45533
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 7\n11 45 14 9 19 81\n", "output": "1 2 11 20 15 10 5 0 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1359_C. Mixing Water
Solve the following coding problem using the programming language python: There are two infinite sources of water: * hot water of temperature h; * cold water of temperature c (c < h). You perform the following procedure of alternating moves: 1. take one cup of the hot water and pour it into an infinitely ...
```python # abs((desired*(2*n + 1) - ((n+1)*hot + n*cold))/(2*n + 1)) #EXPERIMENTING WITH LOSS DEFINTION - float ops ko aage peeche kar diya import sys def input(): return sys.stdin.readline().rstrip() testcases = int(input()) answers = [] def loss(two_n_plus_one, hot, cold, desired): n = two_n_plus_one//2 # if ...
vfc_45537
{ "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\n30 10 20\n41 15 30\n18 13 18\n", "output": "2\n7\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n999855 999262 999557\n", "output": "2\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
1379_E. Inverse Genealogy
Solve the following coding problem using the programming language python: Ivan is fond of genealogy. Currently he is studying a particular genealogical structure, which consists of some people. In this structure every person has either both parents specified, or none. Additionally, each person has exactly one child, e...
```python from heapq import * import sys int1 = lambda x: int(x) - 1 p2D = lambda x: print(*x, sep="\n") def II(): return int(sys.stdin.readline()) def MI(): return map(int, sys.stdin.readline().split()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(row...
vfc_45541
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 0\n", "output": "YES\n0 1 1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n", "output": "YES\n0 1 1 3 3 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
139_C. Literature Lesson
Solve the following coding problem using the programming language python: Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letter...
```python #------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt'...
vfc_45545
{ "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 1\na\na\na\na\na\na\ne\ne\n", "output": "aabb\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\nday\nmay\ngray\nway\n", "output": "aaaa\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1442_F. Differentiating Games
Solve the following coding problem using the programming language python: This is an interactive problem Ginny is taking an exam on game theory. The professor is tired of hearing the same answers over and over again, so he offered Ginny to play a game instead of a standard exam. As known from the course, a combinat...
vfc_45553
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 3\n1 2\n2 3\n\nLose\n\nCorrect\n\nWin\n\nCorrect\n\nDraw\n\nCorrect", "output": "1\n+ 1 3\n\n? 1 3\n? 1 2\n? 1 1\n\n! 3\n? 1 3\n? 1 2\n? 1 1\n\n! 0\n? 1 3\n? 1 2\n? 1 1\n\n! 0\n", "type": "stdin_stdout" }, {...
code_contests
verifiable_code
1493_B. Planet Lapituletti
Solve the following coding problem using the programming language python: The time on the planet Lapituletti goes the same way it goes on Earth but a day lasts h hours and each hour lasts m minutes. The inhabitants of that planet use digital clocks similar to earth ones. Clocks display time in a format HH:MM (the numb...
```python import sys,functools,collections,bisect,math,heapq input = sys.stdin.readline #print = sys.stdout.write mirror = {0:0,1:1,2:5,5:2,8:8} @functools.lru_cache(None) def fun(i): ones = i%10 i //= 10 tens = i%10 if ones in mirror: newten = mirror[ones] else: return None if...
vfc_45561
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n24 60\n12:21\n24 60\n23:59\n90 80\n52:26\n1 100\n00:01\n10 10\n04:04\n", "output": "\n12:21\n00:00\n52:28\n00:00\n00:00\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n1 1\n00:00\n1...
code_contests
verifiable_code
1515_H. Phoenix and Bits
Solve the following coding problem using the programming language python: Phoenix loves playing with bits — specifically, by using the bitwise operations AND, OR, and XOR. He has n integers a_1, a_2, ..., a_n, and will perform q of the following queries: 1. replace all numbers a_i where l ≤ a_i ≤ r with a_i AND x; ...
vfc_45565
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 7\n6 0 2 3 2 7\n1 0 4 3\n2 6 8 4\n4 0 7\n3 2 5 3\n1 0 1 2\n4 0 3\n4 2 7\n", "output": "\n5\n1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n5 4 3 2 1\n1 2 3 2\n4 2 5\n3 2 5 3\n...
code_contests
verifiable_code
1543_A. Exciting Bets
Solve the following coding problem using the programming language python: Welcome to Rockport City! It is time for your first ever race in the game against Ronnie. To make the race interesting, you have bet a dollars and Ronnie has bet b dollars. But the fans seem to be disappointed. The excitement of the fans is giv...
```python import io,os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import math t=int(input()) while(t>0): t-=1 a,b=sorted(list(map(int,input().split()))) if(a==0): print(str(b)+" 0") continue if(a==b): print("0 0") continue if((b-a)==1): print...
vfc_45569
{ "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\n8 5\n1 2\n4 4\n3 9\n", "output": "3 1\n1 0\n0 0\n6 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n8 5\n1 2\n4 5\n3 9\n", "output": "3 1\n1 0\n1 0\n6 3\n", "type": "std...
code_contests
verifiable_code
171_B. Star
Solve the following coding problem using the programming language python: <image> Input The input contains a single integer a (1 ≤ a ≤ 18257). Output Print a single integer output (1 ≤ output ≤ 2·109). Examples Input 2 Output 13 The input will be given via stdin and the output should be printed to stdout by...
```python def star(n): a, b = 1, 12 for i in range(2, n + 1): a += b b += 12 return a print(star(int(input()))) ```
vfc_45573
{ "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": "2\n", "output": "13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3823\n", "output": "87669037\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
190_E. Counter Attack
Solve the following coding problem using the programming language python: Berland has managed to repel the flatlanders' attack and is now starting the counter attack. Flatland has n cities, numbered from 1 to n, and some pairs of them are connected by bidirectional roads. The Flatlandian maps show roads between citie...
vfc_45577
{ "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 1\n1 2\n", "output": "1\n3 1 3 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 2\n1 3\n4 2\n4 3\n", "output": "2\n2 1 4 \n2 2 3 \n", "type": "stdin_stdout" }, ...