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.
Pinkie Pie has bought a bag of patty-cakes with different fillings! But it appeared that not all patty-cakes differ from one another with filling. In other words, the bag contains some patty-cakes with the same filling.
Pinkie Pie eats the patty-cakes o... | {"inputs": ["1\n15\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n", "1\n15\n1 2 3 4 5 1 2 3 4 5 1 2 3 4 5\n", "1\n15\n1 2 3 4 5 1 2 3 4 5 2 2 3 4 5\n", "1\n15\n1 2 3 4 5 1 2 3 4 5 2 1 3 4 5\n", "1\n15\n2 2 3 4 5 1 2 3 4 5 2 2 3 4 5\n", "1\n15\n1 2 3 7 5 1 2 3 4 5 1 2 3 4 9\n", "1\n15\n1 2 3 3 3 1 2 3 3 5 2 1 3 6 5\n", "1\n15\n1 2 3 ... | 666 | 334 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two string arrays words1 and words2, return the number of strings that appear exactly once in eachΒ of the two arrays.
Β
Please complete the following python code precisely:
```python
class Solution:
def coun... | {"functional": "def check(candidate):\n assert candidate(words1 = [\"leetcode\",\"is\",\"amazing\",\"as\",\"is\"], words2 = [\"amazing\",\"leetcode\",\"is\"]) == 2\n assert candidate(words1 = [\"b\",\"bb\",\"bbb\"], words2 = [\"a\",\"aa\",\"aaa\"]) == 0\n assert candidate(words1 = [\"a\",\"ab\"], words2 = [\"a... | 82 | 118 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
In a special ranking system, each voter gives a rank from highest to lowest to all teams participating in the competition.
The ordering of teams is decided by who received the most position-one votes. If two or more t... | {"functional": "def check(candidate):\n assert candidate(votes = [\"ABC\",\"ACB\",\"ABC\",\"ACB\",\"ACB\"]) == \"ACB\"\n assert candidate(votes = [\"WXYZ\",\"XYZW\"]) == \"XWYZ\"\n assert candidate(votes = [\"ZMNAGUEDSJYLBOPHRQICWFXTVK\"]) == \"ZMNAGUEDSJYLBOPHRQICWFXTVK\"\n assert candidate(votes = [\"BCA\... | 189 | 163 |
coding | Solve the programming task below in a Python markdown code block.
There is a data which provides heights (in meter) of mountains. The data is only for ten mountains.
Write a program which prints heights of the top three mountains in descending order.
Constraints
0 β€ height of mountain (integer) β€ 10,000
Input
Hei... | {"inputs": ["100\n0\n0\n3561\n000\n98\n9\n15\n1\n297", "100\n-3\n-4\n629\n010\n48\n2\n1\n4\n112", "100\n-4\n-2\n629\n110\n71\n1\n1\n3\n112", "100\n-8\n0\n651\n010\n104\n1\n1\n3\n112", "100\n-8\n0\n552\n011\n104\n1\n1\n3\n112", "100\n-8\n0\n901\n011\n104\n1\n1\n3\n112", "100\n-8\n0\n901\n011\n193\n1\n1\n3\n112", "100\n-... | 248 | 375 |
coding | Solve the programming task below in a Python markdown code block.
You are playing the game "Arranging The Sheep". The goal of this game is to make the sheep line up. The level in the game is described by a string of length $n$, consisting of the characters '.' (empty space) and '*' (sheep). In one move, you can move an... | {"inputs": ["2\n6\n**..**\n4\n**..\n", "2\n6\n**..**\n4\n**..\n", "2\n6\n**..**\n4\n..**\n", "2\n6\n**.**.\n4\n..**\n", "2\n6\n**..**\n4\n.*.*\n", "2\n6\n**.**.\n4\n*.*.\n", "2\n6\n.**.**\n4\n*..*\n", "2\n6\n**..**\n4\n*..*\n"], "outputs": ["4\n0\n", "4\n0\n", "4\n0\n", "2\n0\n", "4\n1\n", "2\n1\n", "2\n2\n", "4\n2\n"]... | 486 | 189 |
coding | Solve the programming task below in a Python markdown code block.
A map of some object is a rectangular field consisting of n rows and n columns. Each cell is initially occupied by the sea but you can cover some some cells of the map with sand so that exactly k islands appear on the map. We will call a set of sand cell... | {"inputs": ["2 3\n", "6 5\n", "2 1\n", "1 0\n", "2 4\n", "2 0\n", "1 1\n", "2 2\n"], "outputs": ["NO", "YES\nLSLSLS\nSLSLSS\nSSSSSS\nSSSSSS\nSSSSSS\nSSSSSS\n", "YES\nLS\nSS\n", "YES\nS\n", "NO", "YES\nSS\nSS\n", "YES\nL\n", "YES\nLS\nSL\n"]} | 384 | 125 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return the maximum difference between two successive elements in its sorted form. If the array contains less than two elements, return 0.
You must write an algorithm that runs in linear ti... | {"functional": "def check(candidate):\n assert candidate(nums = [3,6,9,1]) == 3\n assert candidate(nums = [10]) == 0\n\n\ncheck(Solution().maximumGap)"} | 96 | 50 |
coding | Solve the programming task below in a Python markdown code block.
Suppose you have a string S which has length N and is indexed from 0 to Nβ1. String R is the reverse of the string S. The string S is funny if the condition |SiβSiβ1|=|RiβRiβ1| is true for every i from 1 to Nβ1.
(Note: Given a string str, stri denotes t... | {"inputs": ["2\nacxz\nbcxz", "2\nivvkxq\nivvkx", "10\njkotzxzxrxtzytlruwrxytyzsuzytwyzxuzytryzuzysxvsmupouysywywqlhg\neklrywzvpxtvoptlrskmskszvwzsuzxrtvyzwruqvyxusqwupnurqmtltnltsmuyxqoksyurpwqpv\nefhpuvqvnuwpvwysvnunostvpqvxtxsvqwqvsxtxvqpvtsonunvsywvpwunvqvupxzy\notytmpszumnryqvxpvnvxyvpvprumnvsqwqwtsqyqksqvnuqpxszwz... | 188 | 400 |
coding | Solve the programming task below in a Python markdown code block.
Hooray! Polycarp turned $n$ years old! The Technocup Team sincerely congratulates Polycarp!
Polycarp celebrated all of his $n$ birthdays: from the $1$-th to the $n$-th. At the moment, he is wondering: how many times he turned beautiful number of years?
... | {"inputs": ["6\n18\n1\n9\n100500\n33\n1000000000\n"], "outputs": ["10\n1\n9\n45\n12\n81\n"]} | 456 | 56 |
coding | Solve the programming task below in a Python markdown code block.
Recently, Mishka started noticing that his keyboard malfunctions β maybe it's because he was playing rhythm games too much. Empirically, Mishka has found out that every other time he presses a key, it is registered as if the key was pressed twice. For ex... | {"inputs": ["4\n4\nossu\n2\naa\n6\naddonn\n3\nqwe\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | 600 | 39 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer array rectangles where rectangles[i] = [li, hi] indicates that ith rectangle has a length of li and a height of hi. You are also given a 2D integer array points where points[j] = [xj, yj] is... | {"functional": "def check(candidate):\n assert candidate(rectangles = [[1,2],[2,3],[2,5]], points = [[2,1],[1,4]]) == [2,1]\n assert candidate(rectangles = [[1,1],[2,2],[3,3]], points = [[1,3],[1,1]]) == [1,3]\n\n\ncheck(Solution().countRectangles)"} | 228 | 94 |
coding | Solve the programming task below in a Python markdown code block.
There is a group of N friends who wish to enroll in a course together. The course has a maximum capacity of M students that can register for it. If there are K other students who have already enrolled in the course, determine if it will still be possible... | {"inputs": ["3\n2 50 27\n5 40 38\n100 100 0\n"], "outputs": ["Yes\nNo\nYes\n"]} | 360 | 44 |
coding | Solve the programming task below in a Python markdown code block.
A tetromino is a figure formed by joining four squares edge to edge. We will refer to the following seven kinds of tetromino as I-, O-, T-, J-, L-, S- and Z-tetrominos, respectively:
a60bcb8e9e8f22e3af51049eda063392.png
Snuke has many tetrominos. The n... | {"inputs": ["1 1 1 0 0 0 0", "4 0 1 0 0 0 0", "0 3 0 0 1 0 0", "0 3 0 0 2 0 0", "6 0 2 0 0 0 0", "2 5 1 0 1 2 2", "1 4 0 0 4 0 3", "0 0 0 0 1 0 0"], "outputs": ["1\n", "4\n", "3\n", "5\n", "6\n", "7\n", "8\n", "0\n"]} | 390 | 158 |
coding | Solve the programming task below in a Python markdown code block.
### Task
King Arthur and his knights are having a New Years party. Last year Lancelot was jealous of Arthur, because Arthur had a date and Lancelot did not, and they started a duel.
To prevent this from happening again, Arthur wants to make sure that ... | {"functional": "_inputs = [[[1, -1, 1]], [[-1, -1, -1]], [[1, -1]], [[1, 1, 1]], [[]]]\n_outputs = [[True], [False], [False], [True], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance... | 241 | 202 |
coding | Solve the programming task below in a Python markdown code block.
Sandy is a professor at a very reputed institute. The institute mandates that all the lectures be communicated in English. As Sandy is not very good at English(or anything actually) the presentations he displays in class have a lot of spelling mistakes i... | {"inputs": ["1\n5 2\nszhbdvrngk\nqzhxibnuec\njfsalpwfkospl\nlevjehdkjy\nwdfhzgatuh\nszhbdvcngk\nqzhxbnuec"], "outputs": ["szhbdvrngk\nqzhxibnuec"]} | 739 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Little Lucy loves to arrange her flowers in patterns similar to those of a binary search tree. Her father, a computer scientist himself, takes note of this and finds out that she has N flowers. Every day she takes some of these N flowers and arranges the... | {"inputs": ["4\n1\n2\n3\n4\n"], "outputs": ["1\n4\n14\n50 \n"]} | 359 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Some time ago Lesha found an entertaining string $s$ consisting of lowercase English letters. Lesha immediately developed an unique algorithm for this string and shared it with you. The algorithm is as follows.
Lesha chooses an arbitrary (possibly zero)... | {"inputs": ["g\n", "g\n", "h\n", "tt\n", "go\n", "tt\n", "go\n", "ut\n"], "outputs": ["1 g\n", "1 g\n", "1 h\n", "0 \n1 t\n", "2 go\n1 o\n", "0 \n1 t\n", "2 go\n1 o\n", "2 ut\n1 t\n"]} | 690 | 93 |
coding | Solve the programming task below in a Python markdown code block.
Ekiden competitions are held every year in Aizukuni. The country of Aiz is dotted with N towns, each numbered from 1 to N. Several towns are connected by roads that allow them to come and go directly to each other. You can also follow several roads betwe... | {"inputs": ["4 5\n1 2 2\n1 3 2\n2 3 1\n2 4 2\n3 4 1", "7 9\n2 1 2\n1 3 1\n2 3 2\n2 4 4\n2 6 1\n6 4 1\n3 5 1\n3 5 1\n4 7 3\n5 7 2\n6 7 1", "7 9\n2 1 2\n1 3 1\n2 3 2\n2 4 4\n2 6 1\n6 1 1\n3 5 1\n3 5 1\n4 7 3\n5 7 2\n6 7 1", "7 9\n2 1 2\n1 3 1\n2 3 2\n2 4 4\n2 6 1\n6 4 1\n3 5 1\n3 6 1\n4 7 3\n5 7 2\n6 7 1", "7 9\n2 1 2\n1... | 588 | 589 |
coding | Solve the programming task below in a Python markdown code block.
We have a large square grid with H rows and W columns.
Iroha is now standing in the top-left cell.
She will repeat going right or down to the adjacent cell, until she reaches the bottom-right cell.
However, she cannot enter the cells in the intersection ... | {"inputs": ["2 3 1 1\n", "10 7 3 4\n", "100000 100000 99999 99999\n", "100000 100000 44444 55555\n"], "outputs": ["2\n", "3570\n", "1\n", "738162020\n"]} | 285 | 110 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n integer matrix grid, and three integers row, col, and color. Each value in the grid represents the color of the grid square at that location.
Two squares are called adjacent if they are next to ... | {"functional": "def check(candidate):\n assert candidate(grid = [[1,1],[1,2]], row = 0, col = 0, color = 3) == [[3,3],[3,2]]\n assert candidate(grid = [[1,2,2],[2,3,2]], row = 0, col = 1, color = 3) == [[1,3,3],[2,3,3]]\n assert candidate(grid = [[1,1,1],[1,1,1],[1,1,1]], row = 1, col = 1, color = 2) == [[2,2,... | 211 | 170 |
coding | Solve the programming task below in a Python markdown code block.
Recently, the students of School 179 have developed a unique algorithm, which takes in a binary string $s$ as input. However, they soon found out that if some substring $t$ of $s$ is a palindrome of length greater than 1, the algorithm will work incorrec... | {"inputs": ["1\n6\n101010\n", "4\n1\n1\n2\n10\n2\n01\n4\n1010\n", "1\n26\n01111111111111111111111111\n"], "outputs": ["NO\n", "YES\nYES\nYES\nNO\n", "NO\n"]} | 450 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Gematria is an Assyro-Babylonian-Greek system of code and numerology later adopted into Jewish culture. The system assigns numerical value to a word or a phrase in the belief that words or phrases with identical numerical values bear some relation to eac... | {"functional": "_inputs = [['love'], ['jaels'], ['JAELS'], ['Devil'], ['Coding is fun']]\n_outputs = [[775], [716], [716], [738], [458]]\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, (l... | 334 | 195 |
coding | Solve the programming task below in a Python markdown code block.
A boy Petya loves chess very much. He even came up with a chess piece of his own, a semiknight. The semiknight can move in any of these four directions: 2 squares forward and 2 squares to the right, 2 squares forward and 2 squares to the left, 2 squares ... | {"inputs": ["1\n...#...#\n........\n.#...K..\n........\n...#...#\n........\n.K...#..\n........\n", "1\nK.#....#\n...#..#.\n..#.....\n..#.###.\n..#.....\n...#....\n.#.....#\n.#...##K\n", "1\n...#...#\n........\n.#...K..\n........\n...#...#\n........\n.K...#..\n........\n", "1\nK.#....#\n...#..#.\n..#.....\n..#.###.\n..#... | 642 | 364 |
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 the number of subarrays of nums where the greatest common divisor of the subarray's elements is k.
A subarray is a contiguous non-empty sequence of elements within ... | {"functional": "def check(candidate):\n assert candidate(nums = [9,3,1,2,6,3], k = 3) == 4\n assert candidate(nums = [4], k = 7) == 0\n\n\ncheck(Solution().subarrayGCD)"} | 120 | 65 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed string word and a character ch, reverse the segment of word that starts at index 0 and ends at the index of the first occurrence of ch (inclusive). If the character ch does not exist in word, do noth... | {"functional": "def check(candidate):\n assert candidate(word = \"abcdefd\", ch = \"d\") == \"dcbaefd\"\n assert candidate(word = \"xyxzxe\", ch = \"z\") == \"zxyxxe\"\n assert candidate(word = \"abcd\", ch = \"z\") == \"abcd\"\n\n\ncheck(Solution().reversePrefix)"} | 152 | 81 |
coding | Solve the programming task below in a Python markdown code block.
Let's define the cost of a simple undirected graph as the sum of the costs of its nodes. The cost of a node is defined as DK, where D is its degree.
You are given N and K. You need to find the sum of the costs of all possible simple undirected graphs wi... | {"inputs": ["5\n1 1\n2 3\n3 2\n6 5\n20 20\n"], "outputs": ["0\n2\n36\n67584000\n956922563\n"]} | 706 | 60 |
coding | Solve the programming task below in a Python markdown code block.
$2^n$ teams participate in a playoff tournament. The tournament consists of $2^n - 1$ games. They are held as follows: in the first phase of the tournament, the teams are split into pairs: team $1$ plays against team $2$, team $3$ plays against team $4$,... | {"inputs": ["1\n1\n", "1\n0\n", "2\n01\n", "2\n00\n", "2\n11\n", "3\n101\n", "3\n000\n", "3\n010\n"], "outputs": ["2 ", "1 ", "2 3 ", "1 ", "4 ", "4 5 6 7 ", "1 ", "2 3 4 5 "]} | 574 | 102 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an n x n binary matrix grid, return the length of the shortest clear path in the matrix. If there is no clear path, return -1.
A clear path in a binary matrix is a path from the top-left cell (i.e., (0, 0)) to t... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,1],[1,0]]) == 2\n assert candidate(grid = [[0,0,0],[1,1,0],[1,1,0]]) == 4\n assert candidate(grid = [[1,0,0],[1,1,0],[1,1,0]]) == -1\n\n\ncheck(Solution().shortestPathBinaryMatrix)"} | 187 | 96 |
coding | Solve the programming task below in a Python markdown code block.
Hossam woke up bored, so he decided to create an interesting array with his friend Hazem.
Now, they have an array $a$ of $n$ positive integers, Hossam will choose a number $a_i$ and Hazem will choose a number $a_j$.
Count the number of interesting pair... | {"inputs": ["2\n3\n1 1 1\n2\n1 2\n", "2\n5\n6 2 3 8 1\n6\n7 2 8 3 2 10\n", "2\n5\n1 1 1 1 1\n6\n7 2 8 3 2 10\n"], "outputs": ["6\n2\n", "2\n4\n", "20\n4\n"]} | 530 | 105 |
coding | Solve the programming task below in a Python markdown code block.
Introduction
The GADERYPOLUKI is a simple substitution cypher used in scouting to encrypt messages. The encryption is based on short, easy to remember key. The key is written as paired letters, which are in the cipher simple replacement.
The most freq... | {"functional": "_inputs = [['Gug hgs g cgt', 'gaderypoluki'], ['Dkucr pu yhr ykbir', 'politykarenu'], ['ABCD', 'gaderypoluki'], ['Ala has a cat', 'gaderypoluki']]\n_outputs = [['Ala has a cat'], ['Dance on the table'], ['GBCE'], ['Gug hgs g cgt']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float)... | 380 | 235 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in mandarin chinese, russian and vietnamese as well.
You are given N integers: A_{1}, A_{2}, ..., A_{N}. You need to count the number of pairs of indices (i, j) such that 1 β€ i < j β€ N and A_{i} | A_{j} β€ max(A_{i}, A_{j}).
No... | {"inputs": ["1\n3\n1 2 3"], "outputs": ["2"]} | 629 | 20 |
coding | Solve the programming task below in a Python markdown code block.
You are given an integer sequence $A_1, A_2, \ldots, A_N$. For any pair of integers $(l, r)$ such that $1 \le l \le r \le N$, let's define $\mathrm{OR}(l, r)$ as $A_l \lor A_{l+1} \lor \ldots \lor A_r$. Here, $\lor$ is the bitwise OR operator.
In total, ... | {"inputs": ["4\n3\n1 2 7\n2\n1 2\n3\n6 5 8\n5\n12 32 45 23 47"], "outputs": ["NO\nYES\nYES\nNO"]} | 564 | 57 |
coding | Solve the programming task below in a Python markdown code block.
Chef's professor is planning to give his class a group assignment. There are 2N students in the class, with distinct roll numbers ranging from 1 to 2N. Chef's roll number is X.
The professor decided to create N groups of 2 students each. The groups were... | {"inputs": ["3\n2 2\n3 1\n3 4\n"], "outputs": ["3\n6\n3"]} | 456 | 29 |
coding | Solve the programming task below in a Python markdown code block.
You are given two integers $a$ and $b$.
In one move, you can choose some integer $k$ from $1$ to $10$ and add it to $a$ or subtract it from $a$. In other words, you choose an integer $k \in [1; 10]$ and perform $a := a + k$ or $a := a - k$. You may use ... | {"inputs": ["1\n5 5\n", "1\n5 5\n", "1\n7 5\n", "1\n2 5\n", "1\n2 9\n", "1\n2 6\n", "1\n0 6\n", "1\n12 5\n"], "outputs": ["0\n", "0\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 454 | 103 |
coding | Solve the programming task below in a Python markdown code block.
Right now she actually isn't. But she will be, if you don't solve this problem.
You are given integers n, k, A and B. There is a number x, which is initially equal to n. You are allowed to perform two types of operations: Subtract 1 from x. This opera... | {"inputs": ["9\n2\n3\n1\n", "7\n2\n3\n1\n", "7\n2\n3\n1\n", "7\n2\n1\n1\n", "9\n2\n3\n0\n", "9\n2\n3\n1\n", "5\n5\n2\n20\n", "19\n3\n4\n2\n"], "outputs": ["6\n", "8\n", "8\n", "4\n", "3\n", "6\n", "8\n", "12\n"]} | 404 | 121 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed string word of length nΒ consisting of digits, and a positive integerΒ m.
The divisibility array div of word is an integer array of length n such that:
div[i] = 1 if theΒ numeric valueΒ ofΒ word[... | {"functional": "def check(candidate):\n assert candidate(word = \"998244353\", m = 3) == [1,1,0,0,0,1,1,0,0]\n assert candidate(word = \"1010\", m = 10) == [0,1,0,1]\n\n\ncheck(Solution().divisibilityArray)"} | 140 | 91 |
coding | Solve the programming task below in a Python markdown code block.
Luke, an intergalactic traveller went on a trip across the universe and got candies from the different planets he visited. He comes back with $N$ candies and decides to distribute them among his $M$ friends. However, Luke only wants a fair distribution o... | {"inputs": ["2 \n28 6 2 \n78 5 3"], "outputs": ["2\n1"]} | 382 | 32 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.
There are $N$ watchtowers built in a row. Each watchtower can only accommodate one person. Some of them are already occupied by members of the Night's Watch.... | {"inputs": ["2\n6\n010001\n11\n00101010000"], "outputs": ["1\n3"]} | 467 | 38 |
coding | Solve the programming task below in a Python markdown code block.
Find the number of ways that a given integer, $\mbox{X}$, can be expressed as the sum of the $N^{\mbox{th}}$ powers of unique, natural numbers.
For example, if $X=13$ and $N=2$, we have to find all combinations of unique squares adding up to $13$. The... | {"inputs": ["10\n2\n", "100\n2\n", "100\n3\n"], "outputs": ["1\n", "3\n", "1\n"]} | 470 | 41 |
coding | Solve the programming task below in a Python markdown code block.
Vanya and his friend Vova play a computer game where they need to destroy n monsters to pass a level. Vanya's character performs attack with frequency x hits per second and Vova's character performs attack with frequency y hits per second. Each character... | {"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 1 2\n1\n", "2 1 1\n1\n2\n", "2 1 2\n1\n2\n", "2 1 2\n1\n4\n", "2 1 1\n1\n1\n", "2 1 1\n1\n2\n"], "outputs": ["Both\n", "Both\n", "Vova\n", "Both\nBoth\n", "Vova\nBoth\n", "Vova\nVova\n", "Both\nBoth\n", "Both\nBoth\n"]} | 449 | 142 |
coding | Solve the programming task below in a Python markdown code block.
Innovation technologies are on a victorious march around the planet. They integrate into all spheres of human activity!
A restaurant called "Dijkstra's Place" has started thinking about optimizing the booking system.
There are n booking requests recei... | {"inputs": ["1\n1 1\n1\n1\n", "1\n2 1\n1\n1\n", "1\n2 1\n1\n1\n", "1\n1 1\n1\n1\n", "1\n0 1\n1\n1\n", "1\n0 1\n1\n2\n", "1\n0 1\n1\n3\n", "1\n0 1\n1\n5\n"], "outputs": ["1 1\n1 1\n", "0 0\n", "0 0\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n", "1 1\n1 1\n"]} | 592 | 174 |
coding | Solve the programming task below in a Python markdown code block.
=====Function Descriptions=====
mean
The mean tool computes the arithmetic mean along the specified axis.
import numpy
my_array = numpy.array([ [1, 2], [3, 4] ])
print numpy.mean(my_array, axis = 0) #Output : [ 2. 3.]
print numpy.mean(my_arra... | {"inputs": ["2 2\n1 2\n3 4"], "outputs": ["[1.5 3.5]\n[1. 1.]\n1.118033988749895"]} | 580 | 56 |
coding | Solve the programming task below in a Python markdown code block.
A sequence of $n$ numbers is called a permutation if it contains all integers from $1$ to $n$ exactly once. For example, the sequences [$3, 1, 4, 2$], [$1$] and [$2,1$] are permutations, but [$1,2,1$], [$0,1$] and [$1,3,4$] β are not.
Polycarp lost his ... | {"inputs": ["1\n1 2\n4\n", "1\n2 4\n5 1\n", "1\n3 13\n4 1 3\n", "1\n7 489\n5 29 12 16 25 36 18\n", "2\n1 9\n2\n9 9\n11 6 5 13 7 10 2 3 12\n", "5\n3 13\n3 1 4\n1 1\n1\n3 3\n1 4 2\n2 1\n4 3\n5 6\n1 2 3 4 5\n", "1\n50 870\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 3... | 695 | 352 |
coding | Solve the programming task below in a Python markdown code block.
You are given a directed acyclic graph with n vertices and m edges. There are no self-loops or multiple edges between any pair of vertices. Graph can be disconnected.
You should assign labels to all vertices in such a way that:
Labels form a valid pe... | {"inputs": ["2 1\n2 1\n", "2 1\n2 1\n", "3 3\n1 2\n1 3\n3 2\n", "3 3\n1 2\n1 3\n3 2\n", "5 4\n3 1\n2 1\n2 3\n4 5\n", "5 4\n3 1\n2 1\n2 5\n4 5\n", "5 4\n3 1\n2 1\n2 3\n4 5\n", "4 5\n3 1\n4 1\n2 3\n3 4\n2 4\n"], "outputs": ["2 1 \n", "2 1\n", "1 3 2 \n", "1 3 2\n", "3 1 2 4 5 \n", "3 1 2 4 5\n", "3 1 2 4 5\n", "4 1 2 3 \... | 333 | 232 |
coding | Solve the programming task below in a Python markdown code block.
In AtCoder city, there are five antennas standing in a straight line. They are called Antenna A, B, C, D and E from west to east, and their coordinates are a, b, c, d and e, respectively.
Two antennas can communicate directly if the distance between the... | {"inputs": ["1\n0\n7\n1\n5\n3", "1\n0\n7\n0\n5\n3", "1\n0\n9\n0\n5\n3", "1\n0\n5\n8\n4\n1", "1\n0\n7\n2\n5\n3", "1\n1\n9\n0\n5\n3", "1\n0\n5\n8\n4\n0", "1\n0\n2\n8\n4\n1"], "outputs": [":(\n", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n"]} | 451 | 150 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a sorted array nums of n non-negative integers and an integer maximumBit. You want to perform the following query n times:
Find a non-negative integer k < 2maximumBit such that nums[0] XOR nums[1] XOR .... | {"functional": "def check(candidate):\n assert candidate(nums = [0,1,1,3], maximumBit = 2) == [0,3,2,3]\n assert candidate(nums = [2,3,4,7], maximumBit = 3) == [5,2,6,5]\n assert candidate(nums = [0,1,2,2,5,7], maximumBit = 3) == [4,3,6,4,6,7]\n\n\ncheck(Solution().getMaximumXor)"} | 158 | 122 |
coding | Solve the programming task below in a Python markdown code block.
Raj loves to listen to songs in his free time. Itβs his birthday tomorrow and his friend Neelansh wants his gift to be the most unique. Being great at making music, he decides to produce a song for him. However, Raj likes songs according to their beauty.... | {"inputs": ["2\n8\n1 2 3 4 5 6 7 8\n16\n1 2 1 2 3 3 4 4 5 5 6 6 7 8 7 8"], "outputs": ["1\n2"]} | 396 | 67 |
coding | Solve the programming task below in a Python markdown code block.
In this problem you are given a sequence of $N$ positive integers $S[1],S[2],\dots,S[N]$. In addition you are given an integer $T$, and your aim is to find the number of quadruples $(i,j,k,l)$, such that $1 \le i < j < k < l \le N$, and $S[i] + S[j] + S... | {"inputs": ["6 20 3 1 1 2 5 10"], "outputs": ["1"]} | 557 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Chef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 5. If any of the permutations is divisible by 5 then print 1 else print 0.
-----Input:-----
- First-line will contain $T$, the number of test case... | {"inputs": ["2\n19\n385"], "outputs": ["0\n1"]} | 176 | 21 |
coding | Solve the programming task below in a Python markdown code block.
Chef is given two arrays A and B of length N each.
In one operation Chef can choose one element of A and one element of B and increase them by 1.
More formally:
Chef can pick two integers i, j (1β€ i, j β€ N) and increment A_{i} and B_{j} by 1.
Determin... | {"inputs": ["3\n2\n1 2\n2 1\n3\n1 1 2\n2 2 1\n3\n4 6 8\n5 7 6\n"], "outputs": ["1\n-1\n2\n"]} | 634 | 57 |
coding | Solve the programming task below in a Python markdown code block.
You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.
The output of the function f is another string of the same length. The i-th character... | {"inputs": ["d\ny\n", "r\nl\n", "s\nl\n", "s\nm\n", "s\nn\n", "d\nx\n", "d\nz\n", "ba\nba\n"], "outputs": ["-1\n", "l\n", "l\n", "m\n", "n\n", "-1\n", "-1\n", "ba\n"]} | 377 | 87 |
coding | Solve the programming task below in a Python markdown code block.
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or ... | {"inputs": ["1 1 1\n0\n", "1 1 1\n1\n", "1 1 1\n1\n", "1 1 2\n1\n", "1 1 1\n0\n", "2 1 1\n1\n1\n", "2 1 1\n1\n0\n", "2 1 1\n0\n1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n1\n", "0\n0\n", "0\n0\n"]} | 602 | 130 |
coding | Solve the programming task below in a Python markdown code block.
An infinitely long railway has a train consisting of n cars, numbered from 1 to n (the numbers of all the cars are distinct) and positioned in arbitrary order. David Blaine wants to sort the railway cars in the order of increasing numbers. In one move he... | {"inputs": ["1\n1\n", "2\n1 2\n", "2\n2 1\n", "3\n3 2 1\n", "3\n1 2 3\n", "3\n3 1 2\n", "3\n1 3 2\n", "3\n2 3 1\n"], "outputs": ["0", "0", "1", "2", "0", "1", "1", "1"]} | 276 | 102 |
coding | Solve the programming task below in a Python markdown code block.
For given integer n, count the totatives of n, that is, the positive integers less than or equal to n that are relatively prime to n.
Input
n
An integer n (1 β€ n β€ 1000000000).
Output
The number of totatives in a line.
Examples
Input
6
Outp... | {"inputs": ["5", "2", "3", "6", "16", "31", "61", "59"], "outputs": ["4\n", "1\n", "2\n", "2", "8\n", "30\n", "60\n", "58\n"]} | 107 | 68 |
coding | Solve the programming task below in a Python markdown code block.
Continuing from previous version of codeXplod series i.e. CodeXplod 1.0,Chandu and daspal are still fighting over a matter of MOMO's(they are very fond of Mo Mos of sector 3..:P).This time the fight became so savior that they want to kill each other.As w... | {"inputs": ["51\n8 10 Chandu\n2 2959 Daspal\n2903 6 Chandu\n9 2938 Daspal\n10 2907 Daspal\n8 2966 Daspal\n8 2938 Daspal\n4 2984 Daspal\n5 2939 Daspal\n2 2975 Daspal\n2925 10 Chandu\n4 2982 Daspal\n10 2959 Daspal\n3 2906 Daspal\n5 2904 Daspal\n2983 5 Chandu\n10 2998 Daspal\n10 2980 Daspal\n6 2913 Daspal\n9 2974 Daspal\n... | 478 | 722 |
coding | Solve the programming task below in a Python markdown code block.
Joisino is planning to open a shop in a shopping street.
Each of the five weekdays is divided into two periods, the morning and the evening. For each of those ten periods, a shop must be either open during the whole period, or closed during the whole per... | {"inputs": ["1\n1 1 0 1 0 0 0 1 0 1\n3 4 5 6 7 8 9 -4 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 0\n3 1 5 6 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 1 1 0 1\n3 1 5 6 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 1\n3 1 5 6 7 8 9 -4 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 1\n3 1 5 6 7 8 9 -7 -3 4 -2", "1\n1 1 0 1 0 0 0 1 0 0\n3 1 5 2 7 8 9 -7 -3 4 -... | 615 | 397 |
coding | Solve the programming task below in a Python markdown code block.
Chef has a binary string S of size N. Chef can perform the following operation on the string:
Select any substring of size 3 and reverse it.
Find the minimum *distance* between any two 1s Chef can achieve, by applying the above operation any (possibly z... | {"inputs": ["3\n2\n11\n3\n101\n7\n0100101\n"], "outputs": ["1\n2\n1"]} | 560 | 38 |
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.
Two players (let's call them A and B) are playing a game on a row of cells. A cell may contain the character 'A', contain the character 'B' or be emp... | {"inputs": ["3\nA.B\nA..B\nA..B.A..B"], "outputs": ["A\nA\nB"]} | 574 | 30 |
coding | Solve the programming task below in a Python markdown code block.
Bob and Alice are having a lockout match between them. There are three problems in the contest worth A, B, and C points respectively. Only the first player to solve a problem gets points for that problem. It is impossible for Bob and Alice to solve a pro... | {"inputs": ["3\n2 5 2\n4 2 2\n3 5 5"], "outputs": ["NO\nYES\nNO"]} | 390 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Akaki, a patissier, can make N kinds of doughnut using only a certain powder called "Okashi no Moto" (literally "material of pastry", simply called Moto below) as ingredient. These doughnuts are called Doughnut 1, Doughnut 2, ..., Doughnut N. In order to... | {"inputs": ["3 0010\n3\n101\n5", "3 1\n575\n3\n9\n15", "3 1\n668\n3\n9\n15", "3 2\n668\n3\n9\n15", "3 2\n668\n6\n9\n15", "3 2\n668\n1\n9\n15", "3 1010\n17\n101\n6", "3 0010\n17\n101\n6"], "outputs": ["-30\n", "-193\n", "-224\n", "-223\n", "-111\n", "-673\n", "150\n", "-16\n"]} | 456 | 183 |
coding | Solve the programming task below in a Python markdown code block.
itertools.product()
This tool computes the cartesian product of input iterables.
It is equivalent to nested for-loops.
For example, product(A, B) returns the same as ((x,y) for x in A for y in B).
Sample Code
>>> from itertools import product
>>... | {"inputs": [" 1 2\n 3 4\n"], "outputs": [" (1, 3) (1, 4) (2, 3) (2, 4)\n"]} | 707 | 45 |
coding | Solve the programming task below in a Python markdown code block.
After a long journey, the super-space-time immigrant ship carrying you finally discovered a planet that seems to be habitable. The planet, named JOI, is a harsh planet with three types of terrain, "Jungle," "Ocean," and "Ice," as the name implies. A simp... | {"inputs": ["4 7\n4\nJIOJOIJ\nIOJOIJO\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7", "4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 5 4 7\n2 2 3 6\n2 2 2 2\n1 1 4 7", "4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 7 4 7\n2 2 3 6\n2 2 2 2\n1 1 1 7", "4 7\n4\nJIOJOIJ\nOJIOJOI\nJOIJOOI\nOOJJIJO\n5 7 4 7\n2 2 3 6\... | 654 | 699 |
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.
For positive integers $a$ and $b$, we say that a fraction $\frac{a}{b}$ is *good* if it is equal to $\frac{m}{m+1}$ for some positive integer $m$.
Y... | {"inputs": ["5"], "outputs": ["8"]} | 392 | 12 |
coding | Solve the programming task below in a Python markdown code block.
Theatre Square in the capital city of Berland has a rectangular shape with the size n Γ m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a Γ a.
Wha... | {"inputs": ["1 1 3\n", "2 1 2\n", "2 2 1\n", "2 3 4\n", "2 1 1\n", "1 1 1\n", "1 2 1\n", "1 1 2\n"], "outputs": ["1\n", "1\n", "4\n", "1\n", "2\n", "1\n", "2\n", "1\n"]} | 185 | 102 |
coding | Solve the programming task below in a Python markdown code block.
A sequence $(b_1, b_2, \ldots, b_k)$ is called strange, if the absolute difference between any pair of its elements is greater than or equal to the maximum element in the sequence. Formally speaking, it's strange if for every pair $(i, j)$ with $1 \le i<... | {"inputs": ["1\n1\n0\n", "1\n1\n0\n", "1\n1\n1\n", "1\n1\n2\n", "1\n2\n0 1\n", "1\n2\n0 1\n", "1\n3\n0 0 3\n", "1\n3\n0 0 4\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "2\n"]} | 701 | 114 |
coding | Solve the programming task below in a Python markdown code block.
Your task is to calculate the sum (indicated by S) of all the k-balanced integers between [L, R]. An integer is called k-balanced when either of #1 or #2 below holds true.
The length of the integer <= k
Sum of the first k digits (with no leading ze... | {"inputs": ["9 23 1\n"], "outputs": ["42\n"]} | 203 | 20 |
coding | Solve the programming task below in a Python markdown code block.
A pangram is a string that contains every letter of the alphabet. Given a sentence determine whether it is a pangram in the English alphabet. Ignore case. Return either pangram or not pangram as appropriate.
Example
$s=\text{'The quick brown fox ju... | {"inputs": ["We promptly judged antique ivory buckles for the prize", "We promptly judged antique ivory buckles for the next prize"], "outputs": ["not pangram", "pangram"]} | 299 | 41 |
coding | Solve the programming task below in a Python markdown code block.
Did you ever hear about 'crossing the bridge noodle' ? Let me tell you that it's not some kind of bridge made of noodles. It's a dish, a kind of rice noodle soup. Mr.Ping makes the best noodle soup and his son Po is eagerly waiting for the user reviews i... | {"inputs": ["2\nP 1\nP 2\n2\nP 2\nM -2\n0", "2\nP 1\nP 2\n\n2\nP 0\nM -2\n\n0", "2\nP 1\nP 4\n\n2\nP 0\nM -2\n\n0", "2\nQ 2\nP 4\n\n0\nP 0\nM -2\n\n0", "2\nP 1\nP 5\n\n2\nQ 0\nM -2\n\n0", "2\nQ 2\nP 6\n\n0\nP 0\nL -4\n\n2", "2\nQ 2\nP 5\n\n0\nP 1\nL -4\n\n2", "2\nQ 2\nP 8\n\n0\nP 1\nM -2\n\n1"], "outputs": ["1\n1", "1\... | 618 | 243 |
coding | Solve the programming task below in a Python markdown code block.
Dima got into number sequences. Now he's got sequence a_1, a_2, ..., a_{n}, consisting of n positive integers. Also, Dima has got a function f(x), which can be defined with the following recurrence: f(0) = 0; f(2Β·x) = f(x); f(2Β·x + 1) = f(x) + 1.
Di... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n6\n", "1\n7\n", "2\n1 1\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "1\n"]} | 342 | 87 |
coding | Solve the programming task below in a Python markdown code block.
Help Johnny!
He can't make his code work!
Easy Code
Johnny is trying to make a function that adds the sum of two encoded strings, but he can't find the error in his code! Help him!
Also feel free to reuse/extend the following starter code:
```python
def ... | {"functional": "_inputs = [['a', 'b']]\n_outputs = [[195]]\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(_... | 81 | 158 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi and Aoki will play a game using a grid with H rows and W columns of square cells. There are N obstacles on this grid; the i-th obstacle is at (X_i,Y_i). Here, we represent the cell at the i-th row and j-th column (1 \leq i \leq H, 1 \leq j \leq... | {"inputs": ["3 6 1\n3 2", "3 4 1\n3 2", "5 6 1\n3 2", "3 3 1\n3 2", "100001 100000 0", "100101 100000 0", "110101 100000 0", "110111 100000 0"], "outputs": ["2\n", "2\n", "2\n", "2", "100001\n", "100101\n", "110101\n", "110111\n"]} | 575 | 169 |
coding | Solve the programming task below in a Python markdown code block.
Chef has an array of N natural numbers most of them are repeated. Cheffina challenges chef to find all numbers(in ascending order) whose frequency is strictly more than K.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then th... | {"inputs": ["1\n5 1\n5 2 1 2 5"], "outputs": ["2 5"]} | 196 | 28 |
coding | Solve the programming task below in a Python markdown code block.
Given two strings, determine if they share a common substring. A substring may be as small as one character.
Example
$s1=\text{'and'}$
$s2=\text{'art'}$
These share the common substring $\class{ML__boldsymbol}{\boldsymbol{a}}$.
$\textbf{s1}... | {"inputs": ["2\nhello\nworld\nhi\nworld\n"], "outputs": ["YES\nNO\n"]} | 401 | 24 |
coding | Solve the programming task below in a Python markdown code block.
Twilight Sparkle once got a crystal from the Crystal Mine. A crystal of size n (n is odd; n > 1) is an n Γ n matrix with a diamond inscribed into it.
You are given an odd integer n. You need to draw a crystal of size n. The diamond cells of the matrix s... | {"inputs": ["3\n", "5\n", "7\n", "9\n", "5\n", "7\n", "3\n", "11\n"], "outputs": ["*D*\nDDD\n*D*\n", "**D**\n*DDD*\nDDDDD\n*DDD*\n**D**\n", "***D***\n**DDD**\n*DDDDD*\nDDDDDDD\n*DDDDD*\n**DDD**\n***D***\n", "****D****\n***DDD***\n**DDDDD**\n*DDDDDDD*\nDDDDDDDDD\n*DDDDDDD*\n**DDDDD**\n***DDD***\n****D****\n", "**D**\n*D... | 213 | 293 |
coding | Solve the programming task below in a Python markdown code block.
Little Chief loves math. Most of all, he loves equations. He can solve any equation in the whole world. Recently he found one interesting and easy equation
x1^{d}+x2^{d}+x3^{d} β‘ m (mod N)
Where x1, x2 and x3 are non negative integer numbers.
But, as ... | {"inputs": ["2\n2 2 3 5\n1 2013 3 31", "2\n2 2 3 5\n1 2013 3 31"], "outputs": ["4\n1\n", "4\n1"]} | 451 | 63 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants to buy a new laptop. However, he is confused about which laptop to buy out of 10 different laptops. He asks his N friends for their recommendation. The i^{th} friend recommends the Chef to buy the {A_{i}}^{th} laptop (1 β€ A_{i} β€ 10).
Chef w... | {"inputs": ["4\n5\n4 4 4 2 1\n7\n1 2 3 4 5 6 6\n6\n2 2 3 3 10 8\n4\n7 7 8 8\n"], "outputs": ["4\n6\nCONFUSED\nCONFUSED\n"]} | 515 | 75 |
coding | Solve the programming task below in a Python markdown code block.
Ahmed Gafer failed to pass the test, but he got the job because of his friendship with Said and Shahhoud. After working in the kitchen for a while, he blew it. The customers didn't like the food anymore and one day he even burned the kitchen. Now the mas... | {"inputs": ["2\na\nabba"], "outputs": ["0\n2"]} | 461 | 19 |
coding | Solve the programming task below in a Python markdown code block.
In this kata you will be given an **integer n**, which is the number of times that is thown a coin. You will have to return an array of string for all the possibilities (heads[H] and tails[T]). Examples:
```coin(1) should return {"H", "T"}```
```coin(2) ... | {"functional": "_inputs = [[1], [2], [3]]\n_outputs = [[['H', 'T']], [['HH', 'HT', 'TH', 'TT']], [['HHH', 'HHT', 'HTH', 'HTT', 'THH', 'THT', 'TTH', 'TTT']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n ... | 275 | 209 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given three integers n, m and k. Consider the following algorithm to find the maximum element of an array of positive integers:
You should build the array arr which has the following properties:
arr has exac... | {"functional": "def check(candidate):\n assert candidate(n = 2, m = 3, k = 1) == 6\n assert candidate(n = 5, m = 2, k = 3) == 0\n assert candidate(n = 9, m = 1, k = 1) == 1\n\n\ncheck(Solution().numOfArrays)"} | 168 | 86 |
coding | Solve the programming task below in a Python markdown code block.
For a given weighted graph G(V, E) and a source r, find the source shortest path to each vertex from the source (SSSP: Single Source Shortest Path).
Constraints
* 1 β€ |V| β€ 100000
* 0 β€ di β€ 10000
* 0 β€ |E| β€ 500000
* There are no parallel edges
* Ther... | {"inputs": ["4 5 0\n0 1 1\n0 2 4\n1 2 2\n2 3 1\n1 3 2", "4 5 0\n0 1 1\n0 2 4\n1 2 0\n2 3 1\n1 3 5", "4 5 0\n0 1 1\n1 2 4\n1 1 0\n2 3 1\n1 3 2", "4 5 0\n0 1 1\n1 2 4\n1 1 0\n2 3 1\n0 3 2", "4 5 0\n0 1 1\n1 2 5\n1 1 0\n2 3 1\n0 3 2", "4 5 0\n0 2 1\n0 3 4\n1 2 2\n2 2 2\n1 3 2", "4 5 0\n0 2 2\n0 3 4\n1 3 2\n3 2 2\n1 3 2", ... | 426 | 382 |
coding | Solve the programming task below in a Python markdown code block.
An array A of length N is said to be *pseudo-sorted* if it can be made non-decreasing after performing the following operation at most once.
Choose an i such that 1 β€ i β€ N-1 and swap A_{i} and A_{i+1}
Given an array A, determine if it is *pseudo-sorted... | {"inputs": ["3\n5\n3 5 7 8 9\n4\n1 3 2 3\n3\n3 2 1\n"], "outputs": ["YES\nYES\nNO\n"]} | 442 | 48 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given the root of a binary tree and a positive integer k.
The level sum in the tree is the sum of the values of the nodes that are on the same level.
Return the kth largest level sum in the tree (not necessari... | {"functional": "def check(candidate):\n assert candidate(root = tree_node([5,8,9,2,1,3,7,4,6]), k = 2) == 13\n assert candidate(root = tree_node([1,2,None,3]), k = 1) == 3\n\n\ncheck(Solution().kthLargestLevelSum)"} | 194 | 83 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Given a string `str`, reverse it omitting all non-alphabetic characters.
# Example
For `str = "krishan"`, the output should be `"nahsirk"`.
For `str = "ultr53o?n"`, the output should be `"nortlu"`.
# Input/Output
- `[input]` string `st... | {"functional": "_inputs = [['krishan'], ['ultr53o?n'], ['ab23c'], ['krish21an']]\n_outputs = [['nahsirk'], ['nortlu'], ['cba'], ['nahsirk']]\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... | 139 | 193 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string S of length N consisting of lowercase English letters.
Process Q queries of the following two types:
- Type 1: change the i_q-th character of S to c_q. (Do nothing if the i_q-th character is already c_q.)
- Type 2: answer the num... | {"inputs": ["7\nabcdbbd\n6\n2 3 6\n1 5 y\n2 1 1\n1 4 a\n1 7 d\n2 1 7", "7\nabccbbd\n6\n2 3 6\n1 5 y\n2 1 1\n1 4 a\n1 7 d\n2 0 7", "7\nabdcbbd\n6\n2 3 6\n1 5 z\n2 1 1\n1 4 a\n1 7 d\n2 0 7", "7\nabcdbbd\n6\n2 3 0\n1 5 z\n2 1 1\n1 4 a\n1 7 d\n2 1 7", "7\nabccbbd\n6\n2 3 5\n1 5 z\n2 1 1\n1 5 a\n1 7 d\n2 0 7", "7\nabcdbbd\n... | 489 | 409 |
coding | Solve the programming task below in a Python markdown code block.
Petya has got an interesting flower. Petya is a busy person, so he sometimes forgets to water it. You are given n days from Petya's live and you have to determine what happened with his flower in the end.
The flower grows as follows:
* If the flower... | {"inputs": ["1\n7\n1 0 1 1 0 0 1 0 0 0\n", "1\n7\n0 0 1 1 0 0 1 0 0 0\n", "1\n7\n0 0 2 1 0 0 1 0 0 0\n", "1\n3\n0 0 2 1 0 0 1 0 0 0\n", "1\n3\n0 0 2 1 0 0 2 0 0 0\n", "1\n7\n0 0 1 1 0 0 1 1 0 0\n", "1\n7\n0 0 2 1 1 0 1 0 0 0\n", "1\n3\n0 0 2 1 1 0 1 0 0 0\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n",... | 395 | 247 |
coding | Solve the programming task below in a Python markdown code block.
You have N cups and 1 ball.
The cups are arranged in a row, from left to right.
You turned down all the cups, then inserted the ball into the leftmost cup.
Then, you will perform the following Q operations:
* The i-th operation: swap the positions of... | {"inputs": ["10 3\n1 3\n2 8\n4 5", "10 3\n1 3\n2 8\n4 2", "14 1\n1 3\n2 8\n5 5", "14 3\n2 1\n2 8\n5 7", "10 3\n1 3\n2 8\n5 5", "10 3\n1 3\n2 8\n4 1", "14 3\n1 3\n2 8\n5 5", "14 1\n1 3\n4 8\n5 5"], "outputs": ["5\n", "4\n", "3\n", "6\n", "4\n", "5\n", "4\n", "3\n"]} | 371 | 182 |
coding | Solve the programming task below in a Python markdown code block.
Ashish has a string $s$ of length $n$ containing only characters 'a', 'b' and 'c'.
He wants to find the length of the smallest substring, which satisfies the following conditions:
Length of the substring is at least $2$
'a' occurs strictly more times ... | {"inputs": ["3\n2\naa\n5\ncbabb\n8\ncacabccc\n"], "outputs": ["2\n-1\n3\n"]} | 509 | 36 |
coding | Solve the programming task below in a Python markdown code block.
Move the first letter of each word to the end of it, then add "ay" to the end of the word. Leave punctuation marks untouched.
## Examples
```python
pig_it('Pig latin is cool') # igPay atinlay siay oolcay
pig_it('Hello world !') # elloHay orldway !
... | {"functional": "_inputs = [['Pig latin is cool'], ['This is my string']]\n_outputs = [['igPay atinlay siay oolcay'], ['hisTay siay ymay tringsay']]\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 isins... | 202 | 187 |
coding | Solve the programming task below in a Python markdown code block.
There are n integers b_1, b_2, ..., b_{n} written in a row. For all i from 1 to n, values a_{i} are defined by the crows performing the following procedure:
The crow sets a_{i} initially 0. The crow then adds b_{i} to a_{i}, subtracts b_{i} + 1, adds... | {"inputs": ["5\n7 -8 8 0 2\n", "5\n2 0 0 1 12\n", "5\n7 -8 6 0 2\n", "5\n3 0 0 1 12\n", "5\n3 0 0 1 10\n", "5\n3 0 1 1 10\n", "5\n4 0 1 1 10\n", "5\n6 -4 8 -2 3\n"], "outputs": ["-1 0 8 2 2\n", "2 0 1 13 12\n", "-1 -2 6 2 2\n", "3 0 1 13 12\n", "3 0 1 11 10\n", "3 1 2 11 10\n", "4 1 2 11 10\n", "2 4 6 1 3 \n"]} | 550 | 231 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of integers nums. You are also given an integer original which is the first number that needs to be searched for in nums.
You then do the following steps:
If original is found in nums, multiply... | {"functional": "def check(candidate):\n assert candidate(nums = [5,3,6,1,12], original = 3) == 24\n assert candidate(nums = [2,7,9], original = 4) == 4\n\n\ncheck(Solution().findFinalValue)"} | 142 | 68 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a 0-indexed integer array nums, return the number of distinct quadruplets (a, b, c, d) such that:
nums[a] + nums[b] + nums[c] == nums[d], and
a < b < c < d
Β
Please complete the following python code precisely... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,6]) == 1\n assert candidate(nums = [3,3,6,4,5]) == 0\n assert candidate(nums = [1,1,1,3,5]) == 4\n\n\ncheck(Solution().countQuadruplets)"} | 106 | 80 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A perfectly straight street is represented by a number line. The street has street lamp(s) on it and is represented by a 2D integer array lights. Each lights[i] = [positioni, rangei] indicates that there is a street l... | {"functional": "def check(candidate):\n assert candidate(lights = [[-3,2],[1,2],[3,3]]) == -1\n assert candidate(lights = [[1,0],[0,1]]) == 1\n assert candidate(lights = [[1,2]]) == -1\n\n\ncheck(Solution().brightestPosition)"} | 170 | 78 |
coding | Solve the programming task below in a Python markdown code block.
The Bitlandians are quite weird people. They have very peculiar customs.
As is customary, Uncle J. wants to have n eggs painted for Bitruz (an ancient Bitland festival). He has asked G. and A. to do the work.
The kids are excited because just as is cus... | {"inputs": ["1\n1 23\n", "1\n0 23\n", "1\n0 28\n", "1\n0 48\n", "1\n0 19\n", "1\n1 999\n", "1\n1 999\n", "1\n1 397\n"], "outputs": ["A\n", "A\n", "A\n", "A\n", "A\n", "A\n", "A\n", "A\n"]} | 545 | 113 |
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\n23\n1\n23\n456\n1\n23\n4 5\n6789\n1\n23\n4 5\n6 7\n89101112"]} | 229 | 73 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an m x n integer grid accounts where accounts[i][j] is the amount of money the iβββββββββββthββββ customer has in the jβββββββββββthββββ bank. Return the wealth that the richest customer has.
A customer'... | {"functional": "def check(candidate):\n assert candidate(accounts = [[1,2,3],[3,2,1]]) == 6\n assert candidate(accounts = [[1,5],[7,3],[3,5]]) == 10\n assert candidate(accounts = [[2,8,7],[7,1,3],[1,9,5]]) == 17\n\n\ncheck(Solution().maximumWealth)"} | 136 | 94 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings word1 and word2. Merge the strings by adding letters in alternating order, starting with word1. If a string is longer than the other, append the additional letters onto the end of the merged ... | {"functional": "def check(candidate):\n assert candidate(word1 = \"abc\", word2 = \"pqr\") == \"apbqcr\"\n assert candidate(word1 = \"ab\", word2 = \"pqrs\") == \"apbqrs\"\n assert candidate(word1 = \"abcd\", word2 = \"pq\") == \"apbqcd\"\n\n\ncheck(Solution().mergeAlternately)"} | 106 | 91 |
coding | Solve the programming task below in a Python markdown code block.
The blinds are known to consist of opaque horizontal stripes that can be rotated thus regulating the amount of light flowing in the room. There are n blind stripes with the width of 1 in the factory warehouse for blind production. The problem is that all... | {"inputs": ["2 2\n3 3\n", "2 2\n3 2\n", "2 3\n1 2\n", "4 2\n1 1 3 4\n", "4 2\n1 2 3 4\n", "5 2\n2 4 1 1 3\n", "5 2\n2 4 1 1 1\n", "5 3\n5 5 7 5 1\n"], "outputs": ["6\n", "4\n", "0\n", "6\n", "8\n", "8\n", "6\n", "20\n"]} | 583 | 145 |
coding | Solve the programming task below in a Python markdown code block.
Christy is interning at HackerRank. One day she has to distribute some chocolates to her colleagues. She is biased towards her friends and plans to give them more than the others. One of the program managers hears of this and tells her to make sure every... | {"inputs": ["1\n4\n2 2 3 7\n", "1\n3\n10 7 12\n"], "outputs": ["2\n", "3\n"]} | 687 | 42 |
coding | Solve the programming task below in a Python markdown code block.
Once upon a time, there was a hero and an old saint. And like in any story with a hero and an old saint, the old saint asked the hero β three questions!
But here's the twist: each question was a binary question, which means that the answer to each must... | {"inputs": ["2\n1 0 1\n1 1 0\n0 0 0\n1 1 1"], "outputs": ["Pass\nFail"]} | 631 | 38 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0.
Notice that the solution set must not contain duplicate trip... | {"functional": "def check(candidate):\n assert candidate(nums = [-1,0,1,2,-1,-4]) == [[-1,-1,2],[-1,0,1]]\n assert candidate(nums = [0,1,1]) == []\n assert candidate(nums = [0,0,0]) == [[0,0,0]]\n\n\ncheck(Solution().threeSum)"} | 114 | 92 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.