input
stringlengths
52
10.1k
response
stringlengths
14
289k
test_cases
stringlengths
124
74M
difficulty
stringclasses
3 values
id
int64
1.6k
9.51k
problem_pass_rate
float64
0
1
test_case_pass_rates
listlengths
4
1.44k
Alice and Bob are playing a game with $n$ piles of stones. It is guaranteed that $n$ is an even number. The $i$-th pile has $a_i$ stones. Alice and Bob will play a game alternating turns with Alice going first. On a player's turn, they must choose exactly $\frac{n}{2}$ nonempty piles and independently remove a positi...
n=int(input()) s=list(map(int,input().split())) print("Bob"if s.count(min(s))>n/2 else"Alice")
[{"input": "2\n8 8\n", "output": "Bob\n"}, {"input": "4\n3 1 4 1\n", "output": "Alice\n"}, {"input": "44\n37 43 3 3 36 45 3 3 30 3 30 29 3 3 3 3 36 34 31 38 3 38 3 48 3 3 3 3 46 49 30 50 3 42 3 3 3 37 3 3 41 3 49 3\n", "output": "Bob\n"}, {"input": "12\n33 26 11 11 32 25 18 24 27 47 28 7\n", "output": "Alice\n"}, {"inp...
interview
5,228
0
[ 0.85, 0.75, 0.75, 0.75, 0.7, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.6, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, ...
SaMer has written the greatest test case of all time for one of his problems. For a given array of integers, the problem asks to find the minimum number of groups the array can be divided into, such that the product of any pair of integers in the same group is a perfect square. Each integer must be in exactly one gro...
#!/usr/bin/env python3 from math import sqrt primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 2...
[{"input": "1\n0\n", "output": "1\n"}, {"input": "1\n-3622679\n", "output": "1\n"}, {"input": "8\n-5 5 10 -5 9 -2 5 7\n", "output": "8 7 7 5 6 3 0 0\n"}, {"input": "80\n8861 -8846 -3257 8263 -8045 4549 9626 -8599 5755 -3559 5813 -7411 9151 -1847 2441 4201 2381 4651 -6571 199 -6737 -6333 -9433 -4967 9041 -9319 6801 5813...
interview
5,995
0
[ 0.3, 0.2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
# Introduction There is a war and nobody knows - the alphabet war! There are two groups of hostile letters. The tension between left side letters and right side letters was too high and the war began. # Task Write a function that accepts `fight` string consists of only small letters and return who wins the fight. ...
def alphabet_war(fight): d = {'w':4,'p':3,'b':2,'s':1, 'm':-4,'q':-3,'d':-2,'z':-1} r = sum(d[c] for c in fight if c in d) return {r==0:"Let's fight again!", r>0:"Left side wins!", r<0:"Right side wins!" }[True]
[{"input": ["zzzzs"], "output": ["Right side wins!"]}, {"input": ["zdqmwpbs"], "output": ["Let's fight again!"]}, {"input": ["z"], "output": ["Right side wins!"]}, {"input": ["wwwwww"], "output": ["Left side wins!"]}, {"input": ["wq"], "output": ["Left side wins!"]}]
introductory
2,928
0
[ 0, 0, 0, 0, 0 ]
# Task Given an array of roots of a polynomial equation, you should reconstruct this equation. ___ ## Output details: * If the power equals `1`, omit it: `x = 0` instead of `x^1 = 0` * If the power equals `0`, omit the `x`: `x - 2 = 0` instead of `x - 2x^0 = 0` * There should be no 2 signs in a row: `x - 1 = 0` ins...
import re def polynomialize(roots): def deploy(roots): r = -roots[0] if len(roots) == 1: return [r, 1] sub = deploy(roots[1:]) + [0] return [c*r + sub[i-1] for i,c in enumerate(sub)] coefs = deploy(roots) poly = ' + '.join(["{}x^{}".format(c,i) for i,c in...
[{"input": [[1]], "output": ["x - 1 = 0"]}, {"input": [[1, 2, 3, 4, 5]], "output": ["x^5 - 15x^4 + 85x^3 - 225x^2 + 274x - 120 = 0"]}, {"input": [[1, -1]], "output": ["x^2 - 1 = 0"]}, {"input": [[0]], "output": ["x = 0"]}, {"input": [[0, 2, 3]], "output": ["x^3 - 5x^2 + 6x = 0"]}, {"input": [[0, 0]], "output": ["x^2 = ...
introductory
3,548
0
[ 0, 0, 0, 0, 0, 0, 0, 0 ]
Given an array of ones and zeroes, convert the equivalent binary value to an integer. Eg: `[0, 0, 0, 1]` is treated as `0001` which is the binary representation of `1`. Examples: ``` Testing: [0, 0, 0, 1] ==> 1 Testing: [0, 0, 1, 0] ==> 2 Testing: [0, 1, 0, 1] ==> 5 Testing: [1, 0, 0, 1] ==> 9 Testing: [0, 0, 1, 0] =...
def binary_array_to_number(arr): return int("".join(map(str, arr)), 2)
[{"input": [[1, 1, 1, 1]], "output": [15]}, {"input": [[0, 1, 1, 0]], "output": [6]}, {"input": [[0, 0, 1, 0]], "output": [2]}, {"input": [[0, 0, 0, 1]], "output": [1]}]
introductory
3,583
0
[ 0, 0, 0, 0 ]
Write a function that takes a single array as an argument (containing multiple strings and/or positive numbers and/or arrays), and returns one of four possible string values, depending on the ordering of the lengths of the elements in the input array: Your function should return... - “Increasing” - if the lengths of ...
def order_type(arr): if not arr : return 'Constant' arr = list( map(len, [str(elt) if type(elt)==int else elt for elt in arr] )) cmp =sorted(arr) if arr == [arr[0]]*len(arr) : s='Constant' elif arr == cmp : s='Increasing' elif arr == cmp[::-1] : s='Decreasing' else : ...
[{"input": [[]], "output": ["Constant"]}, {"input": [[[1, 23, 456, 78910], ["abcdef", "ghijklmno", "pqrstuvwxy"], [[1, 23, 456, 78910, ["abcdef", "ghijklmno", "pqrstuvwxy"]], 1234]]], "output": ["Decreasing"]}, {"input": [[[1, 2, 3, 4], [5, 6, 7], [8, 9]]], "output": ["Decreasing"]}, {"input": [[["ab", "cdef", "g"], ["...
introductory
4,487
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
What are you doing at the end of the world? Are you busy? Will you save us? [Image] Nephren is playing a game with little leprechauns. She gives them an infinite array of strings, f_{0... ∞}. f_0 is "What are you doing at the end of the world? Are you busy? Will you save us?". She wants to let more people know a...
f0 = 'What are you doing at the end of the world? Are you busy? Will you save us?' ft1, ft2, ft3 = 'What are you doing while sending "', '"? Are you busy? Will you send "', '"?' flen = [2 * 10 ** 18] * (10 ** 5 + 1) flen[0] = len(f0) for i in range(1, 56): flen[i] = len(ft1) + len(ft2) + len(ft3) + 2 * flen[i-1] ...
[{"input": "1\n0 1\n", "output": "W"}, {"input": "3\n1 1\n1 2\n1 111111111111\n", "output": "Wh."}, {"input": "10\n1 8\n1 8\n9 5\n0 1\n8 1\n7 3\n5 2\n0 9\n4 6\n9 4\n", "output": "ee WWah at"}, {"input": "9\n50 161003686678495163\n50 161003686678495164\n50 161003686678495165\n51 322007373356990395\n51 322007373356990396...
competition
8,886
0
[ 0.15, 0.1, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
You're on your way to the market when you hear beautiful music coming from a nearby street performer. The notes come together like you wouln't believe as the musician puts together patterns of tunes. As you wonder what kind of algorithm you could use to shift octaves by 8 pitches or something silly like that, it dawns ...
def is_lock_ness_monster(s): return any(i in s for i in ('tree fiddy', 'three fifty', '3.50'))
[{"input": ["Your girlscout cookies are ready to ship. Your total comes to tree fiddy"], "output": [true]}, {"input": ["Yo, I heard you were on the lookout for Nessie. Let me know if you need assistance."], "output": [false]}, {"input": ["I'm from Scottland. I moved here to be with my family sir. Please, $3.50 would go...
introductory
3,855
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Deoxyribonucleic acid, DNA is the primary information storage molecule in biological systems. It is composed of four nucleic acid bases Guanine ('G'), Cytosine ('C'), Adenine ('A'), and Thymine ('T'). Ribonucleic acid, RNA, is the primary messenger molecule in cells. RNA differs slightly from DNA its chemical structu...
def dna_to_rna(dna): return dna.replace("T", "U")
[{"input": ["TTTT"], "output": ["UUUU"]}, {"input": ["GCAT"], "output": ["GCAU"]}, {"input": ["GATTCCACCGACTTCCCAAGTACCGGAAGCGCGACCAACTCGCACAGC"], "output": ["GAUUCCACCGACUUCCCAAGUACCGGAAGCGCGACCAACUCGCACAGC"]}, {"input": ["GACCGCCGCC"], "output": ["GACCGCCGCC"]}, {"input": ["GAAGCTTATCCGTTCCTGAAGGCTGTGGCATCCTCTAAATCAG...
introductory
3,524
0
[ 0, 0, 0, 0, 0, 0, 0 ]
There are N pieces of source code. The characteristics of the i-th code is represented by M integers A_{i1}, A_{i2}, ..., A_{iM}. Additionally, you are given integers B_1, B_2, ..., B_M and C. The i-th code correctly solves this problem if and only if A_{i1} B_1 + A_{i2} B_2 + ... + A_{iM} B_M + C > 0. Among the N code...
n,m,c=map(int,input().split()) b=list(map(int,input().split())) r=0 for _ in range(n): a=list(map(int,input().split())) d=0 for jj in range(m): d+=a[jj]*b[jj] if d+c>0: r+=1 print(r)
[{"input": "9 9 11\n81 90 73 -56 1 -13 71 -82 -64\n-96 39 -26 -53 -31 19 -87 -86 -48\n57 13 -96 32 -10 64 -80 79 -93\n-72 40 54 82 -21 69 38 -37 79\n-65 14 -24 -69 43 89 -74 -84 -21\n-16 23 -4 50 -38 48 -62 92 72\n35 -4 -36 39 7 76 -83 55 50\n-93 16 95 -17 81 22 18 -57 8\n-94 14 51 26 -54 -66 -15 -81 43\n43 -44 -96 80 ...
introductory
9,179
0.85
[ 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.9, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85, 0.85 ]
A camera you have accidentally left in a desert has taken an interesting photo. The photo has a resolution of n pixels width, and each column of this photo is all white or all black. Thus, we can represent the photo as a sequence of n zeros and ones, where 0 means that the corresponding column is all white, and 1 means...
n = int(input()) x = list(map(int, input().split())) d = None s = 1 c = x[0] for i in range(1, n): if x[i] == c: s += 1 else: if d is None: d = s else: if (s != d): print("NO") break s = 1 c = x[i] else: if (d is...
[{"input": "9\n1 1 0 1 1 0 1 1 0\n", "output": "NO\n"}, {"input": "9\n0 1 1 0 0 0 1 1 1\n", "output": "NO\n"}, {"input": "11\n0 1 0 1 0 1 0 0 0 1 0\n", "output": "NO\n"}, {"input": "7\n1 1 1 1 1 0 1\n", "output": "NO\n"}, {"input": "7\n0 0 0 1 1 1 0\n", "output": "NO\n"}, {"input": "5\n1 0 0 0 1\n", "output": "NO\n"}, ...
interview
5,637
0
[ 0.6, 0.6, 0.6, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.45, 0.45, 0.45, 0.45, 0.45, 0.45, 0.4, 0.4, 0.4, 0.4, 0.35, 0.35, 0.35, 0.3, 0.25, 0.25, 0.2, 0.2 ]
Let’s define a grid to be a set of tiles with 2 rows and 13 columns. Each tile has an English letter written in it. The letters don't have to be unique: there might be two or more tiles with the same letter written on them. Here is an example of a grid: ABCDEFGHIJKLM NOPQRSTUVWXYZ We say that two tiles are adjacent ...
3 s = input() n = len(s) a, b = 0, 0 d = dict() for i in range(len(s)): if s[i] in d: a = d[s[i]] b = i d[s[i]] = i if a == b - 1: print("Impossible") else: ans = [[' '] * 13 for i in range(2)] if (b - a) % 2 == 1: for i in range((b - a) // 2): ans[0][-(b - a) ...
[{"input": "UULGRBAODZENVCSMJTHXPWYKFIQ\n", "output": "Impossible\n"}, {"input": "DYCEUXXKMGZOINVPHWQSRTABLJF\n", "output": "Impossible\n"}, {"input": "BUVTYZFQSNRIWOXXGJLKACPEMDH\n", "output": "Impossible\n"}, {"input": "BITCRJOKMPDDUSWAYXHQZEVGLFN\n", "output": "Impossible\n"}, {"input": "BADSLHIYGMZJQKTCOPRVUXFWENN\...
interview
5,467
0
[ 0.15, 0.15, 0.15, 0.15, 0.1, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
You have a digit sequence S of length 4. You are wondering which of the following formats S is in: - YYMM format: the last two digits of the year and the two-digit representation of the month (example: 01 for January), concatenated in this order - MMYY format: the two-digit representation of the month and the last tw...
s=input() s1=int(s[0]+s[1]) s2=int(s[2]+s[3]) if (0<s1<13)and(0<s2<13): print("AMBIGUOUS") elif (0<s1<13): print("MMYY") elif (0<s2<13): print("YYMM") else: print("NA")
[{"input": "9999\n", "output": "NA\n"}, {"input": "1700\n", "output": "NA\n"}, {"input": "0000\n", "output": "NA\n"}, {"input": "1312\n", "output": "YYMM\n"}, {"input": "1905\n", "output": "YYMM\n"}, {"input": "0101\n", "output": "AMBIGUOUS\n"}, {"input": "0348\n", "output": "MMYY\n"}, {"input": "0112\n", "output": "AM...
introductory
9,364
0.2
[ 0.75, 0.75, 0.75, 0.5, 0.45, 0.4, 0.35, 0.35, 0.3, 0.2 ]
# Introduction Ka ka ka cypher is a cypher used by small children in some country. When a girl wants to pass something to the other girls and there are some boys nearby, she can use Ka cypher. So only the other girls are able to understand her. She speaks using KA, ie.: `ka thi ka s ka bo ka y ka i ka s ka u ka gly...
import re KA_PATTERN = re.compile(r'(?![aeiou]+$)([aeiou]+)', re.I) def ka_co_ka_de_ka_me(word): return 'ka' + KA_PATTERN.sub(r'\1ka', word)
[{"input": ["z"], "output": ["kaz"]}, {"input": ["maintenance"], "output": ["kamaikantekanakance"]}, {"input": ["ka"], "output": ["kaka"]}, {"input": ["aa"], "output": ["kaaa"]}, {"input": ["a"], "output": ["kaa"]}, {"input": ["Woodie"], "output": ["kaWookadie"]}, {"input": ["Incomprehensibilities"], "output": ["kaIkan...
introductory
2,895
0
[ 0, 0, 0, 0, 0, 0, 0, 0 ]
Finish the solution so that it takes an input `n` (integer) and returns a string that is the decimal representation of the number grouped by commas after every 3 digits. Assume: `0 <= n < 2147483647` ## Examples ``` 1 -> "1" 10 -> "10" 100 -> "100" 1000 -> "...
def group_by_commas(n): return '{:,}'.format(n)
[{"input": [1], "output": ["1"]}, {"input": [12], "output": ["12"]}, {"input": [123], "output": ["123"]}, {"input": [1234], "output": ["1,234"]}, {"input": [12345], "output": ["12,345"]}, {"input": [123456], "output": ["123,456"]}, {"input": [1234567], "output": ["1,234,567"]}, {"input": [12345678], "output": ["12,345,...
introductory
3,164
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Vova plans to go to the conference by train. Initially, the train is at the point $1$ and the destination point of the path is the point $L$. The speed of the train is $1$ length unit per minute (i.e. at the first minute the train is at the point $1$, at the second minute — at the point $2$ and so on). There are lante...
t = int(input()) for i in range(t): d,v,l,r = list(map(int, input().split())) ans = d // v ans -= r//v - (l-1)//v print(ans)
[{"input": "1\n3 4 3 3\n", "output": "0\n"}, {"input": "1\n2 5 1 1\n", "output": "0\n"}, {"input": "3\n1 1 1 1\n2 3 1 2\n4 4 3 4\n", "output": "0\n0\n0\n"}, {"input": "1\n8 5 1 5\n", "output": "0\n"}, {"input": "1\n12599 3 1 2\n", "output": "4199\n"}, {"input": "10\n10 1 1 1\n10 1 1 2\n10 1 1 3\n10 1 1 4\n10 1 1 5\n10 ...
introductory
9,346
0.1
[ 0.7, 0.55, 0.5, 0.4, 0.25, 0.25, 0.2, 0.15, 0.1, 0.1 ]
German mathematician Christian Goldbach (1690-1764) [conjectured](https://en.wikipedia.org/wiki/Goldbach%27s_conjecture) that every even number greater than 2 can be represented by the sum of two prime numbers. For example, `10` can be represented as `3+7` or `5+5`. Your job is to make the function return a list conta...
import math def goldbach_partitions(n): def is_prime(x): for i in range(2, int(math.sqrt(x))+1): if x % i == 0: return False return True if n % 2: return [] ret = [] for first in range(2, n//2 + 1): if is_prime(first): second = n - first ...
[{"input": [594], "output": [["7+587", "17+577", "23+571", "31+563", "37+557", "47+547", "53+541", "71+523", "73+521", "103+491", "107+487", "127+467", "131+463", "137+457", "151+443", "163+431", "173+421", "193+401", "197+397", "211+383", "227+367", "241+353", "257+337", "263+331", "277+317", "281+313", "283+311"]]}, ...
introductory
3,756
0
[ 0, 0, 0, 0, 0, 0, 0 ]
During the quarantine, Sicromoft has more free time to create the new functions in "Celex-2021". The developers made a new function GAZ-GIZ, which infinitely fills an infinite table to the right and down from the upper left corner as follows: [Image] The cell with coordinates $(x, y)$ is at the intersection of $x$-t...
import sys input = sys.stdin.readline t = int(input()) out = [] for _ in range(t): a, b, c, d = list(map(int, input().split())) dX = c - a dY = d - b out.append(dX * dY + 1) print('\n'.join(map(str,out)))
[{"input": "1\n118730819 699217111 995255402 978426672\n", "output": "244734044025138064\n"}, {"input": "4\n1 1 2 2\n1 2 2 4\n179 1 179 100000\n5 7 5 7\n", "output": "2\n3\n1\n1\n"}, {"input": "2\n57 179 1329 2007\n179 444 239 1568\n", "output": "2325217\n67441\n"}, {"input": "1\n1 1 3 6\n", "output": "11\n"}]
interview
7,350
0
[ 0.1, 0.05, 0, 0 ]
Given is a tree T with N vertices. The i-th edge connects Vertex A_i and B_i (1 \leq A_i,B_i \leq N). Now, each vertex is painted black with probability 1/2 and white with probability 1/2, which is chosen independently from other vertices. Then, let S be the smallest subtree (connected subgraph) of T containing all the...
from sys import stdin, setrecursionlimit from collections import deque setrecursionlimit(10 ** 9) INF = 1 << 60 MOD = 1000000007 N = int(input()) G = [[] for _ in range(N)] for _ in range(N - 1): a, b = list(map(int, input().split())) G[a - 1].append(b - 1) G[b - 1].append(a - 1) pow2 = [1] * (N + 1) fo...
[{"input": "7\n4 7\n3 1\n2 6\n5 2\n7 1\n2 7\n", "output": "570312505\n"}, {"input": "4\n1 2\n2 3\n3 4\n", "output": "375000003\n"}, {"input": "4\n1 2\n1 3\n1 4\n", "output": "250000002\n"}, {"input": "3\n1 2\n2 3\n", "output": "125000001\n"}]
interview
7,378
0
[ 0, 0, 0, 0 ]
We are still with squared integers. Given 4 integers `a, b, c, d` we form the sum of the squares of `a` and `b` and then the sum of the squares of `c` and `d`. We multiply the two sums hence a number `n` and we try to decompose `n` in a sum of two squares `e` and `f` (e and f integers >= 0) so that `n = e² + f²`. Mo...
def prod2sum(a, b, c, d): e = sorted([abs(a*d-b*c), abs(a*c+b*d)]) f = sorted([abs(a*c-b*d), abs(a*d+b*c)]) if e == f: return [e] else: return sorted([e, f])
[{"input": [7, 96, -1, 81], "output": [[[471, 7783], [663, 7769]]]}, {"input": [2, 3, 4, 5], "output": [[[2, 23], [7, 22]]]}, {"input": [112, 0, 0, 1], "output": [[[0, 112]]]}, {"input": [100, 100, 100, 100], "output": [[[0, 20000]]]}, {"input": [10, 11, 12, 13], "output": [[[2, 263], [23, 262]]]}, {"input": [1, 20, -4...
introductory
2,651
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
There are $n$ startups. Startups can be active or acquired. If a startup is acquired, then that means it has exactly one active startup that it is following. An active startup can have arbitrarily many acquired startups that are following it. An active startup cannot follow any other startup. The following steps happe...
m = 1000000007 n = int(input()) a = list(map(int, input().split())) print(pow(2,n-1,m)-1 - sum(pow(2,a.count(x),m)-1 for x in set(a) if x != -1) % m)
[{"input": "2\n2 -1\n", "output": "0\n"}, {"input": "3\n-1 -1 -1\n", "output": "3\n"}, {"input": "8\n-1 3 -1 -1 -1 3 -1 -1\n", "output": "124\n"}, {"input": "50\n36 36 45 44 -1 -1 13 -1 36 -1 44 36 -1 -1 -1 35 -1 36 36 35 -1 -1 -1 14 36 36 22 36 13 -1 35 -1 35 36 -1 -1 13 13 45 36 14 -1 36 -1 -1 -1 22 36 -1 13\n", "out...
competition
2,131
0
[ 0.1, 0.05, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Vanya wants to pass n exams and get the academic scholarship. He will get the scholarship if the average grade mark for all the exams is at least avg. The exam grade cannot exceed r. Vanya has passed the exams and got grade a_{i} for the i-th exam. To increase the grade for the i-th exam by 1 point, Vanya must write b_...
import sys n,r,avg=list(map(int,input().split())) L=[] tot=0 for i in range(n): L.append(list(map(int,input().split()))) L[i][0],L[i][1]=L[i][1],L[i][0] tot+=L[i][1] L[i][1]=r-L[i][1] req=avg*n L.sort() ind=0 ans=0 while(ind<n and req>tot): diff=req-tot if(L[ind][1]>=diff): ans+=diff*L[i...
[{"input": "1 1 1\n1 1\n", "output": "0\n"}, {"input": "2 5 4\n5 2\n5 2\n", "output": "0\n"}, {"input": "1 2 1\n2 2\n", "output": "0\n"}, {"input": "2 1000000 1000000\n1 1000000\n1 1000000\n", "output": "1999998000000\n"}, {"input": "2 100000 100000\n1 1000000\n1 1000000\n", "output": "199998000000\n"}, {"input": "1 10...
interview
6,558
0
[ 0.4, 0.35, 0.35, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0, 0, 0, 0, 0 ]
Let's call some square matrix with integer values in its cells palindromic if it doesn't change after the order of rows is reversed and it doesn't change after the order of columns is reversed. For example, the following matrices are palindromic: $\left[ \begin{array}{l l l}{1} & {3} & {1} \\{3} & {1} & {3} \\{1} & {3...
n=int(input()) a=list(map(int,input().split())) c=[0]*1001 for i in range (len(a)): c[a[i]]+=1 sym=0 sin=0 for i in range (1001): sym+=(c[i]//4) if(c[i]%2==1): sin+=1 if(n%2==0 and sym==((n*n)//4)): mat= [([0]*(n//2)) for i in range (n//2)] ar=[] for i in range (1001): while(c[i]>=4): ar.append(i) ...
[{"input": "1\n10\n", "output": "YES\n10 \n"}, {"input": "7\n1 8 9 6 4 7 4 3 5 5 4 2 1 8 10 7 7 7 8 8 1 10 1 4 6 2 2 1 6 9 6 1 6 4 8 10 4 4 7 3 4 7 10 2 2 9 4 3 3\n", "output": "NO\n"}, {"input": "5\n1 1 1 1 2 2 7 7 3 3 3 3 3 3 4 4 4 4 4 4 4 5 5 6 6\n", "output": "NO\n"}, {"input": "5\n1 1 1 1 2 2 2 2 3 3 3 3 100 11 11...
introductory
9,038
0
[ 0.45, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.35, 0.25, 0.2, 0.15, 0.15, 0.1, 0.1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Happy new year! The year 2020 is also known as Year Gyeongja (경자년, gyeongja-nyeon) in Korea. Where did the name come from? Let's briefly look at the Gapja system, which is traditionally used in Korea to name the years. There are two sequences of $n$ strings $s_1, s_2, s_3, \ldots, s_{n}$ and $m$ strings $t_1, t_2, t_3...
input = __import__('sys').stdin.readline MIS = lambda: map(int,input().split()) n, m = MIS() A = input().split() B = input().split() for TEST in range(int(input())): y = int(input())-1 print(A[y%len(A)] + B[y%len(B)])
[{"input": "1 1\na\na\n1\n1\n", "output": "aa\n"}, {"input": "2 6\na a\nb b c d e f\n1\n3\n", "output": "ac\n"}, {"input": "5 2\na b c d e\nhola mundo\n1\n5\n", "output": "ehola\n"}, {"input": "4 4\na b c b\na b c b\n1\n3\n", "output": "cc\n"}, {"input": "12 10\nyu sul hae ja chuk in myo jin sa o mi sin\nsin im gye gap...
interview
7,105
0.15
[ 0.5, 0.25, 0.15, 0.15, 0.15, 0.15, 0.15 ]
Do you know a story about the three musketeers? Anyway, you will learn about its origins now. Richelimakieu is a cardinal in the city of Bearis. He is tired of dealing with crime by himself. He needs three brave warriors to help him to fight against bad guys. There are n warriors. Richelimakieu wants to choose three ...
#!/usr/bin/env python3 # -*- coding: utf-8 -*- # AUTHOR: haya14busa import sys import io from collections import defaultdict from itertools import combinations def solve(n, m, pairs): # return: minimum possible sum of their recognitions assert 3 <= n <= 4000 # number of warioor assert 0 <= m <= 4000 # ...
[{"input": "3 2\n2 3\n2 1\n", "output": "-1\n"}, {"input": "7 4\n2 1\n3 6\n5 1\n1 7\n", "output": "-1\n"}, {"input": "5 0\n", "output": "-1\n"}, {"input": "3 0\n", "output": "-1\n"}, {"input": "4000 0\n", "output": "-1\n"}, {"input": "3 3\n3 1\n3 2\n2 1\n", "output": "0\n"}, {"input": "8 10\n1 5\n4 1\n1 2\n2 8\n2 7\n6 ...
interview
6,574
0.05
[ 0.35, 0.3, 0.25, 0.25, 0.2, 0.2, 0.15, 0.15, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.05 ]
Alexander is a well-known programmer. Today he decided to finally go out and play football, but with the first hit he left a dent on the new Rolls-Royce of the wealthy businessman Big Vova. Vladimir has recently opened a store on the popular online marketplace "Zmey-Gorynych", and offers Alex a job: if he shows his pro...
import sys input = sys.stdin.readline from math import gcd t = int(input()) for _ in range(t): n = int(input()) l = list(map(int, input().split())) g = max(l) out = [] while l: nex = max((gcd(g,l[i]), i) for i in range(len(l))) out.append(l.pop(nex[1])) g = nex[0] print...
[{"input": "7\n2\n2 5\n4\n1 8 2 3\n3\n3 8 9\n5\n64 25 75 100 50\n1\n42\n6\n96 128 88 80 52 7\n5\n2 4 8 16 17\n", "output": "5 2 \n8 2 1 3 \n9 3 8 \n100 50 25 75 64 \n42 \n128 96 80 88 52 7 \n17 2 4 8 16 \n"}, {"input": "1\n32\n660 510 840 483 805 140 280 476 474 70 120 728 449 210 111 645 105 580 420 84 798 520 132 168...
interview
7,339
0
[ 0, 0, 0, 0 ]
Transpose means is to interchange rows and columns of a two-dimensional array matrix. [A^(T)]ij=[A]ji ie: Formally, the i th row, j th column element of AT is the j th row, i th column element of A: Example : ``` [[1,2,3],[4,5,6]].transpose() //should return [[1,4],[2,5],[3,6]] ``` Write a prototype transpose to...
import numpy as np def transpose(A): if len(A) == 0: return [] return np.array(A, dtype = 'O').T.tolist() if len(A[0]) > 0 else [[]]
[{"input": [[]], "output": [[]]}, {"input": [[[true, false, true], [false, true, false]]], "output": [[[true, false], [false, true], [true, false]]]}, {"input": [[[]]], "output": [[[]]]}, {"input": [[[], [], [], [], [], []]], "output": [[[]]]}, {"input": [[[1]]], "output": [[[1]]]}, {"input": [[[1], [2], [3], [4], [5],...
introductory
3,064
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Masha wants to open her own bakery and bake muffins in one of the n cities numbered from 1 to n. There are m bidirectional roads, each of whose connects some pair of cities. To bake muffins in her bakery, Masha needs to establish flour supply from some storage. There are only k storages, located in different cities nu...
n,m,k = (int(i) for i in input().split()) r = [] for i in range(m): u,v,p = (int(i) for i in input().split()) r += [(p,u,v)] if k == 0: print(-1) return else: s = list(map(int,input().split())) sklad = [False]*n for i in range(len(s)): sklad[s[i]-1] = True ans = 10**10 ...
[{"input": "5 5 5\n1 2 1\n2 3 2\n3 4 3\n4 5 5\n1 5 6\n1 2 3 4 5\n", "output": "-1"}, {"input": "3 1 1\n1 2 3\n3\n", "output": "-1"}, {"input": "2 1 1\n1 2 1000000000\n1\n", "output": "1000000000"}, {"input": "10 10 3\n1 2 1000000000\n2 3 1000000000\n3 4 1000000000\n4 5 1000000000\n5 6 1000000000\n6 7 1000000000\n7 8 10...
interview
6,343
0
[ 0.2, 0.15, 0.15, 0.15, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05 ]
Given a rational number n ``` n >= 0, with denominator strictly positive``` - as a string (example: "2/3" in Ruby, Python, Clojure, JS, CS, Go) - or as two strings (example: "2" "3" in Haskell, Java, CSharp, C++, Swift) - or as a rational or decimal number (example: 3/4, 0.67 in R) - or two integers (Fortran) d...
from math import ceil from fractions import Fraction as F def decompose(n): f = F(n) ff = int(f) result = [str(ff)] if ff else [] f -= ff while f>0: x = F(1,int(ceil(f**-1))) f -= x result.append(str(x)) return result
[{"input": ["75/3"], "output": [["25"]]}, {"input": ["4/5"], "output": [["1/2", "1/4", "1/20"]]}, {"input": ["30/45"], "output": [["1/2", "1/6"]]}, {"input": ["3/4"], "output": [["1/2", "1/4"]]}, {"input": ["22/23"], "output": [["1/2", "1/3", "1/9", "1/83", "1/34362"]]}, {"input": ["2/8"], "output": [["1/4"]]}, {"input...
introductory
3,656
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
_A mad sociopath scientist just came out with a brilliant invention! He extracted his own memories to forget all the people he hates! Now there's a lot of information in there, so he needs your talent as a developer to automatize that task for him._ > You are given the memories as a string containing people's surname ...
def select(memory): lst = memory.split(', ') bad = {who.strip('!') for prev,who in zip(['']+lst,lst+['']) if who.startswith('!') or prev.startswith('!')} return ', '.join(who for who in map(lambda s: s.strip('!'), lst) if who not in bad)
[{"input": ["!Code Wars, !Doug Smith, !Cyril Lemaire, !Codin Game"], "output": [""]}, {"input": ["Jesse Cox, !Selena Gomez"], "output": ["Jesse Cox"]}, {"input": ["Digital Daggers, !Kiny Nimaj, Rack Istley, Digital Daggers, Digital Daggers"], "output": ["Digital Daggers, Digital Daggers, Digital Daggers"]}, {"input": [...
introductory
3,161
0
[ 0.95, 0, 0, 0, 0, 0, 0 ]
Takahashi the Jumbo will practice golf. His objective is to get a carry distance that is a multiple of K, while he can only make a carry distance of between A and B (inclusive). If he can achieve the objective, print OK; if he cannot, print NG. -----Constraints----- - All values in input are integers. - 1 \leq A \le...
k = int(input()) a,b = map(int,input().split()) for i in range(a,b+1): if i%k==0: print('OK') return print('NG')
[{"input": "5\n178 183\n", "output": "OK\n"}, {"input": "1\n11 11\n", "output": "OK\n"}, {"input": "7\n500 600\n", "output": "OK\n"}, {"input": "4\n5 7\n", "output": "NG\n"}, {"input": "379\n400 757\n", "output": "NG\n"}, {"input": "17\n629 629\n", "output": "OK\n"}, {"input": "166\n54 126\n", "output": "NG\n"}, {"inpu...
introductory
9,259
0.4
[ 0.75, 0.7, 0.65, 0.65, 0.65, 0.65, 0.65, 0.65, 0.6, 0.6, 0.55, 0.55, 0.5 ]
In his publication Liber Abaci Leonardo Bonacci, aka Fibonacci, posed a problem involving a population of idealized rabbits. These rabbits bred at a fixed rate, matured over the course of one month, had unlimited resources, and were immortal. Beginning with one immature pair of these idealized rabbits that produce b p...
def fib_rabbits(n, b): (i, a) = (1, 0) for m in range(n): (i, a) = (a * b, a + i) return a
[{"input": [9, 8], "output": [10233]}, {"input": [8, 12], "output": [8425]}, {"input": [7, 4], "output": [181]}, {"input": [6, 3], "output": [40]}, {"input": [40, 6], "output": [2431532871909060205]}, {"input": [4, 100], "output": [201]}, {"input": [4, 0], "output": [1]}, {"input": [11, 33], "output": [58212793]}, {"in...
introductory
2,779
0
[ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ]
Consider the array `[3,6,9,12]`. If we generate all the combinations with repetition that sum to `12`, we get `5` combinations: `[12], [6,6], [3,9], [3,3,6], [3,3,3,3]`. The length of the sub-arrays (such as `[3,3,3,3]` should be less than or equal to the length of the initial array (`[3,6,9,12]`). Given an array of...
from itertools import combinations_with_replacement def find(arr,n): return sum( sum(c) == n for x in range(1,len(arr)+1) for c in combinations_with_replacement(arr, x) )
[{"input": [[3, 6, 9, 12], 15], "output": [5]}, {"input": [[3, 6, 9, 12], 12], "output": [5]}, {"input": [[3, 6, 9, 12, 14, 18], 30], "output": [21]}, {"input": [[1, 4, 5, 8], 8], "output": [3]}, {"input": [[1, 2, 3], 7], "output": [2]}, {"input": [[1, 2, 3], 5], "output": [3]}, {"input": [[1, 2, 3], 10], "output": [0]...
introductory
2,848
0
[ 0, 0, 0, 0, 0, 0, 0 ]
Nikolay has a lemons, b apples and c pears. He decided to cook a compote. According to the recipe the fruits should be in the ratio 1: 2: 4. It means that for each lemon in the compote should be exactly 2 apples and exactly 4 pears. You can't crumble up, break up or cut these fruits into pieces. These fruits — lemons, ...
n1 = int( input() ) n2 = int( input() ) n3 = int( input() ) print( min( n1 , n2 // 2 , n3 // 4 ) * 7 )
[{"input": "2\n1\n8\n", "output": "0\n"}, {"input": "1\n1\n4\n", "output": "0\n"}, {"input": "2\n3\n2\n", "output": "0\n"}, {"input": "1\n2\n3\n", "output": "0\n"}, {"input": "1\n1\n1\n", "output": "0\n"}, {"input": "100\n1\n100\n", "output": "0\n"}, {"input": "1000\n1\n1000\n", "output": "0\n"}, {"input": "1000\n1000\...
interview
5,157
0.3
[ 0.6, 0.6, 0.55, 0.55, 0.55, 0.55, 0.55, 0.55, 0.35, 0.35, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, 0.3, ...
Polycarp has $n$ coins, the value of the $i$-th coin is $a_i$. Polycarp wants to distribute all the coins between his pockets, but he cannot put two coins with the same value into the same pocket. For example, if Polycarp has got six coins represented as an array $a = [1, 2, 4, 3, 3, 2]$, he can distribute the coins i...
def mi(): return map(int, input().split()) from collections import Counter n = list(mi())[0] a = Counter(list(mi())) ma= -1 for i in a: if a[i]>ma: ma = a[i] print (ma)
[{"input": "7\n1 2 3 3 3 1 2\n", "output": "3\n"}, {"input": "10\n1 2 2 3 3 3 4 4 4 4\n", "output": "4\n"}, {"input": "3\n95 95 4\n", "output": "2\n"}, {"input": "3\n58 59 58\n", "output": "2\n"}, {"input": "3\n2 2 5\n", "output": "2\n"}, {"input": "3\n2 1 1\n", "output": "2\n"}, {"input": "1\n100\n", "output": "1\n"},...
introductory
9,057
0
[ 0.8, 0.8, 0.75, 0.75, 0.75, 0.75, 0.65, 0.2, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05, 0, 0, 0, 0 ]
Consider the range `0` to `10`. The primes in this range are: `2, 3, 5, 7`, and thus the prime pairs are: `(2,2), (2,3), (2,5), (2,7), (3,3), (3,5), (3,7),(5,5), (5,7), (7,7)`. Let's take one pair `(2,7)` as an example and get the product, then sum the digits of the result as follows: `2 * 7 = 14`, and `1 + 4 = 5`. W...
import itertools def solve(a, b): primes = set([2] + [n for n in range(3, b, 2) if all(n % r for r in range(3, int(n**0.5)+1, 2))]) return sum( sum(map(int, str(x*y))) in primes for x, y in itertools.combinations_with_replacement([p for p in primes if a <= p < b], 2) )
[{"input": [2000, 5000], "output": [25005]}, {"input": [2, 200], "output": [457]}, {"input": [2, 2000], "output": [17705]}, {"input": [1000, 3000], "output": [12801]}, {"input": [0, 20], "output": [14]}]
introductory
4,311
0
[ 0, 0, 0, 0, 0 ]