problem
stringlengths
14
4.09k
solution
stringlengths
1
802k
task_type
stringclasses
3 values
problem_tokens
int64
5
895
Solve the programming task below in a Python markdown code block. Deoxyribonucleic acid (DNA) is a chemical found in the nucleus of cells and carries the "instructions" for the development and functioning of living organisms. If you want to know more http://en.wikipedia.org/wiki/DNA In DNA strings, symbols "A" and "T...
{"functional": "_inputs = [['AAAA'], ['ATTGC'], ['GTAT'], ['AAGG'], ['CGCG'], ['GTATCGATCGATCGATCGATTATATTTTCGACGAGATTTAAATATATATATATACGAGAGAATACAGATAGACAGATTA']]\n_outputs = [['TTTT'], ['TAACG'], ['CATA'], ['TTCC'], ['GCGC'], ['CATAGCTAGCTAGCTAGCTAATATAAAAGCTGCTCTAAATTTATATATATATATGCTCTCTTATGTCTATCTGTCTAAT']]\nimport ...
coding
208
Solve the programming task below in a Python markdown code block. Did you know you can download more RAM? There is a shop with $n$ different pieces of software that increase your RAM. The $i$-th RAM increasing software takes $a_i$ GB of memory to run (temporarily, once the program is done running, you get the RAM back)...
{"inputs": ["1\n1 1000\n1000\n1000\n", "4\n3 10\n20 30 10\n9 100 10\n5 1\n1 1 5 1 1\n1 1 1 1 1\n5 1\n2 2 2 2 2\n100 100 100 100 100\n5 8\n128 64 32 16 8\n128 64 32 16 8\n"], "outputs": ["2000\n", "29\n6\n1\n256\n"]}
coding
608
Solve the programming task below in a Python markdown code block. Kabir likes Tara's smile and wants to look at her smile. They are sitting in the class and you are friends with Kabir. You have to place a mirror (point size) in the front wall of the class so that Kabir can have a glimpse of Tara's smile. Consider the ...
{"inputs": ["1\n1 1\n4 4"], "outputs": ["1.60"]}
coding
321
Solve the programming task below in a Python markdown code block. There is a blackboard on which all integers from -10^{18} through 10^{18} are written, each of them appearing once. Takahashi will repeat the following sequence of operations any number of times he likes, possibly zero: * Choose an integer between 1 and...
{"inputs": ["14 4 24336", "20 4 24336", "20 4 13351", "3 3 9645713", "7 6 9645713", "4 1 2216083", "13 1 725909", "13 2 725909"], "outputs": ["6561\n", "10656\n", "347\n", "8\n", "120\n", "13\n", "3136\n", "714\n"]}
coding
394
Solve the programming task below in a Python markdown code block. 12:17 (UTC): The sample input 1 and 2 were swapped. The error is now fixed. We are very sorry for your inconvenience. There are N children in AtCoder Kindergarten, conveniently numbered 1 through N. Mr. Evi will distribute C indistinguishable candies to ...
{"inputs": ["1 2\n1\n4", "1 4\n1\n4", "1 3\n1\n3", "1 4\n1\n1", "1 3\n1\n5", "1 4\n1\n2", "1 3\n1\n9", "1 1\n1\n4"], "outputs": ["30\n", "354\n", "36\n", "1\n", "225\n", "17\n", "2025\n", "10\n"]}
coding
622
Solve the programming task below in a Python markdown code block. This is the easier version of the problem. In this version, $1 \le n \le 10^5$ and $0 \le a_i \le 1$. You can hack this problem only if you solve and lock both problems. Christmas is coming, and our protagonist, Bob, is preparing a spectacular present f...
{"inputs": ["1\n1\n", "1\n1\n", "3\n1 0 1\n", "3\n0 0 1\n", "3\n0 0 1\n", "3\n0 1 0\n", "3\n1 1 1\n", "3\n0 1 1\n"], "outputs": ["-1\n", "-1", "2\n", "-1\n", "-1", "-1\n", "2\n", "1\n"]}
coding
514
Solve the programming task below in a Python markdown code block. There is a hallway of length $N-1$ and you have $M$ workers to clean the floor. Each worker is responsible for segment $[L_{i}, R_{i}]$, i.e., the segment starting at $L_{i}$ and ending at $R_{i}$. The segments might overlap. Every unit of length of th...
{"inputs": ["3\n10 3\n1 10\n1 5\n6 10\n10 1\n2 10\n10 2\n5 10\n1 5"], "outputs": ["3\n-1\n5"]}
coding
630
Solve the programming task below in a Python markdown code block. The Little Elephant has got a problem — somebody has been touching his sorted by non-decreasing array a of length n and possibly swapped some elements of the array. The Little Elephant doesn't want to call the police until he understands if he could hav...
{"inputs": ["2\n1 1\n", "2\n2 1\n", "2\n2 2\n", "2\n1 2\n", "3\n2 1 1\n", "3\n1 3 2\n", "3\n3 1 2\n", "3\n2 3 1\n"], "outputs": ["YES", "YES", "YES\n", "YES", "YES", "YES", "NO", "NO"]}
coding
388
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a binary string s, and a 2D integer array queries where queries[i] = [firsti, secondi]. For the ith query, find the shortest substring of s whose decimal value, val, yields secondi when bitwise XORed wit...
{"functional": "def check(candidate):\n assert candidate(s = \"101101\", queries = [[0,5],[1,2]]) == [[0,2],[2,3]]\n assert candidate(s = \"0101\", queries = [[12,8]]) == [[-1,-1]]\n assert candidate(s = \"1\", queries = [[4,5]]) == [[0,0]]\n\n\ncheck(Solution().substringXorQueries)"}
coding
215
Please solve the programming task below using a self-contained code snippet in a markdown code block. In an alien language, surprisingly, they also use English lowercase letters, but possibly in a different order. The order of the alphabet is some permutation of lowercase letters. Given a sequence of words written in ...
{"functional": "def check(candidate):\n assert candidate(words = [\"hello\",\"leetcode\"], order = \"hlabcdefgijkmnopqrstuvwxyz\") == True\n assert candidate(words = [\"word\",\"world\",\"row\"], order = \"worldabcefghijkmnpqstuvxyz\") == False\n assert candidate(words = [\"apple\",\"app\"], order = \"abcdefgh...
coding
124
Solve the programming task below in a Python markdown code block. If this challenge is too easy for you, check out: https://www.codewars.com/kata/5cc89c182777b00001b3e6a2 ___ Upside-Down Pyramid Addition is the process of taking a list of numbers and consecutively adding them together until you reach one number. Wh...
{"functional": "_inputs = [[[5, 2, 1]], [[84, 42, 21, 10, 2]], [[83, 47, 28, 16, 7]], [[101, 57, 29, 13, 6]], [[66, 39, 25, 15, 7]], [[45, 25, 14, 8, 6]], [[60, 32, 16, 7, 4]], [[84, 44, 21, 8, 2]], [[51, 26, 13, 6, 2]], [[78, 42, 22, 11, 6]]]\n_outputs = [[[2, 1, 1]], [[4, 7, 3, 8, 2]], [[6, 4, 3, 9, 7]], [[1, 3, 9, 7...
coding
237
Solve the programming task below in a Python markdown code block. Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Arya has a chessboard with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$); a square in row $r$ and column $c$ is denoted by $...
{"inputs": ["2\n4 2\n1 4\n2 2\n4 0"], "outputs": ["2 3 1 4 3\n4 1 1 2 2 3 3 4 4"]}
coding
679
Solve the programming task below in a Python markdown code block. Xorgon is an extremely delicious treat formed by the sequence $S$ of binary integers $s_1, s_2,..,s_N$. A really interesting property found in a Xorgon is that the xor of all elements in any contiguous subsequence of length $K$ in $S$ will result in $1$....
{"inputs": ["7 5\n1 0 0 1 1 1 1"], "outputs": ["1"]}
coding
375
Solve the programming task below in a Python markdown code block. Give me Biscuit Sunny wants to make slices of biscuit of size c * d into identical pieces. but each piece is a square having maximum possible side length with no left over piece of biscuit. Input Format The first line contains an integer N. N lines ...
{"inputs": ["2\n2 2\n6 9"], "outputs": ["1\n6"]}
coding
279
Solve the programming task below in a Python markdown code block. You are given a tree with N vertices. Here, a tree is a kind of graph, and more specifically, a connected undirected graph with N-1 edges, where N is the number of its vertices. The i-th edge (1≤i≤N-1) connects Vertices a_i and b_i, and has a length of...
{"inputs": ["5\n1 2 1\n1 3 1\n2 4 1\n3 5 2\n3 1\n2 4\n2 3\n4 5", "5\n1 2 1\n1 3 1\n2 4 1\n3 5 1\n3 1\n2 3\n2 3\n4 5", "5\n1 2 1\n1 3 2\n2 4 1\n3 5 1\n3 1\n2 3\n2 3\n4 4", "5\n1 2 1\n2 3 2\n2 4 1\n3 5 1\n3 1\n2 3\n2 3\n4 4", "5\n1 2 2\n1 3 1\n2 4 1\n3 5 1\n3 1\n2 4\n2 3\n4 5", "5\n1 2 1\n1 3 1\n2 4 1\n3 5 1\n3 1\n2 4\n2...
coding
521
Solve the programming task below in a Python markdown code block. You are given an array A consisting of N integers. In one operation, you can: Choose any two indices i and j (i \neq j); Subtract min(A_{i} , A_{j}) from both A_{i} and A_{j}. Note that min(A_{i} , A_{j}) denotes the minimum of A_{i} and A_{j}. Determi...
{"inputs": ["3\n2\n1 1 \n3 \n1 3 1\n4\n1 3 1 3\n"], "outputs": ["1\n1 2\n-1\n2\n1 3\n2 4"]}
coding
680
Solve the programming task below in a Python markdown code block. Most football fans love it for the goals and excitement. Well, this Kata doesn't. You are to handle the referee's little notebook and count the players who were sent off for fouls and misbehavior. The rules: Two teams, named "A" and "B" have 11 players ...
{"functional": "_inputs = [[[]], [['A4Y', 'A4Y']], [['A4Y', 'A4R']], [['A4Y', 'A5R', 'B5R', 'A4Y', 'B6Y']], [['A4R', 'A4R', 'A4R']], [['A4R', 'A2R', 'A3R', 'A6R', 'A8R', 'A10R', 'A11R']]]\n_outputs = [[[11, 11]], [[10, 11]], [[10, 11]], [[9, 10]], [[10, 11]], [[6, 11]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n ...
coding
358
Solve the programming task below in a Python markdown code block. ``` ************************* * Create a frame! * * __ __ * * / \~~~/ \ * * ,----( .. ) * * / \__ __/ * * /| (\ |( * * ^ \ /___\ /\ | * * |__| |__|-.. * ****************...
{"functional": "_inputs = [[['Small', 'frame'], '~'], [['Create', 'this', 'kata'], '+'], [['This is a very long single frame'], '-']]\n_outputs = [['~~~~~~~~~\\n~ Small ~\\n~ frame ~\\n~~~~~~~~~'], ['++++++++++\\n+ Create +\\n+ this +\\n+ kata +\\n++++++++++'], ['------------------------------------\\n- This is a v...
coding
226
Solve the programming task below in a Python markdown code block. I'm new to coding and now I want to get the sum of two arrays...actually the sum of all their elements. I'll appreciate for your help. P.S. Each array includes only integer numbers. Output is a number too. Also feel free to reuse/extend the following st...
{"functional": "_inputs = [[[1, 2, 3], [4, 5, 6]], [[-1, -2, -3], [-4, -5, -6]], [[0, 0, 0], [4, 5, 6]], [[100, 200, 300], [400, 500, 600]]]\n_outputs = [[21], [-21], [15], [2100]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_to...
coding
86
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an m x n grid. Each cell of grid represents a street. The street of grid[i][j] can be: 1 which means a street connecting the left cell and the right cell. 2 which means a street connecting the upper cel...
{"functional": "def check(candidate):\n assert candidate(grid = [[2,4,3],[6,5,2]]) == True\n assert candidate(grid = [[1,2,1],[1,2,1]]) == False\n assert candidate(grid = [[1,1,2]]) == False\n assert candidate(grid = [[1,1,1,1,1,1,3]]) == True\n assert candidate(grid = [[2],[2],[2],[2],[2],[2],[6]]) == T...
coding
254
Solve the programming task below in a Python markdown code block. In HackerLand, they have a very strange monetary system. Each gold coin has an integer number 'N' written on it. A coin N can be split into any number of coins. For example {11} can be split into {5,6} or {2,4,5} or any other possible way. You are offer...
{"inputs": ["30\n1\n8566\n6308\n41\n5680\n4427\n2739\n77\n6274\n3601\n7506\n8951\n5345\n3\n9621\n9300\n23\n720\n2151\n7854\n3607\n256\n6076\n9369\n1729\n8229\n205\n980\n4197\n1460"], "outputs": ["1\n1\n1\n2\n1\n1\n1\n1\n1\n1\n1\n2\n1\n3\n1\n1\n2\n1\n1\n1\n2\n1\n1\n1\n1\n1\n1\n1\n1\n1\n"]}
coding
314
Solve the programming task below in a Python markdown code block. You may have helped Chef and prevented Doof from destroying the even numbers. But, it has only angered Dr Doof even further. However, for his next plan, he needs some time. Therefore, Doof has built $N$ walls to prevent Chef from interrupting him. You ha...
{"inputs": ["1\n2\n1 3\n5\n0 0\n2 0\n0 4\n1 1\n1 2"], "outputs": ["0\n1\n2\n1\n-1"]}
coding
710
Solve the programming task below in a Python markdown code block. My grandfather always predicted how old people would get, and right before he passed away he revealed his secret! In honor of my grandfather's memory we will write a function using his formula! * Take a list of ages when each of your great-grandparent ...
{"functional": "_inputs = [[65, 60, 75, 55, 60, 63, 64, 45], [32, 54, 76, 65, 34, 63, 64, 45]]\n_outputs = [[86], [79]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ...
coding
275
Solve the programming task below in a Python markdown code block. Spring has come, and the management of the AvtoBus bus fleet has given the order to replace winter tires with summer tires on all buses. You own a small bus service business and you have just received an order to replace $n$ tires. You know that the bus...
{"inputs": ["1\n25000\n", "4\n4\n7\n24\n998244353998244352\n"], "outputs": ["4167 6250\n", "1 1\n-1\n4 6\n166374058999707392 249561088499561088\n"]}
coding
542
Solve the programming task below in a Python markdown code block. These days Arkady works as an air traffic controller at a large airport. He controls a runway which is usually used for landings only. Thus, he has a schedule of planes that are landing in the nearest future, each landing lasts $1$ minute. He was asked ...
{"inputs": ["1 1\n0 0\n", "1 5\n1 0\n", "1 2\n3 0\n", "1 5\n0 6\n", "1 2\n2 3\n", "1 2\n2 3\n", "1 1\n0 0\n", "1 2\n3 0\n"], "outputs": ["0 2\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 2\n", "0 0\n"]}
coding
597
Solve the programming task below in a Python markdown code block. The chef was searching for his pen in the garage but he found his old machine with a display and some numbers on it. If some numbers entered then some different output occurs on the display. Chef wants to crack the algorithm that the machine is following...
{"inputs": ["1\n7"], "outputs": ["21"]}
coding
207
Solve the programming task below in a Python markdown code block. Write a function that when given a URL as a string, parses out just the domain name and returns it as a string. For example: ```python domain_name("http://github.com/carbonfive/raygun") == "github" domain_name("http://www.zombie-bites.com") == "zombie-b...
{"functional": "_inputs = [['http://google.com'], ['http://google.co.jp'], ['https://123.net'], ['https://hyphen-site.org'], ['http://codewars.com'], ['www.xakep.ru'], ['https://youtube.com'], ['http://www.codewars.com/kata/'], ['icann.org']]\n_outputs = [['google'], ['google'], ['123'], ['hyphen-site'], ['codewars'], ...
coding
120
Solve the programming task below in a Python markdown code block. There are N cities in a row. The i-th city from the left has a sadness of A_{i}. In an attempt to reduce the sadness of the cities, you can send [blimps] from the left of city 1 that move rightwards (i.e, a blimp crosses cities 1, 2, \ldots in order) Y...
{"inputs": ["3\n4 4 4\n1 5 4 4\n5 4 3\n1 4 3 3 5\n4 3 1\n3 1 3 9"], "outputs": ["2\n2\n3\n"]}
coding
734
Solve the programming task below in a Python markdown code block. Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well. Oh, these difficult contests... In each contest, there are so many hard tasks Chef cannot solve. However, he knows that he can only become a successf...
{"inputs": ["1\n5 7"], "outputs": ["YES"]}
coding
576
Solve the programming task below in a Python markdown code block. The pair of integer numbers `(m, n)`, such that `10 > m > n > 0`, (below 10), that its sum, `(m + n)`, and rest, `(m - n)`, are perfect squares, is (5, 4). Let's see what we have explained with numbers. ``` 5 + 4 = 9 = 3² 5 - 4 = 1 = 1² (10 > 5 > 4 > 0...
{"functional": "_inputs = [[10], [30], [50], [100], [150], [200]]\n_outputs = [[[5, 4]], [[29, 20]], [[45, 36]], [[97, 72]], [[149, 140]], [[197, 28]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if i...
coding
471
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return the number of distinct non-empty subsequences of s. Since the answer may be very large, return it modulo 109 + 7. A subsequence of a string is a new string that is formed from the original str...
{"functional": "def check(candidate):\n assert candidate(s = \"abc\") == 7\n assert candidate(s = \"aba\") == 6\n assert candidate(s = \"aaa\") == 3\n\n\ncheck(Solution().distinctSubseqII)"}
coding
146
Solve the programming task below in a Python markdown code block. Dreamoon is a big fan of the Codeforces contests. One day, he claimed that he will collect all the places from $1$ to $54$ after two more rated contests. It's amazing! Based on this, you come up with the following problem: There is a person who partic...
{"inputs": ["1\n1 5\n6\n", "1\n1 1\n2\n", "1\n1 1\n2\n", "1\n1 5\n6\n", "1\n1 9\n6\n", "1\n1 3\n6\n", "1\n1 3\n9\n", "1\n1 5\n4\n"], "outputs": ["6\n", "2\n", "2\n", "6\n", "10\n", "3\n", "3\n", "6\n"]}
coding
652
Solve the programming task below in a Python markdown code block. In recreational mathematics, a magic square is an arrangement of distinct numbers (i.e., each number is used once), usually integers, in a square grid, where the numbers in each row, and in each column, and the numbers in the main and secondary diagonals...
{"functional": "_inputs = [[[4, 9, 2, 3, 5, 7, 8, 1, 6]], [[4, 9, 2, 3, 5, 7, 8, 6, 1]], [[1, 2, 3, 4, 5, 6, 7, 8, 9]], [[9, 4, 7, 3, 5, 2, 8, 6, 1]], [[8, 1, 6, 3, 5, 7, 4, 9, 2]]]\n_outputs = [[True], [False], [False], [False], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinst...
coding
445
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, return all the numbers in the range [1, n] sorted in lexicographical order. You must write an algorithm that runs in O(n) time and uses O(1) extra space.    Please complete the following python cod...
{"functional": "def check(candidate):\n assert candidate(n = 13) == [1,10,11,12,13,2,3,4,5,6,7,8,9]\n assert candidate(n = 2) == [1,2]\n\n\ncheck(Solution().lexicalOrder)"}
coding
96
Solve the programming task below in a Python markdown code block. The range search problem consists of a set of attributed records S to determine which records from S intersect with a given range. For n points on a plane, report a set of points which are within in a given range. Note that you do not need to consider i...
{"inputs": ["6\n2 1\n2 2\n4 2\n6 2\n3 6\n5 4\n2\n2 4 0 4\n4 10 2 5", "6\n2 1\n2 2\n4 2\n6 4\n3 6\n5 4\n2\n2 4 0 4\n4 10 4 5", "6\n2 1\n2 2\n5 1\n6 4\n3 6\n5 4\n2\n2 4 0 4\n4 10 4 5", "6\n0 1\n2 2\n5 1\n6 4\n3 6\n5 4\n2\n2 4 0 4\n4 10 4 5", "6\n0 1\n2 2\n5 1\n6 4\n3 2\n5 4\n2\n2 4 0 4\n4 10 4 5", "6\n0 1\n2 2\n5 1\n6 4\...
coding
433
Solve the programming task below in a Python markdown code block. A soldier wants to buy w bananas in the shop. He has to pay k dollars for the first banana, 2k dollars for the second one and so on (in other words, he has to pay i·k dollars for the i-th banana). He has n dollars. How many dollars does he have to borr...
{"inputs": ["1 2 1\n", "1 1 1\n", "1 5 6\n", "1 5 6\n", "1 2 1\n", "1 1 1\n", "1 0 1\n", "3 0 4\n"], "outputs": ["0", "0", "16", "16\n", "0\n", "0\n", "1\n", "30\n"]}
coding
202
Solve the programming task below in a Python markdown code block. There is a contest containing 2 problems A and B. 2 strong participants P and Q participated in the contest and solved both the problems. P made AC submissions on problems A and B at time instants P_{A} and P_{B} respectively while Q made AC submissio...
{"inputs": ["4\n5 10 2 12\n10 30 15 15\n20 8 4 20\n6 6 6 6\n"], "outputs": ["P\nQ\nTIE\nTIE\n"]}
coding
571
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D integer array properties where properties[i] = [attacki, defensei] r...
{"functional": "def check(candidate):\n assert candidate(properties = [[5,5],[6,3],[3,6]]) == 0\n assert candidate(properties = [[2,2],[3,3]]) == 1\n assert candidate(properties = [[1,5],[10,4],[4,3]]) == 1\n\n\ncheck(Solution().numberOfWeakCharacters)"}
coding
172
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are playing a game with integers. You start with the integer 1 and you want to reach the integer target. In one move, you can either: Increment the current integer by one (i.e., x = x + 1). Double the current int...
{"functional": "def check(candidate):\n assert candidate(target = 5, maxDoubles = 0) == 4\n assert candidate(target = 19, maxDoubles = 2) == 7\n assert candidate(target = 10, maxDoubles = 4) == 4\n\n\ncheck(Solution().minMoves)"}
coding
169
Solve the programming task below in a Python markdown code block. # Introduction Hamsters are rodents belonging to the subfamily Cricetinae. The subfamily contains about 25 species, classified in six or seven genera. They have become established as popular small house pets, and, partly because they are easy to breed ...
{"functional": "_inputs = [['hamster', 'hamster'], ['hamster', 'helpme'], ['hmster', 'hamster'], ['hhhhammmstteree', 'hamster'], ['f', 'abcdefghijklmnopqrstuvwxyz']]\n_outputs = [['h1a1m1s1t1e1r1'], ['h1e1h5m4m1e1'], ['h1t8m1s1t1e1r1'], ['h1a1m1s1t1e1r1'], ['f22f23f24f25f26f1f2f3f4f5f6f7f8f9f10f11f12f13f14f15f16f17f18f...
coding
655
Solve the programming task below in a Python markdown code block. In this Kata you are expected to find the coefficients of quadratic equation of the given two roots (`x1` and `x2`). Equation will be the form of ```ax^2 + bx + c = 0``` Return type is a Vector (tuple in Rust, Array in Ruby) containing coefficients of ...
{"functional": "_inputs = [[0, 1], [4, 9], [2, 6], [-5, -4]]\n_outputs = [[[1, -1, 0]], [[1, -13, 36]], [[1, -8, 12]], [[1, 9, 20]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list,...
coding
303
Solve the programming task below in a Python markdown code block. Takahashi and Aoki will take N exams numbered 1 to N. They have decided to compete in these exams. The winner will be determined as follows: * For each exam i, Takahashi decides its importance c_i, which must be an integer between l_i and u_i (inclusive...
{"inputs": ["2 100\n85 2 6\n60 1 1", "2 100\n85 2 4\n60 1 1", "2 100\n85 2 3\n60 1 1", "2 100\n85 2 11\n60 1 1", "2 100\n85 2 3\n60 10 10", "1 100000\n3871 4175 1968", "1 100000\n5899 4175 1968", "1 100000\n31415 2718 1443"], "outputs": ["95\n", "100\n", "115", "91\n", "77", "3871\n", "5899\n", "31415\n"]}
coding
665
Solve the programming task below in a Python markdown code block. You are given a tree of $n$ vertices numbered from $1$ to $n$, with edges numbered from $1$ to $n-1$. A tree is a connected undirected graph without cycles. You have to assign integer weights to each edge of the tree, such that the resultant graph is a p...
{"inputs": ["3\n2\n1 2\n4\n1 3\n4 3\n2 1\n7\n1 2\n1 3\n3 4\n3 5\n6 2\n7 2\n"], "outputs": ["2 \n3 2 2 \n-1\n"]}
coding
690
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are working in a ball factory where you have n balls numbered from lowLimit up to highLimit inclusive (i.e., n == highLimit - lowLimit + 1), and an infinite number of boxes numbered from 1 to infinity. Your job at...
{"functional": "def check(candidate):\n assert candidate(lowLimit = 1, highLimit = 10) == 2\n assert candidate(lowLimit = 5, highLimit = 15) == 2\n assert candidate(lowLimit = 19, highLimit = 28) == 2\n\n\ncheck(Solution().countBalls)"}
coding
204
Solve the programming task below in a Python markdown code block. Given a sequence of numbers, find the largest pair sum in the sequence. For example ``` [10, 14, 2, 23, 19] --> 42 (= 23 + 19) [99, 2, 2, 23, 19] --> 122 (= 99 + 23) ``` Input sequence contains minimum two elements and every element is an integer. Al...
{"functional": "_inputs = [[[10, 14, 2, 23, 19]], [[-100, -29, -24, -19, 19]], [[1, 2, 3, 4, 6, -1, 2]], [[-10, -8, -16, -18, -19]]]\n_outputs = [[42], [0], [10], [-18]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_...
coding
136
Solve the programming task below in a Python markdown code block. 10^9 contestants, numbered 1 to 10^9, will compete in a competition. There will be two contests in this competition. The organizer prepared N problems, numbered 1 to N, to use in these contests. When Problem i is presented in a contest, it will be solve...
{"inputs": ["4\n4 7\n1 4\n5 8\n2 8", "4\n4 7\n1 4\n2 8\n2 8", "4\n2 0\n0 0\n8 1\n1 1", "4\n4 7\n1 4\n5 8\n2 5", "4\n4 12\n1 4\n2 8\n2 8", "4\n4 1\n1 4\n1 8\n2 10", "4\n5 2\n1 1\n2 12\n0 8", "4\n0 2\n2 1\n2 16\n0 4"], "outputs": ["7", "8", "1", "6", "12", "9", "11", "15"]}
coding
539
Solve the programming task below in a Python markdown code block. Write a program to determine if a string contains only unique characters. Return true if it does and false otherwise. The string may contain any of the 128 ASCII characters. Characters are case-sensitive, e.g. 'a' and 'A' are considered different charac...
{"functional": "_inputs = [[' nAa'], ['abcdef'], ['++-']]\n_outputs = [[False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len...
coding
91
Solve the programming task below in a Python markdown code block. There are N positive integers A_1, A_2, ..., A_N. Takahashi can perform the following operation on these integers any number of times: * Choose 1 \leq i \leq N and multiply the value of A_i by -2. Notice that he multiplies it by minus two. He would ...
{"inputs": ["4\n2 1 4 1", "4\n3 1 4 4", "4\n2 1 5 1", "4\n2 1 4 2", "4\n3 1 4 2", "4\n3 1 4 8", "4\n2 1 4 8", "4\n2 1 1 2"], "outputs": ["3\n", "1\n", "5\n", "3\n", "3\n", "1\n", "1\n", "1\n"]}
coding
312
Solve the programming task below in a Python markdown code block. Chef wants to gift his girlfriend a necklace made of beads. The beads can be made of either Stone, Glass, Quartz, Ruby or Diamond (he need not use all five types of beads) . Each bead has a value associated with its beauty as follows -2 for Stone -1 fo...
{"inputs": ["1 2 2 3 4\n3\n2 0\n1 -2\n3 6"], "outputs": ["4\n1\n12"]}
coding
487
Solve the programming task below in a Python markdown code block. The ABC number of a string T is the number of triples of integers (i, j, k) that satisfy all of the following conditions: - 1 ≤ i < j < k ≤ |T| (|T| is the length of T.) - T_i = A (T_i is the i-th character of T from the beginning.) - T_j = B - T_k =...
{"inputs": ["ABC\n", "AAA\n", "ACB\n", "???\n", "?C?\n", "?BC\n", "??AC", "A??C"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "1\n", "1\n", "8"]}
coding
505
Solve the programming task below in a Python markdown code block. Students are taught to add multi-digit numbers from right-to-left one digit at a time. Many find the "carry" operation - in which 1 is carried from one digit position to be added to the next - to be a significant challenge. Your job is to count the numb...
{"inputs": ["3\n123 456\n555 555\n123 594", "3\n5555555555 5555555555\n1111111111 1111111111\n5111111111 5111111111"], "outputs": ["No carry operation\n3 carry operations\n1 carry operation", "10 carry operations\nNo carry operation\n1 carry operation"]}
coding
264
Solve the programming task below in a Python markdown code block. Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky. The ticket is consider...
{"inputs": ["000000\n", "123456\n", "111000\n", "120111\n", "999999\n", "199880\n", "899889\n", "899888\n"], "outputs": ["0\n", "2\n", "1\n", "0\n", "0\n", "1\n", "1\n", "1\n"]}
coding
276
Solve the programming task below in a Python markdown code block. Given are N integers A_1,\ldots,A_N. We will choose exactly K of these elements. Find the maximum possible product of the chosen elements. Then, print the maximum product modulo (10^9+7), using an integer between 0 and 10^9+6 (inclusive). -----Constrain...
{"inputs": ["4 2\n1 2 -3 0", "4 2\n1 2 -3 -1", "4 4\n1 2 -3 -4", "4 2\n1 2 -4 -1", "4 2\n1 2 -3 -4", "4 2\n1 2 -3 -4\n", "4 2\n0 -3 -2 -1", "4 3\n-1 -3 -3 -4"], "outputs": ["2\n", "3\n", "24\n", "4\n", "12", "12\n", "6\n", "999999998\n"]}
coding
238
Solve the programming task below in a Python markdown code block. You are given an array (which will have a length of at least 3, but could be very large) containing integers. The array is either entirely comprised of odd integers or entirely comprised of even integers except for a single integer `N`. Write a method th...
{"functional": "_inputs = [[[0, 1, 2]], [[1, 2, 3]]]\n_outputs = [[1], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ...
coding
199
Solve the programming task below in a Python markdown code block. # Task Get the digits sum of `n`th number from the [Look-and-Say sequence](http://en.wikipedia.org/wiki/Look-and-say_sequence)(1-based). `1, 11, 21, 1211, 111221, 312211, 13112221, 1113213211, ...` # Input/Output `[input]` integer `n` `n`th number in...
{"functional": "_inputs = [[1], [2], [3], [4], [5]]\n_outputs = [[1], [2], [3], [5], [8]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): ret...
coding
308
Solve the programming task below in a Python markdown code block. The Berland University is preparing to celebrate the 256-th anniversary of its founding! A specially appointed Vice Rector for the celebration prepares to decorate the campus. In the center of the campus n ice sculptures were erected. The sculptures are ...
{"inputs": ["3\n-2 0 0\n", "3\n-2 1 0\n", "3\n-1 1 0\n", "3\n-1 0 0\n", "3\n-2 0 -1\n", "3\n-2 0 -2\n", "3\n-1 -1 -1\n", "3\n-2 -1 -1\n"], "outputs": ["-2\n", "-1\n", "0\n", "-1\n", "-3\n", "-4\n", "-3\n", "-4\n"]}
coding
452
Solve the programming task below in a Python markdown code block. Chan has decided to make a list of all possible combinations of letters of a given string S. If there are two strings with the same set of characters, print the lexicographically smallest arrangement of the two strings. abc acb cab bac bca all the abo...
{"inputs": ["2\n2\nab\n3\nxyz\n"], "outputs": ["a\nab\nb\nx\nxy\nxyz\nxz\ny\nyz\nz\n"]}
coding
300
Solve the programming task below in a Python markdown code block. In BerSoft $n$ programmers work, the programmer $i$ is characterized by a skill $r_i$. A programmer $a$ can be a mentor of a programmer $b$ if and only if the skill of the programmer $a$ is strictly greater than the skill of the programmer $b$ $(r_a > r...
{"inputs": ["2 0\n3 1\n", "2 0\n1 1\n", "2 0\n3 1\n", "2 0\n1 1\n", "2 0\n1 2\n", "2 0\n3 2\n", "2 0\n3 3\n", "2 0\n1 3\n"], "outputs": ["1 0 \n", "0 0 \n", "1 0 ", "0 0 ", "0 1\n", "1 0\n", "0 0\n", "0 1\n"]}
coding
673
Solve the programming task below in a Python markdown code block. Chef is on his way to become the new big bull of the stock market but is a bit weak at calculating whether he made a profit or a loss on his deal. Given that Chef bought the stock at value X and sold it at value Y. Help him calculate whether he made a p...
{"inputs": ["4\n4 2\n8 8\n3 4\n2 1\n"], "outputs": ["LOSS\nNEUTRAL\nPROFIT\nLOSS\n"]}
coding
372
Solve the programming task below in a Python markdown code block. While working at DTL, Ela is very aware of her physical and mental health. She started to practice various sports, such as Archery, Yoga, and Football. Since she started engaging in sports activities, Ela switches to trying a new sport on days she consi...
{"inputs": ["1\n200274443973227574 485348695690455822\n", "1\n999999999999999999 1000000000000000000\n", "5\n8 19\n8 20\n119 121\n1 100000000000000000\n1234567891011 1000000000000000000\n", "2\n747173626475907138 967354071062227214\n818273638681004942 983018368662317582\n", "2\n1000000000000000000 1000000000000000000\n...
coding
728
Solve the programming task below in a Python markdown code block. Manao is trying to open a rather challenging lock. The lock has n buttons on it and to open it, you should press the buttons in a certain order to open the lock. When you push some button, it either stays pressed into the lock (that means that you've gue...
{"inputs": ["2\n", "3\n", "4\n", "1\n", "4\n", "1\n", "5\n", "8\n"], "outputs": ["3\n", "7\n", "14\n", "1\n", "14\n", "1\n", "25\n", "92\n"]}
coding
404
Solve the programming task below in a Python markdown code block. A monster is attacking the Cyberland! Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF). During the battle, every second the monster's HP de...
{"inputs": ["1 1 1\n1 1 1\n1 1 1\n", "1 1 1\n1 1 1\n1 1 1\n", "1 2 1\n1 1 1\n1 1 1\n", "1 100 1\n1 1 1\n1 1 1\n", "1 100 1\n1 1 1\n1 1 1\n", "79 1 1\n1 1 10\n1 1 100\n", "79 1 1\n1 1 10\n1 1 100\n", "1 10 29\n1 1 43\n1 1 100\n"], "outputs": ["1\n", "1\n", "0\n", "0\n", "0\n", "10\n", "10\n", "34\n"]}
coding
476
Solve the programming task below in a Python markdown code block. Watson gives Sherlock an array $\mbox{A}$ of $N$ elements and two arrays $\mbox{B}$ and $\mbox{C}$, of $\mbox{M}$ elements each. Then he asks Sherlock to perform the following program: for i = 1 to M do for j = 1 to N do if j % B[i] == 0 the...
{"inputs": ["4 3\n1 2 3 4\n1 2 3\n13 29 71\n"], "outputs": ["13 754 2769 1508\n"]}
coding
369
Solve the programming task below in a Python markdown code block. There are N blocks, numbered 1, 2, \ldots, N. For each i (1 \leq i \leq N), Block i has a weight of w_i, a solidness of s_i and a value of v_i. Taro has decided to build a tower by choosing some of the N blocks and stacking them vertically in some order...
{"inputs": ["3\n2 2 20\n2 1 7\n3 1 40", "3\n2 3 20\n2 1 7\n3 1 40", "3\n3 5 20\n1 1 7\n3 1 40", "3\n2 2 20\n2 1 30\n3 1 47", "3\n2 2 20\n2 1 30\n3 2 47", "3\n2 2 20\n2 1 29\n3 2 47", "3\n2 2 20\n2 1 29\n3 4 47", "3\n4 2 20\n2 1 35\n3 0 71"], "outputs": ["40\n", "60\n", "67\n", "50\n", "77\n", "76\n", "96\n", "71\n"]}
coding
505
Solve the programming task below in a Python markdown code block. Nina has an $n\times n$ chessboard and $\boldsymbol{\mbox{k}}$ jumping rooks. Every cell of the chessboard is either blocked or free, and Nina can only put a single rook in any free cell. Two jumping rooks beat each other if they are either in the same...
{"inputs": ["3 4\n...\n...\n...\n", "5 10\n..#..\n..#..\n#####\n..#..\n..#..\n"], "outputs": ["2\n", "4\n"]}
coding
608
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node's key. The right su...
{"functional": "def check(candidate):\n assert candidate(root = tree_node([2,1,3])) == True\n assert candidate(root = tree_node([5,1,4,None,None,3,6])) == False\n\n\ncheck(Solution().isValidBST)"}
coding
178
Solve the programming task below in a Python markdown code block. Do you remember how Kai constructed the word "eternity" using pieces of ice as components? Little Sheldon plays with pieces of ice, each piece has exactly one digit between 0 and 9. He wants to construct his favourite number t. He realized that digits 6...
{"inputs": ["1\n1\n", "5\n2\n", "5\n2\n", "1\n1\n", "11\n1\n", "11\n1\n", "7\n777\n", "25\n52\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "0\n", "3\n", "1\n"]}
coding
296
Solve the programming task below in a Python markdown code block. This challenge is only forPython 2. input() In Python 2, the expression input() is equivalent to eval(raw _input(prompt)). Code >>> input() 1+2 3 >>> company = 'HackerRank' >>> website = 'www.hackerrank.com' >>> input() 'The company name: '+compan...
{"inputs": ["1 4\nx**3 + x**2 + x + 1\n"], "outputs": ["True\n"]}
coding
317
Solve the programming task below in a Python markdown code block. You are given two binary strings $S$ and $P$, each with length $N$. A binary string contains only characters '0' and '1'. For each valid $i$, let's denote the $i$-th character of $S$ by $S_i$. You have to convert the string $S$ into $P$ using zero or mor...
{"inputs": ["3\n2\n00\n00\n3\n101\n010\n4\n0110\n0011"], "outputs": ["Yes\nNo\nYes"]}
coding
551
Solve the programming task below in a Python markdown code block. Given an array A1,A2...AN, you have to print the size of the largest contiguous subarray such that GCD of all integers in that subarray is 1. Formally, For a subarray Ai,Ai+1...Aj where 1 ≤ i < j ≤ N to be valid: GCD(Ai,Ai+1...Aj) should be 1. You have...
{"inputs": ["2\n2\n7 2\n3\n2 2 4", "2\n2\n7 2\n3\n3 2 4", "2\n2\n7 2\n3\n6 2 4", "2\n2\n6 2\n3\n2 2 4", "2\n2\n6 2\n3\n2 3 4", "2\n2\n7 2\n2\n6 2 4", "2\n2\n7 1\n2\n6 2 4", "2\n2\n7 4\n3\n6 2 4"], "outputs": ["2\n-1", "2\n3\n", "2\n-1\n", "-1\n-1\n", "-1\n3\n", "2\n-1\n", "2\n-1\n", "2\n-1\n"]}
coding
299
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of strings wordsDict and two different strings that already exist in the array word1 and word2, return the shortest distance between these two words in the list.   Please complete the following python c...
{"functional": "def check(candidate):\n assert candidate(wordsDict = [\"practice\", \"makes\", \"perfect\", \"coding\", \"makes\"], word1 = \"coding\", word2 = \"practice\") == 3\n assert candidate(wordsDict = [\"practice\", \"makes\", \"perfect\", \"coding\", \"makes\"], word1 = \"makes\", word2 = \"coding\") ==...
coding
94
Solve the programming task below in a Python markdown code block. Fibonacci numbers have the following form: $\begin{aligned}F_1&-1\\ F_2&=1\\ F_3&=2\\ \vdots\\ F_n&=F_{n-2}+F_{n-1}\end{aligned}$ We have an array $a_1,a_2,\ldots,a_N$ which contains $N$ elements. We want to find $\text{gcd}(F_{a_1},F_{a_2},F_{a...
{"inputs": ["2\n3\n6\n", "3\n2\n3\n5\n"], "outputs": ["2\n", "1\n"]}
coding
356
Solve the programming task below in a Python markdown code block. # Task John was in math class and got bored, so he decided to fold some origami from a rectangular `a × b` sheet of paper (`a > b`). His first step is to make a square piece of paper from the initial rectangular piece of paper by folding the sheet along ...
{"functional": "_inputs = [[2, 1], [10, 7], [3, 1], [4, 1], [3, 2], [4, 2], [1000, 700], [1000, 999]]\n_outputs = [[2], [6], [3], [4], [3], [2], [6], [1000]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n ...
coding
397
Solve the programming task below in a Python markdown code block. There is an ice cream shop named Ten Ice Cream. At this store, we always have 10 types of ice cream on the shelves. The store manager creates a daily graph showing how well ice cream is selling for reference in product development. For such a store mana...
{"inputs": ["15\n2\n6\n7\n0\n1\n9\n8\n7\n3\n8\n9\n4\n8\n4\n2\n3\n9\n1\n5\n0", "15\n2\n6\n7\n0\n0\n9\n8\n7\n3\n8\n9\n4\n8\n2\n2\n3\n9\n1\n5\n0", "15\n2\n6\n7\n0\n1\n9\n8\n7\n3\n8\n9\n4\n8\n4\n2\n3\n9\n1\n2\n0", "15\n2\n6\n7\n0\n0\n9\n8\n7\n3\n8\n9\n8\n8\n2\n2\n3\n9\n1\n5\n0", "15\n2\n6\n7\n0\n1\n9\n8\n7\n3\n8\n9\n4\n8\n...
coding
366
Solve the programming task below in a Python markdown code block. A hostel has N rooms in a straight line. It has to accommodate X people. Unfortunately, out of these X people, Y of them are infected with chickenpox. Due to safety norms, the following precaution must be taken: No person should occupy a room directly a...
{"inputs": ["3\n4 0\n5 3\n3 3\n"], "outputs": ["4\n8\n5\n"]}
coding
497
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n availabe seats and n students standing in a room. You are given an array seats of length n, where seats[i] is the position of the ith seat. You are also given the array students of length n, where students...
{"functional": "def check(candidate):\n assert candidate(seats = [3,1,5], students = [2,7,4]) == 4\n assert candidate(seats = [4,1,5,9], students = [1,3,2,6]) == 7\n assert candidate(seats = [2,2,6,6], students = [1,3,2,6]) == 4\n\n\ncheck(Solution().minMovesToSeat)"}
coding
204
Solve the programming task below in a Python markdown code block. Monocarp wrote down two numbers on a whiteboard. Both numbers follow a specific format: a positive integer $x$ with $p$ zeros appended to its end. Now Monocarp asks you to compare these two numbers. Can you help him? -----Input----- The first line co...
{"inputs": ["1\n7 0\n1 1\n", "1\n7 0\n1 2\n", "1\n7 0\n2 2\n", "1\n15 0\n1 1\n", "1\n1 5\n101 3\n", "1\n105 0\n1 2\n", "1\n402 2\n4 4\n", "1\n4 4\n402 2\n"], "outputs": ["<\n", "<\n", "<\n", ">\n", "<\n", ">\n", ">\n", "<\n"]}
coding
391
Solve the programming task below in a Python markdown code block. # Task Given a string `s`, find out if its characters can be rearranged to form a palindrome. # Example For `s = "aabb"`, the output should be `true`. We can rearrange `"aabb"` to make `"abba"`, which is a palindrome. # Input/Output - `[input]`...
{"functional": "_inputs = [['aabb'], ['aaaaaaaaaaaaaaaaaaaaaaaaaaaaaabc'], ['abbcabb'], ['zyyzzzzz'], ['aaabbb']]\n_outputs = [[True], [False], [True], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_t...
coding
171
Solve the programming task below in a Python markdown code block. 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 th...
{"functional": "_inputs = [[[1, 2, 3], 10], [[1, 2, 3], 7], [[1, 2, 3], 5], [[3, 6, 9, 12], 12], [[1, 4, 5, 8], 8], [[3, 6, 9, 12], 15], [[3, 6, 9, 12, 14, 18], 30]]\n_outputs = [[0], [2], [3], [5], [3], [5], [21]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n ...
coding
298
Solve the programming task below in a Python markdown code block. Write a function `consonantCount`, `consonant_count` or `ConsonantCount` that takes a string of English-language text and returns the number of consonants in the string. Consonants are all letters used to write English excluding the vowels `a, e, i, o, ...
{"functional": "_inputs = [[''], ['aaaaa'], ['helLo world'], ['h^$&^#$&^elLo world'], ['0123456789'], ['012345_Cb']]\n_outputs = [[0], [0], [7], [7], [0], [2]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n...
coding
100
Solve the programming task below in a Python markdown code block. In discus throw, a player is given 3 throws and the throw with the longest distance is regarded as their final score. You are given the distances for all 3 throws of a player. Determine the final score of the player. ------ Input Format ------ - Firs...
{"inputs": ["3\n10 15 8\n32 32 32\n82 45 54\n"], "outputs": ["15\n32\n82\n"]}
coding
310
Solve the programming task below in a Python markdown code block. Ashu and Arvind participated in a coding contest, as a result of which they received N chocolates. Now they want to divide the chocolates between them equally. Can you help them by deciding if it is possible for them to divide all the N chocolates in su...
{"inputs": ["4\n10\n4\n3\n2\n"], "outputs": ["Yes\nYes\nNo\nYes"]}
coding
375
Please solve the programming task below using a self-contained code snippet in a markdown code block. A digit string is good if the digits (0-indexed) at even indices are even and the digits at odd indices are prime (2, 3, 5, or 7). For example, "2582" is good because the digits (2 and 8) at even positions are even a...
{"functional": "def check(candidate):\n assert candidate(n = 1) == 5\n assert candidate(n = 4) == 400\n assert candidate(n = 50) == 564908303\n\n\ncheck(Solution().countGoodNumbers)"}
coding
206
Please solve the programming task below using a self-contained code snippet in a markdown code block. Our hero Teemo is attacking an enemy Ashe with poison attacks! When Teemo attacks Ashe, Ashe gets poisoned for a exactly duration seconds. More formally, an attack at second t will mean Ashe is poisoned during the inc...
{"functional": "def check(candidate):\n assert candidate(timeSeries = [1,4], duration = 2) == 4\n assert candidate(timeSeries = [1,2], duration = 2) == 3\n\n\ncheck(Solution().findPoisonedDuration)"}
coding
188
Solve the programming task below in a Python markdown code block. 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: All of...
{"inputs": ["1 1\n1 1\n", "1 1\n1 1\n", "2 1\n1 1\n", "2 1\n1 0\n", "2 1\n2 0\n", "2 1\n2 -1\n", "2 1\n1 -1\n", "4 2\n1 2\n2 2\n"], "outputs": ["1", "1", "1\n", "1\n", "1\n", "1\n", "1\n", "1"]}
coding
605
Solve the programming task below in a Python markdown code block. King Mercer is the king of ACM kingdom. There are one capital and some cities in his kingdom. Amazingly, there are no roads in the kingdom now. Recently, he planned to construct roads between the capital and the cities, but it turned out that the constru...
{"inputs": ["3 3\n1 2 2 2\n2 3 2 1\n3 1 3 2\n5 5\n1 3 2 2\n2 3 1 1\n1 4 1 2\n4 5 1 1\n5 3 1 1\n5 10\n1 2 32 10\n1 3 43 43\n1 4 12 77\n1 5 84 2\n2 3 58 42\n2 4 86 99\n2 5 57 52\n3 4 9 32\n3 5 75 21\n2 5 17 43\n5 10\n1 2 1 85\n1 3 1 65\n2 4 1 24\n1 5 1 76\n2 3 4 19\n3 4 1 46\n2 5 2 25\n3 4 1 13\n3 5 1 65\n4 5 1 36\n0 0",...
coding
765
Solve the programming task below in a Python markdown code block. We have an integer sequence A of length N, where A_1 = X, A_{i+1} = A_i + D (1 \leq i < N ) holds. Takahashi will take some (possibly all or none) of the elements in this sequence, and Aoki will take all of the others. Let S and T be the sum of the numb...
{"inputs": ["3 3 2", "3 3 3", "0 3 2", "2 4 3", "3 4 2", "3 4 2\n", "7 5 5\n", "8 6 0\n"], "outputs": ["8\n", "7\n", "1\n", "4\n", "8", "8\n", "29\n", "9\n"]}
coding
372
Solve the programming task below in a Python markdown code block. Recently a new building with a new layout was constructed in Monocarp's hometown. According to this new layout, the building consists of three types of apartments: three-room, five-room, and seven-room apartments. It's also known that each room of each a...
{"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n6\n", "1\n4\n", "2\n448\n6\n"], "outputs": ["-1\n", "-1\n", "-1\n", "1 0 0\n", "0 1 0\n", "2 0 0\n", "-1\n", "147 0 1\n2 0 0\n"]}
coding
533
Solve the programming task below in a Python markdown code block. There are n railway stations in Berland. They are connected to each other by n-1 railway sections. The railway network is connected, i.e. can be represented as an undirected tree. You have a map of that network, so for each railway section you know whic...
{"inputs": ["2\n2 1\n1\n1 2 3\n", "2\n2 1\n1\n1 2 4\n", "3\n2 1\n3 1\n1\n3 2 3\n", "3\n2 1\n3 1\n1\n2 3 1\n", "2\n2 1\n2\n1 2 3\n1 2 3\n", "2\n2 1\n2\n1 2 1\n2 1 1\n", "4\n4 1\n2 3\n2 1\n1\n1 3 1\n", "3\n1 2\n1 3\n2\n3 2 2\n1 3 4\n"], "outputs": ["3 \n", "4 \n", "3 3 \n", "1 1 \n", "3 \n", "1 \n", "1 1 1 \n", "2 4 \n"]...
coding
701
Solve the programming task below in a Python markdown code block. There are $n$ computers in a row, all originally off, and Phoenix wants to turn all of them on. He will manually turn on computers one at a time. At any point, if computer $i-1$ and computer $i+1$ are both on, computer $i$ $(2 \le i \le n-1)$ will turn o...
{"inputs": ["3 100000007\n", "4 100000007\n", "5 999999937\n", "6 100000007\n", "7 100000007\n", "6 100000007\n", "5 999999937\n", "7 100000007\n"], "outputs": ["6\n", "20\n", "78\n", "344\n", "1680\n", "344\n", "78\n", "1680\n"]}
coding
472
Solve the programming task below in a Python markdown code block. Chef has two numbers X and Y. Chef wants to find three integers A, B, and C such that: -1000 ≤ A, B, C ≤ 1000 mean([A, B, C]) = X median([A, B, C]) = Y Can you help Chef find such three integers? As a reminder, mean([P, Q, R]) = \frac{P + Q + R}{3} and...
{"inputs": ["3\n5 5\n67 100\n4 5\n"], "outputs": ["5 5 5\n0 100 101\n0 5 7"]}
coding
513
Solve the programming task below in a Python markdown code block. # Task You are given an array of integers. Your task is to determine the minimum number of its elements that need to be changed so that elements of the array will form an arithmetic progression. Note that if you swap two elements, you're changing both o...
{"functional": "_inputs = [[[1, 2, 3]], [[1, 3, 0, 7, 9]], [[1, 10, 2, 12, 3, 14, 4, 16, 5]], [[7, 7, 7, 7, 8, 7, 7, 7, 7, 7, 7, 7, 7, 7, 9, 7, 7, 7, 7, 7, 7]], [[2, -1, -4, 12, 1, -13, -16, -19, -6, -25]], [[-1, 2, 5, 8, 11, 14, 17, -6, 23, 26, -25, 32]], [[-10, -21, -20, -25, -13, 14, 2, 6, -50, -55, -60, -65, -70, -...
coding
420
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a string s formed by digits and '#'. We want to map s to English lowercase characters as follows: Characters ('a' to 'i') are represented by ('1' to '9') respectively. Characters ('j' to 'z') are repres...
{"functional": "def check(candidate):\n assert candidate(s = \"10#11#12\") == \"jkab\"\n assert candidate(s = \"1326#\") == \"acz\"\n\n\ncheck(Solution().freqAlphabets)"}
coding
138
Solve the programming task below in a Python markdown code block. This problem is given in two versions that differ only by constraints. If you can solve this problem in large constraints, then you can just write a single solution to the both versions. If you find the problem too difficult in large constraints, you can...
{"inputs": ["1 1\n1\n1\n", "1 1\n4\n6\n", "1 1\n1\n1\n", "1 1\n4\n6\n", "1 1\n8\n6\n", "1 1\n7\n0\n", "1 1\n5\n0\n", "1 1\n9\n6\n"], "outputs": ["2\n", "1\n", "2\n", "1\n", "0\n", "0\n", "0\n", "0\n"]}
coding
595
Solve the programming task below in a Python markdown code block. In this kata you will be given an **integer n**, which is the number of times that is thown a coin. You will have to return an array of string for all the possibilities (heads[H] and tails[T]). Examples: ```coin(1) should return {"H", "T"}``` ```coin(2) ...
{"functional": "_inputs = [[1], [2], [3]]\n_outputs = [[['H', 'T']], [['HH', 'HT', 'TH', 'TT']], [['HHH', 'HHT', 'HTH', 'HTT', 'THH', 'THT', 'TTH', 'TTT']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n ...
coding
275
Solve the programming task below in a Python markdown code block. General primality test are often computationally expensive, so in the biggest prime number race the idea is to study special sub-families of prime number and develop more effective tests for them. [Mersenne Primes](https://en.wikipedia.org/wiki/Mersenn...
{"functional": "_inputs = [[2], [3], [4], [5], [7], [10], [33], [101], [11213], [11215]]\n_outputs = [[True], [True], [False], [True], [True], [False], [False], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, ...
coding
657
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef has always dreamed of becoming an employee of the "Hack and Manipulate Group". Their work is simple ― attacking networks. They gave Chef the fol...
{"inputs": ["5\n5 5\n5 1\n5 2\n1 2\n2 3\n2 4\n5 6\n4 5\n4 1\n4 2\n4 3\n5 1\n5 2\n5 5\n3 4\n3 5\n3 1\n3 2\n4 2\n4 1\n3 4\n6 6\n1 2\n2 3\n3 1\n4 5\n5 6\n6 4"], "outputs": ["1\n4\n2\n-1\n-1"]}
coding
653
Solve the programming task below in a Python markdown code block. Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well. There is an ATM machine. Initially, it contains a total of $K$ units of money. $N$ people (numbered $1$ through $N$) want to withdraw money; for each valid $i$...
{"inputs": ["2\n5 10\n3 5 3 2 1\n4 6\n10 8 6 4"], "outputs": ["11010\n0010"]}
coding
652
Solve the programming task below in a Python markdown code block. Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well. Chef's planet is called Javad. A year on Javad has $N$ months numbered $1$ through $N$. For each valid $i$, the $i$-th month has $a_{i}$ days numbered $1$ th...
{"inputs": ["4\n5\n1 2 3 4 5\n2 1 1\n3 5 1\n2\n3 3\n1 1 1\n2 2 2\n2\n1 1\n3 1 1\n3 2 1\n5\n1 4 3 4 6\n3 5 6\n10 1 1"], "outputs": ["26\n11\n2\n112"]}
coding
699
Solve the programming task below in a Python markdown code block. There are $n$ students in a university. The number of students is even. The $i$-th student has programming skill equal to $a_i$. The coach wants to form $\frac{n}{2}$ teams. Each team should consist of exactly two students, and each student should belo...
{"inputs": ["2\n1 1\n", "2\n1 1\n", "2\n1 70\n", "2\n1 71\n", "2\n1 70\n", "2\n1 71\n", "2\n1 100\n", "2\n2 100\n"], "outputs": ["0\n", "0\n", "69\n", "70\n", "69\n", "70\n", "99\n", "98\n"]}
coding
457