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
725_G. Messages on a Tree
Solve the following coding problem using the programming language python: Alice and Bob are well-known for sending messages to each other. This time you have a rooted tree with Bob standing in the root node and copies of Alice standing in each of the other vertices. The root node has number 0, the rest are numbered 1 ...
vfc_77313
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 3\n0 1 1 2 3 3 4 5\n6 1\n8 2\n4 5\n", "output": "7 6 11 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n0 1 1\n2 1\n3 1\n", "output": "5 3 ", "type": "stdin_stdout" }...
code_contests
verifiable_code
748_A. Santa Claus and a Place in a Class
Solve the following coding problem using the programming language python: Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are n lanes of m desks each, and there are two working places at each of the desks. The lanes are nu...
```python n, m, k = map(int,input().split()) print((k-1)//(2*m)+1,(k-1)%(2*m)//2+1,'L' if k%2 else 'R') ```
vfc_77317
{ "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 4 4\n", "output": "1 2 R\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 9\n", "output": "2 2 L\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
770_D. Draw Brackets!
Solve the following coding problem using the programming language python: A sequence of square brackets is regular if by inserting symbols "+" and "1" into it, you can get a regular mathematical expression from it. For example, sequences "[[]][]", "[]" and "[[][[]]]" — are regular, at the same time "][", "[[]" and "[[...
```python import sys def vert(f, d, c, h): f[d][c] = '+' f[h-1-d][c] = '+' for i in range(d+1,h-1-d): f[i][c] = '|' return f n = int(input()) s = sys.stdin.readline().rstrip() d = 0 maxd=1 for c in s: if c == '[': d+=1 if d>maxd: maxd=d else: d-=1 ...
vfc_77321
{ "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": "8\n[[][]][]\n", "output": "+- -++- -+\n|+- -++- -+|| |\n|| || ||| |\n|+- -++- -+|| |\n+- -++- -+\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n[[[]]]\n", ...
code_contests
verifiable_code
794_G. Replace All
Solve the following coding problem using the programming language python: Igor the analyst is at work. He learned about a feature in his text editor called "Replace All". Igor is too bored at work and thus he came up with the following problem: Given two strings x and y which consist of the English letters 'A' and 'B...
vfc_77325
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "A?\n?\n3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "A\nB\n10\n", "output": "2046\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
816_A. Karen and Morning
Solve the following coding problem using the programming language python: Karen is getting ready for a new school day! <image> It is currently hh:mm, given in a 24-hour format. As you know, Karen loves palindromes, and she believes that it is good luck to wake up when the time is a palindrome. What is the minimum n...
```python h, m = map(int, input().split(':')) for i in range(999): if h == 10 * (m % 10) + m // 10: print(i) break h, m = (h, m + 1) if m < 59 else ((h + 1) % 24, 0) ```
vfc_77329
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "23:59\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "05:39\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13...
code_contests
verifiable_code
841_A. Generous Kefa
Solve the following coding problem using the programming language python: One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloo...
```python from collections import Counter n , k = map(int , input().split()) s = input() s = list(s) cnt = Counter(s) r = 0 for i in cnt: if cnt[i] > k: r = 1 break print('YES' if r == 0 else 'NO') ```
vfc_77333
{ "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": "6 3\naacaab\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\naabb\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
887_F. Row of Models
Solve the following coding problem using the programming language python: During the final part of fashion show all models come to the stage and stay in one row and fashion designer stays to right to model on the right. During the rehearsal, Izabella noticed, that row isn't nice, but she can't figure out how to fix it...
vfc_77341
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n5 3 6 5 2\n", "output": "YES", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
910_A. The Way to Home
Solve the following coding problem using the programming language python: A frog lives on the axis Ox and needs to reach home which is in the point n. She starts from the point 1. The frog can jump to the right at a distance not more than d. So, after she jumped from the point x she can reach the point x + a, where a ...
```python n , d =map(int, input().split()) s= str(input()) ans = -1 i=1 count = 0 while i<len(s): temp = s[i:i+d] if '1' in temp: x = temp.rfind('1') i = i+ x +1 count = count +1 else: print(ans) count=0 break if count!=0: print(count) ```
vfc_77345
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 4\n11100101\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 4\n10010101\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
932_C. Permutation Cycle
Solve the following coding problem using the programming language python: For a permutation P[1... N] of integers from 1 to N, function f is defined as follows: <image> Let g(i) be the minimum positive integer j such that f(i, j) = i. We can show such j always exists. For given N, A, B, find a permutation P of inte...
```python #This code sucks, you know it and I know it. #Move on and call me an idiot later. def solve(a, b, n): i = 0 while i * a <= n: if (n - (i * a)) % b == 0: x = i y = (n - (i * a)) // b return (x, y) i = i + 1 return (-1, -1) n,...
vfc_77349
{ "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": "9 2 5\n", "output": "2 1 4 3 6 7 8 9 5 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 1\n", "output": "1 2 3 ", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
959_D. Mahmoud and Ehab and another array construction task
Solve the following coding problem using the programming language python: Mahmoud has an array a consisting of n integers. He asked Ehab to find another array b of the same length such that: * b is lexicographically greater than or equal to a. * bi ≥ 2. * b is pairwise coprime: for every 1 ≤ i < j ≤ n, bi and...
```python MAX_NUM = 2000000 prime_str = ('2 3 5 7 11 13 17 19 23 29 ' + '31 37 41 43 47 53 59 61 67 71 ' + '73 79 83 89 97 101 103 107 109 113 ' + '127 131 137 139 149 1...
vfc_77353
{ "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": "5\n2 3 5 4 13\n", "output": "2 3 5 7 11 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n10 3 7\n", "output": "10 3 7 ", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
986_B. Petr and Permutations
Solve the following coding problem using the programming language python: Petr likes to come up with problems about randomly generated data. This time problem is about random permutation. He decided to generate a random permutation this way: he takes identity permutation of numbers from 1 to n and then 3n times takes ...
```python import random astr=input() N=int(astr) s=input() sk=s.split(' ') ml=[int(i) for i in sk] kl=[0 for i in ml] #for i in range(0, 7*N+2): # A=random.randint(0,N-1) # B=A # while(A==B): # B=random.randint(0,N-1) # swap=ml[A] # ml[A]=ml[B] # ml[B]=swap #print(ml) k=0 for i in range(0,N): ...
vfc_77357
{ "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 5 1 3\n", "output": "Petr\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 3 5 1 2\n", "output": "Petr\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
agitated-chandan
Solve the following coding problem using the programming language python: Chandan is a horrendous murderer and he wants to kill Arjit just because he's lazy. Chandan is following the trail of Arjit's shoes. The trail is in the form of a k-ary tree. Arjit is lazy, sure, but he's smart. So, he magically moves away from...
```python t=int(raw_input()) def bfs(x): b=[False]*(n+1)# an array of false flags to keep track of vertices visited memo=["p"]*(n+1) l=0 c=0 q=[] q.append(x) memo[x]=0 while len(q)!=0: #t=s[-1] top=q.pop(0) #l=t b[top]=True #q.pop(0) for j ...
vfc_77361
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5\n1 2 4\n3 2 3\n2 5 2\n4 1 1\n\nSAMPLE", "output": "0 8", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n5\n2 2 4\n3 2 3\n2 5 2\n4 1 1\n\nSAMPLE", "output": "0 1\n", "type"...
code_contests
verifiable_code
breakup-app
Solve the following coding problem using the programming language python: Bosky and Menot are two friends who participated in GSF Hacks Prelims on HackerEarth, and both of them easily qualified for the on-site round. Bosky wants to team up with Menot for the on-site round but Menot has a date with his girlfriend the s...
```python days = [0]*31 for i in xrange(input()): string = raw_input().split() if string[0] == 'G:': choice = [int(x) for x in string if x.isdigit()] for gval in choice: days[gval] += 2*(choice.count(gval)) else: choice = [int(x) for x in string if x.isdigit()] for gval in choice: days[gval] += 1*(...
vfc_77365
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nG: I want to go on 19\nM: No that is not possible lets go on 21\nG: No 19 is final and 21 is not\nM: OKAY as you wish\n\nSAMPLE", "output": "Date\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
dalton-and-compiler-design
Solve the following coding problem using the programming language python: As we know , Professor Dalton is teaching Compiler Design. During his first class, he found that the students are very talkative. so,he decided to divide the class into two sections, A & B such that the difference between the strength of two se...
```python testcases = raw_input() for i in range(int(testcases)): tot = raw_input() tot = int(tot) if(tot%2==0): a=tot/2 print a,a else: a=tot/2 print a,a+1 ```
vfc_77369
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n6\n8\n\nSAMPLE", "output": "3 3\n4 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n8\n\nSAMPLE", "output": "0 1\n4 4\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
gajodhars-memory
Solve the following coding problem using the programming language python: Gajodhar is travelling from one city to another city. Let starting city be the source and city at which his journey ends be destination. There are many intermediate cities between source and destination. Gajodhar has weak memory, so he remembers...
```python t = int(raw_input()) while t: t-=1 n = int(raw_input()) a = [] c = 0 for i in xrange(n): b = str(raw_input()) a.append(b[0]) for i in a: if a.count(i) == 1: c+=1 print c ```
vfc_77373
{ "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\nCHANDIGARH\nMUMBAI\nCHENNAI\n4\nKASHMIR\nDELHI\nBANGLORE\nKANYAKUMARI\n\nSAMPLE", "output": "1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3\nCHANDIGARH\nIABMUM\nCHENNAI\n4...
code_contests
verifiable_code
k-distribution
Solve the following coding problem using the programming language python: You are given N positive integers A1, A2, ... AN. Find the number of ways to distribute them in 2 groups in such a way that sum of numbers in each group is greater or equal K. The answer can be large so output it modulo 10^9 + 7. Input The firs...
```python MOD=1000000007 N,K=map(int,raw_input().split()) A=map(int,raw_input().split()) found=[0]*K found[0]=1 Kplus=0 if sum(A)<2*K: print 0 exit() for a in A: Kplus=Kplus*2 for j in range(max(0,K-a),K): Kplus+=found[j] Kplus%=MOD for j in range(K-1,a-1,-1): found[j]=(found[j]+found[j-a])%MOD print (MOD+K...
vfc_77377
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 5\n6 6\n\n\nSAMPLE", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 91019\n6 5 10 9 4 5 4 2 8 10 10 8 6 2 4 2 2 2 9 6 6 9 2 7 7 1 4 7 87301 1 9 7 3 5 3 9 4 10 8 1 5 5 10 ...
code_contests
verifiable_code
palindromic-numbers-7
Solve the following coding problem using the programming language python: Given A and B, count the numbers N such that A ≤ N ≤ B and N is a palindrome. Examples: Palindromes: 121, 11 , 11411 Not Palindromes: 122, 10 Input: First line contains T, the number of testcases. Each testcase consists of two integers A...
```python n = input() def check_palindromic(x): if str(x) == str(x)[::-1]: return True return False kq = [] for i in range(n): dem = 0 nhap = list(map(lambda x: int(x), raw_input().split())) for j in range(nhap[0], nhap[1]+1): if check_palindromic(j) == True: dem += 1 ...
vfc_77385
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10 13\n20 30\n\nSAMPLE", "output": "1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10 13\n20 30\n\nSPMALE", "output": "1\n1\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
road-demolishing
Solve the following coding problem using the programming language python: King Tle4Ever just appointed Moron as the new Engineer for his country Time Limit Exceeded. In the country of Time Limit Exceeded there are n cities and there is a direct road between each pair of cities. Now cleaning up these roads costs Tle4Ev...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' for _ in range(input()): n,q = map(int,raw_input().split()) q=q-1 ans = n*n - (n%q)*((n+q-1)/q)*((n+q-1)/q) - (q - n%q)*(n/q)*(n/q) ans/=2 ans1 =(n*(n-1))/...
vfc_77389
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 3\n5 3\n\nSAMPLE", "output": "2\n4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
staircase
Solve the following coding problem using the programming language python: Jack and Jill are sitting at the bottom of their tree house and debating in how many ways then can jump up the stairs on the tree and reach the tree house .Because Jack is older than Jill, He can jump one, two or three stairs in one step while J...
```python a = 0; b = 1; c = 1; d = 0; e = 1; n = int(raw_input()); if n <= 0: print "ERROR"; else: n -= 1; while (n): c = a + b + c; b = c - a - b; a = c - b - a; e = d + e; d = e - d; n -= 1; e = d + e; d = e - d; print "Jack-"+str(c)+"\nJill-"+st...
vfc_77393
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n\nSAMPLE", "output": "Jack-4\nJill-3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n\nLAMPSE", "output": "Jack-4\nJill-3\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
troubling-triple
Solve the following coding problem using the programming language python: A Puzzle is a game, problem, or toy that tests a person's ingenuity. In a puzzle, one is required to put pieces together, in a logical way, in order to arrive at the correct solution of the puzzle. There are different types of puzzles for differ...
```python (N, K) = map (int, str(raw_input()).split()) nums = sorted (map (int, str(raw_input()).split())) count = 0 for i in range(N-2): j = i+1 k = N-1 while True: while nums[i] * nums[j] * nums[k] > K: k -= 1 if k == j: break count += k-j j += 1 if j >= k: break print count ```
vfc_77397
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 42\n3 2 5 7\n\nSAMPLE", "output": "2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00003 Is it a Right Triangle?
Solve the following coding problem using the programming language python: Write a program which judges wheather given length of three side form a right triangle. Print "YES" if the given sides (integers) form a right triangle, "NO" if not so. Constraints * 1 ≤ length of the side ≤ 1,000 * N ≤ 1,000 Input Input con...
```python N = int(input()) for i in range(N): num = sorted(map(int, input().split())) if num[0] ** 2 + num[1] ** 2 == num[2] ** 2: print("YES") else: print("NO") ```
vfc_77441
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4 3 5\n4 3 6\n8 8 8", "output": "YES\nNO\nNO", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4 3 5\n0 3 6\n8 8 8", "output": "YES\nNO\nNO\n", "type": "stdin_stdout" } ...
code_contests
verifiable_code
p00268 Cats Going Straight II
Solve the following coding problem using the programming language python: There was a big old mansion in one place, and one cat settled in. As shown in the figure, the mansion has a convex polygonal shape when viewed from above, and is made up of several rooms surrounded by straight walls. One wall is supported by pil...
```python from math import atan2 from collections import defaultdict, deque def cross(a, b, c): return (b[0]-a[0])*(c[1]-a[1]) - (b[1]-a[1])*(c[0]-a[0]) def convex_hull(ps): qs = [] n = len(ps) for p in ps: while len(qs)>1 and cross(qs[-1], qs[-2], p) > 0: qs.pop() qs.append(...
vfc_77449
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n0 0\n1 0\n1 1\n0 1\n1 2\n1 4\n2 3\n3 4\n12 22\n2 0\n4 0\n8 0\n4 2\n6 2\n8 2\n2 4\n4 4\n6 4\n0 6\n8 6\n0 8\n1 2\n2 3\n1 4\n1 7\n1 10\n2 4\n2 5\n3 5\n3 6\n4 5\n4 8\n5 6\n5 9\n6 9\n6 11\n7 10\n7 8\n8 9\n9 11\n10 11\n10 12\n11 12\...
code_contests
verifiable_code
p00455 Time Card
Solve the following coding problem using the programming language python: problem JOI Shoji manages the time spent at work by employees with a time card. When an employee arrives at the office, he / she uses a dedicated device to stamp the arrival time on the time card. When leaving the office after work, the time of...
```python for i in range(3): L =list(map(int,input().split())) L0 = L[0] * 60 * 60 + L[1] * 60 + L[2] L1 = L[3] * 60 * 60 + L[4] * 60 + L[5] h = (L1 - L0) // (60 * 60) m = ((L1 - L0) % (60 * 60)) // 60 s = ((L1 - L0) % (60 * 60)) % 60 print(h,m,s) ```
vfc_77453
{ "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 0 0 18 0 0\n9 0 1 18 0 0\n12 14 52 12 15 30", "output": "9 0 0\n8 59 59\n0 0 38", "type": "stdin_stdout" }, { "fn_name": null, "input": "None", "output": "None", "type": "stdin_stdout" ...
code_contests
verifiable_code
p00790 Die Game
Solve the following coding problem using the programming language python: Life is not easy. Sometimes it is beyond your control. Now, as contestants of ACM ICPC, you might be just tasting the bitter of life. But don't worry! Do not look only on the dark side of life, but look also on the bright side. Life may be an en...
```python # AOJ 1210: Die Game # Python3 2018.7.22 bal4u dic = {'s':1, 'w':2, 'e':3, 'n':4} rot = [[0,1,2,3,4,5,6],[0,2,6,3,4,1,5],[0,4,2,1,6,5,3],[0,3,2,6,1,5,4],[0,5,1,3,4,6,2]] while True: n = int(input()) if n == 0: break dice = [i for i in range(7)] for j in range(n): a = input()[0] ...
vfc_77461
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\nnorth\n3\nnorth\neast\nsouth\n0", "output": "5\n1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01187 Make Friendships
Solve the following coding problem using the programming language python: Isaac H. Ives attended an international student party and made a lot of girl friends (as many other persons expected). To strike up a good friendship with them, he decided to have dates with them. However, it is hard for him to schedule dates be...
vfc_77473
{ "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\n3 1 3 5\n2 1 4\n4 1 2 3 6\n1 3\n0", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 1 3 5\n2 1 4\n4 1 1 3 6\n1 3\n0", "output": "2\n", "type": "stdin_stdout"...
code_contests
verifiable_code
p01324 Consistent Unit System
Solve the following coding problem using the programming language python: Kyo, 垓, {Reiyo}, 穣, Mizo, 澗, Tadashi, Ryo, Goku, Tsunekawasa, Amongi, Decillion, etc. Minutes, 厘, hair, thread, 忽, fine, fine, fine, sha, dust, dust, 渺, vagueness, vagueness, patrolling, su 臾, sigh, bullet finger, moment, Rokutoku, emptiness, cl...
```python while True: n = int(input()) if n == 0:break dic = {} for _ in range(n): _, name1, _, val, name2 = input().split() val = int(val.split("^")[1]) if name1 not in dic: dic[name1] = {} if name2 not in dic: dic[name2] = {} dic[name1][name2] = val dic[name2][name1] = -val...
vfc_77477
{ "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\n1 km = 10^3 m\n1 m = 10^2 cm\n1 km = 10^5 cm", "output": "Yes", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01492 CarrotBreeding
Solve the following coding problem using the programming language python: Example Input 4 Output 4 0 0 1 0 2 0 1 1 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_77481
{ "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", "output": "4\n0 0\n1 0\n2 0\n1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "6", "output": "4\n0 0\n1 0\n2 1\n3 3\n4 6\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
p01654 Hashigo Sama
Solve the following coding problem using the programming language python: Problem Statement Chelsea is a modern artist. She decided to make her next work with ladders. She wants to combine some ladders and paint some beautiful pattern. A ladder can be considered as a graph called hashigo. There are n hashigos number...
vfc_77485
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 5\n2\n3 7\n2 3 1\n0 1 1 0\n1 2 2 0\n2 8\n5 6\n0 2 1 2\n2 8\n1 1\n0 0 1 0\n2 2\n2 2\n0 1 1 0\n2 3\n3 3\n0 2 1 1\n2 4\n3 1\n1 0 0 1\n0 0", "output": "708\n1900484\n438404500\n3878\n496\n14246\n9768", "type": "stdin_stdo...
code_contests
verifiable_code
p01940 Unique Subsequence
Solve the following coding problem using the programming language python: C: Only one subsequence --Unique Subsequence- problem One day Ebi-chan noticed that a text string T of length n and a pattern string P (m \ leq n) of length m were placed on the desk. Ebi-chan loves the "only one subsequence" that appears in s...
```python t=input() p=input() mae=[0]*len(p) cnt=0 for i in range(len(t)): if t[i]==p[cnt]: mae[cnt]=i cnt+=1 if cnt==len(p): break if cnt!=len(p):print("no");exit() cnt-=1 for j in range(len(t)-1,-1,-1): if t[j]==p[cnt]: if mae[cnt]!=j:print("no");exit() cnt-...
vfc_77493
{ "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": "aizucamp\nazu", "output": "yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "aizucamp\nuza", "output": "no\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02089 AddMulSubDiv
Solve the following coding problem using the programming language python: B: AddMulSubDiv Problem Statement You have an array A of N integers. A_i denotes the i-th element of A. You have to process one of the following queries Q times: * Query 1: The query consists of non-negative integer x, and two positive integ...
```python import bisect n,Q,L,R = map(int,input().split()) a = list(map(int,input().split())) a.sort() p = [] for i in range(Q): p.append(tuple(map(int,input().split()))) def f(z): for q,x,s,t in p: if q == 1: if z >= x: z = t*(z+s) else: if z <= x: ...
vfc_77497
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 3 10\n1 -2 3\n1 2 2 3\n2 20 1 3\n2 1 20 5", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 3 10\n1 -2 3\n1 2 2 3\n2 20 1 3\n2 2 20 5", "output": "1\n", "typ...
code_contests
verifiable_code
p02373 Lowest Common Ancestor
Solve the following coding problem using the programming language python: For a rooted tree, find the lowest common ancestor of two nodes u and v. The given tree consists of n nodes and every node has a unique ID from 0 to n-1 where 0 is the root. Constraints * 1 ≤ n ≤ 100000 * 1 ≤ q ≤ 100000 Input n k0 c1 c2 .....
```python class Lca: def __init__(self, E, root): import sys sys.setrecursionlimit(500000) self.root = root self.E = E # V<V> self.n = len(E) # 頂点数 self.logn = 1 # n < 1<<logn ぴったりはだめ while self.n >= (1<<self.logn): self.logn += 1 # pa...
vfc_77505
{ "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": "8\n3 1 2 3\n2 4 5\n0\n0\n0\n2 6 7\n0\n0\n4\n4 6\n4 7\n4 3\n5 2", "output": "1\n1\n0\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n3 1 2 3\n2 4 5\n0\n0\n-1\n2 6 7\n0\n0\n4\n4 6\n4 7\n...
code_contests
verifiable_code
bex
Solve the following coding problem using the programming language python: Harry is a bright student. To prepare thoroughly for exams, he completes all the exercises in his book! Now that the exams are approaching fast, he is doing book exercises day and night. He writes down and keeps updating the remaining number of ...
```python import sys filein = sys.stdin #filein = open("bex.in2",'r') def main() : n = int(filein.readline()) ll = [] bookcnt = 0 outstr = [] for str in filein : if str[0] == "-" : outstr.append("%d %s" % (bookcnt-ll[-1][2],ll[-1][1])) #print "%d %s" % (bookcnt-ll[-1][2],ll[-1][1]) book...
vfc_77509
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n9 english\n6 mathematics\n8 geography\n-1\n3 graphics\n-1", "output": "1 mathematics\n0 graphics\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
cn04
Solve the following coding problem using the programming language python: Sheh ! You are bored again. :P You guys decide to play a game, this time based on your names. All of you write your name on a sheet of paper and the one whose name has the maximum number of distinct substrings of his name wins the game. But coun...
```python n=input() for i in range(n): inp=raw_input() li=[] for j in range(len(inp)): string=inp[j] li.append(string) for k in range(j+1,len(inp)): string+=inp[k] li.append(string) print len(set(li)) ```
vfc_77513
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nCCCCC\nABABA", "output": "5\n9", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nCCCCC\nABBAA", "output": "5\n12\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
forgetpw
Solve the following coding problem using the programming language python: Chef changed the password of his laptop a few days ago, but he can't remember it today. Luckily, he wrote the encrypted password on a piece of paper, along with the rules for decryption. The encrypted password is a string S consists of ASCII pri...
```python def get_rules(num_rules): """ Read the input for num_rules times. Return - Dictionary with keys mapping to values. """ rules = {} for _ in xrange(num_rules): key, val = raw_input().split() rules[key] = val return rules def decode_pass(password, rules):...
vfc_77517
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2\n5 3\n3 1\n5\n0\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#dd098x", "output": "3\n1800\n.001\n321.33098\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2\n5 3\n3 1\n5\n0\n01800...
code_contests
verifiable_code
loc01
Solve the following coding problem using the programming language python: In this problem, the divisors of N do not include the number N itself. For example, if N=24, the divisors of N (excluding N) are 1, 2, 3, 4, 6 and 12. Thus, the product of divisors is 1x2x3x4x6x8x12=13824. Since the result may be very large, if ...
```python def factors(n): return reduce(list.__add__, ([i, n//i] for i in range(1, int(n**0.5) + 1) if n % i == 0)) t = long(raw_input()) while t: t-=1 a = long(raw_input()) b = [] b = factors(a) b = list(set(b)) b.sort() c = 1 for i in xrange(len(b)-1): c*=b[...
vfc_77521
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3\n4\n12\n25\n957\n10000", "output": "1\n2\n144\n5\n7493\n0000", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
prime
Solve the following coding problem using the programming language python: Print sum of prime numbers upto n Input n - the number till which sum has to be done. Output print sum of primes ≤n. Example Input: 5 Output: 10 The input will be given via stdin and the output should be printed to stdout by your code. ...
```python def ps(n): r = int(n**0.5) assert r*r <= n and (r+1)**2 > n V = [n//i for i in range(1,r+1)] V += list(range(V[-1]-1,0,-1)) S = {i:i*(i+1)//2-1 for i in V} for p in range(2,r+1): if S[p] > S[p-1]: # p is prime sp = S[p-1] # sum of primes smaller than p ...
vfc_77525
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5", "output": "10", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
tangdiv
Solve the following coding problem using the programming language python: Once Chef decided to divide the tangerine into several parts. At first, he numbered tangerine's segments from 1 to n in the clockwise order starting from some segment. Then he intended to divide the fruit into several parts. In order to do it he...
```python def solve(): N, K, P = map(int, raw_input().split()) pos = set() for k in xrange(K): l, r = map(int, raw_input().split()) pos.add(r) okay = True for p in xrange(P): l, r = map(int, raw_input().split()) if okay and r not in pos: okay = False r...
vfc_77529
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10 3 2\n1 4\n5 5\n6 10\n1 5\n6 10\n10 3 1\n2 5\n10 1\n6 9\n1 10", "output": "Yes\nNo\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10 3 2\n1 4\n5 5\n6 10\n1 5\n6 10\n10 3 1\n4 5\n1...
code_contests
verifiable_code
1010_F. Tree
Solve the following coding problem using the programming language python: The Main Martian Tree grows on Mars. It is a binary tree (a rooted tree, with no more than two sons at each vertex) with n vertices, where the root vertex has the number 1. Its fruits are the Main Martian Fruits. It's summer now, so this tree do...
vfc_77533
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 7, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 10\n1 2\n1 3\n3 4\n", "output": "441\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 5\n1 2\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1036_A. Function Height
Solve the following coding problem using the programming language python: You are given a set of 2n+1 integer points on a Cartesian plane. Points are numbered from 0 to 2n inclusive. Let P_i be the i-th point. The x-coordinate of the point P_i equals i. The y-coordinate of the point P_i equals zero (initially). Thus, ...
```python from math import ceil from sys import stdin, stdout n, k = [int(i) for i in stdin.readline().rstrip().split()] stdout.write(str((n+k-1)//n)+'\n') ```
vfc_77537
{ "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\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "999999999999999999 999999999999999986\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
1057_C. Tanya and Colored Candies
Solve the following coding problem using the programming language python: There are n candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from 1 to n. The i-th box contains r_i candies, candies have the color c_i (the color can take one of three values ​​— red, green, or blue). ...
```python INF = 10e9 n,s,k = map(int, input().split()) r = list(map(int, input().split())) r.append(0) col = input() mat = [] for i in range(n+1): adj = {} for j in range(n): if i == n: adj[j] = abs((s-1)-j) else: if col[i] != col[j] and r[i] < r[j]: adj[j...
vfc_77541
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 15\n5 6\nRG\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3 10\n1 2 3 4 5\nRGBRR\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
1080_B. Margarite and the best present
Solve the following coding problem using the programming language python: Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them. Recently, she was presented with an array a of the size of 10^9 elements that is filled as follows: * a_1 = -1 ...
```python for i in range(int(input())): a,b=map(int,input().split()) if (b-a)%2!=0: if a%2==0: print(-(b-a+1)//2) else: print((b-a+1)//2) else: if a%2!=0: print((b-a)//2 - b) else: print(-(b-a)//2 + b) ```
vfc_77545
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 3\n2 5\n5 5\n4 4\n2 3\n", "output": "-2\n-2\n-5\n4\n-1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
10_A. Power Consumption Calculation
Solve the following coding problem using the programming language python: Tom is interested in power consumption of his favourite laptop. His laptop has three modes. In normal mode laptop consumes P1 watt per minute. T1 minutes after Tom moved the mouse or touched the keyboard for the last time, a screensaver starts a...
```python n,p1,p2,p3,t1,t2 = map(int,input().split()) p=[] c=0 for j in range(n): l,r = map(int,input().split()) if j==0: c+= (r-l)*p1 p.append(r) else: if l-p[-1]>0: if l-p[-1]<=t1: c+=(l-p[-1])*p1 else: if t1+t2>=l-p[-1]>...
vfc_77549
{ "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 8 4 2 5 10\n20 30\n50 100\n", "output": "570\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 3 2 1 5 10\n0 10\n", "output": "30\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1120_F. Secret Letters
Solve the following coding problem using the programming language python: Little W and Little P decided to send letters to each other regarding the most important events during a day. There are n events during a day: at time moment t_i something happens to the person p_i (p_i is either W or P, denoting Little W and Li...
vfc_77553
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 10 94\n17 W\n20 W\n28 W\n48 W\n51 P\n52 W\n56 W\n62 P\n75 P\n78 P\n87\n", "output": "916", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1148_B. Born This Way
Solve the following coding problem using the programming language python: Arkady bought an air ticket from a city A to a city C. Unfortunately, there are no direct flights, but there are a lot of flights from A to a city B, and from B to C. There are n flights from A to B, they depart at time moments a_1, a_2, a_3, ....
```python from collections import * from math import * import array import bisect cin = lambda : [*map(int, input().split())] def upper_bound(a, x): l = 0 r = len(a) - 1 while l < r: m = int((l + r + 1) / 2) if a[m] <= x: l = m else: r = m - 1 return l ...
vfc_77557
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 4 4 2\n1 10\n10 20\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5 1 1 2\n1 3 5 7\n1 2 3 9 10\n", "output": "11\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1169_D. Good Triple
Solve the following coding problem using the programming language python: Toad Rash has a binary string s. A binary string consists only of zeros and ones. Let n be the length of s. Rash needs to find the number of such pairs of integers l, r that 1 ≤ l ≤ r ≤ n and there is at least one pair of integers x, k such th...
```python from sys import stdin s=stdin.readline().strip() x=-1 ans=0 for i in range(len(s)): for j in range(1,10): if (i-2*j)>=0 and s[i]==s[i-j] and s[i-j]==s[i-2*j]: if (i-2*j)>x: ans+=(i-2*j-x)*(len(s)-i) x=i-2*j print(ans) ```
vfc_77561
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "010101\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11001100\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
1187_F. Expected Square Beauty
Solve the following coding problem using the programming language python: Let x be an array of integers x = [x_1, x_2, ..., x_n]. Let's define B(x) as a minimal size of a partition of x into subsegments such that all elements in each subsegment are equal. For example, B([3, 3, 6, 1, 6, 6, 6]) = 4 using next partition:...
```python mod = 10 ** 9 + 7 def pow_(x, y, p) : res = 1 x = x % p if x == 0: return 0 while y > 0: if (y & 1) == 1: res = (res * x) % p y = y >> 1 x = (x * x) % p return res def reverse(x, mod): return pow...
vfc_77565
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1 1\n1 2 3\n", "output": "166666673\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 4 5\n4 5 6\n", "output": "500000010\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1206_E. Palindromic Paths
Solve the following coding problem using the programming language python: This is an interactive problem You are given a grid n× n, where n is odd. Rows are enumerated from 1 to n from up to down, columns are enumerated from 1 to n from left to right. Cell, standing on the intersection of row x and column y, is denot...
```python from sys import stdout # matrix=""" # 101110111011101110111 # 011101110111011101110 # 111011101110111011101 # 110111011101110111011 # 101110111011101110111 # 011101110111011101110 # 111011101110111011101 # 110111011101110111011 # 101110111011101110111 # 011101110111011101110 # 111011101110111011100 # 1101...
vfc_77569
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0\n1\n0\n1\n1\n1\n1", "output": "\n? 1 1 1 3\n? 1 1 2 3\n? 2 1 2 3\n? 3 1 3 3\n? 2 2 3 3\n? 1 2 3 2\n? 1 2 3 3\n!\n100\n001\n000", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n111\n11...
code_contests
verifiable_code
1225_A. Forgetting Things
Solve the following coding problem using the programming language python: Kolya is very absent-minded. Today his math teacher asked him to solve a simple problem with the equation a + 1 = b with positive integers a and b, but Kolya forgot the numbers a and b. He does, however, remember that the first (leftmost) digit ...
```python a,b = map(int,input().split()) if(b == a+1): print(str(a)+"9 "+str(b)+"0") elif(b == a): print(str(a)+"0 "+str(a)+"1") elif(b == 1 and a == 9): print("99 100") else: print(-1) ```
vfc_77573
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2\n", "output": "19 20", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1249_C2. Good Numbers (hard version)
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is the maximum value of n. You are given a positive integer number n. You really love good numbers so you want to find the smallest good number greater than or equal to n. The positive integer...
```python for _ in range(int(input())): n=int(input()) a=[] b=[0] for i in range(50): a.append(3**i) b.append(b[-1]+a[-1]) if b[-1]> n: break s=b[i+1] a=a[::-1] # print(s,a) for j in a: if s-j>=n: s-=j print(s) ```
vfc_77577
{ "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": "8\n1\n2\n6\n13\n14\n3620\n10000\n1000000000000000000\n", "output": "1\n3\n9\n13\n27\n6561\n19683\n1350851717672992089\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n450283905890997363\...
code_contests
verifiable_code
1267_K. Key Storage
Solve the following coding problem using the programming language python: Karl is developing a key storage service. Each user has a positive integer key. Karl knows that storing keys in plain text is bad practice. So, instead of storing a key, he decided to store a fingerprint of a key. However, using some existing f...
```python import math as m import collections IP = lambda: list(map(int, input().split())) INF = 1e9 f = [1] for i in range(1, 22): f.append(f[-1]*i) def solve(arr, n): d = collections.Counter(arr) tu = 1; mau = 1 a = [0]*22 for i in arr: # print(i, n) a[i] += 1 for i in range...
vfc_77581
{ "difficulty": "17", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n11\n123456\n", "output": "0\n1\n127\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26...
code_contests
verifiable_code
128_E. Birthday
Solve the following coding problem using the programming language python: Anna's got a birthday today. She invited many guests and cooked a huge (nearly infinite) birthday cake decorated by n banana circles of different sizes. Maria's birthday is about to start in 7 minutes too, and while Anna is older, she decided to...
vfc_77585
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n0 0 1\n3 0 1\n6 0 1\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 3\n0 0 1\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
1310_A. Recommendations
Solve the following coding problem using the programming language python: VK news recommendation system daily selects interesting publications of one of n disjoint categories for each user. Each publication belongs to exactly one category. For each category i batch algorithm selects a_i publications. The latest A/B t...
```python import heapq n = int(input()) *a, = map(int, input().split()) *t, = map(int, input().split()) i = 0 sorted_idxs = sorted(range(n), key=lambda o: (a[o], -t[o])) cur_val = a[sorted_idxs[0]] dupls = [] ans = 0 s = 0 for i, idx in enumerate(sorted_idxs): cur_val = a[idx] heapq.heappush(dupls, (-t[idx],...
vfc_77589
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5\n1 1 1 1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3 7 9 7 8\n5 2 5 7 5\n", "output": "6\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1332_F. Independent Set
Solve the following coding problem using the programming language python: Eric is the teacher of graph theory class. Today, Eric teaches independent set and edge-induced subgraph. Given a graph G=(V,E), an independent set is a subset of vertices V' ⊂ V such that for every pair u,v ∈ V', (u,v) not ∈ E (i.e. no edge in...
```python import sys readline = sys.stdin.readline def parorder(Edge, p): N = len(Edge) par = [0]*N par[p] = -1 stack = [p] order = [] visited = set([p]) ast = stack.append apo = order.append while stack: vn = stack.pop() apo(vn) for vf in Edge[vn]: ...
vfc_77593
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2\n3 2\n", "output": "11\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
1353_B. Two Arrays And Swaps
Solve the following coding problem using the programming language python: You are given two arrays a and b both consisting of n positive (greater than zero) integers. You are also given an integer k. In one move, you can choose two indices i and j (1 ≤ i, j ≤ n) and swap a_i and b_j (i.e. a_i becomes b_j and vice ver...
```python def swap_sum(a,b,cnt,k): if cnt==k or min(a)>=max(b): return sum(a) else: i=a.index(min(a)) j=b.index(max(b)) a[i],b[j]=b[j],a[i] #print(a) #print(b) return swap_sum(a,b,cnt+1,k) for ii in range(int(input())): n,k=map(int,...
vfc_77597
{ "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 1\n1 2\n3 4\n5 5\n5 5 6 6 5\n1 2 5 4 3\n5 3\n1 2 3 4 5\n10 9 10 10 9\n4 0\n2 2 4 3\n2 4 2 3\n4 4\n1 2 2 1\n4 4 5 4\n", "output": "6\n27\n39\n11\n17\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1373_A. Donut Shops
Solve the following coding problem using the programming language python: There are two rival donut shops. The first shop sells donuts at retail: each donut costs a dollars. The second shop sells donuts only in bulk: box of b donuts costs c dollars. So if you want to buy x donuts from this shop, then you have to buy...
```python import sys input = sys.stdin.readline def main(): t = int(input()) for _ in range(t): A, B, C = [int(x) for x in input().split()] ans1 = -1 ans2 = -1 if A < C: ans1 = 1 if A * B > C: ans2 = B print(ans1, ans2) if __n...
vfc_77601
{ "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\n5 10 4\n4 5 20\n2 2 3\n1000000000 1000000000 1000000000\n", "output": "-1 10\n1 -1\n1 2\n-1 1000000000\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1395_F. Boboniu and String
Solve the following coding problem using the programming language python: Boboniu defines BN-string as a string s of characters 'B' and 'N'. You can perform the following operations on the BN-string s: * Remove a character of s. * Remove a substring "BN" or "NB" of s. * Add a character 'B' or 'N' to the end ...
vfc_77605
{ "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": "8\nNNN\nNNN\nBBNNBBBN\nNNNBNN\nB\nNNN\nNNNNBNN\nNNNNNNNNNNNNNNNBNNNNNNNBNB\n", "output": "12\nBNNNNNNNNNNN\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nB\nN\nBN\n", "output": "...
code_contests
verifiable_code
141_B. Hopscotch
Solve the following coding problem using the programming language python: So nearly half of the winter is over and Maria is dreaming about summer. She's fed up with skates and sleds, she was dreaming about Hopscotch all night long. It's a very popular children's game. The game field, the court, looks as is shown in th...
```python a, x, y = map(int, input().split()) h = a / 2 if y % a == 0: print('-1') exit() y //= a y += 1 if y == 1: if x > -h and x < h: print('1') else: print('-1') else: if y % 2 == 0: if x > -h and x < h: print(y + (y // 2) - 1) else: print(...
vfc_77609
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4 0\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 0 7\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3...
code_contests
verifiable_code
1438_B. Valerii Against Everyone
Solve the following coding problem using the programming language python: You're given an array b of length n. Let's define another array a, also of length n, for which a_i = 2^{b_i} (1 ≤ i ≤ n). Valerii says that every two non-intersecting subarrays of a have different sums of elements. You want to determine if he ...
```python import sys #from collections import deque #from functools import * #from fractions import Fraction as f from copy import * from bisect import * #from heapq import * from math import gcd,ceil,sqrt from itertools import permutations as prm,product def eprint(*args): print(*args, file=sys.stderr) zz=1 #...
vfc_77613
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n6\n4 3 0 1 2 0\n2\n2 5\n", "output": "YES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3\n1 2 3\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
148_A. Insomnia cure
Solve the following coding problem using the programming language python: «One dragon. Two dragon. Three dragon», — the princess was counting. She had trouble falling asleep, and she got bored of counting lambs when she was nine. However, just counting dragons was boring as well, so she entertained herself at best sh...
```python kill=[] for i in range(4): a=int(input()) kill.append(a) d=int(input()) count=0 for i in range(1,d+1): for j in kill: if i%j==0: count+=1 break else: count+=0 print(count) ```
vfc_77621
{ "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\n4\n5\n24\n", "output": "17\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n3\n4\n12\n", "output": "12\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
1511_E. Colorings and Dominoes
Solve the following coding problem using the programming language python: You have a large rectangular board which is divided into n × m cells (the board has n rows and m columns). Each cell is either white or black. You paint each white cell either red or blue. Obviously, the number of different ways to paint them i...
```python mod = 998244353 m,n = map(int,input().split()) mat = [[0]*n for _ in range(m)] t = 0 res = 0 com = [0] * (max(m,n) + 2) com[2] = 1 pow2 = 1 for i in range(3,max(m,n)+1): pow2 = (pow2 << 1) % mod com[i] = (com[i-1] + 2*com[i-2] + pow2) % mod for i in range(m): s = input() for j in range(n)...
vfc_77625
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\noo\no*\n", "output": "\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\n**oo\noo*o\n**oo\n", "output": "\n144\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
1539_C. Stable Groups
Solve the following coding problem using the programming language python: There are n students numerated from 1 to n. The level of the i-th student is a_i. You need to split the students into stable groups. A group of students is called stable, if in the sorted array of their levels no two neighboring elements differ ...
```python n,k,x =list(map(int ,input().split())) arr = list(map(int ,input().split())) arr.sort() groups =1 re = [] for i in range(n-1): diff = arr[i+1]-arr[i] if diff>x : if x==0: groups+=1 continue if diff%x==0: diff = diff//x -1 else: diff =diff//x re...
vfc_77629
{ "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 2 3\n1 1 5 8 12 13 20 22\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13 0 37\n20 20 80 70 70 70 420 5 1 5 1 60 90\n", "output": "3\n", "type": "stdin_std...
code_contests
verifiable_code
165_E. Compatible Numbers
Solve the following coding problem using the programming language python: Two integers x and y are compatible, if the result of their bitwise "AND" equals zero, that is, a & b = 0. For example, numbers 90 (10110102) and 36 (1001002) are compatible, as 10110102 & 1001002 = 02, and numbers 3 (112) and 6 (1102) are not c...
vfc_77633
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 6 3 6\n", "output": "-1 -1 -1 -1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n10 6 9 8 2\n", "output": "-1 8 2 2 8 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
207_D8. The Beaver's Problem - 3
Solve the following coding problem using the programming language python: The Smart Beaver from ABBYY came up with another splendid problem for the ABBYY Cup participants! This time the Beaver invites the contest participants to check out a problem on sorting documents by their subjects. Let's describe the problem: Y...
vfc_77641
{ "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": "36000\nU.K. MONEY MARKET DEFICIT REMOVED\nLONDON, April 9 - The Bank of England said it has satisfied\nits revised estimate of today's shortfall in the money market,\nproviding 261 mln stg assistance in afternoon operations.\nThe B...
code_contests
verifiable_code
233_B. Non-square Equation
Solve the following coding problem using the programming language python: Let's consider equation: x2 + s(x)·x - n = 0, where x, n are positive integers, s(x) is the function, equal to the sum of digits of number x in the decimal number system. You are given an integer n, find the smallest positive integer root of...
```python # your code goes here n=int(input()) def s(x): return sum(int(i) for i in str(x)) x=int(n**0.5) d=0 while x>=0 and d<=50: if(x*x+s(x)*x==n): # print(x) break d+=1 x-=1 if d>50: x=-1 print(x) ```
vfc_77645
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "110\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", ...
code_contests
verifiable_code
259_A. Little Elephant and Chess
Solve the following coding problem using the programming language python: The Little Elephant loves chess very much. One day the Little Elephant and his friend decided to play chess. They've got the chess pieces but the board is a problem. They've got an 8 × 8 checkered board, each square is painted either black or ...
```python flag=True for i in range(8): k=input() if k!='BWBWBWBW' and k!='WBWBWBWB': flag=False if (flag): print ("YES") else: print ("NO") ```
vfc_77649
{ "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": "WBWBWBWB\nBWBWBWBW\nBWBWBWBW\nBWBWBWBW\nWBWBWBWB\nWBWBWBWB\nBWBWBWBW\nWBWBWBWB\n", "output": "YES", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
282_A. Bit++
Solve the following coding problem using the programming language python: The classic programming language of Bitland is Bit++. This language is so peculiar and complicated. The language is that peculiar as it has exactly one variable, called x. Also, there are two operations: * Operation ++ increases the value of...
```python n = int(input()) counter= 0 for i in range(n): if input().find('+') > -1: counter = counter + 1 else: counter = counter - 1 print(counter) ```
vfc_77653
{ "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\n++X\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nX++\n--X\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
304_E. Minimum Modular
Solve the following coding problem using the programming language python: You have been given n distinct integers a1, a2, ..., an. You can remove at most k of them. Find the minimum modular m (m > 0), so that for every pair of the remaining integers (ai, aj), the following unequality holds: <image>. Input The first ...
vfc_77657
{ "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": "7 0\n0 2 3 6 7 12 18\n", "output": "13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 1\n0 2 3 6 7 12 18\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
331_A1. Oh Sweet Beaverette
Solve the following coding problem using the programming language python: — Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything s...
```python from collections import defaultdict n = int(input()) a = list(map(int,input().split())) same = defaultdict(list) only_positive = [max(0,x) for x in a] partial_sum = [0 for i in range(n+1)] for i in range(1,n+1): partial_sum[i] = partial_sum[i-1]+only_positive[i-1] for i in range(n): same[a[i]].append(...
vfc_77661
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 1 2\n", "output": "8 1\n1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 -2 3 1 -2\n", "output": "5 2\n2 5 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
376_E. Circling Round Treasures
Solve the following coding problem using the programming language python: You have a map as a rectangle table. Each cell of the table is either an obstacle, or a treasure with a certain price, or a bomb, or an empty cell. Your initial position is also given to you. You can go from one cell of the map to a side-adjace...
vfc_77669
{ "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 4\n....\n.S1.\n....\n....\n10\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 8\n........\n........\n....1B..\n.S......\n....2...\n3.......\n........\n100\n-100\n100\n...
code_contests
verifiable_code
399_B. Red and Blue Balls
Solve the following coding problem using the programming language python: User ainta has a stack of n red and blue balls. He can apply a certain operation which changes the colors of the balls inside the stack. * While the top ball inside the stack is red, pop the ball from the top of the stack. * Then replace t...
```python n = int(input()) s = list(input()) o = 0 #s.reverse() # while s.count("B") > 0: # while s[-1] == "R": # s.pop() # s[-1] = "R" # while len(s) < n: # s.append("B") # o += 1 # print(s) try: index = s.index("B") o += pow(2, index) while True: index = s.index("B", index + 1) o += ...
vfc_77673
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nRBBR\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\nRBBRR\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
421_C. Online Meeting
Solve the following coding problem using the programming language python: Nearly each project of the F company has a whole team of developers working on it. They often are in different rooms of the office in different cities and even countries. To keep in touch and track the results of the project, the F company condu...
```python #!/Library/Frameworks/Python.framework/Versions/3.6/bin/python3 ''' Created on 13/09/2018 @author: ernesto ''' n, m = [int(x) for x in input().strip().split(" ")] posibles_jefes = set(range(1, n + 1)) anteriores = set() posteriores = set() continuos = [True] * (n + 1) mencionados = set() posibles_jefes_men...
vfc_77677
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n+ 1\n- 2\n", "output": "1\n3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n+ 1\n+ 2\n- 2\n- 1\n", "output": "4\n1 3 4 5 \n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
448_A. Rewards
Solve the following coding problem using the programming language python: Bizon the Champion is called the Champion for a reason. Bizon the Champion has recently got a present — a new glass cupboard with n shelves and he decided to put all his presents there. All the presents can be divided into two types: medals an...
```python import math a1,a2,a3 = list(map(int,input().split())) b1,b2,b3 = list(map(int,input().split())) n = int(input()) s1 = a1+a2+a3 s2 = b1+b2+b3 s3 = math.ceil(s1/5)+math.ceil(s2/10) if s3 <= n: print("YES") else : print("NO") ```
vfc_77681
{ "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 0 0\n1 0 0\n1\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 3\n2 3 4\n2\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
46_B. T-shirts from Sponsor
Solve the following coding problem using the programming language python: One day a well-known sponsor of a well-known contest decided to give every participant of the contest a T-shirt as a present. A natural problem occurred: on the one hand, it is not clear how many T-shirts of what sizes should be ordered, and on ...
```python i=input g=range l=list(map(int,i().split())) d={'S':0,'M':1,'L':2,'XL':3,'XXL':4} r={0:'S',1:'M',2:'L',3:'XL',4:'XXL'} n=int(i()) for x in g(n): s=i() if(l[d[s]]): l[d[s]]-=1 res=s else: f=0 for _ in g(5): if(d[s]+_<5 and l[d[s]+_]): f=_ break elif(d[s]-_>-1 and l[d[s]-_]): f=-_ ...
vfc_77685
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 0 2 0 1\n3\nXL\nXXL\nM\n", "output": "XXL\nL\nL\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0 2 1 1\n4\nS\nXXL\nL\nM\n", "output": "S\nXXL\nL\nL\n", "type": "stdin_stdo...
code_contests
verifiable_code
492_C. Vanya and Exams
Solve the following coding problem using the programming language python: Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade ai for the i-th exam....
```python """*There is no salvation without suffering*""" """* Read the damn question carefully*""" n, r, avg = map(int, input().split()) needed = n * avg current = 0 ammo = [] for i in range(n): a, b = map(int, input().split()) current += a if a < r: ammo.append([b, r - a]) needed -= current wr...
vfc_77689
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 5 4\n5 2\n5 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 4\n5 2\n4 7\n3 1\n3 2\n2 5\n", "output": "4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
516_B. Drazil and Tiles
Solve the following coding problem using the programming language python: Drazil created a following problem about putting 1 × 2 tiles into an n × m grid: "There is a grid with some cells that are empty and some cells that are occupied. You should use 1 × 2 tiles to cover all empty cells and no two tiles should cover...
vfc_77693
{ "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 4\n*..*\n....\n", "output": "*<>*\n<><>\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n..**\n*...\n*.**\n....\n", "output": "<>**\n*^<>\n*v**\n<><>\n", "type": "stdin_s...
code_contests
verifiable_code
56_D. Changing a String
Solve the following coding problem using the programming language python: There is a string s, consisting of capital Latin letters. Let's denote its current length as |s|. During one move it is allowed to apply one of the following operations to it: * INSERT pos ch — insert a letter ch in the string s in the posit...
```python import sys from array import array # noqa: F401 def input(): return sys.stdin.buffer.readline().decode('utf-8') s, t = input().rstrip(), input().rstrip() n, m = len(s), len(t) dp = [[10**9] * (m + 2) for _ in range(n + 2)] dp[n][m] = 0 prev = [[(-1, -1)] * (m + 2) for _ in range(n + 2)] for i in ra...
vfc_77701
{ "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": "ACCEPTED\nWRONGANSWER\n", "output": "10\nREPLACE 1 W\nREPLACE 2 R\nREPLACE 3 O\nREPLACE 4 N\nREPLACE 5 G\nREPLACE 6 A\nINSERT 7 N\nINSERT 8 S\nINSERT 9 W\nREPLACE 11 R\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
591_B. Rebranding
Solve the following coding problem using the programming language python: The name of one small but proud corporation consists of n lowercase English letters. The Corporation has decided to try rebranding — an active marketing strategy, that includes a set of measures to change either the brand (both for the company a...
```python import string N, M = map(int, input().split()) S = input() dic = string.ascii_lowercase for _ in range(M): x, y = input().split() dic = dic.translate(str.maketrans(x+y, y+x)) print(S.translate(str.maketrans(string.ascii_lowercase, dic))) ```
vfc_77705
{ "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": "11 6\nabacabadaba\na b\nb c\na d\ne g\nf a\nb b\n", "output": "cdcbcdcfcdc\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\npolice\np m\n", "output": "molice\n", "type": "s...
code_contests
verifiable_code
632_F. Magic Matrix
Solve the following coding problem using the programming language python: You're given a matrix A of size n × n. Let's call the matrix with nonnegative elements magic if it is symmetric (so aij = aji), aii = 0 and aij ≤ max(aik, ajk) for all triples i, j, k. Note that i, j, k do not need to be distinct. Determine if...
vfc_77713
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 1 2 3\n1 0 3 4\n2 3 0 5\n3 4 5 0\n", "output": "NOT MAGIC\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
661_C. Array Sum
Solve the following coding problem using the programming language python: You are given an array of integers. Calculate the sum of its elements. Input The i-th line of the input contains an integer ai (0 ≤ a ≤ 1000) — the i-th element of the array. The size of the array is between 1 and 10, inclusive. Note that the ...
vfc_77717
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n15\n110\n3\n", "output": "130\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "90\n0\n21\n331\n45\n", "output": "487\n", "type": "stdin_stdout" }, { "fn_name": ...
code_contests
verifiable_code
685_C. Optimal Point
Solve the following coding problem using the programming language python: When the river brought Gerda to the house of the Old Lady who Knew Magic, this lady decided to make Gerda her daughter. She wants Gerda to forget about Kay, so she puts all the roses from the garden underground. Mole, who lives in this garden, ...
vfc_77721
{ "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": "1\n5\n0 0 4\n0 0 -4\n0 4 0\n4 0 0\n1 1 1\n", "output": "0 0 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n3 5 9\n2\n3 5 9\n3 5 9\n", "output": "3 5 9\n3 5 9\n", "type...
code_contests
verifiable_code
708_B. Recover the String
Solve the following coding problem using the programming language python: For each string s consisting of characters '0' and '1' one can define four integers a00, a01, a10 and a11, where axy is the number of subsequences of length 2 of the string s equal to the sequence {x, y}. In these problem you are given four in...
```python import sys def BS(x): l = 1 r = 1000000 while (r-l) > 1: m = (l+r)//2 if m*(m-1)//2 > x: r = m else: l = m if l*(l-1)//2 != x: print("Impossible") sys.exit() return l a00,a01,a10,a11=map(int,input().split()) if (a00 + a01 +...
vfc_77725
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2 2 1\n", "output": "0110", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 3 4\n", "output": "Impossible\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
72_H. Reverse It!
Solve the following coding problem using the programming language python: The 14th of March was the international day of mathematics, because of number π = 3.1415926... In the occasion of this day Goofy Nephews Unity Organization (GNU) wants to publish the fastest program in math at 1:59:26 AM. Now the time is 1:11...
vfc_77729
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "23\n", "output": "32\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "-032\n", "output": "-23\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
750_E. New Year and Old Subsequence
Solve the following coding problem using the programming language python: A string t is called nice if a string "2017" occurs in t as a subsequence but a string "2016" doesn't occur in t as a subsequence. For example, strings "203434107" and "9220617" are nice, while strings "20016", "1234" and "20167" aren't nice. T...
vfc_77733
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "15 5\n012016662091670\n3 4\n1 14\n4 15\n1 13\n10 15\n", "output": "-1\n2\n1\n-1\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 3\n20166766\n1 8\n1 7\n2 8\n", "output": "4\n3\n...
code_contests
verifiable_code
774_C. Maximum Number
Solve the following coding problem using the programming language python: Stepan has the newest electronic device with a display. Different digits can be shown on it. Each digit is shown on a seven-section indicator like it is shown on the picture below. <image> So, for example, to show the digit 3 on the display, 5...
```python n = input() n = int(n) ans = "" if(n % 2 == 1): ans += "7" n -= 3 while(n > 0): ans += "1" n -= 2 print(ans) ```
vfc_77737
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8343\n", ...
code_contests
verifiable_code
799_C. Fountains
Solve the following coding problem using the programming language python: Arkady plays Gardenscapes a lot. Arkady wants to build two new fountains. There are n available fountains, for each fountain its beauty and cost are known. There are two types of money in the game: coins and diamonds, so each fountain cost can b...
```python import operator fc = [] fd = [] n, c, d = map(int, input().split()) for _ in range(n): b, p, m = input().split() b, p = int(b), int(p) if m == 'C': if p <= c: fc.append((b, p)) else: if p <= d: fd.append((b, p)) fc.sort(key=operator.itemgetter(0), re...
vfc_77741
{ "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 10 10\n5 5 C\n5 5 C\n10 11 D\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4 5\n2 5 C\n2 1 D\n", "output": "0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
819_C. Mister B and Beacons on Field
Solve the following coding problem using the programming language python: Mister B has a house in the middle of a giant plain field, which attracted aliens life. For convenience, aliens specified the Cartesian coordinate system on the field in such a way that Mister B's house has coordinates (0, 0). After that they se...
vfc_77745
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 1 1\n2 1 1\n1 1 3\n1 5 1\n2 2 1\n1 1 2\n10 6 18\n2 103 2\n13 1 13\n", "output": "4\n7\n171\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2 3 1000000\n1000000 1 2\n1000000 1000000...
code_contests
verifiable_code
845_A. Chess Tourney
Solve the following coding problem using the programming language python: Berland annual chess tournament is coming! Organizers have gathered 2·n chess players who should be divided into two teams with n people each. The first team is sponsored by BerOil and the second team is sponsored by BerMobile. Obviously, organ...
```python n = int(input()) a = sorted(map(int, input().split())) print('YES' if a[n] > a[n-1] else 'NO') # Made By Mostafa_Khaled ```
vfc_77749
{ "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\n1 3 2 4\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3 3\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
865_C. Gotta Go Fast
Solve the following coding problem using the programming language python: You're trying to set the record on your favorite video game. The game consists of N levels, which must be completed sequentially in order to beat the game. You usually complete each level as fast as possible, but sometimes finish a level slower....
vfc_77753
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 8\n2 8 81\n", "output": "3.140000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 30\n20 30 80\n3 9 85\n", "output": "31.400000000\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
913_F. Strongly Connected Tournament
Solve the following coding problem using the programming language python: There is a chess tournament in All-Right-City. n players were invited to take part in the competition. The tournament is held by the following rules: 1. Initially, each player plays one game with every other player. There are no ties; 2. A...
vfc_77761
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4 6\n", "output": "142606340\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2\n", "output": "598946623\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
935_F. Fafa and Array
Solve the following coding problem using the programming language python: Fafa has an array A of n positive integers, the function f(A) is defined as <image>. He wants to do q queries of two types: * 1 l r x — find the maximum possible value of f(A), if x is to be added to one element in the range [l, r]. You can c...
vfc_77765
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 1 1 1 1\n5\n1 2 4 1\n2 2 3 1\n2 4 4 2\n2 3 4 1\n1 3 3 2\n", "output": "2\n8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 4 5\n4\n1 2 4 2\n2 2 4 1\n2 3 4 1\n1 2 4 2\n", ...
code_contests
verifiable_code
961_E. Tufurama
Solve the following coding problem using the programming language python: One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 online ful...
```python from sys import stdin from sys import setrecursionlimit as SRL; SRL(10**7) rd = stdin.readline rrd = lambda: map(int, rd().strip().split()) n = int(input()) a = list(rrd()) bit = [0]*(n+100) def ins(x): while x<=n: bit[x] += 1 x += x&(-x) def get(l): tot = 0 while l: to...
vfc_77769
{ "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\n1 2 3 4 5\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
989_D. A Shade of Moonlight
Solve the following coding problem using the programming language python: Gathering darkness shrouds the woods and the world. The moon sheds its light on the boat and the river. "To curtain off the moonlight should be hardly possible; the shades present its mellow beauty and restful nature." Intonates Mino. "See? Th...
```python # Codeforces Round #487 (Div. 2)import collections from functools import cmp_to_key #key=cmp_to_key(lambda x,y: 1 if x not in y else -1 ) import sys def getIntList(): return list(map(int, input().split())) import bisect N,L,WM = getIntList() z = {} z[-1] = {1:[], -1:[]} z[0...
vfc_77773
{ "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 1 2\n-2 1\n2 1\n3 -1\n5 -1\n7 -1\n", "output": "4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
amplification-battle
Solve the following coding problem using the programming language python: See Russian Translation Adam and Bob are playing a game. The game is parameterized by the three integers a,b,c. They start out with the integer 1, with Adam going first. Suppose the current integer is S. On a player's turn, he may change the cu...
```python t = input() for i in xrange(t): a,b,c = map(int, raw_input().split()) y = 0 while c!=1: if y%2==0: l = b else: l = a k = c/l q = (1.0*c)/l if k==q: c=k else: c = k+1 y+=1 if y%2==0: print 'Bob' else: print 'Adam' ```
vfc_77777
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2 2 10\n2 10 20\n10 10 3\n2 3 100\n22 40 500\n2 100 1000000000000000000\n\nSAMPLE", "output": "Bob\nBob\nAdam\nAdam\nBob\nAdam\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000\n6 8...
code_contests
verifiable_code
carols-in-morning-1
Solve the following coding problem using the programming language python: When the day begins, it's time to sing carols. Unfortunately, not all the family members know the lyrics to the same carols. Everybody knows at least one, though. You are given a array of lyrics. The j-th character of the i-th element of lyrics ...
```python def arr(p,ar): n=[] for i in ar: if i[p]=='N': n.append(i) return n t=input() for i in range(t): n=input() st=raw_input().split() ar=[] for k in range(len(st[0])): p=k i=0 c=1 rem=st while(i<n): rem=arr(p%len(st[0]),rem) i=n-len(rem) #print rem if len(rem)>0: p+=1 c+=...
vfc_77781
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\nYN NY\n3\nYN YY YN\n6\nYNN YNY YNY NYY NYY NYN\n\nSAMPLE", "output": "2\n1\n2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
diagonal-difference-17
Solve the following coding problem using the programming language python: Given a square matrix of size N×NN×N, calculate the absolute difference between the sums of its diagonals. Input Format The first line contains a single integer, NN. The next NN lines denote the matrix's rows, with each line containing NN spac...
```python n=input() prim=[] seco=[] arr=[] k=0 while k<n: arr=[] arr=list(map(int,raw_input().split())) rarr=arr[::-1] prim.append(arr[k]) seco.append(rarr[k]) k=k+1 addprim=0 addsec=0 for item in prim: addprim=addprim+item for key in seco: addsec=addsec+key print abs(addprim - addsec) ```
vfc_77785
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n11 2 4\n4 5 6\n10 8 -12\n\nSAMPLE", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n-10 3 0 5 -4\n2 -1 0 2 -8\n9 -2 -5 6 0\n9 -7 4 8 -2\n3 7 8 -5 0", "output": "3...
code_contests
verifiable_code
geeko-and-tree-2
Solve the following coding problem using the programming language python: Geeko is very happy because his exam are over so he is busy in playing games and watching movies, today he has watched lord of the rings He got so fascinated after watching the movie that he is seeing himself in the movie in his dreams. Sud...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' #print 'Hello World!' t = int(raw_input()) while t : k, n = map(int, raw_input().split()) nodes = 1 + k * (k ** n - 1) / (k -1) m = 0 while(nodes): m += nodes%...
vfc_77789
{ "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 3\n3 2\n\nSAMPLE", "output": "6\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2000\n8 294\n9 307\n7 310\n3 677\n10 952\n6 902\n9 86\n7 191\n5 423\n5 992\n6 306\n5 873\n3 504\n3 4...
code_contests
verifiable_code
last-ant-on-road
Solve the following coding problem using the programming language python: There are 'n' ants on a 'n+1' length rod. The ants are numbered from 1 to n and are initially placed at positions starting from position 1 till position n. They are moving either in left direction (denoted by '-1') or in the right direction (den...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' T = input() for t in xrange(T): n = input() directions = map(int, raw_input().split()) p = len([x for x in directions if x == 1]) n = len([x for x in directions if x == -1...
vfc_77793
{ "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\n1 1\n8\n1 1 -1 1 1 1 -1 1\n\nSAMPLE", "output": "1\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n-1 -1", "output": "2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
monk-and-the-collision
Solve the following coding problem using the programming language python: As the Monk is also taking part in the CodeMonk Series, this week he learned about hashing. Now he wants to practice some problems. So he came up with a simple problem. Firstly, he made a hash function F such that: F(x) = x % 10 Now using this...
```python # encoding=utf-8 ''' Created on 2015?8?14? @author: limw ''' t = input() for _ in range(t): l = input() kk = raw_input().strip().split(' ') # print kk ss = [] for k1 in kk: ss.append(k1[len(k1) - 1]) ss.sort() # print ss sstr = ''.join(ss) # print sstr co = 0 ...
vfc_77797
{ "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\n1 2 3\n4\n1 1 2 3\n\nSAMPLE", "output": "0\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n100\n71935 12426 60607 14999 24788 53252 88601 42859 45596 30680 87885 51124 77664 8...
code_contests
verifiable_code
performax
Solve the following coding problem using the programming language python: Chinna is preparing for an online entrance examination. The performance in the examination is measured on a rating scale of 1 to 10^6. Recently, Chinna came across an advertisement of an institution which guarantees an increase of 'd' in the rat...
```python n = input() d = input() arr = map(int,raw_input().split()) time = 0 prev_rating = arr[0] for i in range(1,n): current_rating = arr[i] if current_rating<=prev_rating: temp = (prev_rating- current_rating) /d values = [temp,temp+1] index = 0 while current_rating<=prev_rating: current_rating += value...
vfc_77801
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n82\n61 28 956 75 542\n\nSAMPLE", "output": "18", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
roy-and-maximum-xor
Solve the following coding problem using the programming language python: Roy has a matrix of size NxN. Rows and Columns are numbered from 0 to N-1. j^th column of i^th row contains i xor j. In other words, Matrix[i][j] = i ^ j where 0 ≤ i,j < N. ( ^ is a bitwise operation used in C/C++ for xor, please use appropr...
```python for ldskfaj in xrange(int(raw_input())): n = int(raw_input()) next_max_2_n = 1<<(len(bin(n)) - 2) if(n<<1 == next_max_2_n): print n-1, n else: print next_max_2_n - 1, next_max_2_n - 2*(next_max_2_n - n) ```
vfc_77805
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "900\n101\n102\n103\n104\n105\n106\n107\n108\n109\n110\n111\n112\n113\n114\n115\n116\n117\n118\n119\n120\n121\n122\n123\n124\n125\n126\n127\n128\n129\n130\n131\n132\n133\n134\n135\n136\n137\n138\n139\n140\n141\n142\n143\n144\n145\n1...