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. There are N non-negative integers written on a blackboard. The i-th integer is A_i. Takahashi can perform the following two kinds of operations any number of times in any order: - Select one integer written on the board (let this integer be X). Write 2X...
{"inputs": ["3 111\n1111\n00111\n10010", "3 111\n0111\n00111\n10010", "3 111\n1111\n00011\n11000", "3 101\n0111\n00011\n10000", "3 111\n0111\n00011\n10010", "3 111\n0111\n00011\n10000", "3 111\n1111\n00011\n10000", "3 111\n1011\n00011\n11000"], "outputs": ["8\n", "2\n", "4\n", "6\n", "8\n", "8\n", "8\n", "8\n"]}
coding
473
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a valid (IPv4) IP address, return a defanged version of that IP address. A defanged IP address replaces every period "." with "[.]".   Please complete the following python code precisely: ```python class Solutio...
{"functional": "def check(candidate):\n assert candidate(address = \"1.1.1.1\") == \"1[.]1[.]1[.]1\"\n assert candidate(address = \"255.100.50.0\") == \"255[.]100[.]50[.]0\"\n\n\ncheck(Solution().defangIPaddr)"}
coding
86
Solve the programming task below in a Python markdown code block. You are given $\textit{q}$ queries where each query consists of a set of $n$ points on a two-dimensional plane (i.e., $(x,y)$). For each set of points, print YES on a new line if all the points fall on the edges (i.e., sides and/or corners) of a non-dege...
{"inputs": ["2\n3\n0 0\n0 1\n1 0\n4\n0 0\n0 2\n2 0\n1 1\n"], "outputs": ["YES\nNO\n"]}
coding
461
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an array of integers nums, sort the array in increasing order based on the frequency of the values. If multiple values have the same frequency, sort them in decreasing order. Return the sorted array.   Please co...
{"functional": "def check(candidate):\n assert candidate(nums = [1,1,2,2,2,3]) == [3,1,1,2,2,2]\n assert candidate(nums = [2,3,1,3,2]) == [1,3,3,2,2]\n assert candidate(nums = [-1,1,-6,4,5,-6,1,4,1]) == [5,-1,4,4,-6,-6,1,1,1]\n\n\ncheck(Solution().frequencySort)"}
coding
89
Solve the programming task below in a Python markdown code block. Arthur defines a function, $f(k)$, to be the number of $(p,q)$ pairs such that: $1<p\leq q\leq k$ ${p}$ and $q}$ are coprime. $p\cdot q=k$ Given an integer, $n$, help Arthur find and print the result of: $\sum_{k=1}^{n}f(k)$ Input Format The first l...
{"inputs": ["12\n"], "outputs": ["3\n"]}
coding
390
Solve the programming task below in a Python markdown code block. There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote. Each of the employees belongs to one of two fractions: depublic...
{"inputs": ["1\nD\n", "1\nR\n", "1\nR\n", "1\nD\n", "2\nDR\n", "2\nDR\n", "3\nRDD\n", "3\nDRD\n"], "outputs": ["D\n", "R\n", "R\n", "D\n", "D\n", "D\n", "D\n", "D\n"]}
coding
588
Solve the programming task below in a Python markdown code block. In order to win over and get noticed by his favorite streamer Daenerys, Jon decides to donate a significant amount of money . Every donation made to Daenerys is of $at$ $least$ $1$ $beastcoin$ and is displayed on Daenerys's stream alongside any message w...
{"inputs": ["2\n3\n7"], "outputs": ["4\n8"]}
coding
436
Solve the programming task below in a Python markdown code block. ## Nova polynomial add This kata is from a series on polynomial handling. ( [#1](http://www.codewars.com/kata/nova-polynomial-1-add-1) [#2](http://www.codewars.com/kata/570eb07e127ad107270005fe) [#3](http://www.codewars.com/kata/5714041e8807940ff3001140...
{"functional": "_inputs = [[[1], [1]], [[1, 2], [1]], [[1, 2, 3, 4], [4, 3, 2, 1]], [[], []], [[1, 2, 3, 4, 5, 6], []], [[], [1, 2, 3, 4, 5, 6]]]\n_outputs = [[[2]], [[2, 2]], [[5, 5, 5, 5]], [[]], [[1, 2, 3, 4, 5, 6]], [[1, 2, 3, 4, 5, 6]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or is...
coding
297
Solve the programming task below in a Python markdown code block. Petya is having a party soon, and he has decided to invite his $n$ friends. He wants to make invitations in the form of origami. For each invitation, he needs two red sheets, five green sheets, and eight blue sheets. The store sells an infinite number o...
{"inputs": ["3 5\n", "1 1\n", "1 4\n", "1 4\n", "1 1\n", "1 7\n", "2 1\n", "4 5\n"], "outputs": ["10\n", "15\n", "5\n", "5\n", "15\n", "4\n", "30\n", "13\n"]}
coding
291
Please solve the programming task below using a self-contained code snippet in a markdown code block. Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer. The algorithm for myAtoi(string s) is as follows: Whitespace: Ignore any leading whitespace (" "). Signedness: Determine th...
{"functional": "def check(candidate):\n assert candidate(s = \"42\") == 42\n assert candidate(s = \" -042\") == -42\n assert candidate(s = \"1337c0d3\") == 1337\n assert candidate(s = \"0-1\") == 0\n assert candidate(s = \"words and 987\") == 0\n\n\ncheck(Solution().myAtoi)"}
coding
244
Solve the programming task below in a Python markdown code block. A matrix of size $n \times m$ is called nice, if all rows and columns of the matrix are palindromes. A sequence of integers $(a_1, a_2, \dots , a_k)$ is a palindrome, if for any integer $i$ ($1 \le i \le k$) the equality $a_i = a_{k - i + 1}$ holds. Sas...
{"inputs": ["2\n4 2\n4 2\n2 4\n4 2\n2 4\n3 4\n1 2 3 4\n5 6 7 8\n9 10 11 18\n", "2\n4 2\n4 2\n2 4\n4 2\n2 4\n3 4\n1 2 3 4\n5 6 5 8\n9 10 11 18\n", "2\n4 2\n6 2\n0 4\n4 2\n2 4\n2 4\n1 2 3 7\n12 6 7 14\n0 9 11 6\n", "2\n4 2\n6 2\n0 4\n8 2\n2 4\n2 4\n1 2 3 7\n12 6 7 14\n0 9 11 6\n", "2\n4 2\n6 2\n0 4\n8 2\n2 4\n2 4\n1 0 3 ...
coding
450
Solve the programming task below in a Python markdown code block. Is there anything better than going to the zoo after a tiresome week at work? No wonder Grisha feels the same while spending the entire weekend accompanied by pretty striped zebras. Inspired by this adventure and an accidentally found plasticine pack (...
{"inputs": ["b\n", "w\n", "b\n", "w\n", "bw\n", "bw\n", "wb\n", "bwb\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "2\n", "2\n", "3\n"]}
coding
409
Solve the programming task below in a Python markdown code block. There are just some things you can't do on television. In this case, you've just come back from having a "delicious" Barth burger and you're set to give an interview. The Barth burger has made you queezy, and you've forgotten some of the import rules of ...
{"functional": "_inputs = [['water'], ['wet'], ['wash'], [\"i don't know\"], ['slime'], ['wet water'], ['slime water'], [\"I don't know if this will work\"], [\"I don't know if this will work without watering it first.\"], [''], ['is there SLIME in that?!'], [\"i won't say anything\"], ['WaTeR?'], ['but i can say sludg...
coding
414
Solve the programming task below in a Python markdown code block. Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively. After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get: * Each of them simultaneously calculate the sum of the ...
{"inputs": ["2 2 3 1", "0 3 2 0", "2 3 3 1", "4 3 3 1", "9 6 3 2", "7 2 0 0", "1 2 3 1", "2 3 2 0"], "outputs": ["0\n", "-3\n", "1\n", "-1\n", "3\n", "5\n", "1", "-1"]}
coding
312
Solve the programming task below in a Python markdown code block. A conglomerate consists of $n$ companies. To make managing easier, their owners have decided to merge all companies into one. By law, it is only possible to merge two companies, so the owners plan to select two companies, merge them into one, and continu...
{"inputs": ["1\n4 2 2 3 2\n", "1\n4 2 2 3 2\n", "1\n4 2 2 3 0\n", "1\n4 3 2 3 0\n", "1\n4 3 2 4 0\n", "1\n4 1 2 4 0\n", "1\n4 2 2 2 2\n", "1\n1 2 2 3 0\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
coding
508
Solve the programming task below in a Python markdown code block. The integers $0$ to $M - 1$ have been arranged in a circular fashion. That is, $0, 1, 2, \ldots, M - 1$, are in that order and also, $0$ and $M - 1$ are next to each other. The distance between any two adjacent numbers on this circle is 1. You are given ...
{"inputs": ["9 3\n0 2\n3 4\n5 7"], "outputs": ["3"]}
coding
630
Solve the programming task below in a Python markdown code block. You are given a matrix of size n × n filled with lowercase English letters. You can change no more than k letters in this matrix. Consider all paths from the upper left corner to the lower right corner that move from a cell to its neighboring cell to th...
{"inputs": ["1 0\nz\n", "1 1\ng\n", "1 0\na\n", "1 1\nz\n", "1 0\ng\n", "1 0\ny\n", "1 1\nf\n", "1 2\nf\n"], "outputs": ["z\n", "a\n", "a\n", "a\n", "g\n", "y", "a", "a"]}
coding
458
Solve the programming task below in a Python markdown code block. You are playing a new computer game in which you have to fight monsters. In a dungeon you are trying to clear, you met three monsters; the first of them has $a$ health points, the second has $b$ health points, and the third has $c$. To kill the monsters...
{"inputs": ["1\n3 1 5\n", "1\n1 2 6\n", "1\n4 4 1\n", "1\n7 1 1\n", "1\n1 1 7\n", "1\n4 1 4\n", "1\n9 2 7\n", "1\n1 3 5\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n", "YES\n"]}
coding
557
Solve the programming task below in a Python markdown code block. Teacher thinks that we make a lot of progress. Now we are even allowed to use decimal notation instead of counting sticks. After the test the teacher promised to show us a "very beautiful number". But the problem is, he's left his paper with the number i...
{"inputs": ["6 5\n", "1 2\n", "6 4\n", "2 7\n", "1 1\n", "1 1\n", "2 7\n", "2 2\n"], "outputs": ["142857", "Impossible\n", "102564", "Impossible\n", "1", "1\n", "Impossible\n", "Impossible\n"]}
coding
368
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a string s, return true if the s can be palindrome after deleting at most one character from it.   Please complete the following python code precisely: ```python class Solution: def validPalindrome(self, s: ...
{"functional": "def check(candidate):\n assert candidate(s = \"aba\") == True\n assert candidate(s = \"abca\") == True\n assert candidate(s = \"abc\") == False\n\n\ncheck(Solution().validPalindrome)"}
coding
69
Solve the programming task below in a Python markdown code block. There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, ...
{"inputs": ["1 1 1\n1\n1\n", "1 1 13\n2\n3\n", "1 1 13\n2\n2\n", "1 1 10\n5\n15\n", "1 1 10\n2\n15\n", "1 1 13\n2\n15\n", "1 1 10\n10\n10\n", "1 1 10\n10\n15\n"], "outputs": ["0", "11\n", "11\n", "15", "18\n", "15\n", "0", "10\n"]}
coding
494
Please solve the programming task below using a self-contained code snippet in a markdown code block. Alice and Bob are traveling to Rome for separate business meetings. You are given 4 strings arriveAlice, leaveAlice, arriveBob, and leaveBob. Alice will be in the city from the dates arriveAlice to leaveAlice (inclusi...
{"functional": "def check(candidate):\n assert candidate(arriveAlice = \"08-15\", leaveAlice = \"08-18\", arriveBob = \"08-16\", leaveBob = \"08-19\") == 3\n assert candidate(arriveAlice = \"10-01\", leaveAlice = \"10-31\", arriveBob = \"11-01\", leaveBob = \"12-31\") == 0\n\n\ncheck(Solution().countDaysTogether)...
coding
251
Solve the programming task below in a Python markdown code block. Kristina has two arrays $a$ and $b$, each containing $n$ non-negative integers. She can perform the following operation on array $a$ any number of times: apply a decrement to each non-zero element of the array, that is, replace the value of each element...
{"inputs": ["1\n1\n372\n200\n", "1\n2\n1456 5324\n1455 5323\n", "1\n4\n372 372 1 8\n372 372 1 8\n", "1\n4\n8293 8293 1 8\n8293 8293 1 8\n", "6\n4\n3 5 4 1\n1 3 2 0\n3\n1 2 1\n0 1 0\n4\n5 3 7 2\n1 1 1 1\n5\n1 2 3 4 5\n1 2 3 4 6\n1\n8\n0\n1\n4\n6\n"], "outputs": ["YES\n", "YES\n", "YES\n", "YES\n", "YES\nYES\nNO\nNO\nYES...
coding
733
Solve the programming task below in a Python markdown code block. When he's not training for IOI, Little Alawn enjoys playing with puzzles of various types to stimulate his brain. Today, he's playing with a puzzle that consists of a $2 \times n$ grid where each row is a permutation of the numbers $1,2,3,\ldots,n$. The...
{"inputs": ["2\n4\n1 4 2 3\n3 2 1 4\n8\n2 6 5 1 4 3 7 8\n3 8 7 5 1 2 4 6\n", "2\n4\n1 4 2 3\n3 2 1 4\n8\n2 6 5 1 4 3 7 8\n3 8 7 5 1 2 4 6\n"], "outputs": ["2\n8\n", "\n2\n8\n"]}
coding
574
Solve the programming task below in a Python markdown code block. Takahashi loves the number 7 and multiples of K. Where is the first occurrence of a multiple of K in the sequence 7,77,777,\ldots? (Also see Output and Sample Input/Output below.) If the sequence contains no multiples of K, print -1 instead. -----Constr...
{"inputs": ["3", "1", "9", "2", "2\n", "1\n", "3\n", "7\n"], "outputs": ["3\n", "1\n", "9\n", "-1", "-1\n", "1\n", "3\n", "1\n"]}
coding
202
Solve the programming task below in a Python markdown code block. Last summer, Feluda gifted Lalmohan-Babu a balanced bracket sequence $s$ of length $2 n$. Topshe was bored during his summer vacations, and hence he decided to draw an undirected graph of $2 n$ vertices using the balanced bracket sequence $s$. For any t...
{"inputs": ["4\n1\n()\n3\n()(())\n3\n((()))\n4\n(())(())\n"], "outputs": ["1\n2\n3\n3\n"]}
coding
576
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given an integer n, find a sequence that satisfies all of the following: The integer 1 occurs once in the sequence. Each integer between 2 and n occurs twice in the sequence. For every integer i between 2 and n, the ...
{"functional": "def check(candidate):\n assert candidate(n = 3) == [3,1,2,3,2]\n assert candidate(n = 5) == [5,3,1,4,3,5,2,4,2]\n\n\ncheck(Solution().constructDistancedSequence)"}
coding
253
Solve the programming task below in a Python markdown code block. You can perform the following operations on the string, $a$: Capitalize zero or more of $a$'s lowercase letters. Delete all of the remaining lowercase letters in $a$. Given two strings, $a$ and $\boldsymbol{b}$, determine if it's possible to make $a$...
{"inputs": ["1\ndaBcd\nABC\n"], "outputs": ["YES\n"]}
coding
551
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given the head of a linked list, remove the nth node from the end of the list and return its head.   Please complete the following python code precisely: ```python # Definition for singly-linked list. # class ListNode...
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5]), n = 2), list_node([1,2,3,5]))\n assert is_same_list(candidate(head = list_node([1]), n = 1), list_node([]))\n assert is_same_list(candidate(head = list_node([1,2]), n = 1), list_node([1]))\n\n\ncheck(Solution()...
coding
121
Solve the programming task below in a Python markdown code block. There are n positive integers a_1, a_2, ..., a_n. For the one move you can choose any even value c and divide by two all elements that equal c. For example, if a=[6,8,12,6,3,12] and you choose c=6, and a is transformed into a=[3,8,12,3,3,12] after the m...
{"inputs": ["4\n6\n22 3 32 3 20 1\n1\n94\n4\n3 4 8 30\n2\n3 1 7\n", "4\n6\n22 6 18 5 20 1\n1\n311\n4\n2 4 8 16\n3\n3 1 7\n", "4\n6\n22 4 18 5 20 1\n1\n311\n4\n2 4 8 16\n3\n3 1 7\n", "4\n6\n37 6 40 3 20 1\n1\n757\n4\n2 6 8 16\n3\n3 1 7\n", "4\n6\n37 6 40 3 20 1\n1\n757\n4\n2 6 8 20\n3\n3 1 7\n", "4\n6\n40 8 40 3 20 1\n1...
coding
582
Solve the programming task below in a Python markdown code block. ~~~if-not:java You have to code a function **getAllPrimeFactors** wich take an integer as parameter and return an array containing its prime decomposition by ascending factors, if a factors appears multiple time in the decomposition it should appear as m...
{"functional": "_inputs = [[10], [100], [1000], [1000001], [0], [1], [2], ['a'], [1.1], [-1]]\n_outputs = [[[2, 5]], [[2, 2, 5, 5]], [[2, 2, 2, 5, 5, 5]], [[101, 9901]], [[]], [[1]], [[2]], [[]], [[]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur...
coding
671
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given a 2D integer array descriptions where descriptions[i] = [parenti, childi, isLefti] indicates that parenti is the parent of childi in a binary tree of unique values. Furthermore, If isLefti == 1, then ch...
{"functional": "def check(candidate):\n assert is_same_tree(candidate(descriptions = [[20,15,1],[20,17,0],[50,20,1],[50,80,0],[80,19,1]]), tree_node([50,20,80,15,17,19]))\n assert is_same_tree(candidate(descriptions = [[1,2,1],[2,3,0],[3,4,1]]), tree_node([1,2,None,None,3,4]))\n\n\ncheck(Solution().createBinaryTr...
coding
213
Solve the programming task below in a Python markdown code block. Everybody know that you passed to much time awake during night time... Your task here is to define how much coffee you need to stay awake after your night. You will have to complete a function that take an array of events in arguments, according to thi...
{"functional": "_inputs = [[[]], [['cw']], [['CW']], [['cw', 'CAT']], [['cw', 'CAT', 'DOG']], [['cw', 'CAT', 'cw=others']]]\n_outputs = [[0], [1], [2], [3], ['You need extra sleep'], [3]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b,...
coding
238
Solve the programming task below in a Python markdown code block. President of Berland has a very vast office-room, where, apart from him, work his subordinates. Each subordinate, as well as President himself, has his own desk of a unique colour. Each desk is rectangular, and its sides are parallel to the office walls....
{"inputs": ["1 1 C\nC\n", "2 2 W\nKW\nKW\n", "2 2 W\nKW\nKX\n", "2 2 W\nKW\nLW\n", "2 2 W\nKV\nLW\n", "3 2 W\nOO\nWW\nWW\n", "3 3 U\nUOO\nUVV\nUVV\n", "1 10 H\n....DDHHHH\n"], "outputs": ["0\n", "1\n", "2\n", "2\n", "2\n", "1\n", "2\n", "1\n"]}
coding
351
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is an undirected graph with n nodes numbered from 0 to n - 1 (inclusive). You are given a 0-indexed integer array values where values[i] is the value of the ith node. You are also given a 0-indexed 2D integer ar...
{"functional": "def check(candidate):\n assert candidate(values = [0,32,10,43], edges = [[0,1,10],[1,2,15],[0,3,10]], maxTime = 49) == 75\n assert candidate(values = [5,10,15,20], edges = [[0,1,10],[1,2,10],[0,3,10]], maxTime = 30) == 25\n assert candidate(values = [1,2,3,4], edges = [[0,1,10],[1,2,11],[2,3,12...
coding
272
Solve the programming task below in a Python markdown code block. Little Elephant loves magic squares very much. A magic square is a 3 × 3 table, each cell contains some positive integer. At that the sums of integers in all rows, columns and diagonals of the table are equal. The figure below shows the magic square, th...
{"inputs": ["0 1 1\n1 0 1\n1 1 0\n", "0 3 6\n5 0 5\n4 7 0\n", "0 4 4\n4 0 4\n4 4 0\n", "0 7 6\n9 0 1\n4 3 0\n", "0 9 2\n3 0 7\n8 1 0\n", "0 4 4\n4 0 4\n4 4 0\n", "0 9 2\n3 0 7\n8 1 0\n", "0 7 6\n9 0 1\n4 3 0\n"], "outputs": ["1 1 1\n1 1 1\n1 1 1\n", "6 3 6\n5 5 5\n4 7 4\n", "4 4 4\n4 4 4\n4 4 4\n", "2 7 6\n9 5 1\n4 3 8...
coding
494
Solve the programming task below in a Python markdown code block. _This kata is based on [Project Euler Problem 546](https://projecteuler.net/problem=546)_ # Objective Given the recursive sequence fk(n) = ∑ i = 0 n fk(floor(i / k)) where fk(0) = 1 Define a function `f` that takes arguments `k` and `n` and ...
{"functional": "_inputs = [[2, 3], [2, 200], [2, 1000], [7, 500], [100, 0], [3, 50000], [97, 100000], [100, 500000]]\n_outputs = [[6], [7389572], [264830889564], [74845], [1], [80887845303700596855], [209497156], [21469002551]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, fl...
coding
284
Solve the programming task below in a Python markdown code block. Takahashi participated in a contest on AtCoder. The contest had N problems. Takahashi made M submissions during the contest. The i-th submission was made for the p_i-th problem and received the verdict S_i (AC or WA). The number of Takahashi's correct an...
{"inputs": ["1 0", "2 0", "0 0", "8 0", "3 0", "7 0", "6 0", "6 0\n"], "outputs": ["0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0", "0 0\n"]}
coding
366
Solve the programming task below in a Python markdown code block. Charlie and Johnny play a game. For every integer $\mbox{X}$ Charlie gives, Johnny has to find the smallest positive integer $\mathbf{Y}$ such that $X\times Y$ ($\mbox{X}$ multiplied by $\mathbf{Y}$) contains only 4s and 0s and starts with one or more 4s...
{"inputs": ["3\n4\n5\n80\n"], "outputs": ["2\n3\n4\n"]}
coding
463
Please solve the programming task below using a self-contained code snippet in a markdown code block. There is a special square room with mirrors on each of the four walls. Except for the southwest corner, there are receptors on each of the remaining corners, numbered 0, 1, and 2. The square room has walls of length p...
{"functional": "def check(candidate):\n assert candidate(p = 2, q = 1) == 2\n\n\ncheck(Solution().mirrorReflection)"}
coding
161
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given four integer arrays nums1, nums2, nums3, and nums4 all of length n, return the number of tuples (i, j, k, l) such that: 0 <= i, j, k, l < n nums1[i] + nums2[j] + nums3[k] + nums4[l] == 0   Please complete the ...
{"functional": "def check(candidate):\n assert candidate(nums1 = [1,2], nums2 = [-2,-1], nums3 = [-1,2], nums4 = [0,2]) == 2\n assert candidate(nums1 = [0], nums2 = [0], nums3 = [0], nums4 = [0]) == 1\n\n\ncheck(Solution().fourSumCount)"}
coding
141
Solve the programming task below in a Python markdown code block. There are N sweets in the store. The cost of the i^{th} sweet is A_{i} rupees. Chef is a regular customer, so after buying the i^{th} sweet, he gets a cashback of B_{i} rupees. Chef has R rupees. He is fond of all the sweets, so he wants you to calculat...
{"inputs": ["3\n3 3\n2 3 4\n1 1 1\n2 4\n5 4\n1 2\n4 10\n4 4 5 5\n1 2 4 2"], "outputs": ["2\n1\n7\n"]}
coding
526
Solve the programming task below in a Python markdown code block. It's well known that the best way to distract from something is to do one's favourite thing. Job is such a thing for Leha. So the hacker began to work hard in order to get rid of boredom. It means that Leha began to hack computers all over the world. Fo...
{"inputs": ["2 4\n1 2 1\n2 3 2\n", "2 2\n1 1 1\n1 1 1\n", "2 2\n2 2 1\n3 3 2\n", "2 4\n1 2 5\n1 3 5\n", "2 4\n1 2 5\n1 3 5\n", "2 2\n1 1 1\n1 1 1\n", "2 2\n2 2 1\n3 3 2\n", "2 4\n1 2 1\n2 3 2\n"], "outputs": ["-1\n", "-1\n", "3\n", "-1\n", "-1", "-1", "3", "-1"]}
coding
617
Solve the programming task below in a Python markdown code block. # # Task: * #### Complete the pattern, using the special character ```■ □``` * #### In this kata, we draw some histogram of the sound performance of ups and downs. # # Rules: - parameter ```waves``` The value of sound waves, an array of number...
{"functional": "_inputs = [[[1, 2, 3, 4]], [[1, 2, 3, 3, 2, 1]], [[1, 2, 3, 3, 2, 1, 1, 2, 3, 4, 5, 6, 7]], [[5, 3, 1, 2, 4, 6, 5, 4, 2, 3, 5, 2, 1]], [[1, 0, 1, 0, 1, 0, 1, 0]]]\n_outputs = [['\u25a1\u25a1\u25a1\u25a0\\n\u25a1\u25a1\u25a0\u25a0\\n\u25a1\u25a0\u25a0\u25a0\\n\u25a0\u25a0\u25a0\u25a0'], ['\u25a1\u25a1\u2...
coding
476
Solve the programming task below in a Python markdown code block. Mike and Joe are playing a game with some stones. Specifically, they have $n$ piles of stones of sizes $a_1, a_2, \ldots, a_n$. These piles are arranged in a circle. The game goes as follows. Players take turns removing some positive number of stones fr...
{"inputs": ["1\n1\n1\n", "1\n1\n1000000000\n", "2\n1\n37\n2\n100 100\n", "1\n2\n1000000000 999999999\n", "1\n50\n260939408 52936453 298470524 981491199 699765 834662291 553329721 651730905 665925345 395625534 162042985 788733611 54572656 795877605 826562363 882540598 190947839 644851021 335204703 226590818 150893107 90...
coding
408
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an array nums​​​ and an integer k​​​​​. The XOR of a segment [left, right] where left <= right is the XOR of all the elements with indices between left and right, inclusive: nums[left] XOR nums[left+1] X...
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,0,3,0], k = 1) == 3\n assert candidate(nums = [3,4,5,2,1,7,3,4,7], k = 3) == 3\n assert candidate(nums = [1,2,4,1,2,5,1,2,6], k = 3) == 3\n\n\ncheck(Solution().minChanges)"}
coding
142
Solve the programming task below in a Python markdown code block. I've got a crazy mental illness. I dislike numbers a lot. But it's a little complicated: The number I'm afraid of depends on which day of the week it is... This is a concrete description of my mental illness: Monday --> 12 Tuesday --> numbers gr...
{"functional": "_inputs = [['Monday', 13], ['Monday', 12], ['Tuesday', 0], ['Tuesday', 100], ['Tuesday', 95], ['Wednesday', 35], ['Wednesday', 34], ['Thursday', 2], ['Thursday', 0], ['Friday', 5], ['Friday', 4], ['Saturday', 55], ['Saturday', 56], ['Sunday', 55], ['Sunday', 666], ['Sunday', -666]]\n_outputs = [[False],...
coding
182
Solve the programming task below in a Python markdown code block. A palindrome is a word, phrase, number, or other sequence of characters which reads the same backward as forward. Examples of numerical palindromes are: 2332 110011 54322345 For this kata, single digit numbers will not be considered numerical palindro...
{"functional": "_inputs = [[868], [1321], [1215], [2], [123322367], [1551], [13598], ['ACCDDCCA'], ['1551'], [-4505], [22.22]]\n_outputs = [[True], [False], [True], [False], [True], [True], [False], ['Not valid'], ['Not valid'], ['Not valid'], ['Not valid']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstanc...
coding
256
Solve the programming task below in a Python markdown code block. You are given an array $a_1, a_2, \dots , a_n$, which is sorted in non-decreasing order ($a_i \le a_{i + 1})$. Find three indices $i$, $j$, $k$ such that $1 \le i < j < k \le n$ and it is impossible to construct a non-degenerate triangle (a triangle wi...
{"inputs": ["1\n6\n1 1 1 2 2 3\n", "1\n6\n1 1 1 2 2 3\n", "1\n6\n1 1 1 2 3 3\n", "1\n3\n21 78868 80000\n", "1\n3\n21 78868 80000\n", "1\n3\n39 78868 80000\n", "1\n3\n41 78868 80000\n", "1\n3\n11 78868 80000\n"], "outputs": ["1 2 6\n", "1 2 6\n", "1 2 6\n", "1 2 3\n", "1 2 3\n", "1 2 3\n", "1 2 3\n", "1 2 3\n"]}
coding
554
Solve the programming task below in a Python markdown code block. In a small town the population is `p0 = 1000` at the beginning of a year. The population regularly increases by `2 percent` per year and moreover `50` new inhabitants per year come to live in the town. How many years does the town need to see its popula...
{"functional": "_inputs = [[1500, 5, 100, 5000], [1500000, 2.5, 10000, 2000000], [1500000, 0.25, 1000, 2000000], [1500000, 0.25, -1000, 2000000], [1500000, 0.25, 1, 2000000], [1500000, 0.0, 10000, 2000000]]\n_outputs = [[15], [10], [94], [151], [116], [50]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance...
coding
454
Solve the programming task below in a Python markdown code block. Heidi the Cow is aghast: cracks in the northern Wall? Zombies gathering outside, forming groups, preparing their assault? This must not happen! Quickly, she fetches her HC^2 (Handbook of Crazy Constructions) and looks for the right chapter: How to build...
{"inputs": ["5 1\n", "2 2\n", "3 2\n", "1 1\n", "1 1\n", "2 1\n", "3 4\n", "3 1\n"], "outputs": ["5\n", "5\n", "9\n", "1\n", "1\n", "2\n", "34\n", "3\n"]}
coding
505
Solve the programming task below in a Python markdown code block. Rohit was doing the work of his math class about three days but he is tired of make operations a lot and he should deliver his task tomorrow. His math’s teacher gives two numbers a and b. The problem consist in find the last digit of the potency of base ...
{"inputs": ["5\n19021463561276851735171355238976350962817489980593657752206579555021148207736012355943198456853373185208340964575628990983191088521799365137969929935263986287756454173080642274585186167796948331561682 8017\n4565194923754350257539737098390625395160137517839262785449977071416145818084360997843473461107344...
coding
228
Solve the programming task below in a Python markdown code block. Vasya often uses public transport. The transport in the city is of two types: trolleys and buses. The city has n buses and m trolleys, the buses are numbered by integers from 1 to n, the trolleys are numbered by integers from 1 to m. Public transport is...
{"inputs": ["4 4 4 1\n1 1\n0\n0\n", "4 4 4 1\n1 1\n0\n0\n", "4 3 2 1\n1 3\n798\n1 2 3\n", "1 1 3 4\n2 3\n1 1\n1 1 1\n", "1 1 3 4\n2 3\n1 1\n1 1 1\n", "4 3 1 1\n1 3\n798\n1 2 3\n", "1 2 3 4\n2 3\n1 1\n1 1 1\n", "4 3 1 1\n1 3\n798\n2 2 3\n"], "outputs": ["0\n", "0", "1\n", "4\n", "4", "1\n", "4\n", "1\n"]}
coding
660
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given two strings s and part, perform the following operation on s until all occurrences of the substring part are removed: Find the leftmost occurrence of the substring part and remove it from s. Return s after rem...
{"functional": "def check(candidate):\n assert candidate(s = \"daabcbaabcbc\", part = \"abc\") == \"dab\"\n assert candidate(s = \"axxxxyyyyb\", part = \"xy\") == \"ab\"\n\n\ncheck(Solution().removeOccurrences)"}
coding
110
Please solve the programming task below using a self-contained code snippet in a markdown code block. There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend fo...
{"functional": "def check(candidate):\n assert candidate(n = 5, k = 2) == 3\n assert candidate(n = 6, k = 5) == 1\n\n\ncheck(Solution().findTheWinner)"}
coding
251
Solve the programming task below in a Python markdown code block. You can find anything whatsoever in our Galaxy! A cubical planet goes round an icosahedral star. Let us introduce a system of axes so that the edges of the cubical planet are parallel to the coordinate axes and two opposite vertices lay in the points (0,...
{"inputs": ["1 0 0\n0 0 0\n", "1 1 0\n0 0 1\n", "1 1 1\n0 1 1\n", "0 0 1\n1 0 0\n", "1 1 1\n0 0 0\n", "1 0 0\n0 1 0\n", "1 0 0\n0 1 1\n", "0 0 1\n1 0 1\n"], "outputs": ["YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "NO\n", "YES\n"]}
coding
254
Solve the programming task below in a Python markdown code block. Two pirates Polycarpus and Vasily play a very interesting game. They have n chests with coins, the chests are numbered with integers from 1 to n. Chest number i has a_{i} coins. Polycarpus and Vasily move in turns. Polycarpus moves first. During a move...
{"inputs": ["1\n1\n", "1\n2\n", "1\n1\n", "1\n546\n", "1\n546\n", "1\n641\n", "1\n1151\n", "3\n1 2 3\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "3\n"]}
coding
447
Solve the programming task below in a Python markdown code block. Princess Artapoelc greeted her guests by either kissing on the cheek (K) or hugging (H). From the first guest she kisses, she has a compulsion to necessarily kiss every alternate guest from that first kissed guest. That is if the guests are G_{1}, G_...
{"inputs": ["3\n1\n2\n3"], "outputs": ["2\n4\n6"]}
coding
337
Solve the programming task below in a Python markdown code block. You are playing one RPG from the 2010s. You are planning to raise your smithing skill, so you need as many resources as possible. So how to get resources? By stealing, of course. You decided to rob a town's blacksmith and you take a follower with you. Y...
{"inputs": ["1\n8 7\n2 4\n7 3\n", "1\n8 7\n2 4\n7 3\n", "1\n8 7\n2 4\n2 3\n", "1\n8 7\n3 4\n2 3\n", "1\n15 10\n200000 4\n15 1000000000\n", "1\n15 10\n200000 4\n15 1000000000\n", "1\n13 10\n200000 4\n15 1000000000\n", "1\n13 10\n200000 4\n15 1000001000\n"], "outputs": ["4\n", "4\n", "5\n", "6\n", "1\n", "1\n", "0\n", "0...
coding
668
Solve the programming task below in a Python markdown code block. Implement a function that adds two numbers together and returns their sum in binary. The conversion can be done before, or after the addition. The binary number returned should be a string. Also feel free to reuse/extend the following starter code: ```p...
{"functional": "_inputs = [[1, 1], [0, 1], [1, 0], [2, 2], [51, 12], [5, 9], [10, 10], [100, 100], [4096, 1], [0, 2174483647]]\n_outputs = [['10'], ['1'], ['1'], ['100'], ['111111'], ['1110'], ['10100'], ['11001000'], ['1000000000001'], ['10000001100110111111110010111111']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n...
coding
71
Solve the programming task below in a Python markdown code block. -----Input----- The only line of the input is a string of 7 characters. The first character is letter A, followed by 6 digits. The input is guaranteed to be valid (for certain definition of "valid"). -----Output----- Output a single integer. -----E...
{"inputs": ["A221033\n", "A223635\n", "A232726\n", "A102210\n", "A231010\n", "A222222\n", "A555555\n", "A102222\n"], "outputs": ["21\n", "22\n", "23\n", "25\n", "26\n", "13\n", "31\n", "19\n"]}
coding
114
Solve the programming task below in a Python markdown code block. Write a function called "filterEvenLengthWords". Given an array of strings, "filterEvenLengthWords" returns an array containing only the elements of the given array whose length is an even number. var output = filterEvenLengthWords(['word', 'words', 'w...
{"functional": "_inputs = [[['Hello', 'World']], [['One', 'Two', 'Three', 'Four']]]\n_outputs = [[[]], [['Four']]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n ...
coding
107
Please solve the programming task below using a self-contained code snippet in a markdown code block. A message containing letters from A-Z can be encoded into numbers using the following mapping: 'A' -> "1" 'B' -> "2" ... 'Z' -> "26" To decode an encoded message, all the digits must be grouped then mapped back into...
{"functional": "def check(candidate):\n assert candidate(s = \"*\") == 9\n assert candidate(s = \"1*\") == 18\n assert candidate(s = \"2*\") == 15\n\n\ncheck(Solution().numDecodings)"}
coding
350
Solve the programming task below in a Python markdown code block. *CodeChef recently revamped its [practice page] to make it easier for users to identify the next problems they should solve by introducing some new features:* *Recent Contest Problems - Contains only problems from the last 2 contests* *Separate Un-Attemp...
{"inputs": ["4\n3\nSTART38 LTIME108 START38\n4\nLTIME108 LTIME108 LTIME108 START38\n2\nLTIME108 LTIME108\n6\nSTART38 LTIME108 LTIME108 LTIME108 START38 LTIME108\n"], "outputs": ["2 1\n1 3\n0 2\n2 4\n"]}
coding
666
Solve the programming task below in a Python markdown code block. Your task is to construct a building which will be a pile of n cubes. The cube at the bottom will have a volume of n^3, the cube above will have volume of (n-1)^3 and so on until the top which will have a volume of 1^3. You are given the total volume ...
{"functional": "_inputs = [[4183059834009], [24723578342962], [135440716410000], [40539911473216], [26825883955641], [41364076483082], [9541025211025], [112668204662785], [79172108332642], [1788719004901], [131443152397956], [1801879360282], [18262169777476], [11988186060816], [826691919076], [36099801072722], [1718143...
coding
239
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer array matches where matches[i] = [winneri, loseri] indicates that the player winneri defeated player loseri in a match. Return a list answer of size 2 where: answer[0] is a list of all player...
{"functional": "def check(candidate):\n assert candidate(matches = [[1,3],[2,3],[3,6],[5,6],[5,7],[4,5],[4,8],[4,9],[10,4],[10,9]]) == [[1,2,10],[4,5,7,8]]\n assert candidate(matches = [[2,3],[1,3],[5,4],[6,4]]) == [[1,2,5,6],[]]\n\n\ncheck(Solution().findWinners)"}
coding
175
Solve the programming task below in a Python markdown code block. You are given a sequence of $n$ integers $a_1, \, a_2, \, \dots, \, a_n$. Does there exist a sequence of $n$ integers $b_1, \, b_2, \, \dots, \, b_n$ such that the following property holds? For each $1 \le i \le n$, there exist two (not necessarily dis...
{"inputs": ["1\n2\n1 1\n", "1\n2\n1 1\n", "1\n2\n2 1\n", "1\n2\n2 2\n", "1\n2\n0 1\n", "1\n2\n2 3\n", "1\n2\n1 2\n", "1\n2\n0 2\n"], "outputs": ["YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n", "YES\n"]}
coding
616
Solve the programming task below in a Python markdown code block. Eugene loves sequences, especially arithmetic progressions. One day he was asked to solve a difficult problem. If a sequence of numbers A1, A2, ... , AN form an arithmetic progression A, he was asked to calculate sum of F(Ai), for L ≤ i ≤ R. F(X) is def...
{"inputs": ["2\n1 1 1 3\n14 7 2 4\n\n"], "outputs": ["6\n12"]}
coding
652
Solve the programming task below in a Python markdown code block. King Arthur has a large kingdom that can be represented as a tree, where nodes correspond to cities and edges correspond to the roads between cities. The kingdom has a total of $n$ cities numbered from $\mbox{1}$ to $n$. The King wants to divide his ki...
{"inputs": ["5\n1 2\n1 3\n3 4\n3 5\n"], "outputs": ["4\n"]}
coding
531
Solve the programming task below in a Python markdown code block. Given the participants' score sheet for your University Sports Day, you are required to find the runner-up score. You are given $n$ scores. Store them in a list and find the score of the runner-up. Input Format The first line contains $n$. The second ...
{"inputs": ["5\n2 3 6 6 5\n"], "outputs": ["5\n"]}
coding
213
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are given an integer n. A perfectly straight street is represented by a number line ranging from 0 to n - 1. You are given a 2D integer array lights representing the street lamp(s) on the street. Each lights[i] = ...
{"functional": "def check(candidate):\n assert candidate(n = 5, lights = [[0,1],[2,1],[3,2]], requirement = [0,2,1,4,1]) == 4\n assert candidate(n = 1, lights = [[0,1]], requirement = [2]) == 0\n\n\ncheck(Solution().meetRequirement)"}
coding
238
Solve the programming task below in a Python markdown code block. Let’s get to know our hero: Agent #134 - Mr. Slayer. He was sent by his CSV agency to Ancient Rome in order to resolve some important national issues. However, something incredible has happened - the enemies have taken Julius Caesar as a prisoner!!! Ca...
{"functional": "_inputs = [['123,.)(!?', 10], ['', 10], [None, 10], [' ', 10], ['Hello world!', 127], ['eBIIL TLOIA!', -127], ['ksdjai8983hdk?}{', 15], ['Hello world!', 0]]\n_outputs = [['123,.)(!?'], [''], [''], [''], ['eBIIL TLOIA!'], ['Hello world!'], ['zHsypx8983wsz?}{'], ['Hello world!']]\nimport math\ndef _deep...
coding
278
Solve the programming task below in a Python markdown code block. You are given $n$ strings. Each string consists of lowercase English letters. Rearrange (reorder) the given strings in such a way that for every string, all strings that are placed before it are its substrings. String $a$ is a substring of string $b$ if...
{"inputs": ["2\na\nb\n", "2\na\nb\n", "2\na\nc\n", "2\n`\nc\n", "2\nq\nqq\n", "2\nq\nqq\n", "2\nq\npq\n", "2\nr\npq\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "YES\nq\nqq\n", "YES\nq\nqq\n", "YES\nq\npq\n", "NO\n"]}
coding
376
Solve the programming task below in a Python markdown code block. Create a function that checks if a number `n` is divisible by two numbers `x` **AND** `y`. All inputs are positive, non-zero digits. ```JS Examples: 1) n = 3, x = 1, y = 3 => true because 3 is divisible by 1 and 3 2) n = 12, x = 2, y = 6 => true ...
{"functional": "_inputs = [[3, 2, 2], [3, 3, 4], [12, 3, 4], [8, 3, 4], [48, 3, 4], [100, 5, 10], [100, 5, 3], [4, 4, 2], [5, 2, 3], [17, 17, 17], [17, 1, 17]]\n_outputs = [[False], [False], [True], [False], [True], [True], [False], [True], [False], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if is...
coding
213
Please solve the programming task below using a self-contained code snippet in a markdown code block. Given a two-dimensional graph with points on it, find a line which passes the most number of points. Assume all the points that passed by the line are stored in list S sorted by their number. You need to return [S[0],...
{"functional": "def check(candidate):\n assert candidate([[0,0],[1,1],[1,0],[2,0]]) == [0,2]\n\n\ncheck(Solution().bestLine)"}
coding
166
Solve the programming task below in a Python markdown code block. This year $p$ footballers and $q$ cricketers have been invited to participate in IPL (Indian Programming League) as guests. You have to accommodate them in $r$ rooms such that- - No room may remain empty. - A room may contain either only footballers or o...
{"inputs": ["4\n2 1 4\n2 4 4\n2 5 4\n2 8 4"], "outputs": ["0\n3\n10\n609"]}
coding
479
Solve the programming task below in a Python markdown code block. You are given two positive integers A and B. Compare the magnitudes of these numbers. -----Constraints----- - 1 ≤ A, B ≤ 10^{100} - Neither A nor B begins with a 0. -----Input----- Input is given from Standard Input in the following format: A B ----...
{"inputs": ["36\n2", "36\n3", "36\n6", "36\n5", "36\n7", "36\n0", "36\n16", "36\n36"], "outputs": ["GREATER\n", "GREATER\n", "GREATER\n", "GREATER\n", "GREATER\n", "GREATER\n", "GREATER\n", "EQUAL\n"]}
coding
128
Solve the programming task below in a Python markdown code block. Ksusha is a beginner coder. Today she starts studying arrays. She has array a_1, a_2, ..., a_{n}, consisting of n positive integers. Her university teacher gave her a task. Find such number in the array, that all array elements are divisible by it. Help...
{"inputs": ["2\n4 6\n", "2\n6 8\n", "2\n6 4\n", "2\n6 4\n", "2\n4 6\n", "2\n6 8\n", "2\n6 3\n", "2\n6 6\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n", "3\n", "6\n"]}
coding
245
Solve the programming task below in a Python markdown code block. Chef wants to appear in a competitive exam. To take the exam, there are following requirements: Minimum age limit is X (i.e. Age should be greater than or equal to X). Age should be strictly less than Y. Chef's current Age is A. Find whether he is curr...
{"inputs": ["5\n21 34 30\n25 31 31\n22 29 25\n20 40 15\n28 29 28\n"], "outputs": ["YES\nNO\nYES\nNO\nYES\n"]}
coding
523
Solve the programming task below in a Python markdown code block. A positive integer may be expressed as a sum of different prime numbers (primes), in one way or another. Given two positive integers n and k, you should count the number of ways to express n as a sum of k different primes. Here, two ways are considered t...
{"inputs": ["6 3\n24 2\n2 1\n1 1\n4 2\n18 3\n17 1\n17 3\n9 4\n110 5\n1000 1\n980 3\n0 0", "24 6\n15 2\n2 2\n1 1\n6 2\n5 1\n17 2\n24 2\n5 4\n100 2\n1000 3\n680 4\n0 0", "34 3\n24 2\n2 1\n1 1\n4 2\n18 3\n17 1\n17 3\n9 4\n110 5\n1000 1\n980 3\n0 0", "34 6\n24 2\n2 2\n1 1\n4 2\n18 3\n17 1\n17 3\n5 4\n110 5\n1000 1\n715 3\n...
coding
561
Solve the programming task below in a Python markdown code block. Chef has N candies. He has to distribute them to exactly M of his friends such that each friend gets equal number of candies and each friend gets even number of candies. Determine whether it is possible to do so. NOTE: Chef will not take any candies him...
{"inputs": ["4\n9 3\n4 1\n4 2\n8 3"], "outputs": ["No\nYes\nYes\nNo"]}
coding
449
Solve the programming task below in a Python markdown code block. You are currently studying the language $A j o b$ ( which means strange in English ) from a renowned professor. The language has infinite number of letters in its alphabet ( now you know, why it is called ajob ). The professor taught you $N$ words, on...
{"inputs": ["3\n2 1 2\n2 1 5\n5 3 13\n", "5\n5 2 3\n6 5 11\n7 6 3\n6 5 7\n6 5 5\n"], "outputs": ["1\n3\n2\n", "2\n7\n2\n0\n2\n"]}
coding
571
Solve the programming task below in a Python markdown code block. Write a method `alternate_sq_sum()` (JS: `alternateSqSum` ) that takes an array of integers as input and finds the sum of squares of the elements at even positions (*i.e.,* 2nd, 4th, *etc.*) plus the sum of the rest of the elements at odd position. NOTE...
{"functional": "_inputs = [[[]], [[-1, 0, -3, 0, -5, 3]], [[-1, 2, -3, 4, -5]], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]]]\n_outputs = [[0], [0], [11], [245]]\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 is...
coding
394
Solve the programming task below in a Python markdown code block. Let's define a good tree:It is a tree with k * n nodes labeled from 0 to k * n - 1 Node i and node j are not adjacent, for all 0 ≤ i, j < k * n such that i div k = j div k (here div means integer division. E.g. 7 div 2 = 3) Given n and k, how many diff...
{"inputs": ["1 3", "1 1", "2 3", "2 5", "3 3", "2 6", "6 3", "2 8"], "outputs": ["0\n", "1\n", "81\n", "390625\n", "419904\n", "60466176\n", "64489703\n", "46480318\n"]}
coding
245
Solve the programming task below in a Python markdown code block. Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Doraemon has a matrix with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Let's denote the element in row $i$ and co...
{"inputs": ["1\n3 3\n2 1 2\n1 1 1\n2 1 2"], "outputs": ["10"]}
coding
661
Solve the programming task below in a Python markdown code block. Demiurges Shambambukli and Mazukta love to watch the games of ordinary people. Today, they noticed two men who play the following game. There is a rooted tree on n nodes, m of which are leaves (a leaf is a nodes that does not have any children), edges o...
{"inputs": ["1\n", "1\n", "2\n1 2\n", "2\n1 2\n", "3\n1 2\n1 3\n", "3\n1 2\n1 3\n", "3\n1 2\n2 3\n", "5\n1 2\n1 3\n2 4\n2 5\n"], "outputs": ["1 1\n", "1 1", "1 1\n", "1 1", "2 2\n", "2 2", "1 1\n", "3 2\n"]}
coding
649
Solve the programming task below in a Python markdown code block. How can you tell an extrovert from an introvert at NSA? Va gur ryringbef, gur rkgebireg ybbxf ng gur BGURE thl'f fubrf. I found this joke on USENET, but the punchline is scrambled. Maybe you can decipher it? According to Wikipedia, ROT13 (http://en.wiki...
{"functional": "_inputs = [['EBG13 rknzcyr.'], [\"How can you tell an extrovert from an\\nintrovert at NSA? Va gur ryringbef,\\ngur rkgebireg ybbxf ng gur BGURE thl'f fubrf.\"], ['123'], ['Guvf vf npghnyyl gur svefg xngn V rire znqr. Gunaxf sbe svavfuvat vg! :)'], ['@[`{']]\n_outputs = [['ROT13 example.'], [\"Ubj pna l...
coding
215
Solve the programming task below in a Python markdown code block. The only difference between the easy and hard versions is that tokens of type O do not appear in the input of the easy version. Errichto gave Monogon the following challenge in order to intimidate him from taking his top contributor spot on Codeforces. ...
{"inputs": ["1\n6\nXXXXXX\nXXXXXX\nXX..XX\nXX..XX\nXXXXXX\nXXXXXX\n", "3\n3\n.O.\nOOO\n.O.\n6\nXXXOOO\nXXXOOO\nXX..OO\nOO..XX\nOOOXXX\nOOOXXX\n5\n.OOO.\nOXXXO\nOXXXO\nOXXXO\n.OOO.\n", "3\n3\n.X.\nXXX\n.X.\n6\nXX.XXX\nXXXXXX\nXXX.XX\nXXXXXX\nXX.X.X\nXXXXXX\n5\nXXX.X\n.X..X\nXXX.X\n..X..\n..X..\n"], "outputs": ["XXOXXO\n...
coding
682
Solve the programming task below in a Python markdown code block. Ania has a large integer $S$. Its decimal representation has length $n$ and doesn't contain any leading zeroes. Ania is allowed to change at most $k$ digits of $S$. She wants to do it in such a way that $S$ still won't contain any leading zeroes and it'l...
{"inputs": ["1 1\n1\n", "1 0\n1\n", "1 1\n0\n", "1 0\n0\n", "1 0\n7\n", "1 1\n9\n", "1 1\n5\n", "1 1\n2\n"], "outputs": ["0\n", "1\n", "0\n", "0\n", "7\n", "0\n", "0\n", "0\n"]}
coding
344
Solve the programming task below in a Python markdown code block. Your friend won't stop texting his girlfriend. It's all he does. All day. Seriously. The texts are so mushy too! The whole situation just makes you feel ill. Being the wonderful friend that you are, you hatch an evil plot. While he's sleeping, you tak...
{"functional": "_inputs = [['I miss you!'], ['u want to go to the movies?'], [\"Can't wait to see youuuuu\"], ['I want to film the bayou with you and put it on youtube'], ['You should come over Friday night'], ['You u youville utube you youyouyou uuu raiyou united youuuu u you']]\n_outputs = [['I miss your sister!'], [...
coding
261
Solve the programming task below in a Python markdown code block. -----General Statement:----- Read a number in scientific notation and output its equivalent decimal value. -----Input:----- All data is on a single line. The first integer indicates how many pairs of numbers follow. The first of each pair is A, the base...
{"inputs": ["4 4.296 3 3.8 -2 1.8 2 2.8678 1"], "outputs": ["4296.00\n0.04\n180.00\n28.68"]}
coding
293
Solve the programming task below in a Python markdown code block. Mance Rayder, the King-Beyond-the-Wall, has always wanted to lead the largest army the North has ever seen against the NIght’s Watch. For this humungous feat he has banded the waring tribes, the Giants, Thenns and Wildings, together by going to great ext...
{"inputs": ["1\n1 2 1"], "outputs": ["Yes"]}
coding
384
Solve the programming task below in a Python markdown code block. The medians of a triangle are the segments that unit the vertices with the midpoint of their opposite sides. The three medians of a triangle intersect at the same point, called the barycenter or the centroid. Given a triangle, defined by the cartesian co...
{"functional": "_inputs = [[[4, 6], [12, 4], [10, 10]], [[4, 2], [12, 2], [6, 10]], [[4, 8], [8, 2], [16, 6]]]\n_outputs = [[[8.6667, 6.6667]], [[7.3333, 4.6667]], [[9.3333, 5.3333]]]\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...
coding
355
Please solve the programming task below using a self-contained code snippet in a markdown code block. You are in a city that consists of n intersections numbered from 0 to n - 1 with bi-directional roads between some intersections. The inputs are generated such that you can reach any intersection from any other inters...
{"functional": "def check(candidate):\n assert candidate(n = 7, roads = [[0,6,7],[0,1,2],[1,2,3],[1,3,3],[6,3,3],[3,5,1],[6,5,1],[2,5,1],[0,4,5],[4,6,2]]) == 4\n assert candidate(n = 2, roads = [[1,0,10]]) == 1\n\n\ncheck(Solution().countPaths)"}
coding
219
Solve the programming task below in a Python markdown code block. In a Circular City, there are $n$ houses, numbered from 1 to n and arranged in 1,2,...,n,1,2,... Chef needs to deliver packages to $m$ (m≤n) houses. Chef is initially at house 1. Chef decides an integer $x$ and stops after every $x$ houses. i.e- if $n=...
{"inputs": ["6 2\n3 4", "5 3\n1 2 4"], "outputs": ["4", "3"]}
coding
381
Solve the programming task below in a Python markdown code block. Adam Ivan is working as a system administrator at Soy Group, Inc. He is now facing at a big trouble: a number of computers under his management have been infected by a computer virus. Unfortunately, anti-virus system in his company failed to detect this ...
{"inputs": ["3 2\n1 1 3\n2 2 3\n3 2\n2 3 2\n1 2 1\n0 0", "3 2\n1 1 2\n2 2 3\n3 2\n2 3 2\n1 2 0\n0 0", "4 2\n1 0 3\n1 2 3\n3 2\n2 3 2\n2 2 1\n0 0", "3 2\n1 1 3\n1 2 3\n3 2\n2 1 2\n1 2 0\n0 0", "3 2\n1 0 3\n1 2 3\n3 2\n2 1 2\n1 2 0\n0 0", "3 2\n1 1 3\n1 2 3\n3 2\n2 3 2\n1 2 1\n0 0", "3 2\n1 1 3\n1 2 3\n3 2\n3 3 2\n1 2 1\...
coding
464
Solve the programming task below in a Python markdown code block. N persons are standing in a row. The height of the i-th person from the front is A_i. We want to have each person stand on a stool of some heights - at least zero - so that the following condition is satisfied for every person: Condition: Nobody in front...
{"inputs": ["5\n1 3 3 3 3", "5\n2 1 5 8 3", "5\n1 2 3 6 3", "5\n2 1 2 8 4", "5\n4 4 3 6 6", "5\n4 4 3 7 6", "5\n3 1 5 8 3", "5\n0 1 2 8 4"], "outputs": ["0\n", "6\n", "3\n", "5\n", "1\n", "2\n", "7\n", "4\n"]}
coding
279
Solve the programming task below in a Python markdown code block. Sammy and Simmy love candies and frequently visit the local candy shop. Sammy and Simmy have bought $N$ candy packs. Packet $i$ contains $A_{i}$ candies. Sammy being the elder one is happy only if she has strictly more candies than Simmy. However Simmy, ...
{"inputs": ["1 \n2 \n5 2"], "outputs": ["YES"]}
coding
408
Solve the programming task below in a Python markdown code block. There is a street with $n$ houses in a line, numbered from $1$ to $n$. The house $i$ is initially painted in color $c_i$. The street is considered beautiful if all houses are painted in the same color. Tom, the painter, is in charge of making the street ...
{"inputs": ["3\n10 2\n1 1 2 2 1 1 2 2 2 1\n7 1\n1 2 3 4 5 6 7\n10 3\n1 3 3 3 3 1 2 1 3 3\n", "6\n6 4\n2 1 1 1 1 2\n10 5\n1 1 1 2 2 1 2 2 1 1\n9 6\n1 2 3 1 2 3 1 2 3\n1 1\n100\n10 10\n1 100 2 99 3 98 4 97 5 96\n8 1\n50 50 50 50 50 50 50 50\n"], "outputs": ["3\n6\n2\n", "1\n1\n2\n0\n1\n0\n"]}
coding
624
Solve the programming task below in a Python markdown code block. A number is called almost prime if it has exactly two distinct prime divisors. For example, numbers 6, 18, 24 are almost prime, while 4, 8, 9, 42 are not. Find the amount of almost prime numbers which are between 1 and n, inclusive. Input Input contain...
{"inputs": ["1\n", "3\n", "4\n", "8\n", "2\n", "6\n", "5\n", "9\n"], "outputs": ["0\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]}
coding
135