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
p01674 Rings
Solve the following coding problem using the programming language python: H - Rings Problem Statement There are two circles with radius 1 in 3D space. Please check two circles are connected as chained rings. Input The input is formatted as follows. {c_x}_1 {c_y}_1 {c_z}_1 {v_x}_{1,1} {v_y}_{1,1} {v_z}_{1,1} {v_x...
vfc_55829
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0.0 0.0 0.0\n1.0 0.0 0.0 0.0 1.0 0.0\n1.0 0.0 0.5\n1.0 0.0 0.0 0.0 0.0 1.0", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "0.0 0.0 0.0\n1.3851474630540055 0.0 0.0 0.0 1.0 0....
code_contests
verifiable_code
p01951 Low Range-Sum Matrix
Solve the following coding problem using the programming language python: You received a card at a banquet. On the card, a matrix of $N$ rows and $M$ columns and two integers $K$ and $S$ are written. All the elements in the matrix are integers, and an integer at the $i$-th row from the top and the $j$-th column from t...
vfc_55837
{ "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": "2 2 3 100\n0 0\n0 0", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 2 10\n5 3 7\n2 6 1\n3 4 1", "output": "Yes", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
p02238 Depth First Search
Solve the following coding problem using the programming language python: Depth-first search (DFS) follows the strategy to search ”deeper” in the graph whenever possible. In DFS, edges are recursively explored out of the most recently discovered vertex $v$ that still has unexplored edges leaving it. When all of $v$'s ...
```python from sys import stdin n = int(stdin.readline()) M = [0] + [list(map(int, stdin.readline().split()[2:])) for i in range(n)] sndf = [0] + [[False, i] for i in range(1, n + 1)] tt = 0 def dfs(u): global tt sndf[u][0] = True tt += 1 sndf[u].append(tt) for v in M[u]: if not sndf[v][0]: ...
vfc_55845
{ "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\n1 1 2\n2 1 4\n3 0\n4 1 3", "output": "1 1 8\n2 2 7\n3 4 5\n4 3 6", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 2 2 3\n2 2 3 4\n3 1 5\n4 1 6\n5 1 6\n6 0", "output": "1 1 12\n2...
code_contests
verifiable_code
p02384 Dice II
Solve the following coding problem using the programming language python: Construct a dice from a given sequence of integers in the same way as Dice I. You are given integers on the top face and the front face after the dice was rolled in the same way as Dice I. Write a program to print an integer on the right side f...
```python def lotate(dic, dire): if dire == 'N': x,y,z,w = dic['up'], dic['back'], dic['bottom'], dic['front'] dic['back'], dic['bottom'], dic['front'], dic['up'] = x,y,z,w elif dire == 'S': x, y, z, w = dic['up'], dic['back'], dic['bottom'], dic['front'] dic['front'], dic['up'],...
vfc_55849
{ "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 2 3 4 5 6\n3\n6 5\n1 3\n3 2", "output": "3\n5\n6", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 3 4 5 6\n3\n4 5\n1 3\n3 2", "output": "6\n5\n6\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
brokphon
Solve the following coding problem using the programming language python: Chef is judging a game called "Broken telephone". There are total N players taking part in the game. They are all sitting in a line. In the start of the game, first player is given a secret message written on a sheet of paper. Then they keep sen...
```python T = input() for i in xrange(T): N = input() A = map(int,raw_input().split()) visited = [0 for k in xrange(N)] count = 0; for j in xrange(N-1): if(A[j] != A[j+1]): if(visited[j] == 0): visited[j] = 1 count += 1 if(visited[j+1] == 0): visited[j+1] = 1 count += 1 print count ```
vfc_55853
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n7\n1 1 1 3 3 3 2\n5\n1 3 1 1 1\n4\n5 5 5 5", "output": "4\n3\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n7\n1 1 1 3 3 3 2\n5\n1 3 1 1 2\n4\n5 5 5 5", "output": "4\n5\n0\...
code_contests
verifiable_code
commute
Solve the following coding problem using the programming language python: The Chef commutes to work every day using the city's underground metro. The schedule for the trains has recently been changed and he wants to know how long it will take to travel from the station nearest to his house and the station nearest to h...
```python def train(): tcases = int(raw_input()) for i in range(tcases): n = int(raw_input()) time = 0 for j in range(n): path = raw_input() path = path.split() path = map(int, path) if time <= path[0]: time = path[0] ...
vfc_55857
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n0 4 7\n0 6 5\n2\n0 1 2\n6 2 10\n2\n1 2 3\n0 2 3", "output": "11\n8\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\n0 4 7\n0 6 5\n2\n0 1 2\n6 2 10\n2\n1 2 5\n0 2 3", "o...
code_contests
verifiable_code
gcdq
Solve the following coding problem using the programming language python: You are given an array A of integers of size N. You will be given Q queries where each query is represented by two integers L, R. You have to find the gcd(Greatest Common Divisor) of the array after excluding the part from range L to R inclusive...
```python def gcd(x, y): while y > 0: x, y = y, x % y return x for _ in range(input()): n, q = map(int, raw_input().split()) a = map(int, raw_input().split()) lg, rg = [0], [0] for v in a: lg.append(gcd(v, lg[-1])) for v in reversed(a): rg.append(gcd(v, rg[-1])) ...
vfc_55861
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3 3\n2 6 9\n1 1\n2 2\n2 3", "output": "3\n1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3 3\n2 6 9\n1 1\n3 2\n2 3", "output": "3\n1\n2\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
luckystr
Solve the following coding problem using the programming language python: A Little Elephant from the Zoo of Lviv likes lucky strings, i.e., the strings that consist only of the lucky digits 4 and 7. The Little Elephant has K favorite lucky strings A1, A2, ..., AK. He thinks that the lucky string S is good if either |S...
```python def isLuckyString(b, A): if len(b)>=47: print "Good" return for a in A: if a in b: print "Good" return print "Bad" K, N = map(int, raw_input().split()) A=[] for _ in range(K): A.append(raw_input()) for _ in range(N): isLuckyString(raw_input(), A) ```
vfc_55865
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4\n47\n744\n7444\n447\n7774\n77777777777777777777777777777777777777777777774", "output": "Good\nGood\nBad\nGood\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
prpotion
Solve the following coding problem using the programming language python: Naturally, the magical girl is very good at performing magic. She recently met her master wizard Devu, who gifted her R potions of red liquid, B potions of blue liquid, and G potions of green liquid. The red liquid potions have liquid amounts...
```python t =input() for i in range(t): r,g,b,m =map(int,raw_input().split()) rlist =map(int,raw_input().split()) listg = map(int,raw_input().split()) listb = map(int,raw_input().split()) rmax = max(rlist) gmax = max(listg) bmax = max(listb) ls=[rmax,gmax,bmax] for j in xrange(m): ls[ls.index(max(ls))]/=2 ...
vfc_55869
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 1 1 1\n1\n2\n3\n1 1 1 1\n2\n4\n6\n3 2 2 2\n1 2 3\n2 4\n6 8", "output": "2\n4\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 1 1 1\n1\n2\n3\n1 1 1 1\n3\n4\n6\n3 2 2 2\n1 2 3\n...
code_contests
verifiable_code
1012_F. Passports
Solve the following coding problem using the programming language python: Gleb is a famous competitive programming teacher from Innopolis. He is planning a trip to N programming camps in the nearest future. Each camp will be held in a different country. For each of them, Gleb needs to apply for a visa. For each of t...
vfc_55877
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n7 3 1\n13 2 3\n19 3 4\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n13 2 2\n7 3 1\n19 3 4\n", "output": "YES\n1 10\n1 1\n1 2\n", "type": "stdin_st...
code_contests
verifiable_code
1037_F. Maximum Reduction
Solve the following coding problem using the programming language python: Given an array a of n integers and an integer k (2 ≤ k ≤ n), where each element of the array is denoted by a_i (0 ≤ i < n). Perform the operation z given below on a and print the value of z(a,k) modulo 10^{9}+7. function z(a...
```python import sys range = xrange input = raw_input def z(A, k): if len(A) < k: return 0 B = [max(A[i:i+k]) for i in range(len(A) - k + 1)] return sum(B) + z(B, k) def f(n): return n * (n - 1) >> 1 n,k = [int(x) for x in input().split()] A = [int(x) for x in input().split()] prev = [] stac...
vfc_55881
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 2\n9 1 10\n", "output": "29\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1060_B. Maximum Sum of Digits
Solve the following coding problem using the programming language python: You are given a positive integer n. Let S(x) be sum of digits in base 10 representation of x, for example, S(123) = 1 + 2 + 3 = 6, S(0) = 0. Your task is to find two integers a, b, such that 0 ≤ a, b ≤ n, a + b = n and S(a) + S(b) is the large...
```python def digitSum(x): s = 0 while x != 0: s += x % 10 x = (x//10) return s n = int(input()) x = n b = 1 s = 0 while x != 0: num1 = (x - 1)*b + (b-1) num2 = n - num1 ans = digitSum(num1) + digitSum(num2) if ans > s: s = ans x = (x//10) b = b * 10 print(s) ```
vfc_55885
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "35\n", "output": "17\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000000000\n", "output": "91\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1081_H. Palindromic Magic
Solve the following coding problem using the programming language python: After learning some fancy algorithms about palindromes, Chouti found palindromes very interesting, so he wants to challenge you with this problem. Chouti has got two strings A and B. Since he likes [palindromes](https://en.wikipedia.org/wiki/Pa...
vfc_55889
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 1024000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aa\naba\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaba\nabaa\n", "output": "15\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
1101_B. Accordion
Solve the following coding problem using the programming language python: An accordion is a string (yes, in the real world accordions are musical instruments, but let's forget about it for a while) which can be represented as a concatenation of: an opening bracket (ASCII code 091), a colon (ASCII code 058), some (poss...
```python #!/usr/bin/env python # -*- coding: utf-8 -*- s = input() ans = -1 left = 0 right = len(s) - 1 lok = 1 while left < len(s): if s[left] == '[': lok = 2 left += 1 elif s[left] == ':' and lok == 2: break else: left += 1 rok = 1 while right >= 0: if s[right] == ']'...
vfc_55893
{ "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": "|[a:b:|]\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "|]:[|:]\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
1129_E. Legendary Tree
Solve the following coding problem using the programming language python: This is an interactive problem. A legendary tree rests deep in the forest. Legend has it that individuals who realize this tree would eternally become a Legendary Grandmaster. To help you determine the tree, Mikaela the Goddess has revealed to...
vfc_55897
{ "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\n5\n", "output": "3\n1 2 3\n2\n4 5\n2\nANSWER\n1 2\n2 3\n3 4\n2 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 2\n4 5\n5 1\n5 3\n", "output": "1\n1 \n4\n2 3 4 5 \n2\n1\n1 \...
code_contests
verifiable_code
114_A. Cifera
Solve the following coding problem using the programming language python: When Petya went to school, he got interested in large numbers and what they were called in ancient times. For instance, he learned that the Russian word "tma" (which now means "too much to be counted") used to stand for a thousand and "tma tmysc...
```python n = int(input()) m = int(input()) l = 0 x = n while x<m: l += 1 x *= n if x == m: print("YES") print(l) else: print("NO") ```
vfc_55901
{ "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\n8\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n25\n", "output": "YES\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
1170_F. Wheels
Solve the following coding problem using the programming language python: Polycarp has n wheels and a car with m slots for wheels. The initial pressure in the i-th wheel is a_i. Polycarp's goal is to take exactly m wheels among the given n wheels and equalize the pressure in them (then he can put these wheels in a ca...
vfc_55905
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 6 7\n6 15 16 20 1 5\n", "output": "\n39\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3 1\n4 8 15 16 23 42\n", "output": "\n8\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1189_D2. Add on a Tree: Revolution
Solve the following coding problem using the programming language python: Note that this is the second problem of the two similar problems. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems. You are given a tree with n nodes. In the beginning, 0 is writte...
vfc_55909
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 2\n2 3 4\n3 4 10\n3 5 18\n", "output": "NO", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 2 6\n1 3 8\n1 4 12\n2 5 2\n2 6 4\n", "output": "YES\n21\n3 5 4\n3 4 4\n5 4 -4\n3 ...
code_contests
verifiable_code
1208_E. Let Them Slide
Solve the following coding problem using the programming language python: You are given n arrays that can have different sizes. You also have a table with w columns and n rows. The i-th array is placed horizontally in the i-th row. You can slide each array within its row as long as it occupies several consecutive cell...
```python import sys input = sys.stdin.readline from collections import deque def slidemax(X, k): q = deque([]) ret = [] for i in range(len(X)): while q and q[-1][1] <= X[i]: q.pop() deque.append(q, (i+k, X[i])) if q[0][0] == i: deque.popleft(q) if i >...
vfc_55913
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n3 2 4 8\n2 2 5\n2 6 3\n", "output": "10\n15\n16\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n2 7 8\n1 -8\n", "output": "7\n8\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1227_D2. Optimal Subsequences (Hard Version)
Solve the following coding problem using the programming language python: This is the harder version of the problem. In this version, 1 ≤ n, m ≤ 2⋅10^5. You can hack this problem if you locked it. But you can hack the previous problem only if you locked both problems. You are given a sequence of integers a=[a_1,a_2,....
```python """ Author - Satwik Tiwari . 18th Feb , 2021 - Thursday """ #=============================================================================================== #importing some useful libraries. from __future__ import division, print_function from fractions import Fraction import sys import os from io ...
vfc_55917
{ "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\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n", "output": "20\n10\n20\n10\n20\n10\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1250_C. Trip to Saint Petersburg
Solve the following coding problem using the programming language python: You are planning your trip to Saint Petersburg. After doing some calculations, you estimated that you will have to spend k rubles each day you stay in Saint Petersburg — you have to rent a flat, to eat at some local cafe, et cetera. So, if the d...
vfc_55921
{ "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": "4 5\n1 1 3\n3 3 11\n5 5 17\n7 7 4\n", "output": "\n13 3 5 2\n3 2 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 3\n1 2 5\n", "output": "\n0\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
126_A. Hot Bath
Solve the following coding problem using the programming language python: Bob is about to take a hot bath. There are two taps to fill the bath: a hot water tap and a cold water tap. The cold water's temperature is t1, and the hot water's temperature is t2. The cold water tap can transmit any integer number of water ...
```python import math def gcd(a,b): if(b==0): return a return gcd(b,a%b) l=input().split() t1=int(l[0]) t2=int(l[1]) x1=int(l[2]) x2=int(l[3]) t0=int(l[4]) num1=t2-t0 num2=t0-t1 if(t1==t2): print(x1,x2) quit() if(num1==0): print(0,x2) quit() if(num2==0): print(x1,0) quit() z=num2...
vfc_55925
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 70 100 100 25\n", "output": "99 33\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "300 500 1000 1000 300\n", "output": "1000 0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1291_F. Coffee Varieties (easy version)
Solve the following coding problem using the programming language python: This is the easy version of the problem. You can find the hard version in the Div. 1 contest. Both versions only differ in the number of times you can ask your friend to taste coffee. This is an interactive problem. You're considering moving t...
vfc_55929
{ "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": "4 2\nN\nN\nY\nN\nN\nN\nN\n", "output": "? 1\n? 2\nR\n? 1\n? 3\nR\n? 1\n? 4\nR\n? 2\n? 3\nR\n? 2\n? 4\nR\n? 3\n? 4\nR\n! 3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1334_E. Divisor Paths
Solve the following coding problem using the programming language python: You are given a positive integer D. Let's build the following graph from it: * each vertex is a divisor of D (not necessarily prime, 1 and D itself are also included); * two vertices x and y (x > y) have an undirected edge between them if...
```python import sys input = sys.stdin.buffer.readline mod=998244353 d=int(input()) div=[] x=2 di=0 t=0 while d>1 and x*x<=d: if d%x==0: div.append(x) d//=x di+=1 t+=1 while d%x==0: d//=x t+=1 x+=1 if d>1: div.append(d) di+=1 t+=1 fac=[1] for i in ...
vfc_55937
{ "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": "12\n3\n4 4\n12 1\n3 4\n", "output": "1\n3\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "288807105787200\n4\n46 482955026400\n12556830686400 897\n414 12556830686400\n4443186242880 325\...
code_contests
verifiable_code
1354_G. Find a Gift
Solve the following coding problem using the programming language python: This is an interactive problem. Don't forget to flush output after printing queries using cout.flush() or fflush(stdout) in C++ or similar functions in other programming languages. There are n gift boxes in a row, numbered from 1 to n from left...
```python from random import randint def ask(l1, r1, l2, r2): print('?', r1 - l1 + 1, r2 - l2 + 1) for i in range(l1, r1 + 1): print(i + 1, end=' ') print() for i in range(l2, r2 + 1): print(i + 1, end=' ') print(flush=True) s = input() if s[0] == 'F': return 0 if s[0] == 'S': return 1 if s[0] == 'E': ...
vfc_55941
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 1\n-\n-\n-\nFIRST\n-\n5 2\n-\n-\n-\nFIRST\n-\n-\n-\nSECOND\n-\n-\n-\nEQUAL\n-", "output": "? 1 1\n1\n2\n? 1 1\n1\n2\n? 1 1\n1\n2\n? 1 1\n1\n2\n? 1 1\n1\n2\n? 1 1\n1\n2\n? 1 1\n1\n2\n? 1 1\n1\n2\n? 1 1\n1\n2\n? 1 1\n1\n2\...
code_contests
verifiable_code
1374_E2. Reading Books (hard version)
Solve the following coding problem using the programming language python: Easy and hard versions are actually different problems, so read statements of both problems completely and carefully. Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have ...
```python import sys input = sys.stdin.readline INF = 10 ** 18 n, m, k = map(int, input().split()) B = sorted((tuple(map(int, input().split())) + (i,) for i in range(n)), key=lambda v: v[0]) GB, AB, BB, RB = ([] for _ in range(4)) for t, a, b, i in B: if a and b: GB.append((t, i)) elif a: AB.append((t, i)) elif b...
vfc_55945
{ "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": "6 3 2\n6 0 0\n11 1 0\n9 0 1\n21 1 1\n10 1 0\n8 0 1\n", "output": "39\n4 5 6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1398_B. Substring Removal Game
Solve the following coding problem using the programming language python: Alice and Bob play a game. They have a binary string s (a string such that each character in it is either 0 or 1). Alice moves first, then Bob, then Alice again, and so on. During their move, the player can choose any number (not less than one)...
```python for i in range(int(input())): s = list(filter(lambda x:x !='',input().split('0'))) s.sort(reverse=True) pr = '' for i in range(0,len(s),2): pr +=s[i] print(len(pr)) ```
vfc_55949
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n01111001\n0000\n111111\n101010101\n011011110111\n", "output": "4\n0\n6\n3\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n01111101\n0000\n111111\n101010101\n011011110111\n", ...
code_contests
verifiable_code
1421_C. Palindromifier
Solve the following coding problem using the programming language python: Ringo found a string s of length n in his [yellow submarine](https://www.youtube.com/watch?v=m2uTFF_3MaA). The string contains only lowercase letters from the English alphabet. As Ringo and his friends love palindromes, he would like to turn the...
```python s=input() n= len(s) print(4) print("L",2) print("R",n) print("R",2) print("R",2*n+1) ```
vfc_55953
{ "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": "acccc\n", "output": "3\nL 2\nR 2\nR 9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abac\n", "output": "3\nL 2\nR 2\nR 7\n", "type": "stdin_stdout" }, { "fn_nam...
code_contests
verifiable_code
143_B. Help Kingdom of Far Far Away 2
Solve the following coding problem using the programming language python: For some time the program of rounding numbers that had been developed by the Codeforces participants during one of the previous rounds, helped the citizens of Far Far Away to convert numbers into a more easily readable format. However, as time w...
```python import math import sys import collections # imgur.com/Pkt7iIf.png def getdict(n): d = {} if type(n) is list: for i in n: if i in d: d[i] += 1 else: d[i] = 1 else: for i in range(n): t = ii() if t in ...
vfc_55957
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2012\n", "output": "$2,012.00\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0.000\n", "output": "$0.00\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
1466_G. Song of the Sirens
Solve the following coding problem using the programming language python: Whoso in ignorance draws near to them and hears the Sirens' voice, he nevermore returns. Homer, Odyssey In the times of Jason and the Argonauts, it was well known that sirens use the sound of their songs to lure sailors into their demise. Yet ...
vfc_55961
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5\naba\nbbac\n1 a\n3 baca\n3 ab\n2 bab\n4 aba\n", "output": "\n4\n0\n14\n6\n28\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1491_A. K-th Largest Value
Solve the following coding problem using the programming language python: You are given an array a consisting of n integers. Initially all elements of a are either 0 or 1. You need to process q queries of two kinds: * 1 x : Assign to a_x the value 1 - a_x. * 2 k : Print the k-th largest value of the array. A...
```python n, q = map(int,input().split()) a = list(map(int,input().split())) zero = a.count(0) one = n - zero for _ in range(q): t, x = map(int,input().split()) if t == 1: if a[x-1] == 1: zero += 1 one -= 1 a[x-1] = 0 else: zero -= 1 on...
vfc_55965
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n1 1 0 1 0\n2 3\n1 2\n2 3\n2 1\n2 5\n", "output": "\n1\n0\n1\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n0\n2 1\n", "output": "0\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1540_C2. Converging Array (Hard Version)
Solve the following coding problem using the programming language python: This is the hard version of the problem. The only difference is that in this version 1 ≤ q ≤ 10^5. You can make hacks only if both versions of the problem are solved. There is a process that takes place on arrays a and b of length n and length ...
```python def solve(): MOD = 10**9+7 n = int(input()) c = list(map(int, input().split())) b = [0] + list(map(int, input().split())) q = int(input()) queries = list(map(int, input().split())) maxans = 1 for c1 in c: maxans = maxans * (c1+1) % MOD ans = {} for i in range(1,...
vfc_55973
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 3 4\n2 1\n5\n-1 0 1 -100000 100000\n", "output": "56\n28\n4\n60\n0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
168_B. Wizards and Minimal Spell
Solve the following coding problem using the programming language python: Let's dive into one of the most interesting areas of magic — writing spells. Learning this exciting but challenging science is very troublesome, so now you will not learn the magic words, but only get to know the basic rules of writing spells. ...
```python v = [] c = [] resp = "" while True: try: v.append(input()) except: break i = 0 while i < len(v): k = v[i].replace(" ","") if(k == ""): v[i] = k c.append(False) elif(k[0] == '#'): c.append(True) else: v[i] = k c.append(False) i+=1 n = len(v) i = 0 while i < n - 1: if(not c[i] and not c...
vfc_55977
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "#\n\n#\n", "output": "#\n\n#\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "# include &lt;cstdio&gt;\n\nusing namespace std;\n\nint main ( ){\nputs(\"Hello # World\"); #\n#\n}\n",...
code_contests
verifiable_code
188_H. Stack
Solve the following coding problem using the programming language python: In this problem we'll use a stack which supports two types of operations: * Push a given number on the stack. * Pop two numbers from the stack, perform a given operation (addition or multiplication) on them and push the result on the stack...
vfc_55981
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "12+3*66*+\n", "output": "45\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "149\n", "output": "9\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
20_C. Dijkstra?
Solve the following coding problem using the programming language python: You are given a weighted undirected graph. The vertices are enumerated from 1 to n. Your task is to find the shortest path between the vertex 1 and the vertex n. Input The first line contains two integers n and m (2 ≤ n ≤ 105, 0 ≤ m ≤ 105), wh...
```python from collections import defaultdict from heapq import heappush, heapify, heappop INF = 10 ** 18 class Graph: def __init__(self): self.adj_list = defaultdict(list) def add_edge(self, src, dest, cost): self.adj_list[src].append((dest, cost)) self.adj_list[dest].append((src, cost)) def dijkstra(grap...
vfc_55985
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "output": "1 4 3 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n1 2 2\n2 5 5\n2 3 4\n1 4 1\n4 3 3\n3 5 1\n", "output": "1 4 ...
code_contests
verifiable_code
235_E. Number Challenge
Solve the following coding problem using the programming language python: Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum: <image> Find the sum modulo 1073741824 (230). Input The first line contains three spac...
```python primes = [] d = {} for i in range(2, 100): if i not in d: primes.append(i) j = 2 while i * j < 100: d[i*j] = 1 j += 1 def solve(x,y,z): d = {} for p in primes: d[p] = 0 for p in primes: if p > x and p > y and p > z: ...
vfc_55989
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 10 10\n", "output": "11536", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4 4\n", "output": "328", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
260_C. Balls and Boxes
Solve the following coding problem using the programming language python: Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is gua...
```python n, x = map(int,input().split()) a = [int(i) for i in input().split()] j = x - 1 z = min(a) while a[j] != z: if j == 0: j = n - 1 else: j -= 1 m = a[j] k = 0 if x - 1 > j: for i in range(n): if j < i <= x - 1: a[i] -= (m + 1) k += (m + 1) else...
vfc_55993
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\n3 2 0 2 7\n", "output": "2 1 4 1 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n2 3 1\n", "output": "1 2 3\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
332_A. Down the Hatch!
Solve the following coding problem using the programming language python: Everybody knows that the Berland citizens are keen on health, especially students. Berland students are so tough that all they drink is orange juice! Yesterday one student, Vasya and his mates made some barbecue and they drank this healthy drin...
```python n = int(input()) moves = input() i = n count = 0 while(i < len(moves)): m = moves[i - 1] if(m == moves[i - 2] and m == moves[i - 3] and m == moves[i - 3]): count += 1 i += n print(count) ```
vfc_56005
{ "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\nabbba\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
355_A. Vasya and Digital Root
Solve the following coding problem using the programming language python: Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you. Let's assume that S(n) is the sum of digits of number n, for example, S(4098) = 4 + 0 + 9 + 8 = 21. Then the digital root of number ...
```python k,d=map(int,input().split()) if(k==1 and d==0): print(0) elif(d==0): print("No solution") else: print(str(d)+('0'*(k-1))) ```
vfc_56009
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n", "output": "4000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\...
code_contests
verifiable_code
379_B. New Year Present
Solve the following coding problem using the programming language python: The New Year is coming! That's why many people today are busy preparing New Year presents. Vasily the Programmer is no exception. Vasily knows that the best present is (no, it's not a contest) money. He's put n empty wallets from left to right ...
```python n = int(input()) l = [int(x) for x in input().split()] s = '' for x in l[:-1]: if x: s += 'P' for i in range(x - 1): s += 'RLP' s += 'R' if l[-1]: s += 'P' for i in range(l[-1] - 1): s += 'LRP' print(s) ```
vfc_56013
{ "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\n0 2 0 2\n", "output": "RPRLPRRPLRP\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2\n", "output": "PRPLRP\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
425_E. Sereja and Sets
Solve the following coding problem using the programming language python: Let's assume that set S consists of m distinct intervals [l1, r1], [l2, r2], ..., [lm, rm] (1 ≤ li ≤ ri ≤ n; li, ri are integers). Let's assume that f(S) is the maximum number of intervals that you can choose from the set S, such that every two...
vfc_56021
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n", "output": "2", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
44_C. Holidays
Solve the following coding problem using the programming language python: School holidays come in Berland. The holidays are going to continue for n days. The students of school №N are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the BSE (Berland State ...
```python n, m = map(int, input().split()) c = [0] * n for i in range(m): a, b = map(int, input().split()) for j in range(a - 1, b): c[j] += 1 for i in range(n): if c[i] != 1: print(i + 1, c[i]) exit() print('OK') # Made By Mostafa_Khaled ```
vfc_56025
{ "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": "10 5\n1 2\n2 3\n4 5\n7 8\n9 10\n", "output": "2 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 5\n1 2\n3 3\n4 6\n7 7\n8 10\n", "output": "OK\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
470_G. Hamming Distance
Solve the following coding problem using the programming language python: Hamming distance between two strings of equal length is the number of positions at which the corresponding symbols are different. You are given two strings; calculate the distance between them. Input The input consists of two lines. Each line ...
vfc_56029
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "CODECHEF\nTOPCODER\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "HAMMING\nDISTANC\n", "output": "6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
494_E. Sharti
Solve the following coding problem using the programming language python: During the last 24 hours Hamed and Malek spent all their time playing "Sharti". Now they are too exhausted to finish the last round. So they asked you for help to determine the winner of this round. "Sharti" is played on a n × n board with som...
vfc_56033
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2 1\n1 1 3 3\n2 2 4 4\n", "output": "Malek\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
519_C. A and B and Team Training
Solve the following coding problem using the programming language python: A and B are preparing themselves for programming contests. An important part of preparing for a competition is sharing programming knowledge from the experienced members to those who are just beginning to deal with the contests. Therefore, duri...
```python a, b = map(int, input().split()) a, b = min(a, b), max(a, b) if b-a >= a: print(a) else: res = b-a a -= res res += (a//3)*2 if a%3 == 2: res += 1 print(res) ```
vfc_56037
{ "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 5\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 6\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20001 1...
code_contests
verifiable_code
545_D. Queue
Solve the following coding problem using the programming language python: Little girl Susie went shopping with her mom and she wondered how to improve service quality. There are n people in the queue. For each person we know time ti needed to serve him. A person will be disappointed if the time he waits is more than...
```python n=int(input()) l=list(map(int,input().split())) l.sort() s=0 c=0 for i in l: if(i>=s): c=c+1 s=s+i print(c) ```
vfc_56041
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n15 2 1 5 3\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n16839799 17525904 91276752 42650694 60106463 12243176 54892123 25142243 16015971 41250998 11150057 699498...
code_contests
verifiable_code
593_D. Happy Tree Party
Solve the following coding problem using the programming language python: Bogdan has a birthday today and mom gave him a tree consisting of n vertecies. For every edge of the tree i, some number xi was written on it. In case you forget, a tree is a connected non-directed graph without cycles. After the present was gra...
```python from collections import deque import sys #import time sys.setrecursionlimit(200000) def bfs(v, d): global q1, edges, m, n, mark, dep, p, gf mark[v] = True p[v] = v #pp[v] = v dep[v] = d dd = deque([v]) maxdepth = 0 while dd: v = dd.popleft() for ui in l[v]: u = ui[0] if not mark[u]: ma...
vfc_56049
{ "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": "6 6\n1 2 1\n1 3 7\n1 4 4\n2 5 5\n2 6 2\n1 4 6 17\n2 3 2\n1 4 6 17\n1 5 5 20\n2 4 1\n1 5 1 3\n", "output": "2\n4\n20\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n1 2 7\n1 3 3\n3 ...
code_contests
verifiable_code
615_B. Longtail Hedgehog
Solve the following coding problem using the programming language python: This Christmas Santa gave Masha a magic picture and a pencil. The picture consists of n points connected by m segments (they might cross in any way, that doesn't matter). No two segments connect the same pair of points, and no segment connects t...
```python from sys import stdin,stdout,setrecursionlimit setrecursionlimit(10**5) from collections import defaultdict nmbr = lambda: int(stdin.readline()) lst = lambda: list(map(int,stdin.readline().split())) PI=float('inf') def dfs(src): vis[src]=1 for neigh in g[src]: if neigh<src: if not ...
vfc_56053
{ "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": "8 6\n4 5\n3 5\n2 5\n1 2\n2 8\n6 7\n", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n1 2\n1 3\n1 4\n2 3\n2 4\n3 4\n", "output": "12", "type": "stdin_stdout" ...
code_contests
verifiable_code
634_D. Package Delivery
Solve the following coding problem using the programming language python: Johnny drives a truck and must deliver a package from his hometown to the district center. His hometown is located at point 0 on a number line, and the district center is located at the point d. Johnny's truck has a gas tank that holds exactly ...
```python destination, max_gas_tank_volume, gas_prices_number = map(int, input().split()) start_point = 0 gas_prices = {start_point:0} for i in range(gas_prices_number): coordinate, price = map(int, input().split()) gas_prices[coordinate] = price points = sorted(gas_prices.keys(), reverse = True) current_point ...
vfc_56057
{ "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": "16 5 2\n8 2\n5 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 4 4\n3 5\n5 8\n6 3\n8 4\n", "output": "22\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
663_B. International Olympiad
Solve the following coding problem using the programming language python: International Abbreviation Olympiad takes place annually starting from 1989. Each year the competition receives an abbreviation of form IAO'y, where y stands for some number of consequent last digits of the current year. Organizers always pick a...
```python tn=[0]*10000 ts=[0]*10000 a=1989 tn[1]=1989 ts[1]=9 for i in range(1,12): a=a+(10**i) tn[i+1]=a ts[i+1]=int(str(a)[-i-1:]) noc=int(input()) for fk in range(noc): a=input()[4:] temp=len(a) a=int(a) print((a-ts[temp])%(10**temp)+tn[temp]) ```
vfc_56061
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nIAO'15\nIAO'2015\nIAO'1\nIAO'9\nIAO'0\n", "output": "2015\n12015\n1991\n1989\n1990\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nIAO'9\nIAO'99\nIAO'999\nIAO'9999\n", "output"...
code_contests
verifiable_code
755_A. PolandBall and Hypothesis
Solve the following coding problem using the programming language python: PolandBall is a young, clever Ball. He is interested in prime numbers. He has stated a following hypothesis: "There exists such a positive integer n that for each positive integer m number n·m + 1 is a prime number". Unfortunately, PolandBall i...
```python import sys n = int(input()) for m in range(1, 1001): for j in range(2, 1001): if j < (n * m + 1) and (n * m + 1) % j == 0: print(m) sys.exit(0) ```
vfc_56077
{ "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\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "986\n", "...
code_contests
verifiable_code
776_B. Sherlock and his girlfriend
Solve the following coding problem using the programming language python: Sherlock has a new girlfriend (so unlike him!). Valentine's day is coming and he wants to gift her some jewelry. He bought n pieces of jewelry. The i-th piece has price equal to i + 1, that is, the prices of the jewelry are 2, 3, 4, ... n + 1. ...
```python def sieve(n): mark = [True]*(n+1) p = 2 while p*p<=n: if mark[p]: for i in range(p*p,n+1,p): mark[i] = False p+=1 for i in range(2,n+1): if mark[i]: print(1,end=" ") else: print(2,end=" ") n = int(input()) if n==1 or n==2: print(1) else: print(2) sieve(n+1) ```
vfc_56081
{ "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\n", "output": "2\n1 1 2 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
7_C. Line
Solve the following coding problem using the programming language python: A line on the plane is described by an equation Ax + By + C = 0. You are to find any point on this line, whose coordinates are integer numbers from - 5·1018 to 5·1018 inclusive, or to find out that such points do not exist. Input The first li...
```python def gcd(x,y): if x % y == 0: return y else: return gcd(y,x%y) def bezout(x,y): if x % y == 0: return (0,1) else: t,s = bezout (y,x%y) return (s,t-(x//y)*s) a,b,c = map(int,input().split()) if a == 0: if c % b == 0: print("%d %d" % (...
vfc_56085
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 5 3\n", "output": "6 -3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
820_E. Mister B and Beacons on Field
Solve the following coding problem using the programming language python: Mister B has a house in the middle of a giant plain field, which attracted aliens life. For convenience, aliens specified the Cartesian coordinate system on the field in such a way that Mister B's house has coordinates (0, 0). After that they se...
vfc_56089
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 1 1\n2 1 1\n1 1 3\n1 5 1\n2 2 1\n1 1 2\n10 6 18\n2 103 2\n13 1 13\n", "output": " 4\n 7\n ...
code_contests
verifiable_code
868_B. Race Against Time
Solve the following coding problem using the programming language python: Have you ever tried to explain to the coordinator, why it is eight hours to the contest and not a single problem has been prepared yet? Misha had. And this time he has a really strong excuse: he faced a space-time paradox! Space and time replace...
```python ##a = list(map(int, input().split())) ##print(' '.join(map(str, res))) [h, m, s, t1, t2] = list(map(int, input().split())) if h == 12: h = 0 if t1 == 12: t1 = 0 if t2 == 12: t2 = 0 if t1 > t2: t1, t2 = t2, t1 #sa = s*360/60 #ma = m*360/60+s*360/(60*60) #ha = h*360/12+m*360/(12*60)+s*360/...
vfc_56097
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 47 0 4 9\n", "output": "YES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
893_E. Counting Arrays
Solve the following coding problem using the programming language python: You are given two positive integer numbers x and y. An array F is called an y-factorization of x iff the following conditions are met: * There are y elements in F, and all of them are integer numbers; * <image>. You have to count the n...
```python #Code by Sounak, IIESTS #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase import io from fractions import Fraction import collections from itertools import permutations from collections import defaultdict from collections import ...
vfc_56101
{ "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": "2\n6 3\n4 2\n", "output": "36\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n65536 1000000\n", "output": "928522471\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
915_B. Browser
Solve the following coding problem using the programming language python: Luba is surfing the Internet. She currently has n opened tabs in her browser, indexed from 1 to n from left to right. The mouse cursor is currently located at the pos-th tab. Luba needs to use the tabs with indices from l to r (inclusive) for he...
```python n,pos,l,r = [int(i) for i in input().split()] time_l = 0; if l != 1: time_l += abs(pos - l) + 1 # move to l and delete pos1 = l else: pos1 = pos if r != n: time_l += abs(r-pos1) + 1 # move to r and delete time_r = 0; if r != n: time_r += abs(pos - r) + 1 # move to l and delete pos1 = r ...
vfc_56105
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2 1 5\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
938_C. Constructing Tests
Solve the following coding problem using the programming language python: Let's denote a m-free matrix as a binary (that is, consisting of only 1's and 0's) matrix such that every square submatrix of size m × m of this matrix contains at least one zero. Consider the following problem: You are given two integers n a...
```python import math def div(k): res = [] for i in range(1,int(math.sqrt(k))+2): if k % i == 0: res.append(i) return res t = int(input()) for i in range(t): x = int(input()) if x == 0: print("1 1") elif x == 1: print(-1) else: ...
vfc_56109
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n21\n0\n1\n", "output": "5 2\n1 1\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n28\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
963_C. Cutting Rectangle
Solve the following coding problem using the programming language python: A rectangle with sides A and B is cut into rectangles with cuts parallel to its sides. For example, if p horizontal and q vertical cuts were made, (p + 1) ⋅ (q + 1) rectangles were left after the cutting. After the cutting, rectangles were of n ...
```python n =int(input()) w=[] h=[] c=[] cntw={} cnth={} gcdC=0 cntC=0 def insert1(a,b,c): if not a in b : b[a]=c else : b[a]=b[a]+c def gcd(a,b): if a % b == 0 : return b else : return gcd(b,a%b) for i in range(0, n): a,b,d = map(int,input().split()) w.append(a) h.append(b) c.append(d) insert1(a,cn...
vfc_56113
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2 5\n2 3 5\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 1 9\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
990_F. Flow Control
Solve the following coding problem using the programming language python: You have to handle a very complex water distribution system. The system consists of n junctions and m pipes, i-th pipe connects junctions x_i and y_i. The only thing you can do is adjusting the pipes. You have to choose m integer numbers f_1, f...
```python import sys from time import time t1 = time() #sys.setrecursionlimit(300000) def i_ints(): return list(map(int, sys.stdin.readline().split())) def main(): limit =10**10 n, = i_ints() s = [0] + i_ints() if sum(s): print("Impossible") return print("Possible") ...
vfc_56117
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 -10 6 4\n5\n1 2\n3 2\n2 4\n3 4\n3 1\n", "output": "Impossible\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n3 -10 6 1\n5\n1 2\n3 2\n2 4\n3 4\n3 1\n", "output": "Possible\n-...
code_contests
verifiable_code
aprileasy-easy-non-linear-recurrences
Solve the following coding problem using the programming language python: You are given the following recurrences, F(n) = a * F(n - 1) * G(n - 2) + b * G(n - 1) * F(n - 2) for n ≥ 2 G(n) = c * G(n - 1) * F(n - 2) + d * (3 ^ F(n - 1) ) for n ≥2 H(n) = e * F(n) + f * G(n) for n ≥ 0 F[0] = F[1] = G[0] = 0 G[1] = 1 ...
```python from math import * a,b,c,d,e,f = map(int,raw_input().split()) q=input() for i in range(q): t = input() if (t==0): print(0) elif (t==1): print(f) else: print((f*(1+(t-1)*d))%1000000007) ```
vfc_56121
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 2 3 4 5 6\n2\n2 \n3\n\nSAMPLE", "output": "30\n54", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
chandu-and-his-interns
Solve the following coding problem using the programming language python: Chandu is a very strict mentor. He always gives a lot of work to his interns. So his interns decided to kill him. There is a party in the office on Saturday Night, and the interns decided to kill him on the same day. In the party, there are N be...
```python import math def no_of_factors(x): i=1 c=0 sqrtx=int(math.ceil(x**0.5)) if (math.sqrt(x)-int(math.sqrt(x)))>0.0: c=0 while i<sqrtx: if x%i==0: c+=2 if c==4: return c i+=1 else: c=-1 while i<=sqrtx: if x%i==0: c+=2 if c==4: ...
vfc_56125
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n3\n6\n\nSAMPLE", "output": "NO\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1\n100\n2\n99\n3\n98\n4\n97\n5\n96", "output": "NO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nN...
code_contests
verifiable_code
distance
Solve the following coding problem using the programming language python: Sona is in-charge of inviting the guest. She don't know how much far they are from her place. She knows the guest house co-ordinates (gx,gy)and the co-ordinates of the place where she is standing(sx,sy). Help her to calculate the distance betwee...
```python import math one=list(map(int,raw_input().split(" "))) two=list(map(int,raw_input().split(" "))) print "%.5f" % math.sqrt(pow(two[0]-one[0],2)+pow(two[1]-one[1],2)) ```
vfc_56129
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 5\n2 6\n\nSAMPLE", "output": "1.00000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 5\n3 6", "output": "1.41421\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
good-morning-1
Solve the following coding problem using the programming language python: Today is the first class after a long vacation and as always Bagha woke up late. His friend, Nathumama has a motorcycle which they can use to reach class on time. However, Nathumama doesn't have enough fuel to reach class so Bagha makes a magic ...
```python r=input() l=[] while r!=0: k=0 q=raw_input() q=q.split() b =int(q[1]) a=int(q[0]) j = 0 while a!=0: b=b-2 j = j +2 a = a-1 if j==6: a=a+2 j = 0 if b<=0: l.append("Yes") else: l.append("No") r = r-1 for a in l: print a ```
vfc_56133
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 10\n4 25\n\nSAMPLE", "output": "Yes\nNo\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
listing-names-2
Solve the following coding problem using the programming language python: A list of names is taken as input, in which a particular name can occur multiple times. You need to arrange these names as they will appear in the dictionary and also print the number of times the arranged names appear in the list taken as input...
```python n = int(raw_input()) name = [] for i in range(n): name.append(raw_input()) name.sort() c = 1 i = 0 while i < n: pos = i+1 while i < n and pos < n and name[i] == name[pos]: c+=1 pos+=1 print name[i] , c i = pos c = 1 ```
vfc_56137
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nritesh\nsahil\nritesh\n\nSAMPLE", "output": "ritesh 2\nsahil 1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
monks-encounter-with-polynomial
Solve the following coding problem using the programming language python: Our monk, while taking a stroll in the park, stumped upon a polynomial ( A X^2 + B X +C ) lying on the ground. The polynomial was dying! Being considerate, our monk tried to talk and revive the polynomial. The polynomial said: I have served m...
```python __author__ = 'ankur' def get_lowest_x(a, b, c, k): answer = -1 low = 0 high = 100000 if c >= k: return 0 while low <= high: mid = low + (high - low) / 2 left_side = (a * (mid * mid)) + (b * mid) + c if left_side >= k: answer = mid; ...
vfc_56141
{ "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 4 5 6\n3 4 5 5\n3 4 5 150\n\nSAMPLE", "output": "1\n0\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 4 5 8\n3 4 5 5\n3 4 5 150\n\nSAMPLE", "output": "1\n0\n7\n", ...
code_contests
verifiable_code
possible-sums-5
Solve the following coding problem using the programming language python: Given an array A of N elements, find the number of distinct possible sums that can be obtained by taking any number of elements from the array and adding them. Note that 0 can always be obtained by taking none. First line of the input contains...
```python def possibleSums(n,elems): sums = sum(elems) dp = [[False] * (sums+1) for _ in xrange(n)] dp[0][0] = True dp[0][elems[0]] = True for i in xrange(1,n): for j in xrange(sums+1): dp[i][j] = dp[i-1][j] or (dp[i-1][j-elems[i]] if j - elems[i] >= 0 else False) return sum(dp[n-1]) def main(): ...
vfc_56145
{ "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\n1 2 3\n5\n5 1 3 2 7\n4\n1 2 4 8 \n\nSAMPLE", "output": "7\n19\n16\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n35\n62 92 40 83 88 39 33 55 33 45 84 90 81 75 99 94 90 33 11 53 ...
code_contests
verifiable_code
sum-of-medians-1
Solve the following coding problem using the programming language python: Median of K numbers is defined as the (K/2)th smallest number, if K is even; and the ((K+1)/2)th smallest number if K is odd. For example, median of the 4 numbers: 2 1 8 7 is the 2nd smallest number i.e. 2, and the median of the 5 numbers: ...
```python import bisect def median(nums, k): K = k + 1 return nums[(K/2)-1] if K % 2 == 0 else nums[((K+1)/2)-1] numbers = [int(raw_input()) for num in xrange(int(raw_input()))] sorted_numbers = [] median_sum = 0 for k, number in enumerate(numbers): bisect.insort(sorted_numbers, number) median_sum += ...
vfc_56153
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n10\n5\n1\n2\n15\n\nSAMPLE", "output": "27", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n11\n5\n1\n2\n15\n\nSAMPLE", "output": "28\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
walter-jesse-and-hcf
Solve the following coding problem using the programming language python: Walter and Jesse's friend Mike had helped them in making Crymeth and hence, they wanted to give him a share. For deciding the share, they both decided to choose one number each, X and Y and found out that K^th Highest Common Factor of their two ...
```python from fractions import gcd import math for _ in xrange(int(raw_input())): a,b,d=map(int,raw_input().split()); A=[]; q=gcd(a,b); s=int(math.sqrt(q)); for i in xrange(1,s+1): if q%i==0: A.append(i); A.append(q/i); if s*s==q: A.pop() A.sort(reverse=True); if len(A)<d: print "No crymeth today" else...
vfc_56157
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n8 16 2\n8 16 4\n8 16 5\n\nSAMPLE", "output": "4\n1\nNo crymeth today\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "97\n1313416998 993571903 6\n5158133151 6763711071 2\n1004899087 8199...
code_contests
verifiable_code
p00036 A Figure on Surface
Solve the following coding problem using the programming language python: There is a plane like Figure 1 with 8 vertical and 8 horizontal squares. □ | □ | □ | □ | □ | □ | □ | □ --- | --- | --- | --- | --- | --- | --- | --- □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ | □ | □ | □ | □ | □ | □ □ | □ ...
```python import sys readline = sys.stdin.readline write = sys.stdout.write B = [771, 16843009, 15, 66306, 1539, 131841, 774] C = "ABCDEFG" def solve(): N = 8 su = 0 for i in range(N): s = readline().strip() for j in range(N): if s[j] == '1': su |= 1 << (i*N + j) ...
vfc_56201
{ "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": "00000000\n00000000\n01100000\n00110000\n00000000\n00000000\n00000000\n00000000\n\n00011110\n00000000\n00000000\n00000000\n00000000\n00000000\n00000000\n00000000\n\n00000000\n00000000\n00110000\n00110000\n00000000\n00000000\n0000000...
code_contests
verifiable_code
p00168 Kannondou
Solve the following coding problem using the programming language python: There is Kannon-do in the mountain behind Ichiro's house. There are 30 steps from the foot to this Kannon-do, and Ichiro goes to Kannon-do almost every day. Ichiro can go up the stairs up to 3 steps with one foot. While playing, I noticed that t...
```python import sys n=30 f=[1,1,2,4] while len(f)<=n: f.append(f[-1]+f[-2]+f[-3]) while True: n=int(input()) if n==0: sys.exit() day=f[n] if day%3650==0: print(int(day/3650)) else: print(int(day/3650)+1) ```
vfc_56205
{ "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\n10\n20\n25\n0", "output": "1\n1\n34\n701", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n10\n14\n25\n0", "output": "1\n1\n1\n701\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p00496 Night Market
Solve the following coding problem using the programming language python: Taro decided to go to the summer festival held at JOI Shrine. N night shops are open along the way to JOI Shrine. Each night shop is numbered from 1 to N in order, and the fun of playing and the time it takes to play are determined by integers....
```python def solve(): N, T, S = map(int, input().split()) a = [tuple(map(int, input().split())) for _ in [0]*N] dp = [float("-inf")]*(T+1) dp[0] = 0 for fun, mise_time in a: for prev_time, from_fun, to_fun in zip(range(T-mise_time, -1, -1), dp[T-mise_time::-1], dp[::-1]): new_t...
vfc_56213
{ "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 20 14\n8 9\n2 4\n7 13\n6 3\n5 8", "output": "16", "type": "stdin_stdout" }, { "fn_name": null, "input": "None", "output": "None", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
p00823 Molecular Formula
Solve the following coding problem using the programming language python: Your mission in this problem is to write a computer program that manipulates molecular for- mulae in virtual chemistry. As in real chemistry, each molecular formula represents a molecule consisting of one or more atoms. However, it may not have ...
```python # http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1244 from typing import List, Dict atomic_table: Dict[str, int] = {} class NoAppearAtomicSymbol(Exception): pass class Token: s: str index = 0 def __init__(self, s: str): self.s = s @property def c(self) -> str: ...
vfc_56221
{ "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": "H 1\nHe 4\nC 12\nO 16\nF 19\nNe 20\nCu 64\nCc 333\nEND_OF_FIRST_PART\nH2C\n(MgF)2As\nCu(OH)2\nH((CO)2F)99\n0", "output": "14\nUNKNOWN\n98\n7426", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00954 Skinny Polygon
Solve the following coding problem using the programming language python: Example Input 2 5 6 1000000000 2 Output 4 5 6 0 6 0 0 5 0 3 1000000000 0 0 2 999999999 0 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_56225
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 6\n1000000000 2", "output": "4\n5 6\n0 6\n0 0\n5 0\n3\n1000000000 0\n0 2\n999999999 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5 6\n1001000000 2", "output": "3\n0 0\n5 6...
code_contests
verifiable_code
p01087 ICPC Calculator
Solve the following coding problem using the programming language python: ICPC Calculator In mathematics, we usually specify the order of operations by using parentheses. For example, 7 × (3 + 2) always means multiplying 7 by the result of 3 + 2 and never means adding 2 to the result of 7 × 3. However, there are peop...
```python def inp(): global n n = int(input()) return n def strinp(): l = 0 s = list(input()) for i in s: if i == '.': l += 1 else: c = i return [l,c] def calc(p): global f l = f[p][0] c = f[p][1] p += 1 if c == '+': ans = 0 for i in range(p,n): if f[i][0] == l: break elif f[i][0] ==...
vfc_56229
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n9\n4\n+\n.1\n.2\n.3\n9\n+\n.0\n.+\n..*\n...1\n...*\n....1\n....2\n..0\n10\n+\n.+\n..6\n..2\n.+\n..1\n..*\n...7\n...6\n.3\n0", "output": "9\n6\n2\n54", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
p01223 Saizo
Solve the following coding problem using the programming language python: A TV program called "Saizo" is popular in a certain country. In this program, participants challenge field athletics and get a prize if they successfully capture it. Field athletics are made by arranging blocks of different heights in a row, an...
```python t = int(input()) for _ in range(t): n = int(input()) h = list(map(int, input().split())) maxv = minv = 0 for i in range(len(h)-1): maxv = max(maxv, h[i+1]-h[i]) minv = max(minv, h[i]-h[i+1]) print(maxv, minv) ```
vfc_56233
{ "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": "5\n5\n10 70 30 50 90\n2\n20 100\n2\n100 30\n3\n50 50 50\n7\n123 45 678 901 234 567 890", "output": "60 40\n80 0\n0 70\n0 0\n633 667", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01357 Lapin Noir
Solve the following coding problem using the programming language python: This is a city where the ground is a square of regular hexagons. Each square is represented by two integers as shown in the figure below. <image> The cat is about to go to the square (0, 0). The mischievous black rabbit knew this and decided t...
vfc_56237
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 -1 3 -1 3 1 1 3 -1 3 -1 1\n3 0 4 0 4 1 3 2 2 2 2 1\n3\n1 1\n-1 -1\n2 4", "output": "YES\nNO\nYES", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 -1 3 -1 3 1 1 3 -1 3 -1 1\n3 0 4 0 ...
code_contests
verifiable_code
p01695 JAG-channel
Solve the following coding problem using the programming language python: JAG-channel Nathan O. Davis operates an electronic bulletin board called JAG-channel. He is currently working on adding a new feature called Thread View. Like many other electronic bulletin boards, JAG-channel is thread-based. Here, a thread r...
```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 def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x)-1 for x in sys.stdin.readline().split...
vfc_56245
{ "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": "6\nhoge\n.fuga\n..foobar\n..jagjag\n...zigzag\n.piyo\n8\njagjag\n.hogehoge\n..fugafuga\n...ponyoponyo\n....evaeva\n....pokemon\n...nowawa\n.buhihi\n8\nhello\n.goodmorning\n..howareyou\n.goodafternoon\n..letshavealunch\n.goodevening...
code_contests
verifiable_code
p01975 Mapping
Solve the following coding problem using the programming language python: problem AOR Ika made a set $ S = \\ {a_1, ..., a_N \\} $ and a map $ f: S → S $. $ f (a_i) = b_i $. For any element $ x $ in the set $ S $, all maps $ g, h: S → S $ satisfying $ g (f (x)) = h (f (x)) $ are $ g (x). ) = Determine if h (x) $ is s...
```python # -*- coding: utf-8 -*- from collections import Counter def inpl(): return list(map(int, input().split())) N = int(input()) A = inpl() Ai = range(N) Ad = {a:i for i, a in enumerate(A)} F = inpl() C = [0]*N for f in F: C[Ad[f]] += 1 if not 0 in C: print("Yes") else: print("No") print(*list(ma...
vfc_56253
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5\n3 4 2 5 1", "output": "Yes", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 1 3 4 5\n3 4 2 5 1", "output": "Yes\n", "type": "stdin_stdout" }, { "f...
code_contests
verifiable_code
p02261 Stable Sort
Solve the following coding problem using the programming language python: Let's arrange a deck of cards. There are totally 36 cards of 4 suits(S, H, C, D) and 9 values (1, 2, ... 9). For example, 'eight of heart' is represented by H8 and 'one of diamonds' is represented by D1. Your task is to write a program which so...
```python N = int(input()) A = [] for card in input().split(): A.append([card[0], int(card[1])]) B = A[:] for i in range(N): for j in range(N-1, i, -1): if A[j][1] < A[j-1][1]: A[j-1], A[j] = A[j], A[j-1] A = " ".join([i + str(j) for i, j in A]) print(A) print("Stable") for i in range(N-1...
vfc_56261
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nS1 H1", "output": "S1 H1\nStable\nS1 H1\nStable", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
cr07
Solve the following coding problem using the programming language python: POINTS - 25 Sahil is very fond of drinking juice. Every morning he drinks one full bottle of Juice. In every 'm' days, his mother buys one more bottle of juice ( i.e. on day m, 2m, 3m). She buys it in the evening. If Sahil initially has 'n' bott...
```python n,m=map(int,raw_input().split()) counter=0 while(n!=0): counter+=1 n-=1 if counter%m==0: n+=1 print counter ```
vfc_56273
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9 3", "output": "13", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
granama
Solve the following coding problem using the programming language python: Chef has learned a new technique for comparing two recipes. A recipe contains a list of ingredients in increasing order of the times they will be processed. An ingredient is represented by a letter 'a'-'z'. The i-th letter in a recipe denotes th...
```python import sys def main(): for (r, s) in testcases(): if pseudo_granama(r, s): print "NO" else: print "YES" def testcases(cin = sys.stdin): nc = int(cin.next()) for _ in xrange(nc): r, s = cin.next().split() yield (r, s) def pseudo_granama(r, s): r, s = list(r), list(s) r....
vfc_56277
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nalex axle\nparadise diapers\nalice bob", "output": "YES\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nalex axle\nesidarap diapers\nalice bob", "output": "YES\nNO\nYE...
code_contests
verifiable_code
ranklist
Solve the following coding problem using the programming language python: A rank list is a list of ranks of persons in a programming contest. Note that some of the persons might be having same rank. {1, 2}, {1, 2, 2} and {1, 1, 2, 3, 4, 4} are few examples of rank lists whereas {1, 3}, {0, 2}, {1, 2, 4} are not rank l...
```python t = input() it = 0 while (it < t): s = raw_input() s1 = s.split(" ") n = int(s1[0]) s = int(s1[1]) #print n, s if (s == (n*(n+1))/2): print "0" it += 1 continue s -= n for i in range(1,n): if ((s < ((n-i)*(n-i+1))/2) & (s >= ((n-i-1)*(n-i))/2) ): print i break it += 1 ```
vfc_56285
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1\n3 6\n3 5\n3 3", "output": "0\n0\n1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1\n3 6\n5 5\n3 3", "output": "0\n0\n4\n2\n", "type": "stdin_stdout" } ]...
code_contests
verifiable_code
tos03
Solve the following coding problem using the programming language python: You all must know Walter White, from Breaking Bad who created the world’s purest crystal meth. As he is a school teacher, he has to attend school regularly. But Walter does not want to go to school, rather he wants to stay home and create new ki...
```python t=input() for _ in xrange(t): a,b=map(int,raw_input().split()) print max(a,b),(a+b) ```
vfc_56289
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n15 28", "output": "28 43", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1015_E1. Stars Drawing (Easy Edition)
Solve the following coding problem using the programming language python: A star is a figure of the following type: an asterisk character '*' in the center of the figure and four rays (to the left, right, top, bottom) of the same positive length. The size of a star is the length of its rays. The size of a star must be...
```python n, m = map(int, input().split()) arr = [input() for i in range(n)] s1 = set() s2 = set() res = list() for i in range(n): for j in range(m): if arr[i][j] == '*': s1.add((i, j)) l = 1 while True: if i - l >= 0 and i + l < n and j - l >= 0 and j + l...
vfc_56293
{ "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 5\n.*...\n***..\n.*...\n.*...\n.....\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 8\n....*...\n...**...\n..*****.\n...**...\n....*...\n........\n", "output":...
code_contests
verifiable_code
1083_D. The Fair Nut's getting crazy
Solve the following coding problem using the programming language python: The Fair Nut has found an array a of n integers. We call subarray l … r a sequence of consecutive elements of an array with indexes from l to r, i.e. a_l, a_{l+1}, a_{l+2}, …, a_{r-1}, a_{r}. No one knows the reason, but he calls a pair of sub...
vfc_56305
{ "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": "3\n1 2 3\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1102_F. Elongated Matrix
Solve the following coding problem using the programming language python: You are given a matrix a, consisting of n rows and m columns. Each cell contains an integer in it. You can change the order of rows arbitrarily (including leaving the initial order), but you can't change the order of cells in a row. After you p...
```python import sys def read(): return int(input()) def reads(): return [int(x) for x in input().split()] N,M=reads() table=[reads() for i in range(N)] A=[[0]*N for i in range(N)] B=[[0]*N for i in range(N)] for i in range(N): for j in range(N): res=10**9+7 for k in range(M): re...
vfc_56309
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 1\n3\n6\n2\n5\n1\n4\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4\n1 2 3 4\n10 3 7 3\n", "output": "0", "type": "stdin_stdout" }, { "fn_nam...
code_contests
verifiable_code
1130_E. Wrong Answer
Solve the following coding problem using the programming language python: Consider the following problem: given an array a containing n integers (indexed from 0 to n-1), find max_{0 ≤ l ≤ r ≤ n-1} ∑_{l ≤ i ≤ r} (r-l+1) ⋅ a_i. In this problem, 1 ≤ n ≤ 2 000 and |a_i| ≤ 10^6. In an attempt to solve the problem describe...
```python k = int(input()) cSum = 0 res = [-1,1] while True: if cSum + 1_000_000 < k + len(res): cSum += 1_000_000 res.append(1_000_000) else: res.append(k + len(res) - cSum) break print(len(res)) for i in res: print(i, end = ' ') ```
vfc_56313
{ "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": "612\n", "output": "2\n-1 614\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n", "output": "2\n-1 10\n", "type": "stdin_stdout" }, { "fn_name": null, "inp...
code_contests
verifiable_code
1151_B. Dima and a Bad XOR
Solve the following coding problem using the programming language python: Student Dima from Kremland has a matrix a of size n × m filled with non-negative integers. He wants to select exactly one integer from each row of the matrix so that the bitwise exclusive OR of the selected integers is strictly greater than zer...
```python n, m = map(int, input().split()) a = [[int(i) for i in input().split()] for _ in range(n)] t = a[0][0] for i in range(1, n): t ^= a[i][0] if t != 0: print("TAK") print(' '.join('1' for i in range(n))) else: for i in range(n): for j in range(1, m): if a[i][j] != a[i][0]: ...
vfc_56317
{ "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 2\n0 0\n0 0\n0 0\n", "output": "NIE", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n7 7 7\n7 7 10\n", "output": "TAK\n1 3 ", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
1173_A. Nauuo and Votes
Solve the following coding problem using the programming language python: Nauuo is a girl who loves writing comments. One day, she posted a comment on Codeforces, wondering whether she would get upvotes or downvotes. It's known that there were x persons who would upvote, y persons who would downvote, and there were ...
```python x, y, z = [int(x) for x in input().split()] if x == y and z == 0: print(0) elif x > y + z: print("+") elif y > x + z: print("-") else: print("?") ```
vfc_56321
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 7 0\n", "output": "-", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1190_D. Tokitsukaze and Strange Rectangle
Solve the following coding problem using the programming language python: There are n points on the plane, the i-th of which is at (x_i, y_i). Tokitsukaze wants to draw a strange rectangular area and pick all the points in the area. The strange area is enclosed by three lines, x = l, y = a and x = r, as its left side...
```python import sys import copy input = sys.stdin.readline n=int(input()) P=[list(map(int,input().split())) for i in range(n)] SET_X=set() SET_Y=set() for x,y in P: SET_X.add(x) SET_Y.add(y) CX=sorted(SET_X) CY=sorted(SET_Y) LEN=len(CX) MAX=len(CX)-1 DICT_X={x:i for i,x in enumerate(CX)} DICT_Y={x:i for ...
vfc_56325
{ "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\n1 1\n2 1\n3 1\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 1\n2 2\n3 1\n3 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
1209_G1. Into Blocks (easy version)
Solve the following coding problem using the programming language python: This is an easier version of the next problem. In this version, q = 0. A sequence of integers is called nice if its elements are arranged in blocks like in [3, 3, 3, 4, 1, 1]. Formally, if two elements are equal, everything in between must also...
```python n, q = map(int, input().split()) a = list(map(int, input().split())) d = {} def max_frequent(s, e, a): d = {} for x in a[s: e+1]: if x not in d: d[x] = 0 d[x] += 1 return e - s + 1 - max(list(d.values())) for i, x in enumerate(a): if x not...
vfc_56329
{ "difficulty": "13", "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 0\n3 3 1 3 2 1 2\n", "output": "4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
122_A. Lucky Division
Solve the following coding problem using the programming language python: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a number almo...
```python lucky_numbers = [4, 7, 44, 77, 47, 74, 444, 447, 474, 744, 777, 774, 747, 477] n = input() lucky = True for i in range(0, len(n)): if n[i] != '4' and n[i] != '7' : lucky = False break if lucky: print("YES") else: lucky = False for i in lucky_numbers: if int(n) % i == 0...
vfc_56333
{ "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": "16\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "78\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "47\n",...
code_contests
verifiable_code
1250_N. Wires
Solve the following coding problem using the programming language python: Polycarpus has a complex electronic device. The core of this device is a circuit board. The board has 10^9 contact points which are numbered from 1 to 10^9. Also there are n wires numbered from 1 to n, each connecting two distinct contact points...
vfc_56337
{ "difficulty": "21", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n4 7\n4\n1 2\n2 3\n4 5\n5 6\n", "output": "\n0\n1\n2 3 5\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1293_E. 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...
vfc_56345
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2\n1 3\n1 4\n3 5\n", "output": "10", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 2\n2 3\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1313_D. Happy New Year
Solve the following coding problem using the programming language python: Being Santa Claus is very difficult. Sometimes you have to deal with difficult situations. Today Santa Claus came to the holiday and there were m children lined up in front of him. Let's number them from 1 to m. Grandfather Frost knows n spells...
vfc_56349
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5 3\n1 3\n2 4\n3 5\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1000000000 1\n1 1000000000\n", "output": "1000000000\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
1336_B. Xenia and Colorful Gems
Solve the following coding problem using the programming language python: Xenia is a girl being born a noble. Due to the inflexibility and harshness of her family, Xenia has to find some ways to amuse herself. <image> Recently Xenia has bought n_r red gems, n_g green gems and n_b blue gems. Each of the gems has a we...
```python from bisect import bisect_left def fun(arr, val): pos = bisect_left(arr, val) if(pos == 0): return arr[0] elif(pos == len(arr)): return arr[-1] else: left = arr[pos - 1] if((val - left) < (arr[pos] - val)): return left else: ret...
vfc_56353
{ "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\n2 2 3\n7 8\n6 3\n3 1 4\n1 1 1\n1\n1\n1000000000\n2 2 2\n1 2\n5 4\n6 7\n2 2 2\n1 2\n3 4\n6 7\n3 4 1\n3 2 1\n7 3 3 4\n6\n", "output": "14\n1999999996000000002\n24\n24\n14\n", "type": "stdin_stdout" }, { "...
code_contests
verifiable_code
1358_E. Are You Fired?
Solve the following coding problem using the programming language python: Levian works as an accountant in a large company. Levian knows how much the company has earned in each of the n consecutive months — in the i-th month the company had income equal to a_i (positive income means profit, negative income means loss,...
```python import sys input = sys.stdin.readline n = int(input()) a = list(map(int, input().split())) x = int(input()) chg = [0] for i in range(n//2): chg.append(x-a[i]) for i in range(1, n//2+1): chg[i] += chg[i-1] for i in range(1, n//2+1): chg[i] = min(chg[i], chg[i-1]) pref = sum(a) for k in range(...
vfc_56357
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 -1\n2\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n-2 -2 6\n-1\n", "output": "4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1399_E2. Weights Division (hard version)
Solve the following coding problem using the programming language python: Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. Also, each edge has its own cost. A tree is a connected graph ...
```python import sys,bisect from collections import deque input=sys.stdin.buffer.readline t=1 t=int(input()) for _ in range(t): n,S=map(int,input().split()) edge=[[] for i in range(n)] for i in range(n-1): u,v,w,c=map(int,input().split()) edge[u-1].append((v-1,w,float(c))) edge[v-1...
vfc_56365
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 18\n2 1 9 2\n3 2 4 1\n4 1 1 2\n3 20\n2 1 8 1\n3 1 7 2\n5 50\n1 3 100 1\n1 5 10 2\n2 3 123 2\n5 4 55 1\n2 100\n1 2 409 2\n", "output": "0\n0\n11\n6\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1442_B. Identify the Operations
Solve the following coding problem using the programming language python: We start with a permutation a_1, a_2, …, a_n and with an empty array b. We apply the following operation k times. On the i-th iteration, we select an index t_i (1 ≤ t_i ≤ n-i+1), remove a_{t_i} from the array, and append one of the numbers a_{t...
```python mxn=998244353 for _ in range(int(input())): n,k=map(int,input().split()) a=list(map(int,input().split())) b=list(map(int,input().split())) pre=[i-1 for i in range(n)] next=[i+1 for i in range(n)] vis=[0]*(n+1) dct=[0]*(n+1) for i in range(n): dct[a[i]]= i for num in...
vfc_56373
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 3\n1 2 3 4 5\n3 2 5\n4 3\n4 3 2 1\n4 3 1\n7 4\n1 4 7 3 6 2 5\n3 2 4 5\n", "output": "2\n0\n4\n", "type": "stdin_stdout" } ] }