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
22_E. Scheme
Solve the following coding problem using the programming language python: To learn as soon as possible the latest news about their favourite fundamentally new operating system, BolgenOS community from Nizhni Tagil decided to develop a scheme. According to this scheme a community member, who is the first to learn the n...
```python import sys n = int(input()) g = [int(i) - 1 for i in sys.stdin.readline().split()] def solve(n, g): vertex_id = [-1]*n current_id = 0 cycle_starts = [] cycle_starts_by_vertex = [-1]*n cycle_vertex_sample = [] start_on_cycle = [] cycle_index_by_ID = [] for v in range(n): ...
vfc_48913
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 3 2\n", "output": "1\n2 1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
255_D. Mr. Bender and Square
Solve the following coding problem using the programming language python: Mr. Bender has a digital table of size n × n, each cell can be switched on or off. He wants the field to have at least c switched on squares. When this condition is fulfilled, Mr Bender will be happy. We'll consider the table rows numbered from...
```python import sys ii = lambda: sys.stdin.readline().strip() idata = lambda: [int(x) for x in ii().split()] sdata = lambda: list(ii()) def solve(): n, x, y, c = idata() r = n ** 2 l = -1 while l + 1 < r: middle = (l + r) // 2 ans = 1 + 2 * (middle + 1) * middle ans -= pow(midd...
vfc_48917
{ "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": "9 3 8 10\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4 3 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
279_D. The Minimum Number of Variables
Solve the following coding problem using the programming language python: You've got a positive integer sequence a1, a2, ..., an. All numbers in the sequence are distinct. Let's fix the set of variables b1, b2, ..., bm. Initially each variable bi (1 ≤ i ≤ m) contains the value of zero. Consider the following sequence,...
```python def Solve(x,B): if((X,x,B) in Mem): return Mem[(X,x,B)] if(len(B)>X): return False if(x==len(L)): return True if(Form(L[x],B)): A=list(B) for e in range(len(B)): r=A[e] A[e]=L[x] if(Solve(x+1,tuple(sorted(A)))): ...
vfc_48921
{ "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\n1 2 3 6 8\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 6 5\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
301_C. Yaroslav and Algorithm
Solve the following coding problem using the programming language python: Yaroslav likes algorithms. We'll describe one of his favorite algorithms. 1. The algorithm receives a string as the input. We denote this input string as a. 2. The algorithm consists of some number of command. Сommand number i looks either...
```python print ( """0??<>1 1??<>2 2??<>3 3??<>4 4??<>5 5??<>6 6??<>7 7??<>8 8??<>9 9??>>??0 ??<>1 ?0>>0? ?1>>1? ?2>>2? ?3>>3? ?4>>4? ?5>>5? ?6>>6? ?7>>7? ?8>>8? ?9>>9? ?>>?? >>?""" ) ```
vfc_48925
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10\n79\n", "output": "0??<>1\n1??<>2\n2??<>3\n3??<>4\n4??<>5\n5??<>6\n6??<>7\n7??<>8\n8??<>9\n9??>>??0\n??<>1\n?0>>0?\n?1>>1?\n?2>>2?\n?3>>3?\n?4>>4?\n?5>>5?\n?6>>6?\n?7>>7?\n?8>>8?\n?9>>9?\n?>>??\n>>?", "type": "std...
code_contests
verifiable_code
328_A. IQ Test
Solve the following coding problem using the programming language python: Petya is preparing for IQ test and he has noticed that there many problems like: you are given a sequence, find the next number. Now Petya can solve only problems with arithmetic or geometric progressions. Arithmetic progression is a sequence a...
```python import sys fin = sys.stdin a = list(map(int, fin.readline().split())) d = a[1] - a[0] if a[2] - a[1] == a[3] - a[2] == d: print(a[3] + d) else: d = a[1] / a[0] if a[2] / a[1] == a[3] / a[2] == d and d * a[3] == int(d * a[3]): print(int(d * a[3])) else: print(42) ```
vfc_48929
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 334 667 1000\n", "output": "1333", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
34_B. Sale
Solve the following coding problem using the programming language python: Once Bob got to a sale of old TV sets. There were n TV sets at that sale. TV set with index i costs ai bellars. Some TV sets have a negative price — their owners are ready to pay Bob if he buys their useless apparatus. Bob can «buy» any TV sets ...
```python n, m = map(int, input().split()) a = list(map(int, input().split())) a.sort() ans = 0 for i in range(len(a)): if a[i] < 0: ans += a[i] m -= 1 if m == 0: break print(-1 * ans) ```
vfc_48933
{ "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 2\n7 0 0 -7\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n-6 0 35 -2 4\n", "output": "8\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
373_C. Counting Kangaroos is Fun
Solve the following coding problem using the programming language python: There are n kangaroos with pockets. Each kangaroo has a size (integer number). A kangaroo can go into another kangaroo's pocket if and only if the size of kangaroo who hold the kangaroo is at least twice as large as the size of kangaroo who is h...
```python #------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt'...
vfc_48937
{ "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": "8\n9\n1\n6\n2\n6\n5\n8\n3\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n2\n5\n7\n6\n9\n8\n4\n2\n", "output": "5\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
394_E. Lightbulb for Minister
Solve the following coding problem using the programming language python: The Minister for education is coming! Naturally, nobody wants to perform poorly in front of such a honored guest. However, two hours before the arrival it turned out that one of the classes has a malfunctioning lightbulb — for some reason it doe...
vfc_48941
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 2\n3 4\n5 4\n5 2\n4\n3 3\n4 4\n5 3\n4 2\n", "output": "8.000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n-24 27\n-77 8\n10\n-99 5\n-16 98\n61 78\n79 61\n100 0\n20 -97\n18...
code_contests
verifiable_code
418_A. Football
Solve the following coding problem using the programming language python: One day, at the "Russian Code Cup" event it was decided to play football as an out of competition event. All participants was divided into n teams and played several matches, two teams could not play against each other more than once. The appoi...
```python n,k=map(int,input().split()) a=n*(n-1)//2 if(n*k>a): print(-1) else: print(n*k) for i in range(1,n+1): for j in range(k): print(i,(i+j)%n+1) ```
vfc_48945
{ "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 1\n", "output": "3\n1 2\n2 3\n3 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11 6\n", "output": "-1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
444_D. DZY Loves Strings
Solve the following coding problem using the programming language python: DZY loves strings, and he enjoys collecting them. In China, many people like to use strings containing their names' initials, for example: xyz, jcvb, dzy, dyh. Once DZY found a lucky string s. A lot of pairs of good friends came to DZY when th...
vfc_48949
{ "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": "abcabd\n3\na c\nab abc\nab d\n", "output": "2\n3\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "xudyhduxyz\n3\nxyz xyz\ndyh xyz\ndzy xyz\n", "output": "3\n8\n-1\n", "type":...
code_contests
verifiable_code
48_C. The Race
Solve the following coding problem using the programming language python: Every year a race takes place on the motorway between cities A and B. This year Vanya decided to take part in the race and drive his own car that has been around and bears its own noble name — The Huff-puffer. So, Vasya leaves city A on the Huf...
```python eps=10**(-9) mn=10 mx=100000000 n=int(input()) arr=list(map(int,input().split())) for i in range(n): mn = max(mn,(arr[i]*10)/(i+1)) mx = min(mx,((arr[i]+1)*10)/(i+1)) ans1=((n+1)*mn)//10 ans2=((n+1)*(mx-eps))//10 if ans2>ans1: print('not unique') else: print('unique') print(int(ans1)) ...
vfc_48957
{ "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\n1 2 4\n", "output": "unique\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2\n", "output": "not unique\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
513_E2. Subarray Cuts
Solve the following coding problem using the programming language python: You are given an array of length n and a number k. Let's pick k non-overlapping non-empty subarrays of the initial array. Let si be the sum of the i-th subarray in order from left to right. Compute the maximum value of the following expression: ...
vfc_48961
{ "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": "4 2\n7 4 3 7\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3\n5 2 4 3 1\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
53_A. Autocomplete
Solve the following coding problem using the programming language python: Autocomplete is a program function that enables inputting the text (in editors, command line shells, browsers etc.) completing the text by its inputted part. Vasya is busy working on a new browser called 'BERowser'. He happens to be working on t...
```python s = input() l = len(s) n = int(input()) u = [] for i in range(n): a = input() #print('Taken input', a,len(a),l) if a[:l] == s: if len(u) == 0: u.append(a if len(a) == l else a[l:]) elif len(a) == l: u = [a] + u else: j = 0 k = 0 while True: if u[k] == s: if k < len(u) - 1: ...
vfc_48965
{ "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": "find\n4\nfondfind\nfondfirstof\nfondit\nfand\n", "output": "find\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "next\n2\nnextpermutation\nnextelement\n", "output": "nextelement\n", ...
code_contests
verifiable_code
567_C. Geometric Progression
Solve the following coding problem using the programming language python: Polycarp loves geometric progressions very much. Since he was only three years old, he loves only the progressions of length three. He also has a favorite integer k and a sequence a, consisting of n integers. He wants to know how many subsequen...
```python import sys, os, io def rs(): return sys.stdin.readline().rstrip() def ri(): return int(sys.stdin.readline()) def ria(): return list(map(int, sys.stdin.readline().split())) def ws(s): sys.stdout.write(s + '\n') def wi(n): sys.stdout.write(str(n) + '\n') def wia(a): sys.stdout.write(' '.join([str(x) for x in a]...
vfc_48969
{ "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": "10 3\n1 2 6 2 3 6 9 18 3 9\n", "output": "6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
588_E. Duff in the Army
Solve the following coding problem using the programming language python: Recently Duff has been a soldier in the army. Malek is her commander. Their country, Andarz Gu has n cities (numbered from 1 to n) and n - 1 bidirectional roads. Each road connects two different cities. There exist a unique path between any two...
vfc_48973
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4 5\n1 3\n1 2\n1 4\n4 5\n2 1 4 3\n4 5 6\n1 5 2\n5 5 10\n2 3 3\n5 3 1\n", "output": "1 3\n2 2 3\n0\n3 1 2 4\n1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1\n1\n1 1 3\n", ...
code_contests
verifiable_code
610_B. Vika and Squares
Solve the following coding problem using the programming language python: Vika has n jars with paints of distinct colors. All the jars are numbered from 1 to n and the i-th jar contains ai liters of paint of color i. Vika also has an infinitely long rectangular piece of paper of width 1, consisting of squares of size...
```python import itertools import math n = int(input()) a = [int(x) for x in input().split()] amin = min(a) b = list(filter(lambda x: x[1] == amin, enumerate(a))) l = len(b) k = max((b[(i+1) % l][0] - b[i][0] - 1)%n for i in range(l)) print(amin*n + k) ```
vfc_48977
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 4 2 3 3\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 5 5\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
630_L. Cracking the Code
Solve the following coding problem using the programming language python: The protection of a popular program developed by one of IT City companies is organized the following way. After installation it outputs a random five digit number which should be sent in SMS to a particular phone number. In response an SMS activ...
```python #Nearly Lucky ''' a=list(map(str,input())) l=0 for i in range(len(a)): if(a[i]=='4' or a[i]=='7'): l+=1 if(l==4 or l==7 or l==44 or l==47 or l==74 or l==77): print("YES") else: print("NO")''' #IQ Test ''' a=int(input()) b=list(map(int,input().strip().split())) e,o=[],[] for i in range(len(...
vfc_48981
{ "difficulty": "19", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "12345\n", "output": "71232\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "91537\n", "output": "27651\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
659_D. Bicycle Race
Solve the following coding problem using the programming language python: Maria participates in a bicycle race. The speedway takes place on the shores of Lake Lucerne, just repeating its contour. As you know, the lake shore consists only of straight sections, directed to the north, south, east or west. Let's introdu...
```python read = lambda: map(int, input().split()) vect = lambda a, b: a[0] * b[1] - a[1] * b[0] vector = lambda A, B: (B[0] - A[0], B[1] - A[1]) n = int(input()) p = [tuple(read()) for i in range(n)] cnt = 0 for i in range(2, n): v1 = vector(p[i], p[i - 1]) v2 = vector(p[i - 1], p[i - 2]) if vect(v1, v2...
vfc_48985
{ "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": "16\n1 1\n1 5\n3 5\n3 7\n2 7\n2 9\n6 9\n6 7\n5 7\n5 3\n4 3\n4 4\n3 4\n3 2\n5 2\n5 1\n1 1\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n0 0\n0 1\n1 1\n1 2\n2 2\n2 0\n0 ...
code_contests
verifiable_code
682_A. Alyona and Numbers
Solve the following coding problem using the programming language python: After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to ...
```python from math import ceil,floor n,m = map(int, input().split()) res = 0 for i in range(1,n+1): req = 5 - i%5 res += ((m-req) // 5) +1 print(res) ```
vfc_48989
{ "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 7\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 5\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "21 21\n...
code_contests
verifiable_code
704_E. Iron Man
Solve the following coding problem using the programming language python: Tony Stark is playing a game with his suits (they have auto-pilot now). He lives in Malibu. Malibu has n junctions numbered from 1 to n, connected with n - 1 roads. One can get from a junction to any other junction using these roads (graph of Ma...
vfc_48993
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4\n2 5\n6 5\n3 6\n4 6\n4 1\n27 6 1 3\n9 5 1 6\n27 4 3 4\n11 29 2 6\n", "output": "27.3000000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4\n3 1\n4 5\n6 4\n6 1\n2 6\n16 4 4 5\n13 2...
code_contests
verifiable_code
727_C. Guess the Array
Solve the following coding problem using the programming language python: This is an interactive problem. You should use flush operation after each printed line. For example, in C++ you should use fflush(stdout), in Java you should use System.out.flush(), and in Pascal — flush(output). In this problem you should gues...
vfc_48997
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n \n9\n \n7\n \n9\n \n11\n \n6\n ", "output": "? 1 2\n? 1 3\n? 2 3\n? 1 4\n? 1 5\n! 0 0 0 0 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "35\n4 2 2 2 4 4 3 2 4 2 2 4 2 2 3 2 3 4 4 2 ...
code_contests
verifiable_code
748_D. Santa Claus and a Palindrome
Solve the following coding problem using the programming language python: Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to congratulate him, and each of them presented to him a string si having the same length n. We denote the beauty of the i-th string by ai. It...
```python import sys import math def solve(): k, n = map(int, input().split()) D = {} for line in sys.stdin: s, a = line.split() if s in D: D[s].append(int(a)) else: D[s] = [int(a)] res = 0 center = 0 for s in D: revs = s[::-1] if...
vfc_49001
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 3\nabb 2\naaa -3\nbba -1\nzyz -4\nabb 5\naaa 7\nxyx 4\n", "output": "12\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
816_D. Karen and Test
Solve the following coding problem using the programming language python: Karen has just arrived at school, and she has a math test today! <image> The test is about basic addition and subtraction. Unfortunately, the teachers were too busy writing tasks for Codeforces rounds, and had no time to make an actual test. S...
```python n = int(input()) p = list(map(int,input().split())) MOD = 10**9+7 mode = 0 if n%4 == 3: n-= 1 new = [] for i in range(n): if mode == 0: new.append(p[i]+p[i+1]) else: new.append(p[i]-p[i+1]) mode = 1-mode p = new def calc0(p): res = 0 ncr = 1 n = len(p)//2-...
vfc_49013
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 7 5 2\n", "output": "1000000006", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3 6 9 12 15\n", "output": "36", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
841_D. Leha and another game about graph
Solve the following coding problem using the programming language python: Leha plays a computer game, where is on each level is given a connected graph with n vertices and m edges. Graph can contain multiple edges, but can not contain self loops. Each vertex has an integer di, which can be equal to 0, 1 or - 1. To pa...
```python import os,io input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline import sys import heapq INF=10**9 def Dijkstra(graph, start,m): dist=[INF]*len(graph) parent=[INF]*len(graph) queue=[(0, start)] while queue: path_len, v=heapq.heappop(queue) if dist[v]==INF: dist[v]=path_len fo...
vfc_49017
{ "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": "1 0\n1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n0 -1 1\n1 2\n2 3\n1 3\n", "output": "1\n2\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
862_E. Mahmoud and Ehab and the function
Solve the following coding problem using the programming language python: Dr. Evil is interested in math and functions, so he gave Mahmoud and Ehab array a of length n and array b of length m. He introduced a function f(j) which is defined for integers j, which satisfy 0 ≤ j ≤ m - n. Suppose, ci = ai - bi + j. Then f(...
```python from bisect import * f = lambda: list(map(int, input().split())) n, m, q = f() k = m - n + 1 a = f() s = sum(a[0:n:2]) - sum(a[1:n:2]) b = [0] + f() for i in range(2, m + 1, 2): b[i] = -b[i] for i in range(m): b[i + 1] += b[i] u = [b[j] - b[j + n] for j in range(1, k, 2)] v = [b[j + n] - b[j] for j in ran...
vfc_49021
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 6 3\n1 2 3 4 5\n1 2 3 4 5 6\n1 1 10\n1 1 -9\n1 5 -1\n", "output": "0\n9\n0\n0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
911_A. Nearest Minimums
Solve the following coding problem using the programming language python: You are given an array of n integer numbers a0, a1, ..., an - 1. Find the distance between two closest (nearest) minimums in it. It is guaranteed that in the array a minimum occurs at least two times. Input The first line contains positive int...
```python from sys import maxsize n = int(input()) arr = list(map(int,input().split())) m = maxsize res= maxsize ind = [] for i in range(len(arr)): if arr[i] < m: m = arr[i] ind = [i] res=maxsize elif arr[i] == m: ind.append(i) if ind[-1]-ind[-2] < res and len(ind) > 1: ...
vfc_49029
{ "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": "2\n3 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n2 1 3 5 4 1 2 3 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
932_F. Escape Through Leaf
Solve the following coding problem using the programming language python: You are given a tree with n nodes (numbered from 1 to n) rooted at node 1. Also, each node has two values associated with it. The values for i-th node are ai and bi. You can jump from a node to any node in its subtree. The cost of one jump from...
vfc_49033
{ "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": "4\n5 -10 5 7\n-8 -80 -3 -10\n2 1\n2 4\n1 3\n", "output": "-300 100 0 0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 10 -1\n7 -7 5\n2 3\n2 1\n", "output": "10 50 0 ", "ty...
code_contests
verifiable_code
95_A. Hockey
Solve the following coding problem using the programming language python: Petya loves hockey very much. One day, as he was watching a hockey match, he fell asleep. Petya dreamt of being appointed to change a hockey team's name. Thus, Petya was given the original team name w and the collection of forbidden substrings s...
```python n = int(input()) a = [] for i in range(n): a.append(input().rstrip()) w = list(input().rstrip()) c = input().rstrip() m = len(w) z = [] i = 0 while i < m: for j in range(n): if w[i].lower() == a[j][0].lower(): if i + len(a[j]) <= m: f = 1 for k in ra...
vfc_49037
{ "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": "2\naCa\ncba\nabAcaba\nc\n", "output": "abCacba\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
akashs-girlfriend
Solve the following coding problem using the programming language python: Akash singh is a student of Mathematics at Geekland University. These days he is busy with his girlfriend Jassi. On the other hand, Jassi don't like mathematics that much. One day, Jassi decided to find all the strings of length N (comprising on...
```python modulo=(10**9)+9 t=input() for i in range(t): a=input() print((pow(10,a,modulo)-pow(8,a,modulo))*pow(2,modulo-2,modulo))%modulo ```
vfc_49045
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n2\n\nSAMPLE", "output": "1\n18\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4000\n740948\n2\n551\n1152761423221685\n618927954312\n3411\n874277931986\n286024865090\n613893446066184...
code_contests
verifiable_code
broken-amit
Solve the following coding problem using the programming language python: It has been truly said that love is not meant for everyone. Let me introduce you to a very sad story of my friend Broken Amit. Yes several times he has been left heartbroken. Looking at his poor condition even God is pity on him. God has given ...
```python n=input() love=map(int,raw_input().split()) decr=map(int,raw_input().split()) for i in range(len(decr)): decr[i]*=i decr.sort() decr.reverse() tDecr=[0]*n for i in range(len(decr)): cDecr=0 tDec=0 for j in range(i): tDec+=cDecr cDecr+=decr[i] tDecr[i]=tDec+(n-i)*cDecr su=sum(love)*n-sum(tDecr) print ...
vfc_49049
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 4\n1 2\n\nSAMPLE", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n538 29108 5606 27262 6813 27707 20066 27675 10965 14760 \n1338 2767 2817 2255 2088 3969 795 1296 1...
code_contests
verifiable_code
darshit-bday
Solve the following coding problem using the programming language python: Darshit is planning to celebrate the birthday of his friend, Diksha. There are two types of gifts that Diksha wants from Darshit: one is black and the other is white. To make her happy, Darshit has to buy B number of black gifts and W number of ...
```python for tc in xrange(input()): b,w=tuple(map(int,raw_input().split())) x,y,z=tuple(map(int,raw_input().split())) cost=0 if x<y+z: cost+=b*x else: cost+=b*(y+z) if y<x+z: cost+=w*y else: cost+=w*(x+z) print(cost)# your code goes here ```
vfc_49053
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n10 10\n1 1 1\n5 9\n2 3 4\n3 6\n9 1 1\n7 7\n4 2 1\n3 3\n1 9 2\n\nSAMPLE", "output": "20\n37\n12\n35\n12\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
game-of-coins
Solve the following coding problem using the programming language python: Alice and Bob are playing a game of coins. N coins are placed on the table in a row. The game begins with Alice and afterwards they alternate the moves. A valid move is defined as follows: You pick one coin or two adjacent coins and remove t...
```python t = int(raw_input()) for i in range(0,t): coins = int(raw_input()) print "Alice" ```
vfc_49057
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n3\n\nSAMPLE", "output": "Alice\nAlice\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n4681\n6322\n5915\n3351\n5313\n8391\n4844\n7131\n6658\n6796\n7534\n6751\n8850\n3440\n605\n37...
code_contests
verifiable_code
karan-and-prime-numbers
Solve the following coding problem using the programming language python: Karan's mathematics professor has given him a lots of homework. Since he is busy preparing for September Easy Challenge, he needs your help. Given two numbers, find the sum of prime numbers between them, both inclusive. Input: The first line...
```python import math def is_prime(n): for i in range(2, int(math.sqrt(n))+1): if n % i == 0: n = 0 break return n t = int(raw_input()) for i in range(0, t): s = raw_input() s = s.split() sum = 0 if int(s[1]) < 2: sum = 0 if int(s[0]) < 2: s[...
vfc_49061
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1 5\n\nSAMPLE", "output": "10\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
missing-soldiers-december-easy-easy
Solve the following coding problem using the programming language python: An infinite army of ants is marching on an infinite 2-D plane. Since ants are disciplined, here's how they march: each ant chooses exactly one x coordinate and moves along it in positive y direction, starting from (x, 0). There exists exactly on...
```python n = int(raw_input()) l = [] for _ in range(n): x,y,d = map(int,raw_input().split()) l.append((x,d)) l.sort(key=lambda x: x[0]) start,d = l.pop(0) sum = d+1 last = start + d for start,d in l: if start > last: sum += d+1 last = start + d elif start <= last and start+d > last: sum += start + d - last ...
vfc_49065
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 1 4\n7 3 5\n\nSAMPLE", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1 4\n7 3 5", "output": "11\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
panda-and-chain-reaction
Solve the following coding problem using the programming language python: Panda has become a scientist recently. In his laboratory, there are infinite number of chambers where a chamber number K is connected to a chamber number K-1. The numbering of chambers start from 0. Initially, X number of particles are presen...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' mx, mod = 1000013, 1000003 arr = [0]*mx arr[0] = 1 for i in xrange(1, mx): arr[i] = i * arr[i-1] arr[i] %= mod tc = int(raw_input()) while tc>0: tc = t...
vfc_49069
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 3\n2 1\n\nSAMPLE", "output": "3\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 3\n2 1\n\nSAMPLD", "output": "3\n2\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
robots
Solve the following coding problem using the programming language python: Oz and nakul have N robots, and they want to assign a distinct integer to each robot so that they can easily identify them. Also robots have already expressed their preferences to Oz and nakul. The k-th robot wants an integer between 1 and MAX[k...
```python import collections import math def numberOfWaysToMark(): N=int(raw_input()) maxList=[int(v) for v in raw_input().strip().split()] maxList.sort() ways=1 for x in range(N): if maxList[x]<x+1: return 0 else: ways*=(maxList[x]-x) return ways%1000000...
vfc_49073
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n6\n2\n5 8\n\nSAMPLE", "output": "6\n35\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n6\n2\n10 8\n\nSAMPLE", "output": "6\n72\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
state-bank-of-patiala-atm
Solve the following coding problem using the programming language python: The ATM machine of State Bank of Patiala on Thapar Campus has a flaw in it and it takes a lot of time to complete a transaction. This machine is quite different from other's as it needed no card. Only thing it required is customer's unique ATM P...
```python def check(a,l): for i in range(0, l-1): x = len(a[i]) j = i+1 if(len(a[j])>=x and a[i]==a[j][0:(x)]): return 1 return 0 t=int(raw_input()) while(t>0): t = t - 1 n = int(raw_input()) a = [] while(n>0): n -= 1 a.append(raw_input()) a.sort() if check(a,len(a))==1: print('NO') else: ...
vfc_49077
{ "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\n102\n1024\n123477\n3\n102\n1034\n123477\n\nSAMPLE", "output": "NO\nYES", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
two-arrays-and-minimum
Solve the following coding problem using the programming language python: You are given two arrays each with N elements. Elements of each arrays follow a particular generator dependent on factors a,b and c . You have to choose on element from both the arrays such that if you chose i^th element from one array and j^th ...
```python a, b, c = map(int, raw_input().split()) n = int(raw_input()) aa = (a*b*c + a*b + a*c) % 1000000007 bb = (a*b*c + a*b + b*c) % 1000000007 p = a*c ma1 ,ma2 = p, 1000000007 ia1 = ia2 = 0 for i in xrange(1, n): C = p * aa % 1000000007 if C < ma2: if C < ma1: ma2 = ma1 ia2 ...
vfc_49081
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 1\n3\n\nSAMPLE", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6 9\n10", "output": "22410\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p00006 Reverse Sequence
Solve the following coding problem using the programming language python: Write a program which reverses a given string str. Input str (the size of str ≤ 20) is given in a line. Output Print the reversed str in a line. Example Input w32nimda Output admin23w The input will be given via stdin and the output...
```python st = input() print(st[::-1]) ```
vfc_49125
{ "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": "w32nimda", "output": "admin23w", "type": "stdin_stdout" }, { "fn_name": null, "input": "w32njmda", "output": "admjn23w\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p00271 Temperature Difference
Solve the following coding problem using the programming language python: Welcome to PC Koshien, players. Physical condition management is important to participate in the event. It is said that at the turn of the season when the temperature fluctuates greatly, it puts a strain on the body and it is easy to catch a col...
```python c = 0 while c <= 6: a, b = map(int,input().split()) c = c + 1 print(a - b) ```
vfc_49133
{ "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": "30 19\n39 20\n19 18\n25 20\n22 21\n23 10\n10 -10", "output": "11\n19\n1\n5\n1\n13\n20", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00459 Shuffle
Solve the following coding problem using the programming language python: problem There are n cards with numbers from 1 to n. First, make a pile of cards by stacking them in order so that the top is the number 1 card, the second from the top is the number 2 card, ..., and the bottom is the number n card. <image> ...
vfc_49137
{ "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": "9\n1\n3 7 4\n3 5\n12\n3\n3 8 5\n3 8\n2 5\n6 10\n0", "output": "2\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n1\n3 7 4\n4 5\n12\n3\n3 8 5\n3 8\n2 5\n6 10\n0", "output": "2\n3\...
code_contests
verifiable_code
p00649 Yanagi's Comic
Solve the following coding problem using the programming language python: Yanagi is a high school student, and she is called "Hime" by her boyfriend who is a ninja fanboy. She likes picture books very much, so she often writes picture books by herself. She always asks you to make her picture book as an assistant. Toda...
vfc_49141
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 0 100 60\n0 60 50 90\n50 60 100 90\n0 90 100 120\n6\n0 0 100 40\n0 40 50 70\n50 40 100 60\n50 60 100 80\n0 70 50 120\n50 80 100 120\n0", "output": "1\n2\n3\n4\n\n1\n2\n4\n5\n3\n6", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
p00793 Heavenly Jewels
Solve the following coding problem using the programming language python: There is a flat island whose shape is a perfect square. On this island, there are three habitants whose names are IC, PC, and ACM Every day, one jewel is dropped from the heaven. Just as the jewel touches the ground, IC, PC, and ACM leave their ...
vfc_49145
{ "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": "2000 2000 8000 8000 9000 9500\n2500 2500 7500 2500 2500 7500\n0 0 0 0 0 0", "output": "1 0.50000\n2 0.25000", "type": "stdin_stdout" }, { "fn_name": null, "input": "2000 2252 8000 8000 9000 9500\n250...
code_contests
verifiable_code
p00925 Miscalculation
Solve the following coding problem using the programming language python: Example Input 1+2*3+4 11 Output M 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 s,ans=input(),int(input()) x=int(s[0]) for i in range(1,len(s),2): y=int(s[i+1]) x=x*y if s[i]=='*' else x+y print("IMLU"[int(eval(s)==ans)+(int(x==ans)<<1)]) ```
vfc_49149
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1+2*3+4\n11", "output": "M", "type": "stdin_stdout" }, { "fn_name": null, "input": "1+2*3+4\n9", "output": "I\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01058 Point in The Triangle
Solve the following coding problem using the programming language python: Problem Select 3 grid points from the closed rectangular section surrounded by points (0,0), (n-1,0), (0, m-1), (n-1, m-1) and make a triangle. make. At this time, the absolute difference between the number of triangles containing the point (x1...
vfc_49153
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 267386880, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 0 0 0 1", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 1 0 0 0", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
p01190 Reading Brackets in English
Solve the following coding problem using the programming language python: Shun and his professor are studying Lisp and S-expressions. Shun is in Tokyo in order to make a presen- tation of their research. His professor cannot go with him because of another work today. He was making final checks for his slides an hour ...
vfc_49157
{ "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": "4\na list of A, B, C and D\na list of A, a list of P and Q, B, a list of X, Y and Z and C\na list of A\na list of a list of A and B", "output": "(A B C D)\n(A (P Q) B (X Y Z) C)\n(A)\nAMBIGUOUS", "type": "stdin_stdout" ...
code_contests
verifiable_code
p01495 SolveMe
Solve the following coding problem using the programming language python: Example Input 3 1 0 1 Output 18 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
vfc_49165
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1 0 1", "output": "18", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 0 1", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2...
code_contests
verifiable_code
p01663 N and K
Solve the following coding problem using the programming language python: H --N and K Consider a narrowly-sense monotonically increasing sequence of integers greater than or equal to 1 and N, in which no matter which two different numbers are taken from the elements of the sequence, the other does not divide one. Let...
vfc_49169
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 2\n5 2\n8 3\n10 1\n18 12", "output": "3\n3\n5\n4\n-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3 2\n4 2\n8 3\n10 1\n18 12", "output": "3\n3\n5\n4\n-1\n", "type": "s...
code_contests
verifiable_code
p01808 Kuru Kuru Door
Solve the following coding problem using the programming language python: Kuru Kuru Door Round and round door The ICPC (Intelligent Circular Perfect Cleaner), a fully automatic circular vacuum cleaner developed by ACM (Automatic Cleaning Machine) in 2011, has a function to automatically start during the day and clea...
vfc_49173
{ "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\n1 4\n-5 5\n5 -5\n10\n1 10\n-10 5\n5 -10\n5\n3 5\n-20 0\n20 0\n8\n1 9\n-14 58\n6 24\n2\n2 8\n-57 -113\n42 -31\n4\n1 4\n-4 -5\n4 5\n0", "output": "17.5032106371\n41.3850388846\n-1\n102.0656847372\n178.1399151364\n19.55487168...
code_contests
verifiable_code
p02092 Red Black Balloons
Solve the following coding problem using the programming language python: E: Red Black Balloons Story Homura-chan's dream comes true. It means ICPC Asia regional contest 20xx will be held in Sapporo! Homura-chan has been working hard for the preparation. And finally, it's the previous day of the contest. Homura-chan...
vfc_49181
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n6 5 4\n8 1\n7 1", "output": "3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02224 3 Player Co-op Game
Solve the following coding problem using the programming language python: This is a reactive problem. Problem statement There are $ 200 $ non-negative integers of $ 1000 $ bits, $ a_1, \ ldots, a_ {100}, b_1, \ ldots, b_ {100} $. Alice confirms $ a_1, \ ldots, a_ {100} $ and leaves a note $ X $ for $ 3000 $ bits fo...
vfc_49185
{ "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": "", "output": "", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02376 Maximum Flow
Solve the following coding problem using the programming language python: A flow network is a directed graph which has a $source$ and a $sink$. In a flow network, each edge $(u, v)$ has a capacity $c(u, v)$. Each edge receives a flow, but the amount of flow on the edge can not exceed the corresponding capacity. Find t...
```python # Acceptance of input import sys file_input = sys.stdin V, E = map(int, file_input.readline().split()) adj_mat = [[0] * V for i in range(V)] for line in file_input: u, v, c = map(int, line.split()) adj_mat[u][v] = c # Ford???Fulkerson algorithm import collections # BFS for residual capacity ne...
vfc_49189
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5\n0 1 2\n0 2 1\n1 2 1\n1 3 1\n2 3 2", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n0 1 2\n0 2 1\n1 2 1\n1 3 1\n2 3 2", "output": "0\n", "type": "stdin_std...
code_contests
verifiable_code
amifib
Solve the following coding problem using the programming language python: The Head Chef has been playing with Fibonacci numbers for long . He has learnt several tricks related to Fibonacci numbers . Now he wants to test his chefs in the skills . A fibonacci number is defined by the recurrence : f(n) = f(n-1) + f(n-2)...
```python import sys arr=sys.stdin.read().split() N=int(arr[0]) nos=[] nos1=[] k=0 for i in range(0,N): k+=1 nos.append(int(arr[k])) nos1.append(int(arr[k])) nos1.sort() def bin_search(arr,start,end,x): mid=(start+end)/2 if(end<start): return -1 if(arr[mid]==x): return mid if(arr[mid]>x): return bin_s...
vfc_49193
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n4\n5", "output": "YES\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3\n4\n3", "output": "YES\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
chefzot
Solve the following coding problem using the programming language python: Chef loves research! Now he is looking for subarray of maximal length with non-zero product. Chef has an array A with N elements: A1, A2, ..., AN. Subarray Aij of array A is elements from index i to index j: Ai, Ai+1, ..., Aj. Product of subar...
```python n=input() s=map(int,raw_input().split()) l=j=0 a=[0]*n for i in s: if i==0: l=0 else: l+=1 a[j]=l j+=1 print max(a) ```
vfc_49197
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n0", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 0 2 3 0 4", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
dumpling
Solve the following coding problem using the programming language python: Chef Shifu and Chef Po are participating in the Greatest Dumpling Fight of 2012. Of course, Masterchef Oogway has formed the rules of the fight. There is a long horizontal rope of infinite length with a center point P. Initially both Chef Shif...
```python import fractions import sys tc = int(raw_input()) f = fractions.gcd while tc: tc-=1 a,b,c,d,k = map(int,sys.stdin.readline().split()) g1 = f(a,b) g2 = f(c,d) lcm = (g1*g2)/f(g1,g2) mx = k/lcm print 2*mx+1 ```
vfc_49201
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 4 3 6 7\n1 2 4 5 1\n10 12 3 9 16", "output": "3\n3\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 4 3 11 7\n1 2 4 5 1\n10 12 3 9 16", "output": "7\n3\n5\n", "type...
code_contests
verifiable_code
kgood
Solve the following coding problem using the programming language python: Chef Al Gorithm was reading a book about climate and oceans when he encountered the word “glaciological”. He thought it was quite curious, because it has the following interesting property: For every two letters in the word, if the first appears...
```python #top down dp # def function(b,i,j,matrix): # if i>=j: # return 0 # if b[j]-b[i]<=k: # return 0 # if matrix[i][j]!=-1: # return matrix[i][j] # #matrix[i][j]=min(b[i]+matrix[i+1][j],matrix[i][j-1]+b[j]-b[i]-k) # m1=b[i]+function(b,i+1,j,matrix) # m2=b[j]-b[i]-k+function(b,i,j-1,matrix) # matrix[i][...
vfc_49205
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nglaciological 1\nteammate 0\npossessions 3\ndefenselessness 3", "output": "0\n0\n1\n2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
ojumps
Solve the following coding problem using the programming language python: This morning Chef wants to jump a little. In a few minutes he will arrive at the point 0. Then he will perform a lot of jumps in such a sequence: 1-jump, 2-jump, 3-jump, 1-jump, 2-jump, 3-jump, 1-jump, and so on. 1-jump means that if Chef is at ...
```python t=(int)(raw_input()) k=t//3 if((t%3==0)|((t%3==1)&(k%2==0))): print 'yes' else: print 'no' ```
vfc_49209
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2", "output": "no\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0", "output": "yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "o...
code_contests
verifiable_code
snon07
Solve the following coding problem using the programming language python: Starting at the top left corner of an N*M grid and facing towards the right, you keep walking one square at a time in the direction you are facing. If you reach the boundary of the grid or if the next square you are about to visit has already be...
```python # cook your code here T = int(raw_input()) for i in range(T): (n,m) = map(int,raw_input().split()) if n<m: if n%2==0: print "L" else: print "R" elif m<n: if m%2==0: print "U" else: print "D" else: if n%2==0...
vfc_49213
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1\n2 2\n3 1\n3 3", "output": "R\nL\nD\nR", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1005_D. Polycarp and Div 3
Solve the following coding problem using the programming language python: Polycarp likes numbers that are divisible by 3. He has a huge number s. Polycarp wants to cut from it the maximum number of numbers that are divisible by 3. To do this, he makes an arbitrary number of vertical cuts between pairs of adjacent dig...
```python n = input() buf = 0 c = 0 m = 0 for i in range(len(n)): buf += int(n[i]) m += 1 if int(n[i]) % 3 == 0 or buf % 3 == 0 or m >= 3: buf = 0 c += 1 m = 0 print(c) ```
vfc_49217
{ "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": "201920181\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3121\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
1029_B. Creating the Contest
Solve the following coding problem using the programming language python: You are given a problemset consisting of n problems. The difficulty of the i-th problem is a_i. It is guaranteed that all difficulties are distinct and are given in the increasing order. You have to assemble the contest which consists of some p...
```python n=int(input()) a=list(map(int,input().split())) b=[] for _ in range(n-1): if a[_+1]<=a[_]*2: b.append(1) else: b.append(0) b.append(1); s=0; c=[] for i in range(n): if b[i]==1: s+=1 c.append(s) else: s=0 if c[len(c)-1]==max(c) and c.count(max(c))==1: ...
vfc_49221
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 10 50 110 250\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
104_A. Blackjack
Solve the following coding problem using the programming language python: One rainy gloomy evening when all modules hid in the nearby cafes to drink hot energetic cocktails, the Hexadecimal virus decided to fly over the Mainframe to look for a Great Idea. And she has found one! Why not make her own Codeforces, with b...
```python n=int(input()) if n<11 or n>21: print(0) elif n==20: print(15) else: print(4) ```
vfc_49225
{ "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": "12\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n", ...
code_contests
verifiable_code
1071_B. Minimum path
Solve the following coding problem using the programming language python: You are given a matrix of size n × n filled with lowercase English letters. You can change no more than k letters in this matrix. Consider all paths from the upper left corner to the lower right corner that move from a cell to its neighboring c...
```python def solve(m, matrix, good, n): c = 'z' for x in range(n): y = m - x if y < 0 or y >= n: continue if not good[x][y]: continue if x < n - 1: c = min(c, matrix[x + 1][y]) if y < n - 1: c = min(c, matrix[x][y + 1]) for x in range(n): y = m - x if...
vfc_49229
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\nabcd\nbcde\nbcad\nbcde\n", "output": "aaabcde\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 6\nypnxnnp\npnxonpm\nnxanpou\nxnnpmud\nnhtdudu\nnpmuduh\npmutsnz\n", "output": "a...
code_contests
verifiable_code
1093_D. Beautiful Graph
Solve the following coding problem using the programming language python: You are given an undirected unweighted graph consisting of n vertices and m edges. You have to write a number on each vertex of the graph. Each number should be 1, 2 or 3. The graph becomes beautiful if for each edge the sum of numbers on verti...
```python from collections import deque from sys import stdin, stdout input = stdin.readline saida = [] t = int(input()) modulo = 998244353 for _ in range(t): ans = 1 part = 0 factor = 0 fila = deque([]) n, m = map(int, input().split()) if m > (n // 2) * ( n // 2 + 1): saida.append(...
vfc_49233
{ "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\n2 1\n1 2\n4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "output": "4\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\n8 7\n2 3\n3 4\n4 5\n5 2\n6 7\n7 8\n8 6\n1 0\n2 1\n1 2\n3 3\n1 2\n2 3\...
code_contests
verifiable_code
1113_D. Sasha and One More Name
Solve the following coding problem using the programming language python: Reading books is one of Sasha's passions. Once while he was reading one book, he became acquainted with an unusual character. The character told about himself like that: "Many are my names in many countries. Mithrandir among the Elves, Tharkûn t...
```python s=input() if len(set(s[:len(s)//2]))<=1: print("Impossible");exit() for i in range(1,len(s)): n=s[i:]+s[:i] if(n==n[::-1])and(n!=s): print(1);exit() print(2) ```
vfc_49237
{ "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": "nolon\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "kinnikkinnik\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
1141_F2. Same Sum Blocks (Hard)
Solve the following coding problem using the programming language python: This problem is given in two editions, which differ exclusively in the constraints on the number n. You are given an array of integers a[1], a[2], ..., a[n]. A block is a sequence of contiguous (consecutive) elements a[l], a[l+1], ..., a[r] (1 ...
```python n=int(input()) a=list(map(int,input().split())) dic={} for i in range(n): sm=0 for j in range(i,n): sm+=a[j] if sm in dic: dic[sm].append((i,j)) else: dic[sm]=[(i,j)] ans=0 anskey=-1 for key in dic: cnt=0 last=-1 for a,b in sorted(dic[key]): ...
vfc_49241
{ "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": "7\n4 1 2 2 1 5 3\n", "output": "3\n2 3\n4 5\n7 7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1 1 1\n", "output": "4\n1 1\n2 2\n3 3\n4 4\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1162_A. Zoning Restrictions Again
Solve the following coding problem using the programming language python: You are planning to build housing on a street. There are n spots available on the street on which you can build a house. The spots are labeled from 1 to n from left to right. In each spot, you can build a house with an integer height between 0 a...
```python n, h, m = map(int, input().split()) houses = [h] * n for i in range(m): tmp = list(map(int, input().split())) for j in range(tmp[0]-1, tmp[1]): if tmp[2] <= houses[j]: houses[j] = tmp[2] total = 0 for i in houses: total += i*i print(total) ```
vfc_49245
{ "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 3 3\n1 1 1\n2 2 3\n3 3 2\n", "output": "14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 10 2\n2 3 8\n3 4 7\n", "output": "262\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1182_F. Maximum Sine
Solve the following coding problem using the programming language python: You have given integers a, b, p, and q. Let f(x) = abs(sin(p/q π x)). Find minimum possible integer x that maximizes f(x) where a ≤ x ≤ b. Input Each test contains multiple test cases. The first line contains the number of test cases t (1 ≤...
vfc_49249
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n0 3 1 3\n17 86 389 995\n", "output": "1\n55\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 10000000 1 1000000000\n", "output": "10000000\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1200_A. Hotelier
Solve the following coding problem using the programming language python: Amugae has a hotel consisting of 10 rooms. The rooms are numbered from 0 to 9 from left to right. The hotel has two entrances — one from the left end, and another from the right end. When a customer arrives to the hotel through the left entranc...
```python input() l = [0]*10 s = input() for i in range(len(s)): e = s[i] if e == 'L': l[l.index(0)] = 1 elif e == 'R': l[len(l) - l[::-1].index(0) - 1] = 1 else: l[int(e)] = 0 print(*l, sep = '') ```
vfc_49253
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\nL0L0LLRR9\n", "output": "1100000010\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\nLLRL1RL1\n", "output": "1010000011\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
1218_C. Jumping Transformers
Solve the following coding problem using the programming language python: You, the mighty Blackout, are standing in the upper-left (0,0) corner of NxM matrix. You must move either right or down each second. There are K transformers jumping around the matrix in the following way. Each transformer starts jumping from ...
vfc_49257
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 128000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 5\n0 1 1 0 7\n1 1 1 0 10\n1 1 1 1 2\n1 1 1 2 2\n0 1 1 2 3\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5 6\n0 2 2 2 3\n1 2 2 3 4\n0 3 1 2 1\n0 1 1 0 6\n0 2 1 0 6\...
code_contests
verifiable_code
1240_F. Football
Solve the following coding problem using the programming language python: There are n football teams in the world. The Main Football Organization (MFO) wants to host at most m games. MFO wants the i-th game to be played between the teams a_i and b_i in one of the k stadiums. Let s_{ij} be the numbers of games the ...
```python import random import math def set_color(game, color): color_count[game[0]][game[2]] -= 1 color_count[game[1]][game[2]] -= 1 game[2] = color color_count[game[0]][game[2]] += 1 color_count[game[1]][game[2]] += 1 def fix(node): minimum = math.inf maximum = 0 for i in range(k): ...
vfc_49261
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 11 3\n4 7 8 10 10 9 3\n6 2\n6 1\n7 6\n4 3\n4 6\n3 1\n5 3\n7 5\n7 3\n4 2\n1 4\n", "output": "1\n2\n1\n1\n2\n1\n2\n2\n3\n3\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 11 3\n4 7 8 ...
code_contests
verifiable_code
1261_A. Messy
Solve the following coding problem using the programming language python: You are fed up with your messy room, so you decided to clean it up. Your room is a bracket sequence s=s_{1}s_{2}... s_{n} of length n. Each character of this string is either an opening bracket '(' or a closing bracket ')'. In one operation yo...
```python import os, sys, math def solve(seq, k): seq = [ 1 if a == '(' else -1 for a in seq ] size = len(seq) result = [] def rotate(fr, to): assert fr <= to result.append((fr + 1, to + 1)) while fr < to: seq[fr], seq[to] = seq[to], seq[fr] fr += 1 to -= 1 # print(''.join('(' if q > 0 else ')' f...
vfc_49265
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n8 2\n()(())()\n10 3\n))()()()((\n2 1\n()\n2 1\n)(\n", "output": "1\n5 7\n5\n1 3\n3 5\n5 7\n6 9\n7 10\n0\n1\n1 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n8 2\n()(())()\n10 3\n)...
code_contests
verifiable_code
1283_B. Candies Division
Solve the following coding problem using the programming language python: Santa has n candies and he wants to gift them to k kids. He wants to divide as many candies as possible between all k kids. Santa can't divide one candy into parts but he is allowed to not use some candies at all. Suppose the kid who recieves t...
```python n = int(input()) k = [] d = [] r = [] m = [] dk = [] h = 0 z = [] for i in range(n): a = list(map(int,input().split())) k.append(a[0]) d.append(a[1]) r.append(a[0] // a[1]) h += r[i] * a[1] m.append(a[0]-((a[0] // a[1])*a[1])) if (a[1]//2 == m[i]): h += m[i] elif (a[1]/...
vfc_49269
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5 2\n19 4\n12 7\n6 2\n100000 50010\n", "output": "5\n18\n10\n6\n75015\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1233212 4\n", "output": "1233212\n", "type": "stdin_...
code_contests
verifiable_code
1326_F2. Wise Men (Hard Version)
Solve the following coding problem using the programming language python: This is the hard version of the problem. The difference is constraints on the number of wise men and the time limit. You can make hacks only if all versions of this task are solved. n wise men live in a beautiful city. Some of them know each ot...
vfc_49277
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n011\n101\n110\n", "output": "0 0 0 6 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0101\n1000\n0001\n1010\n", "output": "2 2 6 2 2 6 2 2 \n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1346_A. Color Revolution
Solve the following coding problem using the programming language python: Hmm, how long has it been since the last color revolution? 5 years?! It's totally the time to make a new one! So the general idea is the following. Division 1 should have n_1 participants. Division 2 should have n_2 and be exactly k times bigge...
vfc_49281
{ "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\n40 3\n1200 7\n320802005 400\n4 1\n", "output": "\n1 3 9 27\n3 21 147 1029\n5 2000 800000 320000000\n1 1 1 1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1367_F1. Flying Sort (Easy Version)
Solve the following coding problem using the programming language python: This is an easy version of the problem. In this version, all numbers in the given array are distinct and the constraints on n are less than in the hard version of the problem. You are given an array a of n integers (there are no equals elements...
```python t=int(input()) for you in range(t): n=int(input()) l=input().split() li=[int(i) for i in l] z=list(li) z.sort() hashi=dict() for i in range(n): hashi[z[i]]=i+1 for i in range(n): li[i]=hashi[li[i]] hashi=dict() dp=[0 for i in range(n)] for i in range...
vfc_49285
{ "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": "4\n5\n4 7 2 3 9\n5\n3 5 8 1 7\n5\n1 4 5 7 12\n4\n0 2 1 3\n", "output": "2\n2\n0\n2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1389_A. LCM Problem
Solve the following coding problem using the programming language python: Let LCM(x, y) be the minimum positive integer that is divisible by both x and y. For example, LCM(13, 37) = 481, LCM(9, 6) = 18. You are given two integers l and r. Find two integers x and y such that l ≤ x < y ≤ r and l ≤ LCM(x, y) ≤ r. Input...
```python T=int(input()) for _ in range(T): l,r=map(int,input().split()) if abs(l-r)==1 and l!=1: print(-1,-1) elif 2*l>r : print(-1,-1) else: print(l,2*l) ```
vfc_49289
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1337\n13 69\n2 4\n88 89\n", "output": "1 2\n13 26\n2 4\n-1 -1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n80000000 160000000\n", "output": "80000000 160000000\n", "...
code_contests
verifiable_code
1409_D. Decrease the Sum of Digits
Solve the following coding problem using the programming language python: You are given a positive integer n. In one move, you can increase n by one (i.e. make n := n + 1). Your task is to find the minimum number of moves you need to perform in order to make the sum of digits of n be less than or equal to s. You have...
```python for _ in range(int(input())): n,k=[int(x) for x in input().split()] if n%k==0:print(0) else:print(k-(n%k)) ```
vfc_49293
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 1\n1 1\n500 4\n217871987498122 10\n100000000000000001 1\n", "output": "0\n0\n0\n8\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n9987 1\n", "output": "0\n", "type":...
code_contests
verifiable_code
1430_B. Barrels
Solve the following coding problem using the programming language python: You have n barrels lined up in a row, numbered from left to right from one. Initially, the i-th barrel contains a_i liters of water. You can pour water from one barrel to another. In one act of pouring, you can choose two different barrels x an...
```python def solve(): n,k=map(int,input().split()) if n==1: print(0) return ls=list(map(int,input().split())) ls.sort() res=ls.pop() for i in range(k): if ls: res+=ls.pop() print(res) return for _ in range(int(input())): solve() ```
vfc_49297
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 1\n5 5 5 5\n3 2\n0 0 0\n", "output": "10\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4 2\n5 5 5 5\n3 2\n0 0 0\n", "output": "15\n0\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1453_D. Checkpoints
Solve the following coding problem using the programming language python: Gildong is developing a game consisting of n stages numbered from 1 to n. The player starts the game from the 1-st stage and should beat the stages in increasing order of the stage number. The player wins the game after beating the n-th stage. ...
```python t=int(input()) for _ in range(t): n=int(input()) if n%2==1: print(-1) continue ans=[] tmp=0 for i in range(2,62): if 1<<i&n: ans.append('1') for j in range(i-2): ans.append('0') tmp+=1 for i in range(tmp): ans.append('1') if 2&n: ans.append('1') pr...
vfc_49301
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n2\n8\n12\n", "output": "\n-1\n1\n1\n4\n1 1 1 1\n5\n1 1 0 1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "50\n1000000\n1000002\n1000004\n1000006\n1000008\n1000010\n1000012\n100001...
code_contests
verifiable_code
1477_B. Nezzar and Binary String
Solve the following coding problem using the programming language python: Nezzar has a binary string s of length n that he wants to share with his best friend, Nanako. Nanako will spend q days inspecting the binary string. At the same time, Nezzar wants to change the string s into string f during these q days, because...
```python import os import sys from io import BytesIO, IOBase # region fastio BUFSIZE = 8192 class FastIO(IOBase): def __init__(self, file): self.newlines = 0 self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in file.mode self.write ...
vfc_49305
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 2\n00000\n00111\n1 5\n1 3\n2 1\n00\n01\n1 2\n10 6\n1111111111\n0110001110\n1 10\n5 9\n7 10\n1 7\n3 5\n6 10\n5 2\n10000\n11000\n2 5\n1 3\n", "output": "\nYES\nNO\nYES\nNO\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1503_F. Balance the Cards
Solve the following coding problem using the programming language python: A balanced bracket sequence is defined as an integer sequence that can be built with the following rules: * The empty sequence is balanced. * If [a_1,…,a_n] and [b_1,…, b_m] are balanced, then their concatenation [a_1,…,a_n,b_1,…,b_m] is b...
vfc_49309
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 1\n-1 2\n2 -1\n-2 -2\n", "output": "\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 3\n-3 -5\n4 -3\n2 2\n-1 -4\n-2 5\n3 -1\n5 1\n-4 4\n-5 -2\n", "output": "\nYES\n1 3\...
code_contests
verifiable_code
1527_D. MEX Tree
Solve the following coding problem using the programming language python: You are given a tree with n nodes, numerated from 0 to n-1. For each k between 0 and n, inclusive, you have to count the number of unordered pairs (u,v), u ≠ v, such that the MEX of all the node labels in the shortest path from u to v (including...
```python import sys, math import io, os #data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline #from bisect import bisect_left as bl, bisect_right as br, insort #from heapq import heapify, heappush, heappop from collections import defaultdict as dd, deque, Counter #from itertools import permutations,combinations ...
vfc_49313
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n0 1\n0 2\n2 3\n2\n1 0\n", "output": "\n1 2 1 1 1 \n0 0 1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4\n0 1\n1 2\n2 3\n2\n1 0\n", "output": "3 0 1 1 1\n0 0 1\n", ...
code_contests
verifiable_code
159_C. String Manipulation 1.0
Solve the following coding problem using the programming language python: One popular website developed an unusual username editing procedure. One can change the username only by deleting some characters from it: to change the current name s, a user can pick number p and character c and delete the p-th occurrence of c...
```python # cook your dish here n=int(input()) s=list(input())*n d={} for i in range(len(s)): if s[i] not in d: d[s[i]]=[i] else: d[s[i]].append(i) m=int(input()) for i in range(m): o,c=input().split() s[d[c].pop(int(o)-1)]='' print(''.join(s)) ```
vfc_49317
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nbac\n3\n2 a\n1 b\n2 c\n", "output": "acb\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nabacaba\n4\n1 a\n1 a\n1 c\n2 b\n", "output": "baa\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
201_A. Clear Symmetry
Solve the following coding problem using the programming language python: Consider some square matrix A with side n consisting of zeros and ones. There are n rows numbered from 1 to n from top to bottom and n columns numbered from 1 to n from left to right in this matrix. We'll denote the element of the matrix which i...
```python x=int(input()) n=1 while n*n+1<2*x: n+=2 if x==3: n=5 print(n) ```
vfc_49325
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n", ...
code_contests
verifiable_code
225_E. Unsolvable
Solve the following coding problem using the programming language python: Consider the following equation: <image> where sign [a] represents the integer part of number a. Let's find all integer z (z > 0), for which this equation is unsolvable in positive integers. The phrase "unsolvable in positive integers" means ...
```python print([0,1,3,15,63,4095,65535,262143,73741816,536396503,140130950,487761805,319908070,106681874,373391776,317758023,191994803,416292236,110940209,599412198,383601260,910358878,532737550,348927936,923450985,470083777,642578561,428308066,485739298,419990027,287292016,202484167,389339971,848994100,273206869,8530...
vfc_49329
{ "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\n", "output": " 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": " ...
code_contests
verifiable_code
24_C. Sequence of points
Solve the following coding problem using the programming language python: You are given the following points with integer coordinates on the plane: M0, A0, A1, ..., An - 1, where n is odd number. Now we define the following infinite sequence of points Mi: Mi is symmetric to Mi - 1 according <image> (for every natural ...
```python n, k = map(int, input().split()) ax = [] ay = [] mx, my = map(int, input().split()) for i in range(n): x, y = map(int, input().split()) ax.append(x) ay.append(y) k %= 2*n for i in range(k): mx = 2*ax[i % n] - mx my = 2*ay[i % n] - my print(mx, " ", my) ```
vfc_49333
{ "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 4\n0 0\n1 1\n2 3\n-5 3\n", "output": "14 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n5 5\n1000 1000\n-1000 1000\n3 100\n", "output": "1995 1995\n", "type": "stdin_...
code_contests
verifiable_code
274_D. Lovely Matrix
Solve the following coding problem using the programming language python: Lenny had an n × m matrix of positive integers. He loved the matrix so much, because each row of the matrix was sorted in non-decreasing order. For the same reason he calls such matrices of integers lovely. One day when Lenny was at school his ...
```python n, m = map(int, raw_input().split()) b = [map(int, raw_input().split()) for _ in range(n)] c = [n - x.count(-1) for x in zip(*b)] d = [] for r in b: t = {} for i, x in enumerate(r): if x != -1: if x not in t: t[x] = set() t[x].add(i) d.append([x for i, x in sorted(t.items())][ : : -1]) p = [i f...
vfc_49337
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1 -1 -1\n1 2 1\n2 -1 1\n", "output": "3\n1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n1 2 2\n2 5 4\n", "output": "1\n3\n2\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
298_A. Snow Footprints
Solve the following coding problem using the programming language python: There is a straight snowy road, divided into n blocks. The blocks are numbered from 1 to n from left to right. If one moves from the i-th block to the (i + 1)-th block, he will leave a right footprint on the i-th block. Similarly, if one moves f...
```python arg = int(input()) s2=input() start = -1 ending = -1 flag9 = 0 if "R" in s2: for n in range(0, arg): if s2[n]=="R" and flag9 == 0: start = n + 1 flag9 = 1 if s2[n]== "R" and s2[n+1] == "L": ending = n + 1 elif s2[n] == "R": ending = n + 2 else: for n in range(0, arg): if s2[n]=="L"...
vfc_49341
{ "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": "11\n.RRRLLLLL..\n", "output": "2 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n..RRLL...\n", "output": "3 4\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
320_D. Psychos in a Line
Solve the following coding problem using the programming language python: There are n psychos standing in a line. Each psycho is assigned a unique integer from 1 to n. At each step every psycho who has an id greater than the psycho to his right (if exists) kills his right neighbor in the line. Note that a psycho might...
```python n = int(input()) aa = list(map(int,input().split())) live = [] ans=0 for i in range(n-1,-1,-1): c = 0 while len(live)!=0 and live[-1][0]<aa[i]: c = max(c+1,live[-1][1]) live.pop() if c>ans: ans =c live.append((aa[i],c)) print(ans) ```
vfc_49345
{ "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 2 3 4 5 6\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n10 9 7 8 6 5 3 4 2 1\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
345_D. Chain Letter
Solve the following coding problem using the programming language python: A chain letter is a kind of a message which urges the recipient to forward it to as many contacts as possible, usually with some kind of mystic explanation. Of course, this is only a superstition, and you don't believe in it, but all your friend...
vfc_49349
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0111\n1011\n1101\n1110\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0110\n1010\n1100\n0000\n", "output": "0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
369_A. Valera and Plates
Solve the following coding problem using the programming language python: Valera is a lazy student. He has m clean bowls and k clean plates. Valera has made an eating plan for the next n days. As Valera is lazy, he will eat exactly one dish per day. At that, in order to eat a dish, he needs exactly one clean plate o...
```python class CodeforcesTask369ASolution: def __init__(self): self.result = '' self.n_m_k = [] self.plan = [] def read_input(self): self.n_m_k = [int(x) for x in input().split(" ")] self.plan = [int(x) for x in input().split(" ")] def process_task(self): c...
vfc_49353
{ "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 3 1\n1 1 1 1\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1 2\n2 2 2\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
391_B. Word Folding
Solve the following coding problem using the programming language python: You will receive 5 points for solving this problem. Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part of the string above first part, running...
```python t = {} for i, c in enumerate(input()): if c not in t: t[c] = (i, 1) elif (t[c][0] - i) & 1: t[c] = (i, t[c][1] + 1) print(max(b for a, b in t.values())) ```
vfc_49357
{ "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": "ABBBCBDB\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "ABRACADABRA\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
413_A. Data Recovery
Solve the following coding problem using the programming language python: Not so long ago company R2 bought company R1 and consequently, all its developments in the field of multicore processors. Now the R2 laboratory is testing one of the R1 processors. The testing goes in n steps, at each step the processor gets so...
```python n, m, mmin, mmax = map(int, input().split()) s = list(map(int, input().split())) s = sorted(s) if s[0] < mmin or s[m - 1] > mmax: print("Incorrect") elif s[0] == mmin and s[m - 1] == mmax: print("Correct") elif s[0] != mmin and s[m - 1] != mmax: if n - m < 2: print("Incorrect") else: ...
vfc_49361
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 1 3\n2\n", "output": "Incorrect\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 1 2\n1\n", "output": "Correct\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
43_C. Lucky Tickets
Solve the following coding problem using the programming language python: Vasya thinks that lucky tickets are the tickets whose numbers are divisible by 3. He gathered quite a large collection of such tickets but one day his younger brother Leonid was having a sulk and decided to destroy the collection. First he tore ...
```python n=int(input()) inp = list(map(int,input().split())) l=[0,0,0] for item in inp: l[item%3]+=1 a=l[0] b=l[1] c=l[2] print (min(b,c)+a//2) ```
vfc_49365
{ "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\n123 123 99\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 1 1 23 10 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
461_E. Appleman and a Game
Solve the following coding problem using the programming language python: Appleman and Toastman like games. Today they play a game with strings with the following rules. Firstly Toastman tells Appleman two strings s and t both consisting only of letters 'A', 'B', 'C', 'D'. Then Appleman must build string s as quickly ...
vfc_49369
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nAAABACADBABBBCBDCACBCCCDDDBDCDD\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nABCCAD\n", "output": "5\n", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
485_D. Maximum Value
Solve the following coding problem using the programming language python: You are given a sequence a consisting of n integers. Find the maximum possible value of <image> (integer remainder of ai divided by aj), where 1 ≤ i, j ≤ n and ai ≥ aj. Input The first line contains integer n — the length of the sequence (1 ≤ ...
vfc_49373
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 4 5\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
509_D. Restoring Numbers
Solve the following coding problem using the programming language python: Vasya had two arrays consisting of non-negative integers: a of size n and b of size m. Vasya chose a positive integer k and created an n × m matrix v using the following formula: <image> Vasya wrote down matrix v on a piece of paper and put it...
```python """ Codeforces Contest 289 Div 2 Problem D Author : chaotic_iak Language: Python 3.4.2 """ ################################################### SOLUTION def main(): n,m = read() matrix = [read() for _ in range(n)] mod = 10**11 for i in range(n-1): poss = set() for j in range...
vfc_49377
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n1 2\n2 1\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n1 2\n2 0\n", "output": "YES\n3\n0 1 \n1 2 \n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
533_F. Encoding
Solve the following coding problem using the programming language python: Polycarp invented a new way to encode strings. Let's assume that we have string T, consisting of lowercase English letters. Let's choose several pairs of letters of the English alphabet in such a way that each letter occurs in at most one pair. ...
```python raw_input() ss = raw_input() tt = raw_input() def df(s): c = {} res = [] for i, x in enumerate(s): res.append(i - c[x] if x in c else 0) c[x] = i return res s = df(ss) t = df(tt) p = [] l = [] for i, x in enumerate(t): if not x: p.append(i) l.append(ord(tt...
vfc_49381
{ "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": "21 13\nparaparallelogramgram\nqolorreraglom\n", "output": "1\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11 5\nabacabadaba\nacaba\n", "output": "3\n1 3 7\n", "type": "st...
code_contests
verifiable_code
584_C. Marina and Vasya
Solve the following coding problem using the programming language python: Marina loves strings of the same length and Vasya loves when there is a third string, different from them in exactly t characters. Help Vasya find at least one such string. More formally, you are given two strings s1, s2 of length n and number ...
```python fs = frozenset(list("abc")) def calc(s1, s2): return len(list(filter(lambda x: x[0] == x[1], zip(s1, s2)))) if __name__ == '__main__': n, t = map(int, input().split()) s1 = input() s2 = input() q = n - t c = calc(s1, s2) need = q - c w = 0 ss = ['x'] * len(s1) if n...
vfc_49389
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 0\nc\nb\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\nabc\nxyc\n", "output": "bac\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
606_C. Sorting Railway Cars
Solve the following coding problem using the programming language python: An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In on...
```python def LIS(s): n = len(s) L = [0]*n appear = [False]*n L[0] = 1 find = [-1]*n appear[s[0]] = True find[s[0]] = 0 for i in range(1,len(s)): if s[i]>0 and appear[s[i]-1]: L[i] = L[find[s[i]-1]] + 1 else: L[i] = 1 appear[s[i]] = True ...
vfc_49393
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4 1 2 5 3\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4 1 3 2\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "inpu...