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
Solve the programming task below in a Python markdown code block. Two red beads are placed between every two blue beads. There are N blue beads. After looking at the arrangement below work out the number of red beads. @ @@ @ @@ @ @@ @ @@ @ @@ @ Implement count_red_beads(n) (in PHP count_red_beads($n); in Java, Javasc...
{"functional": "_inputs = [[0], [1], [3], [5]]\n_outputs = [[0], [0], [4], [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): return False\...
144
175
coding
Solve the programming task below in a Python markdown code block. Valera has got n domino pieces in a row. Each piece consists of two halves — the upper one and the lower one. Each of the halves contains a number from 1 to 6. Valera loves even integers very much, so he wants the sum of the numbers on the upper halves a...
{"inputs": ["1\n2 3\n", "1\n2 4\n", "1\n1 1\n", "1\n1 2\n", "1\n2 2\n", "1\n1 1\n", "1\n1 2\n", "1\n2 2\n"], "outputs": ["-1\n", "0\n", "-1\n", "-1\n", "0\n", "-1\n", "-1\n", "0\n"]}
454
103
coding
Solve the programming task below in a Python markdown code block. Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with length equal t...
{"inputs": ["5 2 5\n", "5 4 5\n", "3 5 3\n", "3 3 3\n", "7 2 7\n", "5 5 5\n", "4 4 1\n", "5 5 1\n"], "outputs": ["8", "64", "25", "9", "16", "125", "256", "3125"]}
310
104
coding
Solve the programming task below in a Python markdown code block. In this task Anna and Maria play a game with a very unpleasant rival. Anna and Maria are in the opposite squares of a chessboard (8 × 8): Anna is in the upper right corner, and Maria is in the lower left one. Apart from them, the board has several statue...
{"inputs": ["S......A\n.SS..S..\nS....S..\nSSS...S.\n.SS.SSS.\n.S.SS...\n..S..S..\nM.SS....\n", "SSSSSSSA\n......S.\n......S.\n.....SS.\n....SS..\n...SS...\n..SS....\nMSS.....\n", "S..SSSSA\n.S..S...\nS.S....S\nSS..S.S.\nSSSS.S..\n.SS..SS.\n....SS..\nMS..S...\n", "...SSS.A\n.....S..\n..S.S.SS\n.S.S...S\nS.S...S.\n....S...
570
350
coding
Solve the programming task below in a Python markdown code block. Chef has recently learned about number bases and is becoming fascinated. Chef learned that for bases greater than ten, new digit symbols need to be introduced, and that the convention is to use the first few letters of the English alphabet. For example, ...
{"inputs": ["4\n6\n9\n11\n24"], "outputs": ["4\n7\n8\n14"]}
501
29
coding
Solve the programming task below in a Python markdown code block. Little girl Margarita is a big fan of competitive programming. She especially loves problems about arrays and queries on them. Recently, she was presented with an array $a$ of the size of $10^9$ elements that is filled as follows: $a_1 = -1$ $a_2 = 2...
{"inputs": ["1\n682736 1001010010\n", "1\n580408 1001010010\n", "1\n1042324 1001010010\n", "1\n4162847 1001001010\n", "1\n1133909 1001010010\n", "1\n6379767 1001001010\n", "1\n1133909 1001010011\n", "1\n6379767 1001101010\n"], "outputs": ["500846373\n", "500795209\n", "501026167\n", "498419082\n", "499938051\n", "49731...
664
284
coding
Solve the programming task below in a Python markdown code block. You have decided to watch the best moments of some movie. There are two buttons on your player: Watch the current minute of the movie. By pressing this button, you watch the current minute of the movie and the player automatically proceeds to the next ...
{"inputs": ["1 1\n1 1\n", "1 3\n5 6\n", "1 2\n1 1\n", "1 1\n1 1\n", "1 3\n5 6\n", "1 2\n1 1\n", "1 3\n3 6\n", "1 4\n3 6\n"], "outputs": ["1\n", "3\n", "1\n", "1\n", "3\n", "1\n", "6\n", "6\n"]}
593
118
coding
Solve the programming task below in a Python markdown code block. There are $N$ villages numbered $1$ to $N$. The villages are connected through bi-directional paths in between them. The whole network is in the form of a tree. Each village has only $1$ fighter but they help each other in times of crisis by sending the...
{"inputs": ["2\n5\n1 2\n1 3\n2 4\n3 5\n3\n1 2\n2 3"], "outputs": ["1 2\n2 1"]}
523
46
coding
Solve the programming task below in a Python markdown code block. The sequence of integers $a_1, a_2, \dots, a_k$ is called a good array if $a_1 = k - 1$ and $a_1 > 0$. For example, the sequences $[3, -1, 44, 0], [1, -99]$ are good arrays, and the sequences $[3, 7, 8], [2, 5, 4, 1], [0]$ — are not. A sequence of integ...
{"inputs": ["1\n0\n", "1\n1\n", "1\n1\n", "1\n0\n", "1\n2\n", "1\n3\n", "1\n4\n", "1\n6\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
562
86
coding
Solve the programming task below in a Python markdown code block. In Chef's house there are N apples lying in a row on the floor. These apples are numbered from 1 (left most one) to N (right most one). The types of apples are also numbered by positive integers, and the type of apple i is Ti. Chef has recently brought t...
{"inputs": ["5 5\n2 4 3 2 1", "5 5\n2 4 9 2 5", "5 8\n2 4 3 2 1", "5 5\n2 4 3 4 1", "5 8\n2 4 5 3 1", "4 5\n2 4 3 3 1", "3 5\n2 4 9 2 5", "5 8\n2 4 3 3 1"], "outputs": ["2", "-1", "-1\n", "2\n", "3\n", "1\n", "-1\n", "-1\n"]}
619
156
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a binary string s and a positive integer n, return true if the binary representation of all the integers in the range [1, n] are substrings of s, or false otherwise. A substring is a contiguous sequence of chara...
{"functional": "def check(candidate):\n assert candidate(s = \"0110\", n = 3) == True\n assert candidate(s = \"0110\", n = 4) == False\n\n\ncheck(Solution().queryString)"}
101
56
coding
Solve the programming task below in a Python markdown code block. You are given a string s consisting of n lowercase Latin letters. You have to type this string using your keyboard. Initially, you have an empty string. Until you type the whole string, you may perform the following operation: add a character to the en...
{"inputs": ["1\na\n", "1\ns\n", "1\ns\n", "1\na\n", "1\nt\n", "1\n`\n", "2\naa\n", "2\naa\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n"]}
322
86
coding
Solve the programming task below in a Python markdown code block. You know that 1 kg of pulp can be used to make 1000 pages and 1 notebook consists of 100 pages. Suppose a notebook factory receives N kg of pulp, how many notebooks can be made from that? ------ Input Format ------ - First line will contain T, the n...
{"inputs": ["3\n1\n100\n50\n"], "outputs": ["10\n1000\n500\n"]}
319
33
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer array nums and an integer k, return true if it is possible to divide this array into k non-empty subsets whose sums are all equal.   Please complete the following python code precisely: ```python clas...
{"functional": "def check(candidate):\n assert candidate( nums = [4, 3, 2, 3, 5, 2, 1], k = 4) == True\n\n\ncheck(Solution().canPartitionKSubsets)"}
86
58
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two binary strings a and b, return their sum as a binary string.   Please complete the following python code precisely: ```python class Solution: def addBinary(self, a: str, b: str) -> str: ```
{"functional": "def check(candidate):\n assert candidate(a = \"1010\", b = \"1011\") == \"10101\"\n\n\ncheck(Solution().addBinary)"}
67
47
coding
Solve the programming task below in a Python markdown code block. Read problems statements in Mandarin chinese, Russian and Vietnamese as well. There are N minions who are competing in an election of the president of the ACM (Association of Cute Minions). They are standing in a line in the order from minion 1 to mini...
{"inputs": ["2\n4\n4 3 2 1\n5\n1 2 2 3 1"], "outputs": ["1 2 3 2\n2 3 2 3 1"]}
526
50
coding
Solve the programming task below in a Python markdown code block. Bob needs a fast way to calculate the volume of a cuboid with three values: `length`, `width` and the `height` of the cuboid. Write a function to help Bob with this calculation. ```if:shell In bash the script is ran with the following 3 arguments: `leng...
{"functional": "_inputs = [[2, 5, 6], [6.3, 3, 5]]\n_outputs = [[60], [94.5]]\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 ...
114
182
coding
Solve the programming task below in a Python markdown code block. Bash has set out on a journey to become the greatest Pokemon master. To get his first Pokemon, he went to Professor Zulu's Lab. Since Bash is Professor Zulu's favourite student, Zulu allows him to take as many Pokemon from his lab as he pleases. But Zul...
{"inputs": ["1\n1\n", "1\n4\n", "1\n1\n", "1\n4\n", "1\n2\n", "1\n5\n", "1\n3\n", "2\n3 6\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n"]}
445
88
coding
Solve the programming task below in a Python markdown code block. Vitya is studying in the third grade. During the last math lesson all the pupils wrote on arithmetic quiz. Vitya is a clever boy, so he managed to finish all the tasks pretty fast and Oksana Fillipovna gave him a new one, that is much harder. Let's deno...
{"inputs": ["1\n", "5\n", "4\n", "99\n", "91\n", "67\n", "11\n", "33\n"], "outputs": ["0\n", "0\n", "2\n", "54", "0", "0", "10\n", "21"]}
535
74
coding
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 a sequence $A_{1}, A_{2}, \ldots, A_{N}$. The sequence is circular, i.e. for each valid $i$, elements $A_{i}$ and $A_{i+1}$ are considered a...
{"inputs": ["3\n3\n0 0 0\n4\n1 0 1 0\n5\n1 1 0 1 0"], "outputs": ["0\n2\n3"]}
726
46
coding
Solve the programming task below in a Python markdown code block. In recreational mathematics, a [Keith number](https://en.wikipedia.org/wiki/Keith_number) or repfigit number (short for repetitive Fibonacci-like digit) is a number in the following integer sequence: `14, 19, 28, 47, 61, 75, 197, 742, 1104, 1537, 2208, ...
{"functional": "_inputs = [[14], [10], [4], [28], [23], [0], [19], [47], [34], [61], [58], [75], [197], [742], [1104], [1537], [2208], [2697], [7385], [31331], [120284], [1084051], [44121607], [251133297], [96189170155], [11812665388886672], [855191324330802397989], [18354972585225358067718266], [4179620576514742697470...
465
493
coding
Solve the programming task below in a Python markdown code block. You've got two numbers. As long as they are both larger than zero, they go through the same operation: subtract the lesser number from the larger one. If they equal substract one number from the another. For example, one operation transforms pair (4,17) ...
{"inputs": ["1\n920400783 7\n", "1\n718772242 7\n", "1\n718772242 8\n", "1\n718772242 3\n", "1\n718772242 5\n", "1\n589741341 5\n", "1\n589741341 9\n", "1\n459104377 9\n"], "outputs": ["131485833\n", "102681755\n", "89846534\n", "239590750\n", "143754452\n", "117948273\n", "65526818\n", "51011603\n"]}
242
227
coding
Solve the programming task below in a Python markdown code block. There are two infinite sources of water: hot water of temperature $h$; cold water of temperature $c$ ($c < h$). You perform the following procedure of alternating moves: take one cup of the hot water and pour it into an infinitely deep barrel; take...
{"inputs": ["1\n473 0 2\n", "1\n520 0 2\n", "1\n520 1 2\n", "1\n133 0 2\n", "1\n213 0 2\n", "1\n213 0 0\n", "1\n213 1 0\n", "1\n410 4 0\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n"]}
556
134
coding
Solve the programming task below in a Python markdown code block. # Task Given a square `matrix`, your task is to reverse the order of elements on both of its longest diagonals. The longest diagonals of a square matrix are defined as follows: * the first longest diagonal goes from the top left corner to the bottom ri...
{"functional": "_inputs = [[[[1, 2, 3], [4, 5, 6], [7, 8, 9]]], [[[239]]], [[[1, 10], [100, 1000]]], [[[43, 455, 32, 103], [102, 988, 298, 981], [309, 21, 53, 64], [2, 22, 35, 291]]]]\n_outputs = [[[[9, 2, 7], [4, 5, 6], [3, 8, 1]]], [[[239]]], [[[1000, 100], [10, 1]]], [[[291, 455, 32, 2], [102, 53, 21, 981], [309, 29...
258
403
coding
Solve the programming task below in a Python markdown code block. Given a triangle of numbers where each number is equal to the sum of the three numbers on top of it, find the first even number in a row. Explanatory Note: The vertex of the triangle (at the top) is 1. The structure of the triangle is shown below. Eac...
{"inputs": ["2\n3\n4\n"], "outputs": ["2\n3\n"]}
345
20
coding
Solve the programming task below in a Python markdown code block. Chef has a garden with $N$ plants arranged in a line in decreasing order of height. Initially the height of the plants are $A_1, A_2, ..., A_N$. The plants are growing, after each hour the height of the $i$-th plant increases by $i$ millimeters. Find the...
{"inputs": ["1\n3\n8 4 2"], "outputs": ["2"]}
373
20
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums. The effective value of three indices i, j, and k is defined as ((nums[i] | nums[j]) & nums[k]). The xor-beauty of the array is the XORing of the effective values of all th...
{"functional": "def check(candidate):\n assert candidate(nums = [1,4]) == 5\n assert candidate(nums = [15,45,20,2,34,35,5,44,32,30]) == 34\n\n\ncheck(Solution().xorBeauty)"}
170
72
coding
Solve the programming task below in a Python markdown code block. There are 3 problems in a contest namely A, B, C respectively. Alice bets Bob that problem C is the hardest while Bob says that problem B will be the hardest. You are given three integers S_{A}, S_{B}, S_{C} which denotes the number of successful submi...
{"inputs": ["3\n1 4 2\n16 8 10\n14 15 9\n"], "outputs": ["Draw\nBob\nAlice\n"]}
463
40
coding
Solve the programming task below in a Python markdown code block. Two players are playing a game of Tower Breakers! Player $1$ always moves first, and both players always play optimally.The rules of the game are as follows: Initially there are $n$ towers. Each tower is of height $m$. The players move in alternat...
{"inputs": ["2\n2 2\n1 4\n"], "outputs": ["2\n1\n"]}
706
24
coding
Solve the programming task below in a Python markdown code block. Polycarp was gifted an array $a$ of length $n$. Polycarp considers an array beautiful if there exists a number $C$, such that each number in the array occurs either zero or $C$ times. Polycarp wants to remove some elements from the array $a$ to make it b...
{"inputs": ["3\n6\n1 3 2 1 4 2\n4\n100 100 4 100\n8\n1 2 3 3 3 2 6 6\n", "3\n6\n1 3 2 1 4 2\n4\n100 101 4 100\n8\n1 2 3 3 3 2 6 6\n", "3\n6\n1 3 3 1 4 2\n4\n100 100 7 100\n8\n1 0 3 3 3 2 6 6\n", "3\n6\n1 3 3 1 2 2\n4\n100 100 7 100\n8\n1 0 3 3 3 2 6 6\n", "3\n6\n1 3 0 1 4 2\n4\n100 100 7 100\n8\n2 2 3 3 3 2 6 6\n", "3\...
516
486
coding
Solve the programming task below in a Python markdown code block. Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string s is denoted |s|. The Hamming distance between two strings s and t of equal length is defined as $\sum_{i = 1}^{|s|}|s_{i} - t_{i}|$, wh...
{"inputs": ["0\n0\n", "1\n0\n", "0\n1\n", "1\n1\n", "1\n0\n", "0\n1\n", "0\n0\n", "1\n1\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "1\n", "1\n", "0\n", "0\n"]}
523
86
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A parentheses string is a non-empty string consisting only of '(' and ')'. It is valid if any of the following conditions is true: It is (). It can be written as AB (A concatenated with B), where A and B are valid pa...
{"functional": "def check(candidate):\n assert candidate(s = \"))()))\", locked = \"010100\") == True\n assert candidate(s = \"()()\", locked = \"0000\") == True\n assert candidate(s = \")\", locked = \"0\") == False\n\n\ncheck(Solution().canBeValid)"}
212
78
coding
Solve the programming task below in a Python markdown code block. Little Petya has a birthday soon. Due this wonderful event, Petya's friends decided to give him sweets. The total number of Petya's friends equals to n. Let us remind you the definition of the greatest common divisor: GCD(a1, ..., ak) = d, where d repre...
{"inputs": ["8\n", "2\n", "3\n", "7\n", "9\n", "5\n", "4\n", "6\n"], "outputs": ["4849845\n3233230\n1939938\n1385670\n881790\n746130\n570570\n510510\n", "-1\n", "15\n10\n6\n", "255255\n170170\n102102\n72930\n46410\n39270\n30030\n", "111546435\n74364290\n44618574\n31870410\n20281170\n17160990\n13123110\n11741730\n969969...
504
316
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game with a binary string S of length N and an empty string T. They both take turns and Alice plays first. In Alice's turn, she picks the first character of string S, appends the character to either the front or back of str...
{"inputs": ["4\n2\n10\n4\n0001\n6\n010111\n10\n1110000010"], "outputs": ["10\n0100\n101101\n0011011000"]}
583
71
coding
Solve the programming task below in a Python markdown code block. In this kata, we will check is an array is (hyper)rectangular. A rectangular array is an N-dimensional array with fixed sized within one dimension. Its sizes can be repsented like A1xA2xA3...xAN. That means a N-dimensional array has N sizes. The 'As' a...
{"functional": "_inputs = [[[]]]\n_outputs = [[[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, tuple)):\n if len(a) != len(b): return False\n return all(_deep_e...
614
158
coding
Solve the programming task below in a Python markdown code block. There is an array with n elements a_1, a_2, ..., a_{n} and the number x. In one operation you can select some i (1 ≤ i ≤ n) and replace element a_{i} with a_{i} & x, where & denotes the bitwise and operation. You want the array to have at least two equ...
{"inputs": ["2 1\n3 5\n", "2 4\n1 2\n", "2 1\n2 4\n", "2 2\n4 5\n", "2 8\n2 3\n", "2 4\n2 3\n", "2 5\n1 3\n", "2 4\n1 2\n"], "outputs": ["2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "1\n", "2\n"]}
383
118
coding
Solve the programming task below in a Python markdown code block. You have k pieces of laundry, each of which you want to wash, dry and fold. You are at a laundromat that has n_1 washing machines, n_2 drying machines and n_3 folding machines. Each machine can process only one piece of laundry at a time. You can't dry a...
{"inputs": ["1 1 1 1 5 5 5\n", "5 2 4 5 9 9 6\n", "4 5 1 2 4 6 2\n", "1 3 2 2 5 2 8\n", "4 2 1 2 5 2 3\n", "4 2 1 2 5 2 3\n", "4 5 1 2 4 6 2\n", "5 2 4 5 9 9 6\n"], "outputs": ["15\n", "42\n", "30\n", "15\n", "17\n", "17", "30", "42"]}
539
171
coding
Solve the programming task below in a Python markdown code block. Chef likes to play with big numbers. Today, he has a big positive integer N. He can select any two digits from this number (the digits can be same but their positions should be different) and orders them in any one of the two possible ways. For each of t...
{"inputs": ["4\n65\n566\n11\n1623455078"], "outputs": ["A\nAB\nACDFGHIJKLNPQRSTUVW"]}
467
45
coding
Solve the programming task below in a Python markdown code block. Chef and Abhishek both are fighting for the post of Chairperson to be part of ACE committee and are trying their best. To select only one student their teacher gave them a binary string (string consisting of only 0's and 1's) and asked them to find numbe...
{"inputs": ["1\n4\n1010"], "outputs": ["4"]}
467
19
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers arr and an integer k. A value arr[i] is said to be stronger than a value arr[j] if |arr[i] - m| > |arr[j] - m| where m is the median of the array. If |arr[i] - m| == |arr[j] - m|, then arr[i...
{"functional": "def check(candidate):\n assert candidate(arr = [1,2,3,4,5], k = 2) == [5,1]\n assert candidate(arr = [1,1,3,5,5], k = 2) == [5,5]\n assert candidate(arr = [6,7,11,7,6,8], k = 5) == [11,8,6,6,7]\n assert candidate(arr = [6,-3,7,2,11], k = 3) == [-3,11,2]\n assert candidate(arr = [-7,22,17,...
370
176
coding
Solve the programming task below in a Python markdown code block. What is an anagram? Well, two words are anagrams of each other if they both contain the same letters. For example: ``` 'abba' & 'baab' == true 'abba' & 'bbaa' == true 'abba' & 'abbba' == false 'abba' & 'abca' == false ``` Write a function that will ...
{"functional": "_inputs = [['abba', ['aabb', 'abcd', 'bbaa', 'dada']], ['racer', ['crazer', 'carer', 'racar', 'caers', 'racer']], ['a', ['a', 'b', 'c', 'd']], ['ab', ['cc', 'ac', 'bc', 'cd', 'ab', 'ba', 'racar', 'caers', 'racer']], ['abba', ['a', 'b', 'c', 'd', 'aabb', 'bbaa', 'abab', 'baba', 'baab', 'abcd', 'abbba', '...
257
371
coding
Solve the programming task below in a Python markdown code block. Paul is an excellent coder and sits high on the CW leaderboard. He solves kata like a banshee but would also like to lead a normal life, with other activities. But he just can't stop solving all the kata!! Given an array (x) you need to calculate the Pa...
{"functional": "_inputs = [[['life', 'eating', 'life']], [['life', 'Petes kata', 'Petes kata', 'Petes kata', 'eating']], [['Petes kata', 'Petes kata', 'eating', 'Petes kata', 'Petes kata', 'eating']]]\n_outputs = [['Super happy!'], ['Super happy!'], ['Happy!']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinst...
193
220
coding
Solve the programming task below in a Python markdown code block. If you have completed the Tribonacci sequence kata, you would know by now that mister Fibonacci has at least a bigger brother. If not, give it a quick look to get how things work. Well, time to expand the family a little more: think of a Quadribonacci s...
{"functional": "_inputs = [[[0, 1], 10], [[1, 1], 10], [[0, 0, 0, 0, 1], 10], [[1, 0, 0, 0, 0, 0, 1], 10], [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], 20], [[0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10], [[0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0], 20], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 20], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 9], [[1, 2, 3, 4, 5, 6, ...
361
806
coding
Solve the programming task below in a Python markdown code block. # Task We have a N×N `matrix` (N<10) and a robot. We wrote in each point of matrix x and y coordinates of a point of matrix. When robot goes to a point of matrix, reads x and y and transfer to point with x and y coordinates. For each point in...
{"functional": "_inputs = [[[['0,1', '0,0', '1,2'], ['1,1', '1,0', '0,2'], ['2,1', '2,0', '0,0']], 2], [[['0,1', '0,0'], ['1,1', '1,0']], 2]]\n_outputs = [[8], [4]]\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=t...
567
227
coding
Solve the programming task below in a Python markdown code block. When multiple master devices are connected to a single bus (https://en.wikipedia.org/wiki/System_bus), there needs to be an arbitration in order to choose which of them can have access to the bus (and 'talk' with a slave). We implement here a very simpl...
{"functional": "_inputs = [['001000101', 9], ['000000101', 9], ['0000', 4]]\n_outputs = [['001000000'], ['000000100'], ['0000']]\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, tup...
303
214
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums and an integer k. You are initially standing at index 0. In one move, you can jump at most k steps forward without going outside the boundaries of the array. That is, you c...
{"functional": "def check(candidate):\n assert candidate(nums = [1,-1,-2,4,-7,3], k = 2) == 7\n assert candidate(nums = [10,-5,-2,4,0,3], k = 3) == 17\n assert candidate(nums = [1,-5,-20,4,-1,3,-6,-3], k = 2) == 0\n\n\ncheck(Solution().maxResult)"}
176
107
coding
Solve the programming task below in a Python markdown code block. Mysterious Chefland… Recently, Chef realised that Discuss, the educational system of Chefland, is out of date. Therefore, he is trying to find ways to update the infrastructure in the country. One possible way is to move all materials from Discuss to Dis...
{"inputs": ["5\n2 2 1 2\n11 10 5 9\n11 11 5 9\n12 11 5 9\n1 2 1 100"], "outputs": ["Chefirnemo\nChefirnemo\nPofik\nChefirnemo\nPofik"]}
639
81
coding
Solve the programming task below in a Python markdown code block. ZS the Coder has recently found an interesting concept called the Birthday Paradox. It states that given a random set of 23 people, there is around 50% chance that some two of them share the same birthday. ZS the Coder finds this very interesting, and de...
{"inputs": ["3 2\n", "1 3\n", "4 3\n", "2 4\n", "2 4\n", "1 3\n", "4 3\n", "3 2\n"], "outputs": ["1 8", "1 1", "23 128", "29 32", "29 32", "1 1", "23 128", "1 8\n"]}
551
105
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 0-indexed integer array nums of length n. You are initially standing at index 0. You can jump from index i to index j where i < j if: nums[i] <= nums[j] and nums[k] < nums[i] for all indexes k in the ...
{"functional": "def check(candidate):\n assert candidate(nums = [3,2,4,4,1], costs = [3,7,6,4,2]) == 8\n assert candidate(nums = [0,1,2], costs = [1,1,1]) == 2\n\n\ncheck(Solution().minCost)"}
188
77
coding
Solve the programming task below in a Python markdown code block. The Utopian Tree goes through 2 cycles of growth every year. Each spring, it doubles in height. Each summer, its height increases by 1 meter. A Utopian Tree sapling with a height of 1 meter is planted at the onset of spring. How tall will the tree be af...
{"inputs": ["3\n0\n1\n4\n"], "outputs": ["1\n2\n7\n"]}
451
24
coding
Solve the programming task below in a Python markdown code block. There are $n$ cities numbered from $1$ to $n$, and city $i$ has beauty $a_i$. A salesman wants to start at city $1$, visit every city exactly once, and return to city $1$. For all $i\ne j$, a flight from city $i$ to city $j$ costs $\max(c_i,a_j-a_i)$ d...
{"inputs": ["2\n4 0\n5 0\n", "2\n4 0\n5 0\n", "2\n5 2\n4 0\n", "2\n0 2\n4 0\n", "2\n-1 2\n4 0\n", "3\n1 9\n2 1\n4 1\n", "3\n2 1\n0 4\n4 1\n", "3\n1 1\n0 3\n3 1\n"], "outputs": ["1\n", "1\n", "3\n", "4\n", "5\n", "11\n", "6\n", "5\n"]}
438
148
coding
Solve the programming task below in a Python markdown code block. Given a list of integers, return the nth smallest integer in the list. **Only distinct elements should be considered** when calculating the answer. `n` will always be positive (`n > 0`) If the nth small integer doesn't exist, return `-1` (C++) / `None` ...
{"functional": "_inputs = [[[14, 12, 46, 34, 334], 3], [[4000], 1], [[14, 12, 46, 0, 334], 1]]\n_outputs = [[34], [4000], [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, tuple...
285
219
coding
Solve the programming task below in a Python markdown code block. A newly opened multinational brand has decided to base their company logo on the three most common characters in the company name. They are now trying out various combinations of company names and logos based on this condition. Given a string $\boldsymbo...
{"inputs": ["aabbbccde\n"], "outputs": ["b 3\na 2\nc 2\n"]}
380
27
coding
Solve the programming task below in a Python markdown code block. One day n friends met at a party, they hadn't seen each other for a long time and so they decided to make a group photo together. Simply speaking, the process of taking photos can be described as follows. On the photo, each photographed friend occupies...
{"inputs": ["2\n1 5\n2 3\n", "2\n2 3\n1 1\n", "2\n1 1\n1 2\n", "2\n1 1\n1 2\n", "2\n2 3\n1 1\n", "2\n1 5\n2 3\n", "2\n2 6\n1 1\n", "2\n2 5\n2 3\n"], "outputs": ["6 5 ", "1 6 ", "2 1 ", "2 1 ", "1 6 ", "6 5 ", "1 12\n", "6 10\n"]}
395
146
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the head of a linked list. Remove every node which has a node with a greater value anywhere to the right side of it. Return the head of the modified linked list.   Please complete the following python co...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([5,2,13,3,8])), list_node([13,8]))\n assert is_same_list(candidate(head = list_node([1,1,1,1])), list_node([1,1,1,1]))\n\n\ncheck(Solution().removeNodes)"}
129
83
coding
Solve the programming task below in a Python markdown code block. You are playing euchre and you want to know the new score after finishing a hand. There are two teams and each hand consists of 5 tricks. The team who wins the majority of the tricks will win points but the number of points varies. To determine the numbe...
{"functional": "_inputs = [[[4, 0], 1, False, [2, 2, 2, 2, 2]], [[4, 2], 1, True, [2, 2, 2, 2, 2]], [[4, 4], 2, False, [2, 2, 2, 2, 2]], [[4, 6], 2, True, [2, 2, 2, 2, 2]], [[7, 2], 1, False, [1, 2, 2, 2, 2]], [[7, 4], 1, True, [1, 2, 2, 2, 2]], [[7, 6], 2, False, [1, 2, 2, 2, 2]], [[7, 7], 2, True, [1, 2, 2, 2, 2]], [...
278
918
coding
Solve the programming task below in a Python markdown code block. .intersection() The .intersection() operator returns the intersection of a set and the set of elements in an iterable. Sometimes, the & operator is used in place of the .intersection() operator, but it only operates on the set of elements in set. Th...
{"inputs": ["9\n1 2 3 4 5 6 7 8 9\n9\n10 1 2 3 11 21 55 6 8\n"], "outputs": ["5\n"]}
489
56
coding
Solve the programming task below in a Python markdown code block. Chef has many friends, but his best friend is Hemant. They both love to watch anime. In fact, their weekends are meant for that only. Also, Hemant is highly into games, of which Chef is unaware. Hemant once gave a game to Chef and asked him to determine ...
{"inputs": ["3\n1\n3\n7"], "outputs": ["B\nA\nB"]}
294
22
coding
Solve the programming task below in a Python markdown code block. AquaMoon has $n$ friends. They stand in a row from left to right, and the $i$-th friend from the left wears a T-shirt with a number $a_i$ written on it. Each friend has a direction (left or right). In the beginning, the direction of each friend is right....
{"inputs": ["1\n2\n9 8\n", "1\n2\n4 3\n", "1\n2\n6 5\n", "1\n2\n4 3\n", "1\n2\n9 8\n", "1\n2\n6 5\n", "1\n2\n10 8\n", "1\n2\n10 8\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
573
120
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s containing only lowercase English letters and the '?' character, convert all the '?' characters into lowercase letters such that the final string does not contain any consecutive repeating characters....
{"functional": "def check(candidate):\n assert candidate(s = \"?zs\") == \"azs\"\n assert candidate(s = \"ubv?w\") == \"ubvaw\"\n\n\ncheck(Solution().modifyString)"}
152
52
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You have n robots. You are given two 0-indexed integer arrays, chargeTimes and runningCosts, both of length n. The ith robot costs chargeTimes[i] units to charge and costs runningCosts[i] units to run. You are also gi...
{"functional": "def check(candidate):\n assert candidate(chargeTimes = [3,6,1,3,4], runningCosts = [2,1,3,4,5], budget = 25) == 3\n assert candidate(chargeTimes = [11,12,19], runningCosts = [10,8,7], budget = 19) == 0\n\n\ncheck(Solution().maximumRobots)"}
197
102
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums containing distinct numbers, and you can perform the following operations until the array is empty: If the first element has the smallest value, remove it Otherwise, put the first ...
{"functional": "def check(candidate):\n assert candidate(nums = [3,4,-1]) == 5\n assert candidate(nums = [1,2,4,3]) == 5\n assert candidate(nums = [1,2,3]) == 3\n\n\ncheck(Solution().countOperationsToEmptyArray)"}
116
72
coding
Solve the programming task below in a Python markdown code block. You are given two positive integers $x$ and $y$. You can perform the following operation with $x$: write it in its binary form without leading zeros, add $0$ or $1$ to the right of it, reverse the binary form and turn it into a decimal number which is as...
{"inputs": ["3 3\n", "7 4\n", "2 8\n", "4 4\n", "8 8\n", "2 2\n", "6 1\n", "4 5\n"], "outputs": ["YES\n", "NO\n", "NO\n", "YES\n", "YES\n", "YES\n", "NO\n", "NO\n"]}
531
86
coding
Solve the programming task below in a Python markdown code block. Would you want to fight against bears riding horses? Me neither. Limak is a grizzly bear. He is a general of the dreadful army of Bearland. The most important part of an army is the cavalry of course. The cavalry of Bearland consists of N warriors and ...
{"inputs": ["2\n6\n12 9 7 1 20 10\n3 6 4 7 5 5\n4\n5 17 10 1\n200 400 800 600"], "outputs": ["YES\nNO"]}
635
71
coding
Solve the programming task below in a Python markdown code block. Little Dima has two sequences of points with integer coordinates: sequence (a1, 1), (a2, 2), ..., (an, n) and sequence (b1, 1), (b2, 2), ..., (bn, n). Now Dima wants to count the number of distinct sequences of points of length 2·n that can be assembled...
{"inputs": ["1\n1\n2\n3\n", "1\n1\n3\n3\n", "1\n1\n5\n3\n", "1\n1\n5\n2\n", "1\n1\n2\n7\n", "2\n1 2\n1 2\n4\n", "2\n1 2\n2 2\n4\n", "2\n2 2\n1 2\n4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "3\n", "3\n"]}
484
130
coding
Solve the programming task below in a Python markdown code block. You are given a tree with $N$ vertices (numbered $1$ through $N$) and a sequence of integers $A_1, A_2, \ldots, A_N$. You may choose an arbitrary permutation $p_1, p_2, \ldots, p_N$ of the integers $1$ through $N$. Then, for each vertex $i$, you should a...
{"inputs": ["2\n4\n1 2 3 4\n1 2\n2 3\n2 4\n5\n1 2 3 4 5\n1 2\n2 3\n3 4\n4 5"], "outputs": ["24\n15"]}
591
66
coding
Solve the programming task below in a Python markdown code block. You are given an array A = [A_{1}, A_{2}, \ldots, A_{N}], consisting of N integers. In one move, you can take two adjacent numbers A_{i} and A_{i+1}, delete them, and then insert the number A_{i} \land A_{i+1} at the deleted position. Here, \land denotes...
{"inputs": ["4\n4\n0 0 0 1\n2\n1 1\n6\n1 2 3 4 5 6\n4\n2 28 3 22\n"], "outputs": ["1\n0\n4\n3\n"]}
747
62
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. The k-beauty of an integer num is defined as the number of substrings of num when it is read as a string that meet the following conditions: It has a length of k. It is a divisor of num. Given integers num and k, re...
{"functional": "def check(candidate):\n assert candidate(num = 240, k = 2) == 2\n assert candidate(num = 430043, k = 2) == 2\n\n\ncheck(Solution().divisorSubstrings)"}
139
62
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. A confusing number is a number that when rotated 180 degrees becomes a different number with each digit valid. We can rotate digits of a number by 180 degrees to form new digits. When 0, 1, 6, 8, and 9 are rotated 18...
{"functional": "def check(candidate):\n assert candidate(6) == True\n assert candidate(89) == True\n assert candidate(11) == False\n assert candidate(25) == False\n\n\ncheck(Solution().confusingNumber)"}
216
59
coding
Solve the programming task below in a Python markdown code block. Vasya plays a computer game with ninjas. At this stage Vasya's ninja should get out of a deep canyon. The canyon consists of two vertical parallel walls, their height is n meters. Let's imagine that we split these walls into 1 meter-long areas and numbe...
{"inputs": ["1 1\n-\nX\n", "1 20\n-\n-\n", "2 1\n-X\nX-\n", "2 1\n-X\n-X\n", "2 0\n-X\n-X\n", "2 0\n-X\nX-\n", "2 2\n-X\nX-\n", "1 100000\n-\n-\n"], "outputs": ["YES\n", "YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "YES\n", "YES\n"]}
630
127
coding
Solve the programming task below in a Python markdown code block. There are n positive integers a_1, a_2, ..., a_n. For the one move you can choose any even value c and divide by two all elements that equal c. For example, if a=[6,8,12,6,3,12] and you choose c=6, and a is transformed into a=[3,8,12,3,3,12] after the m...
{"inputs": ["4\n6\n22 3 32 3 20 1\n1\n94\n4\n3 4 8 30\n2\n3 1 7\n", "4\n6\n22 6 18 5 20 1\n1\n311\n4\n2 4 8 16\n3\n3 1 7\n", "4\n6\n22 4 18 5 20 1\n1\n311\n4\n2 4 8 16\n3\n3 1 7\n", "4\n6\n37 6 40 3 20 1\n1\n757\n4\n2 6 8 16\n3\n3 1 7\n", "4\n6\n37 6 40 3 20 1\n1\n757\n4\n2 6 8 20\n3\n3 1 7\n", "4\n6\n40 8 40 3 20 1\n1...
582
454
coding
Solve the programming task below in a Python markdown code block. You are given string $\boldsymbol{\mathrm{~s~}}$ and number $\boldsymbol{\mbox{k}}$. Consider a substring $\boldsymbol{p}$ of string $\boldsymbol{\mathrm{~S~}}$. For each position of string $\boldsymbol{\mathrm{~S~}}$ mark it if there is an occurence o...
{"inputs": ["abaab\n2\n"], "outputs": ["3\n"]}
432
17
coding
Solve the programming task below in a Python markdown code block. ### Preface You are currently working together with a local community to build a school teaching children how to code. First plans have been made and the community wants to decide on the best location for the coding school. In order to make this decision...
{"functional": "_inputs = [[[[3, 7], [2, 2], [14, 1]], [{'id': 1, 'x': 3, 'y': 4}, {'id': 2, 'x': 8, 'y': 2}]], [[[54, 7], [1, 211], [14, 44], [12, 5], [14, 7]], [{'id': 1, 'x': 44, 'y': 55}, {'id': 2, 'x': 12, 'y': 57}, {'id': 3, 'x': 23, 'y': 66}]], [[[152, 7], [1, 211], [14, 56], [12, 4], [142, 7]], [{'id': 1, 'x': ...
345
954
coding
Solve the programming task below in a Python markdown code block. You are given a set $\mbox{A}$ and $n$ other sets. Your job is to find whether set $\mbox{A}$ is a strict superset of each of the $N$ sets. Print True, if $\mbox{A}$ is a strict superset of each of the $N$ sets. Otherwise, print False. A strict s...
{"inputs": ["1 2 3 4 5 6 7 8 9 10 11 12 23 45 84 78\n2\n1 2 3 4 5\n100 11 12\n"], "outputs": ["False\n"]}
577
73
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a positive integer n, return the smallest positive integer that is a multiple of both 2 and n.   Please complete the following python code precisely: ```python class Solution: def smallestEvenMultiple(self, ...
{"functional": "def check(candidate):\n assert candidate(n = 5) == 10\n assert candidate(n = 6) == 6\n\n\ncheck(Solution().smallestEvenMultiple)"}
70
46
coding
Solve the programming task below in a Python markdown code block. Tonight, Chef would like to hold a party for his $N$ friends. All friends are invited and they arrive at the party one by one in an arbitrary order. However, they have certain conditions — for each valid $i$, when the $i$-th friend arrives at the party a...
{"inputs": ["3\n2\n0 0\n6\n3 1 0 0 5 5\n3\n1 2 3"], "outputs": ["2\n4\n0"]}
516
44
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array nums. A subsequence of nums is called a square streak if: The length of the subsequence is at least 2, and after sorting the subsequence, each element (except the first element) is the ...
{"functional": "def check(candidate):\n assert candidate(nums = [4,3,6,16,8,2]) == 3\n assert candidate(nums = [2,3,5,6,7]) == -1\n\n\ncheck(Solution().longestSquareStreak)"}
156
65
coding
Solve the programming task below in a Python markdown code block. The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then t...
{"inputs": ["5\n1\n2\n3\n4\n5"], "outputs": ["1\n1\n32\n1\n32\n654\n1\n32\n654\n10987\n1\n32\n654\n10987\n1514131211"]}
235
77
coding
Solve the programming task below in a Python markdown code block. Given two positive numbers B and C, what is the minimum positive value of A, such that A \cdot B is divisible by C. Here, A \cdot B denotes the value obtained when A is multiplied by B. ------ Input Format ------ - The first line will contain an int...
{"inputs": ["2\n2 4\n8 12"], "outputs": ["2\n3"]}
341
23
coding
Solve the programming task below in a Python markdown code block. Alice and Bob are playing a game. They start with a positive integer $n$ and take alternating turns doing operations on it. Each turn a player can subtract from $n$ one of its divisors that isn't $1$ or $n$. The player who cannot make a move on his/her ...
{"inputs": ["4\n1\n4\n12\n69\n"], "outputs": ["Bob\nAlice\nAlice\nBob\n"]}
363
30
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given two strings s and t consisting of only lowercase English letters. Return the minimum number of characters that need to be appended to the end of s so that t becomes a subsequence of s. A subsequence is a...
{"functional": "def check(candidate):\n assert candidate(s = \"coaching\", t = \"coding\") == 4\n assert candidate(s = \"abcde\", t = \"a\") == 0\n assert candidate(s = \"z\", t = \"abcde\") == 5\n\n\ncheck(Solution().appendCharacters)"}
120
73
coding
Solve the programming task below in a Python markdown code block. You are given a string A. Find a string B, where B is a palindrome and A is a subsequence of B. A subsequence of a string is a string that can be derived from it by deleting some (not necessarily consecutive) characters without changing the order of the...
{"inputs": ["ab\n", "ab\n", "ba\n", "ac\n", "ab\n", "aba\n", "aba\n", "abb\n"], "outputs": ["abba", "abba\n", "baab\n", "acca\n", "abba\n", "abaaba", "abaaba\n", "abbbba\n"]}
314
77
coding
Solve the programming task below in a Python markdown code block. There is a huge blanket on your bed but unfortunately it has N stains. You cover them using a single, rectangular silk cloth. The silk is expensive, which is why the rectangular piece needs to have the least area as possible. You love this blanket and d...
{"inputs": ["5 2\n0 1\n3 3\n2 0\n0 3\n2 3\n"], "outputs": ["8\n"]}
450
36
coding
Solve the programming task below in a Python markdown code block. Your task is to write function ```findSum```. Upto and including ```n```, this function will return the sum of all multiples of 3 and 5. For example: ```findSum(5)``` should return 8 (3 + 5) ```findSum(10)``` should return 33 (3 + 5 + 6 + 9 + 10) Als...
{"functional": "_inputs = [[5], [10], [100], [1000]]\n_outputs = [[8], [33], [2418], [234168]]\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)...
117
186
coding
Solve the programming task below in a Python markdown code block. "I don't have any fancy quotes." - vijju123 Chef was reading some quotes by great people. Now, he is interested in classifying all the fancy quotes he knows. He thinks that all fancy quotes which contain the word "not" are Real Fancy; quotes that do not ...
{"inputs": ["2\ni do not have any fancy quotes\nwhen nothing goes right go left"], "outputs": ["Real Fancy\nregularly fancy"]}
322
32
coding
Solve the programming task below in a Python markdown code block. Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representations does a given positive integer have? For example, the integer 53 has two representations 5 + 7 + 11 + 13 + 17 and 53. The integer 41...
{"inputs": ["2\n3\n25\n2\n4\n429\n1\n56\n0", "2\n3\n25\n2\n4\n429\n1\n94\n0", "2\n3\n25\n2\n4\n429\n0\n94\n0", "2\n3\n17\n70\n4\n429\n1\n56\n0", "2\n3\n25\n70\n4\n429\n1\n56\n0", "2\n3\n17\n70\n4\n429\n1\n85\n0", "2\n4\n17\n70\n4\n429\n1\n85\n0", "2\n3\n2\n41\n20\n666\n46\n53\n0"], "outputs": ["1\n1\n0\n1\n0\n0\n0\n1\n...
347
336
coding
Solve the programming task below in a Python markdown code block. Given three numbers $n, a, b$. You need to find an adjacency matrix of such an undirected graph that the number of components in it is equal to $a$, and the number of components in its complement is $b$. The matrix must be symmetric, and all digits on th...
{"inputs": ["3 1 2\n", "3 3 3\n", "5 1 1\n", "2 1 1\n", "1 1 1\n", "3 1 1\n", "5 2 2\n", "4 1 1\n"], "outputs": ["YES\n001\n001\n110\n", "NO\n", "YES\n01000\n10100\n01010\n00101\n00010\n", "NO\n", "YES\n0\n", "NO\n", "NO\n", "YES\n0100\n1010\n0101\n0010\n"]}
561
166
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given the head of a linked list with n nodes. For each node in the list, find the value of the next greater node. That is, for each node, find the value of the first node that is next to it and has a strictly ...
{"functional": "def check(candidate):\n assert candidate(head = list_node([2,1,5])) == [5,5,0]\n assert candidate(head = list_node([2,7,4,3,5])) == [7,0,5,5,0]\n\n\ncheck(Solution().nextLargerNodes)"}
195
75
coding
Solve the programming task below in a Python markdown code block. If you visit Aizu Akabeko shrine, you will find a unique paper fortune on which a number with more than one digit is written. Each digit ranges from 1 to 9 (zero is avoided because it is considered a bad omen in this shrine). Using this string of numeri...
{"inputs": ["88", "73", "19", "31", "799", "836", "138", "774"], "outputs": ["0\n", "4\n", "8\n", "2\n", "2\n", "5\n", "5\n", "3\n"]}
385
74
coding
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 palindromic substrings in it. A string is a palindrome when it reads the same backward as forward. A substring is a contiguous sequence of characters within the string.   Please ...
{"functional": "def check(candidate):\n assert candidate(s = \"abc\") == 3\n assert candidate(s = \"aaa\") == 6\n\n\ncheck(Solution().countSubstrings)"}
92
44
coding
Solve the programming task below in a Python markdown code block. Read problem statements in [Mandarin], [Russian], and [Vietnamese] as well. You are given a sequence of integers A_{1}, A_{2}, \ldots, A_{N} and an integer K. Find the number of contiguous subsequences A_{L}, A_{L+1}, \ldots, A_{R} such that R-L+1 ≥ K a...
{"inputs": ["1\n5 3\n1 2 3 4 5"], "outputs": ["1"]}
425
26
coding
Solve the programming task below in a Python markdown code block. You are given $n$ distinct points on a plane. The coordinates of the $i$-th point are $(x_i, y_i)$. For each point $i$, find the nearest (in terms of Manhattan distance) point with integer coordinates that is not among the given $n$ points. If there are...
{"inputs": ["1\n1 1\n", "1\n200000 200000\n", "6\n2 2\n1 2\n2 1\n3 2\n2 3\n5 5\n", "8\n4 4\n2 4\n2 2\n2 3\n1 4\n4 2\n1 3\n3 3\n"], "outputs": ["1 0\n", "200000 199999\n", "1 1\n1 1\n2 0\n3 1\n2 4\n5 4\n", "4 3\n2 5\n2 1\n2 5\n1 5\n4 1\n1 2\n3 2\n"]}
485
178
coding
Solve the programming task below in a Python markdown code block. The activity of a panipuri seller is "making a panipuri and putting it on the palte of his customer". $N$ customers are eating panipuri, Given an array $A$ of length $N$, $i^{th}$ customer takes $A_i$ seconds to eat a panipuri. The Speed of Pani...
{"inputs": ["2\n4\n2 4 6 3\n5\n2 3 4 6 5"], "outputs": ["2\n3"]}
702
36
coding
Please solve the programming task below using a self-contained code snippet in a markdown code block. Suppose you have n integers labeled 1 through n. A permutation of those n integers perm (1-indexed) is considered a beautiful arrangement if for every i (1 <= i <= n), either of the following is true: perm[i] is divi...
{"functional": "def check(candidate):\n assert candidate(n = 2) == 2\n assert candidate(n = 1) == 1\n\n\ncheck(Solution().countArrangement)"}
127
44
coding
Solve the programming task below in a Python markdown code block. There are n villages in a Chefland. Some of the villages have electricity facilities, other doesn't. You can consider the villages arranged in line in the order 1 to n from left to right. i-th of village can be considered at xi coordinates. Chef decided...
{"inputs": ["2\n2\n01\n1 2\n3\n100\n1 5 6"], "outputs": ["1\n5"]}
491
35
coding
Solve the programming task below in a Python markdown code block. problem There are many $ N $ colored balls of different weights in the queue. The queue is in ascending order from the beginning: $ 1,2,3, \ dots, N-1, N, 1,2,3, \ dots, N-1, N, 1,2,3, \ dots $ The balls are lined up, followed by the balls of color $ N ...
{"inputs": ["6 3\n1 1 9 0 1 47 0 72", "6 4\n1 1 9 0 1 47 0 72", "6 4\n1 1 9 0 0 47 0 72", "6 3\n2 0 5 0 2 23 15 72", "6 3\n2 0 5 0 0 25 15 72", "6 3\n2 0 9 0 1 25 15 72", "6 3\n2 1 9 0 1 25 15 72", "7 4\n1 78 15 3 1 14 15 72"], "outputs": ["55\n", "102\n", "103\n", "28\n", "30\n", "34\n", "33\n", "350\n"]}
460
240
coding
Solve the programming task below in a Python markdown code block. You are given a string S consisting of lowercase English letters. Another string T is initially empty. Determine whether it is possible to obtain S = T by performing the following operation an arbitrary number of times: * Append one of the following at ...
{"inputs": ["dre`merer", "dre`meqer", "reqem`erd", "reqem`erc", "cre`meqer", "bre`meqer", "cre`mdqer", "cre`mdqeq"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
171
91
coding
Solve the programming task below in a Python markdown code block. The only difference between the easy and the hard versions is the maximum value of $k$. You are given an infinite sequence of form "112123123412345$\dots$" which consist of blocks of all consecutive positive integers written one after another. The first...
{"inputs": ["1\n9124\n", "1\n9602\n", "1\n16966\n", "1\n52232\n", "1\n13891\n", "1\n72551\n", "1\n74714\n", "1\n25335\n"], "outputs": ["4\n", "9\n", "1\n", "5\n", "9\n", "1\n", "5\n", "1\n"]}
567
116
coding
Solve the programming task below in a Python markdown code block. Rahul is assigned a task by his fellow mates.He has to take a string from somewhere and first of all he has to calculate the weight of that string.The weight of string is calculated by adding the ASCII values of each characters in that string and then di...
{"inputs": ["Hello", "Worldd", "Hello World"], "outputs": ["olleH", "d", "l"]}
237
27
coding
Solve the programming task below in a Python markdown code block. You have array a_1, a_2, ..., a_{n}. Segment [l, r] (1 ≤ l ≤ r ≤ n) is good if a_{i} = a_{i} - 1 + a_{i} - 2, for all i (l + 2 ≤ i ≤ r). Let's define len([l, r]) = r - l + 1, len([l, r]) is the length of the segment [l, r]. Segment [l_1, r_1], is longer...
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n2\n", "1\n4\n", "1\n5\n", "1\n3\n", "1\n7\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
326
86