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
primed-position
Solve the following coding problem using the programming language python: Prime numbers are those numbers which have only 2 factors, 1 and the number itself. For example, 3 is a prime number have factors 1 and 3 only. Now, all the prime numbers are arranged sequentially in ascending order. i.e:- 2, 3, 5,7...and so on...
```python def primes2(limit): if limit < 2: return [] if limit < 3: return [2] lmtbf = (limit - 3) // 2 buf = [True] * (lmtbf + 1) for i in range((int(limit ** 0.5) - 3) // 2 + 1): if buf[i]: p = i + i + 3 s = p * (i + 1) + i buf[s::p] = [False] * ((lmtbf ...
vfc_33241
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2\n2 3\n\nSAMPLE", "output": "15 \n55", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2\n2 6\n\nSAMPLE", "output": "15\n205\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
satisfaction-sets
Solve the following coding problem using the programming language python: What if we Unite against the Difference between ourselves ? Welcome into the Brother-Hood town. Citizens of Brother-Hood town are feeling very happy that you came for their help. But what is the problem they have ? There is one very crucial pro...
```python n = int(input()) e = [0]*501 for i in range(n): m = int(input()) a = map(int,raw_input().split()) f = [0]*501 for j in a: f[j] = 1 for j in range(501): e[j]+=f[j] ans = 0 for i in range(501): if e[i]==n: ans-=i print ans ```
vfc_33245
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5\n1 1 2 3 7\n5\n3 5 2 1 6\n5\n1 5 7 8 9\n\nSAMPLE", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n5\n1 1 2 3 7\n5\n3 5 2 1 11\n5\n1 5 7 8 9\n\nSAMPLE", "output...
code_contests
verifiable_code
swap-it-2
Solve the following coding problem using the programming language python: Bob loves sorting very much. He is always thinking of new ways to sort an array.His friend Ram gives him a challenging task.He gives Bob an array and an integer K .The challenge is to produce the lexicographical minimal array after at most K-swa...
```python def main(): t = int(raw_input().strip()) while t !=0: n, k = [int(x) for x in raw_input().split()] arr = [int(x) for x in raw_input().split()] i = 0 while i<n and k !=0: temp = arr[i] min_index = i for j in xrange(i+1, min(k+i+1, n)): if arr[j]<temp: min_index = j temp =...
vfc_33249
{ "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 2\n5 3 1\n5 3\n8 9 11 2 1\n\nSAMPLE", "output": "1 5 3\n2 8 9 11 1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
where-is-checkerboard
Solve the following coding problem using the programming language python: At HackerEarth we love play checkers and we play it a lot! However, we play a very specific kind of checkers. Our game is played on 32x32 board. If you are a programmer, you probably know why the board size is 32. Maybe we will describe details ...
```python def search(s): m = len(s) n = len(s[0]) count = 0 mat = [[[0,0]for i in range(n)] for i in range(m)] for i in range(m): for j in range(n): if s[i][j] != s[i][j-1]: mat[i][j][0] = mat[i][j-1][0] + 1 else: mat[i][j][0] = 1 ...
vfc_33253
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "42 42\n__________________________________________\n__________________________________________\n__________________________________________\n__________________________________________\n__________________________________________\n____...
code_contests
verifiable_code
p00052 Factorial II
Solve the following coding problem using the programming language python: n! = n × (n − 1) × (n − 2) × ... × 3 × 2 × 1 Is called the factorial of n. For example, the factorial of 12 12! = 12 x 11 x 10 x 9 x 8 x 7 x 6 x 5 x 4 x 3 x 2 x 1 = 479001600 And there are two consecutive 0s at the end. Write a program that ...
```python import sys f = sys.stdin while True: n = int(f.readline()) if n == 0: break zero_count = 0 while n: n //= 5 zero_count += n print(zero_count) ```
vfc_33297
{ "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\n12\n10000\n0", "output": "0\n2\n2499", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n21\n10000\n0", "output": "0\n4\n2499\n", "type": "stdin_stdout" }, { "fn_...
code_contests
verifiable_code
p00182 Beaker
Solve the following coding problem using the programming language python: Beakers of various capacities are given. First, choose one of the largest beakers and pour it through the faucet until it is full. Next, transfer the water from the beaker to another beaker according to the following rules. * All water in the b...
vfc_33301
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n11 2 23 4 2 12 8 5 2 10\n8\n2 1 3 11 2 3 1 4\n9\n5 9 1 2 4 8 17 1 8\n8\n3 38 9 4 18 14 19 5\n1\n1\n0", "output": "YES\nYES\nYES\nNO\nYES", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00529 Tower of JOIOI
Solve the following coding problem using the programming language python: Tower of JOIOI The JOIOI Tower is a game that uses a disk to be played by one person. This game is played using several disks with the letters J, O, and I written on them. The discs have different diameters, and at the start of the game, these...
vfc_33309
{ "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": "6\nJOIIOI", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\nIOIIOJ", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6...
code_contests
verifiable_code
p00696 Multi-column List
Solve the following coding problem using the programming language python: Ever since Mr. Ikra became the chief manager of his office, he has had little time for his favorites, programming and debugging. So he wants to check programs in trains to and from his office with program lists. He has wished for the tool that p...
```python while True: plen = input() if plen == 0: break cnum = input() width = input() cspace = input() def formated_print(note): for i in xrange(plen): print ("."*cspace).join(note[j*plen+i].ljust(width, ".") for j in xrange(cnum)) print "#" note = [] ...
vfc_33313
{ "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": "6\n2\n8\n1\nAZXU5\n1GU2D4B\nK\nPO4IUTFV\nTHE\nQ34NBVC78\nT\n1961\nXWS34WQ\n\nLNGLNSNXTTPG\nED\nMN\nMLMNG\n?\n4\n2\n6\n2\nQWERTY\nFLHL\n?\n0", "output": "AZXU5....8.......\n1GU2D4B..T.......\nK........1961....\nPO4IUTFV.XWS34W...
code_contests
verifiable_code
p00837 Book Replacement
Solve the following coding problem using the programming language python: The deadline of Prof. Hachioji’s assignment is tomorrow. To complete the task, students have to copy pages of many reference books in the library. All the reference books are in a storeroom and only the librarian is allowed to enter it. To obta...
```python def solve(): from collections import deque from sys import stdin f_i = stdin ans = [] while True: m, c, n = map(int, f_i.readline().split()) if m == 0: break book_pos = dict() studens = deque() shelf = m + 1 ...
vfc_33317
{ "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": "2 1 1\n1\n50\n2 1 2\n1\n50\n1\n60\n2 1 2\n2\n60 61\n1\n70\n4 2 3\n3\n60 61 62\n1\n70\n2\n80 81\n3 1 2\n3\n60 61 62\n2\n70 60\n1 2 5\n2\n87 95\n3\n96 71 35\n2\n68 2\n3\n3 18 93\n2\n57 2\n2 2 1\n5\n1 2 1 3 1\n0 0 0", "output": ...
code_contests
verifiable_code
p00969 Arithmetic Progressions
Solve the following coding problem using the programming language python: Arithmetic Progressions An arithmetic progression is a sequence of numbers $a_1, a_2, ..., a_k$ where the difference of consecutive members $a_{i+1} - a_i$ is a constant ($1 \leq i \leq k-1$). For example, the sequence 5, 8, 11, 14, 17 is an ar...
```python #!/usr/bin/python3 import os import sys def main(): N = read_int() V = read_ints() print(solve(N, V)) def solve(N, V): V.sort() pos = {} for i, a in enumerate(V): pos[a] = i best = 2 done = [[False] * N for _ in range(N)] for i in range(N): a = V[i] ...
vfc_33321
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n0 1 3 5 6 9", "output": "4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01101 Taro's Shopping
Solve the following coding problem using the programming language python: Taro's Shopping Mammy decided to give Taro his first shopping experience. Mammy tells him to choose any two items he wants from those listed in the shopping catalogue, but Taro cannot decide which two, as all the items look attractive. Thus he ...
```python while True: n,m = map(int,input().split(" ")) if n == 0: break items = [] for i in input().split(" "): items.append(int(i)) #全探索 items2 = items sums = [] for i in range(len(items)): for j in range(len(items)): if i == j: co...
vfc_33325
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 45\n10 20 30\n6 10\n1 2 5 8 9 11\n7 100\n11 34 83 47 59 29 70\n4 100\n80 70 60 50\n4 20\n10 5 10 16\n0 0", "output": "40\n10\n99\nNONE\n20", "type": "stdin_stdout" }, { "fn_name": null, "input": "3...
code_contests
verifiable_code
p01238 Subdividing a Land
Solve the following coding problem using the programming language python: Indigo Real-estate Company is now planning to develop a new housing complex. The entire complex is a square, all of whose edges are equally a meters. The complex contains n subdivided blocks, each of which is a b-meter square. Here both a and b ...
vfc_33329
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n0", "output": "Case 1: 3 2\nCase 2: 2 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0\n0", "output": "Case 1: 3 2\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
p01400 Seishun 18 Kippu
Solve the following coding problem using the programming language python: Problem C: Seishun 18 Kippu A student at R University, sirokurostone, was about to attend a training camp at Atsu University. Other members plan to use the Shinkansen, but sirokurostone was going to use the Seishun 18 Ticket. Similarly, a perso...
```python from heapq import heappush, heappop while True: n, m = map(int, input().split()) if n == 0:break s, p, g = input().split() edges = {} for _ in range(m): a, b, d, t = input().split() if a not in edges:edges[a] = [] if b not in edges:edges[b] = [] d = int(d) t = int(t) edges[a]...
vfc_33333
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\nA B G\nA B 40 3\nB C 80 0\nA G 40 0\nB G 80 0\n5 6\nKusatsu Tokyo Aizu\nTokyo Nagoya 120 3\nKusatsu Nagoya 40 0\nKusatsu Kanazawa 40 0\nKanazawa Aizu 40 0\nTokyo Kanazawa 40 0\nTokyo Aizu 80 4\n0 0", "output": "5\n4", ...
code_contests
verifiable_code
p01553 Hakone
Solve the following coding problem using the programming language python: Hakone Ekiden is one of the Japanese New Year's traditions. In Hakone Ekiden, 10 runners from each team aim for the goal while connecting the sashes at each relay station. In the TV broadcast, the ranking change from the previous relay station i...
```python #!/usr/bin/env python3 import sys import math from bisect import bisect_right as br from bisect import bisect_left as bl sys.setrecursionlimit(2147483647) from heapq import heappush, heappop,heappushpop from collections import defaultdict from itertools import accumulate from collections import Counter from ...
vfc_33337
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 262144000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n-\nU\nD", "output": "1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01709 Color the Map Extreme
Solve the following coding problem using the programming language python: Problem Statement You have just transferred to another world, and got a map of this world. There are several countries in this world. Each country has a connected territory, which is drawn on the map as a simple polygon consisting of its border...
vfc_33341
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\n0 0\n1 0\n0 1\n4\n4\n0 0\n10 0\n10 10\n0 10\n4\n10 0\n20 0\n20 10\n10 10\n4\n0 10\n10 10\n10 20\n0 20\n4\n10 10\n20 10\n20 20\n10 20\n3\n4\n-10 -10\n2 2\n10 10\n-11 7\n3\n-1 -1\n1 -1\n0 0\n3\n0 0\n3 -3\n20 20\n7\n4\n46 12\n52...
code_contests
verifiable_code
p01854 Pots
Solve the following coding problem using the programming language python: Problem statement Here are N mysteriously shaped vases. The i-th jar is a shape in which K_i right-sided cylinders are vertically connected in order from the bottom. The order in which they are connected cannot be changed. Mr. A has a volume of...
```python def main(): n, m = map(int, input().split()) height = [] for _ in range(n): lst = list(map(int, input().split())) k = lst[0] ss = lst[1::2] hs = lst[2::2] v_acc = 0 h_acc = 0 index = 0 s, h = ss[0], hs[0] save = [] for i in range(m + 1): if i < v_acc + s * h...
vfc_33345
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 15\n2 3 3 7 2\n2 7 1 1 4", "output": "6.33333333", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 15\n2 3 3 7 2\n1 7 1 1 4", "output": "3.857143\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
p01989 Internet Protocol Address
Solve the following coding problem using the programming language python: A: IP Address (Internet Protocol Address) problem Since one number string is given, find the number of valid delimiters for IPv4 IP addresses. However, the effective delimiters for IPv4 IP addresses are as follows. * The sequence of numbers i...
```python def check(num): if num == "":return False if num[0] == "0":return num == "0" return 0 <= int(num) <= 255 s = input() ans = 0 for i in range(1, 4): for j in range(1, 4): for k in range(1, 4): n1 = s[:i] n2 = s[i:i+j] n3 = s[i+j:i+j+k] n4 = s[i+j+k:] if check(n1) and ch...
vfc_33349
{ "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": "123456789", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "243960381", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1...
code_contests
verifiable_code
p02276 Partition
Solve the following coding problem using the programming language python: Quick sort is based on the Divide-and-conquer approach. In QuickSort(A, p, r), first, a procedure Partition(A, p, r) divides an array A[p..r] into two subarrays A[p..q-1] and A[q+1..r] such that each element of A[p..q-1] is less than or equal to...
```python def partition(A, p, r): i = p - 1 x = A[r] for j in range(p,r): if A[j] <= x: i += 1 A[i], A[j] = A[j], A[i] A[i+1], A[r] = A[r], A[i+1] return i n = int(input()) A = list(map(int, input().split())) i = partition(A, 0, n-1) str_A = list(map(str,A)) ...
vfc_33357
{ "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": "12\n13 19 9 5 12 8 7 4 21 2 6 11", "output": "9 5 8 7 4 2 6 [11] 21 13 19 12", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
abcstr
Solve the following coding problem using the programming language python: Mike likes strings. He is also interested in algorithms. A few days ago he discovered for himself a very nice problem: You are given an AB-string S. You need to count the number of substrings of S, which have an equal number of 'A'-s and 'B'-s...
```python def abcstr(): s = raw_input() n = len(s) if n < 3: return 0 A, B, C = ([0 for _ in xrange(n+1)] for _ in xrange(3)) for i in xrange(1, n+1): ch = s[i-1] A[i] = A[i-1] + 1 if ch == 'A' else A[i-1] B[i] = B[i-1] + 1 if ch == 'B' else B[i-1] C...
vfc_33365
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ABACABA", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "ABBCABA", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "ABA...
code_contests
verifiable_code
cheflr
Solve the following coding problem using the programming language python: Chef has a nice complete binary tree in his garden. Complete means that each node has exactly two sons, so the tree is infinite. Yesterday he had enumerated the nodes of the tree in such a way: Let's call the nodes' level a number of nodes tha...
```python import sys def update_odd( direction , value ) : if direction == 'l' : value = (value * 2) else : value = (2 *value + 2) return value def update_even(direction , value) : if direction == 'l' : value = (2*value - 1) else : value = (2*value + 1) retu...
vfc_33369
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nlrl\nrll\nr\nlllr", "output": "10\n14\n4\n13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nrll\nrll\nr\nlllr", "output": "14\n14\n4\n13\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
divgold
Solve the following coding problem using the programming language python: You have a string S consisting of N uppercase English letters. You are allowed to perform at most one operation of following kind: Choose any position in the string, remove the character at that position and insert it back to any other place in ...
```python t = int(raw_input()) for i in range(t): n = int(raw_input()) s = raw_input() if n == 1: print s continue tmp = [] for j in range(n): for k in range(n): x = list(s) x.insert(k, x.pop(j)) tmp.append(x) print ''.join(min(tmp)) ```
vfc_33373
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\nDCBA\n7\nXYZZYZZ", "output": "ADCB\nXYYZZZZ\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4\nDCBA\n7\nXYZZYZY", "output": "ADCB\nXYYZZYZ\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
intresec
Solve the following coding problem using the programming language python: Problem description. Chef is playing with 'n' set of planes. He notices that when two planes intersects a line is formed. Being that curious guy that chef already is, he wonders as to how many maximum possible line intersections can he obtain wi...
```python for __ in range(input()): n = input() n-=1 print (n*(n+1))/2 ```
vfc_33377
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n3", "output": "1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n0", "output": "1\n0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
nita10
Solve the following coding problem using the programming language python: Alan threw a party and invited all her close friend to it. Let us suppose there were 2n people in the party and all of them were sitting across a round table. The host asked them to shake hands with the condition that no two hands should cross e...
```python from math import factorial as fac def catalan(n): return fac(2*n) // fac(n+1) // fac(n) def num_handshakes(n): if n % 2 == 1: return 0 return catalan(n//2) T=int(raw_input()) while T>0: N=int(raw_input()) print num_handshakes(2*N) %100003 T=T-1 ```
vfc_33381
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n4", "output": "2\n14", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
seakam
Solve the following coding problem using the programming language python: Sereja has an undirected graph on N vertices. There are edges between all but M pairs of vertices. A permutation p on the vertices of the graph is represented as p[1], p[2], … , p[N] such that for all i, p[i] is a vertex of the graph. A permuta...
```python import itertools MODULO=1000000007 visited = [0] * 100001 count_connected_components = 0 #functions def depth_first_traversal(graph, node, visited): stack = [] visited[node] = 1 stack.extend(graph[node]) while len(stack) != 0: seed = stack.pop() if not visited[seed]: visited[seed] = 1 stack.exte...
vfc_33385
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 3\n1 2\n2 3\n3 4\n2 1\n1 2", "output": "2\n0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1000_G. Two-Paths
Solve the following coding problem using the programming language python: You are given a weighted tree (undirected connected graph with no cycles, loops or multiple edges) with n vertices. The edge \\{u_j, v_j\} has weight w_j. Also each vertex i has its own value a_i assigned to it. Let's call a path starting in ve...
vfc_33389
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 6\n6 5 5 3 2 1 2\n1 2 2\n2 3 2\n2 4 1\n4 5 1\n6 4 2\n7 3 25\n1 1\n4 4\n5 6\n6 4\n3 4\n3 7\n", "output": "9\n9\n9\n8\n12\n-14\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10\n857690...
code_contests
verifiable_code
1045_J. Moonwalk challenge
Solve the following coding problem using the programming language python: Since astronauts from BubbleCup XI mission finished their mission on the Moon and are big fans of famous singer, they decided to spend some fun time before returning to the Earth and hence created a so called "Moonwalk challenge" game. Teams of...
vfc_33397
{ "difficulty": "16", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2 3 g\n3 4 n\n5 3 o\n6 1 n\n1 2 d\n7\n1 6 n\n6 4 dg\n6 4 n\n2 5 og\n1 2 d\n6 5 go\n2 3 g\n", "output": "1\n1\n2\n0\n1\n1\n1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
106_D. Treasure Island
Solve the following coding problem using the programming language python: Our brave travelers reached an island where pirates had buried treasure. However as the ship was about to moor, the captain found out that some rat ate a piece of the treasure map. The treasure map can be represented as a rectangle n × m in siz...
```python #!/usr/bin/env python3 from sys import stdin n, m = map(int, stdin.readline().rstrip().split()) island = [] pos = {} for i in range(n): island.append(stdin.readline().rstrip()) for j, c in enumerate(island[i]): if c >= 'A' and c <= 'Z': pos[c] = [i, j] l_reach = [[-1 for j in ra...
vfc_33401
{ "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": "3 4\n####\n#.A#\n####\n2\nW 1\nN 2\n", "output": "no solution\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 10\n##########\n#K#..#####\n#.#..##.##\n#..L.#...#\n###D###A.#\n##########\n...
code_contests
verifiable_code
1091_C. New Year and the Sphere Transmission
Solve the following coding problem using the programming language python: There are n people sitting in a circle, numbered from 1 to n in the order in which they are seated. That is, for all i from 1 to n-1, the people with id i and i+1 are adjacent. People with id n and 1 are adjacent as well. The person with id 1 i...
```python n=int(input()) a={1} for i in range(2,int(n**0.5)+1): if n%i==0: a.add(i) a.add(n//i) ans=[1] a=list(a) for i in a: term=n//i ans.append((term*(2+(term-1)*i))//2) ans.sort() print(*ans) ```
vfc_33405
{ "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": "6\n", "output": "1 5 9 21\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "16\n", "output": "1 10 28 64 136\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
113_C. Double Happiness
Solve the following coding problem using the programming language python: On the math lesson a teacher asked each pupil to come up with his own lucky numbers. As a fan of number theory Peter chose prime numbers. Bob was more original. He said that number t is his lucky number, if it can be represented as: t = a2 + b...
```python f = lambda x: int(x**.5)+1 h,z = map(bytearray,'1\0') L,R = map(int,raw_input().split()) n = f(R); b = n/2*h; b[0] = 0 for k in xrange(1,f(n)/2): if b[k]: p = 2*k+1; s = k*(p+1); b[s::p] = z*len(b[s::p]) g = ((i*(i+1),2*i+1) for i,v in enumerate(b) if v) r = (R+3)/4*h; r[0] = 0 for s,p in g: r[s::...
vfc_33413
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 128000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 66\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1158_B. The minimal unique substring
Solve the following coding problem using the programming language python: Let s be some string consisting of symbols "0" or "1". Let's call a string t a substring of string s, if there exists such number 1 ≤ l ≤ |s| - |t| + 1 that t = s_l s_{l+1} … s_{l + |t| - 1}. Let's call a substring t of string s unique, if there...
```python # ========= /\ /| |====/| # | / \ | | / | # | /____\ | | / | # | / \ | | / | # ========= / \ ===== |/====| # code if __name__ == "__main__": n,k = map(int,input().split()) a = (n - k)//2 ps = '0'*a + '...
vfc_33417
{ "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 4\n", "output": "1111\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1180_A. Alex and a Rhombus
Solve the following coding problem using the programming language python: While playing with geometric figures Alex has accidentally invented a concept of a n-th order rhombus in a cell grid. A 1-st order rhombus is just a square 1 × 1 (i.e just a cell). A n-th order rhombus for all n ≥ 2 one obtains from a n-1-th o...
```python n = int(input()) print(sum(range(n)) * 4 + 1) ```
vfc_33421
{ "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\n", "output": "13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1199_A. City Day
Solve the following coding problem using the programming language python: For years, the Day of city N was held in the most rainy day of summer. New mayor decided to break this tradition and select a not-so-rainy day for the celebration. The mayor knows the weather forecast for the n days of summer. On the i-th day, a...
```python import sys,heapq,math from collections import deque,defaultdict printn = lambda x: sys.stdout.write(x) inn = lambda : int(input()) inl = lambda: list(map(int, input().split())) inm = lambda: map(int, input().split()) DBG = True # and False R = 10**9 + 7 def ddprint(x): if DBG: print(x) n,x,y ...
vfc_33425
{ "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 5\n100000 10000 1000 100 10\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 2 2\n10 9 6 7 8 3 2 1 4 5\n", "output": "3\n", "type": "stdin_stdout" },...
code_contests
verifiable_code
1215_F. Radio Stations
Solve the following coding problem using the programming language python: In addition to complaints about lighting, a lot of complaints about insufficient radio signal covering has been received by Bertown city hall recently. n complaints were sent to the mayor, all of which are suspiciosly similar to each other: in t...
```python # ------------------- fast io -------------------- import os import sys input = lambda: sys.stdin.readline().rstrip("\r\n") # ------------------- fast io -------------------- def find_SCC(graph): SCC, S, P = [], [], [] depth = [0] * len(graph) stack = list(range(len(graph))) while stack...
vfc_33429
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 7, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 4 4 2\n1 3\n2 3\n1 4\n1 2\n3 4\n1 4\n1 2\n3 4\n", "output": "2 3\n1 3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4 4 2\n1 3\n2 4\n1 2\n1 2\n3 4\n3 4\n1 2\n3 4\n", "output": "...
code_contests
verifiable_code
1239_A. Ivan the Fool and the Probability Theory
Solve the following coding problem using the programming language python: Recently Ivan the Fool decided to become smarter and study the probability theory. He thinks that he understands the subject fairly well, and so he began to behave like he already got PhD in that area. To prove his skills, Ivan decided to demon...
```python n, m = map(int, input().split()) mod = 10**9+7 a = [] a.append(0) a.append(2) a.append(4) for i in range(3, max(n, m)+1): a.append((a[i-1]+a[i-2])%mod) print((a[m]-2 + a[n])%mod) ```
vfc_33433
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 3\n", "output": "8\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1257_C. Dominated Subarray
Solve the following coding problem using the programming language python: Let's call an array t dominated by value v in the next situation. At first, array t should have at least 2 elements. Now, let's calculate number of occurrences of each number num in t and define it as occ(num). Then t is dominated (by v) if (an...
```python import collections ii = lambda: int(input()) iia = lambda: list(map(int,input().split())) isa = lambda: list(input().split()) t = ii() for i in range(t): n = ii() x = iia() if(n==1): print('-1') else: dist = collections.defaultdict(lambda : n) last = collections.defaultdict(lambda : -1) mini = n...
vfc_33437
{ "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": "4\n1\n1\n6\n1 2 3 4 5 1\n9\n4 1 2 4 5 4 3 2 1\n4\n3 3 3 3\n", "output": "-1\n6\n3\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n11\n1 1 1 1 1 1 1 1 1 1 1\n", "output": "2\n",...
code_contests
verifiable_code
1280_D. Miss Punyverse
Solve the following coding problem using the programming language python: The Oak has n nesting places, numbered with integers from 1 to n. Nesting place i is home to b_i bees and w_i wasps. Some nesting places are connected by branches. We call two nesting places adjacent if there exists a branch between them. A sim...
vfc_33441
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 3\n10 160 70 50\n70 111 111 0\n1 2\n2 3\n3 4\n2 1\n143 420\n214 349\n2 1\n", "output": "2\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n5 2\n3 0 1 0 3\n0 2 0 2 0\n1 2\n2 3\n3 ...
code_contests
verifiable_code
1300_C. Anu Has a Function
Solve the following coding problem using the programming language python: Anu has created her own function f: f(x, y) = (x | y) - y where | denotes the [bitwise OR operation](https://en.wikipedia.org/wiki/Bitwise_operation#OR). For example, f(11, 6) = (11|6) - 6 = 15 - 6 = 9. It can be proved that for any nonnegative ...
```python import sys,os,io input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline n = int(input()) a = [int(i) for i in input().split()] m = 0 mi = 0 b = [-1]*(35) for i in range (len(a)): bi = bin(a[i])[2:][::-1] for j in range (len(bi)): if bi[j]=='1': if b[j]==-1: ...
vfc_33445
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n13\n", "output": "13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4 0 11 6\n", "output": "11 4 0 6 \n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
1365_D. Solve The Maze
Solve the following coding problem using the programming language python: Vivek has encountered a problem. He has a maze that can be represented as an n × m grid. Each of the grid cells may represent the following: * Empty — '.' * Wall — '#' * Good person — 'G' * Bad person — 'B' The only escape from t...
```python # ------------------- fast io -------------------- import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = "x" in file.mode or "r" not in...
vfc_33457
{ "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": "6\n1 1\n.\n1 2\nG.\n2 2\n#B\nG.\n2 3\nG.#\nB#.\n3 3\n#B.\n#..\nGG.\n2 2\n#B\nB.\n", "output": "Yes\nYes\nNo\nNo\nYes\nYes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 5\nB.GGG\n.B....
code_contests
verifiable_code
1385_D. a-Good String
Solve the following coding problem using the programming language python: You are given a string s[1 ... n] consisting of lowercase Latin letters. It is guaranteed that n = 2^k for some integer k ≥ 0. The string s[1 ... n] is called c-good if at least one of the following three conditions is satisfied: * The lengt...
```python import sys input = sys.stdin.readline def print(val): sys.stdout.write(str(val) + '\n') def solve(s,l,r,c): if l+1 == r: return int(s[l] != c) replace1 = replace2 = 0 for i in range(l,(l+r)//2): if s[i] != c: replace1 += 1 for i in range((l+r)//2, r): if...
vfc_33461
{ "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": "6\n8\nbbdcaaaa\n8\nasdfghjk\n8\nceaaaabb\n8\nbbaaddcc\n1\nz\n2\nac\n", "output": "0\n7\n4\n5\n1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n8\nbbdcaaaa\n8\nasdfghjk\n8\nceaaaabb\...
code_contests
verifiable_code
1427_H. Prison Break
Solve the following coding problem using the programming language python: A prisoner wants to escape from a prison. The prison is represented by the interior of the convex polygon with vertices P_1, P_2, P_3, …, P_{n+1}, P_{n+2}, P_{n+3}. It holds P_1=(0,0), P_{n+1}=(0, h), P_{n+2}=(-10^{18}, h) and P_{n+3}=(-10^{18},...
vfc_33469
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0 0\n2 2\n2 4\n0 6\n", "output": "1.082392202\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n0 0\n412 36\n745 180\n747 184\n746 268\n611 359\n213 441\n0 450\n", "output": "1.1...
code_contests
verifiable_code
1450_H2. Multithreading (Hard Version)
Solve the following coding problem using the programming language python: The only difference between the two versions of the problem is that there are no updates in the easy version. There are n spools of thread placed on the rim of a circular table. The spools come in two types of thread: the first thread is black ...
vfc_33473
{ "difficulty": "14", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 3\n???ww?wb??\n4 ?\n5 ?\n2 w\n", "output": "\n436731905\n218365953\n374341633\n530317313\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 0\nbwbb?www\n", "output": "\n1\n", ...
code_contests
verifiable_code
1474_F. 1 2 3 4 ...
Solve the following coding problem using the programming language python: Igor had a sequence d_1, d_2, ..., d_n of integers. When Igor entered the classroom there was an integer x written on the blackboard. Igor generated sequence p using the following algorithm: 1. initially, p = [x]; 2. for each 1 ≤ i ≤ n h...
```python import sys, io, os if os.environ['USERNAME']=='kissz': inp=open('in55.txt','r').readline def debug(*args): print(*args,file=sys.stderr) else: inp=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline def debug(*args): pass def mexp(size,power): A=[] for i in range(size)...
vfc_33477
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n100\n5 -3 6\n", "output": "\n9 7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3\n1 -1 2\n", "output": "\n3 3\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
14_C. Four Segments
Solve the following coding problem using the programming language python: Several months later Alex finally got his brother Bob's creation by post. And now, in his turn, Alex wants to boast about something to his brother. He thought for a while, and came to the conclusion that he has no ready creations, and decided to...
```python def is_rect(es): v = set([]) for e in es: if not ((e[0] == e[2]) or (e[1] == e[3])): return False v.add((e[0], e[1])) v.add((e[2], e[3])) if len(v) != 4: return False xs = set([]) ys = set([]) for vi in v: xs.add(vi[0]) ys...
vfc_33481
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0 0 0 3\n2 0 0 0\n2 2 2 0\n0 2 2 2\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 6 1\n1 0 6 0\n6 0 6 1\n1 1 1 0\n", "output": "YES\n", "type": "stdin_st...
code_contests
verifiable_code
1523_H. Hopping Around the Array
Solve the following coding problem using the programming language python: <image> William really wants to get a pet. Since his childhood he dreamt about getting a pet grasshopper. William is being very responsible about choosing his pet, so he wants to set up a trial for the grasshopper! The trial takes place on an ...
vfc_33485
{ "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": "9 5\n1 1 2 1 3 1 2 1 1\n1 1 0\n2 5 1\n5 9 1\n2 8 2\n1 9 4\n", "output": "\n0\n2\n1\n2\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20 31\n1 1 3 2 1 1 1 1 2 2 2 3 1 2 1 3 2 3 1 3\n5 1...
code_contests
verifiable_code
156_B. Suspects
Solve the following coding problem using the programming language python: As Sherlock Holmes was investigating a crime, he identified n suspects. He knows for sure that exactly one of them committed the crime. To find out which one did it, the detective lines up the suspects and numbered them from 1 to n. After that, ...
```python n, m = map(int, input().split()) t = [int(input()) for i in range(n)] s, p = 0, [0] * (n + 1) for i in t: if i < 0: m -= 1 p[-i] -= 1 else: p[i] += 1 q = {i for i in range(1, n + 1) if p[i] == m} if len(q) == 0: print('Not defined\n' * n) elif len(q) == 1: j = q.pop() print('\n...
vfc_33489
{ "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": "4 1\n+2\n-3\n+4\n-1\n", "output": "Lie\nNot defined\nLie\nNot defined\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n+1\n", "output": "Truth\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
177_F1. Script Generation
Solve the following coding problem using the programming language python: The Smart Beaver from ABBYY was offered a job of a screenwriter for the ongoing TV series. In particular, he needs to automate the hard decision: which main characters will get married by the end of the series. There are n single men and n sing...
```python I=lambda:list(map(int,input().split())) n,k,T=I() t=[I()for _ in '0'*k] def b(h,w,r,a): if h>n:a+=[r] else: b(h+1,w,r,a) for f,s,v in t: if f==h and s in w:b(h+1,w-set([s]),r+v,a) return a print(sorted(b(1,set(range(1,n+1)), 0,[]))[T-1]) ```
vfc_33493
{ "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": "2 4 3\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4 7\n1 1 1\n1 2 2\n2 1 3\n2 2 7\n", "output": "8\n", "type": "stdin_stdout"...
code_contests
verifiable_code
199_C. About Bacteria
Solve the following coding problem using the programming language python: Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the be...
```python #------------------------template--------------------------# import os import sys from math import * from collections import * from fractions import * from bisect import * from heapq import* from io import BytesIO, IOBase def vsInput(): sys.stdin = open('input.txt', 'r') sys.stdout = open('output.txt'...
vfc_33497
{ "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 2 4 100\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1 3 5\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
246_B. Increase and Decrease
Solve the following coding problem using the programming language python: Polycarpus has an array, consisting of n integers a1, a2, ..., an. Polycarpus likes it when numbers in an array match. That's why he wants the array to have as many equal numbers as possible. For that Polycarpus performs the following operation ...
```python x=int(input()) sm=sum(list(map(int,input().split())))%x if sm==0: print(x) else: print(x-1) ```
vfc_33505
{ "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\n1 4 1\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
271_C. Secret
Solve the following coding problem using the programming language python: The Greatest Secret Ever consists of n words, indexed by positive integers from 1 to n. The secret needs dividing between k Keepers (let's index them by positive integers from 1 to k), the i-th Keeper gets a non-empty set of words with numbers f...
```python import sys; class MyReader: # file = null; def __init__(self): filename = "file.in"; if self.isLocal(): self.file = open(filename); self.str = [""]; self.ind = 1; def isLocal(self): return len(sys.argv) > 1 and sys.argv[1] == "SCHULL...
vfc_33509
{ "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": "11 3\n", "output": "1 1 2 2 3 3 1 2 3 1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n", "output": "-1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
318_C. Perfect Pair
Solve the following coding problem using the programming language python: Let us call a pair of integer numbers m-perfect, if at least one number in the pair is greater than or equal to m. Thus, the pairs (3, 3) and (0, 2) are 2-perfect while the pair (-1, 1) is not. Two integers x, y are written on the blackboard. I...
```python from sys import stdin from math import ceil x, y, m = map(int, stdin.readline().split()) ans = 0 if x >= m or y >= m: print(ans) elif x + y > min(x, y): ma, mi = max(x, y), min(x, y) ans += ((ma - mi) // ma) # + ((ma - mi) % ma) mi, ma = min(ma, mi + ans * ma), max(ma, mi + ans * ma) w...
vfc_33517
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "-1 4 15\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2 5\n", "output": " 2\n", "type": "stdi...
code_contests
verifiable_code
342_C. Cupboard and Balloons
Solve the following coding problem using the programming language python: A girl named Xenia has a cupboard that looks like an arc from ahead. The arc is made of a semicircle with radius r (the cupboard's top) and two walls of height h (the cupboard's sides). The cupboard's depth is r, that is, it looks like a rectang...
```python if __name__=='__main__': inp = input() arr = inp.split(" ") r = int(arr[0]) h = int(arr[1]) ans = 2*(h//r) d = h%r if d*2>=r: ans+=2 if 4*d*d >= 3*r*r: ans+=1 else: ans+=1 print(ans) ```
vfc_33521
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\n", ...
code_contests
verifiable_code
365_E. Beautiful Set
Solve the following coding problem using the programming language python: We'll call a set of positive integers a beautiful if the following condition fulfills: for any prime p, if <image>, then <image>. In other words, if one number from the set is divisible by prime p, then at least half of numbers from the set is d...
```python def main(): k = input() primes = (2, 3, 5, 7, 11, 13) limit = 2 * k * k cnt = 1 a = [1] for p in primes: i = 0 while i < cnt: if a[i] * p <= limit: a.append(a[i] * p) cnt += 1 i += 1 if cnt >= k: break for i in xrange(cnt - 1, cnt - k - 1, -1): print a[i], main() ```
vfc_33525
{ "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": "10\n", "output": "192 162 144 128 108 96 81 72 64 54 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "31\n", "output": "1728 1536 1458 1296 1152 1024 972 864 768 729 648 576 512 486 ...
code_contests
verifiable_code
409_G. On a plane
Solve the following coding problem using the programming language python: Input The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of points on a plane. Each of the next n lines contains two real coordinates xi and yi of the <image> point, specified with exactly 2 fractional digits. All coordin...
```python n = int(input()) ab = 0 for i in range(n): x, y = map(float, input().split()) ab += y print(5 + ab / n) ```
vfc_33533
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\n16.94 2.42\n15.72 2.38\n14.82 1.58\n14.88 0.50\n15.76 -0.16\n16.86 -0.20\n17.00 0.88\n16.40 0.92\n", "output": "6.040", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2.26 1.44\n2.28 0....
code_contests
verifiable_code
437_B. The Child and Set
Solve the following coding problem using the programming language python: At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks. Fortunately, Picks remembers something about his set S: * ...
```python s, limit = list(map(int, input().split())) ans = [] for i in range(limit, 0, -1): k = i & (i ^(i-1)) if s >= k: s-=k ans.append(i) if s: print(-1) else: print(len(ans)) print(*ans) ```
vfc_33537
{ "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 3\n", "output": "3\n3 2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 1\n", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 ...
code_contests
verifiable_code
45_D. Event Dates
Solve the following coding problem using the programming language python: On a history lesson the teacher asked Vasya to name the dates when n famous events took place. He doesn't remembers the exact dates but he remembers a segment of days [li, ri] (inclusive) on which the event could have taken place. However Vasya ...
```python # http://codeforces.com/contest/45/problem/D from sys import stdin inFile = stdin tokens = [] tokens_next = 0 def next_str(): global tokens, tokens_next while tokens_next >= len(tokens): tokens = inFile.readline().split() tokens_next = 0 tokens_next += 1 return tokens[tokens_...
vfc_33541
{ "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": "3\n1 2\n2 3\n3 4\n", "output": "1 2 3 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
506_C. Mr. Kitayuta vs. Bamboos
Solve the following coding problem using the programming language python: Mr. Kitayuta's garden is planted with n bamboos. (Bamboos are tall, fast-growing tropical plants with hollow stems.) At the moment, the height of the i-th bamboo is hi meters, and it grows ai meters at the end of each day. Actually, Mr. Kitayu...
vfc_33549
{ "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 10 10 1000000000\n0 10\n0 10\n", "output": " 10\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
52_B. Right Triangles
Solve the following coding problem using the programming language python: You are given a n × m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triang...
```python n, m = map(int, input().split()) grid = [input() for _ in range(n)] a = [[0 for _ in range(m)] for i in range(n)] b = [[0 for _ in range(m)] for i in range(n)] for i in range(n): for j in range(m): a[i][j] = a[i][j - 1] + (grid[i][j] == '*') if i: b[i][j] = b[i - 1][j] ...
vfc_33553
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n*..*\n.**.\n*.**\n", "output": "9", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n**\n*.\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
555_D. Case of a Top Secret
Solve the following coding problem using the programming language python: Andrewid the Android is a galaxy-famous detective. Now he is busy with a top secret case, the details of which are not subject to disclosure. However, he needs help conducting one of the investigative experiment. There are n pegs put on a plane...
vfc_33557
{ "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": "3 2\n0 3 5\n2 3\n1 8\n", "output": "3\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 5 7 15\n1 4\n2 15\n3 16\n1 28\n", "output": "2\n4\n3\n1\n", "type": "stdin_stdou...
code_contests
verifiable_code
581_C. Developing Skills
Solve the following coding problem using the programming language python: Petya loves computer games. Finally a game that he's been waiting for so long came out! The main character of this game has n different skills, each of which is characterized by an integer ai from 0 to 100. The higher the number ai is, the high...
```python n,k=map(int,input().split()) l=list(map(int,input().split())) rem=[] ans=0 for i in l: rem.append(i%10) ans=ans+i//10 #print(ans) rem.sort() # 0 1 2 3.. 9 9 9.. i=n-1 while(i>=0 and k>0): if(rem[i]!=0): #starting from back 9 -> 8 .... -> 2 -> 1->0 sm=10-(rem[i]) ...
vfc_33561
{ "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 2\n99 100\n", "output": "20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 4\n7 9\n", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
603_B. Moodular Arithmetic
Solve the following coding problem using the programming language python: As behooves any intelligent schoolboy, Kevin Sun is studying psycowlogy, cowculus, and cryptcowgraphy at the Bovinia State University (BGU) under Farmer Ivan. During his Mathematics of Olympiads (MoO) class, Kevin was confronted with a weird fun...
```python __author__ = 'MoonBall' import sys # sys.stdin = open('data/D.in', 'r') T = 1 M = 1000000007 def pow(x, y, m): if y == 0: return 1 if (y & 1): return pow(x, y - 1, m) * x % m else: t = pow(x, y >> 1, m) return t * t % m def process(): P, K = list(map(int, inp...
vfc_33565
{ "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\n", "output": "3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
625_E. Frog Fights
Solve the following coding problem using the programming language python: Ostap Bender recently visited frog farm and was inspired to create his own frog game. Number of frogs are places on a cyclic gameboard, divided into m cells. Cells are numbered from 1 to m, but the board is cyclic, so cell number 1 goes right a...
vfc_33569
{ "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 5\n2 1\n5 3\n4 3\n", "output": "1\n3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n1 2\n3 4\n2 5\n5 1\n6 1\n", "output": "2\n1 4 ", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
64_G. Path Canonization
Solve the following coding problem using the programming language python: A path in some Unix-similar file system is given. The path consists of elements separated with characters "/". For example: "/usr/share/mysql/../tomcat6/conf/server.xml". The path starts with the root directory (i.e. starts with the character "/...
vfc_33573
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "/usr/share/mysql/../tomcat6/conf/server.xml\n", "output": "/usr/share/tomcat6/conf/server.xml\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "/a/./././..\n", "output": "/\n", "...
code_contests
verifiable_code
675_A. Infinite Sequence
Solve the following coding problem using the programming language python: Vasya likes everything infinite. Now he is studying the properties of a sequence s, such that its first element is equal to a (s1 = a), and the difference between any two neighbouring elements is equal to c (si - si - 1 = c). In particular, Vasy...
```python a, b, c = map(int, input().split()) if b == a: print('YES') elif not c: print('NO') elif (a < b) and c < 0: print('NO') elif (a > b) and c > 0: print('NO') else: print('NO' if ((b-a) % c) else 'YES') ```
vfc_33577
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 -4 5\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 7 3\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
699_B. One Bomb
Solve the following coding problem using the programming language python: You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*"). You have one bomb. If you lay the bomb at the cell (x, y), then after tri...
```python def bombs(array, rows, cols, walls, wallsInRows, wallsInCols): if walls == 0: print("YES") print(1, 1) return for i in range(0, rows): for j in range(0, cols): s = wallsInRows[i] + wallsInCols[j] if (array[i][j] == '*' and s - 1 == walls) or (arr...
vfc_33581
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n..*\n.*.\n*..\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 5\n..*..\n..*..\n*****\n..*..\n..*..\n..*..\n", "output": "YES\n3 3\n", "type": "stdin_st...
code_contests
verifiable_code
71_D. Solitaire
Solve the following coding problem using the programming language python: Vasya has a pack of 54 cards (52 standard cards and 2 distinct jokers). That is all he has at the moment. Not to die from boredom, Vasya plays Solitaire with them. Vasya lays out nm cards as a rectangle n × m. If there are jokers among them, th...
```python ranks = '23456789TJQKA' suits = 'CDHS' n, m = [int(i) for i in input().split()] b = [input().split() for _ in range(n)] p = [r + s for r in ranks for s in suits] j1, j2 = False, False for r in b: for c in r: if c == 'J1': j1 = True elif c == 'J2': j2 = True ...
vfc_33585
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 6\n2S 3S 4S 7S 8S AS\n5H 6H 7H 5S TC AC\n8H 9H TH 7C 8C 9C\n2D 2C 3C 4C 5C 6C\n", "output": "No solution.\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
741_A. Arpa's loud Owf and Mehrdad's evil plan
Solve the following coding problem using the programming language python: As you have noticed, there are lovely girls in Arpa’s land. People in Arpa's land are numbered from 1 to n. Everyone has exactly one crush, i-th person's crush is person with the number crushi. <image> Someday Arpa shouted Owf loudly from the...
```python def gcd(a,b): if b==0: return a return gcd(b, a%b) def lcm(a,b): return a*b/gcd(a,b) def dfs(sad, num, posjeceno): """if sad==a[sad]-1 and posjeceno!=[0]*n: return (-10, [])""" posjeceno[sad]=1 if posjeceno[a[sad]-1]==1: return (num+1, posjeceno) return dfs(...
vfc_33589
{ "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\n2 1 4 3\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4 4 4 4\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
764_E. Timofey and remoduling
Solve the following coding problem using the programming language python: Little Timofey likes integers a lot. Unfortunately, he is very young and can't work with very big integers, so he does all the operations modulo his favorite prime m. Also, Timofey likes to look for arithmetical progressions everywhere. One of ...
```python from functools import reduce def gcd_extended(bigger, less): if less == 0: return(bigger, 1, 0) mod = bigger % less div = bigger // less gcd, c_less, c_mod = gcd_extended(less, mod) #gcd == c_less * less + c_mod * mod #mod == bigger - div * less #gcd = (c_less - c_mod * di...
vfc_33593
{ "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": "17 5\n0 2 4 13 15\n", "output": " 13 2\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
809_D. Hitchhiking in the Baltic States
Solve the following coding problem using the programming language python: Leha and Noora decided to go on a trip in the Baltic States. As you know from the previous problem, Leha has lost his car on the parking of the restaurant. Unfortunately, requests to the watchman didn't helped hacker find the car, so friends dec...
vfc_33601
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n6 6\n1 2\n3 4\n2 2\n1 4\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n92332150 92332151\n92332156 92332157\n92332157 92332158\n92332150 92332151\n92332152 92332153\n...
code_contests
verifiable_code
834_B. The Festive Evening
Solve the following coding problem using the programming language python: <image> It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to ...
```python import sys n, k = map(int, input().split()) a = list(input()) st = [0] * 26 ed = [0] * 26 for i in range(n): if st[ord(a[i])-65] == 0: st[ord(a[i])-65] = i + 1 else: ed[ord(a[i])-65] = i + 1 for i in range(26): if st[i] != 0 and ed[i] == 0: ed[i] = st[i] n = 52 i = 0 j = 0 maxi = -1 * sys.maxsize l =...
vfc_33605
{ "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 1\nAABBB\n", "output": "NO\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
854_E. Boredom
Solve the following coding problem using the programming language python: Ilya is sitting in a waiting area of Metropolis airport and is bored of looking at time table that shows again and again that his plane is delayed. So he took out a sheet of paper and decided to solve some problems. First Ilya has drawn a grid ...
vfc_33609
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n1 3 2 4\n4 1 4 4\n1 1 2 3\n", "output": " 3\n 5\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
879_C. Short Program
Solve the following coding problem using the programming language python: Petya learned a new programming language CALPAS. A program in this language always takes one non-negative integer and returns one non-negative integer as well. In the language, there are only three commands: apply a bitwise operation AND, OR or...
```python n = int(input()) a, b = 1023, 0 for _ in range(n): c, d = input().split() d = int(d) if c == '|': a, b = a | d, b | d elif c == '&': a, b = a & d, b & d elif c == '^': a, b = a ^ d, b ^ d print('2\n| {}\n^ {}'.format(a ^ b ^ 1023, a ^ 1023)) # Made By Mostafa_...
vfc_33613
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n&amp; 1\n&amp; 3\n&amp; 5\n", "output": "3\n& 0\n| 0\n^ 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n^ 1\n^ 2\n^ 3\n", "output": "3\n& 1023\n| 0\n^ 0\n", "type": "st...
code_contests
verifiable_code
925_A. Stairs and Elevators
Solve the following coding problem using the programming language python: In the year of 30XX participants of some world programming championship live in a single large hotel. The hotel has n floors. Each floor has m sections with a single corridor connecting all of them. The sections are enumerated from 1 to m along ...
```python def takeClosest(myList, myNumber): """ Assumes myList is sorted. Returns closest value to myNumber. If two numbers are equally close, return the smallest number. """ if len(myList) == 0: return 9e10 pos = bisect_left(myList, myNumber) if pos == 0: return myList[0] ...
vfc_33621
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 6 1 1 3\n2\n5\n3\n1 1 5 6\n1 3 5 4\n3 3 5 3\n", "output": "7\n5\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 10 1 1 1\n1\n10\n1\n1 5 1 8\n", "output": "3\n", "type": ...
code_contests
verifiable_code
980_A. Links and Pearls
Solve the following coding problem using the programming language python: A necklace can be described as a string of links ('-') and pearls ('o'), with the last link or pearl connected to the first one. <image> You can remove a link or a pearl and insert it between two other existing links or pearls (or between a li...
```python s =input() dash = s.count('-') ring = s.count('o') k = min(dash,ring) m = max(dash,ring) if dash == 0 or ring==0: print('YES') else: if dash%ring==0: print('YES') else: print('NO') ```
vfc_33629
{ "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": "<span class=\"tex-font-style-tt\">-o---o-</span>\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "<span class=\"tex-font-style-tt\">-o-o--</span>", "output": "NO\n",...
code_contests
verifiable_code
9_A. Die Roll
Solve the following coding problem using the programming language python: Yakko, Wakko and Dot, world-famous animaniacs, decided to rest from acting in cartoons, and take a leave to travel a bit. Yakko dreamt to go to Pennsylvania, his Motherland and the Motherland of his ancestors. Wakko thought about Tasmania, its b...
```python x, y = input().split() x = int(x) y = int(y) z = 7 - max(x, y) ans = z/6 if ans == (1/6): print("1/6") elif ans == (2/6): print("1/3") elif ans == (3/6): print("1/2") elif ans == (4/6): print("2/3") elif ans == (5/6): print("5/6") else: print("1/1") ```
vfc_33633
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n", "output": "1/2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6\n", "output": "1/6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 4...
code_contests
verifiable_code
connecting-boxes-1
Solve the following coding problem using the programming language python: Problem: N boxes are arranged systematically in a circle and numbered from 1 to N in increasing order in clockwise direction. There will be Q queries asking you whether boxes i and j can be connected by a straight rod such that this rod does no...
```python #Salman Lari import sys n,q=map(int,sys.stdin.readline().split()) u=[] #Used up=[] #Used_ Pair for k in range(q): i,j=map(int,sys.stdin.readline().split()) if i in u or j in u: print "NO" continue flag=1 for l in range(len(up)): if i<up[l][1] and i>up[l][0]: ...
vfc_33641
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "616 4\n305 250\n558 43\n182 37\n297 138", "output": "YES\nYES\nNO\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "60 5\n60 28\n32 38\n31 44\n48 30\n14 34", "output": "YES\nYES\nY...
code_contests
verifiable_code
in-love-with-primes
Solve the following coding problem using the programming language python: Little Arjit is in love with Deepa. They have always thought of themselves as the ideal couple - the best, possible match they could've managed. (No kidding!) And like every other couple, they promised each other not to fight after every other f...
```python ##Goldbach's Conjecture t=int(raw_input()) for i in range(t): num=int(raw_input()) if num==2: print 'Arjit' else: print 'Deepa' ```
vfc_33649
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4\n8\n\nSAMPLE", "output": "Deepa\nDeepa\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n4\n8\n\nSANPLE", "output": "Deepa\nDeepa\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
matching-strings-4
Solve the following coding problem using the programming language python: Subodh'CS Department is writing a spell-checker system, and you have been tasked with writing a function to determine how closely two words resemble each other. The algorithm you are to use, albeit not a very good one, is to compare the two word...
```python import sys from sys import stdin def main(): T = int(stdin.readline().strip()) for i in xrange(T): a = stdin.readline().strip() b = stdin.readline().strip() diff = abs(len(a) - len(b)) if len(a) > len(b): a = a[:len(a) - diff] elif len(b) >len(a): ...
vfc_33653
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nTICK\nTOCK\nCAT\nDOG\nAPPLE\nAPPLES \nFANTASTIC\nANTASTIC\n\nSAMPLE", "output": "3\n0\n5\n0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
odd-mathematics-2
Solve the following coding problem using the programming language python: Mandark thinks he is better than Dexter. He challenges Dexter to find answer to a mathematics problem he created. Dexter accepts the challenge and decides to write a program for it to reduce manual calculations. The problem: Let f(x) be the gre...
```python T = int(raw_input()) while T > 0: num = int(raw_input()) sum = 0 while num!=0: if num%2==1: a=(num+1)/2 else: a=num/2 sum+=a*a num=num-a print sum T-=1 ```
vfc_33657
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n7\n777\n\nSAMPLE", "output": "21\n201537\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n777\n\nSAMPLE", "output": "2\n201537\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
rajat-and-his-fantasy-world-8
Solve the following coding problem using the programming language python: Rajat is a guy who always wants to live in a fantasy world. In his world, a deck consists of X cards, where X is a multiple of 4. There are four types of cards namely spade , heart , club and diamond with each type having values in range of [1,X...
```python T = input() while(T>0): xx,n,d,k = (raw_input().split()) x = int(xx) print '%.10f' % (1.0/x) T = T-1 ```
vfc_33661
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n8 8 2 heart\n52 1 10 spade \n\nSAMPLE", "output": "0.1250000000\n0.0192307692\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "97\n100026500 100010776 19170 diamond\n100024464 99996319 5...
code_contests
verifiable_code
showdown
Solve the following coding problem using the programming language python: Things are heated up between the Finance team and the Marketing team, and they decide to have one-on-one fifa matches to settle it once and for all. Jha, being an intern, won’t play (it’s a battle of legends, after all) and has been given one j...
```python n=input() f=raw_input() m=raw_input() f=f.split() m=m.split() for x in range(0,n): f[x]=int(f[x]) m[x]=int(m[x]) f=sorted(f, reverse=True) m=sorted(m, reverse=True) point=0 i=0 #print f #print m ##winnings while(i<len(f)): j=0 temp=f[i] while(j<len(m)): if(temp>m[j]): ...
vfc_33665
{ "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 5 3\n8 5 3\n\nSAMPLE", "output": "200\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 10 7 4\n15 3 8 7", "output": "250\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
the-silly-snail-3
Solve the following coding problem using the programming language python: Silly Snail was a very intelligent snail on Snail Island. In order to get eligible for marriage, he had to pass the Graduation Exam conducted by C.B.S.E ( Central Board of Snail Education ). Seeing the intelligence level of the Silly Snail, the ...
```python class Node: def __init__(self, data): self.data = data self.left = None self.right = None def traverse(root): print root.data, if root.left: traverse(root.left) if root.right: traverse(root.right) T = int(raw_input()) for t in range(T): num_nodes ...
vfc_33669
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n7\n1 7 3\n7 9 14\n3 10 5\n9 6 12\n14 8 4\n10 2 0\n5 11 0\n4\n1 11 13\n11 14 7\n14 5 9\n7 6 4\n\nSAMPLE", "output": "1 7 9 6 12 14 8 4 3 10 2 5 11 \n1 11 14 5 9 7 6 4 13", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
p00096 Sum of 4 Integers II
Solve the following coding problem using the programming language python: Enter a positive integer n of 4,000 or less, with a pair of integers a, b, c, d in the range 0-1000. a + b + c + d = n Create a program that outputs the number of combinations that satisfy the conditions. Input Given multiple datasets. E...
```python import sys for n in sys.stdin:print(sum(max(0,min(i,2002-i))*max(0,min(int(n)-i+2,2000-int(n)+i))for i in range(int(n)+2))) ```
vfc_33717
{ "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\n3\n35", "output": "10\n20\n8436", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0\n35", "output": "10\n1\n8436\n", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
p00228 Seven Segments
Solve the following coding problem using the programming language python: The screen that displays digital numbers that you often see on calculators is called a "7-segment display" because the digital numbers consist of seven parts (segments). The new product to be launched by Wakamatsu will incorporate a 7-segment d...
```python # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0228 """ import sys from sys import stdin input = stdin.readline LED_pattern = [ ##-gfedcba 0b0111111, # 0 0b0000110, # 1 0b1011011, # 2 0b1001111, ...
vfc_33721
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0\n5\n1\n1\n0\n-1", "output": "0111111\n1010010\n1101011\n0111111", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0\n5\n1\n1\n1\n-1", "output": "0111111\n1010010\n1101011\n000011...
code_contests
verifiable_code
p00606 Cleaning Robot
Solve the following coding problem using the programming language python: Dr. Asimov, a robotics researcher, loves to research, but hates houseworks and his house were really dirty. So, he has developed a cleaning robot. As shown in the following figure, his house has 9 rooms, where each room is identified by an alph...
```python # AOJ 1020: Cleaning Robot # Python3 2018.7.5 bal4u mv = ((-1,0),(0,1),(1,0),(0,-1)) while True: n = int(input()) if n == 0: break t1, t2, t3 = input().split() s, t, b = ord(t1)-ord('A'), ord(t2)-ord('A'), ord(t3)-ord('A') f = [[[0.0 for a in range(3)] for c in range(3)] for r in range(17)] f[0][s//3][...
vfc_33729
{ "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\nE A C\n1\nE B C\n2\nE A B\n0", "output": "0.00000000\n0.25000000\n0.06250000", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nD A C\n1\nE B C\n2\nE A B\n0", "output": "0.25000000\...
code_contests
verifiable_code
p00743 Discrete Speed
Solve the following coding problem using the programming language python: Consider car trips in a country where there is no friction. Cars in this country do not have engines. Once a car started to move at a speed, it keeps moving at the same speed. There are acceleration devices on some points on the road, where a ca...
```python from collections import defaultdict from heapq import heappop, heappush while True: n, m = map(int, input().split()) if n==0 and m==0: break s, g = map(int, input().split()) graph = defaultdict(list) for _ in range(m): x, y, d, c = map(int, input().split()) graph[x].append((y, d, c)) ...
vfc_33733
{ "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 0\n1 2\n5 4\n1 5\n1 2 1 1\n2 3 2 2\n3 4 2 2\n4 5 1 1\n6 6\n1 6\n1 2 2 1\n2 3 2 1\n3 6 2 1\n1 4 2 30\n4 5 3 30\n5 6 2 30\n6 7\n1 6\n1 2 1 30\n2 3 1 30\n3 1 1 30\n3 4 100 30\n4 5 1 30\n5 6 1 30\n6 4 1 30\n0 0", "output": "unr...
code_contests
verifiable_code
p00882 Hobby on Rails
Solve the following coding problem using the programming language python: ICPC (International Connecting Points Company) starts to sell a new railway toy. It consists of a toy tramcar and many rail units on square frames of the same size. There are four types of rail units, namely, straight (S), curve (C), left-switch...
vfc_33737
{ "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 2\nC L S R C\nC C S C C\n6 4\nC C C C C C\nS L R R C S\nS S S L C S\nC C C C C C\n6 6\nC L S S S C\nC C C S S C\nC C C S S C\nC L C S S C\nC C L S S C\nC S L S S C\n6 6\nC S S S S C\nS C S L C S\nS C S R C S\nS C L S C S\nS C R S...
code_contests
verifiable_code
p01013 Cone Cut
Solve the following coding problem using the programming language python: Problem In this problem, a straight line passing through a certain point X and a certain point Y in the three-dimensional space is written as a straight line XY. A cone and a point P inside the cone are given in three-dimensional space. Let po...
vfc_33741
{ "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": "0 0 10\n0 0 0 4\n0 0 1", "output": "91.769438 75.782170", "type": "stdin_stdout" }, { "fn_name": null, "input": "0 -1 10\n0 0 0 4\n0 0 1", "output": "92.747368 75.639914\n", "type": "stdi...
code_contests
verifiable_code
p01284 Erratic Sleep Habits
Solve the following coding problem using the programming language python: Peter is a person with erratic sleep habits. He goes to sleep at twelve o'lock every midnight. He gets up just after one hour of sleep on some days; he may even sleep for twenty-three hours on other days. His sleeping duration changes in a cycle...
```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 = 10**9+7 dd = [(0,-1),(1,0),(0,1),(-1,0)] ddn = [(0,-1),(1,-1),(1,0),(1,1),(0,1),(-1,-1),(-1,0),(-1,1)] def LI(): return [int(x) for x in ...
vfc_33749
{ "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": "2\n1 23\n3\n1 1\n2 1\n3 1\n0", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n0 23\n3\n1 1\n2 1\n3 1\n0", "output": "2\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p01454 Remodeling Plan for Neko-Nabe (tentative)
Solve the following coding problem using the programming language python: You have a lot of cats at home. Your daily routine is to take a picture of your cat in a clay pot and taking a nap (commonly known as a cat pot). The appearance of some cats curling up and sleeping together in a pot is really lovely. Each cat h...
vfc_33753
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 6 65\n30 98\n27 51\n4 74\n65 87\n49 19\n27 48\n43 7\n35 28\n43 69\n8 47\n64 75\n18 23\n54 29\n40 43", "output": "8", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01605 Replace
Solve the following coding problem using the programming language python: replace replace Problem Statement Given the string S. The following processing is performed in the order of Q pieces. * Replace all the characters c_i contained in S with the character string p_i at the same time. Finally, output (1-indexe...
vfc_33757
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "aaaa\n2 1 1\na .\na nothing", "output": ".", "type": "stdin_stdout" }, { "fn_name": null, "input": "original\n1 2 5\nx notchange", "output": "rigi", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
p01900 Mod!Mod!
Solve the following coding problem using the programming language python: C: Mod! Mod! story That's right! I'm looking for eyewitness testimony! A phantom thief has appeared in Aizu! Everyone's horse stick was stolen! Who is the culprit! ?? Unravel! Mod! Mod! Problem statement "Eyes" ... it's a miracle bud that sw...
```python # AOJ 2800: Mod!Mod! # Python3 2018.7.11 bal4u n = int(input()) a = list(map(int, input().split())) c = [0]*3 for i in a: c[i%3] += 1 if (c[1]|c[2]) == 0: ans = 1 else: ans, n = c[0], n-c[0] if n <= 3: ans += n else: t = max(-3, min(3, c[1]-c[2])) if t > 0: ans += 2*c[2]+t else: ans += 2*c[1]-t prin...
vfc_33765
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 268435456, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2 5 2 5 2 1", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n2 5 2 6 2 1", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
p02037 Tile
Solve the following coding problem using the programming language python: problem I want to put as many rectangular tiles as possible on a rectangular wall with a size of $ h $ in height and $ w $ in width, and a size of $ a $ in height and $ b $ in width. The following conditions must be met when attaching tiles. ...
```python h,w=map(int,input().split()) a,b=map(int,input().split()) high=(h//a)*a wide=(w//b)*b print(h*w-high*wide) ```
vfc_33769
{ "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 8\n2 2", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 8\n3 2", "output": "16\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 ...
code_contests
verifiable_code
p02181 AOR-String
Solve the following coding problem using the programming language python: problem Given $ N $ strings $ S_i $. Find the maximum number of "AOR" in the string obtained by connecting $ S_i $ in any order. output Output the maximum number of "AOR" contained in the character string obtained by connecting $ S_i $ in ...
vfc_33773
{ "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": "2\nAORA\nOR", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nAORA\nPR", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
p02323 Traveling Salesman Problem
Solve the following coding problem using the programming language python: For a given weighted directed graph G(V, E), find the distance of the shortest route that meets the following criteria: * It is a closed cycle where it ends at the same point it starts. * It visits each vertex exactly once. Constraints * 2 ≤ ...
```python v,e=[int(j) for j in input().split()] d=[[10**18]*v for i in range(v)] dp=[[-1]*v for i in range(1<<v)] for i in range(e): s,t,w=[int(j) for j in input().split()] d[s][t]=w def f(s,n,dp): if dp[s][n]>=0: return dp[s][n] if s==(1<<v)-1 and n==0: dp[s][n]=0 return 0 ...
vfc_33777
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n0 1 1\n1 2 1\n0 2 1", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 6\n0 1 2\n1 2 3\n1 3 9\n2 0 1\n2 3 6\n3 2 4", "output": "16", "type": "stdin_stdout" ...
code_contests
verifiable_code
p02468 Power
Solve the following coding problem using the programming language python: For given integers m and n, compute mn (mod 1,000,000,007). Here, A (mod M) is the remainder when A is divided by M. Constraints * 1 ≤ m ≤ 100 * 1 ≤ n ≤ 109 Input m n Two integers m and n are given in a line. Output Print mn (mod 1,000,...
```python # https://onlinejudge.u-aizu.ac.jp/courses/library/6/NTL/1/NTL_1_B # pythonのpowが優秀でMODまで取ることができる MOD = 10**9 + 7 a, b = list(map(int, input().split())) print(pow(a, b, MOD)) ```
vfc_33781
{ "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 3", "output": "8", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 8", "output": "390625", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1", ...
code_contests
verifiable_code
acball
Solve the following coding problem using the programming language python: Akhil has many balls of white and black colors. One day, he was playing with them. During the play, he arranged the balls into two rows both consisting of N number of balls. These two rows of balls are given to you in the form of strings X, Y. B...
```python testCases = input() for j in range(testCases): x = raw_input() y = raw_input() N = len(x) result= '' for i in range(N): if x[i]==y[i]: if x[i] == 'W': result=result + 'B' else: result=result + 'W' else: res...
vfc_33785
{ "difficulty": "1", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\nWBWB\nWBBB", "output": "BWBW\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
chefpath
Solve the following coding problem using the programming language python: Chef is stuck in a two dimensional maze having N rows and M columns. He needs to get out of the maze as soon as possible and arrive at the kitchen in order to serve his hungry customers. But, he can get out of the maze only if he is able to succ...
```python val=raw_input() t=int(val) for i in range(t): lens=list() stri=raw_input() lens=stri.split() n=int(lens[0]) m=int(lens[1]) if n%2==0 and m%2==1 and m!=1: print 'Yes' elif m%2==0 and n%2==1 and n!=1: print 'Yes' elif n%2==0 and m%2==0: print 'Yes' elif n%2==1 and m%2==1 and n!=1 and m!=1: pri...
vfc_33789
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2 2", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2 4", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1...
code_contests
verifiable_code
dmsg
Solve the following coding problem using the programming language python: Dilku and Bhopu live in Artland. Dilku loves Bhopu and he writes a message : “iloveyou” on paper and wishes to send it to Bhopu. As Dilku is busy making an artwork, he asks his friend Raj to send the message to Bhopu. However Raj has a conditio...
```python inp,ans,ph=set(raw_input()),['sad','happy'],set('iloveyou') print ans[len(inp.intersection(ph)) == len(ph)] ```
vfc_33793
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abcvleouioydef", "output": "happy", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
ism05
Solve the following coding problem using the programming language python: On a Planet where people are obssessed with Numbers, they have human definitions for relation among Numbers. In one such case, they have designated a father number to be a number formed by the sum of the child number's digits along with the chil...
```python t=raw_input() t=int(t) while t: t-=1 n=raw_input() n=int(n) for i in xrange(1,n): j=i sum=i while j: sum+=j%10 j/=10 if sum==n: j=-1 break if j!=-1: print "NONE" else: print i ```
vfc_33797
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n216\n121\n2005", "output": "198\nNONE\n1979", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n427\n121\n2005", "output": "416\nNONE\n1979\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
nokia
Solve the following coding problem using the programming language python: To protect people from evil, a long and tall wall was constructed a few years ago. But just a wall is not safe, there should also be soldiers on it, always keeping vigil. The wall is very long and connects the left and the right towers. The...
```python d=[None,(2,2),(5,5),(8,9),(12,14),(16,20),(20,27),(24,35),(29,44),(34,54),(39,65),(44,77),(49,90),(54,104),(59,119),(64,135),(70,152),(76,170),(82,189),(88,209),(94,230),(100,252),(106,275),(112,299),(118,324),(124,350),(130,377),(136,405),(142,434),(148,464),(154,495)] for i in range(input()): n,m=map(int,r...
vfc_33801
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 8\n3 9\n2 4\n5 25", "output": "0\n0\n-1\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n3 8\n3 9\n2 4\n8 25", "output": "0\n0\n-1\n-1\n", "type": "stdin_stdout" ...