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
530_D. Set subtraction
Solve the following coding problem using the programming language python: You are given a starting set consisting of all integers from 1 to 1000, inclusive. You are also given several sets which need to be subtracted from the starting set (i.e., each number which is in at least one of these sets needs to be removed fr...
vfc_32717
{ "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\n1 900\n902 999\n", "output": "2 901 1000\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
556_D. Case of Fugitive
Solve the following coding problem using the programming language python: Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water. The only dry land there is an archipelago of n narrow islands located in a row. For more com...
```python #!/usr/bin/env python # 556D_fug.py - Codeforces.com 556D Fug quiz # # Copyright (C) 2015 Sergey # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # http://www.apache.org/licenses...
vfc_32721
{ "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": "4 4\n1 4\n7 8\n9 10\n12 14\n4 5 3 8\n", "output": "Yes\n2 3 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n11 14\n17 18\n2 9\n", "output": "No", "type": "stdin_stdout" ...
code_contests
verifiable_code
604_B. More Cowbell
Solve the following coding problem using the programming language python: Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into k boxes of a fixed size. In order to keep his collection safe ...
```python n, k = map(int, input().split()) a = [int(s) for s in input().split()] p = n - k q = 2*k - n if n < k: q = n p = 0 ma = 0 for i in range ((n - q) // 2): ma = max((a[i] + a[n - q - i - 1]), ma) ma2 = 0 for i in range(n - q, n): ma2 = max(a[i], ma2) print(max(ma,ma2)) ```
vfc_32729
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n2 3 5 9\n", "output": "9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1\n2 5\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
626_E. Simple Skewness
Solve the following coding problem using the programming language python: Define the simple skewness of a collection of numbers to be the collection's mean minus its median. You are given a list of n (not necessarily distinct) integers. Find the non-empty subset (with repetition) with the maximum simple skewness. The...
```python from itertools import accumulate from fractions import Fraction n = int(input()) A = [int(x) for x in input().split()] A.sort() B = list(accumulate([0] + A)) def condition(i, z): return (2*z - 1)*(A[i-z] + A[-z]) > 2*(B[i+1] - B[i-z+1] + B[-1] - B[-z]) def average(i, z): return Fraction((B[i+1] - B[i...
vfc_32733
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2\n", "output": "1\n 1 \n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
650_C. Table Compression
Solve the following coding problem using the programming language python: Little Petya is now fond of data compression algorithms. He has already studied gz, bz, zip algorithms and many others. Inspired by the new knowledge, Petya is now developing the new compression algorithm which he wants to name dis. Petya decid...
vfc_32737
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n20 10 30\n50 40 30\n50 60 70\n90 80 70\n", "output": "2 1 3\n5 4 3\n5 6 7\n9 8 7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n1 2\n3 4\n", "output": "1 2\n2 3\n", ...
code_contests
verifiable_code
676_A. Nicholas and Permutation
Solve the following coding problem using the programming language python: Nicholas has an array a that contains n distinct integers from 1 to n. In other words, Nicholas has a permutation of size n. Nicholas want the minimum element (integer 1) and the maximum element (integer n) to be as far as possible from each ot...
```python n = int(input()) a = list(map(int, input().split())) maxLocate = a.index(n) minLocate = a.index(1) distanceMax = len(a) - 1 - a.index(n) distanceMin = len(a) - 1 - a.index(1) print(max(maxLocate, minLocate, distanceMax, distanceMin)) ```
vfc_32741
{ "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": "6\n6 5 4 3 2 1\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n1 6 5 3 4 7 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
69_A. Young Physicist
Solve the following coding problem using the programming language python: A guy named Vasya attends the final grade of a high school. One day Vasya decided to watch a match of his favorite hockey team. And, as the boy loves hockey very much, even more than physics, he forgot to do the homework. Specifically, he forgot...
```python sum1,sum2,sum3 = 0,0,0 n = int(input()) while n: n-=1 l = list(map(int, input().split())) sum1 += l[0] sum2 += l[1] sum3 += l[2] if sum1==0 and sum2 ==0 and sum3 ==0: print("YES") else: print("NO") ```
vfc_32745
{ "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\n3 -1 7\n-5 2 -4\n2 -1 -3\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4 1 7\n-2 4 -1\n1 -5 -3\n", "output": "NO\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
720_D. Slalom
Solve the following coding problem using the programming language python: Little girl Masha likes winter sports, today she's planning to take part in slalom skiing. The track is represented as a grid composed of n × m squares. There are rectangular obstacles at the track, composed of grid squares. Masha must get from...
vfc_32749
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5 3\n2 2 2 3\n4 2 5 2\n4 4 4 4\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
742_A. Arpa’s hard exam and Mehrdad’s naive cheat
Solve the following coding problem using the programming language python: There exists an island called Arpa’s land, some beautiful girls live there, as ugly ones do. Mehrdad wants to become minister of Arpa’s land. Arpa has prepared an exam. Exam has only one question, given n, print the last digit of 1378n. <imag...
```python n = int(input()) if n == 0: print(1) if n % 4 == 0 and n!= 0 : print(6) if n % 4 == 1: print(8) if n % 4 == 2: print(4) if n % 4 == 3: print(2) ```
vfc_32753
{ "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\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "12\n", ...
code_contests
verifiable_code
789_B. Masha and geometric depression
Solve the following coding problem using the programming language python: Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise. You are given geometric progression b defined by two integers b1 and q. Remind that a geometric progression is a sequence of integers b1, b2, b3, ...
```python b1,q,l,m = map(int,input().split()) a = set(map(int,input().split())) if q==0: if 0 in a: if b1 in a: print(0) elif abs(b1)<=l: print(1) else: print(0) elif abs(b1)<=l: print("inf") else: print(0) elif q==1: if abs(b1)...
vfc_32761
{ "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": "123 1 2143435 4\n123 11 -5453 141245\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 2 30 4\n6 14 25 48\n", "output": "3\n", "type": "stdin_stdout" } ]...
code_contests
verifiable_code
80_D. Falling Anvils
Solve the following coding problem using the programming language python: For some reason in many American cartoons anvils fall from time to time onto heroes' heads. Of course, safes, wardrobes, cruisers, planes fall sometimes too... But anvils do so most of all. Anvils come in different sizes and shapes. Quite often...
```python t = int(input()) for i in range(t): a, b = map(int, input().split()) denom = a * b * 2 if denom == 0: if b == 0: print('1') else: print('0.5') continue if a > 4 * b: nom = 2 * b * b else: nom = (b - a / 4.0 + b) / 2.0 * a ...
vfc_32765
{ "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\n4 2\n1 2\n", "output": "0.6250000000\n0.5312500000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "90\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n1 2\n2 2\n3 2\n4 2\n5 2\n6 2\n7 2\n8 ...
code_contests
verifiable_code
835_B. The number on the board
Solve the following coding problem using the programming language python: Some natural number was written on the board. Its sum of digits was not less than k. But you were distracted a bit, and someone changed this number to n, replacing some digits with others. It's known that the length of the number didn't change. ...
```python """ Author : Arif Ahmad Date : Algo : Difficulty : """ from sys import stdin, stdout def main(): k = int(stdin.readline().strip()) n = stdin.readline().strip() n = sorted(n) total = 0 for c in n: d = ord(c) - 48 total += d ans = 0 for c in n: if total >= k: break d = ord(c) - 4...
vfc_32769
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n11\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n99\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n...
code_contests
verifiable_code
855_E. Salazar Slytherin's Locket
Solve the following coding problem using the programming language python: Harry came to know from Dumbledore that Salazar Slytherin's locket is a horcrux. This locket was present earlier at 12 Grimmauld Place, the home of Sirius Black's mother. It was stolen from there and is now present in the Ministry of Magic in th...
```python import sys range = xrange input = raw_input def int2base(n, base): if n == 0: return [0] A = [] while n: n,r = divmod(n, base) A.append(r) return A big = 10**18 DP = [[[0]*(1 << b) for _ in range(b>1 and len(int2base(big, b)) + 1)] for b in range(11)] DP0 = [[[0]*(...
vfc_32773
{ "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": "2\n2 1 100\n5 1 100\n", "output": "21\n4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
87_C. Interesting Game
Solve the following coding problem using the programming language python: Two best friends Serozha and Gena play a game. Initially there is one pile consisting of n stones on the table. During one move one pile should be taken and divided into an arbitrary number of piles consisting of a1 > a2 > ... > ak > 0 stones. ...
```python import math from collections import Counter n = int(input()) g = [0 for i in range(n + 1)] prefix_xor = g.copy() def in_range(d, k): if (2 * k - d * d + d) % (2 * d) != 0: return -1 x = (2 * k - d * d + d) / (2 * d) return int(x) if x > 0 else -1 def mex(arr): counter = Counter() ...
vfc_32777
{ "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\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n", "output": "8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", ...
code_contests
verifiable_code
903_E. Swapping Characters
Solve the following coding problem using the programming language python: We had a string s consisting of n lowercase Latin letters. We made k copies of this string, thus obtaining k identical strings s1, s2, ..., sk. After that, in each of these strings we swapped exactly two characters (the characters we swapped cou...
```python import collections def swapCharacters(strings, k, n): """ Time: O(n^2 * k) Space: O(1) """ if k == 1: s0 = list(strings[0]) s0[0], s0[1] = s0[1], s0[0] return ''.join(s0) # Initial check for validity freq = collections.Counter(strings[0]) canSame = (max(freq.values()) >= 2) # could swap two o...
vfc_32781
{ "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 4\nabcd\ndcba\nacbd\ndbca\nzzzz\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 4\nabac\ncaab\nacba\n", "output": "acab\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
925_F. Parametric Circulation
Solve the following coding problem using the programming language python: Vova has recently learned what a circulaton in a graph is. Recall the definition: let G = (V, E) be a directed graph. A circulation f is such a collection of non-negative real numbers f_e (e ∈ E), that for each vertex v ∈ V the following conserv...
vfc_32785
{ "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 3\n1 2 0 3 -4 7\n2 3 -2 5 1 6\n3 1 0 4 0 4\n", "output": "0.2500000000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 2\n1 2 1 4 2 4\n1 2 3 4 4 4\n", "output": "0\n", "typ...
code_contests
verifiable_code
954_G. Castle Defense
Solve the following coding problem using the programming language python: Today you are going to lead a group of elven archers to defend the castle that is attacked by an army of angry orcs. Three sides of the castle are protected by impassable mountains and the remaining side is occupied by a long wall that is split ...
```python import sys border = 1 << 30 def build(x=0): res = [0, 0] i = 0 while x and i < 30: if x & 1: res[1] += (1 << i) x >>= 1 i += 1 i = 0 while x: if x & 1: res[0] += (1 << i) x >>= 1 i += 1 return res n, r, k =...
vfc_32789
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 500000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2 0\n1 2 3 4\n", "output": "6\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1-7
Solve the following coding problem using the programming language python: Raj and simran are in love. but thakur baldev singh doesnt want them to be together. But baldev Singh cares for her daughter too. He wants raj to prove his love for her daughter and family. So Baldev singh being a great lover of strings sets ...
```python t = input(); while(t > 0): s = raw_input().split(); print s[0].count(s[1]); t -= 1; ```
vfc_32797
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nabca a\nbbb c\n\nSAMPLE", "output": "2\n0", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\nwlrbbmqbhcdarzowkkyhiddqscdxrjmowfrxsjybldbefsarcbynecdyggxxpklorellnmpapqfwkhopkmcoqhnwnkue...
code_contests
verifiable_code
bhavesh-and-colors
Solve the following coding problem using the programming language python: ** Problem Statement is Updated ** Xenny had N colors with him, all arranged in a straight line. He was interested in picking up a particular subarray of colors. A pre-set is a set that contains all subarrays of colors that start from the firs...
```python def returnAnswer(a): n = len(a) length = 0 arr = [] for i in range(0, n): arr.append(0) i = 1 while(i<n): if(a[i] == a[length]): length += 1 arr[i] = length i += 1 else: if(length != 0): length = arr[length-1] else: arr[i] = 0 i +=...
vfc_32801
{ "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\n1 2 1 2\n\nSAMPLE", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n4\n1 2 1 2\n\nTAMPLE", "output": "2\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
costly-phone-number-december-easy-easy-medium
Solve the following coding problem using the programming language python: A cell phone company is trying out its new model of cell phone. Here's how its structure is: The keypad has 11 buttons corresponding to digits from 0 to 9 and one additional button called Add. After pressing any button from 0 to 9, the corresp...
```python for _ in range(input()): total_cost = map(int, raw_input().split()) for i in range(10): for j in range(1, 10): for k in range(j, 10): total_cost[(j + k) % 10] = min(total_cost[(j + k) % 10], total_cost[j]+total_cost[k]) input() Result = 0 in...
vfc_32805
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 2 2 3 2 1 1 2 3 3 \n3\n171\n3 2 3 1 1 1 1 3 1 2 \n2\n16\n3 3 3 1 3 1 1 2 3 2 \n2\n43\n\nSAMPLE", "output": "6\n3\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 2 2 1 1 1 2 3 ...
code_contests
verifiable_code
find-the-ring
Solve the following coding problem using the programming language python: There is a new magician in town. His trick is known as "Find the Ring". He puts 3 glasses at 3 spots on the table, labeling them as 0, 1 and 2. Now, he hides a ring under one of the glasses. The glasses are opaque and placed upside down, so tha...
```python n=int(raw_input()) while n: t=(raw_input()) t=t.split(' ') t[0]=int(t[0]) t[1]=int(t[1]) if t[1]==0: print t[0] elif t[1]%2==0: if t[0]==1: print "1" else : print '0' else : if t[0]==1: print "0" else : print '1' n-=1 ```
vfc_32809
{ "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 1\n0 1\n2 2\n\nSAMPLE", "output": "0\n1\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\n0 5619\n0 3827\n2 1722\n2 909\n2 7032\n0 832\n1 7280\n2 5860\n0 1391\n2 5694\n0 109\n2 ...
code_contests
verifiable_code
integers-only-allowed
Solve the following coding problem using the programming language python: You have a polygon described by coordinates of its vertices. Can you find how many points with integer coordinates lay strictly inside it? Input The first line contains an integer N - number of vertices. Next N lines contain 2 space-separated i...
```python from fractions import gcd n = input() vertices = [] for i in range(n): vertices.append(map(int, raw_input().split())) vertices.append(vertices[0]) b = 0 for i in range(n): dx = abs(vertices[i + 1][0] - vertices[i][0]) dy = abs(vertices[i + 1][1] - vertices[i][1]) b += gcd(dx, dy) b = max(0, b...
vfc_32813
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n0 0\n0 2\n2 2\n2 0\n\nSAMPLE", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n-728000 477000\n667000 186000\n667000 151000\n-595000 -679000\n-298000 -132000", "outp...
code_contests
verifiable_code
maxi-and-dumpy
Solve the following coding problem using the programming language python: Maxi and Dumpy are playing with numbers. Maxi throws a ball up in the air and shouts a random number. Dumpy notes down this number on a piece of paper. They repeat this N times. But Dumpy just found out that there are many repetitive numbers in ...
```python n=input() num=raw_input() num=num.split(" ") num=map(int, num) dum=[] for i in num: if(i not in dum): dum.append(i) for i in dum: print(i), ```
vfc_32817
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n2 1 5 3 2 5\n\nSAMPLE", "output": "2 1 5 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10000\n5617 9114 7223 8085 7207 6665 9614 9508 8351 8579 7638 9973 6310 9941 7237 6074 9460 65...
code_contests
verifiable_code
one-and-zero
Solve the following coding problem using the programming language python: Little Raju recently learnt about binary numbers. After spending some time with it, he decided to count in how many ways he can make N digit numbers that is formed by ones and zeroes. But zeroes can not be next to each other. Help him finding in...
```python ''' # Read input from stdin and provide input before running code name = raw_input('What is your name?\n') print 'Hi, %s.' % name print 'Hello World!' ''' t=int(input()) for i in range(t): n=int(input()) if n==1: print(2) else: a=1 b=2 for i in range(2,n+1): a,b=b,a+b print(b) ```
vfc_32821
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n3\n7\n\nSAMPLE", "output": "5\n34\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2\n8\n12\n16\n34", "output": "3\n55\n377\n2584\n14930352\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
random-delimma-4
Solve the following coding problem using the programming language python: Manu is a very bright student and had learned c++ Programming on her own.She has covered loops and if/else.She is a very inquisitive child and always love to discover new things.Same applies to programming she learns various syntax.One day while...
```python t=input() while t>0: k,n=map(int,raw_input().split()) if k>n: print "1.000000000" else: f=1.0 for i in range(n,n-k,-1): f=(f*i)/n f=1-f print "%.9f"%(f) t-=1 ```
vfc_32825
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 10\n7 6\n\nSAMPLE", "output": "0.496000000\n1.000000000\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
simple-task
Solve the following coding problem using the programming language python: Given an array A. Delete an single element from the array such that sum of the differences of adjacent elements should be minimum. For more clarification Sum for an array A having N element is defined as : abs( A[0] - A[1] ) + abs( A[1] - ...
```python t=int(raw_input()) for qq in xrange(t): n=int(raw_input()) l=map(int,raw_input().split()) s=sum(l) minval=9999999999999999999 ret=0 if n==1: print 0 continue for i in xrange(n): tmp=0 cp=s if i>0 and i<n-1: tmp = abs(l[i]-l[i-1]) + abs(l[i]-l[i+1]) cp-=tmp cp+=abs(l[i+1]-l[i-1]) i...
vfc_32829
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n5\n1 10 20 40 60\n\nSAMPLE", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1\n100\n2\n100 1\n2\n1 2\n3\n1 100 2\n3\n1 2 3\n3\n1 5 6\n3\n1 7 8\n3\n8 7 1\n3\n7 8 1\n3\n7 1...
code_contests
verifiable_code
the-substring-problem-1
Solve the following coding problem using the programming language python: You have been given a set of N strings S1, S2, .... SN. Consider any non-empty string S (S need not belong to the given set of N strings). Suppose S occurs (as a substring) in K out of the N given strings in the set. Your job is to choose S such...
```python t=input() for i in xrange(t): n=input() l=[] for k in xrange(n): s=raw_input() l.append(s) q="abcdefghijklmnopqrstuvwxyz" o=[0 for i in xrange(26)] for x in xrange(n): for y in xrange(26): if q[y] in l[x]: o[y]+=1 z=max(o) for j in xrange(26): if o[j]==z: print q[j] break ```
vfc_32833
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1\nshades\n\nSAMPLE", "output": "a\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n20\nengagfwhxalwaaucqieavxyutinrmtd\nnxhehybspixeykxillunrhswxskfrzkljeigxwaumrlfqlrrjlngxcyddtunll...
code_contests
verifiable_code
p00101 Aizu PR
Solve the following coding problem using the programming language python: An English booklet has been created for publicizing Aizu to the world. When you read it carefully, you found a misnomer (an error in writing) on the last name of Masayuki Hoshina, the lord of the Aizu domain. The booklet says "Hoshino" not "Hosh...
```python [print(input().replace("Hoshino","Hoshina")) for i in range(int(input()))] ```
vfc_32881
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\nHoshino\nHashino\nMasayuki Hoshino was the grandson of Ieyasu Tokugawa.", "output": "Hoshina\nHashino\nMasayuki Hoshina was the grandson of Ieyasu Tokugawa.", "type": "stdin_stdout" }, { "fn_name": null...
code_contests
verifiable_code
p00234 Aizu Buried Treasure
Solve the following coding problem using the programming language python: Aizu has an ancient legend of buried treasure. You have finally found the place where the buried treasure is buried. Since we know the depth of the buried treasure and the condition of the strata to be dug, we can reach the buried treasure at th...
```python import sys sys.setrecursionlimit(1000000) INF = 10 ** 20 def update_state(state, newx): tmp = list(state) tmp[newx] = 1 return tuple(tmp) def get_co(x, y): dc = do = 0 score = mp[y][x] if score < 0: dc = -score else: do = score return dc, do def minimum_cost(x, y, state, ox, goal, d...
vfc_32885
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 3\n100 10 10\n-100 -20 -100\n-100 -20 -100\n-100 -20 -100\n3 3\n100 10 10\n-100 -20 -100\n-100 -20 -20\n-100 -60 -20\n3 3\n100 10 3\n-100 -20 -100\n-20 -20 -20\n-20 -100 -20\n3 3\n100 3 3\n-100 -20 -30\n-100 -20 2\n-100 -20 -20\n...
code_contests
verifiable_code
p00611 Building Water Ways
Solve the following coding problem using the programming language python: In ancient times, Romans constructed numerous water ways to supply water to cities and industrial sites. These water ways were amongst the greatest engineering feats of the ancient world. These water ways contributed to social infrastructures w...
vfc_32893
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 8\n########\n#P....*#\n########\n10 10\n##########\n#P.......#\n#..#*....#\n#..#*.#.*#\n#.....#*.#\n#*.......#\n#..##....#\n#...#.P..#\n#P......P#\n##########\n0 0", "output": "5\n14", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
p00749 Off Balance
Solve the following coding problem using the programming language python: You are working for an administration office of the International Center for Picassonian Cubism (ICPC), which plans to build a new art gallery for young artists. The center is organizing an architectural design competition to find the best desig...
```python while True: w, h = map(int, input().split()) if w == 0: break mp = [[0] + list(input()) + [0] for _ in range(h)] mp.insert(0, [0] * (w + 2)) mp.append([0] * (w + 2)) for y in range(1, h + 1): for x in range(1, w + 1): if mp[y][x] == ".": mp[y][x] = 0 else: mp[y...
vfc_32897
{ "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 5\n..33\n..33\n2222\n..1.\n.111\n5 7\n....1\n.1..1\n.1..1\n11..1\n.2222\n..111\n...1.\n3 6\n.3.\n233\n23.\n22.\n.11\n.11\n4 3\n2222\n..11\n..11\n4 5\n.3..\n33..\n322.\n2211\n.11.\n3 3\n222\n2.1\n111\n3 4\n11.\n11.\n.2.\n222\n3 4\...
code_contests
verifiable_code
p01018 Warping Girl
Solve the following coding problem using the programming language python: Problem Aizu Magic School is a school where people who can use magic gather. Haruka, one of the students of that school, can use the magic of warp on the magic team. From her house to the school, there is a straight road of length L. There are...
```python INF = 10 ** 20 l, n = map(int, input().split()) lst = [list(map(int, input().split())) for _ in range(n)] + [[l, 0, INF]] lst.sort() score = {} for p, _, _ in lst: score[p] = p for i in range(n + 1): p, d, t = lst[i] for j in range(i + 1, n + 1): to_p, _, _ = lst[j] if to_p >= p + d: score...
vfc_32905
{ "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": "10 2\n2 3 1\n3 5 1", "output": "6", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 0", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
p01151 Divisor is the Conqueror
Solve the following coding problem using the programming language python: Divisor is the Conquerer is a solitaire card game. Although this simple game itself is a great way to pass one’s time, you, a programmer, always kill your time by programming. Your task is to write a computer program that automatically solves Di...
vfc_32909
{ "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\n1 2 3 3 7\n4\n2 3 3 3\n0", "output": "3 3 1 7 2\nNo", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1 2 3 6 7\n4\n2 3 3 3\n0", "output": "No\nNo\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
p01290 Queen's Case
Solve the following coding problem using the programming language python: A small country called Maltius was governed by a queen. The queen was known as an oppressive ruler. People in the country suffered from heavy taxes and forced labor. So some young people decided to form a revolutionary army and fight against the...
```python from collections import deque, defaultdict import sys readline = sys.stdin.readline write = sys.stdout.write dd = ((-1, 0), (0, -1), (1, 0), (0, 1), (0, 0)) def solve(): W, H = map(int, readline().split()) if W == H == 0: return False S = [readline().strip() for i in range(H)] px = py ...
vfc_32913
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 134217728, "problem_url": null, "time_limit": "{'seconds': 8, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 2\nQE\nEA\n3 1\nQAE\n3 1\nAQE\n5 5\n..E..\n.###.\nA###Q\n.###.\n..E..\n5 1\nA.E.Q\n5 5\nA....\n.\n..E..\n.####\n....Q\n0 0", "output": "Queen can not escape and Army can not catch Queen.\nArmy can catch Queen.\nQueen can es...
code_contests
verifiable_code
p01459 Light Road
Solve the following coding problem using the programming language python: There is an evil creature in a square on N-by-M grid (2 \leq N, M \leq 100), and you want to kill it using a laser generator located in a different square. Since the location and direction of the laser generator are fixed, you may need to use se...
```python from collections import deque N, M, A = map(int, input().split()) MP = [[0]*M for i in range(N)] sx = sy = gx = gy = -1 for i in range(N): for j, c in enumerate(input()): if c == '#': MP[i][j] = 1 elif c == 'S': sx = j; sy = i elif c == 'G': gx =...
vfc_32917
{ "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 3 1\nS#.\n...\n.#G", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3 1\nS#G\n...\n.#.", "output": "2", "type": "stdin_stdout" }, { "fn_name": nu...
code_contests
verifiable_code
p01611 K-th String
Solve the following coding problem using the programming language python: K-th String Problem Statement The suffix array SA for the character string S of length N is defined as a permutation of positive integers of N or less obtained by the following procedure. The substring from the i-th character to the j-th chara...
vfc_32921
{ "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 4 2\n2\n1\n3", "output": "bad", "type": "stdin_stdout" }, { "fn_name": null, "input": "18 26 10275802967\n10\n14\n9\n13\n7\n8\n2\n6\n11\n18\n12\n1\n4\n3\n16\n5\n17\n15", "output": "ritsumeica...
code_contests
verifiable_code
p01771 Tree
Solve the following coding problem using the programming language python: Problem statement There is a rooted tree of size N. Each vertex is numbered from 0 to N-1, with a root of 0. For the vertices at both ends of any side, the assigned integer is smaller closer to the root. Initially, the weights of all edges are ...
vfc_32925
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 536870912, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9 6\n0 1\n0 2\n0 3\n1 4\n1 5\n4 6\n5 7\n5 8\n1 0 1\n1 1 2\n0 6 3\n1 5 5\n1 8 4\n0 4 3", "output": "8\n5", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 6\n0 1\n0 2\n0 3\n1 4\n1 5\n4 6\n5 7...
code_contests
verifiable_code
p01905 Tournament
Solve the following coding problem using the programming language python: problem AOR Ika and you came to the tournament-style table tennis tournament singles section for reconnaissance. For AOR Ika-chan, who wants to record all the games, you decide to ask for the number of games that will be played in this tourname...
```python N,M = map(int, input().split()) l = [] for i in range(M): l.append(int(input())) count = N - 1 - M print(count) ```
vfc_32929
{ "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": "2 0", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1", "output": "0\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
p02186 Cutting Subarray
Solve the following coding problem using the programming language python: E: Cut out the sum problem Ebi-chan has a sequence (a_1, a_2, ..., a_n). Ebi-chan is worried about the maximum value of the sum of the partial arrays (which may be empty), so please find it. Here, a subarray refers to a continuous subsequence....
vfc_32937
{ "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": "5 2\n1 2 -3 4 -5\n3 3\n2 -6", "output": "4\n10\n7", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n0 2 -3 4 -5\n3 3\n2 -6", "output": "4\n9\n7\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
carvans
Solve the following coding problem using the programming language python: Most problems on CodeChef highlight chef's love for food and cooking but little is known about his love for racing sports. He is an avid Formula 1 fan. He went to watch this year's Indian Grand Prix at New Delhi. He noticed that one segment of t...
```python # cook your code here for testcases in xrange(int(raw_input() ) ) : n = int(raw_input()) Arr = map(int, raw_input().split() ) m = Arr[0] c = 1 for i in xrange(1, len(Arr)): if (Arr[i] <= m ): c += 1 m = Arr[i] print c ```
vfc_32949
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n10\n3\n8 3 6\n5\n4 5 1 2 3", "output": "1\n2\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n1\n10\n3\n8 3 6\n5\n4 5 1 2 4", "output": "1\n2\n2\n", "type": "stdin_s...
code_contests
verifiable_code
cranbrom
Solve the following coding problem using the programming language python: Seeing the current political scenario in the city of Delhi,and the clean sweep of the Aam Aadmi Party, you are wondering that its maybe time to change careers and start selling broomsticks. Now you sell broomsticks of various lengths. You initia...
```python t=int(input()) ans=0 l=[-1]*(100001) while(t>0): s=raw_input().split(" ") x=int(s[1]) if(s[0]=="found"): l[x]=ans elif(l[x]>=0): ans=max(ans,l[x]+x) l[x]-=1 t-=1 print ans ```
vfc_32953
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nfound 3\nfound 4\ndemand 3\ndemand 4", "output": "4", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
grid
Solve the following coding problem using the programming language python: Sherlock is stuck. There is a N X N grid in which some cells are empty (denoted by ‘.’), while some cells have rocks in them (denoted by ‘#’). Sherlock is on the South of the grid. He has to watch what is happening on the East of the grid. He ca...
```python def proc(a): n=len(a) j=n-1 l=0 ans=0 hsh=[True]*n for j in range(n-1,-1,-1): i=n-1 flag=True while i>=0: if a[i][j]=='#': hsh[i]=False flag=False elif hsh[i] and flag: ans+=1 i-=1 print ans...
vfc_32957
{ "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\n#..\n#..\n#..\n3\n#.#\n#.#\n#.#", "output": "6\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n3\n#..\n..#\n#..\n3\n#.#\n#.#\n#.#", "output": "3\n0\n", "type": "std...
code_contests
verifiable_code
mchairs
Solve the following coding problem using the programming language python: A new school in Byteland is now in the process of renewing some classrooms with new, stronger and better chairs, so that the students can stay still and pay attention to class :) However, due to budget and logistic reasons, it's only possible to...
```python t=input() while t>0: n=input() print pow(2,n,1000000007)-1 t-=1 ```
vfc_32961
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n2", "output": "1\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n4", "output": "1\n15\n", "type": "stdin_stdout" }, { "fn_name": null, "input...
code_contests
verifiable_code
rdioactv
Solve the following coding problem using the programming language python: EDIT : Please note that the user enters the whole string "Energy Level: 217" instead of just 217. You'd have to input accordingly. The output should only be the ids of radioactive elements, one id per line. Stick to the input/output format.   ...
```python for u in range(input()): string = raw_input().split() if int(string[-1]) > 200: print u + 1 ```
vfc_32965
{ "difficulty": "6", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\nEnergy Level: 217\nEnergy Level: 246\nEnergy Level: 4\nEnergy Level: 349", "output": "1\n2\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nEnergy Level: 217\nEnergy Level: 246\nEn...
code_contests
verifiable_code
tproduct
Solve the following coding problem using the programming language python: Given a complete binary tree with the height of H, we index the nodes respectively top-down and left-right from 1. The i-th node stores a positive integer Vi. Define Pi as follows: Pii if the i-th node is a leaf, otherwise Pii*PL, Vi*PR), where ...
```python # tree product - trproduct.py try: import psyco psyco.full() except ImportError: pass mod = 1000000007 h = int(raw_input()) while h>0: v = map(int, raw_input().split()) if h>1: level = 1<<(h-2) while level>=1: for i in xrange(level-1, 2*level-1): ...
vfc_32969
{ "difficulty": "2", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 2 3\n3\n3 1 5 2 6 4 7\n0", "output": "3\n105\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 2 3\n3\n3 1 1 2 6 4 7\n0", "output": "3\n21\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1016_A. Death Note
Solve the following coding problem using the programming language python: You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during n consecutive days. During the i...
```python (n,m) = tuple(map(int, input().split(" "))) x = list(map(int, input().split(" "))) nib = 0 ans = [] cou = 0; for i in x: nib+=i if (nib<m): ans.append(nib//m) else: ans.append(nib//m) nib-=(nib//m)*m print (*ans) ```
vfc_32973
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 100\n99\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 20\n10 9 19 2\n", "output": "0 0 1 1\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
103_A. Testing Pants for Sadness
Solve the following coding problem using the programming language python: The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness". The test consists of n questions; the questions are to be ...
```python import sys,math s = int(input()) arr = list(map(int,input().split(' '))) m = 0 for i in range(0,s): m+=(arr[i]-1)*(i+1)+1 print(m) ''' 2 2 2 1+1 2 1+1+1 3 (1+1+1,1) 4 3 3 1+1+1 3 1+1+1+1+1 5 1+1+1,1+1+1,1 7 3 2 4 1 1+1 1+1+1+1+1+1+1 1 1+1+1+1 ''' ```
vfc_32977
{ "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": "2\n2 2\n", "output": "5", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 1\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n10...
code_contests
verifiable_code
1062_B. Math
Solve the following coding problem using the programming language python: JATC's math teacher always gives the class some interesting math problems so that they don't get bored. Today the problem is as follows. Given an integer n, you can perform the following operations zero or more times: * mul x: multiplies n by...
```python import math def sieve(n): mark = [0]*(n+1) prime = [] for i in range(3, n+1, 2): if not mark[i]: for j in range(3*i, n+1, i+i): mark[j] = 1 prime.append(2) for i in range(3, n+1, 2): if not mark[i]: prime.append(i) return prime...
vfc_32981
{ "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": "20\n", "output": "10 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5184\n", "output": "6 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\...
code_contests
verifiable_code
1084_A. The Fair Nut and Elevator
Solve the following coding problem using the programming language python: The Fair Nut lives in n story house. a_i people live on the i-th floor of the house. Every person uses elevator twice a day: to get from the floor where he/she lives to the ground (first) floor and to get from the first floor to the floor where ...
```python n = int(input()) arr = list(map(int, input().split())) cur = 0 ans = 100000000 for x in range(n): cur = 0 for i in range(n): summ = 0 summ += abs(x - i) summ += i summ += x summ += x summ += i summ += abs(x - i) summ *= arr[i] cu...
vfc_32985
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1 1\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0 2 1\n", "output": "16\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
1131_C. Birthday
Solve the following coding problem using the programming language python: Cowboy Vlad has a birthday today! There are n children who came to the celebration. In order to greet Vlad, the children decided to form a circle around him. Among the children who came, there are both tall and low, so if they stand in a circle ...
```python n = int(input()) arr = [int(i) for i in input().split()] arr1, arr2 = [], [] arr.sort(reverse = True) for i in range(n): if i%2==0: arr1.append(arr[i]) else: arr2.append(arr[i]) arr2.reverse() for i in arr2: arr1.append(i) print(*arr1) ```
vfc_32993
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n30 10 20\n", "output": "10 30 20 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 1 1 3 2\n", "output": "1 2 3 2 1 ", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
1151_E. Number of Components
Solve the following coding problem using the programming language python: The Kingdom of Kremland is a tree (a connected undirected graph without cycles) consisting of n vertices. Each vertex i has its own value a_i. All vertices are connected in series by edges. Formally, for every 1 ≤ i < n there is an edge between ...
```python n = int(input()) + 1 res = 0 a = tuple(map(int, input().split())) for ai in a: res += ai * (n - ai) for ai, aj in map(sorted, zip(a, a[1:])): res -= ai * (n - aj) print(res) # ```
vfc_32997
{ "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": "3\n2 1 3\n", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 5 2 5 5 3 10 6 5 1\n", "output": "104\n", "type": "stdin_stdout" }, { "fn_name": n...
code_contests
verifiable_code
1173_D. Nauuo and Circle
Solve the following coding problem using the programming language python: Nauuo is a girl who loves drawing circles. One day she has drawn a circle and wanted to draw a tree on it. The tree is a connected undirected graph consisting of n nodes and n-1 edges. The nodes are numbered from 1 to n. Nauuo wants to draw a...
```python import sys n = int(sys.stdin.readline().strip()) D = [0] * n p = 998244353 for i in range (0, n - 1): u, v = list(map(int, sys.stdin.readline().strip().split())) D[u-1] = D[u-1] + 1 D[v-1] = D[v-1] + 1 ans = n for i in range (0, n): for j in range (0, D[i]): ans = (ans * (j + 1)) % p...
vfc_33001
{ "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\n1 2\n1 3\n1 4\n", "output": "24\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2\n1 3\n2 4\n", "output": "16\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1191_A. Tokitsukaze and Enhancement
Solve the following coding problem using the programming language python: Tokitsukaze is one of the characters in the game "Kantai Collection". In this game, every character has a common attribute — health points, shortened to HP. In general, different values of HP are grouped into 4 categories: * Category A if HP...
```python n=int(input()) d={} d[0]='1 A' d[1]='0 A' d[2]='1 B' d[3]='2 A' x=n%4 print(d[x]) ```
vfc_33005
{ "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": "33\n", "output": "0 A\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "98\n", "output": "1 B\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "85\n"...
code_contests
verifiable_code
120_A. Elevator
Solve the following coding problem using the programming language python: A sky scraper with 1000 floors has been built in the city of N. It has modern superfast elevators to help to travel from one floor to another. Each elevator has two doors, the front one and the back one. If one goes in through the front door, he...
```python enter = {'front':0, 'back':1} hand = ['L','R'] try: op = open('output.txt', 'w'); with open('input.txt') as ip: op.write(hand[enter[ip.readline().strip()]^(int(ip.readline())-1)]) op.close() except IOError as e: print 'L' ```
vfc_33009
{ "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": "front\n1\n", "output": "L\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "back\n2\n", "output": "L\n", "type": "stdin_stdout" }, { "fn_name": null, "input":...
code_contests
verifiable_code
122_D. Lucky Transformation
Solve the following coding problem using the programming language python: Petya loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya has a number consis...
```python n, k = map(int, input().split()) s = list(input()) cnt = 0 for i in range(n - 1): if cnt == k: break if s[i] == '4' and s[i + 1] == '7': if i & 1: if s[i - 1] == '4': if (cnt - k) & 1: s[i] = '7' print(''.join(s)) ...
vfc_33013
{ "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\n4478\n", "output": "4478\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7 4\n4727447\n", "output": "4427477\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
1251_C. Minimize The Integer
Solve the following coding problem using the programming language python: You are given a huge integer a consisting of n digits (n is between 1 and 3 ⋅ 10^5, inclusive). It may contain leading zeros. You can swap two digits on adjacent (neighboring) positions if the swapping digits are of different parity (that is, t...
```python # -*- coding: utf-8 -*- """ Created on Fri Nov 1 14:39:37 2019 @author: uditg """ ans={} test=int(input()) for each in range(test): num=input() n=len(num) num={i:int(num[i]) for i in range(n)} output={} even={} odd={} even_count=0 odd_count=0 for i in range(n): if...
vfc_33017
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n0709\n1337\n246432\n", "output": "0079\n1337\n234642\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1003\n", "output": "0013\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
1271_A. Suits
Solve the following coding problem using the programming language python: A new delivery of clothing has arrived today to the clothing store. This delivery consists of a ties, b scarves, c vests and d jackets. The store does not sell single clothing items — instead, it sells suits of two types: * a suit of the fir...
```python a = int(input()) b = int(input()) c = int(input()) d = int(input()) c1 = int(input()) c2 = int(input()) p = 0 if c2 > c1: m = min(b,c,d) b -= m c -= m d -= m p += m * c2 if d > 0: p += (min(a,d) * c1) else: m = min(a,d) a -= m d -= m p += m * c1 if d > 0: p +=...
vfc_33021
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n5\n6\n3\n1\n2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "17\n14\n5\n21\n15\n17\n", "output": "325\n", "type": "stdin_stdout" }, { "fn_nam...
code_contests
verifiable_code
1294_B. Collecting Packages
Solve the following coding problem using the programming language python: There is a robot in a warehouse and n packages he wants to collect. The warehouse can be represented as a coordinate grid. Initially, the robot stays at the point (0, 0). The i-th package is at the point (x_i, y_i). It is guaranteed that there a...
```python t=int(input()) for q in range(t): n=int(input()) a=[list(map(int,input().split())) for i in range(n)] a.sort() ans="" x,y=0,0 f=0 for i in range(n): if a[i][0]>=x and a[i][1]>=y: ans+='R'*(a[i][0]-x) x=a[i][0] ans+='U'*(a[i][1]-y) y=a[i][1] else: f=1 print('NO') break if f==0:...
vfc_33025
{ "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\n5\n1 3\n1 2\n3 3\n5 5\n4 3\n2\n1 0\n0 1\n1\n4 3\n", "output": "YES\nRUUURRRRUU\nNO\nYES\nRRRRUUU\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1\n1 1\n1\n1 1\n", "output": "Y...
code_contests
verifiable_code
1315_B. Homecoming
Solve the following coding problem using the programming language python: After a long party Petya decided to return home, but he turned out to be at the opposite end of the town from his home. There are n crossroads in the line in the town, and there is either the bus or the tram station at each crossroad. The cross...
```python t = int(input()) for _ in range(t): a, b, p = map(int, input().split()) s = input() d = {'A': a, 'B': b} i = len(s)-1 prev = len(s)-1 while i >= 0: i -= 1 curr = s[i] while s[i] == curr and i >= 0: i -= 1 i += 1 p -= d[curr] ...
vfc_33029
{ "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\n2 2 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBAABB\n5 3 4\nBBBBB\n2 1 1\nABABAB\n", "output": "2\n1\n3\n1\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 1 1\nBB\n1 1 1\nAB\n3 2 8\nAABBBBA...
code_contests
verifiable_code
1336_E1. Chiori and Doll Picking (easy version)
Solve the following coding problem using the programming language python: This is the easy version of the problem. The only difference between easy and hard versions is the constraint of m. You can make hacks only if both versions are solved. Chiori loves dolls and now she is going to decorate her bedroom! <image> ...
```python import sys MOD = 998244353 BOUND = 21 n, m = map(int, input().split()) l = list(map(int,input().split())) basis = [] for p in range(m-1,-1,-1): p2 = pow(2,p) nex = -1 for i in range(n): if l[i] >= p2: nex = l[i] break if nex != -1: basis.append(nex) ...
vfc_33033
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 3, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 7\n11 45 14 9 19 81\n", "output": "1 2 11 20 15 10 5 0 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n3 5 8 14\n", "output": "2 2 6 6 0 \n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1359_B. New Theatre Square
Solve the following coding problem using the programming language python: You might have remembered Theatre square from the [problem 1A](https://codeforces.com/problemset/problem/1/A). Now it's finally getting repaved. The square still has a rectangular shape of n × m meters. However, the picture is about to get more...
```python cases=input() for i in range(0,int(cases)): inss=input() list=inss.split(' ') n=int(list[0]) m=int(list[1]) x=int(list[2]) y=int(list[3]) price=0 if 2*x > y: lame=True else: lame=False for count in range(0,n): data=input() ###print(data...
vfc_33037
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1 10 1\n.\n1 2 10 1\n..\n2 1 10 1\n.\n.\n3 3 3 7\n..*\n*..\n.*.\n", "output": "10\n1\n20\n18\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n3 3 2 4\n**.\n***\n***\n", "outpu...
code_contests
verifiable_code
1379_D. New Passenger Trams
Solve the following coding problem using the programming language python: There are many freight trains departing from Kirnes planet every day. One day on that planet consists of h hours, and each hour consists of m minutes, where m is an even number. Currently, there are n freight trains, and they depart every day at...
```python from collections import defaultdict import sys input=sys.stdin.readline n,h,m,k=map(int,input().split()) l=[] a=[] start=0 for i in range(n): H,M=map(int,input().split()) M=M%(m//2) a.append(M) l.append((M+1,1,i)) l.append(((M+k)%(m//2),-1,i)) if (M+1)>(M+k)%(m//2): start+=1 l....
vfc_33041
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2 24 60 16\n16 0\n17 15\n", "output": "1 0\n2 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 24 60 15\n16 0\n17 15\n", "output": "0 0\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
139_B. Wallpaper
Solve the following coding problem using the programming language python: Having bought his own apartment, Boris decided to paper the walls in every room. Boris's flat has n rooms, each of which has the form of a rectangular parallelepiped. For every room we known its length, width and height of the walls in meters (d...
```python #------------------------------warmup---------------------------- import os import sys import math from io import BytesIO, IOBase from fractions import Fraction BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = By...
vfc_33045
{ "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": "1\n5 5 3\n3\n10 1 100\n15 2 320\n3 19 500\n", "output": "640\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n9 10 7\n1\n7 1 3\n", "output": "114\n", "type": "stdin_stdout" ...
code_contests
verifiable_code
1423_F. Coins
Solve the following coding problem using the programming language python: A famous gang of pirates, Sea Dogs, has come back to their hideout from one of their extravagant plunders. They want to split their treasure fairly amongst themselves, that is why You, their trusted financial advisor, devised a game to help them...
```python import os import sys from io import BytesIO, IOBase # region fastio 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 file.mode self.write = self.bu...
vfc_33049
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n1 2\n2 2\n", "output": "1", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
1493_A. Anti-knapsack
Solve the following coding problem using the programming language python: You are given two integers n and k. You are asked to choose maximum number of distinct integers from 1 to n so that there is no subset of chosen numbers with sum equal to k. A subset of a set is a set that can be obtained from initial one by re...
```python t=int(input()) for i in range(t): n,k = map(int,input().split()) ans=[] if n==1 and k==1: print(0) continue else: if k%2==0: for j in range(k//2,k): ans.append(j) for j in range(k+1,n+1): ans.append(j) else: for j in range(k//2+1,k): ans.append(j) for j in range(k+1,n+1):...
vfc_33061
{ "difficulty": "7", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 2\n5 3\n1 1\n", "output": "\n2\n3 1 \n3\n4 5 2 \n0\n\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "70\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n4 1\n4 2\n4 3\n4 4\n5 1\n5 2\n5 3\n5 4\n5 5\n6 1...
code_contests
verifiable_code
1515_G. Phoenix and Odometers
Solve the following coding problem using the programming language python: In Fire City, there are n intersections and m one-way roads. The i-th road goes from intersection a_i to b_i and has length l_i miles. There are q cars that may only drive along those roads. The i-th car starts at intersection v_i and has an o...
```python import sys from sys import stdin import math from collections import deque import sys class scc_graph: def __init__(self, N): self.N = N self.edges = [] def csr(self): self.start = [0]*(self.N+1) self.elist = [0]*len(self.edges) for e in self.edges: ...
vfc_33065
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 5\n1 2 1\n2 3 1\n3 1 2\n1 4 1\n4 3 2\n2\n1 2 4\n4 3 5\n", "output": "\nYES\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 4\n1 2 1\n2 3 1\n3 1 2\n1 4 3\n3\n1 1 3\n1 2 4\n4 0 1\n"...
code_contests
verifiable_code
171_A. Mysterious numbers - 1
Solve the following coding problem using the programming language python: Input The input contains two integers a1, a2 (0 ≤ ai ≤ 109), separated by a single space. Output Output a single integer. Examples Input 3 14 Output 44 Input 27 12 Output 48 Input 100 200 Output 102 The input will be give...
```python from math import floor x, y = input().split() x = int(x) y = int(y) rev = 0 while y > 0: a = int(y % 10) rev = rev * 10 + a y = floor(y / 10) b = x + rev print(b) ```
vfc_33073
{ "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": "27 12\n", "output": "48\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 14\n", "output": "44\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10...
code_contests
verifiable_code
190_D. Non-Secret Cypher
Solve the following coding problem using the programming language python: Berland starts to seize the initiative on the war with Flatland. To drive the enemy from their native land, the berlanders need to know exactly how many more flatland soldiers are left in the enemy's reserve. Fortunately, the scouts captured an ...
```python def answer(): ans,count,j=0,0,0 d=dict() for i in range(n): while(j==0 or d[a[j-1]] < k): if(j==n): j+=1 break try:d[a[j]]+=1 except:d[a[j]]=1 count += 1 m=n-count+1 j+=1 ...
vfc_33077
{ "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 3\n1 2 1 1 3\n", "output": " 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 2\n1 2 1 2\n", "output": " ...
code_contests
verifiable_code
263_B. Squares
Solve the following coding problem using the programming language python: Vasya has found a piece of paper with a coordinate system written on it. There are n distinct squares drawn in this coordinate system. Let's number the squares with integers from 1 to n. It turned out that points with coordinates (0, 0) and (ai,...
```python def ans(k,a): a.sort() if(k>len(a)): return "-1" else: if(k!=0): return a[len(a)-k] n,k=map(int,input().split(" ")) arr=list(map(int,input().split(" "))) if (ans(k,arr)=="-1"): print("-1") else: print(ans(k,arr)," ",ans(k,arr)) ...
vfc_33089
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 1\n2 4 1\n", "output": "4 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 3\n5 1 3 4\n", "output": "3 3\n", "type": "stdin_stdout" }, { "fn_name": null, ...
code_contests
verifiable_code
287_B. Pipeline
Solve the following coding problem using the programming language python: Vova, the Ultimate Thule new shaman, wants to build a pipeline. As there are exactly n houses in Ultimate Thule, Vova wants the city to have exactly n pipes, each such pipe should be connected to the water supply. A pipe can be connected to the ...
```python n, k = map(int, input().split()) def prod(n): if n%2: return n*((n+1)//2) else: return (n//2)*(n+1) def total_count(n, k): if k >= n: return (0, 0, 1) else: count = 0 l = 1; r = k s = prod(k) while l <= r: mid = (l+r)//2 if n > s - prod(mid) + mid: r = mid-1 else: l = mid+...
vfc_33093
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 0, 'nanos': 400000000}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 4\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n"...
code_contests
verifiable_code
334_E. Lucky Tickets
Solve the following coding problem using the programming language python: Gerald has a friend, Pollard. Pollard is interested in lucky tickets (ticket is a sequence of digits). At first he thought that a ticket is lucky if between some its digits we can add arithmetic signs and brackets so that the result obtained by ...
vfc_33101
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 6, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "7 4\n", "output": "00000007\n00010006\n00060001\n00070000\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
357_E. Compartments
Solve the following coding problem using the programming language python: A team of students from the city S is sent to the All-Berland Olympiad in Informatics. Traditionally, they go on the train. All students have bought tickets in one carriage, consisting of n compartments (each compartment has exactly four people)...
```python n = int(raw_input()) A = map(int, raw_input().split()) C = [0]*5 for a in A: C[a] += 1 cost = 0 t = min(C[1], C[2]) cost += t C[1] -= t C[2] -= t C[3] += t if C[2] != 0: # C[1] == 0 t = C[2]/3 cost += 2*t C[2] -= 3*t C[3] += 2*t if C[2] == 1: if C[4] > 0: cost += 1 elif C[3] > 1: ...
vfc_33105
{ "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\n1 2 2 4 3\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n4 1 1\n", "output": "2", "type": "stdin_stdout" }, { "fn_name": null, "input"...
code_contests
verifiable_code
401_C. Team
Solve the following coding problem using the programming language python: Now it's time of Olympiads. Vanya and Egor decided to make his own team to take part in a programming Olympiad. They've been best friends ever since primary school and hopefully, that can somehow help them in teamwork. For each team Olympiad, V...
```python mod = 1000000007 ii = lambda : int(input()) si = lambda : input() dgl = lambda : list(map(int, input())) f = lambda : map(int, input().split()) il = lambda : list(map(int, input().split())) ls = lambda : list(input()) n0, n1 = f() s='0'*(n0+n1) if n1<n0-1: print(-1) elif n1==n0-1 or n1==n0: s=s.replac...
vfc_33113
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 8\n", "output": "110110110110\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 5\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
429_D. Tricky Function
Solve the following coding problem using the programming language python: Iahub and Sorin are the best competitive programmers in their town. However, they can't both qualify to an important contest. The selection will be made with the help of a single problem. Blatnatalag, a friend of Iahub, managed to get hold of th...
```python import os import math cumsum = [int(x) for x in os.read(0, os.fstat(0).st_size).split()] n = cumsum[0] cumsum[0] = 0 for i in range(n): cumsum[i+1] += cumsum[i] def work(besta, i, sqrtbesta, lowerbound, upperbound, cumsumi): for j in range(i+1, min(n, i - 1 + sqrtbesta) + 1): if lowerbound <...
vfc_33117
{ "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\n1 0 0 -1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n1 -1\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "inpu...
code_contests
verifiable_code
451_B. Sort the Array
Solve the following coding problem using the programming language python: Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers. Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger ...
```python # coding=utf-8 if __name__ == '__main__': n = int(input()) line = str(input()).split() line = [int(it) for it in line] temp_line = line.copy() temp_line.sort() ptr_head = 0 ptr_tail = n - 1 while line[ptr_head] == temp_line[ptr_head]: if ptr_head == ptr_tail: break ptr_head += 1 while line[p...
vfc_33121
{ "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": "2\n1 2\n", "output": "yes\n1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n2 1 3 4\n", "output": "yes\n1 2\n", "type": "stdin_stdout" }, { "fn_name": null,...
code_contests
verifiable_code
474_A. Keyboard
Solve the following coding problem using the programming language python: Our good friend Mole is trying to code a big message. He is typing on an unusual keyboard with characters arranged in following way: qwertyuiop asdfghjkl; zxcvbnm,./ Unfortunately Mole is blind, so someti...
```python move=input() ans="" s=input() keyboard=["qwertyuiop","asdfghjkl;","zxcvbnm,./"] if move =="R": for i in range(len(s)): for j in range(len(keyboard)): if s[i] in keyboard[j]: ans+=keyboard[j][keyboard[j].index(s[i])-1] elif move =="L": for i in range(len(s)): ...
vfc_33125
{ "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": "R\ns;;upimrrfod;pbr\n", "output": "allyouneedislove\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "R\nwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww...
code_contests
verifiable_code
521_A. DNA Alignment
Solve the following coding problem using the programming language python: Vasya became interested in bioinformatics. He's going to write an article about similar cyclic DNA sequences, so he invented a new method for determining the similarity of cyclic sequences. Let's assume that strings s and t have the same length...
```python # problem statement: https://codeforces.com/problemset/problem/520/C modulo = 1000000007 n = int(input()) char_count = [0] * 256 s = input() for i in range(n): char_count[ord(s[i])] += 1 max_char_count = max(char_count) num_max_char = 0 for i in range(256): if char_count[i] == max_char_count: num_max_cha...
vfc_33133
{ "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": "2\nAG\n", "output": "4\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
548_C. Mike and Frog
Solve the following coding problem using the programming language python: Mike has a frog and a flower. His frog is named Xaniar and his flower is named Abol. Initially(at time 0), height of Xaniar is h1 and height of Abol is h2. Each second, Mike waters Abol and Xaniar. <image> So, if height of Xaniar is h1 and hei...
vfc_33137
{ "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": "1023\n1 2\n1 0\n1 2\n1 1\n", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n4 2\n1 1\n0 1\n2 3\n", "output": "3\n", "type": "stdin_stdout" }, { ...
code_contests
verifiable_code
574_E. Bear and Drawing
Solve the following coding problem using the programming language python: Limak is a little bear who learns to draw. People usually start with houses, fences and flowers but why would bears do it? Limak lives in the forest and he decides to draw a tree. Recall that tree is a connected graph consisting of n vertices a...
vfc_33141
{ "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": "8\n1 2\n1 3\n1 6\n6 4\n6 7\n6 5\n7 8\n", "output": "Yes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13\n1 2\n1 3\n1 4\n2 5\n2 6\n2 7\n3 8\n3 9\n3 10\n4 11\n4 12\n4 13\n", "output...
code_contests
verifiable_code
617_E. XOR and Favorite Number
Solve the following coding problem using the programming language python: Bob has a favorite number k and ai of length n. Now he asks you to answer m queries. Each query is given by a pair li and ri and asks you to count the number of pairs of integers i and j, such that l ≤ i ≤ j ≤ r and the xor of the numbers ai, ai...
```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" no...
vfc_33149
{ "difficulty": "11", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 4, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 2 3\n1 2 1 1 0 3\n1 6\n3 5\n", "output": "7\n0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 3 1\n1 1 1 1 1\n1 5\n2 4\n1 3\n", "output": "9\n4\n4\n", "type": "stdin_stdou...
code_contests
verifiable_code
638_B. Making Genome in Berland
Solve the following coding problem using the programming language python: Berland scientists face a very important task - given the parts of short DNA fragments, restore the dinosaur DNA! The genome of a berland dinosaur has noting in common with the genome that we've used to: it can have 26 distinct nucleotide types,...
```python n = int(input()) genom = dict() heads = set() for i in range(n): part = input() heads.add(part[0]) for i in range(len(part)): prev = None next = None if i - 1 >= 0: prev = part[i - 1] if i + 1 < len(part): next = part[i + 1] if pa...
vfc_33153
{ "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\nbcd\nab\ncdef\n", "output": "abcdef\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nx\ny\nz\nw\n", "output": "wxyz\n", "type": "stdin_stdout" }, { "fn_name"...
code_contests
verifiable_code
665_F. Four Divisors
Solve the following coding problem using the programming language python: If an integer a is divisible by another integer b, then b is called the divisor of a. For example: 12 has positive 6 divisors. They are 1, 2, 3, 4, 6 and 12. Let’s define a function D(n) — number of integers between 1 and n (inclusive) which h...
vfc_33157
{ "difficulty": "12", "memory_limit": null, "memory_limit_bytes": 768000000, "problem_url": null, "time_limit": "{'seconds': 10, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "636940\n"...
code_contests
verifiable_code
68_D. Half-decay tree
Solve the following coding problem using the programming language python: Recently Petya has become keen on physics. Anna V., his teacher noticed Petya's interest and gave him a fascinating physical puzzle — a half-decay tree. A half-decay tree is a complete binary tree with the height h. The height of a tree is the...
vfc_33161
{ "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": "1 4\nadd 1 3\nadd 2 10\nadd 3 11\ndecay\n", "output": "13.50000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 6\nadd 11 467\nadd 9 879\ndecay\nadd 15 551\nadd 14 473\nadd 14 104\n", ...
code_contests
verifiable_code
712_B. Memory and Trident
Solve the following coding problem using the programming language python: Memory is performing a walk on the two-dimensional plane, starting at the origin. He is given a string s with his directions for motion: * An 'L' indicates he should move one unit left. * An 'R' indicates he should move one unit right. ...
```python s = input() ud = lr = 0 for ch in s: if(ch=='R'): lr = lr+1 if(ch=='L'): lr = lr-1 if(ch=='U'): ud = ud+1 if(ch=='D'): ud = ud-1 if((abs(lr) + abs(ud))%2==1): print(-1) else: print(int((abs(lr) + abs(ud))/2)) ```
vfc_33165
{ "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": "UDUR\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "RUUR\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "RRU\n...
code_contests
verifiable_code
733_A. Grasshopper And the String
Solve the following coding problem using the programming language python: One day, the Grasshopper was jumping on the lawn and found a piece of paper with a string. Grasshopper became interested what is the minimum jump ability he should have in order to be able to reach the far end of the string, jumping only on vowe...
```python def solve(a): l = [0] li = [] j = 0 for i in range(len(a)): if a[i] == "A" or a[i] == "E" or a[i] == "I" or a[i] == "O" or a[i] == "U" or a[i] == "Y": l.append(i + 1) j += 1 li.append(l[j] - l[j-1]) l.append(i + 1) j += 1 li.append(l[...
vfc_33169
{ "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": "ABABBBACFEYUKOTT\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "AAA\n", "output": "1\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
757_B. Bash's Big Day
Solve the following coding problem using the programming language python: Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases....
```python def function1(n,s): if n==1: return 1 pokemonj=0 pokecage=[0 for i in range(100001)] for i in range(n): pokecage[s[i]]+=1 maxyincage=min(pokecage[1],1) a = [i for i in range(100001)] a[1] = 0 i = 2 while i <= 100000: if a[i] != 0: poke...
vfc_33173
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n2 3 4 6 7\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n2 3 4\n", "output": "2\n", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
778_D. Parquet Re-laying
Solve the following coding problem using the programming language python: Peter decided to lay a parquet in the room of size n × m, the parquet consists of tiles of size 1 × 2. When the workers laid the parquet, it became clear that the tiles pattern looks not like Peter likes, and workers will have to re-lay it. The...
```python #!/usr/bin/env python3 board = [] n, m = 0, 0 def rotate(x, y): if board[x][y] == 'L': board[x][y] = board[x][y+1] = 'U' board[x+1][y] = board[x+1][y+1] = 'D' else: board[x][y] = board[x+1][y] = 'L' board[x][y+1] = board[x+1][y+1] = 'R' def fix(x, y, moves): if b...
vfc_33177
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 512000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 3\nULR\nDLR\nLRU\nLRD\nULR\nDUU\nUDD\nDLR", "output": "5\n1 2\n3 1\n3 2\n1 2\n2 2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 3\nULR\nDLR\nLRU\nLRD\n", "output": "2\n1 2\n1 1...
code_contests
verifiable_code
802_G. Fake News (easy)
Solve the following coding problem using the programming language python: As it's the first of April, Heidi is suspecting that the news she reads today are fake, and she does not want to look silly in front of all the contestants. She knows that a newspiece is fake if it contains heidi as a subsequence. Help Heidi ass...
```python li = list(input()) def f(n,s): global li while True: if li[n] != s: li.pop(n) else: break try: f(0,'h') f(1,'e') f(2,'i') f(3,'d') f(4,'i') except: print("NO") else: print("YES") ```
vfc_33181
{ "difficulty": "13", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "abcheaibcdi\n", "output": "YES", "type": "stdin_stdout" }, { "fn_name": null, "input": "hiedi\n", "output": "NO", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
825_C. Multi-judge Solving
Solve the following coding problem using the programming language python: Makes solves problems on Decoforces and lots of other different online judges. Each problem is denoted by its difficulty — a positive integer number. Difficulties are measured the same across all the judges (the problem with difficulty d on Deco...
```python n,k=map(int,input().split()) ar=sorted(list(map(int,input().split()))) ans=0 for x in ar: if k <= x <= k*2: k=x while x/2 > k: ans+=1 k*=2 if k <= x <= k*2: k=x print(ans) ```
vfc_33185
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 20\n10 3 6 3\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n2 1 9\n", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "in...
code_contests
verifiable_code
848_A. From Y to Y
Solve the following coding problem using the programming language python: From beginning till end, this message has been waiting to be conveyed. For a given unordered multiset of n lowercase English letters ("multi" means that a letter may appear more than once), we treat all letters as strings of length 1, and repea...
```python # def ap(l): # d = set() # for i in range(1, len(l)): # d.add(l[i]-l[i-1]) # if(len(d) == 1): # return d.pop() # else: # return "re" # def app(ll, oo, nm, ooo): # k = [] # for j in range(n): # if(j%oo !=0): # k.append(ll[j]) # if(ap(k) ...
vfc_33189
{ "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": "12\n", "output": "aaaaabbcc\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n", "output": "aaa\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "...
code_contests
verifiable_code
896_C. Willem, Chtholly and Seniorious
Solve the following coding problem using the programming language python: — Willem... — What's the matter? — It seems that there's something wrong with Seniorious... — I'll have a look... <image> Seniorious is made by linking special talismans in particular order. After over 500 years, the carillon is now in bad...
vfc_33197
{ "difficulty": "9", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10 10 7 9\n", "output": "2\n1\n0\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10 10 9 9\n", "output": "1\n1\n3\n3\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
917_D. Stranger Trees
Solve the following coding problem using the programming language python: Will shares a psychic connection with the Upside Down Monster, so everything the monster knows, Will knows. Suddenly, he started drawing, page after page, non-stop. Joyce, his mom, and Chief Hopper put the drawings together, and they realized, i...
vfc_33201
{ "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\n1 2\n1 3\n", "output": "0 2 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2\n1 3\n1 4\n", "output": "0 9 6 1 ", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
93_D. Flags
Solve the following coding problem using the programming language python: When Igor K. was a freshman, his professor strictly urged him, as well as all other freshmen, to solve programming Olympiads. One day a problem called "Flags" from a website called Timmy's Online Judge caught his attention. In the problem one ha...
```python p=10**9+7 def S(x): if x==0: return 0 elif x==1: return 4 elif x&1: return 11*pow(3,x/2,p)-7 else: return 19*pow(3,x/2-1,p)-7 def G(x): return (S(x)+S(x+1>>1))*pow(2,p-2,p)%p; l,r=map(int,raw_input().split()) print (G(r)-G(l-1))%p; ```
vfc_33205
{ "difficulty": "10", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 2, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 4\n", "output": " 23\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 6\n", "output": " ...
code_contests
verifiable_code
967_B. Watering System
Solve the following coding problem using the programming language python: Arkady wants to water his only flower. Unfortunately, he has a very poor watering system that was designed for n flowers and so it looks like a pipe with n holes. Arkady can only use the water that flows from the first hole. Arkady can block so...
```python n, a, b = [int(i) for i in input().split(' ')] sizes = [int(i) for i in input().split(' ')] st = sum(sizes) s = (sizes[0] * a) / b sb = st - s blockable = sorted(sizes[1:], reverse=True) blocked_no = 0 blocked_amount = 0 for i in range(len(blockable)): if blocked_amount < sb: blocked_no += 1 ...
vfc_33209
{ "difficulty": "8", "memory_limit": null, "memory_limit_bytes": 256000000, "problem_url": null, "time_limit": "{'seconds': 1, 'nanos': 0}" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 10 3\n2 2 2 2\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 10 10\n1000 1 1 1 1\n", "output": "4\n", "type": "stdin_stdout" }, { "fn_name":...
code_contests
verifiable_code
ashu-and-prime-factors-4
Solve the following coding problem using the programming language python: Ashu is very fond of Prime numbers and he like challenging his friends by giving them various problems based on Mathematics and Prime number. One of his friend Harshit is jealous and challenges him to solve a task. Task is :Given a prime number ...
```python MAX = 10**6+1 primes = [1]*MAX primes[0] = primes[1] = 0 for i in xrange(2,MAX): if primes[i]: for j in xrange(i*i,MAX,i): if primes[j]: primes[i] += 1 primes[j] = 0 for _ in xrange(input()): x = input() print primes[x] ```
vfc_33217
{ "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\n11\n\nSAMPLE", "output": "500000\n20779\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2\n7\n\nSAMPLE", "output": "500000\n38095\n", "type": "stdin_stdout" }, ...
code_contests
verifiable_code
chiku-and-his-astrology
Solve the following coding problem using the programming language python: Little Chiku is very choosy about numbers. He considers 0 and 1 together as bad omen. So he hates 0 and 1 appearing adjacent to each other. So he wants you to remove these 0 and 1 combinations from a string. So you proceed like this : Choose any...
```python tc=int(raw_input()) for case in range(tc): s=raw_input() l=len(s) z=s.count("0") o=s.count("1") if z<o: print l-z*2 else: print l-o*2 ```
vfc_33221
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n11101111\n1100\n01010\n\nSAMPLE", "output": "6\n0\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n11101111\n1100\n01010", "output": "6\n0\n1\n", "type": "stdin_stdout"...
code_contests
verifiable_code
dummy-14
Solve the following coding problem using the programming language python: Results are out and admission process has begun in most of the colleges. This is the story of two such young engineering aspirants, Ramesh and Suresh, who intend to make it big in life. They met each other during the admission phase of some co...
```python def numbers(N): my_number = 0 v = {} c = {} i = 0 while my_number < N: c[i] = i * i * i for j in xrange(i): s = c[j] + c[i] if s in v: my_number += 1 yield(s) v[s] = (j,i) i += 1 my = [] def m(N): for x in numbers(N): my.append(x) m(100) T = int(raw_input()) for _ in xra...
vfc_33225
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n1\n\nSAMPLE", "output": "1729", "type": "stdin_stdout" }, { "fn_name": null, "input": "13\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13", "output": "1729\n4104\n13832\n20683\n32832\n39312\n4003...
code_contests
verifiable_code
gudi-trapped-in-the-room-july-easy
Solve the following coding problem using the programming language python: Gudi enters the castle, and moves along the main path. Suddenly, a block in the ground opens and she falls into it! Gudi slides down and lands in a dark room. A mysterious voice announces: Intruders are not allowed inside the castle. To proce...
```python #!/usr/bin/env python # -*- coding: utf-8 -*- # https://www.hackerearth.com/july-easy-16/algorithm/gudi-trapped-in-the-room-july-easy/ from collections import deque def increment_string(s, n, a): start, mul = (0, 1) if n % 2 == 1: start, mul = (1, 10) for i in xrange(start, n, 2): ...
vfc_33229
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n31\n4 1\n160\n9 2\n\nSAMPLE", "output": "11\n000\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n31\n4 1\n98\n9 2\n\nSAMPLE", "output": "11\n90\n", "type": "stdin_stdout"...
code_contests
verifiable_code
little-shino-and-fibonacci
Solve the following coding problem using the programming language python: Little Shino loves to play with numbers. She just came to know about Fibonacci Series. Fibonacci Series is a series of number such that Fib(1) = 0 Fib(2) = 1 Fib(x) = Fib(x-1) + Fib(x-2)\;where\;2 < x Soon Little Shino realized that Fibonacci ...
```python a=[0]*20000 ar=[0]*20000 a[1]=0 a[2]=1 ar[1]=0 ar[2]=1 for i in range(3,16000): a[i]=(a[i-1]+a[i-2])%10000 for i in range(2,16000): ar[i]=(a[i]+ar[i-1])%1000000007 def fibo(n): return (ar[n%15000] + (((n/15000)%1000000007)*ar[15000])%1000000007)%1000000007 for _ in range(input()): l,r=map(int,raw_input().sp...
vfc_33233
{ "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 3\n1 4\n8 10\n\nSAMPLE", "output": "2\n4\n68\n", "type": "stdin_stdout" } ] }
code_contests
verifiable_code
mystery-10
Solve the following coding problem using the programming language python: Solve the Mystery. Input Format: First line contains integer T denoting number of test cases. Next T lines contains sentences, one in each line. Output Format: Print output of each test case on individual line. Constraints: 1 ≤ T ≤ 100 1 ≤ le...
```python k='qwertyuiopasdfghjklzxcvbnm' a='abcdefghijklmnopqrstuvwxyz' o='' for _ in range(input()): string=raw_input() o='' for i in string: if i!=' ': o+=k[a.index(i)] else: o+=' ' print o ```
vfc_33237
{ "difficulty": "0", "memory_limit": null, "memory_limit_bytes": 0, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "8\nhello\nepiphany\ncompetitive programming\ncomputer\nmonitor\ncental processing unit\nkey board\nmouse\n\nSAMPLE", "output": "itssg\nthohiqfn\negdhtzozoct hkgukqddofu\negdhxztk\ndgfozgk\netfzqs hkgetllofu xfoz\natn wgqkr\nd...