task_type
stringclasses
4 values
problem
stringlengths
14
5.23k
solution
stringlengths
1
8.29k
problem_tokens
int64
9
1.02k
solution_tokens
int64
1
1.98k
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a circular integer array nums (i.e., the next element of nums[nums.length - 1] is nums[0]), return the next greater number for every element in nums. The next greater number of a number x is the first greater nu...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,1]) == [2,-1,2]\n assert candidate(nums = [1,2,3,4,3]) == [2,3,4,-1,4]\n\n\ncheck(Solution().nextGreaterElements)"}
138
70
coding
Solve the programming task below in a Python markdown code block. Little girl Alyona is in a shop to buy some copybooks for school. She study four subjects so she wants to have equal number of copybooks for each of the subjects. There are three types of copybook's packs in the shop: it is possible to buy one copybook f...
{"inputs": ["1 1 3 4\n", "6 2 1 1\n", "4 4 4 4\n", "7 4 3 1\n", "7 4 1 1\n", "3 9 1 1\n", "3 4 3 1\n", "3 3 1 1\n"], "outputs": ["3\n", "1\n", "0\n", "3\n", "2\n", "2\n", "3\n", "2\n"]}
456
118
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. Chef is working at his dream workplace with $N-1$ of his friends! Like any dream workplace, this one also has dream work conditions. To ensure absolute happiness of the emplo...
{"inputs": ["1\n2 12"], "outputs": ["4 4"]}
750
19
coding
Solve the programming task below in a Python markdown code block. Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second p...
{"inputs": ["1\n1\n", "1\n2\n", "1\n1\n", "1\n2\n", "1\n8\n", "1\n4\n", "1\n10\n", "1\n10\n"], "outputs": ["NO\n", "NO\n", "NO", "NO", "NO\n", "NO\n", "NO\n", "NO"]}
336
85
coding
Solve the programming task below in a Python markdown code block. There is an integer sequence of length 2^N: A_0, A_1, ..., A_{2^N-1}. (Note that the sequence is 0-indexed.) For every integer K satisfying 1 \leq K \leq 2^N-1, solve the following problem: - Let i and j be integers. Find the maximum value of A_i + A_j ...
{"inputs": ["2\n1 2 3 2", "2\n0 2 3 2", "2\n1 2 3 1", "2\n1 2 3 1\n", "3\n3 210 47 33 0 9 17 82", "3\n3 312 47 33 0 9 17 82", "3\n3 312 59 33 0 9 17 82", "3\n2 312 59 33 0 9 17 82"], "outputs": ["3\n4\n5\n", "2\n3\n5\n", "3\n4\n5", "3\n4\n5\n", "213\n213\n257\n257\n257\n257\n292\n", "315\n315\n359\n359\n359\n359\n394\n...
432
302
coding
Solve the programming task below in a Python markdown code block. Recently, Greg got a grid with n rows and m columns. Rows are indexed from 1 to n and columns are indexed from 1 to m. The cell $ ( i , j )$ is the cell of intersection of row i and column j. Each cell has a number written on it. The number written on ce...
{"inputs": ["3 4\n"], "outputs": ["4"]}
212
15
coding
Solve the programming task below in a Python markdown code block. 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 other. He w...
{"inputs": ["2\n1 2\n", "2\n2 1\n", "2\n1 2\n", "2\n2 1\n", "3\n2 3 1\n", "3\n1 2 3\n", "3\n1 3 2\n", "3\n2 1 3\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n"]}
375
110
coding
Solve the programming task below in a Python markdown code block. N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front...
{"inputs": ["5\n1 3 3 3 3", "5\n2 1 5 8 3", "5\n1 2 3 6 3", "5\n2 1 2 8 4", "5\n4 4 3 6 6", "5\n4 4 3 7 6", "5\n3 1 5 8 3", "5\n0 1 2 8 4"], "outputs": ["0\n", "6\n", "3\n", "5\n", "1\n", "2\n", "7\n", "4\n"]}
279
142
coding
Solve the programming task below in a Python markdown code block. Xenia the beginner programmer has a sequence a, consisting of 2^{n} non-negative integers: a_1, a_2, ..., a_2^{n}. Xenia is currently studying bit operations. To better understand how they work, Xenia decided to calculate some value v for a. Namely, it ...
{"inputs": ["1 1\n1 1\n1 1\n", "1 1\n1 1\n1 1\n", "1 1\n2 1\n1 1\n", "2 4\n1 6 3 5\n1 4\n3 4\n1 2\n1 2\n", "2 4\n1 6 3 2\n1 4\n3 4\n1 2\n1 2\n", "2 4\n1 6 4 2\n1 4\n3 4\n1 2\n1 4\n", "2 4\n1 6 2 2\n1 4\n3 4\n1 2\n1 2\n", "2 4\n1 6 3 2\n1 4\n3 5\n1 2\n1 4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n3\n3\n3\n", "5\n0\n0\n0...
634
260
coding
Solve the programming task below in a Python markdown code block. Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. This problem has no story, so we at least wish you good luck solving it. Consider a multiset $S$ which contains $A$ copies of the integer $1$, $B$ ...
{"inputs": ["5\n3 3 3\n3 2 3\n1 1 2\n1 0 1\n1 1 1"], "outputs": ["YES\nYES\nNO\nNO\nYES"]}
477
50
coding
Solve the programming task below in a Python markdown code block. Polycarp has a strict daily schedule. He has n alarms set for each day, and the i-th alarm rings each day at the same time during exactly one minute. Determine the longest time segment when Polycarp can sleep, i. e. no alarm rings in that period. It is ...
{"inputs": ["1\n05:43\n", "1\n04:43\n", "1\n05:43\n", "2\n00:00\n23:59\n", "2\n01:00\n01:01\n", "2\n06:25\n22:43\n", "2\n05:53\n04:15\n", "2\n11:24\n13:53\n"], "outputs": ["23:59\n", "23:59\n", "23:59\n", "23:58\n", "23:58\n", "16:17\n", "22:21\n", "21:30\n"]}
434
180
coding
Solve the programming task below in a Python markdown code block. In a kindergarten, the children are being divided into groups. The teacher put the children in a line and associated each child with his or her integer charisma value. Each child should go to exactly one group. Each group should be a nonempty segment of ...
{"inputs": ["1\n0\n", "3\n8 1 2\n", "3\n1 1 2\n", "3\n1 1 1\n", "3\n3 3 0\n", "3\n4 3 0\n", "3\n4 3 1\n", "3\n5 3 1\n"], "outputs": ["0\n", "7\n", "1\n", "0\n", "3\n", "4\n", "3\n", "4\n"]}
311
114
coding
Solve the programming task below in a Python markdown code block. ## Find Mean Find the mean (average) of a list of numbers in an array. ## Information To find the mean (average) of a set of numbers add all of the numbers together and divide by the number of values in the list. For an example list of `1, 3, 5, 7` ...
{"functional": "_inputs = [[[1]], [[1, 3, 5, 7]], [[-1, 3, 5, -7]], [[5, 7, 3, 7]], [[]]]\n_outputs = [[1], [4], [0], [5.5], [0]]\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, tu...
177
207
coding
Solve the programming task below in a Python markdown code block. The EEE classes are so boring that the students play games rather than paying attention during the lectures. Harsha and Dubey are playing one such game. The game involves counting the number of anagramic pairs of a given string (you can read about anagr...
{"inputs": ["3\nrama\nabba\nabcd"], "outputs": ["2\n4\n0"]}
271
23
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a digit string s that consists of digits from 0 to 9. A string is called semi-repetitive if there is at most one adjacent pair of the same digit. For example, "0010", "002020", "0123", "2002", and "54944...
{"functional": "def check(candidate):\n assert candidate(s = \"52233\") == 4\n assert candidate(s = \"5494\") == 4\n assert candidate(s = \"1111111\") == 2\n\n\ncheck(Solution().longestSemiRepetitiveSubstring)"}
206
74
coding
Solve the programming task below in a Python markdown code block. The T9 typing predictor helps with suggestions for possible word combinations on an old-style numeric keypad phone. Each digit in the keypad (2-9) represents a group of 3-4 letters. To type a letter, press once the key which corresponds to the letter gro...
{"functional": "_inputs = [[['hello', 'world'], '43556'], [['good', 'home', 'new'], '4663'], [['gone', 'hood', 'good', 'old'], '4663'], [['Hello', 'world'], '43556'], [['gOOD', 'hOmE', 'NeW'], '4663'], [['goNe', 'hood', 'GOOD', 'old'], '4663'], [[], '43556'], [['gold'], '4663'], [['gone', 'hood', 'good', 'old'], '729']...
490
336
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array points containing the coordinates of points on a 2D plane, sorted by the x-values, where points[i] = [xi, yi] such that xi < xj for all 1 <= i < j <= points.length. You are also given an integer...
{"functional": "def check(candidate):\n assert candidate(points = [[1,3],[2,0],[5,10],[6,-10]], k = 1) == 4\n assert candidate(points = [[0,0],[3,0],[9,2]], k = 3) == 3\n\n\ncheck(Solution().findMaxValueOfEquation)"}
180
83
coding
Solve the programming task below in a Python markdown code block. You are given an array A with size N (indexed from 0) and an integer K. Let's define another array B with size N · K as the array that's formed by concatenating K copies of array A. For example, if A = {1, 2} and K = 3, then B = {1, 2, 1, 2, 1, 2}. You h...
{"inputs": ["2\n2 3\n1 2\n3 2\n1 -2 1\n\n"], "outputs": ["9\n2"]}
466
34
coding
Solve the programming task below in a Python markdown code block. Vasya is a CEO of a big construction company. And as any other big boss he has a spacious, richly furnished office with two crystal chandeliers. To stay motivated Vasya needs the color of light at his office to change every day. That's why he ordered bot...
{"inputs": ["1 2 1\n1\n2 1\n", "1 2 1\n1\n2 1\n", "1 2 1\n2\n2 1\n", "1 2 31\n1\n1 2\n", "1 2 23\n1\n1 2\n", "1 2 31\n1\n1 2\n", "2 2 2\n2 1\n1 2\n", "2 2 2\n2 1\n1 2\n"], "outputs": ["1\n", "1\n", "2\n", "62\n", "46\n", "\n62\n", "2\n", "2\n"]}
660
161
coding
Solve the programming task below in a Python markdown code block. Kabir wants to impress Tara by showing her his problem solving skills. He has decided to give the correct answer to the next question which will be asked by his Algorithms teacher. The question asked is: Find the sum of alternate consecutive d$d$ odd num...
{"inputs": ["1\n3\n10 33"], "outputs": ["114"]}
499
22
coding
Solve the programming task below in a Python markdown code block. Pashmak decided to give Parmida a pair of flowers from the garden. There are n flowers in the garden and the i-th of them has a beauty number b_{i}. Parmida is a very strange girl so she doesn't want to have the two most beautiful flowers necessarily. Sh...
{"inputs": ["2\n1 2\n", "2\n1 1\n", "2\n5 6\n", "2\n3 2\n", "2\n1 1\n", "2\n3 2\n", "2\n5 6\n", "2\n0 1\n"], "outputs": ["1 1", "0 1", "1 1", "1 1", "0 1\n", "1 1\n", "1 1\n", "1 1\n"]}
363
114
coding
Solve the programming task below in a Python markdown code block. C*++ language is quite similar to C++. The similarity manifests itself in the fact that the programs written in C*++ sometimes behave unpredictably and lead to absolutely unexpected effects. For example, let's imagine an arithmetic expression in C*++ tha...
{"inputs": ["332\n++a\n", "4\n0*a++\n", "332\na++\n", "1000\n++a\n", "1000\na++\n", "584\n7*++a\n", "584\n6*++a\n", "584\n5*++a\n"], "outputs": ["333\n", "0\n", "332\n", "1001\n", "1000\n", "4095\n", "3510\n", "2925\n"]}
619
139
coding
Solve the programming task below in a Python markdown code block. You are given an integer sequence A=(A_{1}, A_{2},\dots, A_{N}) of length N and an integer M such that 0 ≤ M < \sum\limits_{i=1}^N A_{i}. An integer sequence B=(B_{1}, B_{2},\dots, B_{N}) of length N is called *good* if: 0 ≤ B_{i} ≤ A_{i} for each 1≤ i...
{"inputs": ["4\n4 4\n1 3 5 7\n4 4\n5 5 5 5\n4 0\n4 6 9 12\n6 10\n15 9 3 8 14 17"], "outputs": ["3\n4\n1\n7\n"]}
655
76
coding
Solve the programming task below in a Python markdown code block. You have n problems. You have estimated the difficulty of the i-th one as integer c_{i}. Now you want to prepare a problemset for a contest, using some of the problems you've made. A problemset for the contest must consist of at least two problems. You ...
{"inputs": ["1 10 6 1\n15\n", "1 10 6 1\n17\n", "1 10 6 2\n17\n", "1 10 20 1\n15\n", "1 10 20 1\n15\n", "3 5 6 1\n1 2 3\n", "3 5 8 1\n1 2 3\n", "3 5 8 1\n1 2 0\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "2\n", "2\n", "0\n"]}
459
158
coding
Solve the programming task below in a Python markdown code block. We have an integer sequence A, whose length is N. Find the number of the non-empty contiguous subsequences of A whose sums are 0. Note that we are counting the ways to take out subsequences. That is, even if the contents of some two subsequences are the...
{"inputs": ["5\n0 0 2 0 8", "5\n0 0 3 0 8", "5\n0 0 3 1 8", "5\n1 0 6 -2 5", "5\n1 0 8 -2 5", "5\n2 0 8 -2 5", "5\n2 0 8 -2 9", "5\n2 0 2 -2 5"], "outputs": ["4\n", "4\n", "3\n", "1\n", "1\n", "1\n", "1\n", "3\n"]}
241
142
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two integers, x and y, which represent your current location on a Cartesian grid: (x, y). You are also given an array points where each points[i] = [ai, bi] represents that a point exists at (ai, bi). A ...
{"functional": "def check(candidate):\n assert candidate(x = 3, y = 4, points = [[1,2],[3,1],[2,4],[2,3],[4,4]]) == 2\n assert candidate(x = 3, y = 4, points = [[3,4]]) == 0\n assert candidate(x = 3, y = 4, points = [[2,3]]) == -1\n\n\ncheck(Solution().nearestValidPoint)"}
216
108
coding
Solve the programming task below in a Python markdown code block. Today, Wet Shark is given n bishops on a 1000 by 1000 grid. Both rows and columns of the grid are numbered from 1 to 1000. Rows are numbered from top to bottom, while columns are numbered from left to right. Wet Shark thinks that two bishops attack each...
{"inputs": ["1\n6 3\n", "1\n1 1\n", "1\n1 1\n", "1\n6 3\n", "1\n0 1\n", "1\n6 6\n", "1\n9 6\n", "1\n9 11\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
401
103
coding
Solve the programming task below in a Python markdown code block. Chef 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. Chef has a positive integer N. He c...
{"inputs": ["3\n4\n5\n0", "3\n0\n7\n61", "3\n0\n8\n24", "3\n0\n12\n5", "3\n3\n4\n70", "3\n32\n5\n7", "3\n1\n7\n44", "3\n1\n5\n44"], "outputs": ["0\n1\n1\n", "1\n0\n2\n", "1\n1\n1\n", "1\n2\n1\n", "1\n0\n1\n", "2\n1\n0\n", "1\n0\n0\n", "1\n1\n0\n"]}
268
149
coding
Solve the programming task below in a Python markdown code block. 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 calls a number almost lucky ...
{"inputs": ["4\n", "3\n", "8\n", "7\n", "2\n", "1\n", "5\n", "6\n"], "outputs": ["YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
241
70
coding
Solve the programming task below in a Python markdown code block. While surfing in web I found interesting math problem called "Always perfect". That means if you add 1 to the product of four consecutive numbers the answer is ALWAYS a perfect square. For example we have: 1,2,3,4 and the product will be 1X2X3X4=24. If w...
{"functional": "_inputs = [['4,5,6,7'], ['3,s,5,6'], ['11,13,14,15'], ['10,11,12,13,15'], ['10,11,12,13'], ['ad,d,q,tt,v'], ['//,;;,/,..,'], ['1,2,3,4'], ['1015,1016,1017,1018'], ['555,777,444,111'], ['20,21,22,24'], ['9,10,10,11'], ['11254,11255,11256,11258'], ['25000,25001,25002,25003'], ['2000000,2000001,2000002,200...
208
608
coding
Solve the programming task below in a Python markdown code block. Gotham city is in danger. All the people from Gotham were airlifted and they are going to be dropped at different districts of a new safe city. There are $N$ districts located at position $(1, 2, \ldots, N)$ in a straight line in this newly built safe c...
{"inputs": ["4\n5 5 6 1\n2\n2 11\n2 3\n"], "outputs": ["6\n2\n"]}
568
35
coding
Solve the programming task below in a Python markdown code block. Counting sort can be used for sorting elements in an array which each of the n input elements is an integer in the range 0 to k. The idea of counting sort is to determine, for each input element x, the number of elements less than x as C[x]. This informa...
{"inputs": ["7\n2 5 1 3 2 3 1", "7\n2 5 1 3 4 3 1", "7\n2 5 2 3 4 3 1", "7\n4 5 2 3 4 3 1", "7\n4 9 2 3 4 3 1", "7\n4 9 2 3 4 3 2", "7\n4 9 2 1 4 3 2", "7\n4 9 2 0 4 3 3"], "outputs": ["1 1 2 2 3 3 5\n", "1 1 2 3 3 4 5\n", "1 2 2 3 3 4 5\n", "1 2 3 3 4 4 5\n", "1 2 3 3 4 4 9\n", "2 2 3 3 4 4 9\n", "1 2 2 3 4 4 9\n", "0...
421
270
coding
Solve the programming task below in a Python markdown code block. You are looking for a place to park your car on a wall street. You can park at any position that meets the following requirements: 1. It is not directly in front of a private driveway. 2. It is not directly in front of a bus stop. 3. It is not 5 meter...
{"inputs": ["46\n---B--S-D--S--\nDDBDDBDDBDD\n--S--S--S--S--\nSSD-B---BD-DDSB-----S-S--------S-B----BSB-S--B-S-D\n-SB---S----DD-D-DS---B--BD-S-SD---D----D-B---B-SDD\n------BB-----D--------S--D-BSSS-----B---S-S-SSS---\n----------S--S----D---------SD---DD--D---DSB-B----\n-S---------DDDB---BB----SSD---D-B---S-B-----DD---S...
485
734
coding
Solve the programming task below in a Python markdown code block. We call an quadruple of positive integers, $(W,X,Y,Z)$, beautiful if the following condition is true: $W\oplus X\oplus Y\oplus Z\neq0$ Note: $\theta$ is the bitwise XOR operator. Given $\mbox{A}$, $\mbox{B}$, $\mbox{C}$, and $\mbox{D}$, count the numb...
{"inputs": ["1 2 3 4\n"], "outputs": ["11\n"]}
518
21
coding
Solve the programming task below in a Python markdown code block. # Task You have two sorted arrays `a` and `b`, merge them to form new array of unique items. If an item is present in both arrays, it should be part of the resulting array if and only if it appears in both arrays the same number of times. # Example ...
{"functional": "_inputs = [[[10, 10, 10, 15, 20, 20, 25, 25, 30, 7000], [10, 15, 20, 20, 27, 7200]], [[500, 550, 1000, 1000, 1400, 3500], [2, 2, 2, 2, 3, 1500]], [[5], [5, 5, 7]]]\n_outputs = [[[15, 20, 25, 27, 30, 7000, 7200]], [[2, 3, 500, 550, 1000, 1400, 1500, 3500]], [[7]]]\nimport math\ndef _deep_eq(a, b, tol=1e-...
318
359
coding
Solve the programming task below in a Python markdown code block. E869120 found a chest which is likely to contain treasure. However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters. He also found a string S', which turns out to be the string S with some ...
{"inputs": [">q???d?>\n_ba", "d>>>???q\na`a", "d>>>???q\naaa", "??p??d??\nabb", "??p??d??\n`bb", "??p??d??\n`ab", "??p??d??\nba`", "??p??d??\nb``"], "outputs": [">q_bada>\n", "d>>>a`aq\n", "d>>>aaaq\n", "UNRESTORABLE\n", "UNRESTORABLE\n", "UNRESTORABLE\n", "UNRESTORABLE\n", "UNRESTORABLE\n"]}
313
146
coding
Solve the programming task below in a Python markdown code block. Finally, the pandemic is over in ChefLand, and the chef is visiting the school again. Chef likes to climb the stairs of his school's floor by skipping one step, sometimes chef climbs the stairs one by one. Simply, the chef can take one or 2 steps in one ...
{"inputs": ["1\n3"], "outputs": ["2"]}
326
14
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an m x n picture consisting of black 'B' and white 'W' pixels and an integer target, return the number of black lonely pixels. A black lonely pixel is a character 'B' that located at a specific position (r, c) w...
{"functional": "def check(candidate):\n assert candidate(picture = [[\"W\",\"B\",\"W\",\"B\",\"B\",\"W\"],[\"W\",\"B\",\"W\",\"B\",\"B\",\"W\"],[\"W\",\"B\",\"W\",\"B\",\"B\",\"W\"],[\"W\",\"W\",\"B\",\"W\",\"B\",\"W\"]], target = 3) == 6\n assert candidate(picture = [[\"W\",\"W\",\"B\"],[\"W\",\"W\",\"B\"],[\"W\...
142
132
coding
Solve the programming task below in a Python markdown code block. In this kata, you'll be given an integer of range `0 <= x <= 99` and have to return that number spelt out in English. A few examples: ```python name_that_number(4) # returns "four" name_that_number(19) # returns "nineteen" name_that_number(99) # ret...
{"functional": "_inputs = [[1], [52], [21], [99], [0], [53], [23], [76]]\n_outputs = [['one'], ['fifty two'], ['twenty one'], ['ninety nine'], ['zero'], ['fifty three'], ['twenty three'], ['seventy six']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return m...
168
214
coding
Solve the programming task below in a Python markdown code block. Triangular number is the amount of points that can fill equilateral triangle. Example: the number 6 is a triangular number because all sides of a triangle has the same amount of points. ``` Hint! T(n) = n * (n + 1) / 2, n - is the size of one side. T(...
{"functional": "_inputs = [[1], [3], [6], [10], [15], [21], [28], [2], [7], [14], [27]]\n_outputs = [[True], [True], [True], [True], [True], [True], [True], [False], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(...
146
221
coding
Solve the programming task below in a Python markdown code block. The number ```89``` is the first positive integer that has a particular, curious property: The square of ```89``` is ```7921```; ```89² = 7921``` The reverse of ```7921``` is ```1297```, and ```1297``` is a prime number. The cube of ```89``` is ```704...
{"functional": "_inputs = [[1], [2], [3], [4]]\n_outputs = [[89], [271], [325], [328]]\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...
429
182
coding
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"]}
296
92
coding
Solve the programming task below in a Python markdown code block. Problem description. Winston and Royce love sharing memes with each other. They express the amount of seconds they laughed ar a meme as the number of ‘XD’ subsequences in their messages. Being optimization freaks, they wanted to find the string with mini...
{"inputs": ["1\n9"], "outputs": ["XXXDDD"]}
242
15
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You're given strings jewels representing the types of stones that are jewels, and stones representing the stones you have. Each character in stones is a type of stone you have. You want to know how many of the stones ...
{"functional": "def check(candidate):\n assert candidate(jewels = \"aA\", stones = \"aAAbbbb\") == 3\n assert candidate(jewels = \"z\", stones = \"ZZ\") == 0\n\n\ncheck(Solution().numJewelsInStones)"}
125
66
coding
Solve the programming task below in a Python markdown code block. Some days ago, I learned the concept of LCM (least common multiple). I've played with it for several times and I want to make a big number with it. But I also don't want to use many numbers, so I'll choose three positive integers (they don't have to be ...
{"inputs": ["9\n", "7\n", "1\n", "5\n", "6\n", "2\n", "8\n", "3\n"], "outputs": ["504\n", "210\n", "1\n", "60\n", "60\n", "2\n", "280\n", "6\n"]}
274
78
coding
Solve the programming task below in a Python markdown code block. You have a total of 3N balls of colours Red, Blue and Green. There are exactly N balls of each colour. These 3N balls are now distributed to 3 boxes such that each box contains exactly N balls. You are given the contents of each box. You would like the...
{"inputs": ["2\n3\n3 0 0\n0 3 0\n0 0 3\n5\n2 1 2\n1 4 0\n2 0 3"], "outputs": ["0\n3"]}
750
54
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an infinite number of quarters (25 cents), dimes (10 cents), nickels (5 cents), and pennies (1 cent), write code to calculate the number of ways of representing n cents. (The result may be large, so you should r...
{"functional": "def check(candidate):\n assert candidate(n = 5) == 2\n assert candidate(n = 10) == 4\n\n\ncheck(Solution().waysToChange)"}
116
45
coding
Solve the programming task below in a Python markdown code block. Write a function named setAlarm which receives two parameters. The first parameter, employed, is true whenever you are employed and the second parameter, vacation is true whenever you are on vacation. The function should return true if you are employed a...
{"functional": "_inputs = [[True, True], [False, True], [False, False], [True, False]]\n_outputs = [[False], [False], [False], [True]]\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, (lis...
156
180
coding
Solve the programming task below in a Python markdown code block. There are N flowers arranged in a row. For each i (1 \leq i \leq N), the height and the beauty of the i-th flower from the left is h_i and a_i, respectively. Here, h_1, h_2, \ldots, h_N are all distinct. Taro is pulling out some flowers so that the foll...
{"inputs": ["1\n1\n10", "4\n3 1 3 2\n6 6 0 7", "4\n3 1 4 2\n15 6 2 64", "4\n3 1 4 2\n18 5 0 24", "4\n3 1 3 2\n20 6 0 37", "4\n3 1 4 2\n18 5 0 35", "4\n3 1 3 2\n6 12 0 37", "4\n3 1 3 2\n5 22 2 37"], "outputs": ["10", "13\n", "70\n", "29\n", "43\n", "40\n", "49\n", "59\n"]}
428
198
coding
Solve the programming task below in a Python markdown code block. Chef has an old machine if the chef enters any natural number, the machine will display 1, 2, …n, n-1, n-2, n-3,…1 series and in next line prints sum of cubes of each number in the series. Chef wants to create a computer program which can replicate the f...
{"inputs": ["2\n1\n3"], "outputs": ["1\n45"]}
246
19
coding
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"]}
388
103
coding
Solve the programming task below in a Python markdown code block. Ishank lives in a country in which there are N$N$ cities and N−1$N-1$ roads. All the cities are connected via these roads. Each city has been assigned a unique number from 1 to N$N$. The country can be assumed as a tree, with nodes representing the citie...
{"inputs": ["9 5\n1 2 8\n1 3 -9\n2 4 1\n2 5 -6\n3 6 7\n3 7 6\n6 8 3\n6 9 4\n1 2\n2 7\n4 3\n3 2\n8 9"], "outputs": ["10\n5\n0\n-1\n21"]}
707
93
coding
Solve the programming task below in a Python markdown code block. Polycarp has an integer $n$ that doesn't contain the digit 0. He can do the following operation with his number several (possibly zero) times: Reverse the prefix of length $l$ (in other words, $l$ leftmost digits) of $n$. So, the leftmost digit is swapp...
{"inputs": ["1\n99\n", "1\n21328\n", "1\n87454\n", "1\n77778\n", "1\n77774\n", "1\n841419\n", "1\n77771449\n", "4\n3876\n387\n4489\n3\n"], "outputs": ["-1\n", "0\n", "0\n", "0\n", "0\n", "1\n", "2\n", "0\n2\n1\n-1\n"]}
676
137
coding
Solve the programming task below in a Python markdown code block. A new agent called Killjoy invented a virus COVID-2069 that infects accounts on Codeforces. Each account has a rating, described by an integer (it can possibly be negative or very large). Killjoy's account is already infected and has a rating equal to $...
{"inputs": ["1\n2 2\n0 5\n", "1\n2 2\n0 5\n", "1\n2 2\n0 8\n", "1\n2 2\n0 0\n", "1\n2 2\n1 8\n", "1\n2 4\n0 0\n", "1\n2 1\n0 0\n", "1\n2 2\n-1 0\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
632
135
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two positive integers a and b, return the number of common factors of a and b. An integer x is a common factor of a and b if x divides both a and b.   Please complete the following python code precisely: ```pyth...
{"functional": "def check(candidate):\n assert candidate(a = 12, b = 6) == 4\n assert candidate(a = 25, b = 30) == 2\n\n\ncheck(Solution().commonFactors)"}
89
56
coding
Solve the programming task below in a Python markdown code block. Qwerty the Ranger took up a government job and arrived on planet Mars. He should stay in the secret lab and conduct some experiments on bacteria that have funny and abnormal properties. The job isn't difficult, but the salary is high. At the beginning o...
{"inputs": ["5 5 2 1\n", "1 1 2 2\n", "1 1 1 1\n", "3 1 3 4\n", "1 4 1 5\n", "5 4 1 4\n", "2 3 4 5\n", "2 2 5 4\n"], "outputs": ["2\n", "1\n", "1\n", "2\n", "0\n", "1\n", "3\n", "4\n"]}
390
118
coding
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"]}
394
156
coding
Solve the programming task below in a Python markdown code block. Chef is standing at coordinate A while Chefina is standing at coordinate B. In one step, Chef can increase or decrease his coordinate by at most K. Determine the minimum number of steps required by Chef to reach Chefina. ------ Input Format ------ -...
{"inputs": ["4\n10 20 3\n36 36 5\n50 4 100\n30 4 2\n"], "outputs": ["4\n0\n1\n13\n"]}
414
53
coding
Solve the programming task below in a Python markdown code block. Problem description. Dominic Toretto has taken his crew to compete in this years' Race Wars, a crew-on-crew tournament in which each member of one crew competes with a member of the other crew in a quarter mile drag race. Each win counts as one point for...
{"inputs": ["1\n3\n5 4 1\n5 4 1"], "outputs": ["2"]}
594
26
coding
Solve the programming task below in a Python markdown code block. You have an array of numbers. Your task is to sort ascending odd numbers but even numbers must be on their places. Zero isn't an odd number and you don't need to move it. If you have an empty array, you need to return it. *Example* ```python sort_arr...
{"functional": "_inputs = [[[5, 3, 2, 8, 1, 4, 11]], [[2, 22, 37, 11, 4, 1, 5, 0]], [[1, 111, 11, 11, 2, 1, 5, 0]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0]], [[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]], [[0, 1, 2, 3, 4, 9, 8, 7, 6, 5]]]\n_outputs = [[[1, 3, 2, 8, 5, 4, 11]], [[2, 22, 1, 5, 4, 11, 37, 0]], [[1, 1, 5, 11, 2, 11, 111, 0]], ...
135
482
coding
Solve the programming task below in a Python markdown code block. Write a program which reads an directed graph $G = (V, E)$, and finds the shortest distance from vertex $1$ to each vertex (the number of edges in the shortest path). Vertices are identified by IDs $1, 2, ... n$. Constraints * $1 \leq n \leq 100$ Inpu...
{"inputs": ["4\n1 2 1 4\n2 1 4\n3 0\n4 1 3", "4\n1 2 1 4\n2 1 4\n3 0\n4 1 4", "4\n1 2 2 4\n2 1 4\n3 0\n4 1 1", "4\n1 2 2 4\n2 1 1\n3 0\n4 1 3", "4\n1 2 1 1\n2 1 4\n3 0\n4 1 4", "4\n1 2 2 1\n2 1 1\n3 0\n4 1 3", "4\n1 2 1 4\n3 1 4\n3 0\n4 1 2", "4\n1 2 1 3\n0 1 1\n4 0\n4 1 1"], "outputs": ["1 0\n2 -1\n3 2\n4 1\n", "1 0\n...
303
366
coding
Solve the programming task below in a Python markdown code block. You have a team of N people. For a particular task, you can pick any non-empty subset of people. The cost of having x people for the task is x^{k}. Output the sum of costs over all non-empty subsets of people. -----Input----- Only line of input cont...
{"inputs": ["1 1\n", "3 2\n", "5 3\n", "5 3\n", "7 5\n", "3 3\n", "4 8\n", "1 1\n"], "outputs": ["1\n", "24\n", "800\n", "800\n", "181888", "54", "93320", "1\n"]}
333
98
coding
Solve the programming task below in a Python markdown code block. A frog is initially at position $0$ on the number line. The frog has two positive integers $a$ and $b$. From a position $k$, it can either jump to position $k+a$ or $k-b$. Let $f(x)$ be the number of distinct integers the frog can reach if it never jump...
{"inputs": ["7 5 3\n", "6 4 5\n", "7 5 3\n", "6 4 5\n", "26 92701 7\n", "26 92701 7\n", "3 998 99486\n", "3 998 99486\n"], "outputs": ["19\n", "10\n", "19\n", "10\n", "27\n", "27\n", "4\n", "4\n"]}
488
130
coding
Solve the programming task below in a Python markdown code block. In some other world, today is the day before Christmas Eve. Mr. Takaha is buying N items at a department store. The regular price of the i-th item (1 \leq i \leq N) is p_i yen (the currency of Japan). He has a discount coupon, and can buy one item with t...
{"inputs": ["2\n100\n100\n", "3\n7\n4428\n55", "3\n3\n4428\n55", "3\n2\n4428\n55", "3\n2\n4428\n76", "3\n1\n4428\n76", "3\n1\n4428\n99", "3\n0\n4428\n99"], "outputs": ["150\n", "2276\n", "2272\n", "2271\n", "2292\n", "2291\n", "2314\n", "2313\n"]}
292
164
coding
Solve the programming task below in a Python markdown code block. Given a tree T with non-negative weight, find the height of each node of the tree. For each node, the height is the distance to the most distant leaf from the node. Constraints * 1 ≤ n ≤ 10,000 * 0 ≤ wi ≤ 1,000 Input n s1 t1 w1 s2 t2 w2 : sn-1 tn-1 ...
{"inputs": ["4\n0 2 2\n1 2 1\n1 3 3", "4\n0 1 2\n1 2 2\n1 3 3", "4\n0 1 2\n1 2 1\n2 3 3", "4\n0 1 2\n1 2 0\n1 3 3", "4\n0 2 2\n1 2 1\n2 3 3", "4\n0 1 2\n1 2 0\n0 3 3", "4\n0 1 0\n1 2 0\n1 3 3", "4\n0 1 2\n0 2 0\n0 3 3"], "outputs": ["6\n3\n4\n6\n", "5\n3\n5\n5\n", "6\n4\n3\n6\n", "5\n3\n3\n5\n", "5\n4\n3\n5\n", "3\n5\n...
249
254
coding
Solve the programming task below in a Python markdown code block. You are given a huge decimal number consisting of $n$ digits. It is guaranteed that this number has no leading zeros. Each digit of this number is either 0 or 1. You may perform several (possibly zero) operations with this number. During each operation ...
{"inputs": ["2 1 0\n10\n", "2 1 0\n10\n", "3 1 0\n100\n", "3 1 0\n100\n", "3 2 0\n100\n", "4 2 1\n1011\n", "4 2 0\n1000\n", "4 1 0\n1000\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
498
135
coding
Solve the programming task below in a Python markdown code block. You are given an array $a$ of length $n$. You are also given a set of distinct positions $p_1, p_2, \dots, p_m$, where $1 \le p_i < n$. The position $p_i$ means that you can swap elements $a[p_i]$ and $a[p_i + 1]$. You can apply this operation any numbe...
{"inputs": ["1\n3 1\n3 1 1\n1\n", "1\n3 1\n3 1 1\n1\n", "1\n3 1\n3 2 1\n1\n", "1\n4 2\n4 4 1 2\n2 1\n", "1\n4 2\n4 4 1 2\n2 1\n", "1\n4 2\n4 3 1 2\n2 1\n", "1\n4 2\n6 3 1 2\n2 1\n", "1\n4 1\n4 4 1 2\n2 1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
723
186
coding
Solve the programming task below in a Python markdown code block. Two students of AtCoder Kindergarten are fighting over candy packs. There are three candy packs, each of which contains a, b, and c candies, respectively. Teacher Evi is trying to distribute the packs between the two students so that each student gets th...
{"inputs": ["4 45 8", "1 45 8", "1 57 8", "77 1 1", "77 1 2", "4 30 8", "1 45 5", "4 24 20"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "Yes\n"]}
231
103
coding
Solve the programming task below in a Python markdown code block. A pair of nodes, $(a,b)$, is a similar pair if the following conditions are true: node $a$ is the ancestor of node $b$ $abs(a-b)\leq k$ Given a tree where each node is labeled from $1$ to $n$, find the number of similar pairs in the tree. For example,...
{"inputs": ["5 2\n3 2\n3 1\n1 4\n1 5\n"], "outputs": ["4\n"]}
514
32
coding
Solve the programming task below in a Python markdown code block. Consider sequences \{A_1,...,A_N\} of length N consisting of integers between 1 and K (inclusive). There are K^N such sequences. Find the sum of \gcd(A_1, ..., A_N) over all of them. Since this sum can be enormous, print the value modulo (10^9+7). Here \...
{"inputs": ["5 2", "5 1", "7 2", "5 0", "8 5", "3 3", "1 2", "6 5"], "outputs": ["33\n", "1\n", "129\n", "0\n", "390889\n", "30\n", "3\n", "15697\n"]}
316
91
coding
Solve the programming task below in a Python markdown code block. You are given $n$ positive integers $a_1, \ldots, a_n$, and an integer $k \geq 2$. Count the number of pairs $i, j$ such that $1 \leq i < j \leq n$, and there exists an integer $x$ such that $a_i \cdot a_j = x^k$. -----Input----- The first line contai...
{"inputs": ["2 2\n1 90\n", "2 2\n40 90\n", "2 2\n40 90\n", "2 2\n70 90\n", "2 2\n70 126\n", "2 2\n130 126\n", "2 2\n61441 92480\n", "2 5\n49248 87211\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
326
148
coding
Solve the programming task below in a Python markdown code block. Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem: Find k integers such that the sum of two to the power of each number equals to the number n a...
{"inputs": ["1 2\n", "1 1\n", "7 2\n", "7 3\n", "7 4\n", "1 4\n", "9 4\n", "3 4\n"], "outputs": ["Yes\n-1 -1 \n", "Yes\n0 \n", "No\n", "Yes\n2 1 0 \n", "Yes\n1 1 1 0 \n", "Yes\n-2 -2 -2 -2 \n", "Yes\n2 2 -1 -1 \n", "Yes\n0 0 -1 -1 \n"]}
729
139
coding
Solve the programming task below in a Python markdown code block. Bob is a dance teacher and he started dance classes recently. He observes a strange attendance pattern among his students. Initially, there are no students. On day i, a new student starts attending the class. The student stops attending the class, if and...
{"inputs": ["4\n1\n2\n3\n4\n"], "outputs": ["odd\nodd\nodd\neven\n"]}
572
29
coding
Solve the programming task below in a Python markdown code block. You are given a polynomial of degree N with integer coefficients: f(x)=a_Nx^N+a_{N-1}x^{N-1}+...+a_0. Find all prime numbers p that divide f(x) for every integer x. Constraints * 0 \leq N \leq 10^4 * |a_i| \leq 10^9(0\leq i\leq N) * a_N \neq 0 * All va...
{"inputs": ["0\n8", "0\n5", "0\n3", "0\n7", "0\n63", "0\n56", "0\n15", "0\n54"], "outputs": ["2\n", "5\n", "3\n", "7\n", "3\n7\n", "2\n7\n", "3\n5\n", "2\n3\n"]}
229
90
coding
Solve the programming task below in a Python markdown code block. There is a line with 1000 cells numbered from 1 to 1000 from left to right and N coins placed on it. Coin i is placed at cell X_{i}, and no two coins are placed at the same cell. Bob would like to move the coins to the N leftmost cells of the line. To d...
{"inputs": ["2\n3 2\n2 4 7\n5 3\n1 2 3 4 5", "2\n3 2\n2 4 7\n3 3\n1 2 3 4 5", "2\n3 2\n2 4 7\n3 3\n1 2 3 4 9", "2\n3 2\n2 4 7\n3 3\n1 2 3 4 7", "2\n4 2\n1 4 7\n5 3\n1 2 3 4 9", "2\n4 1\n1 4 7\n5 6\n1 2 5 6 9", "2\n4 2\n1 4 5\n5 6\n1 2 3 4 9", "2\n3 2\n2 4 8\n6 3\n1 2 3 4 5"], "outputs": ["5\n0", "5\n0\n", "5\n4\n", "5\...
409
269
coding
Solve the programming task below in a Python markdown code block. Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down. Moon cycle lasts 3...
{"inputs": ["1\n8\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n5\n", "1\n6\n", "1\n7\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
610
87
coding
Solve the programming task below in a Python markdown code block. Greatest common divisor GCD(a, b) of two positive integers a and b is equal to the biggest integer d such that both integers a and b are divisible by d. There are many efficient algorithms to find greatest common divisor GCD(a, b), for example, Euclid al...
{"inputs": ["1 2\n", "1 1\n", "2 2\n", "3 4\n", "1 1\n", "3 4\n", "2 2\n", "4 4\n"], "outputs": ["1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "2\n", "4\n"]}
366
86
coding
Solve the programming task below in a Python markdown code block. Chef changed the password of his laptop a few days ago, but he can't remember it today. Luckily, he wrote the encrypted password on a piece of paper, along with the rules for decryption. The encrypted password is a string S consists of ASCII printable ch...
{"inputs": ["4\n2\n5 3\n3 1\n5\n0\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#xd098d", "4\n2\n5 3\n3 1\n5\n0\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#dd098x", "4\n2\n5 3\n3 1\n5\n-1\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# /\n0xd21#xd098d", "4\n2\n5 3\n3 1\n5\n-1\n01800.00\n0\n0.00100\n3\nx 0\nd 3\n# .\n0xd21#dd0...
555
695
coding
Solve the programming task below in a Python markdown code block. AtCoder Mart sells 1000000 of each of the six items below: * Riceballs, priced at 100 yen (the currency of Japan) each * Sandwiches, priced at 101 yen each * Cookies, priced at 102 yen each * Cakes, priced at 103 yen each * Candies, priced at 104 yen ea...
{"inputs": ["0", "3", "4", "8", "7", "5", "2", "1"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
235
62
coding
Solve the programming task below in a Python markdown code block. # Task * **_Given_** *three integers* `a` ,`b` ,`c`, **_return_** *the **_largest number_** obtained after inserting the following operators and brackets*: `+`, `*`, `()` * In other words , **_try every combination of a,b,c with [*+()] , and return the ...
{"functional": "_inputs = [[2, 1, 2], [2, 1, 1], [1, 1, 1], [1, 2, 3], [1, 3, 1], [2, 2, 2], [5, 1, 3], [3, 5, 7], [5, 6, 1], [1, 6, 1], [2, 6, 1], [6, 7, 1], [2, 10, 3], [1, 8, 3], [9, 7, 2], [1, 1, 10], [9, 1, 1], [10, 5, 6], [1, 10, 1]]\n_outputs = [[6], [4], [3], [9], [5], [8], [20], [105], [35], [8], [14], [48], [...
697
396
coding
Solve the programming task below in a Python markdown code block. There was a test in your class and you passed it. Congratulations! But you're an ambitious person. You want to know if you're better than the average student in your class. You receive an array with your peers' test scores. Now calculate the average and...
{"functional": "_inputs = [[[2, 3], 5], [[100, 40, 34, 57, 29, 72, 57, 88], 75], [[12, 23, 34, 45, 56, 67, 78, 89, 90], 69]]\n_outputs = [[True], [True], [True]]\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)...
195
245
coding
Solve the programming task below in a Python markdown code block. Chilly Willy loves playing with numbers. He only knows prime numbers that are digits yet. These numbers are 2, 3, 5 and 7. But Willy grew rather bored of such numbers, so he came up with a few games that were connected with them. Chilly Willy wants to f...
{"inputs": ["1\n", "5\n", "6\n", "4\n", "7\n", "8\n", "3\n", "2\n"], "outputs": ["-1\n", "10080", "100170", "1050", "1000020", "10000200", "210\n", "-1\n"]}
216
93
coding
Solve the programming task below in a Python markdown code block. Kevin and Nicky Sun have invented a new game called Lieges of Legendre. In this game, two players take turns modifying the game state with Kevin moving first. Initially, the game is set up so that there are n piles of cows, with the i-th pile containing ...
{"inputs": ["1 1\n1\n", "1 2\n1\n", "1 0\n3\n", "1 2\n3\n", "2 3\n7 7\n", "2 2\n2 5\n", "2 2\n2 4\n", "2 2\n2 2\n"], "outputs": ["Kevin\n", "Kevin\n", "Nicky\n", "Nicky\n", "Nicky\n", "Kevin\n", "Kevin\n", "Nicky\n"]}
400
114
coding
Solve the programming task below in a Python markdown code block. Takahashi and Aoki will have a battle using their monsters. The health and strength of Takahashi's monster are A and B, respectively, and those of Aoki's monster are C and D, respectively. The two monsters will take turns attacking, in the order Takahash...
{"inputs": ["46 4 4 5", "64 4 4 5", "64 8 4 5", "5 9 3 10", "54 8 4 5", "54 8 2 5", "54 6 2 5", "54 6 0 5"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n"]}
324
118
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of positive integers arr (not necessarily distinct), return the lexicographically largest permutation that is smaller than arr, that can be made with exactly one swap. If it cannot be done, then return ...
{"functional": "def check(candidate):\n assert candidate(arr = [3,2,1]) == [3,1,2]\n assert candidate(arr = [1,1,5]) == [1,1,5]\n assert candidate(arr = [1,9,4,6,7]) == [1,7,4,6,9]\n\n\ncheck(Solution().prevPermOpt1)"}
114
92
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin Chinese, Russian and Vietnamese as well. Sereja has an undirected graph on N vertices. There are edges between all but M pairs of vertices. A permutation p on the vertices of the graph is represented as p[1], p[2],...
{"inputs": ["2\n4 3\n1 2\n2 3\n3 4\n2 1\n1 2", "2\n4 3\n1 2\n2 3\n3 4\n2 1\n1 2"], "outputs": ["2\n0", "2\n0"]}
400
70
coding
Solve the programming task below in a Python markdown code block. Zaikia has $N$ sticks of distinct positive lengths $A_1,A_2,\dots,A_N$. For no good reason at all, he wants to know if there is a triplet of sticks which when connected end-to-end will form a non-trivial triangle. Here non-trivial refers to a triangle wi...
{"inputs": ["5\n4 2 10 3 5"], "outputs": ["YES\n5 4 3"]}
418
29
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array of positive integers price where price[i] denotes the price of the ith candy and a positive integer k. The store sells baskets of k distinct candies. The tastiness of a candy basket is the small...
{"functional": "def check(candidate):\n assert candidate(price = [13,5,1,8,21,2], k = 3) == 8\n assert candidate(price = [1,3,1], k = 2) == 2\n assert candidate(price = [7,7,7,7], k = 2) == 0\n\n\ncheck(Solution().maximumTastiness)"}
122
94
coding
Solve the programming task below in a Python markdown code block. # Task Given some sticks by an array `V` of positive integers, where V[i] represents the length of the sticks, find the number of ways we can choose three of them to form a triangle. # Example For `V = [2, 3, 7, 4]`, the result should be `1`. There ...
{"functional": "_inputs = [[[2, 3, 7, 4]], [[5, 6, 7, 8]], [[2, 2, 2, 2]], [[1, 2, 5]], [[1, 2, 3, 10, 20, 30, 4]], [[1, 2, 3]]]\n_outputs = [[1], [4], [4], [0], [1], [0]]\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, ab...
249
246
coding
Solve the programming task below in a Python markdown code block. Chef has invited Alice for his birthday party. Now, Alice is thinking about what to give Chef as a present. She should obviously choose a sequence ― what could possibly be a better birthday gift than a sequence! After some thinking, Alice chose a sequenc...
{"inputs": ["2\n2\n2 3\n4\n2 6 7 7"], "outputs": ["2\n64"]}
472
31
coding
Solve the programming task below in a Python markdown code block. "Night gathers, and now my watch begins. It shall not end until my death. I shall take no wife, hold no lands, father no children. I shall wear no crowns and win no glory. I shall live and die at my post. I am the sword in the darkness. I am the watcher ...
{"inputs": ["1\n1\n", "1\n6\n", "1\n0\n", "1\n3\n", "1\n3\n", "1\n1\n", "1\n6\n", "1\n0\n"], "outputs": ["0", "0", "0", "0", "0\n", "0\n", "0\n", "0\n"]}
413
82
coding
Solve the programming task below in a Python markdown code block. Consider the following $4 \times 4$ pattern: 1 2 4 7 3 5 8 11 6 9 12 14 10 13 15 16 You are given an integer $N$. Print the $N \times N$ pattern of the same kind (containing integers $1$ through $N^2$). -----Input----- - The first line of the inp...
{"inputs": ["1\n4"], "outputs": ["1 2 4 7\n3 5 8 11\n6 9 12 14\n10 13 15 16"]}
283
51
coding
Solve the programming task below in a Python markdown code block. We, the researchers who discovered and investigated the ancient nation Iwashiro, finally discovered the temple in the center of Iwashiro. A lithograph dedicated to the god of Iwashiro was stored in the temple. On the lithograph, two strings were written,...
{"inputs": ["abaa\nab", "`caa\nca", "accc\nac", "aba`\nab", "`baa\nab", "`baa\nac", "`caa\nac", "`caa\ncb"], "outputs": ["1\n", "2\n", "3\n", "1\n", "0\n", "0\n", "0\n", "0\n"]}
372
84
coding
Solve the programming task below in a Python markdown code block. Little Susie, thanks to her older brother, likes to play with cars. Today she decided to set up a tournament between them. The process of a tournament is described in the next paragraph. There are n toy cars. Each pair collides. The result of a collisio...
{"inputs": ["1\n-1\n", "1\n-1\n", "2\n-1 0\n0 -1\n", "2\n-1 1\n2 -1\n", "2\n-1 2\n1 -1\n", "2\n-1 3\n3 -1\n", "2\n-1 1\n2 -1\n", "2\n-1 0\n0 -1\n"], "outputs": ["1\n1 ", "1\n1\n", "2\n1 2 ", "1\n2 ", "1\n1 ", "0\n", "1\n2\n", "2\n1 2\n"]}
497
144
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed 2D integer array flowers, where flowers[i] = [starti, endi] means the ith flower will be in full bloom from starti to endi (inclusive). You are also given a 0-indexed integer array people of ...
{"functional": "def check(candidate):\n assert candidate(flowers = [[1,6],[3,7],[9,12],[4,13]], people = [2,3,7,11]) == [1,2,2,2]\n assert candidate(flowers = [[1,10],[3,3]], people = [3,3,2]) == [2,2,1]\n\n\ncheck(Solution().fullBloomFlowers)"}
166
104
coding
Solve the programming task below in a Python markdown code block. Raj is suffering from shot term memory loss so he is unable to remember his laptop password but he has a list of some string and the only thing that he remember about his password is alphanumeric and also that all the characters are unique. Given a lis...
{"inputs": ["absdbads\nasdjenfef\ntyerbet\nabc564"], "outputs": ["Invalid\nInvalid\nInvalid\nValid"]}
168
33
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s consisting of words and spaces, return the length of the last word in the string. A word is a maximal substring consisting of non-space characters only.   Please complete the following python code pre...
{"functional": "def check(candidate):\n assert candidate(s = \"Hello World\") == 5\n assert candidate(s = \" fly me to the moon \") == 4\n assert candidate(s = \"luffy is still joyboy\") == 6\n\n\ncheck(Solution().lengthOfLastWord)"}
83
72
coding
Solve the programming task below in a Python markdown code block. There is a grid, consisting of n rows and m columns. Each cell of the grid is either free or blocked. One of the free cells contains a lab. All the cells beyond the borders of the grid are also blocked. A crazy robot has escaped from this lab. It is cur...
{"inputs": ["4\n3 3\n...\n.L.\n...\n4 5\n#....\n..##L\n...#.\n.....\n1 1\nL\n1 9\n.#..L....\n", "4\n3 3\n...\n.L.\n...\n4 5\n#....\n..##L\n.#...\n.....\n1 1\nL\n1 9\n.#..L....\n", "4\n3 3\n...\n..L\n...\n4 5\n#....\n..##L\n.#...\n.....\n1 1\nL\n1 9\n.#..L....\n", "4\n3 3\n...\n..L\n...\n4 5\n#....\n..##L\n..#..\n.....\...
679
664
coding
Solve the programming task below in a Python markdown code block. Given a binary number (of $N$ bits) $X$. Find the highest power of 2 that divides this number. Note: If the binary number is "100" then the highest power of 2 that divides it is 2 (as $2^{2}$ = 4) ------ Input: ------ The first line contains N the num...
{"inputs": ["5\n10100"], "outputs": ["2"]}
175
18
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a street with n * 2 plots, where there are n plots on each side of the street. The plots on each side are numbered from 1 to n. On each plot, a house can be placed. Return the number of ways houses can be pla...
{"functional": "def check(candidate):\n assert candidate(n = 1) == 4\n assert candidate(n = 2) == 9\n\n\ncheck(Solution().countHousePlacements)"}
177
45