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
30_E. Tricky and Clever Password
Solve the following coding problem using the programming language python: In his very young years the hero of our story, king Copa, decided that his private data was hidden not enough securely, what is unacceptable for the king. That's why he invented tricky and clever password (later he learned that his password is a...
vfc_80569
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abacaba\n", "output": "1\n1 7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "xabyczba\n", "output": "3\n2 2\n4 1\n7 2\n", "type": "stdin_stdout" }, { "fn_name": ...
code_contests
verifiable_code
333_C. Lucky Tickets
Solve the following coding problem using the programming language python: Gerald has a friend, Pollard. Pollard is interested in lucky tickets (ticket is a sequence of digits). At first he thought that a ticket is lucky if between some its digits we can add arithmetic signs and brackets so that the result obtained by ...
vfc_80573
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 3\n", "output": "00000000\n00010001\n00020002\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 4\n", "output": "00000007\n00000016\n00000017\n00000018\n", "type": "stdin_std...
code_contests
verifiable_code
356_C. Compartments
Solve the following coding problem using the programming language python: A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people)...
```python n = int(input()) A = [0, 0, 0, 0, 0] B = map(int, input().split(' ')) for i in B: A[i] += 1 res = min(A[1], A[2]) A[1] -= res A[2] -= res A[3] += res res += 2 * (A[1] // 3) A[3] += A[1] // 3 A[1] %= 3 res += 2 * (A[2] // 3) A[3] += 2 * (A[2] // 3) A[2] %= 3 assert(A[1] == 0 or A[2] == 0) if (A[1] == 1)...
vfc_80577
{ "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\n4 1 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 3 0 4\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
37_B. Computer Game
Solve the following coding problem using the programming language python: Vasya’s elder brother Petya loves playing computer games. In one of his favourite computer games Petya reached the final level where a fight with the boss take place. While playing the game Petya found spell scrolls and now he is about to use t...
```python class Scroll: def __init__(self, id, power, damage): self.id = id self.power = power self.damage = damage self.active = False num_scrolls, boss_max, regenerate = map(int, input().split()) scrolls = [Scroll(i+1, *map(int, input().split())) for i in range(num_scrolls)] scrolls.sort(key = lambda scroll...
vfc_80581
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 100 10\n100 11\n90 9\n", "output": "YES\n19 2\n0 1\n10 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 10 3\n100 3\n99 1\n", "output": "NO\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
400_A. Inna and Choose Options
Solve the following coding problem using the programming language python: There always is something to choose from! And now, instead of "Noughts and Crosses", Inna choose a very unusual upgrade of this game. The rules of the game are given below: There is one person playing the game. Before the beginning of the game ...
```python n = int(input()) a = [1, 2, 3, 4, 6, 12] for i in range(0, n): s = str(input()) ans = [False for x in range(0, 6)] nans = 0; for i in range (0, 6): for j in range (0, 12 // a[i]): good = True for k in range(0, a[i]): if s[k * 12 // a[i] + j] is 'O': good = False break if good: ...
vfc_80585
{ "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\nOXXXOXOOXOOX\nOXOXOXOXOXOX\nXXXXXXXXXXXX\nOOOOOOOOOOOO\n", "output": "3 1x12 2x6 4x3 \n4 1x12 2x6 3x4 6x2 \n6 1x12 2x6 3x4 4x3 6x2 12x1 \n0 \n", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
427_B. Prison Transfer
Solve the following coding problem using the programming language python: The prison of your city has n prisoners. As the prison can't accommodate all of them, the city mayor has decided to transfer c of the prisoners to a prison located in another city. For this reason, he made the n prisoners to stand in a line, wi...
```python a=list(map(int,input().split()[1:])) b=list(map(int,input().split())) m=0 c=0 for i in b: if i>a[0]: if not c<a[1]: m+=c-a[1]+1 c=0 else:c+=1 print(m+c-a[1]+1 if c>=a[1]else m) ```
vfc_80589
{ "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": "1 1 1\n2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 3\n2 3 1 1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
44_J. Triminoes
Solve the following coding problem using the programming language python: There are many interesting tasks on domino tilings. For example, an interesting fact is known. Let us take a standard chessboard (8 × 8) and cut exactly two squares out of it. It turns out that the resulting board can always be tiled using domin...
vfc_80593
{ "difficulty": "16", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 3\n...\n", "output": "YES\n...\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
472_A. Design Tutorial: Learn from Math
Solve the following coding problem using the programming language python: One way to create a task is to learn from math. You can generate some random math statement or modify some theorems to get something new and build a new task from that. For example, there is a statement called the "Goldbach's conjecture". It sa...
```python def isprime(k): m=0 for j in range(2,k): if k%j==0: m=m+1 if m==0: return 0 else: return 1 n=int(input()) for i in range(4,n-3): if isprime(i)==1 and isprime(n-i)==1: print(i,n-i) exit() ```
vfc_80597
{ "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": "1000000\n", "output": "4 999996\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "23\n", "output": "8 15\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
496_B. Secret Combination
Solve the following coding problem using the programming language python: You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9...
```python n = int(input()) s = input() i = 0 min_ = int(s) s1 = s i = 0 while (i <= n): s = s[1::] + s[0] if (int(s[0]) != 0): g = (9 - int(s[0])) + 1 s2 = '' for j in range(len(s)): h = int(s[j]) + g if (h >= 10): h = abs(10 - h) s2 = ...
vfc_80601
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2014\n", "output": "0142\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n579\n", "output": "024\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
547_A. Mike and Frog
Solve the following coding problem using the programming language python: Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar. <image> So, if height of Xaniar is h1 and hei...
```python def main(): m, tt = int(input()), [0] * 4 for i in 0, 2: h, a = map(int, input().split()) x, y = map(int, input().split()) ha = (h, a) for t in range(1, m * 2): h = (h * x + y) % m if h in ha: if h == ha[0]: if...
vfc_80609
{ "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": "1023\n1 2\n1 0\n1 2\n1 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 2\n1 1\n0 1\n2 3\n", "output": "3\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
573_C. Bear and Drawing
Solve the following coding problem using the programming language python: Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree. Recall that tree is a connected graph consisting of n vertices a...
vfc_80613
{ "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": "13\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13\n", "output": "No\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
616_D. Longest k-Good Segment
Solve the following coding problem using the programming language python: The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it contains no more than k different values. Find any longest k-good segment. As the input/ou...
```python import re import sys exit=sys.exit from bisect import bisect_left as bsl,bisect_right as bsr from collections import Counter,defaultdict as ddict,deque from functools import lru_cache cache=lru_cache(None) from heapq import * from itertools import * from math import inf from pprint import pprint as pp enum=en...
vfc_80621
{ "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 5\n1 2 3 4 5\n", "output": "1 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 3\n6 5 1 2 3 2 1 4 5\n", "output": "3 7\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
635_E. Package Delivery
Solve the following coding problem using the programming language python: Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d. Johnny's truck has a gas tank that holds exactly ...
vfc_80625
{ "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 4 4\n3 5\n5 8\n6 3\n8 4\n", "output": "22\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "16 5 2\n8 2\n5 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
664_D. Graph Coloring
Solve the following coding problem using the programming language python: You are given an undirected graph that consists of n vertices and m edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges wi...
```python # # http://codeforces.com/problemset/problem/664/D import sys def visit(start, color, flag, visited): stack, swaps, n_swaps = [start], dict(), 0 while stack: u = stack.pop() visited[u], first, swap = 2, True, flag for v, c in edges[u]: if visited[v] == 2: ...
vfc_80629
{ "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": "6 5\n1 3 R\n2 3 R\n3 4 B\n4 5 R\n4 6 R\n", "output": "2\n3 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n1 2 R\n1 3 R\n2 3 B\n3 4 B\n1 4 B\n", "output": "-1\n", "type...
code_contests
verifiable_code
689_B. Mike and Shortcuts
Solve the following coding problem using the programming language python: Recently, Mike was very busy with studying for exams and contests. Now he is going to chill a bit by doing some sight seeing in the city. City consists of n intersections numbered from 1 to n. Mike starts walking from his house located at the i...
```python def amount_of_total_energy(n, a): dist = [-1] * n dist[0] = 0 pos = [0] for u in pos: for v in [u - 1, u + 1, a[u] - 1]: if v >= 0 and v < n and dist[v] == -1: dist[v] = dist[u] + 1 pos.append(v) return dist n = int(input()) a = list(map(int,input().split()...
vfc_80633
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5\n", "output": "0 1 2 3 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n4 4 4 4 7 7 7\n", "output": "0 1 2 1 2 3 3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
710_F. String Set Queries
Solve the following coding problem using the programming language python: You should process m queries over a set D of strings. Each query is one of three kinds: 1. Add a string s to the set D. It is guaranteed that the string s was not added before. 2. Delete a string s from the set D. It is guaranteed that the...
vfc_80637
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 768000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 abc\n3 abcabc\n2 abc\n1 aba\n3 abababc\n", "output": "2\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 abc\n1 bcd\n1 abcd\n3 abcd\n2 abcd\n3 abcd\n2 bcd\n3 abcd\n2 abc\n3 ab...
code_contests
verifiable_code
731_F. Video Cards
Solve the following coding problem using the programming language python: Little Vlad is fond of popular computer game Bota-2. Recently, the developers announced the new add-on named Bota-3. Of course, Vlad immediately bought only to find out his computer is too old for the new game and needs to be updated. There are...
```python n = int(input()) s = list(map(int, input().split())) h = max(s) ss = [0] * (h + 1) for i in s: ss[i] += 1 f, x = [0] * h, 0 for j in reversed(ss): x += j f.append(x) f.reverse() res = [] for i, x in enumerate(ss): if x: summ, x = 0, f[i] for j in range(i, h + 1, i): ...
vfc_80641
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n8 2 2 7\n", "output": "18\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n3 2 15 9\n", "output": "27\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
756_A. Pavel and barbecue
Solve the following coding problem using the programming language python: Pavel cooks barbecue. There are n skewers, they lay on a brazier in a row, each on one of n positions. Pavel wants each skewer to be cooked some time in every of n positions in two directions: in the one it was directed originally and in the rev...
```python import sys input = sys.stdin.readline n = int(input()) permutation = list(map(int, input().split())) go = set(range(1,n+1)) reached = set() ans = 0 while go: x = go.pop() while x not in reached: reached.add(x) x = permutation[x-1] if x in go: go.remove(x) ans += 1 if ans == 1: ans ...
vfc_80645
{ "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\n2 3 1\n0 0 0\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
777_B. Game of Credit Cards
Solve the following coding problem using the programming language python: After the fourth season Sherlock and Moriary have realized the whole foolishness of the battle between them and decided to continue their competitions in peaceful game of Credit Cards. Rules of this game are simple: each player bring his favour...
```python n = int(input()) s = list(map(int, list(input()))) m = map(int, list(input())) ma = [0] * 10 for dig in m: ma[dig] += 1 ma2 = list(ma) min_f = 0 for nu in s: for x in range(nu, 10): if ma[x] > 0: ma[x] -= 1 break else: min_f += 1 for z in range(le...
vfc_80649
{ "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\n123\n321\n", "output": "0\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n88\n00\n", "output": "2\n0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
801_E. Vulnerable Kerbals
Solve the following coding problem using the programming language python: You are given an integer m, and a list of n distinct integers between 0 and m - 1. You would like to construct a sequence satisfying the properties: * Each element is an integer between 0 and m - 1, inclusive. * All prefix products of the...
vfc_80653
{ "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": "0 5\n", "output": "5\n1 2 4 3 0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 10\n2 9 1\n", "output": "6\n3 9 2 4 8 0\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
822_B. Crossword solving
Solve the following coding problem using the programming language python: Erelong Leha was bored by calculating of the greatest common divisor of two factorials. Therefore he decided to solve some crosswords. It's well known that it is a very interesting occupation though it can be very difficult from time to time. In...
```python n, m = map(int, input().split()) s = input() t = input() res = 1001 res_ind = [] b = 0 e = len(s) while b <= len(t)-len(s): sr = t[b:e] k = 0 ind = [] for i in range(len(s)): if s[i] != sr[i]: k += 1 else: ind.append(i+1) if k < res: res = ...
vfc_80657
{ "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 10\nabcd\nebceabazcd\n", "output": "1\n2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\nabc\nxaybz\n", "output": "2\n2 3 \n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
847_G. University Classes
Solve the following coding problem using the programming language python: There are n student groups at the university. During the study day, each group can take no more than 7 classes. Seven time slots numbered from 1 to 7 are allocated for the classes. The schedule on Monday is known for each group, i. e. time slot...
```python n = int(input()) schedules = [] for i in range(n): schedules.append(input()) minimum = 0 for i in range(7): activeSlots = 0 for j in range(n): activeSlots += int(schedules[j][i]) if activeSlots > minimum: minimum = activeSlots print(minimum) ```
vfc_80661
{ "difficulty": "13", "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\n0101011\n0011001\n0110111\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
869_B. The Eternal Immortality
Solve the following coding problem using the programming language python: Even if the world is full of counterfeits, I still regard it as wonderful. Pile up herbs and incense, and arise again from the flames and ashes of its predecessor — as is known to many, the phoenix does it like this. The phoenix has a rather l...
```python # Main maut ko takiya, aur kafan ko chaadar banakkar audhta hoon! a,b=input().split() if a[:-1]!=b[:-1]: print("0") else: ans=1 for i in range(int(a[-1])+1,int(b[-1])+1): ans*=i ans=ans%10 print(ans) ```
vfc_80665
{ "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": "107 109\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 10\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 ...
code_contests
verifiable_code
895_A. Pizza Separation
Solve the following coding problem using the programming language python: Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order a pizza. In this problem pizza is a circle of some radius. The pizza was delivered already cut into n pieces. The i-th piece...
```python n=int(input()) a=list(map(int,input().split())) print(2*min(abs(180-sum(a[l:r])) for l in range(n) for r in range(l,n))) ```
vfc_80669
{ "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\n170 30 150 10\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n100 100 160\n", "output": "40\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
916_B. Jamie and Binary Sequence (changed after round)
Solve the following coding problem using the programming language python: Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find k integers such that the sum of two to the power of each number equals to the n...
```python n, k = map(int, input().split()) cnt = [0] * 200010 ans = '' for i in range(64): if (n >> i)&1: k -= 1 cnt[i] = 1; if k < 0: print("No") else: print("Yes") for i in range(64, -64, -1): if k >= cnt[i]: cnt[i - 1] += cnt[i] * 2 k -= cnt[i] cnt[i] = 0 else: break for i...
vfc_80673
{ "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": "23 5\n", "output": "Yes\n3 3 2 1 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\n", "output": "Yes\n-1 -1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
939_C. Convenient For Everybody
Solve the following coding problem using the programming language python: In distant future on Earth day lasts for n hours and that's why there are n timezones. Local times in adjacent timezones differ by one hour. For describing local time, hours numbers from 1 to n are used, i.e. there is no time "0 hours", instead ...
```python # Problem D n = int(input()) inp = input().split(" ") people = [ int(x) for x in inp ] inp = input().split(" ") s, f = int(inp[0]), int(inp[1]) r = f-s#+1 # tamaño de la ventana max_s, idx_max = sum( people[i] for i in range(r) ), 0 sum_ac = max_s res = (n-idx_max+s)%n if (n-idx_max+s)%n else n for j in rang...
vfc_80677
{ "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\n1 2 3 4 1\n1 3\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2 3\n1 3\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
964_E. Cutting Rectangle
Solve the following coding problem using the programming language python: A rectangle with sides A and B is cut into rectangles with cuts parallel to its sides. For example, if p horizontal and q vertical cuts were made, (p + 1) ⋅ (q + 1) rectangles were left after the cutting. After the cutting, rectangles were of n ...
```python n = input() w=[] h=[] c=[] cntw={} cnth={} gcdC=0 cntC=0 def insert1(a,b,c): if not a in b : b[a]=c else : b[a]=b[a]+c def gcd(a,b): if a % b == 0 : return b else : return gcd(b,a%b) for i in range(0, n): a,b,d = map(int, raw_input().split()) w.append(a) h.append(b) c.append(d) insert1(a...
vfc_80681
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 3 20\n2 4 40\n", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2 5\n2 3 5\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
991_F. Concise and clear
Solve the following coding problem using the programming language python: Vasya is a regular participant at programming contests and is already experienced in finding important sentences in long statements. Of course, numbers constraints are important — factorization of a number less than 1000000 is easier than of a n...
```python import math import itertools pow10 = [1] for i in range(10): pow10.append(pow10[-1] * 10) def getlen(x): """length of the decimal representation of integer x""" return int(math.log10(x)) + 1 class ShortestRepresentation: def __init__(self, n): self.n = n self._m = {} ...
vfc_80685
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000000007\n", "output": "10^9+7", "type": "stdin_stdout" }, { "fn_name": null, "input": "2018\n", "output": "2018", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
arrange-boxes-1
Solve the following coding problem using the programming language python: Subodh is celebrating its annual Techno-Cultural Fest. The IT student Kejal has agreed to supply candies for this festive season. The Kejal has prepared N boxes of candies, numbered 1 to N (Each number occurring exactly once ). The Kejal is ver...
```python for _ in range(input()): try:n=input() except:n=input() if n==0: print 0 continue # print n try:arr=raw_input().split() except:arr=raw_input().split() try:seq=raw_input().split() except:seq=raw_input().split() if n==1: print 0 continue #print n count=0 flag=False while len(arr)>0: x=0 ...
vfc_80689
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n\n3\n1 2 3\n3 1 2\n\nSAMPLE", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n\n3\n1 2 3\n3 2 1", "output": "3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
check-if-its-a-check
Solve the following coding problem using the programming language python: In a game of chess, Check is a game position in which a player's King is under attack by any of the opponent's pieces. Bob is playing with Chess pieces. He randomly arranges three pieces on 8x8 chessboard: a black's King , a white's King and an...
```python #!/usr/bin/python def getCoords(p): if p[0] == 'a': y = 1 elif p[0] == 'b': y = 2 elif p[0] == 'c': y = 3 elif p[0] == 'd': y=4 elif p[0] == 'e': y=5 elif p[0] == 'f': y=6 elif p[0] == 'g': y=7 elif p[0] == 'h': y...
vfc_80693
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\ne8 e1\nq a4\ne7 d3\nb f6\nh6 g4 \nk h4\nd8 e1\nr d3\n\nSAMPLE", "output": "check\ncheck\n-1\ncheck", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\ne8 e1\nq a4\ne7 d3\nb f6\nh6 g4 \nk h...
code_contests
verifiable_code
doghouses
Solve the following coding problem using the programming language python: Russian version of the problem can be read here. As you probably know, cats usually fight with dogs. There are N doghouses in a backyard. For simplicity, we consider the backyard as a plane, and the doghouses as points on the plane. All doghou...
```python def main(): n=int(raw_input()) Y=map(int,raw_input().split()) y={} i=0 while(i<len(Y)): if Y[i] in y: y.update({Y[i]:[y[Y[i]][0],i,y[Y[i]][2]+1]}) else: y.update({Y[i]:[i,i,1]}) i+=1 if n==1: print "1" else: ans=0 flag=0 for key1 in y: g=key1 for key2 in y: if key2!=key1: ...
vfc_80697
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 3 4 1 1\n\nSAMPLE", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000\n3 6 10 2 7 0 12 2 10 10 3 6 7 8 9 6 8 12 11 4 8 6 12 5 10 7 9 1 2 1 10 4 12 12 11 13 12 12 10 0 13...
code_contests
verifiable_code
gotta-catch-em-all
Solve the following coding problem using the programming language python: Little Arihant has always wanted to be the best Pokemon trainer in this world. And he thinks he has achieved his goal, so he wants to quickly go and meet Professor Oak and verify this fact. But like all Pokemon trainers, he has a weird habit, to...
```python nosOfPokemon = input() evolutionPeriod = sorted(map(int, raw_input().split()), reverse=True) daysNeeded = 0 for i, v in enumerate(evolutionPeriod): daysNeeded = max(daysNeeded, i+v) print daysNeeded + 2 ```
vfc_80701
{ "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 1\n\nSAMPLE", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10001\n100028 100028 100028 2289 1226 3868 100028 100028 1231 1861 100028 1604 4238 100028 100028 3575 10002...
code_contests
verifiable_code
little-jhool-and-his-breakup
Solve the following coding problem using the programming language python: After minting loads of money from innocent people by using the psychic powers (As we saw in the previous question!) - little Jhool managed to woo his girlfriend big Jhool! And now, he's in love - madly, madly in love with his girlfriend. But t...
```python import re def main(): s1=raw_input() if re.search("l.*o.*v.*e",s1):print 'I love you, too!' else:print 'Let us breakup!' if __name__=="__main__": main() ```
vfc_80705
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "lov3333333asdafajfgnkdfn33333e\n\nSAMPLE", "output": "I love you, too!\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
mr-smoothy
Solve the following coding problem using the programming language python: Mr. Smoothy is a restaurant that serves mostly smoothies at which Ben and his friends are regular customers. The titular mascot is a cup with face and legs that holds a smaller cup. It serves the strangest assortment of flavors in its smoothies,...
```python T = int(input()) for t in range(T): L = map(int, raw_input().split()) N = L[0] del L[0] counter = 0 for i in range(N): for j in range(i+1, N): if L[i]>L[j]: counter += 1 print counter ```
vfc_80709
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5 5 6 3 4 8\n\nSAMPLE", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n5 5 6 3 7 8\n\nSAMPLE", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
prateek-and-theories-3
Solve the following coding problem using the programming language python: Scientists, researchers, mathematicians and thinkers propose theories for a number of things. For explaining a single thing, a number of theories are proposed. A number of theories are rendered invalid after a new and more relevant theory surf...
```python T = int(raw_input()) mod = 1000000007 for t in xrange(T): startsorted = [] endsorted = [] events = [] n = int(raw_input()) for i in xrange(n): x,y = map(int,raw_input().split()) startsorted.append((x,y-1)) endsorted.append((y-1,x)) events.append(x) ...
vfc_80713
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5\n1 10\n2 4\n3 5\n11 12\n12 13\n\nSAMPLE", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n5\n1 12\n2 4\n3 5\n11 12\n12 13\n\nSAMPLE", "output": "3\n", "type"...
code_contests
verifiable_code
samu-and-permutations
Solve the following coding problem using the programming language python: Samu had got N fruits. Sweetness of i^th fruit is given by A[i]. Now she wants to eat all the fruits , in such a way that total taste is maximised. Total Taste is calculated as follow (Assume fruits sweetness array uses 1-based indexing) : in...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' def greed(arr,j,N): max1=0 op=[] k=0 chk=[] N1=N sol=0 for x in arr: chk.append(0) seed=arr[j] op.append(arr[j]) chk[j]=1 flag=0 while N1>=2: flag=0 f...
vfc_80717
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n2 5 4\n\nSAMPLE", "output": "13", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n12\n77 45 4 92 12 57 14 41 87 96 68 48\n8\n41 38 50 92 26 43 20 55\n7\n48 61 70 58 84 93 18\n4\n81 4...
code_contests
verifiable_code
sumit-and-rohil
Solve the following coding problem using the programming language python: See Russian Translation It's a fine sunny afternoon today in California. Looking at the pleasant weather, Sumit is all ready to go out and play with his friend Rohil. Unfortunately, Rohil is down with fever. Seeing that his friend is ill, Sumit...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' arr = [] no = int(raw_input()) for i in range(no): strInput = raw_input() firstChar = strInput[0] lastChar = strInput[-1] sortedStrInput = "".join(so...
vfc_80721
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nvinay\nvainy\nvinit\nviint\navinash\naasivnh\n\nSAMPLE", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "24\nabcd\nabdc\nacbd\nacdb\nadbc\nadcb\nbacd\nbadc\nbcad\nbcda\nbda...
code_contests
verifiable_code
welcome-to-ooty
Solve the following coding problem using the programming language python: Find a*b, for all given number pairs SAMPLE INPUT 5 4 6 3 7 SAMPLE OUTPUT 24 21 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.
```python import sys for line in sys.stdin: a = line.split() if(len(a)==2): print int(a[0])*int(a[1]) ```
vfc_80725
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 6\n3 7\n\nSAMPLE", "output": "24\n21\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 6\n3 7\n\nTAMPLE", "output": "24\n21\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p00504 Gifts
Solve the following coding problem using the programming language python: problem JOI, who came to Australia for a trip, enjoyed sightseeing in various places and finally returned to Japan. Now, JOI is in the town with the international airport where the return flight departs. The town is divided into north, south, e...
vfc_80781
{ "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": "5 4 2\n...#\n.#.#\n.#73\n8##.\n....", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4 2\n...#\n.#/#\n.#73\n8##.\n....", "output": "11\n", "type": "stdin_stdout"...
code_contests
verifiable_code
p00688 Factorization of Quadratic Formula
Solve the following coding problem using the programming language python: As the first step in algebra, students learn quadratic formulas and their factorization. Often, the factorization is a severe burden for them. A large number of students cannot master the factorization; such students cannot be aware of the elega...
```python import fractions while True: a, b, c = map(int, input().split()) if not a: break d = (b ** 2 - 4 * a * c) ** 0.5 if isinstance(d, complex) or d - int(d) > 1e-6: print('Impossible') continue num1, num2 = -b + int(d), -b - int(d) den = 2 * a cmn1, cmn2 = frac...
vfc_80785
{ "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": "2 5 2\n1 1 1\n10 -7 0\n1 0 -3\n0 0 0", "output": "2 1 1 2\nImpossible\n10 -7 1 0\nImpossible", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00830 Pathological Paths
Solve the following coding problem using the programming language python: Professor Pathfinder is a distinguished authority on the structure of hyperlinks in the World Wide Web. For establishing his hypotheses, he has been developing software agents, which automatically traverse hyperlinks and analyze the structure of...
```python # from urllib.parse import urljoin def testcase_ends(): n, m = map(int, input().split()) if (n, m) == (0, 0): return 1 htmls = set(input() for i in range(n)) files = set('/') for html in htmls: sp = html.split('/') for i in range(2, len(sp)): files.add...
vfc_80789
{ "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 6\n/home/ACM/index.html\n/ICPC/index.html\n/ICPC/general.html\n/ICPC/japanese/index.html\n/ICPC/secret/confidential/2005/index.html\n/home/ACM/\n/home/ICPC/../ACM/\n/ICPC/secret/\n/ICPC/secret/index.html\n/ICPC\n/ICPC/../ICPC/ind...
code_contests
verifiable_code
p00961 Black or White
Solve the following coding problem using the programming language python: Problem E Black or White Here lies a row of a number of bricks each painted either black or white. With a single stroke of your brush, you can overpaint a part of the row of bricks at once with either black or white paint. Using white paint, al...
vfc_80793
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\nBWWB\nWBBW", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\nBWWB\nWBBW", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p01094 Look for the Winner!
Solve the following coding problem using the programming language python: Look for the Winner! The citizens of TKB City are famous for their deep love in elections and vote counting. Today they hold an election for the next chairperson of the electoral commission. Now the voting has just been closed and the counting ...
```python from collections import Counter while True: n = int(input()) if n == 0: quit() elif n == 1: print(input(), 1) else: c = list(input().split()) h = [0 for i in range(26)] flag = 0 for i in range(n): h[ord(c[i])-65] += 1 if ...
vfc_80797
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n10\nU U U U U V V W W W\n0", "output": "A 1\nTIE\nTIE\nK 4\nX 5\nA 7\nU 8", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
p01364 Two-Wheel Buggy
Solve the following coding problem using the programming language python: International Car Production Company (ICPC), one of the largest automobile manufacturers in the world, is now developing a new vehicle called "Two-Wheel Buggy". As its name suggests, the vehicle has only two wheels. Quite simply, "Two-Wheel Bugg...
```python from math import pi, cos, sin def solve(): def rotate(x, y, theta): cv = cos(theta); sv = sin(theta) return x*cv - y*sv, x*sv + y*cv N, D = map(int, input().split()) if N == D == 0: return False x0 = -D; x1 = D y0 = y1 = 0 for i in range(N): dl, dr, t = ...
vfc_80805
{ "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 1\n180 90 2\n1 1\n180 180 20\n2 10\n360 -360 5\n-90 360 8\n3 2\n100 60 9\n-72 -72 10\n-45 -225 5\n0 0", "output": "3.00000\n3.00000\n0.00000\n62.83185\n12.00000\n0.00000\n-2.44505\n13.12132", "type": "stdin_stdout" ...
code_contests
verifiable_code
p01702 Unknown Switches
Solve the following coding problem using the programming language python: Problem Statement In the headquarter building of ICPC (International Company of Plugs & Connectors), there are $M$ light bulbs and they are controlled by $N$ switches. Each light bulb can be turned on or off by exactly one switch. Each switch m...
```python while 1: n,m,q=map(int,input().split()) if (n|m|q)==0: break p=[] res=[{_ for _ in range(n)} for _ in range(m)] for i in range(q): s,b=[[int(c) for c in s] for s in input().split()] if i>0: for j in range(n): s[j]^=p[j] zero={i for i in range(n) if s[i]==0} one={i fo...
vfc_80813
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 10 3\n000 0000000000\n110 0000001111\n101 1111111100\n2 2 0\n1 1 0\n2 1 1\n01 1\n11 11 10\n10000000000 10000000000\n11000000000 01000000000\n01100000000 00100000000\n00110000000 00010000000\n00011000000 00001000000\n00001100000 0...
code_contests
verifiable_code
p01846 jfen
Solve the following coding problem using the programming language python: jfen There is a one-person game to play on the H × W board. This game is a game to move 0 or 1 balls in each cell. You were playing this game and found it difficult to move the ball accurately from cell to cell because the ball is so round. So ...
```python while True: s = input() if s == "#":break s = s.split("/") area = [0] * len(s) for i in range(len(s)): t = [] while True: if s[i][0] == "b": t.append(1) s[i] = s[i][1:] else: if "b" in s[i]: ...
vfc_80817
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 4\nb2b2b/7\n1 4 2 4\n#", "output": "1b/1b\nb2b2/bbb1bb\nb5b/3b3", "type": "stdin_stdout" }, { "fn_name": null, "input": "b1/1b\n1 1 1 2\nb5/bbbbbb\n2 4 1 4\nb2b2b/7\n...
code_contests
verifiable_code
p01982 Generalized Leap Years
Solve the following coding problem using the programming language python: Generalized leap year Normally, whether or not the year x is a leap year is defined as follows. 1. If x is a multiple of 400, it is a leap year. 2. Otherwise, if x is a multiple of 100, it is not a leap year. 3. Otherwise, if x is a multiple o...
```python def solve(n ,l, r, A): res = 0 for x in range(l, r+1): for i in range(n): if (not x%A[i]) : res += 0 if (i&1) else 1 break else: res += 0 if (n&1) else 1 return res def main(): ans = [] while True: n, l, r =...
vfc_80821
{ "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 1988 2014\n400\n100\n4\n1 1000 1999\n1\n2 1111 3333\n2\n2\n6 2000 3000\n5\n7\n11\n9\n3\n13\n0 0 0", "output": "7\n1000\n2223\n785", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1988 201...
code_contests
verifiable_code
p02269 Dictionary
Solve the following coding problem using the programming language python: Your task is to write a program of a simple dictionary which implements the following instructions: * insert str: insert a string str in to the dictionary * find str: if the distionary contains str, then print 'yes', otherwise print 'no' Notes...
```python n = int(input()) dic = {} for i in range(n): a = input() if a[0] == "i": dic[a[7:]] = 0 else: if a[5:] in dic: print("yes") else: print("no") ```
vfc_80829
{ "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": "5\ninsert A\ninsert T\ninsert C\nfind G\nfind A", "output": "no\nyes", "type": "stdin_stdout" }, { "fn_name": null, "input": "13\ninsert AAA\ninsert AAC\ninsert AGA\ninsert AGG\ninsert TTT\nfind AAA\...
code_contests
verifiable_code
p02416 Sum of Numbers
Solve the following coding problem using the programming language python: Write a program which reads an integer and prints sum of its digits. Input The input consists of multiple datasets. For each dataset, an integer x is given in a line. The number of digits in x does not exceed 1000. The input ends with a lin...
```python while True: n = input() if n == "0": break n = map(int, n) print(sum(n)) ```
vfc_80833
{ "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": "123\n55\n1000\n0", "output": "6\n10\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "123\n55\n1001\n0", "output": "6\n10\n2\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
btreat
Solve the following coding problem using the programming language python: Its Chef's Birthday and his friends are demanding him for treat. So he went to the shop to buy N gift packets (one for each friend). Each gift packet bought from shop contains some number of chocolates in it. Chef believes in equality i.e. all...
```python import sys for t in xrange(int(sys.stdin.readline())): n=int(sys.stdin.readline()) arr=map(int,sys.stdin.readline().split()) s=sum(arr) if s%n ==0: avg=s/n c=0 for i in xrange(n): c+=abs(avg-arr[i]) print c/2 else: print "No Treat" ```
vfc_80837
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n5 2 4 5\n6\n5 2 4 1 7 5", "output": "2\n5", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
compiler
Solve the following coding problem using the programming language python: Lira is now very keen on compiler development. :) She knows that one of the most important components of a compiler, is its parser. A parser is, in simple terms, a software component that processes text, and checks it's semantic correctness, or...
```python import sys RL = sys.stdin.readline T = int(RL()) for i in xrange(T): inp = RL() stack = 0 strlen = len(inp) count = 0 for j in xrange(strlen): if inp[j] == '<': stack += 1 elif inp[j] == '>': if stack == 0: break stack ...
vfc_80841
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n<<>>\n><\n<>>>", "output": "4\n0\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n<<>>\n<>\n<>>>", "output": "4\n2\n2\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
gdog
Solve the following coding problem using the programming language python: Tuzik is a little dog. But despite the fact he is still a puppy he already knows about the pretty things that coins are. He knows that for every coin he can get very tasty bone from his master. He believes that some day he will find a treasure a...
```python # @author Kilari Teja # GDOG Possibles = [100, 50, 10, 5, 2, 1] for _ in xrange(int(raw_input().strip())): Bucks = map(int, raw_input().strip().split(" ")) MaxBucks = 0 for People in xrange(1, Bucks[1] + 1): if Bucks[0]%People > MaxBucks: MaxBucks = Bucks[0]%People print MaxBucks ```
vfc_80845
{ "difficulty": "1", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 2\n11 3", "output": "1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5 4\n11 3", "output": "2\n2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
prys01
Solve the following coding problem using the programming language python: Problem Statement N knights were sitting at a round table and having a serious talk. The knights are so tired, that they can’t even rotate their neck to talk to talk to the knights sitting on their sides. So, a knight can only talk to the knight...
```python #chiragjn t=int(raw_input()) for i in xrange(t): n,m=map(int,raw_input().split()) print m+(n>>1) if m<=n/2 else m-(n>>1) ```
vfc_80853
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n6 2", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n10 2", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n20 ...
code_contests
verifiable_code
tidrice
Solve the following coding problem using the programming language python: Did you know that there are over 40,000 varieties of Rice in the world ? There are so many dishes that can be prepared with Rice too. A famous chef from Mumbai, Tid Gusto prepared a new dish and named it 'Tid Rice'. He posted the recipe in his n...
```python t=int(raw_input()) for _ in range(0,t): n=int(raw_input()) d= dict(raw_input().split() for _ in range(n)) k=[] for value in d: k.append(d[value]) sum=0 for item in k: if item=='+': sum+=1 elif item=="-": sum-=1 print sum ```
vfc_80857
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\ntilak +\ntilak +\ntilak -\ntilak +\n3\nratna +\nshashi -\nratna -\n3\nbhavani -\nbhavani +\nbhavani -", "output": "1\n-2\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4\ntil...
code_contests
verifiable_code
1013_A. Piles With Stones
Solve the following coding problem using the programming language python: There is a beautiful garden of stones in Innopolis. Its most beautiful place is the n piles with stones numbered from 1 to n. EJOI participants have visited this place twice. When they first visited it, the number of stones in piles was x_1,...
```python n=int(input()) p=input().split(' ') c=input().split(' ') t=z=0 for k in range(n): t+=int(p[k]) z+=int(c[k]) if (t<z): print('No') else: print('Yes') ```
vfc_80861
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5\n2 1 4 3 5\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 1 1 1\n1 0 1 0 1\n", "output": "Yes\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1037_G. A Game on Strings
Solve the following coding problem using the programming language python: Alice and Bob are playing a game on strings. Initially, they have some string t. In one move the first player selects the character c present in t and erases all it's occurrences in t, thus splitting t into many smaller strings. The game then g...
vfc_80865
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aaccbdb\n2\n5 7\n1 7\n", "output": "Alice\nAlice\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1060_C. Maximum Subrectangle
Solve the following coding problem using the programming language python: You are given two arrays a and b of positive integers, with length n and m respectively. Let c be an n × m matrix, where c_{i,j} = a_i ⋅ b_j. You need to find a subrectangle of the matrix c such that the sum of its elements is at most x, and...
```python n,m=[int(x) for x in input().split()] a=[int(x) for x in input().split()] b=[int(x) for x in input().split()] x=int(input()) csa=[0]*(n+1) csb=[0]*(m+1) ans=0 for i in range(1,n+1): csa[i]=(csa[i-1]+a[i-1]) for i in range(1,m+1): csb[i]=(csb[i-1]+b[i-1]) misubsa=[0]*(n+1) misubsb=[0]*(m+1) for i in ra...
vfc_80869
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 1\n5 4 2 4 5\n2\n5\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 2 3\n1 2 3\n9\n", "output": "4", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
1082_A. Vasya and Book
Solve the following coding problem using the programming language python: Vasya is reading a e-book. The file of the book consists of n pages, numbered from 1 to n. The screen is currently displaying the contents of page x, and Vasya wants to read the page y. There are two buttons on the book which allow Vasya to scro...
```python T = int(input()) from math import ceil for i in range(T): n,in_,fin_,d = map(int,input().split()) r1 = in_%d r2 = fin_%d r = n%d z = float("inf") a1,a2,a3 = float("inf"),float("inf"),float("inf") if r1 == r2: a1 = abs(fin_-in_)//d if r2 == r: a2 = ceil((n-in_)/d)+abs((fin_-n)//d) if r2 == 1: ...
vfc_80873
{ "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\n10 4 5 2\n5 1 3 4\n20 4 19 3\n", "output": "4\n-1\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n123 123 123 123\n", "output": "0\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1101_C. Division and Union
Solve the following coding problem using the programming language python: There are n segments [l_i, r_i] for 1 ≤ i ≤ n. You should divide all segments into two non-empty groups in such way that there is no pair of segments from different groups which have at least one common point, or say that it's impossible to do i...
```python for _ in range(int(input())): n=int(input()) a=sorted(list(map(int,input().split()))+[i] for i in range(n)) ans=[0]*n group=1 maxx=a[0][1] for l,r,i in a: if group==1 and maxx<l: group=2 if r>maxx: maxx=r ans[i]=group if group==2: ...
vfc_80877
{ "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\n2\n5 5\n2 3\n3\n3 5\n2 3\n2 3\n3\n3 3\n4 4\n5 5\n", "output": "2 1 \n-1\n1 2 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\n5 5\n2 3\n3\n3 5\n1 3\n2 3\n3\n3 3\n4 4\n5 5\n", ...
code_contests
verifiable_code
112_A. Petya and Strings
Solve the following coding problem using the programming language python: Little Petya loves presents. His mum bought him two strings of the same size for his birthday. The strings consist of uppercase and lowercase Latin letters. Now Petya wants to compare those two strings lexicographically. The letters' case does n...
```python a=input();b=input() A=a.lower();B=b.lower() if A==B: print(0) elif A>B: print(1) elif A<B: print(-1) ```
vfc_80881
{ "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": "aaaa\naaaA\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abs\nAbz\n", "output": "-1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
114_B. PFAST Inc.
Solve the following coding problem using the programming language python: When little Petya grew up and entered the university, he started to take part in АСМ contests. Later he realized that he doesn't like how the АСМ contests are organised: the team could only have three members (and he couldn't take all his friend...
```python '''input 7 12 Pasha Lesha Vanya Taras Nikita Sergey Andrey Pasha Taras Pasha Nikita Pasha Andrey Pasha Sergey Lesha Taras Lesha Nikita Lesha Andrey Lesha Sergey Vanya Taras Vanya Nikita Vanya Andrey Vanya Sergey ''' from sys import stdin, stdout from collections import deque import sys from copy import deepco...
vfc_80885
{ "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 0\nPasha\nLesha\nVanya\n", "output": "3\nLesha\nPasha\nVanya\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\nPetya\nVasya\nMasha\nPetya Vasya\n", "output": "2\nMasha\nPetya\n"...
code_contests
verifiable_code
1189_E. Count Pairs
Solve the following coding problem using the programming language python: You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k. Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p. Input The first line contains integers n, p, k (2 ≤ n ≤...
```python from collections import Counter n, p, k = map(int, input().split()) arr = [ (x ** 4 - k * x) % p for x in list(map(int, input().split())) ] print( sum([ (x * (x - 1)) // 2 for x in Counter(arr).values() ]) ) ```
vfc_80893
{ "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": "6 7 2\n1 2 3 4 5 6\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 0\n0 1 2\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1208_F. Bits And Pieces
Solve the following coding problem using the programming language python: You are given an array a of n integers. You need to find the maximum value of a_{i} | ( a_{j} \& a_{k} ) over all triplets (i,j,k) such that i < j < k. Here \& denotes the [bitwise AND operation](https://en.wikipedia.org/wiki/Bitwise_operation...
vfc_80897
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 4 6\n", "output": "6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1227_E. Arson In Berland Forest
Solve the following coding problem using the programming language python: The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events. A destructive fire raged through the Forest, and several trees were damaged by it. Precisely speaking, you...
vfc_80901
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 6\nXXXXXX\nXXXXXX\nXXXXXX\n", "output": "1\n......\n.XXXX.\n......\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10\n.XXXXXX...\n.XXXXXX...\n.XXXXXX...\n.XXXXXX...\n.XXXXXXXX.\n...X...
code_contests
verifiable_code
1250_D. Conference Problem
Solve the following coding problem using the programming language python: A large-scale conference on unnatural sciences is going to be held soon in Berland! In total, n scientists from all around the world have applied. All of them have indicated a time segment when they will attend the conference: two integers l_i, ...
vfc_80905
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n1 10 30\n5 6 30\n6 12 0\n1 1 0\n4\n1 2 1\n2 3 0\n3 4 0\n4 5 2\n", "output": "\n4\n2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
126_B. Password
Solve the following coding problem using the programming language python: Asterix, Obelix and their temporary buddies Suffix and Prefix has finally found the Harmony temple. However, its doors were firmly locked and even Obelix had no luck opening them. A little later they found a string s, carved on a rock below the...
```python from fractions import Fraction import bisect import os from collections import Counter import bisect from collections import defaultdict import math import random import heapq as hq from math import sqrt import sys from functools import reduce, cmp_to_key from collections import deque import threading from it...
vfc_80909
{ "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": "abcdabc\n", "output": "Just a legend\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "fixprefixsuffix\n", "output": "fix\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
1292_A. NEKO's Maze Game
Solve the following coding problem using the programming language python: [3R2 as DJ Mashiro - Happiness Breeze](https://open.spotify.com/track/2qGqK8GRS65Wlf20qUBEak) [Ice - DJ Mashiro is dead or alive](https://soundcloud.com/iceloki/dj-mashiro-is-dead-or-alive) NEKO#ΦωΦ has just got a new maze game on her PC! The...
```python import sys input = sys.stdin.readline hell=1000000007 def meowmeow321(): n,q=map(int,input().split()) cnt=0 mark1 = [0]*(n+5) mark2 = [0]*(n+5) for i in range(q): r,c = map(int,input().split()) if r==1: if mark1[c]: cnt-=mark2[c] ...
vfc_80913
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n2 3\n1 4\n2 4\n2 3\n1 4\n", "output": "Yes\nNo\nNo\nNo\nYes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "73034 53\n2 21523\n1 21522\n2 21523\n2 21521\n2 37146\n2 21521\n2 21521\n2 ...
code_contests
verifiable_code
1312_B. Bogosort
Solve the following coding problem using the programming language python: You are given an array a_1, a_2, ... , a_n. Array is good if for each pair of indexes i < j the condition j - a_j ≠ i - a_i holds. Can you shuffle this array so that it becomes good? To shuffle an array means to reorder its elements arbitrarily ...
```python N=int(input()) for i in range(N): b=int(input()) a=list(map(int, input().split()[:b])) print(*sorted(a)[::-1]) ```
vfc_80917
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n7\n4\n1 1 3 5\n6\n3 2 1 5 6 4\n", "output": "7\n5 3 1 1\n6 5 4 3 2 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3\n4 2 1\n", "output": "4 2 1\n", "type": "stdin_s...
code_contests
verifiable_code
1334_F. Strange Function
Solve the following coding problem using the programming language python: Let's denote the following function f. This function takes an array a of length n and returns an array. Initially the result is an empty array. For each integer i from 1 to n we add element a_i to the end of the resulting array if it is greater ...
vfc_80921
{ "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": "11\n4 1 3 3 7 8 7 9 10 7 11\n3 5 0 -2 5 3 6 7 8 2 4\n3\n3 7 10\n", "output": "YES\n20", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1355_A. Sequence with Digits
Solve the following coding problem using the programming language python: Let's define the following recurrence: $$$a_{n+1} = a_{n} + minDigit(a_{n}) ⋅ maxDigit(a_{n}).$$$ Here minDigit(x) and maxDigit(x) are the minimal and maximal digits in the decimal representation of x without leading zeroes. For examples refer ...
```python ans = [] for h in range(int(input())): a, k = map(int, input().strip().split()) temp = a a = str(a) for i in range(k-1): maxi = int(max(a)); mini = int(min(a)) a = str(temp + maxi*mini) if '0' in a: break temp = int(a) ans.append(a) print('...
vfc_80925
{ "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\n1 4\n487 1\n487 2\n487 3\n487 4\n487 5\n487 6\n487 7\n", "output": "42\n487\n519\n528\n544\n564\n588\n628\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 333\n", "output": "5...
code_contests
verifiable_code
1374_F. Cyclic Shifts Sorting
Solve the following coding problem using the programming language python: You are given an array a consisting of n integers. In one move, you can choose some index i (1 ≤ i ≤ n - 2) and shift the segment [a_i, a_{i + 1}, a_{i + 2}] cyclically to the right (i.e. replace the segment [a_i, a_{i + 1}, a_{i + 2}] with [a_...
```python def swap(i): tmp = a[i+2] a[i+2] = a[i+1] a[i+1] = a[i] a[i] = tmp ans.append(i+1) #print (*a) tt = int(input()) for loop in range(tt): n = int(input()) a = list(map(int,input().split())) sa = 0.0001 lis = [sa] * 501 b1 = [] b2 = [] f2 ...
vfc_80929
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5\n1 2 3 4 5\n5\n5 4 3 2 1\n8\n8 4 5 2 3 6 7 3\n7\n5 2 1 6 4 7 3\n6\n1 2 3 3 6 4\n", "output": "0\n\n6\n3 1 3 2 2 3 \n13\n2 1 1 6 4 2 4 3 3 4 4 6 6 \n-1\n4\n3 3 4 4 \n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
1421_D. Hexagons
Solve the following coding problem using the programming language python: Lindsey Buckingham told Stevie Nicks ["Go your own way"](https://www.youtube.com/watch?v=6ul-cZyuYq4). Nicks is now sad and wants to go away as quickly as possible, but she lives in a 2D hexagonal world. Consider a hexagonal tiling of the plane...
```python import sys input=sys.stdin.buffer.readline #FOR READING PURE INTEGER INPUTS (space separation ok) #import sys #input=lambda: sys.stdin.readline().rstrip("\r\n") #FOR READING STRING/TEXT INPUTS. def oneLineArrayPrint(arr): print(' '.join([str(x) for x in arr])) def multiLineArrayPrint(arr): print('\n'....
vfc_80937
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n-3 1\n1 3 5 7 9 11\n1000000000 1000000000\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n", "output": "18\n1000000000000000000\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
143_C. Help Farmer
Solve the following coding problem using the programming language python: Once upon a time in the Kingdom of Far Far Away lived Sam the Farmer. Sam had a cow named Dawn and he was deeply attached to her. Sam would spend the whole summer stocking hay to feed Dawn in winter. Sam scythed hay and put it into haystack. As ...
```python from math import sqrt p, n = [], int(input()) def f(x, y): return (x + 2) * (y + 2) + (2 * (x + y + 2) * n) // (x * y) for x in range(2, int(sqrt(n)) + 1): if n % x == 0: p.append(x) p += [n // x for x in reversed(p)] p.append(n) u = v = f(1, 1) for m in p: for x in range(1, int(sqrt(m)) + 1)...
vfc_80941
{ "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\n", "output": "47 65\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "28 41\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\...
code_contests
verifiable_code
1466_H. Finding satisfactory solutions
Solve the following coding problem using the programming language python: Getting so far in this contest is not an easy feat. By solving all the previous problems, you have impressed the gods greatly. Thus, they decided to spare you the story for this problem and grant a formal statement instead. Consider n agents. E...
vfc_80945
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 1024000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 1 3 4\n", "output": "\n27408\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1\n", "output": "\n1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1540_D. Inverse Inversions
Solve the following coding problem using the programming language python: You were playing with permutation p of length n, but you lost it in Blair, Alabama! Luckily, you remember some information about the permutation. More specifically, you remember an array b of length n, where b_i is the number of indices j such ...
vfc_80957
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0 0 0\n7\n2 1\n2 2\n2 3\n1 2 1\n2 1\n2 2\n2 3\n", "output": "1 2 3 2 1 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 1 2 3 4\n15\n2 1\n2 2\n1 2 1\n2 2\n2 3\n2 5\n1 3 0\n1 4 0\...
code_contests
verifiable_code
168_C. Wizards and Trolleybuses
Solve the following coding problem using the programming language python: In some country live wizards. They love to ride trolleybuses. A city in this country has a trolleybus depot with n trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a dista...
```python # written with help of passed solutions from math import sqrt n, a, d = map(int, input().split()) a = float(a) ans = [0] * n tm = 0 for i in range(n): t, v = map(int, input().split()) acc_t = v / a add_t = 0 if acc_t ** 2 * a > 2 * d: add_t = sqrt(2 * d / a) else: add_t ...
vfc_80961
{ "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 10 10000\n0 10\n5 11\n1000 1\n", "output": "1000.500000000\n1000.500000000\n11000.050000000\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
189_A. Cut Ribbon
Solve the following coding problem using the programming language python: Polycarpus has a ribbon, its length is n. He wants to cut the ribbon in a way that fulfils the following two conditions: * After the cutting each ribbon piece should have length a, b or c. * After the cutting the number of ribbon pieces s...
```python from math import *; lineup=[int(x) for x in input().split()] a,b,c=sorted(lineup[1:4]) n=lineup[0] value=0 if a==1: print(n) exit() for i in range(0,n+1,a): for j in range(0,n+1,b): z=(n-i-j)/c if ceil(z)==floor(z) and int(z)>=0: x=i//a y=j//b z=int(z) value=max(value,x+y+z) print(int(value...
vfc_80965
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5 3 2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 5 5 2\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
212_A. Privatization
Solve the following coding problem using the programming language python: There is a developed network of flights between Berland and Beerland. All of them belong to the Berland state company BerAvia. Each flight connects some Berland city with some Beerland city. For each flight airplanes fly in both directions. Cha...
vfc_80969
{ "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 5 8 2\n1 4\n1 3\n3 3\n1 2\n1 1\n2 1\n1 5\n2 2\n", "output": "4\n1 2 1 1 2 1 1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 1 1\n1 1\n", "output": "0\n1 ", "type": "st...
code_contests
verifiable_code
236_A. Boy or Girl
Solve the following coding problem using the programming language python: Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they...
```python for _ in range(1): x=set(list(input())) if len(x)%2==0: print('CHAT WITH HER!') else: print("IGNORE HIM!") ```
vfc_80973
{ "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": "xiaodao\n", "output": "IGNORE HIM!\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "sevenkplus\n", "output": "CHAT WITH HER!\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
260_D. Black and White Tree
Solve the following coding problem using the programming language python: The board has got a painted tree graph, consisting of n nodes. Let us remind you that a non-directed graph is called a tree if it is connected and doesn't contain any cycles. Each node of the graph is painted black or white in such a manner tha...
```python n = int(input()) white, black = [], [] for i in range(n): color, weightSum = map(int, input().split()) if color == 0: white.append([weightSum, i+1]) else : black.append([weightSum, i+1]) #white.sort() #black.sort() wc,bc, wl, bl, edges = 0 , 0, len(white), len(black), [] while...
vfc_80977
{ "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": "6\n1 0\n0 3\n1 8\n0 2\n0 3\n0 0\n", "output": "6 1 0\n4 1 0\n4 3 2\n2 3 3\n5 3 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 3\n1 2\n0 5\n", "output": "3 2 2\n3 1 3\n", ...
code_contests
verifiable_code
284_D. Cow Program
Solve the following coding problem using the programming language python: Farmer John has just given the cows a program to play with! The program contains two integer variables, x and y, and performs the following operations on a sequence a1, a2, ..., an of positive integers: 1. Initially, x = 1 and y = 0. If, afte...
```python from sys import stdin,stdout def dfs(): visit, stack = {(0, 0)}, [] cur, su, ix, ext = 1, a[0], a[0], 0 while ix > -1 and ix < n: if mem[ix][cur]: if mem[ix][cur] != -1: ext = mem[ix][cur] else: su = -1 break v...
vfc_80981
{ "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\n1 2\n", "output": "-1\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 4 1\n", "output": "3\n6\n8\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
309_D. Tennis Rackets
Solve the following coding problem using the programming language python: Professional sport is more than hard work. It also is the equipment, designed by top engineers. As an example, let's take tennis. Not only should you be in great shape, you also need an excellent racket! In this problem your task is to contribut...
vfc_80985
{ "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 0\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 0\n", "output": "24\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
355_B. Vasya and Public Transport
Solve the following coding problem using the programming language python: Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m. Public tra...
```python c1,c2,c3 ,c4 = map(int,input().split()) n , m = map(int, input().split()) a = [int(x) for x in input().split()] b = [int(x) for x in input().split()] ans1 = 0 ans2 = 0 for i in a: ans1 += min(c1 * i,c2) ans1 = min(ans1, c3) for i in b: ans2 += min(c1 * i,c2) ans2 = min(ans2, c3) ans = min(ans1 + ans2,...
vfc_80993
{ "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 3 2 1\n1 3\n798\n1 2 3\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 100 8 100\n3 5\n7 94 12\n100 1 47 0 42\n", "output": "16", "type": "stdin_stdout" ...
code_contests
verifiable_code
379_C. New Year Ratings Change
Solve the following coding problem using the programming language python: One very well-known internet resource site (let's call it X) has come up with a New Year adventure. Specifically, they decided to give ratings to all visitors. There are n users on the site, for each user we know the rating value he wants to ge...
```python n = int(input()) x = list(map(int, input().split())) ans = x.copy() b = sorted(x.copy()) k = b[0] + 1 d = {b[0]: [1, b[0]]} for i in range(1, n): if b[i - 1] == b[i]: d[b[i]].append(k) k += 1 else: if b[i] < k: d[b[i]] = [1, k] else: d[b[i]] = [1...
vfc_80997
{ "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\n1000000000\n", "output": "1000000000 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
39_J. Spelling Check
Solve the following coding problem using the programming language python: Petya has noticed that when he types using a keyboard, he often presses extra buttons and adds extra letters to the words. Of course, the spell-checking system underlines the words for him and he has to click every word and choose the right vari...
```python s,t=input(),input() n=idx=len(t) for i in range(n): if s[i]!=t[i]: idx=i break for i in range(idx+1,n+1): if s[i]!=t[i-1]: print(0) import sys sys.exit() i=idx while i>0 and s[i-1]==s[idx]: i-=1 print(idx-i+1) print(' '.join(map(str,range(i+1,idx+2)))) ```
vfc_81001
{ "difficulty": "16", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "competition\ncodeforces\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abdrakadabra\nabrakadabra\n", "output": "1\n3 ", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
426_A. Sereja and Mugs
Solve the following coding problem using the programming language python: Sereja showed an interesting game to his friends. The game goes like that. Initially, there is a table with an empty cup and n water mugs on it. Then all players take turns to move. During a move, a player takes a non-empty mug of water and pour...
```python n, s = map(int, input().split()) arr = list(map(int, input().split())) print("NO" if sum(arr) - max(arr) > s else "YES") ```
vfc_81005
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n1 1 1\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n3 1 3\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
470_H. Array Sorting
Solve the following coding problem using the programming language python: Sorting arrays is traditionally associated with high-level languages. How hard can it be in FALSE? Sort the given array in non-descending order. Input The input consists of a single line of space-separated integers. The first number is n (1 ≤ ...
vfc_81013
{ "difficulty": "14", "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 1 2\n", "output": "1 2 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 12 2 3 44 5 60 2\n", "output": "2 2 3 5 12 44 60 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
495_A. Digital Counter
Solve the following coding problem using the programming language python: Malek lives in an apartment block with 100 floors numbered from 0 to 99. The apartment has an elevator with a digital counter showing the floor that the elevator is currently on. The elevator shows each digit of a number with 7 light sticks by t...
```python from sys import stdin def nb_good_numbers(n): by_digit = { "0": 2, "1": 7, "2": 2, "3": 3, "4": 3, "5": 4, "6": 2, "7": 5, "8": 1, "9": 2, } result = 1 for digit in n: result *= by_digit[digit] return...
vfc_81017
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "00\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "89\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "73\n", ...
code_contests
verifiable_code
545_E. Paths and Trees
Solve the following coding problem using the programming language python: Little girl Susie accidentally found her elder brother's notebook. She has many things to do, more important than solving problems, but she found this problem too interesting, so she wanted to know its solution and decided to ask you about it. S...
```python import heapq n, m = map(int, input().split()) g = [[] for _ in range(n + 1)] for i in range(1, m + 1): u, v, w = map(int, input().split()) g[u].append((i, v, w)) g[v].append((i, u, w)) src = int(input()) pq = [(0, 0, src, -1)] mk = [0] * (n + 1) t = [] s = 0 while pq: d, w, u, e = heapq.heap...
vfc_81025
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1 2 1\n2 3 1\n1 3 2\n3\n", "output": "2\n1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 2 1\n2 3 1\n3 4 1\n4 1 2\n4\n", "output": "4\n4 2 3 ", "type": "stdin_st...
code_contests
verifiable_code
572_B. Order Book
Solve the following coding problem using the programming language python: In this task you need to process a set of stock exchange orders and use them to create order book. An order is an instruction of some participant to buy or sell stocks on stock exchange. The order number i has price pi, direction di — buy or se...
```python n,s = [int(x) for x in input().split()] buy_dict = {} sell_dict = {} for i in range(n): chtype,pi,di = input().split() pi = int(pi) di = int(di) if chtype=='B': buy_dict[pi] = buy_dict.get(pi,0)+di else: sell_dict[pi] = sell_dict.get(pi,0)+di buy_list = sorted(buy_dict.items(),reverse=True)[:s] sell_...
vfc_81029
{ "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\nB 10 3\nS 50 2\nS 40 1\nS 50 6\nB 20 4\nB 25 10\n", "output": "S 50 8\nS 40 1\nB 25 10\nB 20 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\nS 1 1\nB 0 2\n", "output": "S...
code_contests
verifiable_code
593_E. Strange Calculation and Cats
Solve the following coding problem using the programming language python: Gosha's universe is a table consisting of n rows and m columns. Both the rows and columns are numbered with consecutive integers starting with 1. We will use (r, c) to denote a cell located in the row r and column c. Gosha is often invited some...
vfc_81033
{ "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 3\n2 2 2 2\n1 3 3 5\n1 3 3 7\n", "output": "2\n42\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
615_C. Running Track
Solve the following coding problem using the programming language python: A boy named Ayrat lives on planet AMI-1511. Each inhabitant of this planet has a talent. Specifically, Ayrat loves running, moreover, just running is not enough for him. He is dreaming of making running a real art. First, he wants to construct ...
```python def find_max_substr(t, s): l, r = 0, len(t) while l != r: m = (l + r) // 2 if t[:m + 1] in s: l = m + 1 else: r = m l1 = l rs = s[::-1] l, r = 0, len(t) while l != r: m = (l + r) // 2 if t[:m + 1] in rs: l = m ...
vfc_81037
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ami\nno\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abc\ncbaabc\n", "output": "2\n3 1\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
634_E. Preorder Test
Solve the following coding problem using the programming language python: For his computer science class, Jacob builds a model tree with sticks and balls containing n nodes in the shape of a tree. Jacob has spent ai minutes building the i-th ball in the tree. Jacob's teacher will evaluate his model and grade Jacob ba...
```python import sys input = sys.stdin.readline n, k = map(int, input().split()) a = [int(i) for i in input().split()] g = [[] for _ in range(n)] for i in range(n - 1): u, v = map(int, input().split()) g[u-1].append(v-1) g[v-1].append(u-1) stack = [0] done = [False] * n par = [0] * n order = [] while len(stack) > 0...
vfc_81041
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 7, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n1 5 5 5\n1 2\n1 3\n1 4\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n3 6 1 4 2\n1 2\n2 4\n2 5\n1 3\n", "output": "3", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
663_C. Graph Coloring
Solve the following coding problem using the programming language python: You are given an undirected graph that consists of n vertices and m edges. Initially, each edge is colored either red or blue. Each turn a player picks a single vertex and switches the color of all edges incident to it. That is, all red edges wi...
```python n, e = map(int, raw_input().strip().split()) adj1 = [[] for i in xrange(n)] adj2 = [[] for i in xrange(n)] for i in xrange(e): a, b, c = raw_input().strip().split() a = int(a) - 1 b = int(b) - 1 if c == 'B': adj1[a].append((b, 0)) adj1[b].append((a, 0)) adj2[a].append(...
vfc_81045
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 5\n1 3 R\n2 3 R\n3 4 B\n4 5 R\n4 6 R\n", "output": "2\n3 4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 2 B\n3 1 R\n3 2 B\n", "output": "1\n2 \n", "type": "stdin_s...
code_contests
verifiable_code
688_A. Opponents
Solve the following coding problem using the programming language python: Arya has n opponents in the school. Each day he will fight with all opponents who are present this day. His opponents have some fighting plan that guarantees they will win, but implementing this plan requires presence of them all. That means if ...
```python import math from typing import Iterable, List def solve(arr:Iterable[str], n: int) -> int: curr = 0 res = 0 for v in arr: if v == '1'*n: curr = 0 else : curr += 1 res = max(res , curr) return res def main(): n,d = map(int, input().split(' ')) arr = [] ...
vfc_81049
{ "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 5\n1101\n1111\n0110\n1011\n1111\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n10\n00\n", "output": "2", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
70_E. Information Reform
Solve the following coding problem using the programming language python: Thought it is already the XXI century, the Mass Media isn't very popular in Walrusland. The cities get news from messengers who can only travel along roads. The network of roads in Walrusland is built so that it is possible to get to any city fr...
vfc_81053
{ "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": "8 10\n2 5 9 11 15 19 20\n1 4\n1 3\n1 7\n4 6\n2 8\n2 3\n3 5\n", "output": "38\n1 2 1 1 1 1 1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 10\n1 4 7 11 13\n4 6\n3 4\n3 5\n1 2\n2 4\n", ...
code_contests
verifiable_code
730_L. Expression Queries
Solve the following coding problem using the programming language python: A simplified arithmetic expression (SAE) is an arithmetic expression defined by the following grammar: * <SAE> ::= <Number> | <SAE>+<SAE> | <SAE>*<SAE> | (<SAE>) * <Number> ::= <Digit> | <Digit><Number> * <Digit> ::= 0 | 1 | 2 | 3 | 4 | 5...
vfc_81057
{ "difficulty": "19", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "(01)\n1\n1 4\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "((1+2)*3+101*2)\n6\n8 14\n1 6\n2 10\n11 14\n5 5\n4 5\n", "output": "205\n-1\n10\n2\n2\n-1\n", "typ...
code_contests
verifiable_code
755_B. PolandBall and Game
Solve the following coding problem using the programming language python: PolandBall is playing a game with EnemyBall. The rules are simple. Players have to say words in turns. You cannot say a word which was already said. PolandBall starts. The Ball which can't say a new word loses. You're given two lists of words f...
```python import sys input = sys.stdin.readline n, m = input().split() n = int(n) m = int(m) polW = [] eneW = [] turnsP = 0 turnsE = 0 same = 0 for i in range(n): polW.append(input()) turnsP+=1 for i in range(m): word = input() if word in polW: turnsP-=1 same+=1 else: ...
vfc_81061
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\nkremowka\nwadowicka\nkremowka\nwiedenska\n", "output": "YES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
776_C. Molly's Chemicals
Solve the following coding problem using the programming language python: Molly Hooper has n different kinds of chemicals arranged in a line. Each of the chemicals has an affection value, The i-th of them has affection value ai. Molly wants Sherlock to fall in love with her. She intends to do this by mixing a contigu...
```python from sys import stdin n,k = [int(x) for x in stdin.readline().split()] arr = [int(x) for x in stdin.readline().split()] sums = [0] for x in arr: sums.append(sums[-1]+x) powers = [1] base = 1 if k != 1 and k != -1: while abs(base) <= 10**14: base *= k powers.append(base) if k == -1: powers.ap...
vfc_81065
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n2 2 2 2\n", "output": " 8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 -3\n3 -6 -3 12\n", "output": "3\n", ...
code_contests
verifiable_code
7_D. Palindrome Degree
Solve the following coding problem using the programming language python: String s of length n is called k-palindrome, if it is a palindrome itself, and its prefix and suffix of length <image> are (k - 1)-palindromes. By definition, any string (even empty) is 0-palindrome. Let's call the palindrome degree of string s...
```python T = raw_input() P = T + '#' + T[::-1] def compute_prefix_func(P): m = len(P) pi = [0] * m for q in range(1, m): k = pi[q-1] while k > 0 and P[k] != P[q]: k = pi[k-1] if P[k] == P[q]: k += 1 pi[q] = k return pi pi = compute_prefix_func...
vfc_81069
{ "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": "abacaba\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "a2A\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "z\n...