problem stringlengths 14 4.09k | solution stringlengths 1 802k | task_type stringclasses 3
values | problem_tokens int64 5 895 |
|---|---|---|---|
Solve the programming task below in a Python markdown code block.
Today is Chef's birthday. His mom decided to surprise him with a truly fantastic gift: his favourite binary string B. But, unfortunately, all the stocks of binary string B have been sold out, and only a binary string A (A ≠ B) is available in the market.... | {"inputs": ["2\n101\n010\n1111\n1010", "2\n101\n011\n1111\n1010", "2\n001\n111\n1111\n1010", "2\n111\n110\n1111\n1010", "2\n110\n110\n1111\n1010", "2\n110\n110\n1011\n1010", "2\n010\n110\n0011\n1010", "2\n000\n110\n0011\n1010"], "outputs": ["Lucky Chef\n2\nUnlucky Chef", "Lucky Chef\n1\nUnlucky Chef\n", "Lucky Chef\n2\... | coding | 693 |
Solve the programming task below in a Python markdown code block.
# Task
You are given three integers `l, d and x`. Your task is:
```
• determine the minimal integer n
such that l ≤ n ≤ d, and the sum of its digits equals x.
• determine the maximal integer m
such that l ≤ m ≤ d, and the sum of its digits equ... | {"functional": "_inputs = [[100, 200, 10], [123, 456, 5], [99, 501, 5], [99, 234, 1], [99, 234, 19], [99, 5001, 27], [99, 5001, 28], [2000, 7000, 3]]\n_outputs = [[[109, 190]], [[131, 410]], [[104, 500]], [[100, 100]], [[199, 199]], [[999, 4995]], [[1999, 4996]], [[2001, 3000]]]\nimport math\ndef _deep_eq(a, b, tol=1e-... | coding | 290 |
Solve the programming task below in a Python markdown code block.
You are given two integers, $N$ and $\mbox{M}$. Count the number of strings of length $N$ (under the alphabet set of size $\mbox{M}$) that doesn't contain any palindromic string of the length greater than $\mbox{1}$ as a consecutive substring.
Input For... | {"inputs": ["2\n2 2\n2 3\n"], "outputs": ["2\n6\n"]} | coding | 463 |
Solve the programming task below in a Python markdown code block.
Priya loves bitwise AND, but she hates programming. Help her solve this problem.
Given an array $A$ of size $N$, let $B_{ij}$ denote the [bitwise AND] of $A[i]$ and $A[j]$. You have to find the number of pairs $(i, j)$, such that $i < j$ and $B_{ij} = ... | {"inputs": ["2\n5\n1 1 1 1 1\n1\n10"], "outputs": ["10\n0"]} | coding | 369 |
Solve the programming task below in a Python markdown code block.
You are given a string $s$. You need to find two non-empty strings $a$ and $b$ such that the following conditions are satisfied:
Strings $a$ and $b$ are both subsequences of $s$.
For each index $i$, character $s_i$ of string $s$ must belong to exactly ... | {"inputs": ["3\nfc\naaaa\nthebrightboiler\n", "5\nkbxiahaosfyclumgnaczggrnljumplxknibxmeedvnefh\ndkqosshpegwunnzsohmxxumnnhckwyczaowpoxezqlovukcuuqgrsbrtifngthlquuqdjvyltgjbrmwoefypvdyzqwlainjoqx\nwktnblvszfndrjodikurlytsayblhpdnrytxnhfejtjfzeeamtt\ngkffwelozvmyosbmoufjpjzbeohbulotcinspqmyurolxwlwloobkszpnddxhrkbxoytmd... | coding | 559 |
Solve the programming task below in a Python markdown code block.
Jack and Jill got into a serious fight. Jack didn't not belive Jill when she said that her memory was far better than the others. He asked her to prove it as follows :-
- Jack would dictate a long list of numbers to her. At any point after he has dict... | {"inputs": ["6\n2\n3\n2\n-1\n-1\n1\n-1", "10\n5\n3\n6\n1\n4\n2\n9\n3\n1\n0\n-1"], "outputs": ["3\n3\n2", "3"]} | coding | 460 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s consisting of only the characters 'a' and 'b', return true if every 'a' appears before every 'b' in the string. Otherwise, return false.
Please complete the following python code precisely:
```pytho... | {"functional": "def check(candidate):\n assert candidate(s = \"aaabbb\") == True\n assert candidate(s = \"abab\") == False\n assert candidate(s = \"bbb\") == True\n\n\ncheck(Solution().checkString)"} | coding | 85 |
Solve the programming task below in a Python markdown code block.
From "ftying rats" to urban saniwation workers - can synthetic biology tronsform how we think of pigeons?
The upiquitous pigeon has long been viewed as vermin - spleading disease, scavenging through trush, and defecating in populous urban spases. Yet t... | {"inputs": ["5\n1 2 3 4 5\n", "5\n1 2 3 7 5\n", "5\n1 2 3 4 5\n", "5\n0 2 3 14 5\n", "5\n1 2 3 14 5\n", "5\n27 30 8 6 3\n", "5\n27 60 8 6 3\n", "5\n27 30 8 32 3\n"], "outputs": ["4\n", "4\n", "4\n", "5\n", "4\n", "13\n", "13\n", "13\n"]} | coding | 352 |
Solve the programming task below in a Python markdown code block.
Bleatrix Trotter the sheep has devised a strategy that helps her fall asleep faster. First, she picks a number N. Then she starts naming N, 2 × N, 3 × N, and so on.
Whenever she names a number, she thinks about all of the digits in that number. She keeps... | {"functional": "_inputs = [[1692], [2], [7], [100], [1], [11], [163444], [206929], [459923], [691520], [0], [12500], [1250000]]\n_outputs = [[5076], [90], [70], [900], [10], [110], [653776], [620787], [4139307], [2074560], ['INSOMNIA'], [900000], [90000000]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstanc... | coding | 383 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You may recall that an array arr is a mountain array if and only if:
arr.length >= 3
There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:
arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
arr[i] >... | {"functional": "def check(candidate):\n assert candidate(arr = [2,1,4,7,3,2,5]) == 5\n assert candidate(arr = [2,2,2]) == 0\n\n\ncheck(Solution().longestMountain)"} | coding | 168 |
Solve the programming task below in a Python markdown code block.
This is a simplified version of the problem B2. Perhaps you should read the problem B2 before you start solving B1.
Paul and Mary have a favorite string $s$ which consists of lowercase letters of the Latin alphabet. They want to paint it using pieces of... | {"inputs": ["1\naa\n", "1\naa\n", "1\nab\n", "1\ndscnjksdcnsjkvndfjkvndfjkvnkdfnv\n", "1\ndscnjksdcnsjkvndfjkvndfjkvnkdfnv\n", "1\ndscnjksdcnsjkvndfjkvndfjkvnkdfnu\n", "1\ndscnjksdcnsjkvndfjkvnefjkvnkdfnu\n", "1\ndscnjksdcnsjjvndfjkvoefjkwnkdfnu\n"], "outputs": ["1\n", "1\n", "1\n", "8\n", "8\n", "8\n", "9\n", "10\n"]} | coding | 657 |
Solve the programming task below in a Python markdown code block.
Given an array $\boldsymbol{A\left[\right]}$ of $N$ distinct elements. Let $M_1$ and $M_2$ be the smallest and the next smallest element in the interval $[L,R]$ where $1\leq L<R\leq N$.
$S_i=(((M_1\wedge M_2)\oplus(M_1\vee M_2))\wedge(M_1\oplus M_2))$... | {"inputs": ["5\n9 6 3 5 2\n"], "outputs": ["15\n"]} | coding | 323 |
Solve the programming task below in a Python markdown code block.
You are both a shop keeper and a shop assistant at a small nearby shop. You have $n$ goods, the $i$-th good costs $a_i$ coins.
You got tired of remembering the price of each product when customers ask for it, thus you decided to simplify your life. More... | {"inputs": ["1\n2\n75 2\n", "1\n2\n65 0\n", "1\n2\n777 1\n", "1\n2\n777 1\n", "1\n2\n386 1\n", "1\n2\n665 1\n", "1\n2\n449 1\n", "1\n2\n327 1\n"], "outputs": ["39\n", "33\n", "389\n", "389\n", "194\n", "333\n", "225\n", "164\n"]} | coding | 490 |
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 containing unique integer values and an integer array nums that is a subset of the linked list values.
Return the number of connected components in nums where two values are con... | {"functional": "def check(candidate):\n assert candidate(head = list_node([0,1,2,3]), nums = [0,1,3]) == 2\n assert candidate(head = list_node([0,1,2,3,4]), nums = [0,3,1,4]) == 2\n\n\ncheck(Solution().numComponents)"} | coding | 146 |
Solve the programming task below in a Python markdown code block.
Let's start from some definitions.
Strings A and B are called anagrams if it's possible to rearrange the letters of string A using all the original letters exactly once and achieve string B; in other words A and B are permutations of each other. For exa... | {"inputs": ["2\nwall\nstep", "2\nllaw\nstep", "2\namlu\nutfq", "2\nwmck\nmhqt", "2\nllwa\nstep", "2\nllwa\nstfp", "2\nmlwa\nstfp", "2\nawlm\nstfp"], "outputs": ["no such string", "no such string\n", "u\n", "m\n", "no such string\n", "no such string\n", "no such string\n", "no such string\n"]} | coding | 632 |
Solve the programming task below in a Python markdown code block.
Lets define G(x, {A_{1}, A_{2}, A_{3}, ..., A_{x}}) as a game played by 2 players in which we have x piles of stones with ith pile having A_{i} stones. Player 1 moves first. The players move alternatively. In a move a player can select a single non empty... | {"inputs": ["6\n1 1 2 3 3 2"], "outputs": ["1"]} | coding | 642 |
Solve the programming task below in a Python markdown code block.
Chef and his girlfriend are going to have a promenade. They are walking along the straight road which consists of segments placed one by one. Before walking Chef and his girlfriend stay at the beginning of the first segment, they want to achieve the end ... | {"inputs": ["2\n5\n6 5 4 3 2\n5\n3 4 3 1 1", "2\n5\n6 5 4 3 2\n5\n3 4 6 1 1", "2\n5\n6 5 4 3 2\n5\n3 7 9 1 1", "2\n5\n6 5 4 3 3\n5\n3 7 9 1 1", "2\n5\n6 5 4 3 2\n5\n3 8 3 1 1", "2\n5\n6 5 4 5 2\n5\n3 7 6 1 1", "2\n5\n6 5 4 4 2\n5\n3 8 3 1 1", "2\n5\n6 5 0 3 2\n5\n3 4 3 1 1"], "outputs": ["6\n5", "6\n8\n", "6\n11\n", "7... | coding | 495 |
Solve the programming task below in a Python markdown code block.
Given a word consisting of lowercase English letters, write a program to remove duplicates from the word. The characters in the output must preserve the same order, as their first appearance in the original word.
Input Format
The input consists of seve... | {"inputs": ["5\nbananasqr\naaaaa\nabcde\nayacazkeafagahbcbdbebfbg\nqweer\n"], "outputs": ["bansqr\na\nabcde\nayczkefghbd\nqwer\n"]} | coding | 168 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings s and t, return true if s is a subsequence of t, or false otherwise.
A subsequence of a string is a new string that is formed from the original string by deleting some (can be none) of the characters... | {"functional": "def check(candidate):\n assert candidate(s = \"abc\", t = \"ahbgdc\") == True\n assert candidate(s = \"axc\", t = \"ahbgdc\") == False\n\n\ncheck(Solution().isSubsequence)"} | coding | 135 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
An integer array original is transformed into a doubled array changed by appending twice the value of every element in original, and then randomly shuffling the resulting array.
Given an array changed, return original... | {"functional": "def check(candidate):\n assert candidate(changed = [1,3,4,2,6,8]) == [1,3,4]\n assert candidate(changed = [6,3,0,1]) == []\n assert candidate(changed = [1]) == []\n\n\ncheck(Solution().findOriginalArray)"} | coding | 119 |
Solve the programming task below in a Python markdown code block.
Snuke is going to open a contest named "AtCoder s Contest".
Here, s is a string of length 1 or greater, where the first character is an uppercase English letter, and the second and subsequent characters are lowercase English letters.
Snuke has decided to... | {"inputs": ["AtCoder X Contert", "AtCoder W Contert", "AtCoder V Contert", "AtCocer Y Cpnteqt", "AtCoder X Contest", "AtCoder X Contest\n", "AtCoder nSuke Contest", "AtCoder Sunke Contest"], "outputs": ["AXC\n", "AWC\n", "AVC\n", "AYC\n", "AXC", "AXC\n", "AnC\n", "ASC\n"]} | coding | 211 |
Solve the programming task below in a Python markdown code block.
Tokitsukaze and CSL are playing a little game of stones.
In the beginning, there are n piles of stones, the i-th pile of which has a_i stones. The two players take turns making moves. Tokitsukaze moves first. On each turn the player chooses a nonempty p... | {"inputs": ["1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n4\n", "1\n6\n", "1\n9\n", "1\n0\n"], "outputs": ["sjfnb\n", "cslnb\n", "sjfnb\n", "sjfnb\n", "cslnb\n", "cslnb\n", "sjfnb\n", "cslnb\n"]} | coding | 702 |
Solve the programming task below in a Python markdown code block.
Vasya is studying in the last class of school and soon he will take exams. He decided to study polynomials. Polynomial is a function P(x) = a_0 + a_1x^1 + ... + a_{n}x^{n}. Numbers a_{i} are called coefficients of a polynomial, non-negative integer n is ... | {"inputs": ["2 2 2\n", "2 3 3\n", "1 1 1\n", "7 8 9\n", "3 3 3\n", "1 5 5\n", "1 2 2\n", "1 2 5\n"], "outputs": ["2\n", "1\n", "inf\n", "1\n", "2\n", "1\n", "1\n", "1\n"]} | coding | 286 |
Solve the programming task below in a Python markdown code block.
Mark loves eating chocolates and also likes to be fit. Given the calorie count for every chocolate he eats, find what he has to do to burn the calories.
The name of the chocolates along with its calorie count are given as follows:
Calories per one whole... | {"inputs": ["DDTM"], "outputs": ["17\n1\n6"]} | coding | 361 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer number n, return the difference between the product of its digits and the sum of its digits.
Please complete the following python code precisely:
```python
class Solution:
def subtractProductAnd... | {"functional": "def check(candidate):\n assert candidate(n = 234) == 15 \n assert candidate(n = 4421) == 21\n\n\ncheck(Solution().subtractProductAndSum)"} | coding | 71 |
Solve the programming task below in a Python markdown code block.
Read problems statements in [Russian] and [Bengali].
Chef opened a company which manufactures cars and bikes. Each car requires 4 tyres while each bike requires 2 tyres. Chef has a total of N tyres (N is even). He wants to manufacture maximum number of ... | {"inputs": ["3\n8\n2\n6\n"], "outputs": ["NO\nYES\nYES"]} | coding | 387 |
Solve the programming task below in a Python markdown code block.
Even if it's a really easy question, she won't be able to answer it
— Perfect Memento in Strict Sense
Cirno's perfect bitmasks classroom has just started!
Cirno gave her students a positive integer $x$. As an assignment, her students need to find the ... | {"inputs": ["1\n1073741824\n", "7\n1\n2\n5\n9\n16\n114514\n1000000\n"], "outputs": ["1073741825\n", "3\n3\n1\n1\n17\n2\n64\n"]} | coding | 369 |
Solve the programming task below in a Python markdown code block.
In this kata we want to convert a string into an integer. The strings simply represent the numbers in words.
Examples:
* "one" => 1
* "twenty" => 20
* "two hundred forty-six" => 246
* "seven hundred eighty-three thousand nine hundred and nineteen" => 7... | {"functional": "_inputs = [['zero'], ['one'], ['two'], ['three'], ['four'], ['five'], ['six'], ['seven'], ['eight'], ['nine'], ['ten'], ['twenty'], ['twenty-one'], ['thirty-seven'], ['forty-six'], ['fifty-nine'], ['sixty-eight'], ['seventy-two'], ['eighty-three'], ['ninety-four'], ['one hundred'], ['one hundred one'], ... | coding | 190 |
Solve the programming task below in a Python markdown code block.
Chef has two integers A and B.
Chef wants to find the minimum value of \texttt{lcm}(A, X) - \texttt{gcd}(B, X) where X is any positive integer.
Help him determine this value.
Note: \texttt{gcd}(P, Q) denotes the [greatest common divisor] of P and Q a... | {"inputs": ["3\n12 15\n5 50\n9 11\n"], "outputs": ["9\n0\n8\n"]} | coding | 439 |
Solve the programming task below in a Python markdown code block.
We will call a non-negative integer increasing if, for any two adjacent digits in its decimal representation, the digit to the right is greater than or equal to the digit to the left. For example, 1558, 11, 3 and 0 are all increasing; 10 and 20170312 are... | {"inputs": ["4", "5", "2", "3", "6", "1", "73", "22"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]} | coding | 286 |
Solve the programming task below in a Python markdown code block.
# Task
Consider a `bishop`, a `knight` and a `rook` on an `n × m` chessboard. They are said to form a `triangle` if each piece attacks exactly one other piece and is attacked by exactly one piece.
Calculate the number of ways to choose positions of ... | {"functional": "_inputs = [[2, 3], [1, 30], [3, 3], [2, 2], [5, 2], [40, 40]]\n_outputs = [[8], [0], [48], [0], [40], [92400]]\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... | coding | 325 |
Solve the programming task below in a Python markdown code block.
As a part of this Kata, you need to create a function that when provided with a triplet, returns the index of the numerical element that lies between the other two elements.
The input to the function will be an array of three distinct numbers (Haskell: ... | {"functional": "_inputs = [[[2, 3, 1]], [[5, 10, 14]], [[1, 3, 4]], [[15, 10, 14]], [[-0.41, -23, 4]], [[-15, -10, 14]]]\n_outputs = [[0], [1], [1], [2], [0], [1]]\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=to... | coding | 205 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array queries and a positive integer intLength, return an array answer where answer[i] is either the queries[i]th smallest positive palindrome of length intLength or -1 if no such palindrome exists.
A... | {"functional": "def check(candidate):\n assert candidate(queries = [1,2,3,4,5,90], intLength = 3) == [101,111,121,131,141,999]\n assert candidate(queries = [2,4,6], intLength = 4) == [1111,1331,1551]\n\n\ncheck(Solution().kthPalindrome)"} | coding | 120 |
Solve the programming task below in a Python markdown code block.
Given a string, swap the case for each of the letters.
e.g. CodEwArs --> cODeWaRS
### Examples
```
"" -> ""
"CodeWars" -> "cODEwARS"
"abc" -> "ABC"
"ABC" -> "abc"
"123235" -> "123235"
```
Also feel free to reuse... | {"functional": "_inputs = [['HelloWorld'], ['CodeWars'], ['ThIs iS A l0NG sENTence witH nUMbERs in IT 123 456'], [''], [' '], [' '], [' 1a1 '], ['H_E_l-l_0 WO|||Rld'], ['TeSt'], ['EeEEeeEEEeee']]\n_outputs = [['hELLOwORLD'], ['cODEwARS'], ['tHiS Is a L0ng SentENCE WITh NumBerS IN it 123 456'], [''], [' '], [' '], [' ... | coding | 123 |
Solve the programming task below in a Python markdown code block.
A new strain of flu has broken out. Fortunately, a vaccine was developed very quickly and is now being administered to the public. Your local health clinic is administering this vaccine, but the waiting line is very long.
For safety reasons, people are ... | {"inputs": ["3\n2 4\n1\n2\n2 2\n1\n2\n4 1\n0\n0.5\n0.6\n2.75"], "outputs": ["2.0000\n0.5000\n1.4000"]} | coding | 769 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an n x n binary matrix grid where 1 represents land and 0 represents water.
An island is a 4-directionally connected group of 1's not connected to any other 1's. There are exactly two islands in grid.
Yo... | {"functional": "def check(candidate):\n assert candidate(grid = [[0,1],[1,0]]) == 1\n assert candidate(grid = [[0,1,0],[0,0,0],[0,0,1]]) == 2\n assert candidate(grid = [[1,1,1,1,1],[1,0,0,0,1],[1,0,1,0,1],[1,0,0,0,1],[1,1,1,1,1]]) == 1\n\n\ncheck(Solution().shortestBridge)"} | coding | 138 |
Solve the programming task below in a Python markdown code block.
Sereja has a string A consisting of n lower case English letters.
Sereja calls two strings X and Y each of length n similar if they can be made equal by applying the following operation at most once in each of them.
- Chose any two position i, j in th... | {"inputs": ["2\nz\nabcd\n\n"], "outputs": ["0\n144"]} | coding | 504 |
Solve the programming task below in a Python markdown code block.
Doremy is asked to test $n$ contests. Contest $i$ can only be tested on day $i$. The difficulty of contest $i$ is $a_i$. Initially, Doremy's IQ is $q$. On day $i$ Doremy will choose whether to test contest $i$ or not. She can only test a contest if her c... | {"inputs": ["5\n1 1\n1\n2 1\n1 2\n3 1\n1 2 1\n4 2\n1 4 3 1\n5 2\n5 1 2 4 3\n", "2\n10 999999999\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\n5 1000000000\n1000000000 1 2 3 4\n"], "outputs": ["1\n11\n101\n1011\n01111\n", "1111111111\n11111\n"]} | coding | 609 |
Solve the programming task below in a Python markdown code block.
Take debugging to a whole new level:
Given a string, remove every *single* bug.
This means you must remove all instances of the word 'bug' from within a given string, *unless* the word is plural ('bugs').
For example, given 'obugobugobuoobugsoo', you ... | {"functional": "_inputs = [['obugobugobuoobugsoo'], ['obbugugo'], ['bugs bunny'], ['bugs buggy'], ['oaiwjefbugoijoijapsbugsdoibugbugjfoijasdfbugsbug'], ['bugbugbugiahweoifuhiaasnoidfhnbugbugs'], ['bugsbugswaoeifhiauwehfoiwubugshefjnviouah'], ['bugbugbugbug'], ['bugsbugsbugsbugs'], ['buggybugs'], ['oaisjdfowjefpoibugsjs... | coding | 138 |
Solve the programming task below in a Python markdown code block.
Iahub is so happy about inventing bubble sort graphs that he's staying all day long at the office and writing permutations. Iahubina is angry that she is no more important for Iahub. When Iahub goes away, Iahubina comes to his office and sabotage his res... | {"inputs": ["2\n-1 1\n", "2\n-1 -1\n", "5\n-1 -1 4 1 -1\n", "5\n-1 -1 4 2 -1\n", "5\n-1 -1 5 3 -1\n", "5\n-1 -1 5 1 -1\n", "5\n-1 -1 1 3 -1\n", "5\n-1 -1 1 5 -1\n"], "outputs": ["1\n", "1\n", "3\n", "3\n", "3\n", "4\n", "3\n", "4\n"]} | coding | 452 |
Solve the programming task below in a Python markdown code block.
After Misha's birthday he had many large numbers left, scattered across the room. Now it's time to clean up and Misha needs to put them in a basket. He ordered this task to his pet robot that agreed to complete the task at certain conditions. Before the ... | {"inputs": ["2\n5\n5\n", "2\n3\n5\n", "2\n6\n5\n", "2\n7\n5\n", "2\n7\n6\n", "2\n7\n9\n", "2\n5\n5\n", "2\n7\n12\n"], "outputs": ["0\n1 0\n", "0\n0\n", "0\n0\n", "0\n0\n", "0\n0\n", "0\n0\n", "0\n1 0\n", "0\n0\n"]} | coding | 464 |
Solve the programming task below in a Python markdown code block.
You probably know the 42 number as "The answer to life, the universe and everything" according to Douglas Adams' "The Hitchhiker's Guide to the Galaxy". For Freud, the answer was quite different.
In the society he lived in, people-women in particular- h... | {"functional": "_inputs = [['test'], ['sexy sex'], ['This is a test'], ['This is a longer test'], [\"You're becoming a true freudian expert\"]]\n_outputs = [['sex'], ['sex sex'], ['sex sex sex sex'], ['sex sex sex sex sex'], ['sex sex sex sex sex sex']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, ... | coding | 254 |
Solve the programming task below in a Python markdown code block.
# Task
Given an array `arr`, find the maximal value of `k` such `a[i] mod k` = `a[j] mod k` for all valid values of i and j.
If it's impossible to find such number (there's an infinite number of `k`s), return `-1` instead.
# Input/Output
`[input]` in... | {"functional": "_inputs = [[[1, 2, 3]], [[1, 1, 1]], [[5, 2, 8]], [[4, 1, 7]], [[1, 7, 13]], [[4, 5, 4]], [[5, 6, 7, 8]], [[10, 100]], [[64, 8, 1]], [[2, 9, 30]]]\n_outputs = [[1], [-1], [3], [3], [6], [1], [1], [90], [7], [7]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, fl... | coding | 295 |
Solve the programming task below in a Python markdown code block.
Sarthak has a set S of N distinct prime numbers. He grew very fond of that set, and now he only likes a positive integer X if all of its prime factors belong to S. Given the set and a positive integer M, can you find out how many integers he likes which ... | {"inputs": ["1\n2 10\n3 5\n"], "outputs": ["4"]} | coding | 329 |
Solve the programming task below in a Python markdown code block.
You are given an array $a$ of length $n$ that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square.
A sequence $a$ ... | {"inputs": ["1\n1\n", "1\n1\n", "2\n1 1\n", "1\n998\n", "1\n998\n", "2\n1 1\n", "2\n2 1\n", "2\n2 2\n"], "outputs": ["1", "1", "1", "-1", "-1", "1", "1\n", "2\n"]} | coding | 388 |
Solve the programming task below in a Python markdown code block.
We have an integer sequence of length N: A_0,A_1,\cdots,A_{N-1}.
Find the following sum (\mathrm{lcm}(a, b) denotes the least common multiple of a and b):
* \sum_{i=0}^{N-2} \sum_{j=i+1}^{N-1} \mathrm{lcm}(A_i,A_j)
Since the answer may be enormous, ... | {"inputs": ["3\n1 4 6", "3\n2 3 6", "3\n2 1 6", "3\n2 4 6", "3\n0 1 10", "8\n1 4 3 4 6 8 12 12", "8\n1 8 3 4 6 8 12 12", "8\n1 8 3 4 6 7 12 12"], "outputs": ["22\n", "18\n", "14\n", "22", "10\n", "327\n", "383\n", "585\n"]} | coding | 347 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer num, return the number of steps to reduce it to zero.
In one step, if the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.
Please complete the following... | {"functional": "def check(candidate):\n assert candidate(num = 14) == 6\n assert candidate(num = 8) == 4\n assert candidate(num = 123) == 12\n\n\ncheck(Solution().numberOfSteps)"} | coding | 94 |
Solve the programming task below in a Python markdown code block.
Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved pro... | {"inputs": ["3\n3 5 4\n", "3\n6 5 4\n", "3\n6 5 8\n", "3\n6 5 6\n", "3\n4 5 6\n", "3\n4 0 6\n", "3\n4 0 7\n", "3\n7 0 7\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 561 |
Solve the programming task below in a Python markdown code block.
You are given a string s, consisting of lowercase English letters, and the integer m.
One should choose some symbols from the given string so that any contiguous subsegment of length m has at least one selected symbol. Note that here we choose positions... | {"inputs": ["1\nbaaa\n", "1\nbaaa\n", "3\ncbabc\n", "2\nabcab\n", "3\nbbabc\n", "2\nabbab\n", "3\ncbabc\n", "2\nabcab\n"], "outputs": ["aaab\n", "aaab", "a\n", "aab\n", "a\n", "aab\n", "a", "aab"]} | coding | 494 |
Solve the programming task below in a Python markdown code block.
Humpy, the little elephant, has his birthday coming up. He invited all his cousins but doesn’t know how many of them are really coming as some of them are having exams coming up. He will only get to know how many of them are coming on the day of his birt... | {"inputs": ["2\n4 10 2\n2 2 3 1\n4 12 3\n6 5 7 3"], "outputs": ["YES\nNO"]} | coding | 383 |
Solve the programming task below in a Python markdown code block.
# Two samurai generals are discussing dinner plans after a battle, but they can't seem to agree.
The discussion gets heated and you are cannot risk favoring either of them as this might damage your political standing with either of the two clans the sam... | {"functional": "_inputs = [['eat chicken', 'eat chicken and rice'], ['eat a burger and drink a coke', 'drink a coke'], ['i like turtles', 'what are you talking about'], ['aa bb', 'aa bb cc'], ['aa bb cc', 'bb cc'], ['aa bb cc', 'bb cc bb aa'], ['aa bb', 'cc dd'], ['aa bb', ''], ['', 'cc dd'], ['', '']]\n_outputs = [['e... | coding | 236 |
Solve the programming task below in a Python markdown code block.
"The Shell Game" involves cups upturned on a playing surface, with a ball placed underneath one of them. The index of the cups are swapped around multiple times. After that the players will try to find which cup contains the ball.
Your task is as follo... | {"functional": "_inputs = [[5, []], [0, []], [9, []], [0, [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 9], [9, 10], [10, 11], [11, 12], [12, 13], [13, 14], [14, 15], [15, 16], [16, 17], [17, 18], [18, 19], [19, 20], [20, 21], [21, 22], [22, 23], [23, 24], [24, 25], [25, 26], [26, 27], [27, 28], ... | coding | 272 |
Solve the programming task below in a Python markdown code block.
Read problem statements in [Mandarin], [Bengali], [Russian], and [Vietnamese] as well.
Chef has three spells. Their powers are A, B, and C respectively. Initially, Chef has 0 hit points, and if he uses a spell with power P, then his number of hit points... | {"inputs": ["2\n4 2 8\n10 14 18"], "outputs": ["12\n32"]} | coding | 413 |
Solve the programming task below in a Python markdown code block.
Consider a tic-tac-toe on a 3x3 board. Tic-tac-toe is a two-player battle game. Decide the first attack and the second attack, one hits Kuroishi and one hits Shiraishi. The winner is the person who puts stones one by one on the board alternately and arra... | {"inputs": ["bbw\nwbw\n+b+\nbwb\nwbx\nwbw\n0", "bbw\nbww\n+b+\nbwb\nwbx\nwbw\n0", "bbw\nwwb\n+a+\nbwb\nxbw\nwvb\n0", "bbw\nwbw\n+b+\nbbw\nwcw\nbww\n0", "bbw\nwcw\n+c+\nwbb\nwcw\nwwb\n0", "cwb\nwwb\n++b\nbwb\nwbw\nxyb\n0", "bbw\nwbw\n+b+\nbwb\nwcw\nwbw\n0", "cbw\nwbw\n+b+\nbwb\nwbx\nwbw\n0"], "outputs": ["b\nNA\n", "NA\... | coding | 324 |
Solve the programming task below in a Python markdown code block.
The Tower of Hanoi problem involves 3 towers. A number of rings decreasing in size are placed on one tower. All rings must then be moved to another tower, but at no point can a larger ring be placed on a smaller ring.
Your task: Given a number of rin... | {"functional": "_inputs = [[4], [5], [10], [50]]\n_outputs = [[15], [31], [1023], [1125899906842623]]\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) !=... | coding | 213 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array target that consists of distinct integers and another integer array arr that can have duplicates.
In one operation, you can insert any integer at any position in arr. For example, if arr = [1,4,... | {"functional": "def check(candidate):\n assert candidate(target = [5,1,3], arr = [9,4,2,3,4]) == 2\n assert candidate(target = [6,4,8,1,3,2], arr = [4,7,6,2,3,8,6,1]) == 3\n\n\ncheck(Solution().minOperations)"} | coding | 238 |
Solve the programming task below in a Python markdown code block.
You've got an n × m matrix. The matrix consists of integers. In one move, you can apply a single transformation to the matrix: choose an arbitrary element of the matrix and increase it by 1. Each element can be increased an arbitrary number of times.
Yo... | {"inputs": ["1 1\n14\n", "1 1\n14\n", "1 1\n32\n", "1 1\n19\n", "1 1\n36\n", "1 1\n99992\n", "1 1\n20000\n", "1 1\n99992\n"], "outputs": ["3\n", "3\n", "5\n", "0\n", "1\n", "11\n", "11\n", "11\n"]} | coding | 495 |
Solve the programming task below in a Python markdown code block.
There are two rectangles.
The lengths of the vertical sides of the first rectangle are A, and the lengths of the horizontal sides of the first rectangle are B.
The lengths of the vertical sides of the second rectangle are C, and the lengths of the horizo... | {"inputs": ["3 3 2 7", "0 3 0 7", "1 4 4 2", "1 4 4 4", "0 0 9 1", "3 5 2 7", "3 5 2 7\n", "2 1 1 11"], "outputs": ["14\n", "0\n", "8\n", "16\n", "9\n", "15", "15\n", "11\n"]} | coding | 259 |
Solve the programming task below in a Python markdown code block.
You are given two integers A and B as the input. Output the value of A + B.
However, if A + B is 10 or greater, output error instead.
-----Constraints-----
- A and B are integers.
- 1 ≤ A, B ≤ 9
-----Input-----
Input is given from Standard Input in t... | {"inputs": ["6 7", "6 0", "7 0", "5 0", "1 1", "1 0", "2 1", "3 1"], "outputs": ["error\n", "6\n", "7\n", "5\n", "2\n", "1\n", "3\n", "4\n"]} | coding | 133 |
Solve the programming task below in a Python markdown code block.
The game of Berland poker is played with a deck of $n$ cards, $m$ of which are jokers. $k$ players play this game ($n$ is divisible by $k$).
At the beginning of the game, each player takes $\frac{n}{k}$ cards from the deck (so each card is taken by exac... | {"inputs": ["1\n49 7 7\n", "1\n49 7 7\n", "1\n48 7 4\n", "1\n48 3 6\n", "1\n49 9 7\n", "1\n48 0 6\n", "1\n71 9 7\n", "1\n48 1 4\n"], "outputs": ["7\n", "7\n", "7\n", "3\n", "6\n", "0\n", "9\n", "1\n"]} | coding | 637 |
Solve the programming task below in a Python markdown code block.
You are given the array of integer numbers a_0, a_1, ..., a_{n} - 1. For each element find the distance to the nearest zero (to the element which equals to zero). There is at least one zero element in the given array.
-----Input-----
The first line co... | {"inputs": ["1\n0\n", "1\n0\n", "1\n0\n", "1\n0\n", "1\n0\n", "2\n0 0\n", "2\n0 1\n", "2\n1 0\n"], "outputs": ["0 ", "0 ", "0 ", "0 ", "0 ", "0 0 ", "0 1 ", "1 0 "]} | coding | 290 |
Solve the programming task below in a Python markdown code block.
There are $n$ boxers, the weight of the $i$-th boxer is $a_i$. Each of them can change the weight by no more than $1$ before the competition (the weight cannot become equal to zero, that is, it must remain positive). Weight is always an integer number.
... | {"inputs": ["1\n1\n", "1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "2\n1 1\n", "2\n2 2\n", "2\n2 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n"]} | coding | 440 |
Solve the programming task below in a Python markdown code block.
Note : Issues Fixed with python 2.7.6 , Use any one you like :D , ( Thanks to
Time , time , time . Your task is to write a function that will return the degrees on a analog clock from a digital time that is passed in as parameter . The digital time is ... | {"functional": "_inputs = [['01:01'], ['00:00'], ['01:03'], ['01:30'], ['12:05'], ['26:78'], ['16:25'], ['17:09'], ['19:00'], ['20:34'], ['23:20'], ['24:00'], ['-09:00']]\n_outputs = [['30:6'], ['360:360'], ['30:18'], ['30:180'], ['360:30'], ['Check your time !'], ['120:150'], ['150:54'], ['210:360'], ['240:204'], ['33... | coding | 414 |
Solve the programming task below in a Python markdown code block.
Let's denote d(n) as the number of divisors of a positive integer n. You are given three integers a, b and c. Your task is to calculate the following sum:
$\sum_{i = 1}^{a} \sum_{j = 1}^{b} \sum_{k = 1}^{c} d(i \cdot j \cdot k)$
Find the sum modulo 107... | {"inputs": ["2 2 2\n", "5 6 7\n", "1 5 1\n", "1 5 1\n", "2 1 2\n", "2 2 2\n", "5 6 7\n", "71 2 1\n"], "outputs": ["20\n", "1520\n", "10\n", "10\n", "8\n", "20\n", "1520\n", "811\n"]} | coding | 390 |
Solve the programming task below in a Python markdown code block.
You received a notebook which is called Death Note. This notebook has infinite number of pages. A rule is written on the last page (huh) of this notebook. It says: "You have to write names in this notebook during $n$ consecutive days. During the $i$-th d... | {"inputs": ["1 1\n2\n", "1 1\n1\n", "1 1\n2\n", "1 1\n1\n", "1 1\n4\n", "1 100\n99\n", "1 100\n51\n", "1 001\n51\n"], "outputs": ["2 \n", "1 \n", "2\n", "1\n", "4\n", "0 \n", "0\n", "51\n"]} | coding | 687 |
Solve the programming task below in a Python markdown code block.
Arpa is researching the Mexican wave.
There are n spectators in the stadium, labeled from 1 to n. They start the Mexican wave at time 0.
At time 1, the first spectator stands. At time 2, the second spectator stands. ... At time k, the k-th specta... | {"inputs": ["5 3 5\n", "3 2 4\n", "6 1 4\n", "2 2 3\n", "5 4 6\n", "2 1 2\n", "2 2 2\n", "5 5 6\n"], "outputs": ["3\n", "1\n", "1\n", "1\n", "3\n", "1\n", "2\n", "4\n"]} | coding | 666 |
Solve the programming task below in a Python markdown code block.
Oh no! You have stumbled upon a mysterious signal consisting of beeps of various lengths, and it is of utmost importance that you find out the secret message hidden in the beeps. There are long and short beeps, the longer ones roughly three times as lo... | {"functional": "_inputs = [['.... . .-.. .-.. --- .-- --- .-. .-.. -..'], ['.---- ... - .- -. -.. ..--- -. -..'], ['.. .- -- .- - . ... -'], ['.- -... -.-. -.. . ..-. --. .... .. .--- -.- .-.. -- -. --- .--. --.- .-. ... - ..- ...- .-- -..- -.-- --.. ----- .---- ..--- ...-- ....- ..... -.... --... ---.. ----.'], ... | coding | 520 |
Solve the programming task below in a Python markdown code block.
A permutation is a sequence of integers from 1 to n of length n containing each number exactly once. For example, (1), (4, 3, 5, 1, 2), (3, 2, 1) are permutations, and (1, 1), (4, 3, 1), (2, 3, 4) are not.
There are many tasks on permutations. Today yo... | {"inputs": ["1\n1\n", "1\n2\n", "1\n3\n", "1\n5\n", "1\n4\n", "1\n6\n", "3\n2 1 1\n", "3\n4 1 1\n"], "outputs": ["1\n1 ", "-1", "-1\n", "-1\n", "-1\n", "-1\n", "2\n1 1 2 ", "-1\n"]} | coding | 527 |
Solve the programming task below in a Python markdown code block.
The country Treeland consists of n cities, some pairs of them are connected with unidirectional roads. Overall there are n - 1 roads in the country. We know that if we don't take the direction of the roads into consideration, we can get from any city to ... | {"inputs": ["2\n1 2\n", "3\n2 1\n2 3\n", "4\n1 4\n2 4\n3 4\n", "8\n1 2\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7\n", "8\n1 4\n3 2\n4 3\n4 5\n6 5\n6 7\n8 7\n", "8\n1 4\n3 2\n4 3\n4 5\n6 5\n6 7\n8 4\n", "8\n1 4\n3 2\n4 3\n4 5\n6 5\n6 7\n8 1\n", "8\n1 4\n3 2\n7 3\n4 5\n6 5\n6 7\n8 4\n"], "outputs": ["0\n1\n", "0\n2\n", "2\n1 2 3\n", ... | coding | 408 |
Solve the programming task below in a Python markdown code block.
There are H rows and W columns of white square cells.
You will choose h of the rows and w of the columns, and paint all of the cells contained in those rows or columns.
How many white cells will remain?
It can be proved that this count does not depend on... | {"inputs": ["2 4\n2 3", "5 5\n2 2", "4 2\n2 1", "4 5\n2 2", "4 0\n2 1", "7 5\n2 2", "4 0\n0 1", "7 5\n1 2"], "outputs": ["0\n", "9\n", "2\n", "6\n", "-2\n", "15\n", "-4\n", "18\n"]} | coding | 212 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two version strings, version1 and version2, compare them. A version string consists of revisions separated by dots '.'. The value of the revision is its integer conversion ignoring leading zeros.
To compare vers... | {"functional": "def check(candidate):\n assert candidate(version1 = \"1.2\", version2 = \"1.10\") == -1\n assert candidate(version1 = \"1.01\", version2 = \"1.001\") == 0\n assert candidate(version1 = \"1.0\", version2 = \"1.0.0.0\") == 0\n\n\ncheck(Solution().compareVersion)"} | coding | 157 |
Solve the programming task below in a Python markdown code block.
For "x", determine how many positive integers less than or equal to "x" are odd but not prime. Assume "x" is an integer between 1 and 10000.
Example: 5 has three odd numbers (1,3,5) and only the number 1 is not prime, so the answer is 1
Example: 10 has... | {"functional": "_inputs = [[5], [10], [99]]\n_outputs = [[1], [2], [26]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ... | coding | 146 |
Solve the programming task below in a Python markdown code block.
Polycarp remembered the $2020$-th year, and he is happy with the arrival of the new $2021$-th year. To remember such a wonderful moment, Polycarp wants to represent the number $n$ as the sum of a certain number of $2020$ and a certain number of $2021$.
... | {"inputs": ["1\n7\n", "1\n9\n", "1\n8\n", "1\n2\n", "1\n3\n", "1\n6\n", "1\n4\n", "1\n1\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | coding | 518 |
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)"} | coding | 195 |
Solve the programming task below in a Python markdown code block.
The Academy is a school where each common area is laid out on an $m\times n$ grid and each cell in the grid is $\mbox{1}$ meter by $\mbox{1}$ meter. Danielle is their new head of security, and she wants to place a surveillance camera along every square m... | {"inputs": ["2\n3 3\n3 4\n"], "outputs": ["36\n78\n"]} | coding | 572 |
Solve the programming task below in a Python markdown code block.
Let us calculate the sum of k-th powers of natural numbers from 1 to n. As the result can be quite large, output the result modulo some integer p.
------ Input ------
First t≤10 - the number of test cases.
Each test case consist of numbers: 1≤n≤100000... | {"inputs": ["4\n10 1 1000000\n10 2 1000000\n10 3 1000000\n10 4 1000000"], "outputs": ["55\n385\n3025\n25333"]} | coding | 229 |
Solve the programming task below in a Python markdown code block.
Read problems statements [Hindi] , [Vietnamese] , [Mandarin Chinese] , [Russian] and [Bengali] as well.
You are given a directed acyclic graph with $N$ vertices (numbered $1$ through $N$) and $M$ edges. You want to destroy it all! To destroy the graph, ... | {"inputs": ["6 6\n1 2\n2 3\n1 3\n3 4\n3 5\n1 6\n"], "outputs": ["4\n2 4 5\n2 6 3\n1 2\n1 1\n"]} | coding | 581 |
Solve the programming task below in a Python markdown code block.
You are given an array $A$ of $N$ positive and pairwise distinct integers.
You can permute the elements in any way you want.
The cost of an ordering $(A_1, A_2, \ldots, A_N)$ is defined as $ (((A_1 \bmod A_2) \bmod A_3)......) \bmod A_N$ where $X \bmod... | {"inputs": ["1\n2\n7 12"], "outputs": ["7"]} | coding | 413 |
Solve the programming task below in a Python markdown code block.
Let's denote that some array $b$ is bad if it contains a subarray $b_l, b_{l+1}, \dots, b_{r}$ of odd length more than $1$ ($l < r$ and $r - l + 1$ is odd) such that $\forall i \in \{0, 1, \dots, r - l\}$ $b_{l + i} = b_{r - i}$.
If an array is not bad,... | {"inputs": ["2 3\n3 3\n", "2 3\n3 3\n", "2 6\n3 3\n", "2 6\n5 3\n", "2 6\n2 3\n", "2 6\n3 5\n", "2 7\n3 5\n", "2 9\n3 5\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | coding | 442 |
Solve the programming task below in a Python markdown code block.
Chef’s girlfriend is angry with him because he forgot her birthday. Chef decided to please her by gifting her a Love Graph.
Chef has $N$ vertices: $V_1, V_2, \dots, V_N$. Love Graph is an undirected multigraph with no self-loops and can be constructed b... | {"inputs": ["1\n2 1"], "outputs": ["2"]} | coding | 494 |
Solve the programming task below in a Python markdown code block.
Serval soon said goodbye to Japari kindergarten, and began his life in Japari Primary School.
In his favorite math class, the teacher taught him the following interesting definitions.
A parenthesis sequence is a string, containing only characters "(" a... | {"inputs": ["1\n?\n", "1\n(\n", "1\n)\n", "1\n)\n", "1\n?\n", "1\n(\n", "2\n??\n", "2\n((\n"], "outputs": [":(\n", ":(\n", ":(\n", ":(\n", ":(\n", ":(\n", "()\n", ":(\n"]} | coding | 526 |
Solve the programming task below in a Python markdown code block.
One day n cells of some array decided to play the following game. Initially each cell contains a number which is equal to it's ordinal number (starting from 1). Also each cell determined it's favourite number. On it's move i-th cell can exchange it's val... | {"inputs": ["1\n1\n1\n", "1\n1\n2\n", "2\n2 1\n2 2\n", "2\n2 1\n1 1\n", "2\n1 2\n1 1\n", "2\n1 2\n2 2\n", "2\n2 1\n1 2\n", "4\n1 2 3 4\n1 1 1 1\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]} | coding | 333 |
Solve the programming task below in a Python markdown code block.
Count the number of distinct sequences a_1, a_2, ..., a_{n} (1 ≤ a_{i}) consisting of positive integers such that gcd(a_1, a_2, ..., a_{n}) = x and $\sum_{i = 1}^{n} a_{i} = y$. As this number could be large, print the answer modulo 10^9 + 7.
gcd here m... | {"inputs": ["3 9\n", "5 8\n", "1 8\n", "1 9\n", "1 1\n", "1 1\n", "1 9\n", "1 8\n"], "outputs": ["3\n", "0\n", "120\n", "252\n", "1\n", "1\n", "252\n", "120\n"]} | coding | 220 |
Solve the programming task below in a Python markdown code block.
Chef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let F_{d}(x) equals to the number o... | {"inputs": ["3\n2\n6\n011", "3\n0\n6\n010", "3\n0\n3\n010", "3\n1\n3\n010", "3\n1\n1\n010", "3\n2\n1\n010", "3\n2\n1\n011", "3\n2\n1\n111"], "outputs": ["3\n9\n39\n", "0\n9\n31\n", "0\n6\n31\n", "1\n6\n31\n", "1\n1\n31\n", "3\n1\n31\n", "3\n1\n39\n", "3\n1\n1709\n"]} | coding | 323 |
Solve the programming task below in a Python markdown code block.
Three guys play a game: first, each person writes down $n$ distinct words of length $3$. Then, they total up the number of points as follows:
if a word was written by one person — that person gets 3 points,
if a word was written by two people — each of... | {"inputs": ["1\n1\niiy\niiy\niiy\n", "3\n1\nabc\ndef\nabc\n3\norz for qaq\nqaq orz for\ncod for ces\n5\niat roc hem ica lly\nbac ter iol ogi sts\nbac roc lly iol iat\n"], "outputs": ["0 0 0 \n", "1 3 1 \n2 2 6 \n9 11 5 \n"]} | coding | 417 |
Solve the programming task below in a Python markdown code block.
There are N squares in a row. The leftmost square contains the integer A, and the rightmost contains the integer B. The other squares are empty.
Aohashi would like to fill the empty squares with integers so that the following condition is satisfied:
* ... | {"inputs": ["4 7 9 4 6", "4 4 9 4 6", "4 4 9 0 6", "3 4 9 0 5", "3 7 9 0 5", "3 7 9 0 3", "3 7 9 0 2", "5 1 5 2 4"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES"]} | coding | 384 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums.
You should move each element of nums into one of the two arrays A and B such that A and B are non-empty, and average(A) == average(B).
Return true if it is possible to achieve that... | {"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4,5,6,7,8]) == True\n assert candidate(nums = [3,1]) == False\n\n\ncheck(Solution().splitArraySameAverage)"} | coding | 129 |
Solve the programming task below in a Python markdown code block.
Given a positive integer n, find k integers (not necessary distinct) such that all these integers are strictly greater than 1, and their product is equal to n.
Input
The first line contains two integers n and k (2 ≤ n ≤ 100000, 1 ≤ k ≤ 20).
Output
If... | {"inputs": ["4 5\n", "9 6\n", "5 6\n", "5 4\n", "8 2\n", "6 2\n", "2 5\n", "5 3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "2 4\n", "2 3\n", "-1\n", "-1\n"]} | coding | 192 |
Solve the programming task below in a Python markdown code block.
Goal
Given a list of elements [a1, a2, ..., an], with each ai being a string, write a function **majority** that returns the value that appears the most in the list.
If there's no winner, the function should return None, NULL, nil, etc, based on the pr... | {"functional": "_inputs = [[['A', 'B', 'A']], [['A', 'B', 'C']], [['A', 'B', 'B', 'A']], [['A', 'A', 'A', 'A']], [['A']], [['A', 'A', 'A', 'BBBBBBBB']], [['A', 'B', 'C', 'C']], [[]], [['B', 'C', '', '']]]\n_outputs = [['A'], [None], [None], ['A'], ['A'], ['A'], ['C'], [None], ['']]\nimport math\ndef _deep_eq(a, b, tol=... | coding | 135 |
Solve the programming task below in a Python markdown code block.
The BFS algorithm is defined as follows. Consider an undirected graph with vertices numbered from $1$ to $n$. Initialize $q$ as a new queue containing only vertex $1$, mark the vertex $1$ as used. Extract a vertex $v$ from the head of the queue $q$. P... | {"inputs": ["1\n1\n", "1\n1\n", "2\n1 2\n2 1\n", "2\n2 1\n1 2\n", "2\n2 1\n2 1\n", "2\n1 2\n2 1\n", "2\n2 1\n1 2\n", "2\n2 1\n2 1\n"], "outputs": ["Yes", "Yes\n", "No", "Yes", "No", "No\n", "Yes\n", "No\n"]} | coding | 562 |
Solve the programming task below in a Python markdown code block.
You are given two strings $s$ and $t$, both consisting only of lowercase Latin letters.
The substring $s[l..r]$ is the string which is obtained by taking characters $s_l, s_{l + 1}, \dots, s_r$ without changing the order.
Each of the occurrences of str... | {"inputs": ["1 1 1\na\na\n1 1\n", "1 1 1\na\nb\n1 1\n", "1 1 1\na\nb\n1 1\n", "1 1 1\na\na\n1 1\n", "1 2 1\na\nb\n1 1\n", "1 2 1\na\nb\n1 0\n", "1 1 1\na\nb\n1 0\n", "1 4 1\na\nb\n1 1\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n"]} | coding | 546 |
Solve the programming task below in a Python markdown code block.
ZS the Coder and Chris the Baboon are travelling to Udayland! To get there, they have to get on the special IOI bus. The IOI bus has n rows of seats. There are 4 seats in each row, and the seats are separated into pairs by a walkway. When ZS and Chris ca... | {"inputs": ["1\nXO|OX\n", "1\nOO|OO\n", "1\nOO|XX\n", "1\nXO|OX\n", "1\nOO|OO\n", "1\nOO|XX\n", "1\nXX|OO\n", "1\nXO|NX\n"], "outputs": ["NO\n", "YES\n++|OO\n", "YES\n++|XX\n", "NO\n", "YES\n++|OO\n", "YES\n++|XX\n", "YES\nXX|++\n", "NO\n"]} | coding | 613 |
Solve the programming task below in a Python markdown code block.
For each positive integer n consider the integer ψ(n) which is obtained from n by replacing every digit a in the decimal notation of n with the digit (9 - a). We say that ψ(n) is the reflection of n. For example, reflection of 192 equals 807. Note that l... | {"inputs": ["4 6\n", "1 2\n", "1 4\n", "2 2\n", "6 7\n", "5 7\n", "3 7\n", "1 1\n"], "outputs": ["20\n", "14\n", "20\n", "14\n", "18\n", "20\n", "20\n", "8\n"]} | coding | 362 |
Solve the programming task below in a Python markdown code block.
Alexey, a merry Berland entrant, got sick of the gray reality and he zealously wants to go to university. There are a lot of universities nowadays, so Alexey is getting lost in the diversity — he has not yet decided what profession he wants to get. At sc... | {"inputs": ["2\n5 2 3\n6 4 5\n", "2\n5 3 4\n9 4 4\n", "2\n5 2 3\n9 4 7\n", "2\n5 2 3\n1 4 7\n", "2\n5 2 4\n9 4 4\n", "2\n5 2 4\n1 4 7\n", "2\n5 4 4\n1 4 7\n", "2\n5 3 4\n9 4 5\n"], "outputs": ["Yes\nNo\n", "No\nNo\n", "Yes\nYes\n", "Yes\nNo\n", "Yes\nNo\n", "Yes\nNo\n", "No\nNo\n", "No\nYes\n"]} | coding | 694 |
Solve the programming task below in a Python markdown code block.
Pair of gloves
=============
Winter is coming, you must prepare your ski holidays. The objective of this kata is to determine the number of pair of gloves you can constitute from the gloves you have in your drawer.
A pair of gloves is constituted of tw... | {"functional": "_inputs = [[['red', 'red']], [['red', 'green', 'blue']], [['gray', 'black', 'purple', 'purple', 'gray', 'black']], [[]], [['red', 'green', 'blue', 'blue', 'red', 'green', 'red', 'red', 'red']]]\n_outputs = [[1], [0], [3], [0], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float)... | coding | 200 |
Solve the programming task below in a Python markdown code block.
Chef is watching a football match. The current score is A:B, that is, team 1 has scored A goals and team 2 has scored B goals. Chef wonders if it is possible for the score to become C:D at a later point in the game (i.e. team 1 has scored C goals and tea... | {"inputs": ["3\n1 5\n3 5\n3 4\n2 6\n2 2\n2 2\n"], "outputs": ["POSSIBLE\nIMPOSSIBLE\nPOSSIBLE\n"]} | coding | 497 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is an undirected connected tree with n nodes labeled from 0 to n - 1 and n - 1 edges.
You are given the integer n and the array edges where edges[i] = [ai, bi] indicates that there is an edge between nodes ai an... | {"functional": "def check(candidate):\n assert candidate(n = 6, edges = [[0,1],[0,2],[2,3],[2,4],[2,5]]) == [8,12,6,10,10,10]\n assert candidate(n = 1, edges = []) == [0]\n assert candidate(n = 2, edges = [[1,0]]) == [1,1]\n\n\ncheck(Solution().sumOfDistancesInTree)"} | coding | 148 |
Solve the programming task below in a Python markdown code block.
Given an array (ints) of n integers, find three integers in arr such that the sum is closest to a given number (num), target.
Return the sum of the three integers.
You may assume that each input would have exactly one solution.
Example:
Note: your so... | {"functional": "_inputs = [[[-1, 2, 1, -4], 1], [[5, 4, 0, 3], 3], [[1, 2, 3, 4], 4], [[-2, 2, -3, 1], 3]]\n_outputs = [[2], [7], [6], [1]]\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,... | coding | 101 |
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed 2D integer array items of length n and an integer k.
items[i] = [profiti, categoryi], where profiti and categoryi denote the profit and category of the ith item respectively.
Let's define the... | {"functional": "def check(candidate):\n assert candidate(items = [[3,2],[5,1],[10,1]], k = 2) == 17\n assert candidate(items = [[3,1],[3,1],[2,2],[5,3]], k = 3) == 19\n assert candidate(items = [[1,1],[2,1],[3,1]], k = 3) == 7\n\n\ncheck(Solution().findMaximumElegance)"} | coding | 229 |
Solve the programming task below in a Python markdown code block.
Given two positive integers a and b, we define f(a, b) = \text{lcm}(a, b) - \gcd(a, b), where \text{lcm} denotes the [lowest common multiple] and \gcd denotes the [greatest common divisor].
Chef has a positive integer N. He wonders, what is the maximum ... | {"inputs": ["3\n3\n4\n6\n"], "outputs": ["1\n2\n4\n"]} | coding | 517 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.