source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
code_contests
verifiable_code
958_F2. Lightsabers (medium)
Solve the following coding problem using the programming language python: There is unrest in the Galactic Senate. Several thousand solar systems have declared their intentions to leave the Republic. Master Heidi needs to select the Jedi Knights who will go on peacekeeping missions throughout the galaxy. It is well-kno...
```python n, m = map(int, input().split()) c = list(map(int, input().split())) k = list(map(int, input().split())) p = [0] * m c = [i -1 for i in c] s = sum(k) cnt = k.count(0) l = 0 r = 0 while r < n and cnt < m: p[c[r]] += 1 if p[c[r]] == k[c[r]]: cnt += 1 r += 1 if cnt != m: print(-1) exi...
vfc_46125
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 3\n3 3 1 2 2 1 1 3\n3 1 1\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n1 1\n1 0\n", "output": "0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
985_D. Sand Fortress
Solve the following coding problem using the programming language python: You are going to the beach with the idea to build the greatest sand castle ever in your head! The beach is not as three-dimensional as you could have imagined, it can be decribed as a line of spots to pile up sand pillars. Spots are numbered 1 t...
```python from math import ceil, sqrt n, H = map(int, input().split(' ')) k = ceil(0.5*(sqrt(8*n+1)-1)) while k*k+k >= 2*n: k -= 1 while k*k+k < 2*n: k += 1 if k <= H: print(k) else: k = ceil(sqrt(2*H*H-2*H+4*n)-H) if (k - H) % 2 == 1: k += 1 a = (k-H)//2 while (H+a)*(H+a+1) + ...
vfc_46129
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 8\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000...
code_contests
verifiable_code
abhinav-and-manav
Solve the following coding problem using the programming language python: Abhinav and Manav both being one of the best coders of SVNIT went onto participate in ACM ICPC Regional Contest. Apparently Manav’s team the 3Horsemen stood ahead of Abhinav’s team akatsuki11 in the contest though both solved the same number of ...
```python a = [0,10,100,1000,10000,100000,1000000,10000000,100000000,1000000000,10000000000] def max(): tval=input() for t in xrange(tval): l,r = map(int,raw_input().split()) len_r = len(str(r)) if l <= a[len_r]/2 and r >= a[len_r]/2: v = a[len_r]/2 tt = str(v) mir = [] fo...
vfc_46133
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 7\n1 1\n8 10\n\nSAMPLE", "output": "20\n8\n890", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
booboo-and-upsolving-circuits
Solve the following coding problem using the programming language python: The hero of this story is a toddler named BooBoo. Inspired by the legendary competitive coder Gena, BooBoo has also started preparing to race to the top of the ranks. BooBoo is going to practice N different problems in the exact given order ove...
```python t,n = map(int,raw_input().split()) a = map(int,raw_input().split()) z = sum(a) high = z low = int(z/t) while low<high: mid = int((low+high)/2) count = 1 flag = 0 num = mid for x in a: if x>num: if x>mid: low=mid+1 flag = 1 ...
vfc_46137
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3\n1 2 2 1 3\n\nSAMPLE", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "680 478\n27436 32744 23403 9394 31389 21512 9460 3738 8344 4419 20737 2938 8741 12881 20986 23654 13...
code_contests
verifiable_code
cut-the-stick
Solve the following coding problem using the programming language python: We have a S cm long stick.It can be broken only at certain positions.Sarah wants to calculate the number of GOOD Pairs. It satisfies the following conditions A good pair consists of 2 distinct positions where the stick can be broken. When the...
```python from bisect import bisect_left for _ in xrange(input()): s,n,l=map(int,raw_input().split()) a=map(int,raw_input().split()) a.sort() ans=0 for i in xrange(n): if a[i]>l: ans+=n-i-1 else: aa=[] tmp=bisect_left(a,s-l)-1 if i+1<=tmp: aa.append([i+1,bisect_left(a,s-l)-1]) #ans+=tmp-1-...
vfc_46141
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10 2 6\n1 3\n10 3 5\n1 3 9\n\nSAMPLE", "output": "1\n3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
fun-with-fibonacci
Solve the following coding problem using the programming language python: find the sum of the even fibonacci numbers till the given number(it is the value not index). INPUT: T test cases next T lines consists of a number n. OUTPUT: Output the sum value. 0<t<10 2<n<10^20 Example: if n=10 the numbers which are less th...
```python aa = int(raw_input()) outt=[] for x in range(aa): b= int(raw_input()) if b==0 or b==1: outt.append(0) else: l=[0,1] while(l[-1]<=b): l.append(l[-1]+l[-2]) s=[j for j in l if j<=b if j%2==0] outt.append(sum(s)) for k in outt: print k ```
vfc_46145
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10\n100\n\nSAMPLE", "output": "10\n44\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n14576\n145786\n1254478\n147852\n125478", "output": "14328\n60696\n1089154\n60696\n60696\n"...
code_contests
verifiable_code
just-add-1
Solve the following coding problem using the programming language python: You are given three numbers. Is there a way to replace variables A, B and C with these numbers so the equality A + B = C is correct? Input: There are three numbers X1, X2 and X3 (1 ≤ Xi ≤ 10^100), each on a separate line of input. Output: Ou...
```python a=int(input()) b=int(input()) c=int(input()) if (a+b==c or a+c==b or b+c==a or 2*a==c or 2*a==b or 2*b==a or 2*b==c or 2*c==a or 2*c==b): print('YES') else: print('NO') ```
vfc_46149
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n3\n\nSAMPLE", "output": "YES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
minimum-class
Solve the following coding problem using the programming language python: See Russian Translation After a long term relationship, Anandi and Jagdish decided to marry. Anandi being a studious girl decided to complete her studies first. What next, she comes to ABC Public School. Her classes haven't even started yet and...
```python a = raw_input('') a = int(a) l = [] for cnt in range(a): b = raw_input('') b = int(b) c = b**0.5 c = int(c) d = c**2 if d == b: l.append(2*c-1) elif b<=d+c: l.append(2*c) else: l.append(2*c+1) for cnt in l: print(cnt) ```
vfc_46153
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\n1\n9 \n\nSAMPLE", "output": "3\n1\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000\n923867676\n992240520\n13107104\n686562368\n904879438\n584988420\n788043140\n467961024\n1037...
code_contests
verifiable_code
rhezo-and-cinema-hall-1
Solve the following coding problem using the programming language python: Rhezo is the new manager of Specialist Cinema Hall. A new movie is being released this Friday and Rhezo wants people in the hall to be seated according to some rules. His rules are weird and he likes that no 2 people in a row sit together/adjace...
```python #import time #time1=time.time() MOD=1000000007 # rowlen i, people j, f(i,j)=0 if j<(i+1)/2 else i if j==1 else f(i-1,j)+f(i-2,j-1) combs={3:{2:1},4:{2:3},5:{2:6,3:1},6:{2:10,3:4},7:{2:15,3:10,4:1}, 8:{2:21,3:20,4:5}, 9:{2:28,3:35,4:15,5:1}, 10:{2:36,3:56,4:35,5:6}} #combs=[[0,0,1,0,0,0],[0,0,3,0,0,0]...
vfc_46161
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "304 8\n475", "output": "660379328", "type": "stdin_stdout" }, { "fn_name": null, "input": "500 10\n500", "output": "616800443", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
special-paths
Solve the following coding problem using the programming language python: You are given a rectangular grid with n rows and m columns. The rows are numbered 1 to n, from bottom to top, and the columns are numbered 1 to m, from left to right. You are also given k special fields in the form (row, column). For each i,...
```python N, M, K = map(int, raw_input().split()) special = [[False for j in xrange(M)] for i in xrange(N)] for k in xrange(K) : a, b = map(int, raw_input().split()) special[a - 1][b - 1] = True dp = [[[0 for k in xrange(K + 1)] for j in xrange(M)] for i in xrange(N)] for k in xrange(K + 1): specialCo...
vfc_46165
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 2\n2 2\n3 2\n\nSAMPLE", "output": "1 3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 4 2\n5 3\n3 2", "output": "14 24 18\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
travel-sky-bag-lock
Solve the following coding problem using the programming language python: A Sky bag to lock accepts only the Prime number (all combination of prime numbers are allowed) except ignoring the leading zero's (0's). If there is prime number like '003' or '103' both of them are considered as the valid codes to unlock the Sk...
```python invalids = [1, 4, 6, 8, 9] for _ in range(input()): nod, ins = map(int, raw_input().split()) ans = 0 while ins > 0: mods = ins % 10 if mods in invalids: if mods == 9: ans += 2 else: ans += 1 ins /= 10 print...
vfc_46169
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 001\n5 45654\n4 1234\n\nSAMPLE", "output": "1\n3\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n3 001\n5 55555\n4 9955\n2 22\n1 7\n3 001\n5 10101\n4 2468\n2 98\n1 5\n3 401\n5 55...
code_contests
verifiable_code
p00130 Train
Solve the following coding problem using the programming language python: There are trains with 26 cars or less. Each vehicle has an identification code from lowercase a to z. No vehicle has the same symbol. However, the order in which the vehicles are connected is arbitrary. The conductor patrols the train. The condu...
```python for _ in range(int(input())): s=list(input()) word,direct=[],"" for i in s: if i.isalpha(): if direct==">": if i not in word:word.append(i) else: if i not in word:word.insert(0,i) elif i=="<" or i==">":direct=i print(*word...
vfc_46217
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\na->e->c->b->d\nb", "output": "aecbd\nedacb\nbacde\nbcdae", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\na->e->c->b->d\nb<-c<-a<-d<-e\nb->a->c<-a->c->d<-c<-a<-b->a->c->d->e<-d\na->e<-a...
code_contests
verifiable_code
p00263 Kongo Type
Solve the following coding problem using the programming language python: Consider a 32-bit real type with 7 bits from the right as the decimal part, the following 24 bits as the integer part, and the leftmost 1 bit as the sign part as shown below (b1, ..., b32). Represents 0 or 1). <image> To translate this format...
```python q = int(input()) for _ in range (q): bits = F'{int(input(), 16):32b}' sign = '-' if bits[0] == '1' else '' integer = sum([2**i for i, b in enumerate(bits[1:25][::-1]) if b == '1']) fraction = sum([0.5**i for i, b in enumerate(bits[25:], start=1) if b == '1']) print(sign + str(float(integer...
vfc_46221
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n00000000\n80000000\n00000080\n00000040\n000000c0\n00000100\n80000780\n80000f70", "output": "0.0\n-0.0\n1.0\n0.5\n1.5\n2.0\n-15.0\n-30.875", "type": "stdin_stdout" }, { "fn_name": null, "input": "8...
code_contests
verifiable_code
p00641 Huge Family
Solve the following coding problem using the programming language python: Mr. Dango's family has extremely huge number of members. Once it had about 100 members, and now it has as many as population of a city. It is jokingly guessed that the member might fill this planet in near future. They all have warm and gracious...
```python # AOJ 1055 Huge Family # Python3 2018.7.7 bal4u # UNION-FIND library class UnionSet: def __init__(self, nmax): self.size = [1]*nmax self.id = [i for i in range(nmax+1)] def root(self, i): while i != self.id[i]: self.id[i] = self.id[self.id[i]] i = self.id[i] return i def connected(self, p, q...
vfc_46229
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1 2 3\n0 1 2 2\n1 2 0 3\n7\n1 2 2 1\n0 2 3 2\n0 1 3 1\n2 1 1 2\n5 3 6 2\n4 3 6 1\n4 2 5 1\n0", "output": "1\n2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00784 Pipeline Scheduling
Solve the following coding problem using the programming language python: An arithmetic pipeline is designed to process more than one task simultaneously in an overlapping manner. It includes function units and data paths among them. Tasks are processed by pipelining: at each clock, one or more units are dedicated to ...
vfc_46233
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\nX...XX.\n.X.....\n..X....\n...X...\n......X\n0", "output": "34", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\nX...XX.\n.X.....\n..X/...\n...X...\n......X\n0", "output": "34\n", ...
code_contests
verifiable_code
p00917 Clock Hands
Solve the following coding problem using the programming language python: We have an analog clock whose three hands (the second hand, the minute hand and the hour hand) rotate quite smoothly. You can measure two angles between the second hand and two other hands. Write a program to find the time at which "No two hand...
```python import sys def gcd(m, n): while n: m, n = n, m % n return m readline = sys.stdin.readline write = sys.stdout.write def solve(): f = lambda h, m, s: 3600*h + 60*m + s H, h, m, s = map(int, readline().split()) if H == 0: return False d0 = f(h, m, s) M = f(H, 0, 0) ...
vfc_46237
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "12 0 0 0\n12 11 59 59\n12 1 56 0\n12 1 56 3\n12 1 56 34\n12 3 9 43\n12 3 10 14\n12 7 17 58\n12 7 18 28\n12 7 23 0\n12 7 23 31\n2 0 38 29\n2 0 39 0\n2 0 39 30\n2 1 6 20\n2 1 20 1\n2 1 20 31\n3 2 15 0\n3 2 59 30\n4 0 28 48\n5 1 5 40\...
code_contests
verifiable_code
p01050 String Compression
Solve the following coding problem using the programming language python: Problem Given the string S, which consists of lowercase letters and numbers. Follow the steps below to compress the length of string S. 1. Change the order of the characters in the character string to any order. Example: "0ig3he12fz99"-> "efgh...
```python #!/usr/bin/env python3 # -*- coding: utf-8 -*- from collections import defaultdict S = input() S = sorted(S) S = list(map(ord, S)) ans = 0 while len(S) > 0: mn = S[0] S.remove(mn) nxt = mn + 1 succ = 1 while True: if nxt in S: S.remove(nxt) succ += 1 ...
vfc_46241
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 267386880, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0ig3he12fz99", "output": "9", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01182 Restaurant
Solve the following coding problem using the programming language python: Steve runs a small restaurant in a city. Also, as he is the only cook in his restaurant, he cooks everything ordered by customers. Basically he attends to orders by first-come-first-served principle. He takes some prescribed time to prepare eac...
vfc_46245
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\nRamen 3 10\nChahan 5 5\nGyoza 5 10\nRice 1 1\nSoup 1 1\n5 2 Ramen Gyoza\n10 6 Chahan Gyoza Soup Ramen Gyoza Rice\n20 1 Chahan\n25 1 Ramen\n0 0", "output": "25\n42\n40\n35", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01319 Canal: Water Going Up and Down
Solve the following coding problem using the programming language python: ACM countries have rivers that flow from east to west in the center. This river flows from the neighboring country in the west through the neighboring country in ACM to the neighboring country in the east, and the total length in ACM is K km. It...
```python while True: n, m, k = (int(s) for s in input().split()) if (n, m, k) == (0, 0, 0): break t_out = [0.] * (k + m + 1) tl_east = [0.] * (k + m + 1) tl_west = [0.] * (k + m + 1) for i in range(n): xi, li, fi, di, udi = (int(s) for s in input().split()) if not udi:...
vfc_46249
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1 100\n50 200 20 40 0\n1\n2 4 100\n7 4 1 4 1\n19 5 1 4 0\n5\n3\n7\n9\n1 2 3\n1 1 1 1 0\n1\n3\n1 2 10\n5 10 1 1 1\n2\n3\n0 0 0", "output": "110\n46.6666666667\n5\n41.6666666667", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p01487 RabbitWalking
Solve the following coding problem using the programming language python: Example Input 8 5 1 2 6 5 6 4 1 3 4 7 Output 11 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M = map(int, readline().split()) G = [[] for i in range(N)] for i in range(M): a, b = map(int, readline().split()) G[a-1].append(b-1) G[b-1].append(a-1) col ...
vfc_46253
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 5\n1 2\n6 5\n6 4\n1 3\n4 7", "output": "11", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 5\n1 2\n8 5\n6 4\n1 3\n4 7", "output": "11\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p01649 Billiard
Solve the following coding problem using the programming language python: Problem Statement You have a billiard table. The playing area of the table is rectangular. This billiard table is special as it has no pockets, and the playing area is completely surrounded with a cushion. You succeeded in producing a ultra-pr...
vfc_46257
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n26 16 1 8 4\n10 6\n9 2\n9 10\n3\n71 363 4 8 0\n52 238\n25 33\n59 288\n0", "output": "3\n-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n26 16 1 8 4\n10 6\n9 2\n9 10\n3\n71 363 4 8 0...
code_contests
verifiable_code
p01800 Runner and Sniper
Solve the following coding problem using the programming language python: Example Input 100 100 0 1 Output 1.16699564 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
vfc_46261
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100 100 0 1", "output": "1.16699564", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01934 Dimension travel
Solve the following coding problem using the programming language python: problem Dimension exists from $ 1 $ dimension to $ N $ dimension. AOR Ika can move between dimensions. Specifically, when AOR Ika is in the $ i $ dimension, she can move freely to the $ j $ dimension ($ i> j $), but in the $ k $ dimension ($ i ...
```python # AOJ 2834 Dimension travel # Python3 2018.7.12 bal4u INF = 0x7fffffff import heapq def dijkstra(V, to, start, goal): dist = [INF]*V Q = [] dist[start] = 0 heapq.heappush(Q, (0, start)) while Q: t, s = heapq.heappop(Q) if s == goal: break if dist[s] < t: continue for e in to[s]: nt = t if ...
vfc_46265
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1 2 3\n1 2 3\n1 3", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1 2 3\n1 2 2\n1 3", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02072 All your base are belong to us
Solve the following coding problem using the programming language python: Problem Statement In A.D. 2101, war was beginning. The enemy has taken over all of our bases. To recapture the bases, we decided to set up a headquarters. We need to define the location of the headquarters so that all bases are not so far away ...
vfc_46269
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "", "output": "", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02368 Strongly Connected Components
Solve the following coding problem using the programming language python: A direced graph is strongly connected if every two nodes are reachable from each other. In a strongly connected component of a directed graph, every two nodes of the component are mutually reachable. Constraints * 1 ≤ |V| ≤ 10,000 * 0 ≤ |E| ≤ ...
```python def solve(): N, M = map(int, input().split()) edges = [[] for _ in [0]*N] r_edges = [[] for _ in [0]*N] for _ in [0]*M: a, b = map(int, input().split()) edges[a].append(b) r_edges[b].append(a) c = kosaraju(edges, r_edges) group = [0]*N for i in range(len(c...
vfc_46277
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 6\n0 1\n1 0\n1 2\n2 4\n4 3\n3 2\n4\n0 1\n0 3\n2 3\n3 4", "output": "1\n0\n1\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n0 1\n1 0\n0 2\n2 4\n4 3\n3 2\n4\n0 1\n0 3\n2 3\n3 4", ...
code_contests
verifiable_code
buycar
Solve the following coding problem using the programming language python: Walter white wants to buy a car, he does not care much about the type of car (sedan/hatchback/SUV) nor the power that the car has, all he cares about is how much the car will cost him, since he has loads of money , he wants to buy the most expen...
```python def maxim(lis,n): i=0 maxi=-1000 maxib=-100 coord=0 while i<n: t=lis[i][0]+lis[i][0]*lis[i][1]/100 if(t==maxi): if(lis[i][0]>maxib): maxi=t maxib=lis[i][0] coord=i elif(t>maxi): maxi=t ...
vfc_46281
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\nFerrari $100000 20%\nPorsche $200000 10%\nLamborghini $300000 10%\n2\nBMW $20000 50%\nBenz $15000 100%", "output": "Lamborghini\nBMW", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
conflip
Solve the following coding problem using the programming language python: Little Elephant was fond of inventing new games. After a lot of research, Little Elephant came to know that most of the animals in the forest were showing less interest to play the multi-player games.Little Elephant had started to invent single ...
```python for i in range(int(raw_input())): for j in range(int(raw_input())): i,n,q = map(int,raw_input().split()) if n % 2 == 0: print n/2 else: if i == q: print n/2 else: print n/2 + 1 ```
vfc_46285
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n1 5 1\n1 5 2", "output": "2\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2\n1 1 1\n1 5 2", "output": "0\n3\n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
gerald04
Solve the following coding problem using the programming language python: Problem Statement One day Chef is waiting his girlfriend on the bus station. The girlfriend said that she will be at time1. Chef went to the bus station at time2. When Chef has reached the bus station he realized that he forgot a gift for his be...
```python #!/usr/bin/python t=input() for i in range(t): gh,gm=map(int,raw_input().split(':')) ch,cm=map(int,raw_input().split(':')) gh=gh*60+gm; ch=ch*60+cm; dist=input() if(2*dist<=(gh-ch)) : print float(gh-ch+dist) ,float(gh-ch); else: print float(gh-ch+dist), float(gh-ch+2*dist)/2 ```
vfc_46289
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n10:00\n09:00\n10\n10:00\n09:00\n30\n10:00\n09:00\n60", "output": "70.0 60.0\n90.0 60.0\n120.0 90.0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
makeart
Solve the following coding problem using the programming language python: Chef's new hobby is painting, but he learned the fact that it's not easy to paint 2D pictures in a hard way, after wasting a lot of canvas paper, paint and of course time. From now on, he decided to paint 1D pictures only. Chef's canvas is N mil...
```python for _ in range(int(raw_input())): n = int(raw_input()) a = map(int, raw_input().split()) ans = "No" c = 1 p = a[0] for i in a[1:]: if i == p: c += 1 if c == 3: ans = "Yes" break else: p = i ...
vfc_46293
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4\n1 5 5 5\n4\n1 1 1 5\n3\n5 5 2", "output": "Yes\nYes\nNo\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4\n1 5 5 5\n3\n1 1 1 5\n3\n5 5 2", "output": "Yes\nYes\nNo\n", ...
code_contests
verifiable_code
psudo4
Solve the following coding problem using the programming language python: In the fest of Paradigm, every organiser is given a special kind of pager. The pager consists of a screen and a single big red button. To type a message in it, one has to push the red button that many time at which the alphabet occurs in the alp...
```python n=int(input()) l=[] for i in range(0,n): x=raw_input() val=0 for char in x: val=val+ord(char)-64 l.append(val) for i in l: print i ```
vfc_46297
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nA\nAB", "output": "1\n3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
timeasr
Solve the following coding problem using the programming language python: Chef is sitting in a very boring lecture, waiting for it to end. He has recently asked his friend about the time, and instead of the straightforward answer, his friend, being an absolute jerk, told him the absolute value of angle between hour an...
```python from collections import defaultdict as dd def pre_times(): rs=dd(list) for h in xrange(12): ha=0.0+h*30 ma=0.0 for m in xrange(60): calculated_angle=min(abs(ha-ma),360-abs(ha-ma)) index=int(calculated_angle) rs[index].append({calculated_angle:[h,m]}) ha+=0.5 ma+=6.0 return rs ...
vfc_46301
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n0\n30", "output": "00:00\n01:00\n11:00\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1013_C. Photo of The Sky
Solve the following coding problem using the programming language python: Pavel made a photo of his favourite stars in the sky. His camera takes a photo of all points of the sky that belong to some rectangle with sides parallel to the coordinate axes. Strictly speaking, it makes a photo of all points with coordinates...
```python n = int(input()) a = [int(x) for x in input().split()] a.sort() top = [a[0], a[-1]] right = [a[n - 1], a[n]] case2 = abs((top[0] - right[0])*(top[1] - right[1])) case1 = top[-1] - top[0] mny = 10000000000 for i in range(1, n): mny = min(mny, abs(a[i] - a[i + n-1])) #print(mny) case1 *= mny print(m...
vfc_46305
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 1 3 2 3 2 1 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5 8 5 5 7 5\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": nul...
code_contests
verifiable_code
1060_E. Sergey and Subway
Solve the following coding problem using the programming language python: Sergey Semyonovich is a mayor of a county city N and he used to spend his days and nights in thoughts of further improvements of Nkers' lives. Unfortunately for him, anything and everything has been done already, and there are no more possible i...
```python # by the authority of GOD author: manhar singh sachdev # import os,sys from io import BytesIO,IOBase def main(): n = int(input()) path = [[] for _ in range(n)] for _ in range(n-1): a1,b1 = map(lambda xx:int(xx)-1,input().split()) path[a1].append(b1) path[b1].append(a1) ...
vfc_46313
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 2\n1 3\n1 4\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2\n2 3\n3 4\n", "output": "7\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1082_C. Multi-Subject Competition
Solve the following coding problem using the programming language python: A multi-subject competition is coming! The competition has m different subjects participants can choose from. That's why Alex (the coach) should form a competition delegation among his students. He has n candidates. For the i-th person he know...
```python import sys input=sys.stdin.readline n, m = map(int, input().split()) s = [[] for _ in range(m)] size = [0]*m for _ in range(n): si, ri = map(int, input().split()) s[si-1].append(ri) size[si-1] += 1 # print(s) # print(size) sa = max(size) # print(sa) i = 0 ans = [0]*sa # print("ans",ans) for i i...
vfc_46317
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n1 -1\n1 -5\n2 -1\n2 -1\n1 -10\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3\n2 6\n3 6\n2 5\n3 5\n1 9\n3 1\n", "output": "22\n", "type": "stdin_stdou...
code_contests
verifiable_code
1101_E. Polycarp's New Job
Solve the following coding problem using the programming language python: Polycarp has recently got himself a new job. He now earns so much that his old wallet can't even store all the money he has. Berland bills somehow come in lots of different sizes. However, all of them are shaped as rectangles (possibly squares)...
```python import sys amount = int(input()) max_1 = -1 max_2 = -1 ans = "" for i in range(amount): inputs = [s for s in input().split()] x = int(inputs[1]) y = int(inputs[2]) if x > y: x,y = y,x if inputs[0] == '+': if max_1 < x: max_1 = x if max_2 < y: ...
vfc_46321
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n+ 3 2\n+ 2 3\n? 1 20\n? 3 3\n? 2 3\n+ 1 5\n? 10 10\n? 1 5\n+ 1 1\n", "output": "NO\nYES\nYES\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n+ 47 81\n? 18 64\n? 49 81\n? 87...
code_contests
verifiable_code
112_C. Petya and Inequiations
Solve the following coding problem using the programming language python: Little Petya loves inequations. Help him find n positive integers a1, a2, ..., an, such that the following two conditions are satisfied: * a12 + a22 + ... + an2 ≥ x * a1 + a2 + ... + an ≤ y Input The first line contains three space-separa...
```python n, x, y = input().split() n=int(n) x=int(x) y=int(y) a = y-n+1 if a<=0: print(-1) else: if a**2 + n - 1 >= x: print(a) for i in range(n-1): print(1) else: print(-1) ```
vfc_46325
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 15 15\n", "output": "11\n1\n1\n1\n1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
114_D. Petr#
Solve the following coding problem using the programming language python: Long ago, when Petya was a schoolboy, he was very much interested in the Petr# language grammar. During one lesson Petya got interested in the following question: how many different continuous substrings starting with the sbegin and ending with ...
```python from functools import cmp_to_key def calc_lcp(s, sa): rank = [0 for _ in range(len(s))] for i in range(len(s)): rank[sa[i]] = i lcp = [0 for _ in range(len(s) - 1)] h = 0 for i in range(len(s)): if rank[i] < len(s) - 1: while max(i, sa[rank[i] + 1])...
vfc_46329
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "round\nro\nou\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abababab\na\nb\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1227_F2. Wrong Answer on test 233 (Hard Version)
Solve the following coding problem using the programming language python: Your program fails again. This time it gets "Wrong answer on test 233" . This is the harder version of the problem. In this version, 1 ≤ n ≤ 2⋅10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you ...
```python from bisect import * from collections import * from math import gcd,ceil,sqrt,floor,inf from heapq import * from itertools import * from operator import add,mul,sub,xor,truediv,floordiv from functools import * #------------------------------------------------------------------------ import os import sys from...
vfc_46345
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2\n1 1 2 2 1 1\n", "output": "16\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 3 1\n", "output": "9\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1250_F. Data Center
Solve the following coding problem using the programming language python: You are developing a project to build a new data center. The data center will be a rectangle with an area of exactly n square meters. Each side of the data center must be an integer. Your goal is to minimize the impact of the external environme...
vfc_46349
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "36\n", "output": "\n24\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13\n", "output": "\n28\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n...
code_contests
verifiable_code
126_D. Fibonacci Sums
Solve the following coding problem using the programming language python: Fibonacci numbers have the following form: F1 = 1, F2 = 2, Fi = Fi - 1 + Fi - 2, i > 2. Let's consider some non-empty set S = {s1, s2, ..., sk}, consisting of different Fibonacci numbers. Let's find the sum of values of this set's elements: ...
vfc_46353
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n13\n16\n", "output": " 3\n 4\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1292_C. Xenon's Attack on the Gangs
Solve the following coding problem using the programming language python: [INSPION FullBand Master - INSPION](https://www.youtube.com/watch?v=kwsciXm_7sA) [INSPION - IOLITE-SUNSTONE](https://www.youtube.com/watch?v=kwsciXm_7sA) On another floor of the A.R.C. Markland-N, the young man Simon "Xenon" Jackson, takes a b...
```python import sys # Read input and build the graph inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 n = inp[ii]; ii += 1 coupl = [[] for _ in range(n)] for _ in range(n - 1): u = inp[ii] - 1; ii += 1 v = inp[ii] - 1; ii += 1 coupl[u].append(v) coupl[v].append(u) # Relable to speed up n^2 ...
vfc_46357
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2\n2 3\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2\n1 3\n1 4\n3 5\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
1355_C. Count Triangles
Solve the following coding problem using the programming language python: Like any unknown mathematician, Yuri has favourite numbers: A, B, C, and D, where A ≤ B ≤ C ≤ D. Yuri also likes triangles and once he thought: how many non-degenerate triangles with integer sides x, y, and z exist, such that A ≤ x ≤ B ≤ y ≤ C ≤...
```python a,b,c,d=map(int,input().split(" ")) li=[0]*int(pow(10,6)+2) n=int(pow(10,6)+2) for i in range(a,b+1): li[i+b]+=1 li[i+c+1]-=1 for i in range(1,n): li[i]+=li[i-1] for i in range(1,n): li[i]+=li[i-1] ans=0 for i in range(c,d+1): ans+=li[n-1]-li[i] print(ans) ```
vfc_46369
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2 2 5\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 3 4\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "500...
code_contests
verifiable_code
1398_E. Two Types of Spells
Solve the following coding problem using the programming language python: Polycarp plays a computer game (yet again). In this game, he fights monsters using magic spells. There are two types of spells: fire spell of power x deals x damage to the monster, and lightning spell of power y deals y damage to the monster an...
```python import bisect import sys input = sys.stdin.readline class TreeSet(object): """ Binary-tree set like java Treeset. Duplicate elements will not be added. When added new element, TreeSet will be sorted automatically. """ def __init__(self, elements): self._treeset = [] se...
vfc_46377
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 5\n0 10\n1 -5\n0 5\n1 11\n0 -10\n", "output": "5\n25\n10\n15\n36\n21\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 5\n0 10\n1 -5\n1 5\n1 11\n0 -10\n", "output": "5\n25\n1...
code_contests
verifiable_code
1422_A. Fence
Solve the following coding problem using the programming language python: Yura is tasked to build a closed fence in shape of an arbitrary non-degenerate simple quadrilateral. He's already got three straight fence segments with known lengths a, b, and c. Now he needs to find out some possible integer length d of the fo...
```python t = int(input()) for i in range(t): a, b, c = map(int, input().split()) sides = [a, b, c] print(max(sides) + 1) ```
vfc_46381
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2 3\n12 34 56\n", "output": "5\n101\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n5 4 3\n", "output": "11\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
143_E. Help Caretaker
Solve the following coding problem using the programming language python: Autumn came late to the kingdom of Far Far Away. The harvest was exuberant and it is now time to get ready for the winter. As most people celebrate the Harvest festival, Simon the Caretaker tries to solve a very non-trivial task of how to find p...
vfc_46385
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 6\n", "output": "4\nAAABBB\n.A..B.\nCA.DB.\nCCCDDD\nC..D..\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n", "output": "1\nAAA\n.A.\n.A.\n\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1491_D. Zookeeper and The Infinite Zoo
Solve the following coding problem using the programming language python: There is a new attraction in Singapore Zoo: The Infinite Zoo. The Infinite Zoo can be represented by a graph with an infinite number of vertices labeled 1,2,3,…. There is a directed edge from vertex u to vertex u+v if and only if u\&v=v, where ...
```python import sys readline = sys.stdin.readline T = int(readline()) Ans = ['NO']*T limit = 33 for qu in range(T): u, v = map(int, readline().split()) if u <= v: p = 0 for k in range(limit): if (1<<k)&u == (1<<k)&v: continue if (1<<k)&u == 0: ...
vfc_46393
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 4\n3 6\n1 6\n6 2\n5 5\n", "output": "\nYES\nYES\nNO\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 4\n3 7\n1 6\n6 2\n5 5\n", "output": "YES\nNO\nNO\nNO\nYES\n", ...
code_contests
verifiable_code
1514_A. Perfectly Imperfect Array
Solve the following coding problem using the programming language python: Given an array a of length n, tell us whether it has a non-empty subsequence such that the product of its elements is not a perfect square. A sequence b is a subsequence of an array a if b can be obtained from a by deleting some (possibly zero)...
```python import math rr = input rri = lambda: int(rr()) rrm = lambda: list(map(int, rr().split())) def perfect_square(n): root = math.sqrt(n) if int(root + 0.5) ** 2 == n: return True else: return False def prod(lst): ret = 1 for i in lst: ret *= i return ret def sol...
vfc_46397
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n1 5 4\n2\n100 10000\n", "output": "\nYES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1\n1\n1\n2\n1\n3\n", "output": "NO\nYES\nYES\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1541_A. Pretty Permutations
Solve the following coding problem using the programming language python: There are n cats in a line, labeled from 1 to n, with the i-th cat at position i. They are bored of gyrating in the same spot all day, so they want to reorder themselves such that no cat is in the same place as before. They are also lazy, so the...
```python t = int(input()) for j in range(t): n = int(input()) a = [int(i) for i in range(1, n + 1)] if n % 2 == 0: for i in range(0, n, 2): a[i], a[i + 1] = a[i + 1], a[i] else: for i in range(0, n - 1, 2): a[i], a[i + 1] = a[i + 1], a[i] a[-2], a[-1] = a...
vfc_46401
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n3\n", "output": "2 1 \n3 1 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "99\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n...
code_contests
verifiable_code
168_E. Wizards and Numbers
Solve the following coding problem using the programming language python: In some country live wizards. They love playing with numbers. The blackboard has two numbers written on it — a and b. The order of the numbers is not important. Let's consider a ≤ b for the sake of definiteness. The players can cast one of the...
vfc_46405
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n10 21\n31 10\n0 1\n10 30\n", "output": "First\nSecond\nSecond\nFirst\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "66\n7 0\n5 7\n1 3\n3 2\n3 5\n0 6\n1 2\n0 7\n4 5\n4 7\n5 1\n2 0\n4 0\...
code_contests
verifiable_code
212_C. Cowboys
Solve the following coding problem using the programming language python: A very tense moment: n cowboys stand in a circle and each one points his colt at a neighbor. Each cowboy can point the colt to the person who follows or precedes him in clockwise direction. Human life is worthless, just like in any real western....
vfc_46413
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "BABBBABBA\n", "output": " 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "ABABAB\n", "output": " ...
code_contests
verifiable_code
236_C. LCM Challenge
Solve the following coding problem using the programming language python: Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't ha...
```python from math import * n, ans = int(input()), 0 if n < 3: ans = n elif n % 2: ans = n * (n - 1) * (n - 2) else: a = 0 if gcd(n, n - 3) == 1: a = n * (n - 1) * (n - 3) n -= 1 ans = max(n * (n - 1) * (n - 2), a) print(ans) ```
vfc_46417
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\n", "output": "504\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n", "output": "210\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "862795\...
code_contests
verifiable_code
261_A. Maxim and Discounts
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 customer tak...
```python #!/usr/bin/env python from __future__ import division, print_function import math import os import sys from fractions import * from sys import * from decimal import * from io import BytesIO, IOBase from itertools import * from collections import * # sys.setrecursionlimit(10**5) M = 10 ** 9 + 7 # print(math....
vfc_46421
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n4\n50 50 100 100\n", "output": "200", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 3\n5\n50 50 50 50 50\n", "output": "150", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
285_A. Slightly Decreasing Permutations
Solve the following coding problem using the programming language python: Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as pi. We'll call number n the size or the length of permutati...
```python n,k = map(int,input().strip().split()) a=list(range(1,n+1)) a[:k+1] = a[k::-1] a=[str(i) for i in a] print(' '.join(a)) ```
vfc_46425
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n", "output": "3 2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n", "output": "5 4 1 2 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
30_A. Accounting
Solve the following coding problem using the programming language python: A long time ago in some far country lived king Copa. After the recent king's reform, he got so large powers that started to keep the books by himself. The total income A of his kingdom during 0-th year is known, as well as the total income B du...
```python import math import sys a,b,c=input().split(' ') a=int(a); b=int(b); c=int(c) for i in range( -abs(b), abs(b)+1): if a*pow(i, c)==b: print(i,end='') sys.exit(0) print("No solution",end='') ```
vfc_46429
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 0 10\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "-1 8 3\n", "output": "-2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
332_D. Theft of Blueprints
Solve the following coding problem using the programming language python: Insurgents accidentally got hold of the plan of a top secret research polygon created on a distant planet for the needs of the Galaxy Empire. The insurgents suppose that this polygon is developing new deadly weapon. The polygon consists of n mis...
```python import sys sys.setrecursionlimit(2100) range = xrange input = raw_input def getter(DP, n, k): if 2 * k >= n: k = n - k if k < 0: return 0 return DP[k] inp = [int(x) for x in sys.stdin.read().split()]; ii = 0 n = inp[ii]; ii += 1 k = inp[ii]; ii += 1 DP = [1] DPk = [] DPkm1 = [] ...
vfc_46433
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n10 0\n11\n", "output": "14\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
355_D. Game with Strings
Solve the following coding problem using the programming language python: Given an n × n table T consisting of lowercase English letters. We'll consider some string s good if the table contains a correct path corresponding to the given string. In other words, good strings are all strings we can obtain by moving from t...
vfc_46437
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nxa\nay\n", "output": "FIRST\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nab\ncd\n", "output": "DRAW\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
379_E. New Year Tree Decorations
Solve the following coding problem using the programming language python: Due to atheistic Soviet past, Christmas wasn't officially celebrated in Russia for most of the twentieth century. As a result, the Russian traditions for Christmas and New Year mixed into one event celebrated on the New Year but including the tr...
vfc_46441
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n2 1 2\n1 2 1\n", "output": "3.000000000\n0.500000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 1\n2 7\n7 2\n5 5\n6 4\n", "output": "4.500000000\n1.250000000\n0.050000000...
code_contests
verifiable_code
3_A. Shortest path of the king
Solve the following coding problem using the programming language python: The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square t. As the king is not in habit of wasting his ti...
```python xi = tuple(input()) xf = tuple(input()) row = [1,2,3,4,5,6,7,8] col = ["a","b","c","d","e","f","g","h"] movelist=[] row_in = int(xi[1]) col_in = xi[0] row_fin = int(xf[1]) col_fin = xf[0] index_ri = row.index(row_in) index_rf = row.index(row_fin) index_ci = col.index(col_in) index_cf = col.index(col_fin) ...
vfc_46445
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "a8\nh1\n", "output": "7\nRD\nRD\nRD\nRD\nRD\nRD\nRD\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "g8\na8\n", "output": "6\nL\nL\nL\nL\nL\nL\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
426_C. Sereja and Swaps
Solve the following coding problem using the programming language python: As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation: <image> A swap operation is the following sequence of actions: * choose two indexes i, j (i ≠ j); * perform assignments tmp = a[i],...
```python read_line = lambda: [int(i) for i in input().split()] n, k = read_line() x = read_line() print(max(sum(sorted(x[l:r] + sorted(x[:l] + x[r:])[-k:])[l-r:]) for l in range(n) for r in range(l + 1, n + 1))) # Made By Mostafa_Khaled ```
vfc_46449
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 2\n10 -1 2 2 2 2 2 2 -1 10\n", "output": "32\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 10\n-1 -1 -1 -1 -1\n", "output": "-1\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
44_F. BerPaint
Solve the following coding problem using the programming language python: Anfisa the monkey got disappointed in word processors as they aren't good enough at reflecting all the range of her emotions, that's why she decided to switch to graphics editors. Having opened the BerPaint, she saw a white rectangle W × H in si...
vfc_46453
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 4\n9\n1 2 2 3\n2 3 3 2\n3 2 2 1\n2 1 1 2\n3 2 4 2\n4 2 5 3\n5 3 6 2\n6 2 5 1\n5 1 4 2\n2\n2 2 black\n2 2 red\n", "output": "red 2.0000000000\nwhite 26.0000000000\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
471_B. MUH and Important Things
Solve the following coding problem using the programming language python: It's time polar bears Menshykov and Uslada from the zoo of St. Petersburg and elephant Horace from the zoo of Kiev got down to business. In total, there are n tasks for the day and each animal should do each of these tasks. For each task, they h...
```python n = int(input()) ar = [int(i) for i in input().split()] new = sorted((ar[i],i+1) for i in range(n)) res = [new[i][1] for i in range(n)] swap = [] for i in range(n-1): if new[i][0] == new[i+1][0]: swap.append((i,i+1)) if len(swap) == 2: print("YES") print(" ".join(str(i) for i in res)) ...
vfc_46457
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 3 3 1\n", "output": "YES\n1 4 2 3 \n4 1 2 3 \n4 1 3 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 4 1 4 8\n", "output": "NO", "type": "stdin_stdout" }, {...
code_contests
verifiable_code
51_A. Cheaterius's Problem
Solve the following coding problem using the programming language python: Cheaterius is a famous in all the Berland astrologist, magician and wizard, and he also is a liar and a cheater. One of his latest inventions is Cheaterius' amulets! They bring luck and wealth, but are rather expensive. Cheaterius makes them him...
```python nro_amu = int(input()) amu = [] for i in range(nro_amu): fila1 = list(input()) fila2 = list(input()) fila1.extend(fila2) amu.append(fila1) if i+1 != nro_amu: _ = input() pilas = [] nro_pilas = 0 for a in amu: existe = False for i in range(nro_pilas): for...
vfc_46465
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n31\n23\n**\n31\n23\n**\n13\n32\n**\n32\n13\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
546_B. Soldier and Badges
Solve the following coding problem using the programming language python: Colonel has n badges. He wants to give one badge to every of his n soldiers. Each badge has a coolness factor, which shows how much it's owner reached. Coolness factor can be increased by one for the cost of one coin. For every pair of soldier...
```python n=int(input());k=0 if n==1:print(0);exit() a=list(map(int,input().split()));b=[];c=[] for i in range(n*n):b.append(0) for i in range(n): if b[a[i]]==0:b[a[i]]=a[i] else:c.append(a[i]) for i in range(len(c)): for j in range(c[i],len(b)): if b[j]==0:k+=b[j-1]-c[i]+1;b[j]=j;break print(k) ```
vfc_46469
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 2 5\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
615_E. Hexagons
Solve the following coding problem using the programming language python: Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined: ...
```python import math def main(m): if m == 0: print("0 0") else: x = math.floor(1/6*((12*m - 3)**0.5 + 3)) # Approx ?... while True: d = m - (x**3 - (x-1)**3) if (d < 0): x -= 1 elif (d > x * 6 + 6): x += 1 else: break s,r = divmod(...
vfc_46481
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n", "output": " 3 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": " ...
code_contests
verifiable_code
635_A. Orchestra
Solve the following coding problem using the programming language python: Paul is at the orchestra. The string section is arranged in an r × c rectangular grid and is filled with violinists with the exception of n violists. Paul really likes violas, so he would like to take a picture including at least k of them. Paul...
```python import io import sys import time import random #~ start = time.clock() #~ test = '''2 2 1 1 #~ 1 2''' #~ test = '''3 2 3 3 #~ 1 1 #~ 3 1 #~ 2 2''' #~ test = '''3 2 3 2 #~ 1 1 #~ 3 1 #~ 2 2''' #~ sys.stdin = io.StringIO(test) r,c,n,k = map(int,input().split()) # row column number-of-violists data = [ [0 for ...
vfc_46485
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2 3 3\n1 1\n3 1\n2 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2 1 1\n1 2\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
663_E. Binary Table
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 either 0 or 1. In one move, you are allowed to pick any row or any column and invert all values, that is, replace 0 by 1 and vice versa. What is the minim...
vfc_46489
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n0110\n1010\n0111\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
688_C. NP-Hard Problem
Solve the following coding problem using the programming language python: Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting. Suppose the graph G is given. Subset A of its vertices is called a vertex cover of this graph, if for each edge u...
```python n,m=map(int,input().split()) flag=False f=[0]*100001 E=[[] for i in range(n+1)] e=[tuple(map(int,input().split())) for _ in range(m)] for u,v in sorted(e): E[u]+=[v]; E[v]+=[u] def bfs(nom,col): ch=[(nom,col)] while ch: v,c=ch.pop() if f[v]==0: f[v]=c for u in E[v]: ...
vfc_46493
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n1 2\n2 3\n1 3\n", "output": "-1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
710_B. Optimal Point on a Line
Solve the following coding problem using the programming language python: You are given n points on a line with their coordinates xi. Find the point x so the sum of distances to the given points is minimal. Input The first line contains integer n (1 ≤ n ≤ 3·105) — the number of points on the line. The second line c...
```python n=int(input()) q=sorted(list(map(int,input().split()))) print(q[(n-1)//2]) ```
vfc_46497
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 2 3 4\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
731_B. Coupons and Discounts
Solve the following coding problem using the programming language python: The programming competition season has already started and it's time to train for ICPC. Sereja coaches his teams for a number of year and he knows that to get ready for the training session it's not enough to prepare only problems and editorial....
```python n = int(input()) l = list(map(int, input().split())) carrier = 0 for i in range(n): if l[i] == 0 and carrier == 1: print("NO") exit() if l[i] % 2 == 1: if carrier == 0: carrier = 1 else: carrier = 0 if carrier == 0: print("YES")...
vfc_46501
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 0 1\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 1 2\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
755_D. PolandBall and Polygon
Solve the following coding problem using the programming language python: PolandBall has such a convex polygon with n veritces that no three of its diagonals intersect at the same point. PolandBall decided to improve it and draw some red segments. He chose a number k such that gcd(n, k) = 1. Vertices of the polygon ...
```python import sys inf = (1 << 31) - 1 def solve(): n, k = map(int, input().split()) if k > n - k: k = n - k bit = BinaryIndexedTree([0]*n) s = 0 res = 1 ans = [] for i in range(n): t = (s + k) % n if s < t: res += bit.get_sum(t) - bit.get_sum(s +...
vfc_46505
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 3\n", "output": "2 3 4 6 9 12 16 21 26 31 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n", "output": "2 3 5 8 11 ", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
801_A. Vicious Keyboard
Solve the following coding problem using the programming language python: Tonio has a keyboard with only two letters, "V" and "K". One day, he has typed out a string s with only these two letters. He really likes it when the string "VK" appears, so he wishes to change at most one letter in the string (or do no change...
```python a = input() b = [a.count('VK')] + [0] * len(a) s = a[:] for i in range(len(a)): if a[i] == 'V': if i != len(a) - 1: s = s[:i] + 'K' + s[i + 1:] else: s = s[:i] + 'K' else: if i != len(a) - 1: s = s[:i] + 'V' + s[i + 1:] else: ...
vfc_46513
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "VK\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "V\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "VKKKKKKKKK...
code_contests
verifiable_code
821_C. Okabe and Boxes
Solve the following coding problem using the programming language python: Okabe and Super Hacker Daru are stacking and removing boxes. There are n boxes numbered from 1 to n. Initially there are no boxes on the stack. Okabe, being a control freak, gives Daru 2n commands: n of which are to add a box to the top of the ...
```python n = int(input()) cnt = 1 ans = 0 l = [] for i in range(2*n): a = input() if a[0] == 'a': l.append(int(a[4:])) else: if len(l) == 0: cnt += 1 elif l[-1] == cnt: l.pop() cnt += 1 else: l = [] ans += 1 ...
vfc_46517
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\nadd 3\nadd 2\nadd 1\nremove\nadd 4\nremove\nremove\nremove\nadd 6\nadd 7\nadd 5\nremove\nremove\nremove\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nadd 1\nremove\n...
code_contests
verifiable_code
847_C. Sum of Nestings
Solve the following coding problem using the programming language python: Recall that the bracket sequence is considered regular if it is possible to insert symbols '+' and '1' into it so that the result is a correct arithmetic expression. For example, a sequence "(()())" is regular, because we can get correct arithme...
```python # Legends Always Come Up with Solution # Author: Manvir Singh import os import sys from io import BytesIO, IOBase from collections import Counter from bisect import * from math import gcd from itertools import permutations,combinations from math import sqrt,ceil,floor def main(): n,k=map(int,input().spl...
vfc_46521
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n", "output": "(())()", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 5\n", "output": "Impossible\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
868_E. Policeman and a Tree
Solve the following coding problem using the programming language python: You are given a tree (a connected non-oriented graph without cycles) with vertices numbered from 1 to n, and the length of the i-th edge is wi. In the vertex s there is a policeman, in the vertices x1, x2, ..., xm (xj ≠ s) m criminals are locate...
vfc_46525
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 2 3\n2 3 5\n3 4 1\n3 5 4\n2 6 3\n2\n3\n1 3 5\n", "output": "21\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 2\n1 3 1\n1 4 1\n2\n4\n3 1 4 1\n", "output": "8\n", "...
code_contests
verifiable_code
894_B. Ralph And His Magic Field
Solve the following coding problem using the programming language python: Ralph has a magic field which is divided into n × m blocks. That is to say, there are n rows and m columns on the field. Ralph can put an integer in each block. However, the magic field doesn't always work properly. It works only if the product ...
```python def main(): N, M, K = [int(i) for i in input().split()] if (N + M) % 2 != 0 and K == -1: print(0) else: P = ((N - 1)*(M - 1)) print(pow(2, P, 1000000007)) main() # 1512152080884 ```
vfc_46529
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3 -1\n", "output": "16\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 3 1\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1...
code_contests
verifiable_code
915_E. Physical Education Lessons
Solve the following coding problem using the programming language python: This year Alex has finished school, and now he is a first-year student of Berland State University. For him it was a total surprise that even though he studies programming, he still has to attend physical education lessons. The end of the term i...
vfc_46533
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n6\n1 2 1\n3 4 1\n2 3 2\n1 3 2\n2 4 1\n1 4 2\n", "output": "2\n0\n2\n3\n1\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n8\n2 2 1\n3 3 2\n1 1 1\n1 3 2\n2 3 2\n3 3 1\n1 2 1\n2 2 2\...
code_contests
verifiable_code
938_F. Erasing Substrings
Solve the following coding problem using the programming language python: You are given a string s, initially consisting of n lowercase Latin letters. After that, you perform k operations with it, where <image>. During i-th operation you must erase some substring of length exactly 2i - 1 from s. Print the lexicograph...
vfc_46537
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "adcbca\n", "output": "aba\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abacabadabacaba\n", "output": "aabacaba\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
964_A. Splits
Solve the following coding problem using the programming language python: Let's define a split of n as a nonincreasing sequence of positive integers, the sum of which is n. For example, the following sequences are splits of 8: [4, 4], [3, 3, 2], [2, 2, 1, 1, 1, 1], [5, 2, 1]. The following sequences aren't splits o...
```python from collections import deque import math import os import random import re import sys #n=list(map(int, input().split())) #n=map(int, input().split()) def main(): n=int(input()) ans=n//2+1 print(ans) main() ```
vfc_46541
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n", ...
code_contests
verifiable_code
991_B. Getting an A
Solve the following coding problem using the programming language python: Translator's note: in Russia's most widespread grading system, there are four grades: 5, 4, 3, 2, the higher the better, roughly corresponding to A, B, C and F respectively in American grading system. The term is coming to an end and students s...
```python #!/usr/bin/env python3 n = int(input().strip()) ais = list(map(int, input().strip().split())) ais.sort() cnt = 0 s = sum(ais) thrs = -((-9 * n) // 2) # ceil(4.5 * n) while s < thrs: s += 5 - ais[cnt] cnt += 1 print (cnt) ```
vfc_46545
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5 3 3 5\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
aquarium-visit-b-1
Solve the following coding problem using the programming language python: Kritika visits a aquarium and is astonished to find that the sections of aquarium are numbered in a different way. First Section : -1 Second Section : 1 Third Section : 16 Fourth Section : 60 She realized that there is a pattern in the...
```python print 5170862977916541521 ```
vfc_46549
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "67438", "output": "5170862977916541521", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
chandu-and-xor-6
Solve the following coding problem using the programming language python: Chandu is weak in maths. His teacher gave him homework to find maximum possible pair XOR in a matrix of size N x M with some conditions. Condition imposed is that, the pair can be formed between sum of elements in a column and sum of elements in...
```python def XOR(a,b): return a ^ b def chandu_xor(matrix): sumN = [] sumM = [] for i in range(0,N): sum_ = 0 for j in range(0,M): sum_ = sum_ + matrix[i][j] sumN.append(sum_) for i in range(0,M): sum_ = 0 for j in range(0,N): sum_ = s...
vfc_46553
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n1 2\n3 4\n\nSAMPLE", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n9 \n16 \n16", "output": "57\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
divide-to-three-33
Solve the following coding problem using the programming language python: Stannis borathean is attacking kings landing from three gates.To defend the city Tyrion again comes up with a fair solution. Tyrion has N soldier troops with given strengths. Tyrion wants to divide army into 3 sets such that the sum of strengths...
```python import itertools,sys t=input() tn=t l=[] while t>0: n=input() l.append(n) t=t-1 li=range(0,tn) tsm=sum(l) rt=[] mdiff=99999 for i in xrange(1,tn-1): for j in itertools.combinations(li,i): diff=list(set(li)-set(j)) #print list(diff)[0] d={0:0} td={0:0} ...
vfc_46557
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3\n4\n1\n3\n\nSAMPLE", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n3\n4\n1\n3\n\nELPMAS", "output": "4\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
good-words
Solve the following coding problem using the programming language python: Description In a particular language words are written using only two symbols: ones(1) and zeroes(0). A given word N is called “good” if it can be written in the form of concatenation of several(two or more than two) copies of some shorter word,...
```python dc = dict() def desfac(n): for i in range(2,n): if n%i == 0: dc[i] = 0 def gcd(a, b): while b: a, b = b, a%b return a def fac(a): s = 1 for i in range(2,a+1): s *= i return s zer = int(input()) one = int(input()) md = 10**7+1 span = zer+one ans = 0 for i in range(1, span+1): # ...
vfc_46561
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n0", "output": "1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
little-deepu-vs-little-kuldeep
Solve the following coding problem using the programming language python: Little Deepu and Little Kuldeep are the two best warriors in the realm of Westeros. But, their priorities and their loyalties are very much divided. Little Kuldeep fights for the right, just while Little Deepu fights for the wrong reasons, and s...
```python M=10**9+7 a=[1]*2000001 for i in range(1,2000001): a[i]=(a[i-1]*i)%M for t in range(input()): n=input() print (a[n<<1]*pow(a[n+1],M-2,M)*pow(a[n],M-2,M))%M ```
vfc_46565
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n1548\n\nSAMPLE", "output": "2\n57584392", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n826555\n29937\n82698\n346981\n490420\n801306\n142167\n948126\n190048\n472464\n365458\n53378...
code_contests
verifiable_code
moody-numbers
Solve the following coding problem using the programming language python: Some people are just moody, you just cannot reason with them. Same goes with Natural Numbers. Some of them ultimely want to become 1 or 4 and will evolve infinite times if they have to, to become what they want to. To evolve, they use a function...
```python mem={} def sum_digits3(n): n=n**2 r = 0 while n: r, n = r + n % 10, n // 10 return r def findnature(n): if(mem.has_key(n)):return mem[n] if(n==1 or n==4): return 1 if(n==9 or n==13): return -1 ans=findnature(sum_digits3(n)) mem[n]=ans return ans for t in range(int(...
vfc_46569
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1\n2\n3\n8\n\nSAMPLE", "output": "YES\nYES\nNO\nYES", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
power-of-twos-1
Solve the following coding problem using the programming language python: Little Jhool is friend with the magical creature from Koi Mil Gaya as we all know, called Jaadu. Now, Jhool is learning Mathematics from Jaadu; he wants to know about the Mathematics of the other planet, too. In Jaadu's planet, the sequenc...
```python import math t = input() for k in range(t): n=input() srt = int(math.sqrt(n)) r=0 for i in range(1,srt+1): r += n/i print 2*r - srt**2 -n ```
vfc_46573
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10000\n20001\n20002\n20003\n20004\n20005\n20006\n20007\n20008\n20009\n20010\n20011\n20012\n20013\n20014\n20015\n20016\n20017\n20018\n20019\n20020\n20021\n20022\n20023\n20024\n20025\n20026\n20027\n20028\n20029\n20030\n20031\n20032\n...
code_contests
verifiable_code
sale-2
Solve the following coding problem using the programming language python: There is a sale in the market on clothes , so as usual N girls gathered there to grab great deals.But due to huge popularity of sale crowd has gone uncontrollable. You being head of management team of the mall has been assigned the task to make ...
```python def dfs(i, parent): global res, visited if visited[i]: res = False return visited[i] = True for adj in G[i]: if adj != parent: dfs(adj, i) for tc in xrange(input()): V, E = map(int, raw_input().split()) G = [[] for i in xrange(V + 1)] res = True for e in xrange(E): a, b = map(int, raw_i...
vfc_46577
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 3\n1 2\n3 4\n2 5\n4 3\n1 2\n1 3\n1 4\n\nSAMPLE", "output": "YES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5 3\n1 2\n3 4\n2 5\n4 1\n1 2\n1 3\n1 4\n\nSAMPLE", "output...
code_contests
verifiable_code
sum-of-primes
Solve the following coding problem using the programming language python: Dark with his love for the prime numbers wanted to do some arithmetic so he decided to do some additions. He wants to generate all prime numbers between two given numbers and add them up and decide whether that addition of numbers is a prime nu...
```python # Sum of prime number # import time import sys # import os import math PRIME_NUMS = [2] def check_prime(n): limit = int(math.sqrt(n)) idx = 0 while(PRIME_NUMS[idx] <= limit): if n % PRIME_NUMS[idx] == 0: return(False) idx += 1 return(True) def main(): m_list = [] n_list = [] no_case = int(sy...
vfc_46581
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 9\n14 37\n1 6\n\nSAMPLE", "output": "YES\nNO\nNO", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
weighted-string
Solve the following coding problem using the programming language python: Given a string S which contains only lowercase characters ['a'-'z'] and an integer K you have to find number of substrings having weight equal to K. Weight of characters is defined as : Weight['a']=1 Weight['b']=2 Weight['c']=3 Weight['d'...
```python def binary_search(ar, key): lo, hi = 0, len(ar) - 1 while lo<=hi: mid = (lo + hi) >> 1 if ar[mid] == key: return True elif ar[mid]<key: lo = mid + 1 else: hi = mid - 1 return False T = int(raw_input()) for _ in range(T): K = int(raw_input()) ar = [ord(i) - 97 + 1 for i in raw_input()] #print ar...
vfc_46585
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\nabcdef\n4\nabcdefSAMPLE", "output": "2\n1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n6\nabcdef\n4\nabcdefSAMPLE", "output": "2\n1\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
p00039 Roman Figure
Solve the following coding problem using the programming language python: Counting was a difficult task in ancient Rome. The Arabic numerals 0,1,2,3,…, 9 have not yet been disseminated. Instead, the following symbols were used: Arabic numerals | Roman numerals | Arabic numerals | Roman numerals | Arabic numerals | Ro...
```python import sys r={'I':1,'V':5,'X':10,'L':50,'C':100,'D':500,'M':1000} for e in sys.stdin: a=0 n=[r[c]for c in e.strip()] for i in range(len(n)): if i+1<len(n)and n[i]<n[i+1]:a-=n[i] else:a+=n[i] print(a) ```
vfc_46629
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "IV\nCCCCLXXXXVIIII\nCDXCIX", "output": "4\n499\n499", "type": "stdin_stdout" }, { "fn_name": null, "input": "VI\nCCCCLXXXXVIIII\nCDXCIX", "output": "6\n499\n499\n", "type": "stdin_stdout"...
code_contests
verifiable_code
p00171 Dice Puzzle
Solve the following coding problem using the programming language python: There is a dice with one letter of the alphabet (a ~ z, A ~ Z) drawn on each side. <image> Consider combining eight such dice to make a 2 x 2 x 2 cube. <image> There are conditions on how to combine the dice, and the facing faces of each...
vfc_46633
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "zabZNq\nBCxmAi\nZcbBCj\naizXCm\nQgmABC\nJHzMop\nImoXGz\nMZTOhp\nzabZnQ\nBCxmAi\nZcbBCj\naizXCm\nQgmABC\nJHzMop\nImoXGz\nMZTOhp\nabcdef\nABDCFE\nFBDCAE\nabcdef\nBEACDF\nbfcaed\nfabcde\nDEABCF\nUnivOf\nAizuaH\nzTXZYW\npiglIt\nGRULNP\...
code_contests
verifiable_code
p00500 Unique number
Solve the following coding problem using the programming language python: problem JOI decided to play a game with his friends. N players participate in this game. The rules for a single game are as follows: Each player writes a favorite integer from 1 to 100 on the card and submits it. Each player gets the same scor...
```python n=int(input()) p=[list(map(int,input().split())) for _ in range(n)] point=[0]*n for j in range(3): r=[row[j] for row in p] for i in range(n): if i==0: if r[i] not in r[1:]: point[0]+=r[i] elif i==n-1: if r[i] not in r[:n-1]: point...
vfc_46641
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n100 99 98\n100 97 92\n63 89 63\n99 99 99\n89 97 98", "output": "0\n92\n215\n198\n89", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n100 99 98\n100 97 68\n63 89 63\n99 99 99\n89 97 98",...
code_contests
verifiable_code
p00684 Calculation of Expressions
Solve the following coding problem using the programming language python: Write a program to calculate values of arithmetic expressions which may involve complex numbers. Details of the expressions are described below. In this problem, basic elements of expressions are non-negative integer numbers and the special sym...
```python OVER = 10000 def factor(): global w, pos if buf[pos] == '(': pos += 1 f, v1 = calc() if not f: return [f, 0] pos += 1 elif buf[pos] == 'i': pos += 1 v1 = complex(0, 1) else: v1 = 0 while pos < w and buf[pos].isdigit(): v1 = 10*v1 + int(buf[pos]) pos += 1 if v1 > OVER: return [Fal...
vfc_46645
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "(1-10*i)+00007+(3+10*i)\n3+4*i*(4+10*i)\n(102+10*i)*(99+10*i)\n2*i+3+9999*i+4", "output": "11\n-37+16i\n9998+2010i\noverflow", "type": "stdin_stdout" }, { "fn_name": null, "input": "(1-10*i)+00007+(3...
code_contests
verifiable_code
p00826 Monster Trap
Solve the following coding problem using the programming language python: Once upon a time when people still believed in magic, there was a great wizard Aranyaka Gondlir. After twenty years of hard training in a deep forest, he had finally mastered ultimate magic, and decided to leave the forest for his home. Arrivin...
```python def string_to_complex(s): a, b, c, d = map(int, s.split()) return (a + b * 1j, c + d * 1j) def dot(c1, c2): return c1.real * c2.real + c1.imag * c2.imag def cross(c1, c2): return c1.real * c2.imag - c1.imag * c2.real def cross_point(p1, p2, p3, p4): crs1 = cross(p2 - p1, p3 - p1) cr...
vfc_46649
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n-7 9 6 9\n-5 5 6 5\n-10 -5 10 -5\n-6 9 -9 -6\n6 9 9 -6\n-1 -2 -3 10\n1 -2 3 10\n-2 -3 2 -3\n8\n-7 9 5 7\n-5 5 6 5\n-10 -5 10 -5\n-6 9 -9 -6\n6 9 9 -6\n-1 -2 -3 10\n1 -2 3 10\n-2 -3 2 -3\n0", "output": "yes\nno", "typ...
code_contests
verifiable_code
p01090 Bridge Construction Planning
Solve the following coding problem using the programming language python: Bridge Construction Planning There is a city consisting of many small islands, and the citizens live in these islands. Citizens feel inconvenience in requiring ferry rides between these islands. The city mayor decided to build bridges connectin...
```python from collections import deque import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N, M, K = map(int, readline().split()) if N == 0: return False def root(x): if prt[x] == x: return x prt[x] = y = root(prt[x]) return y def u...
vfc_46657
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5 2\n1 2 2 A\n1 3 2 A\n1 4 2 A\n2 3 1 B\n3 4 1 B\n5 8 2\n1 2 1 A\n2 3 1 A\n3 4 3 A\n4 5 3 A\n1 2 5 B\n2 3 5 B\n3 4 8 B\n4 5 8 B\n5 5 1\n1 2 1 A\n2 3 1 A\n3 4 1 A\n4 5 1 B\n3 5 1 B\n4 5 3\n1 2 2 A\n2 4 3 B\n3 4 4 B\n2 3 5 A\n3 1 6...
code_contests
verifiable_code
p01226 Battle Town
Solve the following coding problem using the programming language python: You decide to develop a game with your friends. The title of the game is "Battle Town". This is a game with the theme of urban warfare with tanks. As the first step in game development, we decided to develop the following prototype. In this pro...
```python def move(act,y,x,direction):#戦車の動き #print("x,y",y,x) #print("M,H",M,H) if x<0 or x == M or y<0 or y == H: return s_map if act == 'U':#Up if y == 0: s_map[y][x] = '^' else: if s_map[y-1][x] == '.':#下が平地なら s_map[y][x],s_map[y-1][x] ...
vfc_46661
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 6\n*.*..*\n*.....\n..-...\n^.*#..\n10\nSRSSRRUSSR\n2 2\n<.\n..\n12\nDDSRRSUUSLLS\n3 5\n>-#**\n.-*#*\n.-**#\n15\nSSSDRSSSDRSSSUU\n5 5\nv****\n*****\n*****\n*****\n*****\n44\nSSSSDDRSDRSRDSULUURSSSSRRRRDSSSSDDLSDLSDLSSD", ...
code_contests
verifiable_code
p01360 Step Step Evolution
Solve the following coding problem using the programming language python: Japanese video game company has developed the music video game called Step Step Evolution. The gameplay of Step Step Evolution is very simple. Players stand on the dance platform, and step on panels on it according to a sequence of arrows shown ...
```python import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools sys.setrecursionlimit(10**7) inf = 10**20 eps = 1.0 / 10**10 mod = 998244353 dd = [(0,-1),(1,0),(0,1),(-1,0)] ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return [int(x) for x i...
vfc_46665
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n12\n123\n369\n6748\n4247219123\n1232123212321232", "output": "0\n0\n1\n0\n1\n2\n7", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01542 Lost Number
Solve the following coding problem using the programming language python: The time was 3xxx, and the highly developed civilization was in a stagnation period. Historians decided to learn the wisdom of the past in an attempt to overcome this situation. What I paid attention to was the material left by the genius of the...
```python from itertools import product import time def ok(s): if '(+' in s or '(-' in s or '(*' in s or '++' in s or '+-' in s or '-+' in s \ or '--' in s or '**' in s or '*+' in s or '*-' in s: return False if '(' in s or ')' in s: dic={} count=-1 for c in s: if...
vfc_46669
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0.0", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "(1.1)", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "...", "...
code_contests
verifiable_code
p01698 Wish upon a shooting star
Solve the following coding problem using the programming language python: Make a wish to a shooting star The mysterious organization JAG (Japanese Alumni Group) holds regular meetings. One day, the agenda was "How to enable participating teams to demonstrate their strength in the upcoming ICPC (International Collegia...
```python import sys readline = sys.stdin.readline write = sys.stdout.write def solve(): N = int(readline()) if N == 0: return False P = [list(map(float, readline().split())) for i in range(N)] CS = [] R = [-1]*N for i in range(N): pxi, pyi, pzi, vxi, vyi, vzi, ri, vri = P[i] ...
vfc_46673
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n0.0000 0.0000 0.0000 2.0000 0.0000 0.0000 4.0000 1.0000\n2\n0.0000 0.0000 0.0000 2.0000 0.0000 0.0000 4.0000 1.0000\n10.0000 0.0000 0.0000 -2.0000 0.0000 0.0000 4.0000 1.0000\n5\n-10.0000 0.0000 0.0000 10.0000 0.0000 0.0000 2.00...
code_contests
verifiable_code
p01842 Invisible
Solve the following coding problem using the programming language python: D --Invisible Problem Statement You are trying to play a card game called "Invisible" with your friends. This card game uses two types of cards, a "scoring card" and a "jamming card". A positive value is written on each score card. The rules o...
```python n, m = [int(i) for i in input().split()] A = [int(i) for i in input().split()] B = [int(i) for i in input().split()] memo = dict() def calc(A, i): if A[i] != -1: return 0 point = 0 for j in range(i - 1, -1, -1): if A[j] == -1: break point += A[j] return p...
vfc_46677
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n100 -1\n200 300", "output": "-100", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n100 -1\n200 62", "output": "38\n", "type": "stdin_stdout" }, { "fn_name"...