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
767_E. Change-free
Solve the following coding problem using the programming language python: Student Arseny likes to plan his life for n days ahead. He visits a canteen every day and he has already decided what he will order in each of the following n days. Prices in the canteen do not change and that means Arseny will spend ci rubles d...
vfc_51505
{ "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": "5 42\n117 71 150 243 200\n1 1 1 1 1\n", "output": "79\n1 17\n1 0\n2 0\n2 43\n2 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 42\n117 71 150 243 200\n5 4 3 2 1\n", "output": "23...
code_contests
verifiable_code
838_A. Binary Blocks
Solve the following coding problem using the programming language python: You are given an image, that can be represented with a 2-d n by m grid of pixels. Each pixel of the image is either on or off, denoted by the characters "0" or "1", respectively. You would like to compress this image. You want to choose an integ...
```python from sys import stdin as fin def check(x, y): if x < 0 or y < 0: return 0 else: return table2[x][y] n, m = [int(x) for x in fin.readline().split()] table = fin.readlines() fin.close() table2 = [[None]*m for _ in range(n)] table2[0][0] = int(table[0][0]) for __ in range(1, m): t...
vfc_51517
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n00100\n10110\n11001\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n00100\n00110\n11001\n", "output": "4\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
858_D. Polycarp's phone book
Solve the following coding problem using the programming language python: There are n phone numbers in Polycarp's contacts on his phone. Each number is a 9-digit integer, starting with a digit different from 0. All the numbers are distinct. There is the latest version of Berdroid OS installed on Polycarp's phone. If ...
```python n = int(input()) a = [] d = {} for b in range(n): s = input() g = set() for i in range(len(s)): for k in range(i, len(s)): w = s[i:k + 1] if w in g: continue else: g.add(w) if w in d: d[w] += 1 ...
vfc_51521
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n123456789\n100000000\n100123456\n", "output": "7\n000\n01\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n123456789\n193456789\n134567819\n934567891\n", "output": "2\n193\n13\n...
code_contests
verifiable_code
883_J. Renovation
Solve the following coding problem using the programming language python: The mayor of the Berland city S sees the beauty differently than other city-dwellers. In particular, he does not understand at all, how antique houses can be nice-looking. So the mayor wants to demolish all ancient buildings in the city. The ci...
vfc_51525
{ "difficulty": "16", "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\n5 3 1\n5 2 9 1 10\n4 2 1 3 10\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n2 4\n6 2 3\n1 3 2\n", "output": "2\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
907_E. Party
Solve the following coding problem using the programming language python: Arseny likes to organize parties and invite people to it. However, not only friends come to his parties, but friends of his friends, friends of friends of his friends and so on. That's why some of Arseny's guests can be unknown to him. He decide...
vfc_51529
{ "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": "5 6\n1 2\n1 3\n2 3\n2 5\n3 4\n4 5\n", "output": "2\n2 3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
928_B. Chat
Solve the following coding problem using the programming language python: There are times you recall a good old friend and everything you've come through together. Luckily there are social networks — they store all your message history making it easy to know what you argued over 10 years ago. More formal, your messag...
```python def count_unic_mess(crt, display, array, n, result_arr): low_bound = 0 if crt - display < 0 else crt - display high_bound = n if crt + display + 1 > n else crt + display + 1 result = high_bound - low_bound if array[crt] == 0: result_arr.append(result) return result ref ...
vfc_51533
{ "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": "6 0\n0 1 1 2 3 2\n", "output": "1 2 2 3 3 3 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n0 1\n", "output": "2 2 \n", "type": "stdin_stdout" }, { "fn_name...
code_contests
verifiable_code
957_D. Riverside Curio
Solve the following coding problem using the programming language python: Arkady decides to observe a river for n consecutive days. The river's water level on each day is equal to some real value. Arkady goes to the riverside each day and makes a mark on the side of the channel at the height of the water level, but i...
```python import sys n = int(input()) a = [int(x) for x in input().split(' ')] maxm = 0 idx=0 ans=0 b=[0]*n for i in range(n): if a[i]>=maxm: maxm=a[i] idx=i for i in range(idx,n): b[i]=maxm+1 i=idx-1 while i>=0: b[i]=max(a[i]+1,b[i+1]-1) i-=1 for i in range(1,n): if b[i]<b[i-1]: ...
vfc_51537
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n0 1 1 2 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 1 2 1 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
982_D. Shark
Solve the following coding problem using the programming language python: For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations. Max is a young biologist. For n days he watched a specific shark, and no...
```python BigNum = 10 ** 10 n = int(input()) aa = [BigNum] + list(map(int, input().split(' '))) + [BigNum] appear = sorted([(v, i) for i, v in enumerate(aa)]) ans = -1 maxLocations = 0 intervals = [(i, i) for i in range(len(aa))] lengths = {} def incCount(val): global lengths lengths[val] = lengths.get(val,...
vfc_51541
{ "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": "8\n1 2 7 3 4 8 5 6\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n25 1 2 3 14 36\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": ...
code_contests
verifiable_code
a-game-6
Solve the following coding problem using the programming language python: Two sweet dogs, Bernard and Havanese, play the following game. There are P sticks, each of exactly Q meters in length. The dogs move in turns. For each move a dog chooses a stick and splits it into two or more equal parts each having integer len...
```python def divisors(n): from math import sqrt s = int(sqrt(n + 0.0)) for i in xrange(1, s + 1): if n % i == 0: yield i yield (n / i) def winning(p, q, s): if p % 2 == 0: return False for d in divisors(q): if d >= 2 and q / d >= s and not winning(d, q / d, s): return True return False def...
vfc_51545
{ "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 15 4\n4 9 5\n\nSAMPLE", "output": "Bernard\nHavanese", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 2 2\n2 1 1 \n100...
code_contests
verifiable_code
binomial-theorem
Solve the following coding problem using the programming language python: Description You are tasked to determine the kth term of the binomial expansion of the expression (x + y)^n. Input Format The input starts with an integer M > 0, followed by M pairs of integers k, n, where 1 ≤ k ≤ n+1 and 0 < n < 1000. Output...
```python import math def nCr(n,r): f = math.factorial return f(n) / f(r) / f(n-r) t = int(raw_input()) while t>0: a = raw_input().split(' ') a = [int(x) for x in a] c = nCr(a[1],a[0]-1) x = a[1]-a[0]+1 y = a[0]-1 if(c!=1): print c, if(x!=0): print "x^%d"%x, if(y==1): print "y" elif(y==0): ...
vfc_51549
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 10\n2 5\n4 30\n\nSAMPLE", "output": "x^10\n5 x^4 y\n4060 x^27 y^3", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1 10\n2 5\n4 30", "output": "x^10\n5 x^4 y\n4060 x^27 y^3", ...
code_contests
verifiable_code
covering-chessboard
Solve the following coding problem using the programming language python: You have an n by m grid. Each grid square has a certain value associated with it. This is given by the numbers vi,j. You can capture grid squares in two different ways. You can directly capture a grid square. This costs ci,j. You can indirectl...
```python import sys from collections import deque from collections import OrderedDict as dict INFINITE = 999999999999 global_edges = set() def solve(): r, c = map(int, sys.stdin.readline().split()) val = [] indirect = [] direct = [] for array in [val, indirect, direct]: for row in range(...
vfc_51553
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n9 0 3 2 4\n0 2 8 6 2\n5 3 4 1 3\n5 1 7 9 5\n2 4 1 2 4\n9 1 2 2 0\n9 1 8 9 7\n2 7 3 2 9\n9 1 9 8 2\n\nSAMPLE", "output": "13", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n20\n2429...
code_contests
verifiable_code
first-7
Solve the following coding problem using the programming language python: Daenerys Targaryen has set her eyes on The kingdom of Dorne. Dornishmen, known for their strong sense of national identity, have refused to surrender to the whims of Daenerys. Fearing the imminent attack on their kingdom and knowing their streng...
```python t = input(); for qq in range(t): n = input(); ans = 0.0; ans += ((5.0*n - 2) * (2.0*n - 1)) / (3.0 * n); print '%.6f' % ans ```
vfc_51557
{ "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\n2\n\nSAMPLE", "output": "1.000000\n4.000000", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n2\n\nSAMPLE", "output": "4.000000\n4.000000\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
its-awsome
Solve the following coding problem using the programming language python: Quan_Lank loves awsome numbers. Awsome numbers are the positive integers whose decimal representations contain only the awsome digits 4 and 7. For example, numbers 7, 74, 4 are awsome and 5, 137, 4467 are not. Unfortunately, not all numbers are ...
```python for i in range(int(raw_input())): s=raw_input() S=0 S=s.count("4")+s.count("7") if str(S).count("4")+str(S).count("7")==len(str(S)): print("YES") else: print("NO") ```
vfc_51561
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n40047\n4777\n\nSAMPLE", "output": "NO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n40047\n4777", "output": "NO\nYES\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
micro-and-array-1
Solve the following coding problem using the programming language python: Micro's friend Ravi gifted him a game called Array on his birthday. The game involves an array of distinct numbers of size N . The game follows 1-based indexing of array. Player has to perform Q operation on the array. The operation can be of fo...
```python import sys ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' array = [] class InvalidInput(Exception): pass def _read_operation(string): splits = map(int, string.split()) code = splits[0] if code == 0: ...
vfc_51565
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 4\n5 4 3 2 1\n1 4\n1 6\n0 3 7\n1 6\n\nSAMPLE", "output": "1\n-1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10\n34 37 28 16 44 36 43 50 22 13 \n1 41\n1 14\n0 1 27\n0 7 12\n0 8 ...
code_contests
verifiable_code
ozs-lucky-strings-3
Solve the following coding problem using the programming language python: Today Oz wants to play with Lucky strings. A string S is called Lucky string if there exists a non-negative integer m such that S is composed of m consecutive 'R' characters followed by m consecutive 'K' characters. Empty string is also a Lucky ...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' t = int(raw_input()) strings = [] for i in range(0,t): strings.append(raw_input()) for i in range(len(strings)): count = 0 start = 0 end = len(strings[i]) while(st...
vfc_51569
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nKRKRKKR\nKKKRRR\n\nSAMPLE", "output": "4\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nKRKRKKR\nKKKRRR\n\nSAMPLD", "output": "4\n0\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
ravis-trouble-3
Solve the following coding problem using the programming language python: Ravi is very tensed nowadays because of the design project. He has not even decided the topic yet. Micro feels very bad for Ravi, so to help Ravi take his mind off from design project for sometime he gave him a problem. He gave him two strings S...
```python try: t = int(input()) for i in xrange(t): s = list(raw_input()) p = list(raw_input()) i = 0 flag = 0 for j in s: if(p[i] == j): i += 1 if(i == len(p)): flag = 1 break if(...
vfc_51573
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nabcde\nade\nabc\npe\n\nSAMPLE", "output": "YES\nNO", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\nchfpbcevrllrlsodmhicuiaykptuxxabfiqikxdbiqvvjjyxqhbmrbkbsfxrdxtkfjsqgvtrlomwaltsuwf...
code_contests
verifiable_code
socks-puzzle
Solve the following coding problem using the programming language python: Tom is off to a school Annual Day and is searching for a matching pair of socks. His drawer is filled with socks, each pair of a different color. In its worst case scenario, how many socks (x) should Tom remove from his drawer until he finds a m...
```python n = input() while(n>0): n-=1 k = input() print k+1 ```
vfc_51577
{ "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\n2\n\nSAMPLE", "output": "2\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "277\n757398\n133393\n492078\n341193\n789282\n839521\n317835\n887487\n370144\n49082\n902037\n626803\n3262...
code_contests
verifiable_code
time-penalty
Solve the following coding problem using the programming language python: You are enthusiastically participating in Virtual Boot Camp-14 and want to seriously learn programming. To be a good programmer you not only need to solve a problem, but also need to solve it as quickly as possible. You are participating in th...
```python s=raw_input() d,h,m,w=s.split(' ') d=int(d) h=int(h) m=int(m) w=int(w) print (d-1)*24*60+h*60+m+w*20 ```
vfc_51581
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 0 0 100000000\n\nSAMPLE", "output": "2000005760\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 0 0 100000000", "output": "2000005760\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
p00114 Electro-Fly
Solve the following coding problem using the programming language python: A calculator scholar has discovered a strange life form called an electronic fly that lives in electronic space. While observing the behavior of the electronic flies, the electronic flies at the (x, y, z) point in this space then move to (x', y'...
```python def gcd(m, n): while n: m, n = n, m % n return m def lcm(m, n): return m // gcd(m, n) * n def f(a, m): x = a cnt = 1 while x != 1: x = x * a % m cnt += 1 return cnt while 1: a1, m1, a2, m2, a3, m3 = map(int, input().split()) if a1 == 0: bre...
vfc_51629
{ "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 5 3 7 6 13\n517 1024 746 6561 4303 3125\n0 0 0 0 0 0", "output": "12\n116640000", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 5 5 7 6 13\n517 1024 746 6561 4303 3125\n0 0 0 0 0 0", ...
code_contests
verifiable_code
p00247 Ice Maze
Solve the following coding problem using the programming language python: There is a rectangular maze with square squares lined up vertically and horizontally. In this maze, while moving to the adjacent squares in the north, south, east and west, the starting square S departs and the goal square G is aimed at. There a...
```python from collections import deque while True: x, y = map(int, input().split()) if x == 0:break mp = [list("#" * (x + 2))] + [list("#" + input() + "#") for _ in range(y)] + [list("#" * (x + 2))] ice_cnt = 0 ice_dic = [] vec = ((1, 0), (0, -1), (-1, 0), (0, 1)) def ice_search(...
vfc_51633
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n.X.S.\n.X#..\n.XX##\n.#XG.\n..X..\n7 3\nSXX.XXG\nX.#.#X.\nXXX.XX#\n4 4\nS...\nX.X.\nGX..\n...X\n10 10\n..XXXXX.XX\n.X.#.#X.XX\nSX.#X.X..X\n#X.##.X.XX\n..XXXX#.XX\n##.##.##XX\n....X.XX#X\n.##X..#X#X\n....XX#..X\n...#XXG..X\n0 0...
code_contests
verifiable_code
p00624 Dr. Nakamura's Lab.
Solve the following coding problem using the programming language python: Dr. Nakamura is a great inventor, and he is still working on a new invention that ordinary people cannot think of. Now he is inventing a new security system and container. The security system is a panel that identifies the person who rides on i...
vfc_51641
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n#####\n##@##\n#wc.#\n#Ew.#\n#####\n5 5\n#####\n##@.#\n#wc.#\n#E#.#\n#####\n3 6\n######\n#@.wE#\n######\n0 0", "output": "3\n5\n-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n\n...
code_contests
verifiable_code
p00768 ICPC Ranking
Solve the following coding problem using the programming language python: ICPC Ranking Your mission in this problem is to write a program which, given the submission log of an ICPC (International Collegiate Programming Contest), determines team rankings. The log is a sequence of records of program submission in the ...
```python # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1187&lang=jp """ import sys from sys import stdin input = stdin.readline class Team(object): def __init__(self, id): self.id = id self.correct = 0 # ??£?§£??° self.time = 0 # ...
vfc_51645
{ "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": "300 10 8 5\n50 5 2 1\n70 5 2 0\n75 1 1 0\n100 3 1 0\n150 3 2 0\n240 5 5 7\n50 1 1 0\n60 2 2 0\n70 2 3 0\n90 1 3 0\n120 3 5 0\n140 4 1 0\n150 2 4 1\n180 3 5 4\n15 2 2 1\n20 2 2 1\n25 2 2 0\n60 1 1 0\n120 5 5 4\n15 5 4 1\n20 5 4 0\n4...
code_contests
verifiable_code
p00899 City Merger
Solve the following coding problem using the programming language python: Recent improvements in information and communication technology have made it possible to provide municipal service to a wider area more quickly and with less costs. Stimulated by this, and probably for saving their not sufficient funds, mayors o...
```python #!usr/bin/env python3 from collections import defaultdict,deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def LS():return [list(x) for x in sys.stdin.readline(...
vfc_51649
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nFUKUOKA\nOKAYAMA\nYAMAGUCHI\n3\nFUKUOKA\nFUKUYAMA\nOKAYAMA\n2\nABCDE\nEDCBA\n4\nGA\nDEFG\nCDDE\nABCD\n2\nABCDE\nC\n14\nAAAAA\nBBBBB\nCCCCC\nDDDDD\nEEEEE\nFFFFF\nGGGGG\nHHHHH\nIIIII\nJJJJJ\nKKKKK\nLLLLL\nMMMMM\nNNNNN\n0", "...
code_contests
verifiable_code
p01164 Sort the Panels
Solve the following coding problem using the programming language python: There was an explorer Henry Nelson traveling all over the world. One day he reached an ancient building. He decided to enter this building for his interest, but its entrance seemed to be locked by a strange security system. There were some blac...
vfc_51657
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nWBWB\nBWBW\n8\nWWWWBWBB\nWWBBWBWW\n0", "output": "3\n9", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nWBWB\nBWBW\n8\nWWWWBWBB\nBWBBWWWW\n0", "output": "3\n14\n", "type": "...
code_contests
verifiable_code
p01302 Cave Explorer
Solve the following coding problem using the programming language python: Mike Smith is a man exploring caves all over the world. One day, he faced a scaring creature blocking his way. He got scared, but in short time he took his knife and then slashed it to attempt to kill it. Then they were split into parts, which ...
vfc_51661
{ "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\n0 1\n0 0\n5 0\n1 1\n5 2\n0 2\n7\n9999 9998\n0 0\n2 0\n3 1\n1 1\n10000 9999\n2 2\n0 2\n0", "output": "2.00\n2.2500000", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p01471 Fractional Knapsack
Solve the following coding problem using the programming language python: Problem statement Real variables $ x_1, x_2, ..., x_N $ satisfy the following conditions. 1. $ 0 \ leq x_i \ leq 1 $ ($ 1 \ leq i \ leq N $) 2. $ w_1x_1 + w_2x_2 + ... + w_Nx_N \ leq W $ At this time, find the maximum value that $ v_1x_1 + ...
```python import heapq N, W = [int(n) for n in input().split()] tmpw = 0 tmpv = 0 minheap = [] for i in range(N): w, v = [int(n) for n in input().split()] if(w < 0): tmpw += w tmpv += v w *= -1 v *= -1 if(v > 0): if w == 0: tmpv += v else: ...
vfc_51665
{ "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 1\n3 1", "output": "0.333333", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n-1 -3\n3 10", "output": "3.666667", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
p01631 English
Solve the following coding problem using the programming language python: Problem Statement Mr. Takatsuki, who is planning to participate in the Aizu training camp, is enthusiastic about studying and has been studying English recently. She tries to learn as many English words as possible by playing the following game...
```python def main(): n = int(input()) words = [] scores = [] for _ in range(n): word, score = input().split() words.append(word) scores.append(int(score)) mp = ["#" * 6] + ["#" + input() + "#" for _ in range(4)] + ["#" * 6] t = int(input()) def search(word): used = [[False] * 6 for _ i...
vfc_51669
{ "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\nAIZU 10\nLINER 6\nLINE 4\nALL 2\nAS 1\nCIEL 10\nASLA\nCILI\nIRZN\nELEU\n21", "output": "40", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\nAIZU 10\nLINER 6\nLINE 4\nALL 2\nAS 1\nCIEL 1...
code_contests
verifiable_code
p01783 LR
Solve the following coding problem using the programming language python: Example Input R?????,2?) Output 29 The input will be given via stdin and the output should be printed to stdout by your code. Now solve the problem by providing the code.
```python 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**13 mod = 10**9+7 dd = [(-1,0),(0,1),(1,0),(0,-1)] ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)] def LI(): return [int(x) for x in ...
vfc_51673
{ "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": "R?????,2?)", "output": "29", "type": "stdin_stdout" }, { "fn_name": null, "input": ")?2,?????R", "output": "invalid\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
p01918 Imagawayaki Man
Solve the following coding problem using the programming language python: C: Imagawayaki Man-Imagawayaki Man- story Imagawayaki Man is a hero of justice. The face is Imagawayaki with a diameter of 1 meter (mainly a food made by filling a dough made of wheat flour with a generous amount of bean paste, and it looks ro...
vfc_51677
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 267386880, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "", "output": "", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02056 Jam
Solve the following coding problem using the programming language python: E: Jam problem There are N cities in a country, numbered 1, \ 2, \ ..., \ N. These cities are connected in both directions by M roads, and the i-th road allows you to travel between the cities u_i and v_i in time t_i. Also, any two cities can ...
```python import sys from heapq import heappop as hpp, heappush as hp def dijkstra(N, s, Edge): inf = 10**18 dist = [inf] * N Q = [(0, s)] decided = set() for _ in range(N): while True: dn, vn = hpp(Q) if vn not in decided: decided.add(vn) ...
vfc_51681
{ "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": "4 4 3\n3 6 1 6\n1 1 2 3\n6 1 5 5\n1 2 1\n2 3 1\n1 3 1\n1 4 1", "output": "10\n8\n9", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02352 RMQ and RAQ
Solve the following coding problem using the programming language python: Write a program which manipulates a sequence $A$ = {$a_0, a_1, ..., a_{n-1}$} with the following operations: * $add(s, t, x)$ : add $x$ to $a_s, a_{s+1}, ..., a_t$. * $find(s, t)$ : report the minimum value in $a_s, a_{s+1}, ..., a_t$. Note ...
```python import sys, re from collections import deque, defaultdict, Counter from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2 from itertools import accumulate, permutations, combinations, product from operator import itemgetter, mul from copy import deepcopy from string import ascii_lowercase,...
vfc_51689
{ "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": "6 7\n0 1 3 1\n0 2 4 -2\n1 0 5\n1 0 1\n0 3 5 3\n1 3 4\n1 0 5", "output": "-2\n0\n1\n-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 7\n0 1 3 1\n0 2 4 -2\n1 0 5\n1 0 1\n0 1 5 3\n1 3 4\n1 ...
code_contests
verifiable_code
ashigift
Solve the following coding problem using the programming language python: Suraj, the Chief Prankster is back in action now and this time he has stolen the valentine's day gift given by Ashi (the love of Chef) to the Chef and ran away with it to Byteland. Byteland is a not a regular place like Chef's town. The safest w...
```python arr = [] def check(ppl): for i in range(0,len(arr)): if(arr[i][2]==-1):#magic dish ppl -= arr[i][1] elif(ppl>=arr[i][1]):#clan - applicable ppl += arr[i][2] return ppl def binary_search(low,high): while True: #print low,high if(low+1==high): break if (low==high): return low mid =...
vfc_51693
{ "difficulty": "3", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n10\n2 1 3 8 1\n0\n10\n2 1 3 8 5\n0\n10\n2 2 3 8 5\n3 1 2 1 4 3 2 9 1 1", "output": "5\n9\n6", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n10\n2 1 3 8 1\n0\n10\n2 1 3 8 5\n0\n10\n2 2 ...
code_contests
verifiable_code
cleanup
Solve the following coding problem using the programming language python: After a long and successful day of preparing food for the banquet, it is time to clean up. There is a list of n jobs to do before the kitchen can be closed for the night. These jobs are indexed from 1 to n. Most of the cooks have already left ...
```python t=int(raw_input()) for i in range(0,t): lis=map(int,raw_input().split()) lis1=map(int,raw_input().split()) l=[] for j in range(0,lis[0]): l.append(j+1) l=set(l) lis1=set(lis1) m=list(set(l)-set(lis1)) m.sort() if len(m)==0: print print elif len(m)==1: print m[0] print else: for j in ran...
vfc_51697
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n6 3\n2 4 1\n3 2\n3 2\n8 2\n3 8", "output": "3 6 \n5 \n1 \n\n1 4 6 \n2 5 7 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4 3\n2 4 1\n3 2\n3 2\n8 2\n3 8", "output": "3\n\n1\n\...
code_contests
verifiable_code
flow002
Solve the following coding problem using the programming language python: Write a program to find the remainder when two given numbers are divided. Input The first line contains an integer T, total number of test cases. Then follow T lines, each line contains two Integers A and B. Output Find remainder when A is d...
```python from sys import stdin, stdout t=int(input()) for i in range(t): A,B = map( int, stdin.readline().rstrip().split() ) c=A%B print(c) ```
vfc_51701
{ "difficulty": "1", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 \n1 2\n100 200\n10 40", "output": "1\n100\n10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 \n0 2\n100 200\n10 40", "output": "0\n100\n10\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
lecards
Solve the following coding problem using the programming language python: Little Elephant from the Zoo of Lviv likes cards. He has N cards, each of which has one of 1000 colors. The colors are numbered from 1 to 1000. Little Elephant and Big Hippo are playing the following game. At first Little Elephant takes some sub...
```python ''' Created on Feb 22, 2013 @author: anuvrat ''' import sys MODULATOR = 1000000007 class Memoize( object ): def __init__( self, f ): self.f, self.cache = f, {} def __call__( self, *args ): if not args in self.cache: self.cache[args] = self.f( *args ) return self.cache[args...
vfc_51705
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n1 2 3\n4\n1 1 3 2", "output": "4\n5", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3\n1 2 3\n4\n2 1 3 2", "output": "4\n5\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
polydifr
Solve the following coding problem using the programming language python: In this problem, you will be given a polynomial, you have to print what it becomes after differentiation. Following are the rules for differentiation: For a polynomial f(x), its differentiation is defined as f'(x). If a is a constant, then di...
```python # your code goes here from sys import stdin, stdout t = int(stdin.readline()) while t: t -= 1 n = int(stdin.readline()) d = [] for _ in xrange(n): a, p = map(int, stdin.readline().strip().split(' ')) d.append([p,a]) if n>1 and p == 0: d.pop() n -= 1 ans = "" for i in range(len(d)): if i < ...
vfc_51709
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n1 2\n3\n1 3\n1 1\n1 0", "output": "2x^1\n3x^2 + 1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n1 2\n3\n1 3\n1 1\n2 0", "output": "2x^1\n3x^2 + 1\n", "type": "stdin...
code_contests
verifiable_code
subgcd
Solve the following coding problem using the programming language python: Given an array A1,A2...AN, you have to print the size of the largest contiguous subarray such that GCD of all integers in that subarray is 1. Formally, For a subarray Ai,Ai+1...Aj where 1 ≤ i < j ≤ N to be valid: GCD(Ai,Ai+1...Aj) should be 1. Y...
```python """ http://www.codechef.com/COOK50/problems/SUBGCD """ from fractions import gcd def GCD(L) : """GCD of list L. length of list L is at least 2.""" ans = L[0] for i in xrange(1,len(L)) : ans = gcd(ans,L[i]) if ans == 1 : break return ans T = int(raw_input()) for _ in xrange(T) : N = int(raw_input())...
vfc_51713
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n7 2\n3\n2 2 4", "output": "2\n-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n7 2\n3\n3 2 4", "output": "2\n3\n", "type": "stdin_stdout" }, { "fn_n...
code_contests
verifiable_code
100_D. World of Mouth
Solve the following coding problem using the programming language python: There are a lot of rumors in the media these days. One day Aida decided to find out how rumors are made. She asked n of her friends to help her. They all formed a circle and Aida told the person to her right a piece of news which was just a sim...
vfc_51717
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "100\nCodeforces\nMMIODPC\n", "output": "Yes\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1033_A. King Escape
Solve the following coding problem using the programming language python: Alice and Bob are playing chess on a huge chessboard with dimensions n × n. Alice has a single piece left — a queen, located at (a_x, a_y), while Bob has only the king standing at (b_x, b_y). Alice thinks that as her queen is dominating the ches...
```python n = int(input()) bx, by = map(int, input().split()) ax, ay = map(int, input().split()) cx, cy = map(int, input().split()) ans = "NO" if(ax<bx and cx<bx): if(ay<by and cy<by): ans = "YES" elif(ay>by and cy>by): ans = "YES" elif(ax>bx and cx>bx): if(ay<by and cy<by): ans = "Y...
vfc_51721
{ "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": "8\n4 4\n2 3\n1 6\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n3 5\n1 2\n6 1\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
1055_F. Tree and XOR
Solve the following coding problem using the programming language python: You are given a connected undirected graph without cycles (that is, a tree) of n vertices, moreover, there is a non-negative integer written on every edge. Consider all pairs of vertices (v, u) (that is, there are exactly n^2 such pairs) and fo...
vfc_51725
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 6\n1 2\n1 3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n1 3\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1077_F2. Pictures with Kittens (hard version)
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is the constraints. Vova likes pictures with kittens. The news feed in the social network he uses can be represented as an array of n consecutive pictures (with kittens, of course). Vova likes ...
```python n, k, x = map(int, input().split()) a = [None] + list(map(int, input().split())) lo, hi = 0, 10 ** 9 * 5000 q = [None] * (n + 1) def get(mid): f, r = 0, 0 q[0] = 0, 0, 0 for i in range(1, n + 1): if q[r][2] == i - k - 1: r += 1 cur = q[r][0] + a[i] - mid, q[r][1] + 1, i w...
vfc_51729
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3 1\n1 100 1 1\n", "output": "100\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2 3\n5 1 3 10 1\n", "output": "18\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
1098_F. Ж-function
Solve the following coding problem using the programming language python: The length of the longest common prefix of two strings s=s_1 s_2 … s_n and t = t_1 t_2 … t_m is defined as the maximum k ≤ min(n, m) such that s_1 s_2 … s_k equals t_1 t_2 … t_k. Let's denote the longest common prefix of two strings s and t as l...
vfc_51733
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "bbaaa\n5\n2 4\n1 5\n1 5\n3 3\n1 2\n", "output": "3\n6\n6\n1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abbd\n4\n2 3\n1 3\n3 3\n1 4\n", "output": "3\n3\n1\n4\n", "type":...
code_contests
verifiable_code
1146_D. Frog Jumping
Solve the following coding problem using the programming language python: A frog is initially at position 0 on the number line. The frog has two positive integers a and b. From a position k, it can either jump to position k+a or k-b. Let f(x) be the number of distinct integers the frog can reach if it never jumps on ...
```python from math import gcd m,a,b = map(int,input().split()) g = gcd(a,b) vis = [0]*(a+b+1) vis[0] = 1 nvis = 1 count = 0 last = 0 t = 0 while True: #print(t, vis) if t >= b: #print('back') t -= b if vis[t]: break vis[t] = 1 nvis += 1 else: ...
vfc_51741
{ "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": "1000000000 1 2019\n", "output": "500000001500000001\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 5 3\n", "output": "19\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1167_D. Bicolored RBS
Solve the following coding problem using the programming language python: A string is called bracket sequence if it does not contain any characters other than "(" and ")". A bracket sequence is called regular (shortly, RBS) if it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" i...
```python # import math # import sys n = int(input().strip()) s = input().strip() a = 0 for i in range(n): if s[i]=='(': if a&1: print(0,end="") else: print(1,end="") a+=1 else: a-=1 if a&1: print(0,end="") else: print(1,end="") ```
vfc_51745
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n()\n", "output": "00\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n(())\n", "output": "0110\n", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
1185_G1. Playlist for Polycarp (easy version)
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is constraints. Polycarp loves to listen to music, so he never leaves the player, even on the way home from the university. Polycarp overcomes the distance from the university to the house in e...
```python import sys input = sys.stdin.readline n,T=map(int,input().split()) S=[list(map(int,input().split())) for i in range(n)] DP=[[0]*(4) for i in range(T+1)] mod=10**9+7 from functools import lru_cache @lru_cache(maxsize=None) def calc(used,recent,time): ANS=0 for i in range(n): #print(i,used) ...
vfc_51749
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 10\n5 3\n2 1\n3 2\n5 1\n", "output": "10", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1204_D2. Kirk and a Binary String (hard version)
Solve the following coding problem using the programming language python: The only difference between easy and hard versions is the length of the string. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems. Kirk has a binary string s (a string which consist...
```python pp = input() if len(pp) == 1: print('0') exit(0) z = 1 if pp[0]=='0' else 0 zc = [z] l = 1 lndl = [l] for p in pp[1:]: l = max(z + 1, l + (1 if p == '1' else 0)) z += 1 if p == '0' else 0 lndl.append(l) zc.append(z) lnda = lndl[-1] o = 1 if pp[-1]=='1' else 0 oc = [o] l = 1 lndr = [l] ...
vfc_51753
{ "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": "110\n", "output": "010", "type": "stdin_stdout" }, { "fn_name": null, "input": "0001111\n", "output": "0000000", "type": "stdin_stdout" }, { "fn_name": null, "input": ...
code_contests
verifiable_code
1221_C. Perfect Team
Solve the following coding problem using the programming language python: You may have already known that a standard ICPC team consists of exactly three members. The perfect team however has more restrictions. A student can have some specialization: coder or mathematician. She/he can have no specialization, but can't ...
```python q = int(input()) for i in range(q): k = 0 c, m, x = [int(s) for s in input().split()] if min(c, m, x) != x: print(min(c, m)) else: k += x z = (c + m - 2 * x) // 3 print(k + min(z, c - x, m - x)) ```
vfc_51757
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n1 1 1\n3 6 0\n0 0 0\n0 1 1\n10 1 10\n4 4 1\n", "output": "1\n3\n0\n0\n1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n1 1 1\n3 6 0\n0 0 0\n1 1 1\n10 1 10\n4 4 1\n", "outpu...
code_contests
verifiable_code
1246_F. Cursor Distance
Solve the following coding problem using the programming language python: There is a string s of lowercase English letters. A cursor is positioned on one of the characters. The cursor can be moved with the following operation: choose a letter c and a direction (left or right). The cursor is then moved to the closest o...
vfc_51761
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abacaba\n", "output": "58\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1266_D. Decreasing Debts
Solve the following coding problem using the programming language python: There are n people in this world, conveniently numbered 1 through n. They are using burles to buy goods and services. Occasionally, a person might not have enough currency to buy what he wants or needs, so he borrows money from someone else, wit...
```python # ---------------------------iye ha aam zindegi--------------------------------------------- import math import random import heapq, bisect import sys from collections import deque, defaultdict from fractions import Fraction import sys import threading from collections import defaultdict #threading.stack_size...
vfc_51765
{ "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\n1 2 10\n2 3 5\n", "output": "2\n1 2 5\n1 3 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 2 10\n2 3 15\n3 1 10\n", "output": "1\n2 3 5\n", "type": "stdin_stdout"...
code_contests
verifiable_code
1287_E2. Madhouse (Hard version)
Solve the following coding problem using the programming language python: This problem is different with easy version only by constraints on total answers length It is an interactive problem Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of le...
vfc_51769
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n\na\naa\na\n\ncb\nb\nc\n\nc", "output": "? 1 2\n? 2 2\n? 1 4\n! aacb\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "33\nuuuuuuutttttttmmmmmmmtttttthhhhhh\n", "output": "? 1 17\n?...
code_contests
verifiable_code
1331_B. Limericks
Solve the following coding problem using the programming language python: There was once young lass called Mary, Whose jokes were occasionally scary. On this April's Fool Fixed limerick rules Allowed her to trip the unwary. Can she fill all the lines To work at al...
```python n = int(input()) res = '' while n != 1: for i in range(2,n+1): if n % i == 0: res += str(i) n //= i break print(res) ```
vfc_51777
{ "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": "391\n", "output": "1723", "type": "stdin_stdout" }, { "fn_name": null, "input": "57\n", "output": "319", "type": "stdin_stdout" }, { "fn_name": null, "input": "35\n", ...
code_contests
verifiable_code
1350_F. Slime and Sequences (Easy Version)
Solve the following coding problem using the programming language python: Note that the only differences between easy and hard versions are the constraints on n and the time limit. You can make hacks only if all versions are solved. Slime is interested in sequences. He defined good positive integer sequences p of len...
vfc_51781
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n", "output": "10 7 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n", ...
code_contests
verifiable_code
1371_B. Magical Calendar
Solve the following coding problem using the programming language python: A competitive eater, Alice is scheduling some practices for an eating contest on a magical calendar. The calendar is unusual because a week contains not necessarily 7 days! In detail, she can choose any integer k which satisfies 1 ≤ k ≤ r, and ...
```python import sys; import math; def get_ints(): return map(int, sys.stdin.readline().strip().split()) def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_string(): return sys.stdin.readline().strip() t = int(input()); for test in range(t): n,k = get_ints(); ans=0; if(n<=...
vfc_51785
{ "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\n3 4\n3 2\n3 1\n13 7\n1010000 9999999\n", "output": "4\n3\n1\n28\n510049495001\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n632934461 955818012\n", "output": "200303015644213...
code_contests
verifiable_code
1418_D. Trash Problem
Solve the following coding problem using the programming language python: Vova decided to clean his room. The room can be represented as the coordinate axis OX. There are n piles of trash in the room, coordinate of the i-th pile is the integer p_i. All piles have different coordinates. Let's define a total cleanup as...
```python def get(t, l, r): l += len(t)//2 r += len(t)//2 res = -1 while l <= r: if l % 2 == 1: res = max(res, t[l]) if r % 2 == 0: res = max(res, t[r]) l = (l + 1) // 2 r = (r - 1) // 2 return res def change(t, x, v): x += len(t)//2 t[x] = v while x > 1: x //= 2 t[x] = max(t[x*2],t[x*2+1]) ...
vfc_51793
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 8\n5 1 2 4 3\n0 1\n0 2\n0 3\n0 4\n0 5\n1 1000000000\n1 1\n1 500000000\n", "output": "3\n2\n1\n0\n0\n0\n0\n0\n499999999\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n1 2 6 8 10\n1 ...
code_contests
verifiable_code
1461_A. String Generation
Solve the following coding problem using the programming language python: One fall day Joe got bored because he couldn't find himself something interesting to do. Marty suggested Joe to generate a string of length n to entertain him somehow. It didn't seem particularly difficult, but Joe's generated string had to foll...
```python for u in range(int(input())): n, k = map(int, input().split()) t = n-k s = "" for i in range(t): if(i%3==0): s += "a" if(i%3 == 1): s += "b" if(i%3 == 2): s += "c" if(t%3 == 0): s += "a"*...
vfc_51801
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3 2\n4 1\n", "output": "\naab\nacba\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n", "output": "abcabcabcab\nabca...
code_contests
verifiable_code
1486_B. Eastern Exhibition
Solve the following coding problem using the programming language python: You and your friends live in n houses. Each house is located on a 2D plane, in a point with integer coordinates. There might be different houses located in the same point. The mayor of the city is asking you for places for the building of the Ea...
```python import os DEBUG = 'DEBUG' in os.environ def debug(*args): if DEBUG: print(">", *args) def solution(houses): if len(houses) == 1: return 1 housesX = [] housesY = [] for house in houses: housesX.append(house[0]) housesY.append(house[1]) housesX.sort() housesY.sort() leftX =...
vfc_51805
{ "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": "6\n3\n0 0\n2 0\n1 2\n4\n1 0\n0 2\n2 3\n3 1\n4\n0 0\n0 1\n1 0\n1 1\n2\n0 0\n1 1\n2\n0 0\n2 0\n2\n0 0\n0 0\n", "output": "\n1\n4\n4\n4\n3\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2...
code_contests
verifiable_code
1510_B. Button Lock
Solve the following coding problem using the programming language python: You are standing in front of the room with great treasures. The only thing stopping you is the door with a push-button combination lock. This lock has d buttons with digits from 0 to d - 1. Whenever you press a button, it stays pushed down. You ...
vfc_51809
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n001\n111\n101\n011\n", "output": "\n6\n2 0 R 1 2 0 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n10\n11\n", "output": "\n2\n0 1 \n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
163_C. Conveyor
Solve the following coding problem using the programming language python: Anton came to a chocolate factory. There he found a working conveyor and decided to run on it from the beginning to the end. The conveyor is a looped belt with a total length of 2l meters, of which l meters are located on the surface and are ar...
```python import sys range = xrange input = raw_input n,L,v1,v2 = [int(x) for x in input().split()] L2 = 2 * L L3 = 3 * L n2 = 2 * n l = L/(1.0 + v1*1.0/v2) A = [int(x) for x in input().split()] B = [a + L3 for a in A] A += [a + L2 for a in A] A += B x = 0.0 i = 0 j = 0 count = [0.0]*(n + 1) while j < n2 and A[j]...
vfc_51817
{ "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 3 1 2\n2 5\n", "output": "0.333333333333333\n0.666666666666667\n0.000000000000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1 1\n0\n", "output": "0.750000000000000\n0.250...
code_contests
verifiable_code
183_D. T-shirt
Solve the following coding problem using the programming language python: You are going to work in Codeforces as an intern in a team of n engineers, numbered 1 through n. You want to give each engineer a souvenir: a T-shirt from your country (T-shirts are highly desirable in Codeforces). Unfortunately you don't know t...
vfc_51821
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 5, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 4\n100 200 300 400\n", "output": "0.400000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n500 500\n500 500\n", "output": "1.500000000\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
207_B3. Military Trainings
Solve the following coding problem using the programming language python: The Smart Beaver from ABBYY started cooperating with the Ministry of Defence. Now they train soldiers to move armoured columns. The training involves testing a new type of tanks that can transmit information. To test the new type of tanks, the t...
vfc_51825
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2\n2\n2\n2\n2\n", "output": " 10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2\n1\n1\n", "output": " ...
code_contests
verifiable_code
256_D. Liars and Serge
Solve the following coding problem using the programming language python: There are n people, sitting in a line at the table. For each person we know that he always tells either the truth or lies. Little Serge asked them: how many of you always tell the truth? Each of the people at the table knows everything (who is ...
```python a=[[0],[2,1],[32,30,80,109],[6824,59808,147224,415870,1757896,1897056,4898872,7593125],[776830421,290516100,746623577,293783147,33900006,735127505,565460332,428982705,472062098,161873957,117354594,515619293,578944191,312106242,569389279,391464593],[261086313,584837659,683961846,468868529,211593382,736955478,2...
vfc_51833
{ "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": "1 1\n", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
27_D. Ring Road 2
Solve the following coding problem using the programming language python: It is well known that Berland has n cities, which form the Silver ring — cities i and i + 1 (1 ≤ i < n) are connected by a road, as well as the cities n and 1. The goverment have decided to build m new roads. The list of the roads to build was p...
```python n, m = map(int, input().split()) road = [[] for i in range(m)] for i in range(m): road[i] = [i] + list(map(int, input().split())) + ['NONE'] for i in road: if i[2] < i[1]: i[1], i[2] = i[2], i[1] i[1], i[2] = i[1] - 1, i[2] - 1 participation = [[] for i in range(m)] for i in range(len(roa...
vfc_51837
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n1 3\n2 4\n", "output": "io\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 3\n1 3\n3 5\n5 1\n", "output": "iii\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
302_C. Yaroslav and Sequence
Solve the following coding problem using the programming language python: Yaroslav has an array, consisting of (2·n - 1) integers. In a single operation Yaroslav can change the sign of exactly n elements in the array. In other words, in one operation Yaroslav can select exactly n array elements, and multiply each of t...
```python n = int(input()) a = list(map(int, input().split())) c = list(map(abs, a)) if len(list(filter(lambda x: x < 0, a))) & 1 and n + 1 & 1: print(sum(c) - 2 * min(c)) else: print(sum(c)) # Made By Mostafa_Khaled ```
vfc_51841
{ "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\n50 50 50\n", "output": "150\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n-1 -100 -1\n", "output": "100\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
329_D. The Evil Temple and the Moving Rocks
Solve the following coding problem using the programming language python: Important: All possible tests are in the pretest, so you shouldn't hack on this problem. So, if you passed pretests, you will also pass the system test. You are an adventurer currently journeying inside an evil temple. After defeating a couple ...
```python r, c = map(int, input().split()) if r == 3: print('>vv') print('^<.') print('^.<') print('1 3') elif r == 5: print('>...v') print('v.<..') print('..^..') print('>....') print('..^.<') print('1 1') elif r == 100: for i in range(25): print('>'*50+'.>'*24+'.v')...
vfc_51845
{ "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\n", "output": ">vv\n^<.\n^.<\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n", "output": ">...v\nv.<..\n..^..\n>....\n..^.<\n1 1\n", "type": "stdin_stdout" }...
code_contests
verifiable_code
350_B. Resort
Solve the following coding problem using the programming language python: Valera's finally decided to go on holiday! He packed up and headed for a ski resort. Valera's fancied a ski trip but he soon realized that he could get lost in this new place. Somebody gave him a useful hint: the resort has n objects (we will c...
```python import sys def Z(s): return int(s)-1 n=int(sys.stdin.readline()) Hotels=[False]*(n) Rep=[0]*(n+1) Chains=[] Type=list(map(int,sys.stdin.readline().split())) for i in range(n): if(Type[i]==1): Hotels[i]=True A=list(map(Z,sys.stdin.readline().split())) for item in A: Rep[item]+=1 for i ...
vfc_51849
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n0 0 1 0 1\n0 1 2 2 4\n", "output": "2\n4 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 0 0 0 1\n0 1 2 3 4\n", "output": "5\n1 2 3 4 5\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
374_C. Inna and Dima
Solve the following coding problem using the programming language python: Inna and Dima bought a table of size n × m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A". Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that...
```python import sys from functools import lru_cache, cmp_to_key from heapq import merge, heapify, heappop, heappush # from math import * from collections import defaultdict as dd, deque, Counter as C from itertools import combinations as comb, permutations as perm from bisect import bisect_left as bl, bisect_right as ...
vfc_51853
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\nDIMAD\nDIMAI\nDIMAM\nDDMAA\nAAMID\n", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 2\nDI\n", "output": "Poor Dima!\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
396_E. On Iteration of One Well-Known Function
Solve the following coding problem using the programming language python: Of course, many of you can calculate φ(n) — the number of positive integers that are less than or equal to n, that are coprime with n. But what if we need to calculate φ(φ(...φ(n))), where function φ is taken k times and n is given in the canoni...
vfc_51857
{ "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": "1\n7 1\n2\n", "output": "1\n2 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n2 100000000000000000\n10000000000000000\n", "output": "1\n2 90000000000000000\n", "type": "st...
code_contests
verifiable_code
41_A. Translation
Solve the following coding problem using the programming language python: The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely....
```python #41A print("YES" if input()==input()[::-1] else "NO") ```
vfc_51861
{ "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": "code\nedoc\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "abb\naba\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "i...
code_contests
verifiable_code
445_D. DZY Loves FFT
Solve the following coding problem using the programming language python: DZY loves Fast Fourier Transformation, and he enjoys using it. Fast Fourier Transformation is an algorithm used to calculate convolution. Specifically, if a, b and c are sequences with length n, which are indexed from 0 to n - 1, and <image> ...
vfc_51865
{ "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": "3 1 1\n", "output": "1\n3\n2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
467_E. Alex and Complicated Task
Solve the following coding problem using the programming language python: After you have read all the problems, probably, you think Alex is genius person. That's true! One day he came up with the following task. Given a sequence of integer numbers a1, a2, ..., an. You are to find a longest sequence b1, b2, ..., b4m, ...
vfc_51869
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 5 3 5\n", "output": "4\n3 5 3 5 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n35 1 2 1 2 35 100 200 100 200\n", "output": "8\n1 2 1 2 100 200 100 200 ", "type": "stdi...
code_contests
verifiable_code
48_H. Black and White
Solve the following coding problem using the programming language python: According to the legends the king of Berland Berl I was noted for his love of beauty and order. One day he ordered to tile the palace hall's floor where balls and receptions used to take place with black and white tiles according to a regular ge...
vfc_51873
{ "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": "2 2\n0 0 4\n", "output": "#/\\#\n/..\\\n./\\.\n/##\\\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
513_G3. Inversions problem
Solve the following coding problem using the programming language python: You are given a permutation of n numbers p1, p2, ..., pn. We perform k operations of the following type: choose uniformly at random two indices l and r (l ≤ r) and reverse the order of the elements pl, pl + 1, ..., pr. Your task is to find the e...
```python f = lambda: map(int, input().split()) n, k = f() p = list(f()) r = range u = [l * l + l >> 1 for l in r(n + 1)] v = [(i, j) for i in r(n) for j in r(i + 1, n)] t = [[p[i] > p[j] for j in r(n)] for i in r(n)] a = [[0] * n for i in r(n)] b = [[0] * n for i in r(n)] c = [[0] * n for i in r(n)] for l in r(min(...
vfc_51877
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n1 3 2\n", "output": "1.458333333333\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n1 2 3\n", "output": "0.833333333333\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
540_A. Combination Lock
Solve the following coding problem using the programming language python: Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he wants to put there the treasures that he's earned fair and square, he has to open the lock. <image> The combination lock is represented by n r...
```python n=int(input()) s=input() s=list(s) s1=input() s1=list(s1) c=0 for i in range(n): if abs(int(s[i])-int(s1[i]))>5: c+=10-abs(int(s[i])-int(s1[i])) else: c+=abs(int(s[i])-int(s1[i])) print(c) ```
vfc_51881
{ "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\n82195\n64723\n", "output": "13\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n9\n2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
568_B. Symmetric and Transitive
Solve the following coding problem using the programming language python: Little Johnny has recently learned about set theory. Now he is studying binary relations. You've probably heard the term "equivalence relation". These relations are very important in many areas of mathematics. For example, the equality of the tw...
```python from math import factorial cat = [1, 1] p = 10**9 + 7 n = int(input()) ans = 0 fac = [1] mat = [[0 for i in range(n + 1)] for j in range(n + 1)] mat[0][0] = 1 for i in range(1, n + 1): mat[i][0] = mat[i - 1][i - 1] for j in range(i): mat[i][j + 1] = (mat[i][j] + mat[i - 1][j]) % p print(mat...
vfc_51885
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", ...
code_contests
verifiable_code
589_i
Solve the following coding problem using the programming language python: Today Berland holds a lottery with a prize — a huge sum of money! There are k persons, who attend the lottery. Each of them will receive a unique integer from 1 to k. The organizers bought n balls to organize the lottery, each of them is painted...
```python n,m=raw_input().split() n=int(n);m=int(m) a=[int(i) for i in raw_input().split()] div = n/m res=0 s=set(a) for i in s: if (a.count(i) > div): res+=a.count(i)-div print res ```
vfc_51889
{ "difficulty": "15", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8 4\n1 2 1 1 1 4 1 4", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n2 1 2 2", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
611_B. New Year and Old Property
Solve the following coding problem using the programming language python: The year 2015 is almost over. Limak is a little polar bear. He has recently learnt about the binary system. He noticed that the passing year has exactly one zero in its representation in the binary system — 201510 = 111110111112. Note that he d...
```python a,b=map(int,input().split()) lis=list() s='' for i in range(1,69): s=s+'1' for j in range(1,len(s)): temp=s[:j]+'0'+s[j+1:] lis.append(int(temp,2)) c=0 for x in lis: if x>=a and x<=b: c+=1 print(c) ```
vfc_51893
{ "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": "72057594000000000 72057595000000000\n", "output": "26\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100 105\n", "output": "0\n", "type": "stdin_stdout" }, { "fn...
code_contests
verifiable_code
630_Q. Pyramids
Solve the following coding problem using the programming language python: IT City administration has no rest because of the fame of the Pyramids in Egypt. There is a project of construction of pyramid complex near the city in the place called Emerald Walley. The distinction of the complex is that its pyramids will be ...
```python a,a1,a2 = map(int,input().split()) print(a**3 / 6 / 2**.5 + a1**3 * 2**.5 / 6 + a2**3 * (5 + 5 ** .5) / 24) ```
vfc_51897
{ "difficulty": "24", "memory_limit": null, "memory_limit_bytes": 64000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 5 3\n", "output": "38.546168065708805\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 999 1000\n", "output": "536498692.9990839\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
65_B. Harry Potter and the History of Magic
Solve the following coding problem using the programming language python: The History of Magic is perhaps the most boring subject in the Hogwarts school of Witchcraft and Wizardry. Harry Potter is usually asleep during history lessons, and his magical quill writes the lectures for him. Professor Binns, the history of ...
```python n,a,ans,last=int(input()),[],[],1000 for i in range(n):a.append(input()) for d in a: minoverd=10000000 for i in range(10): for j in range(i==0,5): t=int(d[:j]+str(i)+d[j+1:]) if minoverd>t>=last:minoverd=t ans.append(str(minoverd)) if minoverd>2011:break ...
vfc_51901
{ "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\n1999\n5055\n2000\n", "output": "No solution", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n9999\n2000\n3000\n3011\n", "output": "1999\n2000\n2000\n2011\n", "type": "stdin_...
code_contests
verifiable_code
683_A. The Check of the Point
Solve the following coding problem using the programming language python: On the coordinate plane there is a square with sides parallel to the coordinate axes. The length of the square side is equal to a. The lower left corner of the square coincides with the point (0, 0) (the point of the origin). The upper right cor...
vfc_51905
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4 4\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
705_E. Black Widow
Solve the following coding problem using the programming language python: Natalia Romanova is trying to test something on the new gun S.H.I.E.L.D gave her. In order to determine the result of the test, she needs to find the number of answers to a certain equation. The equation is of form: <image> Where <image> repre...
vfc_51909
{ "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": "8 10\n1 -5\n2 4 -6\n2 -2 -6\n2 -7 9\n2 10 -1\n2 3 -1\n2 -8 9\n2 5 8\n", "output": "544\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\n2 1 1\n2 -3 3\n", "output": "4\n", "...
code_contests
verifiable_code
749_C. Voting
Solve the following coding problem using the programming language python: There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote. Each of the employees belongs to one of two fractions:...
```python n=int(input()) s=input() t=[] d=r=0 for i in s: t.append(i) while len(t)!=1: for i in range(len(t)): if t[i]=="R" and d==0: r+=1 elif t[i]=="D" and r==0: d+=1 elif t[i]=="R" and d!=0: d-=1 t[i]=0 else: r-=1 ...
vfc_51917
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\nDDRRR\n", "output": "D\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\nDDRRRR\n", "output": "R\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
817_D. Imbalanced Array
Solve the following coding problem using the programming language python: You are given an array a consisting of n elements. The imbalance value of some subsegment of this array is the difference between the maximum and minimum element from this segment. The imbalance value of the array is the sum of imbalance values ...
```python ##################################### import atexit, io, sys, collections, math, heapq, fractions,copy, os from io import BytesIO, IOBase ##################################### python 3 START BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.f...
vfc_51929
{ "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 4 1\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "30\n2 2 9 1 10 8 3 3 1 4 6 10 2 2 1 4 1 1 1 1 1 2 4 7 6 7 5 10 8 9\n", "output": "3147\n", "type": "st...
code_contests
verifiable_code
842_D. Vitya and Strange Lesson
Solve the following coding problem using the programming language python: Today at the lesson Vitya learned a very interesting function — mex. Mex of a sequence of numbers is the minimum non-negative number that is not present in the sequence as element. For example, mex([4, 33, 0, 1, 1, 5]) = 2 and mex([1, 2, 3]) = 0...
```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_51933
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\n1 3\n1\n3\n", "output": "1\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 4\n0 1 5 6 7\n1\n1\n4\n5\n", "output": "2\n2\n0\n2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
863_D. Yet Another Array Queries Problem
Solve the following coding problem using the programming language python: You are given an array a of size n, and q queries to it. There are queries of two types: * 1 li ri — perform a cyclic shift of the segment [li, ri] to the right. That is, for every x such that li ≤ x < ri new value of ax + 1 becomes equal to...
```python import sys import math from collections import defaultdict,deque def get(ind ,arr): n = len(arr) for i in range(n): t,l,r = arr[i] if t == 1: if l <= ind <= r: if ind == l: ind = r else: ind -= 1 continue if t == 2: if l <=ind <= r: ind = (r - ind + l) continue retur...
vfc_51937
{ "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 3 5\n1 2 3 4 5 6\n2 1 3\n2 3 6\n1 1 6\n2 2 1 5 3\n", "output": "3 3 1 5 2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 1\n474812122\n2 1 1\n1\n", "output": "474812122 ", ...
code_contests
verifiable_code
889_A. Petya and Catacombs
Solve the following coding problem using the programming language python: A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really experienced, his exploration is just walking through the catacombs. Catacombs consist of several rooms and bidirectional passages between some pairs ...
```python n = int(input()) notes = [int(x) for x in input().split()] greatest_cave = 1 visits = {0: 1} for time, curr in enumerate(notes, start=1): if curr in visits and visits[curr] != -1: visits[time] = visits[curr] visits[curr] = -1 else: greatest_cave += 1 visits[time] = grea...
vfc_51941
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n0 0\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n0 1 0 1 3\n", "output": "3\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
960_A. Check the string
Solve the following coding problem using the programming language python: A has a string consisting of some number of lowercase English letters 'a'. He gives it to his friend B who appends some number of letters 'b' to the end of this string. Since both A and B like the characters 'a' and 'b', they have made sure that...
```python s = input()+"d" d = [] r,l = 0,0 e = set() while r!=len(s): if s[r]!=s[l]: d.append(s[l:r]) l=r r+=1 if d[-1][0]!="c" or d[0][0]!="a" or d[1][0]!="b" or len(d)!=3: print("NO") elif len(d[-1])!=len(d[0]) and len(d[-1])!=len(d[1]): print("NO") else: print("YES") ```
vfc_51953
{ "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": "aabc\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "aaabccc\n", "output": "YES\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
alice-bob-and-xor
Solve the following coding problem using the programming language python: Bob has just learned bit manipulation and is very excited about it. He goes to his friend Alice to show off his skills who is new to programming, and thus Bob challenges Alice to solve the following problem. Given two positive integers L and R, ...
```python def f(a): res=[] res.append(a) res.append(1) res.append(a+1) res.append(0) return res[a%4] if __name__=='__main__': T = int(raw_input()) for i in range(T): M,N=map(int,raw_input().split()) print f(N)^f(M-1) ```
vfc_51961
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2 3\n3 5\n\nSAMPLE", "output": "1\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000\n778 1778\n83 1083\n324 1324\n56 1056\n80 1080\n682 1682\n643 1643\n245 1245\n140 1140\n573 157...
code_contests
verifiable_code
bytelandian-encoding
Solve the following coding problem using the programming language python: In Byteland,people don't use standard e-mail services like gmail,yahoo-mail etc.Instead they have their own e-mail service know as Bytemail.In Bytemail, encryption of e-mails is done using a special algorithm known as Bytecryption algorithm.It w...
```python #Sudhanshu Patel if __name__=='__main__': t=int(raw_input()) for i in range(t): st=raw_input() st=st.lower() r='' while(st!=''): l=len(st) if l%2!=0: r=r+st[l/2] st=st[0:l/2]+st[(l/2)+1:] else: ...
vfc_51965
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\naaaaaaaa\nadappadsdsdas\n\nSAMPLE", "output": "aaaaaaaa\ndasdppsadadas\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\naaaaaaaa\nadappadsdsdas\n\nELPMAS", "output": "aaaaaaaa\n...
code_contests
verifiable_code
death-the-multiverse-and-nothing
Solve the following coding problem using the programming language python: You'll be given an array A of N integers as input. For each element of the array A[i], print A[i]-1. Input: There will be N+1 iines of input each consisting of a single integer. Integer in first line denotes N For the following N lines the int...
```python totalCases = int(raw_input()) for i in xrange(totalCases): print int(raw_input()) -1 ```
vfc_51969
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n2\n6\n\nSAMPLE", "output": "1\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n1\n2\n3\n4\n5\n6\n7\n8\n9", "output": "0\n1\n2\n3\n4\n5\n6\n7\n8\n", "type": "stdin_stdou...
code_contests
verifiable_code
game-of-riches
Solve the following coding problem using the programming language python: There is a special game played in remote part of Rajasthan, where all people assemble with their all wealth and try to earn more wealth on the account of their current wealth. Suppose you are also a part of this game. The game is like, there a...
```python for i in range(input()): s=raw_input().split(" ") t=raw_input().split(" ") l=[]; for k in t: z=str(k)+".0" l.append(int(float(z))) l.sort() l.reverse() c=l.index(int(t[0])) l2=[] l2.append(int(t[0])) cd=c while True: cd=cd-int(s[1]) i...
vfc_51973
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n12 11\n1640 3997 4133 4282 3130 3938 4628 1138 4474 4534 2218 1293 \n1 1\n2491 \n15 6\n1242 3342 4797 4252 811 4955 76 4298 3753 1104 168 17 2364 1207 4764\n\nSAMPLE", "output": "0\n0\n1\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
khicchar-and-khicchar
Solve the following coding problem using the programming language python: Pradeep Khicchar , a very influential ,dominating ,smart and definitely an intelligent guy, is very eager to get his patent on his first project which he is about to complete. Only assistance that he needs from his friend Amit Chahal from IT d...
```python def gcd(a,b): if b==0: return a else: return gcd(b,a%b) for _ in xrange(input()): l=[] for i in xrange(5): l.append(int(raw_input())) print gcd(l[0],gcd(l[1],gcd(l[2],gcd(l[3],l[4])))) ```
vfc_51977
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n10\n20\n30\n10\n5\n\nSAMPLE", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n86738277921516\n192791744\n138880864\n40232\n20116\n0542668987214528\n37569168\n15881112\n218...
code_contests
verifiable_code
modified-power-set
Solve the following coding problem using the programming language python: As we all know that power sets of any set are formed by taking i elements (where i is from 1 to n) and then random shuffling them like this power set of {1,2,3} are {EMPTY SET},{1},{2},{3},{1,2}{1,3}{2,3}{1,2,3} . Now we have a MODIfied POWER S...
```python from collections import OrderedDict t=input() while t: t-=1 s=raw_input() l= list(OrderedDict.fromkeys(s)) l=len(l) print (l*(l+1))/2 ```
vfc_51981
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nabcde\nabc\n\nSAMPLE", "output": "15\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\nabcde\nabc\n\nSAMPEL", "output": "15\n6\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
panda-and-xor-2
Solve the following coding problem using the programming language python: Panda had recently learnt about Bit manipulation and logic gates,now he is very excited about it.One day he came across a very interesting question: Given two numbers,xor them and then in resulting number find the number of set bits.If number of...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' T=long(raw_input('')) while(T>0): [A,B]=map(long,raw_input().split(' ')) C=A^B count=0 while C>0: C-=C&(-1*C) count+=1 if(count&1): print "NO" else: print "YES" ...
vfc_51985
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n6 5\n10 11\n\nSAMPLE", "output": "YES\nNO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "400\n89383 30886\n92777 36915\n47793 38335\n85386 60492\n16649 41421\n2362 90027\n68690 20059\n...
code_contests
verifiable_code
round-it
Solve the following coding problem using the programming language python: To round an integer a, it is customary to round to some multiple of a power of 10, and you will round it accordingly. This time, rules have changed. Given an int n and an int b, round n to the nearest value which is a multiple of b. If n is exa...
```python T = int(raw_input()) for i in range(T): n,b = (raw_input()).split() n,b = int(n), int(b) div_a = (n//b)*b div_b = div_a + b if(n - div_a == div_b - n) : print div_b elif(n - div_a < div_b - n) : print div_a else : print div_b ```
vfc_51989
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5 10\n100 3\n\nSAMPLE", "output": "10\n99\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n5 10\n101 3\n\nSAMPLE", "output": "10\n102\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
string-and-primes
Solve the following coding problem using the programming language python: Dark completed with studying Strings last night and trying to solve the problem of primes numbers from last three months but did not succeed every time he preferred to ask your help and same goes this time. He likes to play a game with PRIMES A...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name ''' def isPrime(n): for i in range(2,n): if n% i == 0: return 1 return 0 n = int(raw_input()) i=0 str = [] out = [] while i < n: str.append(raw_in...
vfc_51993
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nMEHTA\nMehta\nHELLO\nhello\n\nSAMPLE", "output": "MEHTA\nMht\nHELL\nhllo\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
unusual-blocks-6
Solve the following coding problem using the programming language python: Admin is provided with infinite supply of Unusual blocks and now he has being assigned the task to fill the rectangular floor(completely) of Area A with one of these Unusual blocks. The Property of Unusual Blocks being :- Property 1 :- Both o...
```python def s(n): x=[] c=0 for i in xrange(1,int(n**.5)+1): if n%i==0: if i%2==0 and (n/i)%2==0: if i==n/i: c+=1 else: c+=1 return c for _ in xrange(input()): n=input() print s(n) ```
vfc_51997
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n4\n\nSAMPLE", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n7\n\nSAMPLE", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "...
code_contests
verifiable_code
p00011 Drawing Lots
Solve the following coding problem using the programming language python: Let's play Amidakuji. In the following example, there are five vertical lines and four horizontal lines. The horizontal lines can intersect (jump across) the vertical lines. <image> In the starting points (top of the figure), numbers are ass...
```python w = int(input()) + 1 l = [i for i in range(w)] n = int(input()) for i in range(n): a, b = map(int, input().split(",")) l[a], l[b] = l[b], l[a] for i in range(1, w): print(l[i]) ```
vfc_52041
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n4\n2,4\n3,5\n1,2\n3,4", "output": "4\n1\n2\n5\n3", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00276 Formation
Solve the following coding problem using the programming language python: At Akabe High School, which is a programmer training school, the roles of competition programmers in team battles are divided into the following three types. C: | Coder | I am familiar with the language and code. --- | --- | --- A: | Algorithm |...
```python # -*- coding: utf-8 -*- """ http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0281 """ import sys from sys import stdin input = stdin.readline def solve(c, a, n): CCA, CCC, CAN = 0, 0, 0 CAN = min(c, a, n) # CAN??????????????° c -= CAN a -= CAN if a > 0 and ...
vfc_52049
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n3 0 0\n1 1 1\n9 4 1\n0 1 2", "output": "1\n1\n4\n0", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p00654 Squid Multiplication
Solve the following coding problem using the programming language python: Problem H: Squid Multiplication Squid Eiko loves mathematics. Especially she loves to think about integer. One day, Eiko found a math problem from a website. "A sequence b ={ai + aj | i < j } is generated from a sequence a ={a0 , ... , an | ai...
```python # AOJ 1069: Squid Multiplication # Python3 2018.7.10 bal4u def gcd(a, b): while b != 0: r = a % b a, b = b, r return a while True: n = int(input()) if n == 0: break even, odd = [], [] b = list(map(int, input().split())) for i in b: if i & 1: odd.append(i) else: even.append(i) even.sort() od...
vfc_52057
{ "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": "3\n6 10 14 15 21 35\n2\n30 42 35\n0", "output": "2\n3 5 7\n6\n5 7", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n6 10 14 15 27 35\n2\n30 42 35\n0", "output": "2\n3 5 7\n6\n5 7\n", ...
code_contests
verifiable_code
p00799 Pump up Batteries
Solve the following coding problem using the programming language python: Bill is a boss of security guards. He has pride in that his men put on wearable computers on their duty. At the same time, it is his headache that capacities of commercially available batteries are far too small to support those computers all da...
vfc_52061
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 25\n3 1 2 1 4 1 0\n1 1 0\n2 1 3 2 0\n\n4 1000\n80 20 80 20 80 20 80 20 0\n80\n20\n0\n80 20 90\n10 80\n20\n0\n90 10\n0\n\n0 0", "output": "10\n110", "type": "stdin_stdout" }, { "fn_name": null, "inp...