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
codeforces
verifiable_code
543
Solve the following coding problem using the programming language python: The country has *n* cities and *n*<=-<=1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to *n* inclusive. All the roads are initially ba...
import sys MODULO = int(1e9) + 7 def solve(n, p, out_stream): prod = [1] * n modpow = [0] * n for i in range(n - 1, 0, -1): j = p[i] if modpow[i] == 0 and prod[i] + 1 == MODULO: modpow[j] += 1 else: prod[j] = (prod[j] * ((prod[i] if modpow[i] == 0 el...
vfc_84669
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1", "output": "4 3 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 4", "output": "5 8 9 8 5", "type": "stdin_stdout" }, { "fn_name": null, "in...
codeforces
verifiable_code
91
Solve the following coding problem using the programming language python: A newspaper is published in Walrusland. Its heading is *s*1, it consists of lowercase Latin letters. Fangy the little walrus wants to buy several such newspapers, cut out their headings, glue them one to another in order to get one big string. A...
s1 = input() s2 = input() from collections import defaultdict d = defaultdict(list) for i in range(len(s1)): d[s1[i]].append(i) import bisect ans = 0 cur = 10**18 for ch in s2: if ch not in d: print(-1) exit() else: if cur >= d[ch][-1]: cur = d[ch][0] ...
vfc_84673
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abc\nxyz", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "abcd\ndabc", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
135
Solve the following coding problem using the programming language python: Little Petya very much likes arrays consisting of *n* integers, where each of them is in the range from 1 to 109, inclusive. Recently he has received one such array as a gift from his mother. Petya didn't like it at once. He decided to choose ex...
input() p = list(map(int, input().split())) x = max(p) if p[p.index(x)] == 1: p[p.index(x)] = 2 else: p[p.index(x)] = 1 p.sort() print(' '.join(str(i) for i in p))
vfc_84677
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5", "output": "1 1 2 3 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 3 4 5 6", "output": "1 2 3 4 5", "type": "stdin_stdout" }, { "fn_name": nul...
codeforces
verifiable_code
590
Solve the following coding problem using the programming language python: The famous global economic crisis is approaching rapidly, so the states of Berman, Berance and Bertaly formed an alliance and allowed the residents of all member states to freely pass through the territory of any of them. In addition, it was dec...
# lista doble enlazada o(1) operaciones en los bordes es mejor que si se implementa en el propio lenguaje from collections import deque n, m = input().split() n = int(n) m = int(m) def idx(i, j): return i*m + j max = n*m*2 graph = "" virtDist = [[], [], []] virtVertex = [deque(), deque(), deque()] virtNodesDst ...
vfc_84685
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5\n11..2\n#..22\n#.323\n.#333", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 5\n1#2#3", "output": "-1", "type": "stdin_stdout" }, { "fn_name": n...
codeforces
verifiable_code
491
Solve the following coding problem using the programming language python: Hiking club "Up the hill" just returned from a walk. Now they are trying to remember which hills they've just walked through. It is known that there were *N* stops, all on different integer heights between 1 and *N* kilometers (inclusive) above...
a=int(input()) b=int(input()) ans=[i for i in range(b+1,0,-1)]+[i for i in range(b+2,a+b+2)] print(*ans)
vfc_84689
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0\n1", "output": "2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1", "output": "2 3 4 1 ", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
288
Solve the following coding problem using the programming language python: Little penguin Polo adores strings. But most of all he adores strings of length *n*. One day he wanted to find a string that meets the following conditions: 1. The string consists of *n* lowercase English letters (that is, the string's length...
a,b=map(int,input().split()) if b==1 and a!=1:print(-1) elif a<b:print(-1) elif a==1==b:print("a") else: b-=2;a-=b;print("ab"*(a//2)+"a"*(a%2),end="") for i in range(b):print(chr(99+i),end="")
vfc_84693
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 4", "output": "ababacd", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 7", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 5", ...
codeforces
verifiable_code
198
Solve the following coding problem using the programming language python: Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the be...
def mikroby(k, b, n, t): z = 1 while z <= t: z = k * z + b n -= 1 return max(n + 1, 0) K, B, N, T = [int(i) for i in input().split()] print(mikroby(K, B, N, T))
vfc_84697
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1 3 5", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 4 4 7", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 4 1...
codeforces
verifiable_code
852
Solve the following coding problem using the programming language python: John has just bought a new car and is planning a journey around the country. Country has *N* cities, some of which are connected by bidirectional roads. There are *N*<=-<=1 roads and every city is reachable from any other city. Cities are labele...
n=int(input()) a = [0]*(n+1) for i in range(n-1): for i in input().split(): a[int(i)]+=1 l = a.count(1) print ((l*2**(n-l+1)+(n-l)*(2**(n-l)))%(10**9+7))
vfc_84705
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2\n2 3", "output": "10", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
150
Solve the following coding problem using the programming language python: You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer *q*. During a move a player should write any integer number that is a non-trivia...
q = int(input()) def is_prime(n): if n % 2 == 0 and n != 2: return False for i in range(3, int(n**0.5)+1, 2): if n % i == 0: return False return True if is_prime(q): print("1\n0") else: f = [] while q % 2 == 0: q //= 2 f.append(2) for x in range(3, int(q**0.5)+1, 2): ...
vfc_84709
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "30", "output": "1\n6", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "outp...
codeforces
verifiable_code
634
Solve the following coding problem using the programming language python: A remote island chain contains *n* islands, labeled 1 through *n*. Bidirectional bridges connect the islands to form a simple cycle — a bridge connects islands 1 and 2, islands 2 and 3, and so on, and additionally a bridge connects islands *n* a...
N = int(input()) #количество островов A = list(map(int,input().split())) B = list(map(int,input().split())) A.remove(0) B.remove(0) ind_b = B.index(A[0]) R = B[ind_b:] + B[0:ind_b] if A == R: print("YES") else: print("NO")
vfc_84713
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 0 2\n2 0 1", "output": "YES", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
949
Solve the following coding problem using the programming language python: Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he h...
import sys def query(n, a): while not (a & 1): a += (n - a//2) return a+1 >> 1 n, q = map(int, sys.stdin.readline().split()) arr = [int(sys.stdin.readline()) for _ in range(q)] sys.stdout.write("\n".join(str(query(n, a)) for a in arr))
vfc_84717
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n2\n3\n4", "output": "3\n2\n4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
42
Solve the following coding problem using the programming language python: It's a very unfortunate day for Volodya today. He got bad mark in algebra and was therefore forced to do some work in the kitchen, namely to cook borscht (traditional Russian soup). This should also improve his algebra skills. According to the ...
n, V = list(map(float, input().split(" "))) a = list(map(int, input().split(" "))) b = list(map(float, input().split(" "))) minB = min(b) if minB == 0: print(0) else: x = b[0]/a[0] for i, j in enumerate(a): if x > b[i]/a[i]: x = b[i]/a[i] output = sum(a)*x print(min(output, V)) ...
vfc_84721
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 100\n1\n40", "output": "40.0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 100\n1 1\n25 30", "output": "50.0", "type": "stdin_stdout" }, { "fn_name": null, ...
codeforces
verifiable_code
449
Solve the following coding problem using the programming language python: Jzzhu has a big rectangular chocolate bar that consists of *n*<=×<=*m* unit squares. He wants to cut this bar exactly *k* times. Each cut must meet the following requirements: - each cut should be straight (horizontal or vertical); - each cut...
import math n,m,k=map(int,input().split()) if k>n+m-2 : print(-1) exit() if n%(k+1)==0 : print(int(n/(k+1))*m) exit() if m%(k+1)==0 : print(int(m/(k+1))*n) exit() r=max(n//(k+1),1) r1=max(0,k-n+1) r2=m//(1+r1) ans=r*r2 r=max(m//(k+1),1) r1=max(0,k-m+1) r2=n//(1+r1) ans=max(ans,...
vfc_84725
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4 1", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4 2", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3 4", ...
codeforces
verifiable_code
269
Solve the following coding problem using the programming language python: Emuskald is an avid horticulturist and owns the world's longest greenhouse — it is effectively infinite in length. Over the years Emuskald has cultivated *n* plants in his greenhouse, of *m* different plant species numbered from 1 to *m*. His g...
n, m = map(int, input().split()) t = [int(input().split()[0]) for i in range(n)] p = [0] * (m + 1) for i in t: p[i] = max(p[1:i+1])+1 print(n - max(p))
vfc_84729
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n2 1\n1 2.0\n1 3.100", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 5.0\n2 5.5\n3 6.0", "output": "0", "type": "stdin_stdout" }, { "fn_na...
codeforces
verifiable_code
896
Solve the following coding problem using the programming language python: This is an interactive problem. Refer to the Interaction section below for better understanding. Ithea and Chtholly want to play a game in order to determine who can use the kitchen tonight. Initially, Ithea puts *n* clear sheets of paper in...
import sys n, m, c=map(int, input().split()) a=[] for i in range(n+1): a.append(0) cnt=0 while cnt<n: i=0 x=int(input()) if x*2<=c: i=1 while a[i] and a[i]<=x: i+=1 else: i=n while a[i] and a[i]>=x: i-=1 if a[i]==0: cnt+=1 a[i]...
vfc_84733
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4 4\n2\n1\n3\n4", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 2\n1\n2", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "in...
codeforces
verifiable_code
464
Solve the following coding problem using the programming language python: Paul hates palindromes. He assumes that string *s* is tolerable if each its character is one of the first *p* letters of the English alphabet and *s* doesn't contain any palindrome contiguous substring of length 2 or more. Paul has found a tole...
n, p = map(int, input().split()) s = list(ord(i) - 97 for i in input()) for i in range(n - 1, -1, -1): for j in range(s[i] + 1, p): if (i < 1 or j != s[i - 1]) and (i < 2 or j != s[i - 2]): s[i] = j for i in range(i + 1, n): for j in range(p): ...
vfc_84737
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "5000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\ncba", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\ncba", "output": "cbd", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 ...
codeforces
verifiable_code
524
Solve the following coding problem using the programming language python: Основой любой социальной сети является отношение дружбы между двумя пользователями в том или ином смысле. В одной известной социальной сети дружба симметрична, то есть если *a* является другом *b*, то *b* также является другом *a*. В этой же с...
d={} m,k=map(int,input().split()) for i in range(m): a,b=map(int,input().split()) d.setdefault(a,set()).add(b) d.setdefault(b,set()).add(a) for x in sorted(d): s=[] for y in sorted(d): if x==y or y in d[x]: continue if len(d[x]&d[y])*100>=k*len(d[x]): s+=[str(y)] print(str(x)+':',len(s),'...
vfc_84741
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 51\n10 23\n23 42\n39 42\n10 39\n39 58", "output": "10: 1 42\n23: 1 39\n39: 1 23\n42: 1 10\n58: 2 10 42", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 100\n1 2\n1 3\n1 4\n2 3\n2 4", ...
codeforces
verifiable_code
575
Solve the following coding problem using the programming language python: Sasha and Ira are two best friends. But they aren’t just friends, they are software engineers and experts in artificial intelligence. They are developing an algorithm for two bots playing a two-player game. The game is cooperative and turn based...
def f(n, mod=10**9+7): ans = 1 for i in range(1, n + 1): ans = ans * i % mod return ans def g(n, mod=10**9+7): num1 = f(n * 2) den1 = f(n) ** 2 % mod return num1 * pow(den1, mod - 2, mod) % mod n = int(input()) + 1 print(g(n) - 1)
vfc_84745
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2", "output": "19", "type": "stdin_stdout" }, { "fn_name": null, "input": "1", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "3", "output"...
codeforces
verifiable_code
73
Solve the following coding problem using the programming language python: Vasya plays The Elder Trolls IV: Oblivon. Oh, those creators of computer games! What they do not come up with! Absolutely unique monsters have been added to the The Elder Trolls IV: Oblivon. One of these monsters is Unkillable Slug. Why it is "U...
xyzk = [int(i) for i in input().split()] k=xyzk[3] x, y, z = sorted([xyzk[0],xyzk[1],xyzk[2]]) x = min(k // 3 + 1, x) y = min((k - x + 1) // 2 + 1, y) z = min(k - x - y + 3, z) print(x * y * z)
vfc_84749
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2 2 3", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 2 1", "output": "2", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
95
Solve the following coding problem using the programming language python: Petya loves volleyball very much. One day he was running late for a volleyball match. Petya hasn't bought his own car yet, that's why he had to take a taxi. The city has *n* junctions, some of which are connected by two-way roads. The length of ...
import sys def input(): return sys.stdin.readline()[:-1] N,M = list(map(int,input().split())) e_list = [[] for i in range(N)] X,Y = list(map(int,input().split())) X-=1 Y-=1 for i in range(M): u,v,w = list(map(int,input().split())) u-=1 v-=1 e_list[u].append((v,w)) e_list[v]....
vfc_84753
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n1 3\n1 2 3\n1 4 1\n2 4 1\n2 3 5\n2 7\n7 2\n1 2\n7 7", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 3\n1 2 2\n1 3 3\n3 2 1\n2 7\n2 7\n3 6", "output": "14", ...
codeforces
verifiable_code
261
Solve the following coding problem using the programming language python: Maxim always goes to the supermarket on Sundays. Today the supermarket has a special offer of discount systems. There are *m* types of discounts. We assume that the discounts are indexed from 1 to *m*. To use the discount number *i*, the custom...
from sys import stdin,stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) for _ in range(1):#nmbr()): n=nmbr() a=sorted(lst()) d=a[0] n=nmbr() a=sorted(lst()) ans=0 p=n-1;buy=d while p>=0: if d==0: d=buy ...
vfc_84757
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n4\n50 50 100 100", "output": "200", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 3\n5\n50 50 50 50 50", "output": "150", "type": "stdin_stdout" }, { "fn...
codeforces
verifiable_code
311
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...
r= lambda x:(x*(x+1))//2 a,b=map(int,input().split()) if r(a-1)<=b:exit(print("no solution")) for i in range(a):print(0,0+i)
vfc_84761
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "6000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3", "output": "0 0\n0 1\n1 0\n1 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 100", "output": "no solution", "type": "stdin_stdout" }, { "fn_name": null, ...
codeforces
verifiable_code
241
Solve the following coding problem using the programming language python: The Old City is a rectangular city represented as an *m*<=×<=*n* grid of blocks. This city contains many buildings, straight two-way streets and junctions. Each junction and each building is exactly one block. All the streets have width of one b...
def main(): n, m, k = map(int, input().split()) a = [input().strip() for _ in range(n)] pp = [None] * 26 di = [1, 0, -1, 0] dj = [0, 1, 0, -1] for i in range(n): for j in range(m): if 'a' <= a[i][j] <= 'z': pp[ord(a[i][j]) - ord('a')] = (i, j) ...
vfc_84765
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 10 12\n##########\n#z1a1111b#\n##########\n2 3 ab 2 8", "output": "2 8", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 3 5\n###\n#w#\n#1#\n#a#\n#1#\n#1#\n#1#\n#1#\n#b#\n###\n3 2 abababa...
codeforces
verifiable_code
67
Solve the following coding problem using the programming language python: A teacher decides to give toffees to his students. He asks *n* students to stand in a queue. Since the teacher is very partial, he follows the following rule to distribute toffees. He looks at the first two students and gives more toffees to th...
import math from collections import Counter, defaultdict from itertools import accumulate R = lambda: map(int, input().split()) n = int(input()) s = input() dp = [[0] * 1005 for i in range(n + 1)] for i in range(1, 1001): dp[0][i] = i dp[0][1001] = math.inf for i in range(n): dp[i][0] = math.inf f...
vfc_84769
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nLRLR", "output": "2 1 2 1 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n=RRR", "output": "1 1 2 3 4", "type": "stdin_stdout" }, { "fn_name": null, "...
codeforces
verifiable_code
140
Solve the following coding problem using the programming language python: Gerald is setting the New Year table. The table has the form of a circle; its radius equals *R*. Gerald invited many guests and is concerned whether the table has enough space for plates for all those guests. Consider all plates to be round and ...
from math import asin, pi from sys import exit n, R, r = [int(i) for i in input().split()] if r == R: if n == 1: print("YES") exit() else: print("NO") exit() if r > R: print("NO") exit() if 2 * r > R and R > r: if n == 1: print("YES") ...
vfc_84773
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 10 4", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 10 4", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 10 1...
codeforces
verifiable_code
85
Solve the following coding problem using the programming language python: We all know the problem about the number of ways one can tile a 2<=×<=*n* field by 1<=×<=2 dominoes. You probably remember that it goes down to Fibonacci numbers. We will talk about some other problem below, there you also are going to deal with...
import sys input = sys.stdin.readline n = int(input()) if n % 2: x1 = ('aacc' * n)[:n-1] x2 = ('ccaa' * n)[:n-1] x3 = ('bbdd' * n)[:n-1] x4 = ('ddbb' * n)[:n-1] print(x1+'e') print(x2+'e') print('f'+x3) print('f'+x4) else: x1 = ('aacc' * n)[:n] x2 = ('ccaa' * ...
vfc_84777
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4", "output": "aacc\nbbdd\nzkkz\nzllz", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "aa\nbb\naa\nbb", "type": "stdin_stdout" }, { "fn_name": null, ...
codeforces
verifiable_code
196
Solve the following coding problem using the programming language python: You've got string *s*, consisting of only lowercase English letters. Find its lexicographically maximum subsequence. We'll call a non-empty string *s*[*p*1*p*2... *p**k*]<==<=*s**p*1*s**p*2... *s**p**k*(1<=≤<=*p*1<=&lt;<=*p*2<=&lt;<=...<=&lt;<=...
w = input() res = '' while len(w) > 0: c = max(c for c in w) res += c * w.count(c) wr = w[::-1] wr = wr[:wr.index(c)] w = wr[::-1] print(res)
vfc_84785
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ababba", "output": "bbba", "type": "stdin_stdout" }, { "fn_name": null, "input": "abbcbccacbbcbaaba", "output": "cccccbba", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
700
Solve the following coding problem using the programming language python: Treeland is a country in which there are *n* towns connected by *n*<=-<=1 two-way road such that it's possible to get from any town to any other town. In Treeland there are 2*k* universities which are located in different towns. Recently, th...
from collections import defaultdict def put(): return map(int, input().split()) def dfs(): s = [(1,0)] ans = 0 vis = [0]*(n+1) while s: i,p = s.pop() if vis[i]==0: vis[i]=1 s.append((i,p)) for j in tree[i]: if j!=p: ...
vfc_84789
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 2\n1 5 6 2\n1 3\n3 2\n4 5\n3 7\n4 3\n4 6", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 3\n3 2 1 6 5 9\n8 9\n3 2\n2 7\n3 4\n7 6\n4 5\n2 1\n2 8", "output": "9", ...
codeforces
verifiable_code
229
Solve the following coding problem using the programming language python: You are given a table consisting of *n* rows and *m* columns. Each cell of the table contains a number, 0 or 1. In one move we can choose some row of the table and cyclically shift its values either one cell to the left, or one cell to the right...
def calc_shift_cost(row): starts = [i for i, x in enumerate(row) if x] for start in starts: d = 2 pos = start + 1 if pos == len(row): pos = 0 while row[pos] != 1: if row[pos]: row[pos] = min(row[pos], d) else: ro...
vfc_84793
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 6\n101010\n000100\n100000", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n111\n000", "output": "-1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
809
Solve the following coding problem using the programming language python: Leha decided to move to a quiet town Vičkopolis, because he was tired by living in Bankopolis. Upon arrival he immediately began to expand his network of hacked computers. During the week Leha managed to get access to *n* computers throughout th...
import sys import math import collections import heapq import decimal input=sys.stdin.readline n=int(input()) mod=1000000007 p=[] p1=1 for i in range(n+1): p.append(p1) p1=(p1*2)%mod l=sorted([int(i) for i in input().split()]) s=0 for i in range(n): s=(s+(l[i]*p[i])%mod)%mod s=(s-(l[i]*...
vfc_84797
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 7", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4 3 1", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n8 1...
codeforces
verifiable_code
107
Solve the following coding problem using the programming language python: As a German University in Cairo (GUC) student and a basketball player, Herr Wafa was delighted once he heard the news. GUC is finally participating in the Annual Basketball Competition (ABC). A team is to be formed of *n* players, all of which...
import math n, m, h = map(int,input().split()) ls = list(map(int,input().split())) if sum(ls) < n : print(-1) else : print("{:.9f}".format(1 - math.comb(sum(ls)-ls[h-1], n-1)/math.comb(sum(ls)-1, n-1)))
vfc_84801
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 1\n2 1", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 1\n1 1", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
codeforces
verifiable_code
323
Solve the following coding problem using the programming language python: You are given a cube of size *k*<=×<=*k*<=×<=*k*, which consists of unit cubes. Two unit cubes are considered neighbouring, if they have common face. Your task is to paint each of *k*3 unit cubes one of two colours (black or white), so that the...
if __name__ == "__main__": n = int(input()) if n % 2 == 1: print(-1) exit() str1 = ''.join(['bb' if i % 2 == 1 else 'ww' for i in range(n // 2)]) str2 = ''.join(['bb' if i % 2 == 0 else 'ww' for i in range(n // 2)]) for i in range(n): str1, str2 = str2, str1 ...
vfc_84805
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "bb\nww\n\nbb\nww", "type": "stdin_stdout" }, { "fn_name": null, "input": "3",...
codeforces
verifiable_code
856
Solve the following coding problem using the programming language python: Masha and Grisha like studying sets of positive integers. One day Grisha has written a set *A* containing *n* different integers *a**i* on a blackboard. Now he asks Masha to create a set *B* containing *n* different integers *b**j* such that al...
d = [-1] * 1000001 for t in range(int(input())): n, a = int(input()), list(map(int, input().split())) a.sort() for i in range(n): for j in range(i + 1, n): d[a[j] - a[i]] = t i = 1 while any(d[i * j] == t for j in range(1, n)): i += 1 print("YES\n" + ' '.join(str(j * i + 1) for ...
vfc_84809
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n1 10 100\n1\n1\n2\n2 4", "output": "YES\n1 2 3 \nYES\n1 \nYES\n1 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n100\n74 14 24 45 22 9 49 78 79 20 60 1 31 91 32 39 90 5 42 57 30 ...
codeforces
verifiable_code
840
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 t...
R=lambda:map(int,input().split()) n=int(input()) a=sorted(R()) c=[0]*n for i,(_,j) in enumerate(sorted(zip(R(),range(n)))): c[j]=a[-1-i] print(' '.join(map(str,c)))
vfc_84813
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n7 3 5 3 4\n2 1 3 2 3", "output": "4 7 3 5 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n4 6 5 8 8 2 6\n2 1 2 2 1 1 2", "output": "2 6 4 5 8 8 6", "type": "stdin_stdout"...
codeforces
verifiable_code
833
Solve the following coding problem using the programming language python: Slastyona and her loyal dog Pushok are playing a meaningless game that is indeed very interesting. The game consists of multiple rounds. Its rules are very simple: in each round, a natural number *k* is chosen. Then, the one who says (or barks)...
import io import os input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline t = int(input()) for tc in range(t): a, b = map(int, input().split()) cbrt = round(pow(a*b, 1/3)) if pow(cbrt, 3) == a*b: if a % cbrt == b % cbrt == 0: print("Yes") continue ...
vfc_84821
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2 4\n75 45\n8 8\n16 16\n247 994\n1000000000 1000000", "output": "Yes\nYes\nYes\nNo\nNo\nYes", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1\n8 27\n1000 1331", "output": "Yes\...
codeforces
verifiable_code
585
Solve the following coding problem using the programming language python: Alice and Bob decided to eat some fruit. In the kitchen they found a large bag of oranges and apples. Alice immediately took an orange for herself, Bob took an apple. To make the process of sharing the remaining fruit more fun, the friends decid...
def gcd(a,b): if b==0: return a else: return gcd(b, a%b) def solve(x, y, a, b): ans="" while not x==1 or not y==1: if x < y: x,y,a,b=y,x,b,a ans+=str((x-1)//y)+a x = x - (x-1)//y * y print (ans) x,y=map(int, input().split()...
vfc_84825
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 4", "output": "3B", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2", "output": "Impossible", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2",...
codeforces
verifiable_code
132
Solve the following coding problem using the programming language python: INTERCAL is the oldest of esoteric programming languages. One of its many weird features is the method of character-based output, known as Turing Tape method. It converts an array of unsigned 8-bit integers into a sequence of characters to print...
istr = input() print((0 - int('{0:08b}'.format(ord(istr[0]))[::-1], 2)) % 256) for i in range(len(istr)-1): print((int('{0:08b}'.format(ord(istr[i]))[::-1], 2) - int('{0:08b}'.format(ord(istr[i+1]))[::-1], 2)) % 256) # num = int('{0:08b}'.format(c)[::-1], 2) # num = '{0:08b}'.format(prev_value)[::-1] # print(num...
vfc_84829
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "Hello, World!", "output": "238\n108\n112\n0\n64\n194\n48\n26\n244\n168\n24\n16\n162", "type": "stdin_stdout" }, { "fn_name": null, "input": "N", "output": "142", "type": "stdin_stdout" ...
codeforces
verifiable_code
392
Solve the following coding problem using the programming language python: Imagine you have an infinite 2D plane with Cartesian coordinate system. Some of the integral points are blocked, and others are not. Two integral points *A* and *B* on the plane are 4-connected if and only if: - the Euclidean distance between ...
print(max(1, 4*int(int(input())*2**0.5)))
vfc_84833
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
201
Solve the following coding problem using the programming language python: Consider some square matrix *A* with side *n* consisting of zeros and ones. There are *n* rows numbered from 1 to *n* from top to bottom and *n* columns numbered from 1 to *n* from left to right in this matrix. We'll denote the element of the ma...
n = int(input()) if n == 3: print(5) else: s = [((2 * i + 1) * (2 * i + 1)+ 1)// 2 for i in range(200)] for i in range(200): if s[i] >= n: print(2 * i + 1) break
vfc_84837
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "9", "output": "5", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
183
Solve the following coding problem using the programming language python: Sensation, sensation in the two-dimensional kingdom! The police have caught a highly dangerous outlaw, member of the notorious "Pihters" gang. The law department states that the outlaw was driving from the gang's headquarters in his car when he ...
n = int(input()) r = 1; c = 1 for i in range(n): s = input() if (len(s) == 4): r += 1; c += 1 elif(s == "UL" or s == "DR"): r += 1 else: c += 1 print(r * c)
vfc_84841
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nUR\nUL\nULDR", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nDR\nDL", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input"...
codeforces
verifiable_code
878
Solve the following coding problem using the programming language python: Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or...
from operator import __or__, __and__, __xor__ from sys import stdin, stdout n, b, c = int(stdin.readline()), 0, 1023 m = {'|': __or__, '&': __and__, '^': __xor__} for i in range(n): t, v = [i for i in stdin.readline().split()] b = m[t](b, int(v)) c = m[t](c, int(v)) x, o, a = 0, 0, 1023 for i in ra...
vfc_84845
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n| 3\n^ 2\n| 1", "output": "2\n| 3\n^ 2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n& 1\n& 3\n& 5", "output": "1\n& 1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
297
Solve the following coding problem using the programming language python: You are fishing with polar bears Alice and Bob. While waiting for the fish to bite, the polar bears get bored. They come up with a game. First Alice and Bob each writes a 01-string (strings that only contain character "0" and "1") *a* and *b*. T...
a = input() b = input() cnt1 = a.count('1') + (a.count('1') % 2 == 1) cnt2 = b.count('1') print('YES'if cnt1 >= cnt2 else'NO')
vfc_84849
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "01011\n0110", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "0011\n1110", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input"...
codeforces
verifiable_code
594
Solve the following coding problem using the programming language python: In the official contest this problem has a different statement, for which jury's solution was working incorrectly, and for this reason it was excluded from the contest. This mistake have been fixed and the current given problem statement and mod...
# LUOGU_RID: 99814317 ans=0x3f3f3f3f n=int(input()) a=list(map(int,input().split()))#输入n个点的位置坐标 b=n//2 a.sort()#给n个点的位置坐标从小到大排序 for i in range(b):#找出最后剩下的两个点的位置坐标的最小值 ans=min(ans,a[b+i]-a[i])#a[b+i]为剩下右侧的点的位置坐标,a[i]为剩下左侧的点的位置坐标 print(ans)
vfc_84853
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n0 1 3 7 15 31", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n73 37", "output": "36", "type": "stdin_stdout" }, { "fn_name": null, "input...
codeforces
verifiable_code
566
Solve the following coding problem using the programming language python: As you must know, the maximum clique problem in an arbitrary graph is *NP*-hard. Nevertheless, for some graphs of specific kinds it can be solved effectively. Just in case, let us remind you that a clique in a non-directed graph is a subset of ...
n = int(input()) base = list(map(int, input().split())) stock = [0 for k in range(int(1e6+1))] for zbi in base : stock[zbi] = 1 t = base[-1] for k in range(2,n+1) : num = base[n-k] for i in range(2, (t//num)+1) : if stock[i*num] >= 1 : stock[num] = max(stock[num], 1 + ...
vfc_84857
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n3 4 6 8 10 18 21 24", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
223
Solve the following coding problem using the programming language python: A bracket sequence is a string, containing only characters "(", ")", "[" and "]". A correct bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the orig...
t = list(input()) d, p = [], set(range(len(t))) for j, q in enumerate(t): if q in '([': d.append((q, j)) elif d: x, i = d.pop() if x + q in '(][)': d = [] else: p -= {i, j} for i in p: t[i] = ' ' n, s = 0, '' for q in ''.join(t).split(): k = q.count('[') if k > n: n,...
vfc_84861
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "([])", "output": "1\n([])", "type": "stdin_stdout" }, { "fn_name": null, "input": "(((", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "(][)", ...
codeforces
verifiable_code
280
Solve the following coding problem using the programming language python: Bike loves looking for the second maximum element in the sequence. The second maximum element in the sequence of distinct numbers *x*1,<=*x*2,<=...,<=*x**k* (*k*<=&gt;<=1) is such maximum element *x**j*, that the following inequality holds: . T...
def maximum_xor_secondary(sequence): stack, answer = [], 0 for x in sequence: while stack: answer = max(answer, stack[-1] ^ x) if stack[-1] > x: break else: stack.pop() stack.append(x) return answer size, num = input(), [...
vfc_84865
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n5 2 1 4 3", "output": "7", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n9 8 3 5 7", "output": "15", "type": "stdin_stdout" }, { "fn_name": null, "input...
codeforces
verifiable_code
438
Solve the following coding problem using the programming language python: Our child likes computer science very much, especially he likes binary trees. Consider the sequence of *n* distinct positive integers: *c*1,<=*c*2,<=...,<=*c**n*. The child calls a vertex-weighted rooted binary tree good if and only if for ever...
standard_input, packages, dfs, hashing = 1, 1, 0, 0 if standard_input: import sys input = lambda: sys.stdin.readline().rstrip("\r\n") def I(): return input() def II(): return int(input()) def MII(): return map(int, input().split()) def LI(): ...
vfc_84869
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n1 2", "output": "1\n3\n9", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 10\n9 4 3", "output": "0\n0\n1\n1\n0\n2\n4\n2\n6\n15", "type": "stdin_stdout" }, { "...
codeforces
verifiable_code
375
Solve the following coding problem using the programming language python: You are given a matrix consisting of digits zero and one, its size is *n*<=×<=*m*. You are allowed to rearrange its rows. What is the maximum area of the submatrix that only consists of ones and can be obtained in the given problem by the descri...
n, m = map(int, input().split()) c = [input() for _ in range(n)] cnt = [0] * (m + 1) h = [0] * n res = 0 for j in range(m): for i in range(n): if c[i][j] == '1': h[i] += 1 else: h[i] = 0 cnt = [0] * (m + 1) for i in range(n): cnt[h[i]] += 1 ...
vfc_84873
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1\n1", "output": "1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
756
Solve the following coding problem using the programming language python: A new innovative ticketing systems for public transport is introduced in Bytesburg. Now there is a single travel card for all transport. To make a trip a passenger scan his card and then he is charged according to the fare. The fare is construc...
n = int(input()) trip_1, trip_2 = 0, 0 time = [] f = [0] * (n+1) for i in range(n): time.append(int(input())) while time[i] - time[trip_1] >= 90: trip_1 +=1 while time[i] - time[trip_2] >= 1440: trip_2 += 1 f[i+1] = min(min(f[trip_1] + 50, f[trip_2] + 120), f[i] + 20) ...
vfc_84877
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n10\n20\n30", "output": "20\n20\n10", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n13\n45\n46\n60\n103\n115\n126\n150\n256\n516", "output": "20\n20\n10\n0\n20\n0\n0\n20\n20\n10"...
codeforces
verifiable_code
325
Solve the following coding problem using the programming language python: You are given *n* rectangles. The corners of rectangles have integer coordinates and their edges are parallel to the *Ox* and *Oy* axes. The rectangles may touch each other, but they do not overlap (that is, there are no points that belong to th...
# LUOGU_RID: 116314114 n, s = int(input()), 0 mix = miy = float('inf') maxx = maxy = -1 for i in range(n): a, b, c, d = *map(int, input().split()), s += (c-a)*(d-b) mix, miy = min(mix, a), min(miy, b) maxx, maxy = max(maxx, c), max(maxy, d) if maxx-mix == maxy-miy: if (maxx-mix)*(maxy-miy) ...
vfc_84881
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5\n2 2 3 3", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 0 2 3\n0 3 3 5\n2 0 5 2\n3 2 5 5", "output": "NO", "type": "s...
codeforces
verifiable_code
351
Solve the following coding problem using the programming language python: Jeff got 2*n* real numbers *a*1,<=*a*2,<=...,<=*a*2*n* as a birthday present. The boy hates non-integer numbers, so he decided to slightly "adjust" the numbers he's got. Namely, Jeff consecutively executes *n* operations, each of them goes as fo...
n=int(input()) s,z=0,0 for l in map(float,input().split()): s+=(d:=l-int(l)) z+=d>0 print("%.3f"%min(abs(s-i) for i in range(z-n,min(z,n)+1)))
vfc_84885
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0.000 0.500 0.750 1.000 2.000 3.000", "output": "0.250", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4469.000 6526.000 4864.000 9356.383 7490.000 995.896", "output": "0.279", ...
codeforces
verifiable_code
963
Solve the following coding problem using the programming language python: A rectangle with sides $A$ and $B$ is cut into rectangles with cuts parallel to its sides. For example, if $p$ horizontal and $q$ vertical cuts were made, $(p + 1) \cdot (q + 1)$ rectangles were left after the cutting. After the cutting, rectang...
from math import gcd num_elements = int(input()) a_vals = [0] * (3000001) b_vals = [0] * (3000001) c_vals = [0] * (3000001) f1_map = {} f2_map = {} sum_c = 0 gcd_c = 0 for i in range(1, num_elements+1): a_vals[i], b_vals[i], c_vals[i] = map(int, input().split()) if a_vals[i] not in f1_...
vfc_84889
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1 1 9", "output": "3", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
367
Solve the following coding problem using the programming language python: Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as *q*<==<=*q*1*q*2... *q**k*. The algorithm consists of two steps: 1. F...
s=input() hs=[[0]*3 for i in range(len(s)+1)] for i in range(len(s)): for j in range(3): hs[i+1][j]=hs[i][j] if s[i]=='x': hs[i+1][0]+=1 if s[i]=='y': hs[i+1][1]+=1 if s[i]=='z': hs[i+1][2]+=1 n=int(input()) res=[] for i in range(n): l,r=map(int,input()....
vfc_84893
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "zyxxxxxxyyz\n5\n5 5\n1 3\n1 11\n1 4\n3 6", "output": "YES\nYES\nNO\nYES\nNO", "type": "stdin_stdout" }, { "fn_name": null, "input": "yxzyzxzzxyyzzxxxzyyzzyzxxzxyzyyzxyzxyxxyzxyxzyzxyzxyyxzzzyzxyyxyzx...
codeforces
verifiable_code
623
Solve the following coding problem using the programming language python: One day student Vasya was sitting on a lecture and mentioned a string *s*1*s*2... *s**n*, consisting of letters "a", "b" and "c" that was written on his desk. As the lecture was boring, Vasya decided to complete the picture by composing a graph ...
f = lambda: map(int, input().split()) n, m = f() p = [1 << i for i in range(n)] for i in range(m): x, y = f() x -= 1 y -= 1 p[x] |= 1 << y p[y] |= 1 << x s = set(p) b = (1 << n) - 1 t = {} if b in s: t[b] = 'b' s.remove(b) if len(s) == 2: a, c = s if a | c == b and b...
vfc_84897
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1\n1 2", "output": "Yes\naa", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n1 2\n1 3\n1 4", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, ...
codeforces
verifiable_code
457
Solve the following coding problem using the programming language python: Piegirl got bored with binary, decimal and other integer based counting systems. Recently she discovered some interesting properties about number , in particular that *q*2<==<=*q*<=+<=1, and she thinks it would make a good base for her new uniqu...
def clean(d): ans = ['0'] for c in list(d): ans.append(c) i = len(ans) - 1 #find last index while i > 1 and ans[i-2]== '0' and ans[i - 1] == '1' and ans[i] == '1': ans[i - 2] = '1' ans[i - 1] = '0' ans[i] = '0' i -= 2 return ''.join(ans...
vfc_84901
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000\n111", "output": "<", "type": "stdin_stdout" }, { "fn_name": null, "input": "00100\n11", "output": "=", "type": "stdin_stdout" }, { "fn_name": null, "input": "110...
codeforces
verifiable_code
163
Solve the following coding problem using the programming language python: One day Polycarpus got hold of two non-empty strings *s* and *t*, consisting of lowercase Latin letters. Polycarpus is quite good with strings, so he immediately wondered, how many different pairs of "*x* *y*" are there, such that *x* is a subst...
from sys import stdin s=[ord(i)-97 for i in stdin.readline().strip()] s1=[ord(i)-97 for i in stdin.readline().strip()] n=len(s) m=len(s1) ans=0 mod=10**9+7 dp=[[0 for i in range(n)] for j in range(26)] for i in range(m): arr=[0 for j in range(n)] for j in range(n): if s1[i]==s[j] : ...
vfc_84905
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aa\naa", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "codeforces\nforceofcode", "output": "60", "type": "stdin_stdout" }, { "fn_name": null, "...
codeforces
verifiable_code
243
Solve the following coding problem using the programming language python: Polycarpus has a sequence, consisting of *n* non-negative integers: *a*1,<=*a*2,<=...,<=*a**n*. Let's define function *f*(*l*,<=*r*) (*l*,<=*r* are integer, 1<=≤<=*l*<=≤<=*r*<=≤<=*n*) for sequence *a* as an operation of bitwise OR of all the se...
def subarrayBitwiseOR(A): res = set() pre = {0} for x in A: pre = {x | y for y in pre} | {x} res |= pre return len(res) n, A = int(input()), list(map(int, input().split())) print(subarrayBitwiseOR(A))
vfc_84909
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 0", "output": "4", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
93
Solve the following coding problem using the programming language python: Students love to celebrate their holidays. Especially if the holiday is the day of the end of exams! Despite the fact that Igor K., unlike his groupmates, failed to pass a programming test, he decided to invite them to go to a cafe so that each...
EPS = 1e-9 class Bottle: def __init__(self, i, c1, c2, v): self.i = i self.c1 = c1 self.c2 = c2 self.v = v class Cup: def __init__(self, i, v): self.i = i self.v = v self.b = [0] * 50 def distribute_milk(n, w, m): if 2 * n < m: ...
vfc_84913
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 500 3", "output": "YES\n1 333.333333\n2 333.333333\n2 166.666667 1 166.666667", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 100 5", "output": "YES\n3 20.000000 4 60.000000\n1 80....
codeforces
verifiable_code
718
Solve the following coding problem using the programming language python: Efim just received his grade for the last test. He studies in a special school and his grade can be equal to any positive decimal fraction. First he got disappointed, as he expected a way more pleasant result. Then, he developed a tricky plan. E...
n,t = map(int,input().split()) num = input() idx = num.index(".") cnt=1 for i in range(idx+1,n): if num[i]<"5": if 5-int(num[i])==1:cnt+=1 else:cnt=1 if num[i]>="5": j = min(cnt,t) if num[i-j]!=".": num = num[:i-j]+str(int(num[i-j])+1) else: ...
vfc_84917
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "5000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 1\n10.245", "output": "10.25", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 2\n10.245", "output": "10.3", "type": "stdin_stdout" }, { "fn_name": null, "i...
codeforces
verifiable_code
317
Solve the following coding problem using the programming language python: Let us call a pair of integer numbers *m*-perfect, if at least one number in the pair is greater than or equal to *m*. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not. Two integers *x*, *y* are written on the black...
def Solve(): x,y,m=map(int,input().split()) if(x>=m or y>=m): return 0 if(x<=0 and y<=0): return -1 ans=0 if(y<=0): ans=abs(y)//x+1 y+=ans*x elif(x<=0): ans=abs(x)//y+1 x+=ans*y while(x<m and y<m): if(x<y): x+=y ...
vfc_84921
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2 5", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "-1 4 15", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 -1 5", ...
codeforces
verifiable_code
138
Solve the following coding problem using the programming language python: Vera adores poems. All the poems Vera knows are divided into quatrains (groups of four lines) and in each quatrain some lines contain rhymes. Let's consider that all lines in the poems consist of lowercase Latin letters (without spaces). Letter...
n,k=list(map(int,input().split())) def z(a,b): global k c=0 d='' for i in range(len(a)-1,-1,-1): d+=a[i] if a[i] in ['a','e','i','o','u']: c+=1 if c==k: break f=c==k c=0 e='' for i in range(len(b)-1,-1,-1): e+=b[i] ...
vfc_84933
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1\nday\nmay\nsun\nfun", "output": "aabb", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\nday\nmay\ngray\nway", "output": "aaaa", "type": "stdin_stdout" }, { "...
codeforces
verifiable_code
398
Solve the following coding problem using the programming language python: User ainta loves to play with cards. He has *a* cards containing letter "o" and *b* cards containing letter "x". He arranges the cards in a row, and calculates the score of the deck by the formula below. 1. At first, the score is 0. 1. For ea...
# Made By Mostafa_Khaled bot = True a,b=map(int,input().split()) def sqr(x): return x*x def work( num, flag=0 ): ans=sqr(a-num+1)+num-1 could = min(b, num+1) cc=b//could res=b%could ans-=res * sqr(cc+1) + (could-res)*sqr(cc) if flag: print(ans) list='' ...
vfc_84937
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3", "output": "-1\nxoxox", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 0", "output": "16\noooo", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
335
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*....
s,n,q,a=input(),int(input()),{},"" for i in s:q[i]=[q[i][0]+1,1]if i in q else [1,1] if len(q)>n:print(-1) else: for i in range(n-len(q)): o=0 for j in q: m=(q[j][0]+q[j][1]-1)//q[j][1] if m>o:o,w=m,j q[w][1]=q[w][1]+1 for i in q:a+=i*q[i][1] o=0 ...
vfc_84941
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "banana\n4", "output": "2\nbaan", "type": "stdin_stdout" }, { "fn_name": null, "input": "banana\n3", "output": "3\nnab", "type": "stdin_stdout" }, { "fn_name": null, "i...
codeforces
verifiable_code
286
Solve the following coding problem using the programming language python: A permutation *p* of size *n* is the sequence *p*1,<=*p*2,<=...,<=*p**n*, consisting of *n* distinct integers, each of them is from 1 to *n* (1<=≤<=*p**i*<=≤<=*n*). A lucky permutation is such permutation *p*, that any integer *i* (1<=≤<=*i*<=≤...
n=int(input()) if (n//2)&1: print(-1) else: ans=[0]*(n+1) for i in range(1,(n//2)+1,2): ans[i]=i+1 ans[i+1]=n-i+1 ans[n-i+1]=n-i ans[n-i]=i if n%2: ans[(n//2)+1]=(n//2)+1 print(*ans[1:])
vfc_84945
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1", "output": "1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4", "output...
codeforces
verifiable_code
293
Solve the following coding problem using the programming language python: Yaroslav, Andrey and Roman can play cubes for hours and hours. But the game is for three, so when Roman doesn't show up, Yaroslav and Andrey play another game. Roman leaves a word for each of them. Each word consists of 2·*n* binary characters...
ii=lambda:int(input()) kk=lambda:map(int,input().split()) ll=lambda:list(kk()) n,a1,a2=ii(),input(),input() locs = [0]*4 for i in range(2*n): locs[int(a1[i])+2*int(a2[i])]+=1 rm = min(locs[1],locs[2]) locs[1]-=rm locs[2]-=rm locs[3]=locs[3]&1 if locs[1]: print("First") else: if locs[3]: if locs[2]==...
vfc_84949
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n0111\n0001", "output": "First", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n110110\n001001", "output": "First", "type": "stdin_stdout" }, { "fn_name": null,...
codeforces
verifiable_code
827
Solve the following coding problem using the programming language python: Arkady needs your help again! This time he decided to build his own high-speed Internet exchange point. It should consist of *n* nodes connected with minimum possible number of wires into one network (a wire directly connects two nodes). Exactly...
n = list(map(int,input().split(' '))) a,b = n[0],n[1] if b >= a-b-1: if a-b == 1: print(2) for i in range(2,a+1): print(1,i) elif a-b == 2: print(3) print(1,2) print(2,3) for i in range(4,a+1): print(3,i) else: print(4) ...
vfc_84953
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2", "output": "2\n1 2\n2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3", "output": "3\n1 2\n2 3\n3 4\n3 5", "type": "stdin_stdout" }, { "fn_name": null, ...
codeforces
verifiable_code
643
Solve the following coding problem using the programming language python: Bearland has *n* cities, numbered 1 through *n*. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities. Bear Limak was once in a city *a* and he wanted to go to a city...
import sys input = lambda: sys.stdin.readline().rstrip() N,K = map(int, input().split()) A = list(map(int, input().split())) if K<N+1 or N==4: exit(print(-1)) B = [] for i in range(1,N+1): if i in A:continue B.append(i) ans = [A[0],A[2]]+B+[A[3],A[1]] print(*ans) ans = [A[2],A[0]]+...
vfc_84957
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 11\n2 4 7 3", "output": "2 7 1 3 6 5 4\n7 1 5 4 6 2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 999\n10 20 30 40", "output": "-1", "type": "stdin_stdout" }, ...
codeforces
verifiable_code
238
Solve the following coding problem using the programming language python: A sequence of non-negative integers *a*1,<=*a*2,<=...,<=*a**n* of length *n* is called a wool sequence if and only if there exists two integers *l* and *r* (1<=≤<=*l*<=≤<=*r*<=≤<=*n*) such that . In other words each wool sequence contains a subs...
a,b=map(int,input().split()) ans=1;mod=1000000009;gh=pow(2,b,mod) for i in range(1,1+a):ans=(ans*(gh-i))%mod print(ans)
vfc_84961
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "1000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2", "output": "0", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
167
Solve the following coding problem using the programming language python: In some country live wizards. They love to ride trolleybuses. A city in this country has a trolleybus depot with *n* trolleybuses. Every day the trolleybuses leave the depot, one by one and go to the final station. The final station is at a dis...
n, a, d = map(int, input().split()) t = 0; for i in range (n): t0, v = map(int, input().split()) t1 = v / a s1 = v**2 / (2*a) if s1 > d: t = max(t, t0 + (2*d/a)**0.5) else: t = max(t0 + t1 + (d - s1)/v, t) print(t)
vfc_84965
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 10 10000\n0 10\n5 11\n1000 1", "output": "1000.5000000000\n1000.5000000000\n11000.0500000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 26\n28 29", "output": "33.0990195136"...
codeforces
verifiable_code
249
Solve the following coding problem using the programming language python: In the evenings Donkey would join Shrek to look at the stars. They would sit on a log, sipping tea and they would watch the starry sky. The sky hung above the roof, right behind the chimney. Shrek's stars were to the right of the chimney and the...
import sys readline=sys.stdin.readline import bisect def LIS(lst,weakly=False,max_value=float('inf')): f=bisect.bisect_right if weakly else bisect.bisect_left N=len(lst) update=[None]*N dp=[max_value]*N for k,x in enumerate(lst): i=f(dp,x) dp[i]=x update[k]=(i,dp...
vfc_84969
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "15\n1/3 2/1\n3 1\n6 2\n4 2\n2 5\n4 5\n6 6\n3 4\n1 6\n2 1\n7 4\n9 3\n5 3\n1 3\n15 5\n12 4", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n2/1 2/0\n3 1\n6 2\n9 3\n12 4\n15 5...
codeforces
verifiable_code
364
Solve the following coding problem using the programming language python: You have a string of decimal digits *s*. Let's define *b**ij*<==<=*s**i*·*s**j*. Find in matrix *b* the number of such rectangles that the sum *b**ij* for all cells (*i*,<=*j*) that are the elements of the rectangle equals *a* in each rectangle....
a = int(input()) s = input() sm ={} for i in range(len(s)): for j in range(i,len(s)): if j== i: t = int(s[j]) else: t += int(s[j]) if t in sm: sm[t] += 1 else: sm[t] = 1 if a==0: if 0 in sm: sum_pairs = (len...
vfc_84977
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n12345", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "16\n439873893693495623498263984765", "output": "40", "type": "stdin_stdout" }, { "fn_name":...
codeforces
verifiable_code
314
Solve the following coding problem using the programming language python: During the last Sereja's Codesecrof round the server crashed many times, so the round was decided to be made unrated for some participants. Let's assume that *n* people took part in the contest. Let's assume that the participant who got the fi...
from sys import stdin,stdout nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) def fn(a): print('a',a) n=len(a) pos1=[0] for i in range(1,n): pos1+=[pos1[-1]+a[i]*i] print('pos1',pos1) neg=[] for i in range(n): neg+=[i*(n-i...
vfc_84981
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 0\n5 3 4 1 2", "output": "2\n3\n4", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 -10\n5 5 1 7 5 1 2 4 9 2", "output": "2\n4\n5\n7\n8\n9", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
504
Solve the following coding problem using the programming language python: After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Be...
m = int(input()) basis = [] for i in range(m): a = int(input()) need=0 for v,bitset in basis: if a^v<a: need^=bitset a^=v if a: basis.append((a,need^(1<<i))) print(0) else: res = [d for d in range(i) if 1<<d&need] print(le...
vfc_84989
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n7\n6\n5\n4\n3\n2\n1", "output": "0\n0\n0\n3 0 1 2\n2 1 2\n2 0 2\n2 0 1", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
529
Solve the following coding problem using the programming language python: Many years have passed, and *n* friends met at a party again. Technologies have leaped forward since the last meeting, cameras with timer appeared and now it is not obligatory for one of the friends to stand with a camera, and, thus, being absen...
n = int(input()) w, h = [0]*n, [0]*n for i in range(n): w[i], h[i] = map(int, input().split()) def dientich(Hmax): k = n//2 a = [] for i in range(n): if h[i] > Hmax: if k <= 0 or w[i] > Hmax: return 10**9 else: a.append((h[i...
vfc_84993
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n10 1\n20 2\n30 3", "output": "180", "type": "stdin_stdout" } ] }
codeforces
verifiable_code
396
Solve the following coding problem using the programming language python: Let's assume that - *v*(*n*) is the largest prime number, that does not exceed *n*;- *u*(*n*) is the smallest prime number strictly greater than *n*. Find . The input will be provided via standard input and looks as follows: The first line...
T = int( input() ) MAX = 33000 bePrime = [0] * MAX; primNum = [] for j in range(2, MAX): if bePrime[j] == 0: primNum.append( j ) i = j while i < MAX: bePrime[i] = 1 i = i + j def isPrime( a ): for j in primNum: if j >= a: ...
vfc_84997
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n3", "output": "1/6\n7/30", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1000000000", "output": "999999941999999673/1999999887999999118", "type": "stdin_stdout" }, ...
codeforces
verifiable_code
89
Solve the following coding problem using the programming language python: Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other. A widget is some element of graphical in...
#bobwish(md) import re def size(name): global d if len(d[name]) == 4: type, children, border, spacing = d[name] if not children: d[name] = (0, 0) else: ww, hh = zip(*map(size, children)) b, s = 2 * border, spacing * max(0, len(children) - 1...
vfc_85001
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "500" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "12\nWidget me(50,40)\nVBox grandpa\nHBox father\ngrandpa.pack(father)\nfather.pack(me)\ngrandpa.set_border(10)\ngrandpa.set_spacing(20)\nWidget brother(30,60)\nfather.pack(brother)\nWidget friend(20,60)\nWidget uncle(100,20)\ngrand...
codeforces
verifiable_code
105
Solve the following coding problem using the programming language python: In Disgaea as in most role-playing games, characters have skills that determine the character's ability to use certain weapons or spells. If the character does not have the necessary skill, he cannot use it. The skill level is represented as an ...
from collections import Counter n, m, k = input().split() k, c = int(k.split('.')[1]), Counter() for i in range(int(n)): s, e = input().split() e = int(e) * k // 100 if e >= 100: c[s] = e for i in range(int(m)): c[input()] += 0 print(len(c)) print('\n'.join(sorted(x + ' ' + str(c[x]) ...
vfc_85005
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4 0.75\naxe 350\nimpaler 300\nionize 80\nmegafire 120\nmagicboost 220\nheal\nmegafire\nshield\nmagicboost", "output": "6\naxe 262\nheal 0\nimpaler 225\nmagicboost 165\nmegafire 0\nshield 0", "type": "stdin_stdout" ...
codeforces
verifiable_code
191
Solve the following coding problem using the programming language python: The ancient Berlanders believed that the longer the name, the more important its bearer is. Thus, Berland kings were famous for their long names. But long names are somewhat inconvenient, so the Berlanders started to abbreviate the names of thei...
from sys import stdin n = int(stdin.readline().strip()) l = [stdin.readline().strip() for i in range(n)] dp = [] for i in range(26): dp.append([-999999999] * 26) ans = 0 for i in range(26): dp[i][i] = 0 for j in range(n): first = ord(l[j][0]) - 97 ln = len(l[j]) last = ord(l[j][ln - ...
vfc_85009
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nabc\nca\ncba", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nvvp\nvvp\ndam\nvvp", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, ...
codeforces
verifiable_code
786
Solve the following coding problem using the programming language python: Rick and his co-workers have made a new radioactive formula and a lot of bad guys are after them. So Rick wants to give his legacy to Morty before bad guys catch them. There are *n* planets in their universe numbered from 1 to *n*. Rick is in ...
from sys import stdin input=lambda :stdin.readline()[:-1] from heapq import heappush, heappop INF=10**18 def dijkstra(start,n): dist=[INF]*n hq=[(0,start)] dist[start]=0 seen=[False]*n while hq: w,v=heappop(hq) if dist[v]<w: continue seen[v]=True for to,cost in edge[v]: ...
vfc_85013
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5 1\n2 3 2 3 17\n2 3 2 2 16\n2 2 2 3 3\n3 3 1 1 12\n1 3 3 17", "output": "0 28 12 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3 1\n3 4 1 3 12\n2 2 3 4 10\n1 2 4 16", "output":...
codeforces
verifiable_code
819
Solve the following coding problem using the programming language python: In order to fly to the Moon Mister B just needs to solve the following problem. There is a complete indirected graph with *n* vertices. You need to cover it with several simple cycles of length 3 and 4 so that each edge is in exactly 2 cycles. ...
import sys def solve(n): if n == 3: return [(1, 2, 3)]*2 if n == 4: return [(1, 2, 3, 4), (1, 2, 4, 3), (1, 4, 2, 3)] else: return [*solve(n-2), (n, n - 1, 1), (n, n - 1, n - 2), *[(n, i, n - 1, i + 1) for i in range(1, n - 2)]] answer = solve(int(sys.stdin.readline()...
vfc_85017
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "2000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3", "output": "2\n3 1 2 3\n3 1 2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5", "output": "6\n3 1 2 3\n3 2 3 4\n3 3 4 5\n3 4 5 1\n4 2 1 3 5\n4 5 1 4 2", "type": "stdin_std...
codeforces
verifiable_code
528
Solve the following coding problem using the programming language python: Leonid works for a small and promising start-up that works on decoding the human genome. His duties include solving complex problems of finding certain patterns in long strings consisting of letters 'A', 'T', 'G' and 'C'. Let's consider the fol...
if True: from io import BytesIO, IOBase import math import random import sys import os import bisect import typing from collections import Counter, defaultdict, deque from copy import deepcopy from functools import cmp_to_key, lru_cache, reduce from heapq impor...
vfc_85021
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "3000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 4 1\nAGCAATTCAT\nACAT", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 0\nA\nA", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, ...
codeforces
verifiable_code
506
Solve the following coding problem using the programming language python: Mr. Kitayuta has just bought an undirected graph with *n* vertices and *m* edges. The vertices of the graph are numbered from 1 to *n*. Each edge, namely edge *i*, has a color *c**i*, connecting vertex *a**i* and *b**i*. Mr. Kitayuta wants you ...
import io , os , sys input = io . BytesIO ( os . read ( 0 , os . fstat ( 0 ) . st_size ) ) . readline def print ( *values , sep = " " , end = "\n" ) : sep = str ( sep ) end = str ( end ) for i in range ( len ( values ) -1 ) : sys.stdout.write( str( values[i] ) ) sys.stdout.write( ...
vfc_85025
{ "difficulty": "N/A", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "4000" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5\n1 2 1\n1 2 2\n2 3 1\n2 3 3\n2 4 3\n3\n1 2\n3 4\n1 4", "output": "2\n1\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 7\n1 5 1\n2 5 1\n3 5 1\n4 5 1\n1 2 2\n2 3 2\n3 4 2\n5\n1 5\n5 ...
taco
verifiable_code
https://codeforces.com/problemset/problem/1057/C
Solve the following coding problem using the programming language python: There are $n$ candy boxes in front of Tania. The boxes are arranged in a row from left to right, numbered from $1$ to $n$. The $i$-th box contains $r_i$ candies, candies have the color $c_i$ (the color can take one of three values ​​— red, green...
```python INF = 10000000000.0 max_n = 50 max_k = 2000 def main(): (n, s, k) = map(int, input().split()) s -= 1 buf = [''] * (max_n + 1) dp = [[0 for i in range(max_n + 1)] for j in range(max_k + 1)] r = list(map(int, input().split())) c = input() answer = INF for i in range(len(c)): buf[i] = c[i] for i in r...
vfc_85029
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1057/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3 10\n1 2 3 4 5\nRGBRR\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 15\n5 6\nRG\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_na...
taco
verifiable_code
https://codeforces.com/problemset/problem/1492/B
Solve the following coding problem using the programming language python: You have a deck of $n$ cards, and you'd like to reorder it to a new one. Each card has a value between $1$ and $n$ equal to $p_i$. All $p_i$ are pairwise distinct. Cards in a deck are numbered from bottom to top, i. e. $p_1$ stands for the bott...
```python import heapq from math import sqrt import operator import sys inf_var = 0 if inf_var == 1: inf = open('input.txt', 'r') else: inf = sys.stdin input = inf.readline def read_one_int(): return int(input().rstrip('\n')) def read_list_of_ints(): res = [int(val) for val in input().rstrip('\n').split(' ')] re...
vfc_85037
{ "difficulty": "easy", "memory_limit": "512 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1492/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4\n1 2 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 6 1\n1\n1\n", "output": "4 3 2 1\n5 2 4 3 1\n6 1 5 3 4 2\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4\n2 1 3 4\n5\n1 5 2 4 3\n6\n4 2 5 3 ...
taco
verifiable_code
Solve the following coding problem using the programming language python: The number obtained by multiplying 1 by 2, 3, 5 several times (0 or more times) is called the Hamming numbers. For example * 1 * 1 x 2 x 2 = 4 * 1 x 2 x 2 x 3 x 5 x 5 = 300 Etc. are humming numbers, but 11, 13, 14 etc. are not humming number...
```python import sys from sys import stdin from bisect import bisect_right, bisect_left from math import ceil, log input = stdin.readline def main(args): hammings = [] temp = set() for i in range(ceil(log(1000000.0, 2)) + 1): for j in range(ceil(log(1000000.0, 3)) + 1): for k in range(ceil(log(1000000.0, 5)) +...
vfc_85041
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 8\n2 27\n1 86\n0", "output": "5\n16\n31\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 9\n2 27\n1 86\n0", "output": "6\n16\n31\n", "type": "stdin_stdout" }, { ...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/smallest-number-by-rearranging-digits-of-a-given-number0820/1
Solve the following coding problem using the programming language python: Given a number s(in string form). Find the Smallest number (Not leading Zeros) which can be obtained by rearranging the digits of given number. Example 1: Input: s = "846903" Output: 304689 Explanation: 304689 is the smallest number by rearran...
```python class Solution: def minimum_Number(self, s): l = list(s) l.sort() for i in range(len(l)): if int(l[i]) > 0: (l[0], l[i]) = (l[i], l[0]) break n = '' for i in l: n += i return n ```
vfc_85045
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/smallest-number-by-rearranging-digits-of-a-given-number0820/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "s = \"846903\"", "output": "304689", "type": "stdin_stdout" }, { "fn_name": null, "input": "s = \"55010\"", "output": "10055", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/the-painters-partition-problem1535/1
Solve the following coding problem using the programming language python: Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1...
```python class Solution: def minTime(self, arr, n, k): def numofPainter(maxLen): painters = 1 total = 0 for board in arr: total += board if total > maxLen: total = board painters += 1 return painters (low, high) = (max(arr), sum(arr)) while low < high: p = low + (high - low) /...
vfc_85046
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/the-painters-partition-problem1535/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 5\nk = 3\narr[] = {5,10,30,20,15}", "output": "35", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 4\nk = 2\narr[] = {10,20,30,40}", "output": "60", "type": "stdin_stdout"...
taco
verifiable_code
https://codeforces.com/problemset/problem/957/D
Solve the following coding problem using the programming language python: Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but i...
```python import sys n = int(input()) a = [int(x) for x in input().split(' ')] maxm = 0 idx = 0 ans = 0 b = [0] * n for i in range(n): if a[i] >= maxm: maxm = a[i] idx = i for i in range(idx, n): b[i] = maxm + 1 i = idx - 1 while i >= 0: b[i] = max(a[i] + 1, b[i + 1] - 1) i -= 1 for i in range(1, n): if b[i] <...
vfc_85048
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/957/D", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0 1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n0 0 1 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
taco
verifiable_code
https://www.codechef.com/problems/CCHEAVEN
Solve the following coding problem using the programming language python: When Chef was born, his parents took him to the famous monk Doctor Strange to know whether he will land himself in heaven after his life or not. According to Strange, Chef will live for $L$ years in total. If he wants to go to heaven, he must sp...
```python for i in range(0, int(input())): n = int(input()) l = list(input()) t = 0 a = 0 b = 0 for j in range(0, n): t = t + 1 if l[j] == '0': a = a + 1 else: b = b + 1 if b >= t / 2: print('YES') break elif j == n - 1 and b < t / 2: print('NO') else: continue ```
vfc_85056
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/CCHEAVEN", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n10\n3\n001\n4\n0100", "output": "YES\nNO\nYES", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/smallest-distant-window3132/1
Solve the following coding problem using the programming language python: Given a string 's'. The task is to find the smallest window length that contains all the characters of the given string at least one time. For eg. A = aabcbcdbca, then the result would be 4 as of the smallest window will be dbca. Example 1: In...
```python class Solution: def findSubString(self, str): dict = {} ans = float('inf') j = 0 for i in str: if i not in dict: dict[i] = 0 length = len(dict) for i in range(len(str)): dict[str[i]] += 1 if dict[str[i]] == 1: length -= 1 while length == 0: ans = min(ans, i - j + 1) d...
vfc_85060
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/smallest-distant-window3132/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "\"AABBBCBBAC\"", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "\"aaab\"", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
taco
verifiable_code
https://www.codechef.com/problems/DIFSUBARRAYS
Solve the following coding problem using the programming language python: You are given an array A of N integers A_{1}, A_{2}, \ldots, A_{N}. Determine if there are two [permutations] B and C of this array, for which the following condition is satisfied: * There doesn't exist a pair of integers (i, j) such that 1 ≤ i...
```python from math import ceil, log, floor, sqrt, gcd for _ in range(int(input())): n = int(input()) l = list(map(int, input().split())) f = {} for i in l: try: f[i] += 1 except: f[i] = 1 if max(f.values()) > n // 2 or len(set(l)) <= 2: print('NO') else: print('YES') l.sort() print(*l) print(...
vfc_85061
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/DIFSUBARRAYS", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n1 1 2\n4\n19 39 19 84\n6\n1 2 3 1 2 3", "output": "NO\nYES\n19 19 39 84 \n39 84 19 19 \nYES\n1 1 2 2 3 3 \n2 3 3 1 1 2 ", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/77/B
Solve the following coding problem using the programming language python: For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all. Anvils come in different sizes and shapes. Quite often...
```python t = int(input()) for _ in range(t): (a, b) = map(int, input().split()) if a == 0 and b == 0: print(1) elif a == 0: print(0.5) elif b == 0: print(1) elif a > 4 * b: print('%.10f' % ((a - b) / a)) else: print('%.10f' % (a / 16 / b + 0.5)) ```
vfc_85065
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/77/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n4 6\n4 2\n10 3\n6 3\n7 8\n2 5\n0 3\n6 1\n4 1\n10 9\n", "output": "0.5416666667\n0.6250000000\n0.7083333333\n0.6250000000\n0.5546875000\n0.5250000000\n0.5000000000\n0.8333333333\n0.7500000000\n0.5694444444\n", "type"...
taco
verifiable_code
https://www.codechef.com/COVO2020/problems/GRIG
Solve the following coding problem using the programming language python: There are players standing in a row each player has a digit written on their T-Shirt (multiple players can have the same number written on their T-Shirt). You have to select a group of players, note that players in this group should be standi...
```python import sys def GRIG(L): LENT = len(L) MINT = 1 GOT = 0 DY = [[{x: 0 for x in range(0, 10)}, 0, 0]] for i in L: DY.append([{x: 0 for x in range(0, 10)}, 0, 0]) GOT += 1 for j in range(0, GOT): if DY[j][0][i] == 1: DY[j][0][i] = 0 DY[j][1] -= 1 else: DY[j][0][i] = 1 DY[j][1] +=...
vfc_85074
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COVO2020/problems/GRIG", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n123343\n", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/print-binary-tree-levels-in-sorted-order3241/1
Solve the following coding problem using the programming language python: Given an array arr[] which contains data of N nodes of Complete Binary tree in level order fashion. The task is to print the level order traversal in sorted order. Example 1: Input: N = 7 arr[] = {7 6 5 4 3 2 1} Output: 7 5 6 1 2 3 4 Explanatio...
```python class Solution: def binTreeSortedLevels(self, arr, n): li = [] i = 0 level = 0 while i < n: dumm = [] if level == 0: li.append([arr[i]]) i += 1 level += 1 else: size = 2 ** level if i + size < n: dumm.extend(arr[i:i + size]) dumm.sort() li.append(dumm) ...
vfc_85078
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/print-binary-tree-levels-in-sorted-order3241/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 7\narr[] = {7 6 5 4 3 2 1}", "output": "7\n5 6\n1 2 3 4", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 6\narr[] = {5 6 4 9 2 1}", "output": "5\n4 6\n1 2 9", "type": "std...
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/buy-stock-2/1
Solve the following coding problem using the programming language python: You are given the prices of stock for n number of days. every ith day tell the price of the stock on that day.find the maximum profit that you can make by buying and selling stock any number of times as you can't proceed with other transactions ...
```python class Solution: def maximumProfit(self, prices, n): n = len(prices) curr = [0 for i in range(2)] nex = [0 for i in range(2)] profit = 0 for ind in range(n - 1, -1, -1): for buy in range(0, 2): if buy: buynow = -prices[ind] + nex[0] notbuy = 0 + nex[1] profit = max(buynow, not...
vfc_85083
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/buy-stock-2/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 7\nprices = [1,2,3,4,5,6,7]", "output": "6", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: <image> Matryoshka is a wooden doll in the shape of a female figure and is a typical Russian folk craft. Matryoshka has a nested structure in which smaller dolls are contained inside a large doll, and is composed of multiple dolls of different ...
```python while True: n = int(input()) if n == 0: break hr_lst = [] for _ in range(n): (h, r) = map(int, input().split()) hr_lst.append((h, r)) m = int(input()) for _ in range(m): (h, r) = map(int, input().split()) hr_lst.append((h, r)) hr_lst.sort(reverse=True) r_lst = [[] for _ in range(1001)] for ...
vfc_85084
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 1\n4 3\n6 5\n8 6\n10 10\n14 14\n5\n2 1\n5 4\n6 6\n9 8\n15 10\n4\n1 1\n4 3\n6 5\n8 6\n3\n2 2\n5 4\n6 6\n4\n1 1\n4 3\n6 5\n8 6\n4\n10 10\n12 11\n18 15\n24 20\n0", "output": "8\n6\n8\n", "type": "stdin_stdout" } ...
taco
verifiable_code
https://codeforces.com/problemset/problem/593/C
Solve the following coding problem using the programming language python: Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful set of points, such that there ...
```python def f(x): if x == n: return '0' if x == 0: return '(' + str(X[0]) + '+' + f(1) + ')' ss = '(abs((t-' + str(x - 1) + '))-abs((t-' + str(x) + ')))' tmp = (X[x] - X[x - 1]) // 2 re = X[x] - X[x - 1] - 2 * tmp X[x] -= re if tmp < 0: tmp = '(0' + str(tmp) + ')' ss = '((' + str(tmp) + '*' + ss + ')' +...
vfc_85092
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/593/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n9 5 8\n8 9 10\n9 5 2\n", "output": "(((4*((1-abs((t-0)))+abs((abs((t-0))-1))))+(4*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(4*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n(((2*((1-abs((t-0)))+abs((abs((t-0))-1))))+(4*((1-abs((t-1...
taco
verifiable_code
https://www.codechef.com/ENDE2020/problems/ENCDEC2
Solve the following coding problem using the programming language python: You are the principal of the Cake school in chefland and today is your birthday. You want to treat each of the children with a small cupcake which is made by you. But there is a problem, You don't know how many students are present today. The st...
```python for _ in range(int(input())): n = list(map(int, input().split())) print(n[0] * n[1]) ```
vfc_85098
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/ENDE2020/problems/ENCDEC2", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5 10\n", "output": "50\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/COCU2016/problems/CURR2
Solve the following coding problem using the programming language python: The EEE classes are so boring that the students play games rather than paying attention during the lectures. Harsha and Dubey are playing one such game. The game involves counting the number of anagramic pairs of a given string (you can read ab...
```python def sort_str(s): o = [] for c in s: o.append(c) o.sort() return ''.join(o) def find_ana(s): if len(s) <= 1: return 0 h = {} c = 0 for i in range(len(s)): for j in range(i + 1, len(s) + 1): t = sort_str(s[i:j]) if t in h: c += h[t] h[t] += 1 else: h[t] = 1 return c t = int(...
vfc_85102
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/COCU2016/problems/CURR2", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nrama\nabba\nabcd\n", "output": "2\n4\n0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-smallest-values-of-x-and-y-such-that-ax-by-01433/1
Solve the following coding problem using the programming language python: Given two values ‘a’ and ‘b’ that represent coefficients in “ax – by = 0”, find the smallest values of x and y that satisfy the equation. It may also be assumed that x > 0, y > 0, a > 0 and b > 0. Example 1: Input: a = 25, b = 35 Output: 7 5 Exp...
```python class Solution: def findXY(self, a, b): import math n = math.gcd(a, b) x = a / n y = b / n if b / a == y / x: return [int(y), int(x)] ```
vfc_85111
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-smallest-values-of-x-and-y-such-that-ax-by-01433/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "a = 25, b = 35", "output": "7 5", "type": "stdin_stdout" } ] }