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
214_E. Relay Race
Solve the following coding problem using the programming language python: Furik and Rubik take part in a relay race. The race will be set up on a large square with the side of n meters. The given square is split into n × n cells (represented as unit squares), each cell has some number. At the beginning of the race Fu...
vfc_45581
{ "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": "1\n5\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n11 14\n16 12\n", "output": "53", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
238_E. Meeting Her
Solve the following coding problem using the programming language python: Urpal lives in a big city. He has planned to meet his lover tonight. The city has n junctions numbered from 1 to n. The junctions are connected by m directed streets, all the roads have equal length. Urpal lives in junction a and the date is p...
vfc_45585
{ "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 8 1 7\n1 2\n1 3\n2 4\n3 4\n4 6\n4 5\n6 7\n5 7\n3\n2 7\n1 4\n5 7\n", "output": "2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
287_C. Lucky Permutation
Solve the following coding problem using the programming language python: A permutation p of size n is the sequence p1, p2, ..., pn, consisting of n distinct integers, each of them is from 1 to n (1 ≤ pi ≤ n). A lucky permutation is such permutation p, that any integer i (1 ≤ i ≤ n) meets this condition ppi = n - i +...
```python n=int(input()) L=[0]*(n+1) X=[False]*(n+1) if(n%4!=0 and n%4!=1): print(-1) else: for i in range(1,n+1): if(X[i]): continue X[i]=True X[n-i+1]=True for j in range(i+1,n+1): if(X[j]): continue X[j]=True ...
vfc_45593
{ "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\n", "output": "1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n", "output": "2 5 3 1 4 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n",...
code_contests
verifiable_code
312_C. The Closest Pair
Solve the following coding problem using the programming language python: Currently Tiny is learning Computational Geometry. When trying to solve a problem called "The Closest Pair Of Points In The Plane", he found that a code which gave a wrong time complexity got Accepted instead of Time Limit Exceeded. The problem...
```python n,k = map(int,input().split()) if n*(n-1) <= k*2: print('no solution') else: for i in range(n): print(0,i) ```
vfc_45597
{ "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 100\n", "output": "no solution\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n", "output": "0 0\n0 1\n0 2\n0 3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
335_A. Banana
Solve the following coding problem using the programming language python: Piegirl is buying stickers for a project. Stickers come on sheets, and each sheet of stickers contains exactly n stickers. Each sticker has exactly one character printed on it, so a sheet of stickers can be described by a string of length n. Pie...
```python s = input() n = int(input()) symb_cnt = {} for c in s: symb_cnt[c] = symb_cnt[c] + 1 if c in symb_cnt else 1 for cnt in range(1, len(s) + 1): s1 = "" for c in symb_cnt: s1 += c * ((symb_cnt[c] + cnt - 1) // cnt) if len(s1) <= n: for i in range(n - len(s1)): s1 += 'a' print(cnt) print(s1) exi...
vfc_45601
{ "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": "banana\n3\n", "output": "3\nabn", "type": "stdin_stdout" }, { "fn_name": null, "input": "banana\n2\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
358_A. Dima and Continuous Line
Solve the following coding problem using the programming language python: Dima and Seryozha live in an ordinary dormitory room for two. One day Dima had a date with his girl and he asked Seryozha to leave the room. As a compensation, Seryozha made Dima do his homework. The teacher gave Seryozha the coordinates of n d...
```python n = int(input()) lst = list(map(int,input().split())) a = list(zip(lst,lst[1:])) record = [] for x in a: s,e = min(x[0],x[1]),max(x[0],x[1]) for y in record: if y[0]<s<y[1]<e or s<y[0]<e<y[1]: exit(print("yes")) record.append((s,e)) print("no") ```
vfc_45605
{ "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\n0 10 5 15\n", "output": "yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 15 5 10\n", "output": "no\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
401_D. Roman and Numbers
Solve the following coding problem using the programming language python: Roman is a young mathematician, very famous in Uzhland. Unfortunately, Sereja doesn't think so. To make Sereja change his mind, Roman is ready to solve any mathematical problem. After some thought, Sereja asked Roma to find, how many numbers are...
```python d = '0123456789ABCDEFGH' prev = {d[i]: d[i - 1] for i in range(1, 18)} next = {d[i]: d[i + 1] for i in range(17)} n, m = raw_input().split() p, m = ['0'] * 10, int(m) k, l = 1, len(n) for x in map(int, n): p[x] = next[p[x]] a = ''.join(p) u, v = {a: [0] * m}, {} u[a][0] = 1 for r in range(1, l + 1): if...
vfc_45613
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7067678 8\n", "output": "47", "type": "stdin_stdout" }, { "fn_name": null, "input": "104 2\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "22...
code_contests
verifiable_code
429_E. Points and Segments
Solve the following coding problem using the programming language python: Iahub isn't well prepared on geometry problems, but he heard that this year there will be a lot of geometry problems on the IOI selection camp. Scared, Iahub locked himself in the basement and started thinking of new problems of this kind. One o...
vfc_45617
{ "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": "6\n1 5\n1 3\n3 5\n2 10\n11 11\n12 12\n", "output": "0 1 1 0 0 0 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 2\n2 3\n", "output": "0 1 ", "type": "stdin_stdout" } ...
code_contests
verifiable_code
451_C. Predict Outcome of the Game
Solve the following coding problem using the programming language python: There are n games in a football tournament. Three teams are participating in it. Currently k games had already been played. You are an avid football fan, but recently you missed the whole k games. Fortunately, you remember a guess of your frie...
```python from sys import * t=int(stdin.readline()) for i in range(t): n,k,d1,d2=(int(z) for z in stdin.readline().split()) vars=((2*d1+d2,2*d2+d1),(2*max(d1,d2)-min(d1,d2),d1+d2)) y=False for i in vars: if i[0]<=k and i[0]%3==k%3 and n-k-i[1]>=0 and (n-i[1]-k)%3==0: print("yes") ...
vfc_45621
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n3 0 0 0\n3 3 0 0\n6 4 1 0\n6 3 3 0\n3 3 3 2\n", "output": "yes\nyes\nyes\nno\nno\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n3 0 0 0\n3 3 0 0\n6 4 1 0\n6 6 3 0\n3 3 3 2\n", ...
code_contests
verifiable_code
474_B. Worms
Solve the following coding problem using the programming language python: It is lunch time for Mole. His friend, Marmot, prepared him a nice game for lunch. Marmot brought Mole n ordered piles of worms such that i-th pile contains ai worms. He labeled all these worms with consecutive integers: worms in first pile are...
```python from bisect import bisect_left n = int(input()) n1 = input().split() m = int(input()) m1 = input().split() lista = [] valor = 0 for e in n1: valor += int(e) lista.append(valor) for e in m1: print(bisect_left(lista, int(e)) + 1) ```
vfc_45625
{ "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 7 3 4 9\n3\n1 25 11\n", "output": "1\n5\n3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
521_B. Cubes
Solve the following coding problem using the programming language python: Once Vasya and Petya assembled a figure of m cubes, each of them is associated with a number between 0 and m - 1 (inclusive, each number appeared exactly once). Let's consider a coordinate system such that the OX is the ground, and the OY is dir...
```python import heapq def coor_neighbor(coor, dxs, dys): x, y = coor for dx in dxs: for dy in dys: yield x + dx, y + dy def coor_bottoms(coor): return coor_neighbor(coor, (-1, 0, 1), (-1, )) def coor_tops(coor): return coor_neighbor(coor, (-1, 0, 1), (1, )) def coor_sibs(coor...
vfc_45633
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 1\n1 0\n0 1\n", "output": "19\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 0\n0 1\n0 2\n0 3\n0 4\n", "output": "2930\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
548_D. Mike and Feet
Solve the following coding problem using the programming language python: Mike is the president of country What-The-Fatherland. There are n bears living in this country besides Mike. All of them are standing in a line and they are numbered from 1 to n from left to right. i-th bear is exactly ai feet high. <image> A...
```python from sys import stdin, stdout def input(): return stdin.readline().strip() def print(x, end='\n'): stdout.write(str(x) + end) n, lst = int(input()), list(map(int, input().split())) nse, pse, stk, ans = [n for i in range(n)], [-1 for i in range(n)], [], [0 for i in range(n+1)] for i in range(n): while stk...
vfc_45637
{ "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": "10\n1 2 3 4 5 4 3 2 1 6\n", "output": "6 4 4 3 3 2 2 1 1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "19\n519879446 764655030 680293934 914539062 744988123 317088317 653721289 2398622...
code_contests
verifiable_code
575_A. Fibonotci
Solve the following coding problem using the programming language python: Fibonotci sequence is an integer recursive sequence defined by the recurrence relation Fn = sn - 1·Fn - 1 + sn - 2·Fn - 2 with F0 = 0, F1 = 1 Sequence s is an infinite and almost cyclic sequence with a cycle of length N. A sequence s is call...
vfc_45641
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 8\n3\n1 2 1\n2\n7 3\n5 4\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 10007\n3\n29491273 336201633 1060883\n1\n3 1589311\n", "output": "317\n", "type":...
code_contests
verifiable_code
618_A. Slime Combining
Solve the following coding problem using the programming language python: Your friend recently gave you some slimes for your birthday. You have n slimes all initially with value 1. You are going to play a game with these slimes. Initially, you put a single slime by itself in a row. Then, you will add the other n - 1 ...
```python def answer(n): x=[] while(n!=0): temp=n%2 n//=2 x.append(temp) for i in reversed(range(len(x))): if x[i]==1: print(i+1,end=' ') n=int(input()) answer(n) ```
vfc_45649
{ "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": "8\n", "output": "4 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", "output": "2 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
638_C. Road Improvement
Solve the following coding problem using the programming language python: In Berland there are n cities and n - 1 bidirectional roads. Each road connects some pair of cities, from any city you can get to any other one using only the given roads. In each city there is exactly one repair brigade. To repair some road, y...
```python import sys import threading from collections import defaultdict def put(): return map(int, input().split()) def dfs(i, p, m): cnt = 1 z = 0 for j in tree[i]: if j==p: continue if cnt==m: cnt+=1 index = edge_index[(i,j)] ans[cnt].append(index) z = max(d...
vfc_45653
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n3 4\n5 4\n3 2\n1 3\n4 6\n", "output": "3\n2 4 2\n1 1\n2 5 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2\n3 4\n3 2\n", "output": "2\n2 1 2 \n1 3 \n", "type": "stdi...
code_contests
verifiable_code
666_A. Reberland Linguistics
Solve the following coding problem using the programming language python: First-rate specialists graduate from Berland State Institute of Peace and Friendship. You are one of the most talented students in this university. The education is not easy because you need to have fundamental knowledge in different areas, whic...
```python from sys import * setrecursionlimit(200000) d = {} t = set() s = input() + ' ' def gen(l, ll): if (l, ll) in t: return t.add((l, ll)) if l > 6: d[s[l - 2 : l]] = 1 if s[l - 2 : l] != s[l : ll]: gen(l - 2, l) if l > 7: d[s[l - 3 : l]] = 1 if s[l - 3 : l] != s[l :...
vfc_45657
{ "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": "abaca\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abacabaca\n", "output": "3\naca\nba\nca\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
733_B. Parade
Solve the following coding problem using the programming language python: Very soon there will be a parade of victory over alien invaders in Berland. Unfortunately, all soldiers died in the war and now the army consists of entirely new recruits, many of whom do not even know from which leg they should begin to march. ...
```python n = int(input()) L, R = 0, 0 D = [] for i in range(n): l, r = map(int, input().split()) L += l R += r D.append((l, r)) ans = abs(L - R) num = 0 for i in range(n): l, r = D[i] L1 = L - l + r R1 = R - r + l if ans < abs(L1 - R1): ans = abs(L1 - R1) num = i + 1 p...
vfc_45669
{ "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 5\n5 6\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n5 9\n1 3\n4 8\n4 5\n23 54\n12 32\n", "output": "0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
757_C. Felicity is Coming!
Solve the following coding problem using the programming language python: It's that time of the year, Felicity is around the corner and you can see people celebrating all around the Himalayan region. The Himalayan region has n gyms. The i-th gym has gi Pokemon in it. There are m distinct Pokemon types in the Himalayan...
```python # ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq, bisect import sys from collections import deque, defaultdict,Counter from fractions import Fraction import sys import threading from collections import defaultdict threading.sta...
vfc_45673
{ "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 3\n3 1 2 3\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n2 1 2\n2 2 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
802_H. Fake News (medium)
Solve the following coding problem using the programming language python: Thanks to your help, Heidi is confident that no one can fool her. She has now decided to post some fake news on the HC2 Facebook page. However, she wants to be able to communicate to the HC2 committee that the post is fake, using some secret phr...
```python def rek(k): if k == 1: return ('a', 'a') elif k == 2: return ('aa', 'a') s, p = rek((k - 1) // 2) x = chr(ord(p[-1]) + 1) return (p + x * (2 - k % 2) + s[len(p):] + 2 * x, p + x) s, p = rek(int(input())) print(s, p) ```
vfc_45681
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "aa a", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n", "output": "abbbb ab\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n...
code_contests
verifiable_code
86_E. Long sequence
Solve the following coding problem using the programming language python: A sequence a0, a1, ... is called a recurrent binary sequence, if each term ai (i = 0, 1, ...) is equal to 0 or 1 and there exist coefficients <image> such that an = c1·an - 1 + c2·an - 2 + ... + ck·an - k (mod 2), for all n ≥ k. Assume that n...
```python m={2: '11', 3: '101', 4: '1001', 5: '01001', 6: '100001', 7: '1000001', 8: '01110001', 9: '000100001', 10: '0010000001', 11: '01000000001', 12: '100101000001', 13: '1011000000001', 14: '10101000000001', 15: '100000000000001', 16: '0110100000000001', 17: '00100000000000001', 18: '000000100000000001', 19: '1100...
vfc_45693
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "1 1 \n1 1 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "1 0 1 \n1 1 1 \n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
896_D. Nephren Runs a Cinema
Solve the following coding problem using the programming language python: Lakhesh loves to make movies, so Nephren helps her run a cinema. We may call it No. 68 Cinema. <image> However, one day, the No. 68 Cinema runs out of changes (they don't have 50-yuan notes currently), but Nephren still wants to start their bu...
vfc_45697
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 100 0 4\n", "output": "35", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 97 2 3\n", "output": "13", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
917_E. Upside Down
Solve the following coding problem using the programming language python: As we all know, Eleven has special abilities. Thus, Hopper convinced her to close the gate to the Upside Down World with her mind. Upside down monsters like to move between the worlds, so they are going to attack Hopper and Eleven in order to ma...
vfc_45701
{ "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": "10 6 7\n1 3 s\n10 1 d\n2 6 s\n5 2 d\n7 4 l\n8 9 d\n8 10 l\n7 2 d\n8 7 l\ndl\ndssld\nd\nd\nl\nsl\n4 5 4\n3 7 5\n10 6 2\n3 1 4\n7 5 6\n10 9 4\n9 8 4\n", "output": "2\n2\n0\n0\n0\n1\n1\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
93_E. Lostborn
Solve the following coding problem using the programming language python: Igor K. very much likes a multiplayer role playing game WineAge II. Who knows, perhaps, that might be the reason for his poor performance at the university. As any person who plays the game, he is interested in equipping his hero with as good we...
vfc_45705
{ "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": "50 2\n15 8\n", "output": "41\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
967_C. Stairs and Elevators
Solve the following coding problem using the programming language python: In the year of 30XX participants of some world programming championship live in a single large hotel. The hotel has n floors. Each floor has m sections with a single corridor connecting all of them. The sections are enumerated from 1 to m along ...
```python import bisect as bs import sys inp = sys.stdin.readlines() n, m, ladders, elevators, v = [int(x) for x in inp[0].strip().split()] ladders = [int(x) for x in inp[1].strip().split()] elevators = [int(x) for x in inp[2].strip().split()] q = int(inp[3].strip()) qs = [] for i in range(q): qs.append([int(x) f...
vfc_45709
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n", "output": "7\n5\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 1000 1 1 10\n1\n2\n1\n1 900 1 1000\n", "output": "100\n", ...
code_contests
verifiable_code
993_C. Careful Maneuvering
Solve the following coding problem using the programming language python: There are two small spaceship, surrounded by two groups of enemy larger spaceships. The space is a two-dimensional plane, and one group of the enemy spaceships is positioned in such a way that they all have integer y-coordinates, and their x-coo...
```python n, m = map(int, input().strip().split()) y1 = list(map(int, input().strip().split())) y2 = list(map(int, input().strip().split())) y1.sort() y2.sort() u1 = list() u2 = list() p = 0 while p < n: q = p while q < n and y1[q] == y1[p]: q += 1 u1.append((y1[p], q - p)) p = q p = 0 while p ...
vfc_45713
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n1 2 3 4 5\n1 2 3 4 5\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 9\n1 2 3\n1 2 3 7 8 9 11 12 13\n", "output": "9\n", "type": "stdin_stdout" } ...
code_contests
verifiable_code
assorted-arrangement-3
Solve the following coding problem using the programming language python: You have a set of n distinct positive numbers. You also have m colors. Your colors are labeled from 1 to m. You're also given a list c with m distinct integers. You paint the numbers according to the following rules: For each i in order from 1 ...
```python # get number of integers and noumber of colours n, m = map(int, raw_input().split()) # paint integer c = map(int, raw_input().split()) c.insert(0, c[0]) my_ints = map(int, raw_input().split()) result = [] result.append(c[my_ints[0]]) # for every integer in my_ints for integer in range(1, len(my_ints)): ...
vfc_45717
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4\n3 6 7 9\n1 2 1 1 4 3\n\nSAMPLE", "output": "42\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "25 2\n35 70\n1 2 1 2 2 1 1 1 1 1 2 1 2 1 1 2 1 1 2 2 1 1 1 1 1", "output": "1295\n...
code_contests
verifiable_code
children-love-candies
Solve the following coding problem using the programming language python: Today, N candies were placed on the table. At any point, for the purpose of clarity, let X represent the number of candies left on the table. Every day, at 9 PM, if the number of candies remaining is divisible by 2, the child will take exactly X...
```python import sys def main(): I=sys.stdin.readlines() x=int(I[0]) for i in xrange(x): n,t=map(int,I[i+1].split()) for j in xrange(t): if(n%2==0): n=n/2 else: n=n-((n+1)/2) ...
vfc_45721
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2 1\n\nSAMPLE", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3 1\n\nSAMPLE", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
dummy-2
Solve the following coding problem using the programming language python: Hansa is throwing a birthday party. Seeing the extravagant parties thrown by her friends in the past, Hansa too decided to do something unique. Being a Computer Engineer herself, she knew just how to do it. She sent password-protected e-invites ...
```python t=input() while t: a=map(str, raw_input("").split()) base=int(a[0]) s=a[1] k=1 ans=0 while len(s)>0: l=s[-1] if ord(l)<59: l=ord(l)-48 else: l=ord(l)-87 ans+=k*l k*=base s=s[:-1] x=str(ans) print sum(int(i)...
vfc_45725
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n27 1\n4 3201011\n6 5\n29 ffarpr\n3 1\n\nSAMPLE", "output": "1\n14\n5\n49\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n24 je6kbgm514608c5g336fl2jmi46fb5h2j250lhcinhhfl4i90ee9jg...
code_contests
verifiable_code
guess-it-1
Solve the following coding problem using the programming language python: Gazi is a very talented mathematician, recently he discovered the majestic power of the number '9' so he wants to play a game with you. He tells you to pick any real integer [from 10 to 10^200], then subtract sum of digits of this number from th...
```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=input() while t>0: t-=1 s=raw_input() for i in range(0,9): x=s.replace("_",str(i)) if int(x)%9==0: c=i break if c==0: print "0 or 9" e...
vfc_45729
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4_1\n52_2\n63_124\n25141452_5575\n\nSAMPLE", "output": "4\n0 or 9\n2\n8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4_1\n52_2\n63_124\n25141452_5575\n\nS@MPLE", "output": "...
code_contests
verifiable_code
mystery-11
Solve the following coding problem using the programming language python: Solve the mystery HINT : Digital Display Input : First line has an integer T. Next T lines has an integer N in each line. It is guaranteed that N never starts with 0 unless value is equal to zero. Output : Print the output for each test case i...
```python def digital(t): dc = 0 while dc < t: dic = {'0':6, '1':2, '2':5, '3':5, '4':4, '5':5, '6':6, '7':3, '8':7, '9':6} s = raw_input() sum = 0 for e in s: sum = sum + dic[e] print sum dc += 1 t = int(raw_input()) digital(t) ```
vfc_45737
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n1234567\n123456\n1234\n193\n12\n11\n1\n0\n\nSAMPLE", "output": "30\n27\n16\n13\n7\n4\n2\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n29524202908583907894039338661216178710911...
code_contests
verifiable_code
primes-on-rails
Solve the following coding problem using the programming language python: The arrival times of N trains are given in the format hours : minutes : seconds. However for the sake of simplicity the time is considered only in seconds format i.e., 3600hours + 60minutes + seconds (Let's say this x). Now if x is a prime numbe...
```python def primes(n): if n==2: return[2] elif n<2: return [] s=range(3,n+1,2) mroot=n**0.5 half=(n+1)/2 -1 i=0 m=3 while (m<=mroot): if s[i]: j=(m*m-3)/2 s[j]=0 while(j<half): s[j]=0 j+=m i+=1 m=2*i+3 return [2]+[x for x in s if x] p=set(primes(100000)) n=int(raw_input()) arr=[] dep=...
vfc_45741
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n11 57 9\n20 25 53\n8 41 3\n16 58 30\n21 47 8\n\nSAMPLE", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n1 20 0\n3 13 7\n4 0 58\n22 43 19\n5 12 8\n20 3 11\n12 19 55\n2 2...
code_contests
verifiable_code
sauron-eye
Solve the following coding problem using the programming language python: Gandalf the Grey is in trouble as Saurons eye Rearrived in the middle world. Now he has to prepare for the war, But in order to defeat Sauron he has to know the power of saurons eye on the day in which he wants to attack. A...
```python import sys M = 10 ** 9 + 7 MAX_T = 10000 MAX_N = 10**12 _CUTOFF = 1536 cache = {} results = [] def do_calc(n): if n in cache: return cache[n] the_matrix = [3, 1, -1, 0] result = power(the_matrix, n)[1] if n not in cache: cache[n] = result return result def power(matrix, n): result = ...
vfc_45745
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n3\n\nSAMPLE", "output": "1\n8", "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\n27\n28...
code_contests
verifiable_code
swapping-game-6
Solve the following coding problem using the programming language python: Sherlock and Watson are playing swapping game. Watson gives to Sherlock a string S on which he has performed K swaps. You need to help Sherlock in finding the original string. One swap on a string is performed in this way: Assuming 1 indexi...
```python k = int(raw_input()) s = raw_input() l = len(s) def swap(s): j = l - 1 while j: if not j % 2 == 0: e = s[j] s = s[:j] + s[j + 1:] + e j -= 1 return s c = s count = 0 itr = "" while itr != s: itr = swap(c) c = itr count += 1 count = k % count for i in range(count): s = swap(s) print s ...
vfc_45749
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nhrrkhceaate\n\nSAMPLE", "output": "hackerearth\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
who-wants-to-be-a-millionaire-7
Solve the following coding problem using the programming language python: You are on a game show "Who Wants to Be a Millionaire".The host presents you "N" number of closed doors.There is huge prize behind one door while there are sumo wrestlers behind rest of the doors.Initially you are asked to choose a door.After th...
```python for i in range(int(raw_input())): n=int(raw_input()) print ( '%.6f' %(float(n-1)/n)) ```
vfc_45753
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n\nSAMPLE", "output": "0.666667\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "444\n793\n255\n144\n906\n931\n102\n101\n301\n341\n340\n308\n524\n678\n587\n405\n718\n733\n466\n145\n13\...
code_contests
verifiable_code
p00053 Sum of Prime Numbers
Solve the following coding problem using the programming language python: Let p (i) be the i-th prime number from the smallest. For example, 7 is the fourth prime number from the smallest, 2, 3, 5, 7, so p (4) = 7. Given n, the sum of p (i) from i = 1 to n s s = p (1) + p (2) + .... + p (n) Create a program that ou...
```python num = 200000 L = [True] * (num+1) L[0] = False L[1] = False for i in range( 2, int(num**0.5)+ 2 ): if not L[i]: continue for j in range(i*2, num+1, i): L[j] = False p = [ x for x in range(num+1) if L[x] ] while True: n = int(input()) if n == 0: break print(sum(p[0...
vfc_45797
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n9\n0", "output": "5\n100", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n0", "output": "5\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
p00183 Black-and-White
Solve the following coding problem using the programming language python: Consider a tic-tac-toe on a 3x3 board. Tic-tac-toe is a two-player battle game. Decide the first attack and the second attack, one hits Kuroishi and one hits Shiraishi. The winner is the person who puts stones one by one on the board alternately...
```python def f1(c, l): for i in range(3): if c*3 == l[i]: return 1 return 0 def f2(c, l): for i in range(0, 7, 3): s = set(h[i:i+3]) if c in s and len(s) == 1: return 1 return 0 def f3(c, l): if c*3 == l[0]+l[4]+l[8]: return 1 if c*3 == ...
vfc_45801
{ "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": "bbw\nwbw\n+b+\nbwb\nwbw\nwbw\n0", "output": "b\nNA", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00530 Bubble Sort
Solve the following coding problem using the programming language python: Bubble Sort Bubble sort is one of the algorithms for sorting columns. Suppose you want to sort the sequence A of length N in ascending order. Bubble sort exchanges the positions of two adjacent numbers if the magnitude relationship is broken. T...
vfc_45809
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n10\n3\n6\n8\n1", "output": "0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00697 Jigsaw Puzzles for Computers
Solve the following coding problem using the programming language python: Ordinary Jigsaw puzzles are solved with visual hints; players solve a puzzle with the picture which the puzzle shows on finish, and the diverse patterns of pieces. Such Jigsaw puzzles may be suitable for human players, because they require abili...
```python p_ch = [True] * 9 rot = ((0, 1, 2, 3), (1, 2, 3, 0), (2, 3, 0, 1), (3, 0, 1, 2)) adj = ['c'] * 13 # record indices of right and botoom adjacent edge label. 12 is invalid. rec_adj = [[0, 2], [1, 3], [12, 4], [5, 7], [6, 8], [12, 9], [10, 12], [11, 12], [12, 12]] # refernce indices to top and left ...
vfc_45813
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nWwRR wwrg RRGb rGBG RGrb RrRg RGrg rgBB Wrgr\nRrGb WWGR rGgb Wbrg wgBb GgBg WbBG Wwwg WWGG\nRBbr Wrbr wGGG wggR WgGR WBWb WRgB wBgG WBgG\nwBrg rGgb WRrB WWbw wRRB RbbB WRrb wrbb WgrG\nWrwB WWww wRRB WGGb Wbbg WBgG WrbG Wrww RBgg...
code_contests
verifiable_code
p00838 Colored Cubes
Solve the following coding problem using the programming language python: There are several colored cubes. All of them are of the same size but they may be colored differently. Each face of these cubes has a single color. Colors of distinct faces of a cube may or may not be the same. Two cubes are said to be identica...
```python import copy # 回転方法の全列挙 def turn(box): turnlist = [] for j in range(4): for i in range(4): turnlist.append(box) box = [box[0], box[3], box[1], box[4], box[2], box[5]] box = [box[3], box[1], box[0], box[5], box[4], box[2]] box = [box[1], box[5], box[2], box[3...
vfc_45817
{ "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\nscarlet green blue yellow magenta cyan\nblue pink green magenta cyan lemon\npurple red blue yellow cyan green\n2\nred green blue yellow magenta cyan\ncyan green blue yellow magenta red\n2\nred green gray gray magenta cyan\ncyan ...
code_contests
verifiable_code
p01102 Almost Identical Programs
Solve the following coding problem using the programming language python: Almost Identical Programs The programming contest named Concours de Programmation Comtemporaine Interuniversitaire (CPCI) has a judging system similar to that of ICPC; contestants have to submit correct outputs for two different inputs to be ac...
```python def main(s): if s == ".": return False ss = input() diffc = 0 sl = s.split("\"") ssl = ss.split("\"") if len(sl) != len(ssl): print("DIFFERENT") return True for i in range(len(sl)): if i % 2 == 0: if sl[i] != ssl[i]: print("DIFFERENT") return True else: if sl[i] != ssl[i]: d...
vfc_45825
{ "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": "print\"hello\";print123\nprint\"hello\";print123\nread\"B1input\";solve;output;\nread\"B2\";solve;output;\nread\"C1\";solve;output\"C1ans\";\nread\"C2\";solve;output\"C2ans\";\n\"\"\"\"\"\"\"\"\n\"\"\"42\"\"\"\"\"\nslow\"program\"\...
code_contests
verifiable_code
p01239 Connect Line Segments
Solve the following coding problem using the programming language python: Your dear son Arnie is addicted to a puzzle named Connect Line Segments. In this puzzle, you are given several line segments placed on a two-dimensional area. You are allowed to add some new line segments each connecting the end points of two e...
vfc_45829
{ "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\n0 1 0 9\n10 1 10 9\n1 0 9 0\n1 10 9 10\n2\n1.2 3.4 5.6 7.8\n5.6 3.4 1.2 7.8\n0", "output": "Case 1: 36.24264\nCase 2: 16.84508", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 1 0 9\n...
code_contests
verifiable_code
p01401 The Legendary Sword
Solve the following coding problem using the programming language python: Problem D: Legendary Sword * This problem contains a lot of two ingredients in the kitchen. Please be careful about heartburn. The Demon King, who has finally revived, is about to invade the human world to wrap the world in darkness again. Th...
```python while True: w, h = map(int, input().split()) if w == 0:break mp = [input().split() for _ in range(h)] points = {} for y in range(h): for x in range(w): if mp[y][x] == "S": sx, sy = x, y points[0] = [(x, y)] elif mp[y][x] == "G": gx, gy = x, y elif mp[...
vfc_45833
{ "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": "10 10\nS . . . . . . . . .\n. . . . . . . . . .\n. . . . 1 . . . . .\n. . . . . . . . . .\n. . . . . . . . . .\n. . . . . . . 3 . .\n. . . . . . . . . .\n. . . . . 4 . . . .\n. . . . . . . . . .\n2 . . . . . . . . G\n10 10\nS . . ....
code_contests
verifiable_code
p01555 FizzBuzz
Solve the following coding problem using the programming language python: FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules. * "Fizz" when divisible by 3 * "Buzz" when divisible by 5 * "FizzBuzz" when divisible by both 3 and 5 * At other times, that number A...
```python def calc_start(mid): cnt = -1 i = 1 while 10 ** i < mid: cnt += i * (10 ** i - 10 ** (i - 1)) fif = (10 ** i - 1) // 15 - (10 ** (i - 1) - 1) // 15 three = (10 ** i - 1) // 3 - (10 ** (i - 1) - 1) // 3 five = (10 ** i - 1) // 5 - (10 ** (i - 1) - 1) // 5 cnt...
vfc_45837
{ "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": "20", "output": "zzBuzz11Fizz1314Fizz", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000000000", "output": "93FizzBuzz1418650796", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01855 Checkered Pattern
Solve the following coding problem using the programming language python: Problem statement There are rectangles with vertical and horizontal lengths of h and w, and square squares with a side length of 1 are spread inside. If the upper left cell is (0,0) and the cell to the right of j below (0,0) is represented as (...
```python def gcd(a,b): if a == 0: return b else: return gcd(b%a,a) t = int(input()) while t: t -= 1 a,b = map(int, input().split()) c = gcd(a,b) a = a//c b = b//c if a == b: ans1 = 1 ans2 = 0 elif a % 2 == 0 or b % 2 == 0: ans1 = 1 ans...
vfc_45845
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 3\n3 3\n4 3", "output": "1 1\n1 0\n1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 3\n3 3\n4 3", "output": "2 1\n1 0\n1 1\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p01990 Pivots
Solve the following coding problem using the programming language python: B: Pivots problem Given a permutation of length N, a_1, a_2, ..., a_N, which is a permutation of integers from 1 to N. Also, Q queries are given in order for this permutation. In the i-th query, you have to do the following: * The value q_i (...
```python # -*- coding: utf-8 -*- def inpl(): return list(map(int, input().split())) N, _ = inpl() A = inpl() if N == 1: print(*A) exit() L = [0]*(N+1) R = [0]*(N+1) for i in range(N-1): R[A[i]] = A[i+1] L[A[i+1]] = A[i] lm = A[0] rm = A[-1] for q in inpl(): if q == rm: l = L[q] ...
vfc_45849
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n1 5 3 2 4\n5 2", "output": "4 5 1 2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n1 5 3 2 4\n5 3", "output": "2 4 5 1 3\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p02136 Manhattan Bomb
Solve the following coding problem using the programming language python: Problem There are $ n $ bombs on a two-dimensional plane. Each bomb is numbered from 1 to $ n $, and the $ i $ th bomb is located at coordinates $ (x_i, y_i) $. It is known that all bombs have the same Manhattan distance from the origin. When t...
vfc_45853
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n-1 -1 10\n1 1 1", "output": "0\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 2 2\n4 -1 4\n1 -4 7", "output": "2\n1\n0", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
p02277 Quick Sort
Solve the following coding problem using the programming language python: Let's arrange a deck of cards. Your task is to sort totally n cards. A card consists of a part of a suit (S, H, C or D) and an number. Write a program which sorts such cards based on the following pseudocode: Partition(A, p, r) 1 x = A[r] 2 i ...
```python def partition(A, p, r): x = A[r][1] i = p - 1 for j in range(p, r): if A[j][1] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i + 1], A[r] = A[r], A[i + 1] return i + 1 def quick_sort(A, p, r): if p < r: q = partition(A, p, r) # 左半分 quic...
vfc_45857
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nS 1\nH 1", "output": "Stable\nS 1\nH 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\nD 3\nH 2\nD 1\nS 3\nD 2\nC 1", "output": "Not stable\nD 1\nC 1\nD 2\nH 2\nD 3\nS 3", ...
code_contests
verifiable_code
approx2
Solve the following coding problem using the programming language python: You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that i ≠ j |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the numbe...
```python def test(s,r): sum=s[1] k=0 if r[0]+r[1]-sum>0: i=r[0]+r[1]-sum else: i=sum-r[0]-r[1] for x in range(len(r)): for y in r[x+1:]: if r[x]+y-sum>=0: if r[x]+y-sum<i: i=r[x]+y-sum k=1 el...
vfc_45865
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 \n4 9\n4 4 2 6", "output": "1 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 \n4 14\n4 4 2 6", "output": "4 2\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
cielnum2
Solve the following coding problem using the programming language python: Recently, chef Ciel often hears about lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are n...
```python import sys def main(): n=int(raw_input()) res=0 for i in range(n): t=raw_input().split() t=int(t[-1]) v=t #print(t) b=0 v8=v5=v3=0 while t!=0: r=t%10 t=int(t/10) #print(r,t) if r == 8: v8+=1 elif r==5: v5+=1 elif r==3: v3+=1 else: b=1 break #print(v...
vfc_45869
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\nmilk 58\nCiel's Drink 80\nThe curry 2nd edition 888888\nrice omelet 85855\nunagi 1\n The first and last letters can be a space 358", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
exam
Solve the following coding problem using the programming language python: An exam consists of N questions. The marks of the N questions are m1, m2, m3, .. mN respectively. Jam is giving the exam and he wants to maximise his number of marks. However he takes some time to solve each question. The time taken by him to so...
```python N=int(raw_input()) T=int(raw_input()) m=map(int,raw_input().split()) t=map(int,raw_input().split()) dp = [[0]*(2) for i in range(T+1)] for i in range(N): for x in xrange(T,t[i]-1,-1): dp[x][0]=max(dp[x][0],dp[x-t[i]][0]+m[i]) dp[x][1]=max(dp[x][1],dp[x-t[i]][1]+m[i],dp[x-t[i]][0]+2*m[i]) print dp[T][1] `...
vfc_45873
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n10\n1 2 3\n4 3 4", "output": "8", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
lastdig
Solve the following coding problem using the programming language python: For a non-negative integer N, define S(N) as the sum of the odd digits of N plus twice the sum of the even digits of N. For example, S(5)=5, S(456)=2*4+5+2*6=25, and S(314159)=3+1+2*4+1+5+9=27. Define D(N) as the last digit of S(N). So D(5)=5, D...
```python def func(x): sum=0 if x==0 or x==1: return 0 sum+= (x/10)*45 for z in range(x-(x%10),x): sum1=0 while(z): r=z%10 if(r%2==0): sum1+= 2*r else: sum1+=r z=z/10 sum+= sum1%10 ret...
vfc_45877
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 8\n28 138\n314159 314159", "output": "36\n495\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 6\n28 138\n314159 314159", "output": "23\n495\n7\n", "type": "stdin_s...
code_contests
verifiable_code
pd31
Solve the following coding problem using the programming language python: You are given an unweighted, undirected graph. Write a program to check if it's a tree topology. Input The first line of the input file contains two integers N and M --- number of nodes and number of edges in the graph (0 < N ≤ 10000, 0 ≤ M ≤...
```python s=raw_input().split() m,n=int(s[0]),int(s[1]) if m-n==1: print 'YES' else: print 'NO' ```
vfc_45881
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 2\n2 3", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2\n1 3\n2 3", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1008_C. Reorder the Array
Solve the following coding problem using the programming language python: You are given an array of integers. Vasya can permute (change order) its integers. He wants to do it so that as many as possible integers will become on a place where a smaller integer used to stand. Help Vasya find the maximal number of such in...
```python n = int(input().strip()) a = list(map(int, input().strip().split())) a.sort() cnt = 0 que = [] l = 0 for i in a: if l == 0: que.append(i) l += 1 else: if i != que[0]: que.append(i) del que[0] cnt += 1 else: que.append(i) l += 1 print(cnt) ```
vfc_45889
{ "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": "7\n10 1 1 1 5 5 3\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 1 1 1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1031_A. Golden Plate
Solve the following coding problem using the programming language python: You have a plate and you want to add some gilding to it. The plate is a rectangle that we split into w× h cells. There should be k gilded rings, the first one should go along the edge of the plate, the second one — 2 cells away from the edge and...
```python w, h, k = input().split() w = int(w) h = int(h) k = int(k) s = 0 for i in range(k): k = 2*w + 2*h - 4 - 16*i s = s + k print(s) ```
vfc_45893
{ "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": "7 9 2\n", "output": "40\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 9 1\n", "output": "28\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3...
code_contests
verifiable_code
1054_A. Elevator or Stairs?
Solve the following coding problem using the programming language python: Masha lives in a multi-storey building, where floors are numbered with positive integers. Two floors are called adjacent if their numbers differ by one. Masha decided to visit Egor. Masha lives on the floor x, Egor on the floor y (not on the sam...
```python x,y,z,tuno,tdos,ttres=map(int,input().split()) var1=(x-y) stair=abs(var1)*tuno var2=(x-z) eleva=(3*ttres)+((abs(var2))*tdos)+((abs(var1))*tdos) if stair >= eleva: print("YES") else: print("NO") ```
vfc_45897
{ "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 6 6 2 1 1\n", "output": "NO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1097_A. Gennady and a Card Game
Solve the following coding problem using the programming language python: Gennady owns a small hotel in the countryside where he lives a peaceful life. He loves to take long walks, watch sunsets and play cards with tourists staying in his hotel. His favorite game is called "Mau-Mau". To play Mau-Mau, you need a pack ...
```python n = str(input()) alist = input().split(' ') for i in alist: if i[0] == n[0]: print('YES') exit(0) elif i[-1] == n[-1]: print('YES') exit(0) print('NO') ```
vfc_45905
{ "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": "AS\n2H 4C TH JH AD\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2H\n3D 4C AC KD AS\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_nam...
code_contests
verifiable_code
1165_D. Almost All Divisors
Solve the following coding problem using the programming language python: We guessed some integer number x. You are given a list of almost all its divisors. Almost all means that there are all divisors except 1 and x in the list. Your task is to find the minimum possible integer x that can be the guessed number, or s...
```python def divisors(num): """ 約数全列挙 """ divisors = [] for i in range(1, int(num ** 0.5) + 1): if num % i == 0: divisors.append(i) if i != num // i: divisors.append(num // i) return divisors T = int(input()) for t in range(T): N = int(inpu...
vfc_45917
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n8\n8 2 12 6 4 24 16 3\n1\n2\n", "output": "48\n4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1202_F. You Are Given Some Letters...
Solve the following coding problem using the programming language python: You are given a uppercase Latin letters 'A' and b letters 'B'. The period of the string is the smallest such positive integer k that s_i = s_{i~mod~k} (0-indexed) for each i. Note that this implies that k won't always divide a+b = |s|. For exa...
```python import math a,b= map(int,input().split()) n=a+b ans,l=0,1 while l<=n: g= n//l if a<g or b<g: l= (n//g) +1 continue r= n//g a_low = (a+g)//(g+1) a_high = a//g b_low=(b+g)//(g+1) b_high = b//g if (a_low <= a_high and b_low <= b_high): ans += max(0,min(r,a_...
vfc_45925
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4\n", "output": "4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
121_B. Lucky Transformation
Solve the following coding problem using the programming language python: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has a number consis...
```python import sys input=sys.stdin.readline from math import * n,m=map(int,input().split()) s=list(input().rstrip()) for i in range(n-1): if m==0: break if i>0: if s[i-1]=='4' and s[i]=='4' and s[i+1]=='7' and i%2==1: if m%2==1: s[i]='7' break if s...
vfc_45929
{ "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": "7 4\n4727447\n", "output": "4427477\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1244_F. Chips
Solve the following coding problem using the programming language python: There are n chips arranged in a circle, numbered from 1 to n. Initially each chip has black or white color. Then k iterations occur. During each iteration the chips change their colors according to the following rules. For each chip i, three c...
```python import sys input = sys.stdin.readline n,k=map(int,input().split()) S=input().strip() ANS=["?"]*n for i in range(n-1): if S[i]=="B": if S[i-1]=="B" or S[i+1]=="B": ANS[i]="B" else: if S[i-1]=="W" or S[i+1]=="W": ANS[i]="W" if S[n-1]=="B": if S[n-2]=="B" ...
vfc_45933
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 4\nBWBWBW\n", "output": "BWBWBW", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 3\nWBWBWBW\n", "output": "WWWWWWW", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
1264_D1. Beautiful Bracket Sequence (easy version)
Solve the following coding problem using the programming language python: This is the easy version of this problem. The only difference is the limit of n - the length of the input string. In this version, 1 ≤ n ≤ 2000. The hard version of this challenge is not offered in the round for the second division. Let's defi...
vfc_45937
{ "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": "(?(?))\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "??\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "(?(??...
code_contests
verifiable_code
1285_F. Classical?
Solve the following coding problem using the programming language python: Given an array a, consisting of n integers, find: $$$max_{1 ≤ i < j ≤ n} LCM(a_i,a_j),$$$ where LCM(x, y) is the smallest positive integer that is divisible by both x and y. For example, LCM(6, 8) = 24, LCM(4, 12) = 12, LCM(2, 3) = 6. Input ...
vfc_45941
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 2 4 8 16 32\n", "output": "32\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n13 35 77\n", "output": "1001\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
1305_A. Kuroni and the Gifts
Solve the following coding problem using the programming language python: Kuroni has n daughters. As gifts for them, he bought n necklaces and n bracelets: * the i-th necklace has a brightness a_i, where all the a_i are pairwise distinct (i.e. all a_i are different), * the i-th bracelet has a brightness b_i, whe...
```python t=int(input()) for _ in range(t): n=int(input()) a=list(map(int,input().split())) b=list(map(int,input().split())) a=sorted(a) b=sorted(b) print(*a) print(*b) ```
vfc_45945
{ "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\n3\n1 8 5\n8 4 5\n3\n1 7 5\n6 1 2\n", "output": "1 5 8\n4 5 8\n1 5 7\n1 2 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3\n1 8 10\n8 4 5\n3\n1 7 5\n6 1 2\n", "output": "1 8 ...
code_contests
verifiable_code
1329_C. Drazil Likes Heap
Solve the following coding problem using the programming language python: Drazil likes heap very much. So he created a problem with heap: There is a max heap with a height h implemented on the array. The details of this heap are the following: This heap contains exactly 2^h - 1 distinct positive non-zero integers. A...
```python import io, os input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline T = int(input()) for _ in range(T): H, G = map(int, input().split()) A = [0] + list(map(int, input().split())) N = len(A) target_N = 2**G - 1 target_ans_len = 2**H - 2**G Ans = [] Roots = [True] * (N+1) i...
vfc_45949
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 2\n7 6 3 5 4 2 1\n3 2\n7 6 5 4 3 2 1\n", "output": "10\n1 1 3 3 \n8\n1 1 1 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3 2\n7 6 3 5 4 2 1\n3 2\n7 6 5 4 3 2 1\n", "outp...
code_contests
verifiable_code
1349_C. Orac and Game of Life
Solve the following coding problem using the programming language python: Please notice the unusual memory limit of this problem. Orac likes games. Recently he came up with the new game, "Game of Life". You should play this game on a black and white grid with n rows and m columns. Each cell is either black or white....
```python import sys input = sys.stdin.readline n,m,t=map(int,input().split()) MAP=[input().strip() for i in range(n)] COUNT=[[-1]*m for i in range(n)] from collections import deque Q=deque() for i in range(n): for j in range(m): for z,w in [[i+1,j],[i-1,j],[i,j+1],[i,j-1]]: if 0<=z<n and 0<=...
vfc_45953
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 128000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 3\n0\n1 1 1\n1 1 2\n1 1 3\n", "output": "0\n0\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 3\n000\n111\n000\n1 1 1\n2 2 2\n3 3 3\n", "output": "1\n1\n1\n", "type"...
code_contests
verifiable_code
136_A. Presents
Solve the following coding problem using the programming language python: Little Petya very much likes gifts. Recently he has received a new laptop as a New Year gift from his mother. He immediately decided to give it to somebody else as what can be more pleasant than giving somebody gifts. And on this occasion he org...
```python n = int(input()) arr = list(map(int, input().split())) brr = arr[:] t = 0 for i in range(n): t = arr[i] - 1 brr[t] = i + 1 print(*brr) ```
vfc_45957
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 3 2\n", "output": "1 3 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 3 4 1\n", "output": "4 1 2 3 \n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
1416_C. XOR Inverse
Solve the following coding problem using the programming language python: You are given an array a consisting of n non-negative integers. You have to choose a non-negative integer x and form a new array b of size n according to the following rule: for all i from 1 to n, b_i = a_i ⊕ x (⊕ denotes the operation [bitwise ...
```python n=int(input()) l=input().split() li=[int(i) for i in l] xori=0 ans=0 mul=1 for i in range(32): hashi1=dict() hashi0=dict() inv1=0 inv2=0 for j in li: if(j//2 in hashi1 and j%2==0): inv1+=hashi1[j//2] if(j//2 in hashi0 and j%2==1): inv2+=hashi0[j//2] ...
vfc_45965
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n8 10 3\n", "output": "0 8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n10 7 9 10 7 5 5 3 5\n", "output": "4 14\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
1433_B. Yet Another Bookshelf
Solve the following coding problem using the programming language python: There is a bookshelf which can fit n books. The i-th position of bookshelf is a_i = 1 if there is a book on this position and a_i = 0 otherwise. It is guaranteed that there is at least one book on the bookshelf. In one move, you can choose some...
```python import sys try: import os f = open('input.txt', 'r') sys.stdin = f except FileNotFoundError: None from math import sqrt, ceil input=lambda: sys.stdin.readline().strip() o=int(input()) for _ in range(o): n=int(input()) A=list(map(int,input().split())) dou=-1 ;las=-1 for i in ra...
vfc_45969
{ "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\n7\n0 0 1 0 1 0 1\n3\n1 0 0\n5\n1 1 0 0 1\n6\n1 0 0 0 0 1\n5\n1 1 0 1 1\n", "output": "2\n0\n2\n4\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n8\n0 0 0 1 1 1 1 1\n", "outp...
code_contests
verifiable_code
1458_A. Row GCD
Solve the following coding problem using the programming language python: You are given two positive integer sequences a_1, …, a_n and b_1, …, b_m. For each j = 1, …, m find the greatest common divisor of a_1 + b_j, …, a_n + b_j. Input The first line contains two integers n and m (1 ≤ n, m ≤ 2 ⋅ 10^5). The second l...
```python from math import gcd n, m = map(int, input().split()) a = list(map(int, input().split())) b = list(map(int, input().split())) for i in b: ans = a[0]+i if(len(a)>=2): ans = gcd(a[0]+i,a[1]+i) if(len(a)>2): ans = gcd(ans, a[(len(a)-1)//4]+i) ans = gcd(ans, a[(len(a)-1)//2]+...
vfc_45973
{ "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": "4 4\n1 25 121 169\n1 2 7 23\n", "output": "\n2 3 8 24\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n45\n54\n", "output": "99\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1481_A. Space Navigation
Solve the following coding problem using the programming language python: You were dreaming that you are traveling to a planet named Planetforces on your personal spaceship. Unfortunately, its piloting system was corrupted and now you need to fix it in order to reach Planetforces. <image> Space can be represented as...
```python # https://codeforces.com/problemset/problem/1481/A for _ in range(int(input())): x, y = map(int, input().split()) string = input() positiveX, positiveY, negativeX, negativeY = 0, 0, 0, 0 for i in string: if i == "R": positiveX += 1 elif i == "L": negati...
vfc_45977
{ "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\n10 5\nRRRRRRRRRRUUUUU\n1 1\nUDDDRLLL\n-3 -5\nLDLDLDDDR\n1 2\nLLLLUU\n3 -2\nRDULRLLDR\n-1 6\nRUDURUUUUR\n", "output": "\nYES\nYES\nYES\nNO\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
161_E. Polycarpus the Safecracker
Solve the following coding problem using the programming language python: Polycarpus has t safes. The password for each safe is a square matrix consisting of decimal digits '0' ... '9' (the sizes of passwords to the safes may vary). Alas, Polycarpus has forgotten all passwords, so now he has to restore them. Polycarp...
```python from collections import defaultdict def primes(n): pr = range(n) for i in xrange(2,n): if not pr[i]: continue ii=i*i if ii>n: break pr[ii::i]=[0]*len(pr[ii::i]) return filter(None,pr)[1:] pr = primes(100000) pe = defaultdict(lambda: defaultdict(int)) for p in pr: ...
vfc_45989
{ "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": "4\n11\n239\n401\n9001\n", "output": "4\n28\n61\n2834\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30\n70003\n10103\n11003\n22003\n13003\n20023\n10303\n52103\n50053\n30203\n37003\n13103\...
code_contests
verifiable_code
181_A. Series of Crimes
Solve the following coding problem using the programming language python: The Berland capital is shaken with three bold crimes committed by the Pihsters, a notorious criminal gang. The Berland capital's map is represented by an n × m rectangular table. Each cell of the table on the map represents some districts of th...
```python a,b=map(int,input().split());c,d,e,g=0,0,0,0 for i in range(a): k=input().replace(" ","") if k.count("*")==2:c=k.find("*");k=k[::-1];d=b-1-k.find("*") if k.count("*")==1:e=k.find("*");g=i if e==c:print(g+1,d+1) else :print(g+1,c+1) ```
vfc_45993
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n.*\n..\n**\n", "output": "1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n*.*\n*..\n...\n", "output": "2 3", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
204_C. Little Elephant and Furik and Rubik
Solve the following coding problem using the programming language python: Little Elephant loves Furik and Rubik, who he met in a small city Kremenchug. The Little Elephant has two strings of equal length a and b, consisting only of uppercase English letters. The Little Elephant selects a pair of substrings of equal l...
```python n=input() a=[map(lambda x:[],range(26)) for _ in (0,1)] for i in (0,1): for j,x in enumerate(raw_input()): a[i][ord(x)-ord('A')]+=[j] s=0 for i in range(26): p,q=a[0][i],a[1][i] if p and q: t,j,w,k,m=0,0,sum(q),len(p),len(q) for u,x in enumerate(p): while j<m and q[j]<x:t,j=t+q[j],j+1 ...
vfc_45997
{ "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\nAB\nBA\n", "output": "0.400000000000000022", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nAAB\nCAA\n", "output": "0.642857142857142794", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
229_B. Planets
Solve the following coding problem using the programming language python: Goa'uld Apophis captured Jack O'Neill's team again! Jack himself was able to escape, but by that time Apophis's ship had already jumped to hyperspace. But Jack knows on what planet will Apophis land. In order to save his friends, Jack must repea...
```python from heapq import * n, m = map(int, input().split()) l = [] from copy import * from bisect import * from math import * from sys import * for _ in range(0, n + 2): l.append([]) for i in range(0, m): a, b, c = map(int, stdin.readline().split()) l[a].append((c, b)) l[b].append((c, a)) dist = [1...
vfc_46001
{ "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 1\n1 2 3\n0\n1 3\n0\n", "output": " -1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n1 2 2\n1 3 3\n1 4 8\n2 3 4\n2 4 5\n...
code_contests
verifiable_code
252_E. Number Transformation
Solve the following coding problem using the programming language python: Little Petya likes positive integers a lot. Recently his mom has presented him a positive integer a. There's only one thing Petya likes more than numbers: playing with little Masha. It turned out that Masha already has a positive integer b. Pety...
vfc_46005
{ "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": "6 3 10\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000000000000 1 3\n", "output": "666666666666666667\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
278_A. Circle Line
Solve the following coding problem using the programming language python: The circle line of the Berland subway has n stations. We know the distances between all pairs of neighboring stations: * d1 is the distance between the 1-st and the 2-nd station; * d2 is the distance between the 2-nd and the 3-rd station; ...
```python n = int(input()) a = list(map(int, input().split())) s, t = sorted(map(int, input().split())) print(min(sum(a[s-1:t-1]), sum(a[:s-1])+sum(a[t-1:]))) ```
vfc_46009
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n31 41 59\n1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n5 8 2 100\n4 1\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
2_C. Commentator problem
Solve the following coding problem using the programming language python: The Olympic Games in Bercouver are in full swing now. Here everyone has their own objectives: sportsmen compete for medals, and sport commentators compete for more convenient positions to give a running commentary. Today the main sport events ta...
```python import math x1, y1, r1 = [int(_) for _ in input().split()] x2, y2, r2 = [int(_) for _ in input().split()] x3, y3, r3 = [int(_) for _ in input().split()] def get_line(p1, p2): x1, y1 = p1 x2, y2 = p2 if x1 * y2 == x2 * y1: c = 0 a = 1 if y1 != 0: b = -x1 / y1 ...
vfc_46013
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 0 10\n60 0 10\n30 30 10\n", "output": "30.00000 0.00000", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 0 10\n300 300 13\n500 -500 16\n", "output": "282.61217 -82.24022\n", "...
code_contests
verifiable_code
325_C. Monsters and Diamonds
Solve the following coding problem using the programming language python: Piegirl has found a monster and a book about monsters and pies. When she is reading the book, she found out that there are n types of monsters, each with an ID between 1 and n. If you feed a pie to a monster, the monster will split into some num...
```python import sys, heapq _BLANCO, _GRIS, _NEGRO = 0, 1, 2 _OO = int(1e18) class Regla: def __init__(self, id, diamantes, deMonstruo, monstruos): self.id = id self.diamantes = diamantes self.deMonstruo = deMonstruo self.monstruos = monstruos def clonar(self): return...
vfc_46017
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n1 2 1 -1\n2 2 -1 -1\n2 3 2 1 -1\n", "output": "-1 -1\n2 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4\n1 3 -1 1 -1\n1 2 -1 -1\n2 3 -1 3 -1\n2 3 -1 -1 -1\n3 2 -1 -1\n4 2 4 -1\n...
code_contests
verifiable_code
348_D. Turtles
Solve the following coding problem using the programming language python: You've got a table of size n × m. We'll consider the table rows numbered from top to bottom 1 through n, and the columns numbered from left to right 1 through m. Then we'll denote the cell in row x and column y as (x, y). Initially cell (1, 1) ...
vfc_46021
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5\n.....\n.###.\n.###.\n.....\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n...\n...\n", "output": "1\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
371_E. Subway Innovation
Solve the following coding problem using the programming language python: Berland is going through tough times — the dirt price has dropped and that is a blow to the country's economy. Everybody knows that Berland is the top world dirt exporter! The President of Berland was forced to leave only k of the currently exi...
```python from sys import stdin n = int(stdin.readline()) a = [int(x) for x in stdin.readline().split()] a = sorted([(a[x],str(x+1)) for x in range(n)]) k = int(stdin.readline()) sums = [0] for x in a: sums.append(sums[-1]+x[0]) total = 0 s = 0 for x in range(k): total += a[x][0]*x-s s += a[x][0] low =...
vfc_46025
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 100 101\n2\n", "output": "2 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n-4 -2 10 -9 -10\n2\n", "output": "5 4\n", "type": "stdin_stdout" }, { "fn_na...
code_contests
verifiable_code
416_C. Booking System
Solve the following coding problem using the programming language python: Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity! A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system. There are n booking reque...
```python import sys input = sys.stdin.readline read_tuple = lambda _type: map(_type, input().split(' ')) def solve(): # input n = int(input()) c_p = [] for i in range(n): c_i, p_i = read_tuple(int) c_p.append((c_i, p_i, i + 1)) k = int(input()) r = [(r_i, i + 1) for i, r_i in ...
vfc_46033
{ "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\n10 50\n2 100\n5 30\n3\n4 6 9\n", "output": "2 130\n2 1\n3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n23 163\n895 838\n344 444\n284 763\n942 39\n431 92\n147 515\n59 505\n940 99...
code_contests
verifiable_code
443_A. Anton and Letters
Solve the following coding problem using the programming language python: Recently, Anton has found a set. The set consists of small English letters. Anton carefully wrote out all the letters from the set in one line, separated by a comma. He also added an opening curved bracket at the beginning of the line and a clos...
```python ls=list(input()) d=list(dict.fromkeys(ls)) if(len(d)==2): print(0) elif(len(d)==3): print(1) else: print(len(d)-4) ```
vfc_46037
{ "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": "{a, b, c}\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
489_A. SwapSort
Solve the following coding problem using the programming language python: In this problem your goal is to sort an array consisting of n integers in at most n swaps. For the given array find the sequence of swaps that makes the array sorted in the non-descending order. Swaps are performed consecutively, one after anoth...
```python n = int(input()) arr = list(map(int,input().split())) ans = [] for i in range(n): k = i for j in range(i+1,n): if arr[j]<arr[k]: k=j if k!=i: arr[k],arr[i]=arr[i],arr[k] ans.append([i,k]) print(len(ans)) if len(ans)>0: for i in ans: print(*i) ```
vfc_46045
{ "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\n101 100\n", "output": "1\n0 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n10 20 20 40 60 60\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": ...
code_contests
verifiable_code
512_E. Fox And Polygon
Solve the following coding problem using the programming language python: Fox Ciel just designed a puzzle game called "Polygon"! It is played using triangulations of a regular n-edge polygon. The goal is to transform one triangulation to another by some tricky rules. <image> Triangulation of an n-edge poylgon is a s...
vfc_46049
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 3\n2 4\n", "output": "1\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n2 6\n3 6\n4 6\n6 2\n5 2\n4 2\n", "output": "6\n2 6\n3 6\n4 6\n1 3\n1 4\n1 5\n", "type": "st...
code_contests
verifiable_code
538_A. Cutting Banner
Solve the following coding problem using the programming language python: A large banner with word CODEFORCES was ordered for the 1000-th onsite round of Codeforcesω that takes place on the Miami beach. Unfortunately, the company that made the banner mixed up two orders and delivered somebody else's banner that contai...
```python inp=input() fl=False for i in range(len(inp)): for j in range(i,len(inp)+1): if inp[:i]+inp[j:]=='CODEFORCES': fl=True if fl: print('Yes') else: print('No') ```
vfc_46053
{ "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": "DOGEFORCES\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "DECODEFORCES\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
587_C. Duff in the Army
Solve the following coding problem using the programming language python: Recently Duff has been a soldier in the army. Malek is her commander. Their country, Andarz Gu has n cities (numbered from 1 to n) and n - 1 bidirectional roads. Each road connects two different cities. There exist a unique path between any two...
```python import sys range = xrange input = raw_input ## LCA class RangeQuery: def __init__(self, data, func=min): self.func = func self._data = _data = [list(data)] i, n = 1, len(_data[0]) while 2 * i <= n: prev = _data[-1] _data.append([func(prev[j], prev[j...
vfc_46061
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4 5\n1 3\n1 2\n1 4\n4 5\n2 1 4 3\n4 5 6\n1 5 2\n5 5 10\n2 3 3\n5 3 1\n", "output": "1 3 \n2 2 3 \n0 \n3 1 2 4 \n1 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5 5\n4 1\n4 2\n3 5\...
code_contests
verifiable_code
609_E. Minimum spanning tree for each edge
Solve the following coding problem using the programming language python: Connected undirected weighted graph without self-loops and multiple edges is given. Graph contains n vertices and m edges. For each edge (u, v) find the minimal possible weight of the spanning tree that contains the edge (u, v). The weight of ...
```python from sys import stdin, stdout n, m = map(int, stdin.readline().split()) d = [] ev = [set() for _ in range(n + 1)] ans = [0] * m for i in range(m): u, v, w = map(int, stdin.readline().split()) d.append((w, u, v)) ev[u].add(i) ev[v].add(i) ans[i] = w d.sort() par = [i for i in range(n + 1)...
vfc_46065
{ "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 7\n1 2 3\n1 3 1\n1 4 5\n2 3 2\n2 5 3\n3 4 2\n4 5 4\n", "output": "9\n8\n11\n8\n8\n8\n9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n1 2 42\n", "output": "42\n", "type...
code_contests
verifiable_code
630_D. Hexagons!
Solve the following coding problem using the programming language python: After a probationary period in the game development company of IT City Petya was included in a group of the programmers that develops a new turn-based strategy game resembling the well known "Heroes of Might & Magic". A part of the game is turn-...
```python n = int(input()) n += 1 print(1 + 6 * n * (n-1) // 2) ```
vfc_46069
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "19\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "748629743\n", "output": "1681339478558627377\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
658_A. Bear and Reverse Radewoosh
Solve the following coding problem using the programming language python: Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order. There will be n problems. The i-th problem has initial score pi and it ta...
```python n,c = map(int,input().split()) p=input().split() t=input().split() sl=0 sr=0 ti=0 for i in range(n): ti+=int(t[i]) if int(p[i])-c*ti>=0: sl+=int(p[i])-c*ti ti=0 for i in range(n): ti+=int(t[n-i-1]) if int(p[n-i-1])-c*ti>=0: sr+=int(p[n-i-1])-c*ti if sl == sr: print('Tie') e...
vfc_46073
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n50 85 250\n10 15 25\n", "output": "Limak\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 6\n50 85 250\n10 15 25\n", "output": "Radewoosh\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
680_C. Bear and Prime 100
Solve the following coding problem using the programming language python: This is an interactive problem. In the output section below you will see the information about flushing the output. Bear Limak thinks of some hidden number — an integer from interval [2, 100]. Your task is to say if the hidden number is prime o...
```python # from __future__ import division, print_function import sys import os from io import BytesIO, IOBase # def inp(): return sys.stdin.readline().rstrip("\r\n") #for fast input # n = int(os.read(0,100)) # if(n==1): # os.write(1,b'! 1') # sys.stdout.flush() # else: # per = [0]*n # # print('?...
vfc_46077
{ "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": "no\nyes\nno\nno\nno\n", "output": "2\n3\n5\n7\n11\n13\n17\n19\n23\n29\n31\n37\n41\n43\n47\n4\n9\n25\n49\nprime\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "yes\nno\nyes\n", "outpu...
code_contests
verifiable_code
703_B. Mishka and trip
Solve the following coding problem using the programming language python: Little Mishka is a great traveller and she visited many countries. After thinking about where to travel this time, she chose XXX — beautiful, but little-known northern country. Here are some interesting facts about XXX: 1. XXX consists of n ...
```python from collections import * import os, sys from io import BytesIO, IOBase def main(): n, k = rints() a, b = rints(), set(rints()) su, ans, su2 = sum(a), 0, 0 for i in b: ans += a[i - 1] * (su - a[i - 1]) su2 += a[i - 1] for i in range(n): if i + 1 not in b: ...
vfc_46081
{ "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 1\n2 3 1 2\n3\n", "output": "17\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n3 5 2 2 4\n1 4\n", "output": "71\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
725_B. Food on the Plane
Solve the following coding problem using the programming language python: A new airplane SuperPuperJet has an infinite number of rows, numbered with positive integers starting with 1 from cockpit to tail. There are six seats in each row, denoted with letters from 'a' to 'f'. Seats 'a', 'b' and 'c' are located to the l...
```python s = input() n = int(s[:len(s) - 1]) - 1 time = (n // 4) * 16 k = n % 4 if k in [1,3]: time += 7 a = [4, 5, 6, 3, 2, 1] time += a[ord(s[-1]) - ord('a')] print(time) ```
vfc_46085
{ "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": "1f\n", "output": "1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
747_B. Mammoth's Genome Decoding
Solve the following coding problem using the programming language python: The process of mammoth's genome decoding in Berland comes to its end! One of the few remaining tasks is to restore unrecognized nucleotides in a found chain s. Each nucleotide is coded with a capital letter of English alphabet: 'A', 'C', 'G' or...
```python n, s, g, c, r = int(input()), input(), 'ACGT', [], '===' if n % 4 != 0: exit(print(r)) for i in g: c.append(s.count(i)) if c[-1] > n // 4: exit(print(r)) for i in range(4): for j in range(c[i], n // 4): s = s.replace('?', g[i], 1) print(s) ```
vfc_46089
{ "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\nAA??\n", "output": "===\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nAGCT\n", "output": "AGCT\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
76_E. Points
Solve the following coding problem using the programming language python: You are given N points on a plane. Write a program which will find the sum of squares of distances between all pairs of points. Input The first line of input contains one integer number N (1 ≤ N ≤ 100 000) — the number of points. Each of the f...
```python import math if __name__== '__main__': n = int(input()) n_1= n- 1 totalDistance= 0 Xs= [] Ys= [] xs= [] ys= [] xAddition= 0 yAddition= 0 for _ in range(n): x, y= [int(x) for x in input().split()] Xs.append(n_1* x* x) Ys.append(n_1* y* y) ...
vfc_46093
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1\n-1 -1\n1 -1\n-1 1\n", "output": "32", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n6 3\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
794_B. Cutting Carrot
Solve the following coding problem using the programming language python: Igor the analyst has adopted n little bunnies. As we all know, bunnies love carrots. Thus, Igor has bought a carrot to be shared between his bunnies. Igor wants to treat all the bunnies equally, and thus he wants to cut the carrot into n pieces ...
```python from math import sqrt n,hn = list(map(int,input().split())) kn = sqrt(n) h = hn/kn for i in range(1,n): print(h*sqrt(i),end = ' ') ```
vfc_46097
{ "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 2\n", "output": "1.1547005383792515 1.632993161855452\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 100000\n", "output": "70710.67811865476", "type": "stdin_stdout" }...
code_contests
verifiable_code
840_A. Leha and Function
Solve the following coding problem using the programming language python: Leha like all kinds of strange things. Recently he liked the function F(n, k). Consider all possible k-element subsets of the set [1, 2, ..., n]. For subset find minimal element in it. F(n, k) — mathematical expectation of the minimal element am...
```python import operator class pa(): def __init__(self,b,i): self.b = b self.i = i n = int(input()) a = list(map(int,input().strip().split(' '))) b = list(map(int,input().strip().split(' '))) a.sort() m = [] for i in range(n): tp = pa(b[i],i) m.append(tp) m.sort(key=operator.attrgetter('b')) c = [0]*n fo...
vfc_46105
{ "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\n7 3 5 3 4\n2 1 3 2 3\n", "output": "5 7 3 4 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2\n", "output": "6 8 5 4 8 6 2 \n", "type": "std...
code_contests
verifiable_code
860_B. Polycarp's phone book
Solve the following coding problem using the programming language python: There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If ...
```python n = int(input()) s, p = {}, [''] * n for k in range(n): p[k] = t = input() for q in [t[i: j] for i in range(9) for j in range(i + 1, 10)]: s[q] = -1 if q in s and s[q] != k else k for q, k in s.items(): if k >= 0 and len(p[k]) > len(q): p[k] = q print('\n'.join(p)) # Made By Mos...
vfc_46109
{ "difficulty": "8", "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\n123456789\n100000000\n100123456\n", "output": "7\n000\n01\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
887_A. Div. 64
Solve the following coding problem using the programming language python: Top-model Izabella participates in the competition. She wants to impress judges and show her mathematical skills. Her problem is following: for given string, consisting of only 0 and 1, tell if it's possible to remove some digits in such a way,...
```python n=list(input()) m=len(n) e=0 s=1 if n.count('1')==0: s=0 for i in range(0,m): if n[i]=='1': e=i break k=n[e:] if s==1: if k.count('0')>=6: print('yes') else: print('no') else: print('no') ```
vfc_46113
{ "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": "100\n", "output": "no\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100010001\n", "output": "yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
90_A. Cableway
Solve the following coding problem using the programming language python: A group of university students wants to get to the top of a mountain to have a picnic there. For that they decided to use a cableway. A cableway is represented by some cablecars, hanged onto some cable stations by a cable. A cable is scrolled c...
```python rgb = [int(i) for i in input().split()] r = rgb[0] g = rgb[1] b = rgb[2] x = (r+1) // 2 * 3 - 3 y = (g+1) // 2 * 3 - 2 z = (b+1) // 2 * 3 - 1 print(max(x, y, z) + 30) ```
vfc_46117
{ "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": "1 3 2\n", "output": "34", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 1\n", "output": "33", "type": "stdin_stdout" }, { "fn_name": null, "input": "96 3 ...
code_contests
verifiable_code
931_D. Peculiar apple-tree
Solve the following coding problem using the programming language python: In Arcady's garden there grows a peculiar apple-tree that fruits one time per year. Its peculiarity can be explained in following way: there are n inflorescences, numbered from 1 to n. Inflorescence number 1 is situated near base of tree and any...
```python from collections import Counter tree = [] class Node: def __init__(self, num=None): self.length = 0 if num is None else tree[num-1].length + 1 def main(): n = int(input()) global tree tree = [Node()] for x in input().split(): tree.append(Node(int(x))) print(sum([...
vfc_46121
{ "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": "18\n1 1 1 4 4 3 2 2 2 10 8 9 9 9 10 10 4\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1\n", "output": "1\n", "type": "stdin_stdout" }, { ...