task_type stringclasses 1
value | problem stringlengths 261 3.34k | answer stringlengths 35 6.15k | problem_tokens int64 62 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Solve the programming task below in a Python markdown code block.
You have N items that you want to put them into a knapsack. Item i has value vi and weight wi.
You want to find a subset of items to put such that:
* The total value of the items is as large as possible.
* The items have combined weight at most W, that... | {"inputs": ["2 20\n5 9\n4 0", "2 20\n5 28\n4 8", "2 20\n5 14\n4 8", "2 20\n5 14\n5 8", "2 20\n5 28\n1 8", "2 20\n5 9\n4 10", "2 20\n5 14\n4 10", "2 20\n5 28\n1 10"], "outputs": ["9\n", "4\n", "5\n", "5\n", "1\n", "9", "5\n", "1\n"]} | 256 | 158 |
coding | Solve the programming task below in a Python markdown code block.
Given the number n, find the smallest positive integer which has exactly n divisors. It is guaranteed that for the given n the answer will not exceed 1018.
Input
The first line of the input contains integer n (1 ≤ n ≤ 1000).
Output
Output the smalles... | {"inputs": ["8\n", "7\n", "1\n", "9\n", "2\n", "3\n", "5\n", "6\n"], "outputs": ["24", "64", "1", "36", "2\n", "4\n", "16\n", "12"]} | 102 | 70 |
coding | Solve the programming task below in a Python markdown code block.
Two integer sequences existed initially, one of them was strictly increasing, and another one — strictly decreasing.
Strictly increasing sequence is a sequence of integers $[x_1 < x_2 < \dots < x_k]$. And strictly decreasing sequence is a sequence of in... | {"inputs": ["1\n89\n", "1\n34\n", "1\n63\n", "1\n507\n", "1\n783\n", "1\n165\n", "1\n238\n", "1\n1337\n"], "outputs": ["YES\n1\n", "YES\n1\n", "YES\n1\n", "YES\n1\n", "YES\n1\n", "YES\n1\n", "YES\n1\n", "YES\n1 \n"]} | 719 | 117 |
coding | Solve the programming task below in a Python markdown code block.
A binary string is a string consisting only of the characters 0 and 1. You are given a binary string $s$.
For some non-empty substring$^\dagger$ $t$ of string $s$ containing $x$ characters 0 and $y$ characters 1, define its cost as:
$x \cdot y$, if $x ... | {"inputs": ["1\n7\n0111111\n", "6\n5\n11100\n7\n1100110\n6\n011110\n7\n1001010\n4\n1000\n1\n0\n"], "outputs": ["36\n", "9\n12\n16\n12\n9\n1\n"]} | 692 | 94 |
coding | Solve the programming task below in a Python markdown code block.
## Story
Before we dive into the exercise, I would like to show you why these numbers are so important in computer programming today.
It all goes back to the time of 19th century. Where computers we know today were non-existing. The first ever **comput... | {"functional": "_inputs = [[0], [3], [1337]]\n_outputs = [[1], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n ... | 731 | 172 |
coding | Solve the programming task below in a Python markdown code block.
A sequence a_1,a_2,... ,a_n is said to be /\/\/\/ when the following conditions are satisfied:
* For each i = 1,2,..., n-2, a_i = a_{i+2}.
* Exactly two different numbers appear in the sequence.
You are given a sequence v_1,v_2,...,v_n whose length i... | {"inputs": ["4\n3 2 3 2", "4\n4 1 3 2", "4\n4 1 3 0", "4\n4 1 3 1", "4\n4 1 6 1", "4\n4 0 6 1", "4\n4 0 9 1", "4\n8 0 9 1"], "outputs": ["0\n", "2\n", "2\n", "1\n", "1\n", "2\n", "2\n", "2\n"]} | 273 | 126 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of intervals intervals where intervals[i] = [starti, endi], return the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.
Note that intervals which only to... | {"functional": "def check(candidate):\n assert candidate(intervals = [[1,2],[2,3],[3,4],[1,3]]) == 1\n assert candidate(intervals = [[1,2],[1,2],[1,2]]) == 2\n assert candidate(intervals = [[1,2],[2,3]]) == 0\n\n\ncheck(Solution().eraseOverlapIntervals)"} | 125 | 90 |
coding | Solve the programming task below in a Python markdown code block.
Return a new array consisting of elements which are multiple of their own index in input array (length > 1).
Some cases:
```
[22, -6, 32, 82, 9, 25] => [-6, 32, 25]
[68, -1, 1, -7, 10, 10] => [-1, 10]
[-56,-85,72,-26,-14,76,-27,72,35,-21,-67,87,0,2... | {"functional": "_inputs = [[[22, -6, 32, 82, 9, 25]], [[68, -1, 1, -7, 10, 10]], [[11, -11]], [[-56, -85, 72, -26, -14, 76, -27, 72, 35, -21, -67, 87, 0, 21, 59, 27, -92, 68]], [[28, 38, -44, -99, -13, -54, 77, -51]], [[-1, -49, -1, 67, 8, -60, 39, 35]]]\n_outputs = [[[-6, 32, 25]], [[-1, 10]], [[-11]], [[-85, 72, 0, 6... | 200 | 404 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two integer arrays nums and divisors.
The divisibility score of divisors[i] is the number of indices j such that nums[j] is divisible by divisors[i].
Return the integer divisors[i] with the maximum divis... | {"functional": "def check(candidate):\n assert candidate(nums = [4,7,9,3,9], divisors = [5,2,3]) == 3\n assert candidate(nums = [20,14,21,10], divisors = [5,7,5]) == 5\n assert candidate(nums = [12], divisors = [10,16]) == 10\n\n\ncheck(Solution().maxDivScore)"} | 120 | 106 |
coding | Solve the programming task below in a Python markdown code block.
In some other world, today is Christmas Eve.
There are N trees planted in Mr. Takaha's garden. The height of the i-th tree (1 \leq i \leq N) is h_i meters.
He decides to choose K trees from these trees and decorate them with electric lights. To make the ... | {"inputs": ["3 3\n5\n7\n0\n1\n7", "3 3\n5\n7\n5\n7\n7", "3 3\n5\n7\n5\n1\n7", "3 3\n5\n7\n5\n1\n5", "5 3\n5\n7\n5\n9\n7", "3 3\n5\n7\n5\n7\n6", "5 3\n5\n7\n2\n0\n6", "5 3\n5\n7\n5\n1\n5"], "outputs": ["7\n", "2\n", "2\n", "2\n", "2\n", "2\n", "2\n", "0\n"]} | 334 | 158 |
coding | Solve the programming task below in a Python markdown code block.
Mrs. Smith is trying to contact her husband, John Smith, but she forgot the secret phone number!
The only thing Mrs. Smith remembered was that any permutation of $n$ can be a secret phone number. Only those permutations that minimize secret value might ... | {"inputs": ["4\n", "2\n", "1\n", "3\n", "5\n", "6\n", "7\n", "8\n"], "outputs": ["3 4 1 2\n", "2 1\n", "1\n", "3 2 1\n", "4 5 2 3 1\n", "5 6 3 4 1 2\n", "6 7 4 5 2 3 1\n", "7 8 5 6 3 4 1 2\n"]} | 744 | 126 |
coding | Solve the programming task below in a Python markdown code block.
An array is called beautiful if all the elements in the array are equal.
You can transform an array using the following steps any number of times:
1. Choose two indices i and j (1 ≤ i,j ≤ n), and an integer x (1 ≤ x ≤ a_i). Let i be the source index... | {"inputs": ["3\n0 0 3\n", "3\n0 3 3\n", "3\n0 1 2\n", "3\n0 2 3\n", "3\n1 3 3\n", "3\n0 3 1\n", "3\n0 3 2\n", "3\n0 1 1\n"], "outputs": ["3", "3\n", "6\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 659 | 117 |
coding | Solve the programming task below in a Python markdown code block.
Given is a string S. Let T be the concatenation of K copies of S. We can repeatedly perform the following operation: choose a character in T and replace it with a different character. Find the minimum number of operations required to satisfy the followin... | {"inputs": ["oo\n4", "oo\n7", "rq\n81", "oo\n13", "qq\n81", "rr\n552", "rr\n826", "rr\n757"], "outputs": ["4\n", "7\n", "0\n", "13\n", "81", "552\n", "826\n", "757\n"]} | 208 | 94 |
coding | Solve the programming task below in a Python markdown code block.
You are asked to ensure that the first and last names of people begin with a capital letter in their passports. For example, alison heck should be capitalised correctly as Alison Heck.
$\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\quad\... | {"inputs": ["chris alan\n"], "outputs": ["Chris Alan\n"]} | 641 | 17 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the head of a singly linked list, reverse the list, and return the reversed list.
Please complete the following python code precisely:
```python
# Definition for singly-linked list.
# class ListNode:
# def... | {"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,4,5])), list_node([5,4,3,2,1]))\n assert is_same_list(candidate(head = list_node([1,2])), list_node([2,1]))\n assert is_same_list(candidate(head = list_node([])), list_node([]))\n\n\ncheck(Solution().reverseList)"} | 110 | 97 |
coding | Solve the programming task below in a Python markdown code block.
You've got an array, consisting of n integers a_1, a_2, ..., a_{n}. Also, you've got m queries, the i-th query is described by two integers l_{i}, r_{i}. Numbers l_{i}, r_{i} define a subsegment of the original array, that is, the sequence of numbers a_{... | {"inputs": ["1 1\n6\n1 1\n", "1 1\n6\n1 1\n", "1 1\n7\n1 1\n", "1 1\n5\n1 1\n", "1 1\n2\n1 1\n", "1 1\n3\n1 1\n", "2 5\n1 1\n1 2\n2 2\n2 2\n1 2\n1 2\n", "2 5\n1 1\n1 2\n2 2\n2 2\n1 2\n1 2\n"], "outputs": ["Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\n", "Yes\nYes\nYes\nYes\nYes\n", "Yes\nYes\nYes\nYes\nYes\n"]} | 518 | 186 |
coding | Solve the programming task below in a Python markdown code block.
Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he's not sure which movie he should watch.
There are n m... | {"inputs": ["2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 4 1 4"], "outputs": ["1\n2"]} | 409 | 42 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
An array A is larger than some array B if for the first index i where A[i] != B[i], A[i] > B[i].
For example, consider 0-indexing:
[1,3,2,4] > [1,2,2,4], since at index 1, 3 > 2.
[1,4,4,4] < [2,1,1,1], since at index... | {"functional": "def check(candidate):\n assert candidate(nums = [1,4,5,2,3], k = 3) == [5,2,3]\n assert candidate(nums = [1,4,5,2,3], k = 4) == [4,5,2,3]\n assert candidate(nums = [1,4,5,2,3], k = 1) == [5]\n\n\ncheck(Solution().largestSubarray)"} | 187 | 109 |
coding | Solve the programming task below in a Python markdown code block.
Dreamoon loves summing up something for no reason. One day he obtains two integers a and b occasionally. He wants to calculate the sum of all nice integers. Positive integer x is called nice if $\operatorname{mod}(x, b) \neq 0$ and $\frac{\operatorname{d... | {"inputs": ["1 1\n", "2 2\n", "4 1\n", "4 2\n", "4 3\n", "4 4\n", "3 4\n", "2 4\n"], "outputs": ["0\n", "8\n", "0\n", "24\n", "102\n", "264\n", "162\n", "84\n"]} | 348 | 94 |
coding | Solve the programming task below in a Python markdown code block.
There are n wizards. They are numbered from 1 to n, and the i-th wizard has the magical power ri (1 ≤ i ≤ n). Now they are confronting a powerful wizard, whose enemy's magical power is S. n Wizards are good at fighting together, especially two people. Wh... | {"inputs": ["3 7\n1\n0\n5\n0 0", "3 7\n1\n3\n9\n0 0", "3 7\n1\n0\n9\n0 0", "3 7\n5\n4\n2\n0 0", "3 7\n4\n4\n2\n0 0", "3 7\n4\n4\n1\n0 0", "3 7\n0\n3\n3\n0 0", "3 5\n1\n0\n9\n0 0"], "outputs": ["0\n", "2\n", "2\n", "1\n", "1\n", "1\n", "0\n", "2\n"]} | 381 | 158 |
coding | Solve the programming task below in a Python markdown code block.
You have N bamboos. The lengths (in centimeters) of these are l_1, l_2, ..., l_N, respectively.
Your objective is to use some of these bamboos (possibly all) to obtain three bamboos of length A, B, C. For that, you can use the following three kinds of ma... | {"inputs": ["3 3 2 1\n1\n2\n3\n", "4 1000 2 1\n663\n663\n2\n1\n", "5 100 20 80\n79\n50\n9\n9\n80", "5 100 20 80\n79\n50\n9\n9\n157", "5 100 12 80\n80\n40\n42\n21\n62", "5 100 12 22\n80\n40\n42\n21\n62", "5 100 171 80\n68\n40\n9\n21\n80", "5 100 12 22\n80\n41\n42\n21\n62"], "outputs": ["0\n", "336\n", "32\n", "62\n", "2... | 598 | 253 |
coding | Solve the programming task below in a Python markdown code block.
```if-not:sql
Implement a function that receives two IPv4 addresses, and returns the number of addresses between them (including the first one, excluding the last one).
```
```if:sql
Given a database of first and last IPv4 addresses, calculate the numbe... | {"functional": "_inputs = [['150.0.0.0', '150.0.0.1'], ['10.0.0.0', '10.0.0.50'], ['20.0.0.10', '20.0.1.0'], ['10.11.12.13', '10.11.13.0'], ['160.0.0.0', '160.0.1.0'], ['170.0.0.0', '170.1.0.0'], ['50.0.0.0', '50.1.1.1'], ['180.0.0.0', '181.0.0.0'], ['1.2.3.4', '5.6.7.8']]\n_outputs = [[1], [50], [246], [243], [256], [... | 328 | 398 |
coding | Solve the programming task below in a Python markdown code block.
Create a program that will take in a string as input and, if there are duplicates of more than two alphabetical characters in the string, returns the string with all the extra characters in a bracket.
For example, the input "aaaabbcdefffffffg" should re... | {"functional": "_inputs = [['aaaabbcdefffffffg'], [3], ['boopdedoop'], ['helloookat'], [True], [''], ['aAAabbcdeffFfFffg'], ['aAAabbcdeFFFffffg'], [{}], [[5.3]]]\n_outputs = [['aa[aa]bbcdeff[fffff]g'], ['Please enter a valid string'], ['boopdedoop'], ['helloo[o]kat'], ['Please enter a valid string'], [''], ['aAAabbcdef... | 128 | 291 |
coding | Solve the programming task below in a Python markdown code block.
------Read problems statements in Mandarin chinese
, Russian and Vietnamese as well. ------
Tumut, the best programmer in his village Applidz, invented a problem and decided to share it with you:
You are given two integer sequences $S_{1}, S_{2}, \dot... | {"inputs": ["2 2 3\n1 8\n2 3"], "outputs": ["2"]} | 759 | 24 |
coding | Solve the programming task below in a Python markdown code block.
Recently, Chef studied the binary numeral system and noticed that it is extremely simple to perform bitwise operations like AND, XOR or bit shift on non-negative integers, while it is much more complicated to perform arithmetic operations (e.g. addition,... | {"inputs": ["3\n100010\n0\n0\n100010\n11100\n1010"], "outputs": ["0\n1\n3"]} | 732 | 45 |
coding | Solve the programming task below in a Python markdown code block.
My friend John likes to go to the cinema. He can choose between system A and system B.
```
System A : he buys a ticket (15 dollars) every time
System B : he buys a card (500 dollars) and a first ticket for 0.90 times the ticket price,
then for each addi... | {"functional": "_inputs = [[500, 15, 0.9], [100, 10, 0.95], [0, 10, 0.95], [250, 20, 0.9], [500, 20, 0.9], [2500, 20, 0.9]]\n_outputs = [[43], [24], [2], [21], [34], [135]]\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, a... | 443 | 256 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese] and [Bengali] as well.
You have three shoes of the same size lying around. Each shoe is either a left shoe (represented using 0) or a right shoe (represented using 1). Given A, B, ... | {"inputs": ["3\n0 0 0\n0 1 1\n1 0 1"], "outputs": ["0\n1\n1"]} | 330 | 34 |
coding | Solve the programming task below in a Python markdown code block.
You are going out for a walk, when you suddenly encounter a monster. Fortunately, you have N katana (swords), Katana 1, Katana 2, …, Katana N, and can perform the following two kinds of attacks in any order:
- Wield one of the katana you have. When you ... | {"inputs": ["1 10\n4 5", "1 10\n3 5", "1 10\n3 5\n", "2 10\n2 5\n2 6", "2 19\n2 5\n2 6", "2 19\n4 5\n2 6", "2 19\n4 5\n2 4", "2 2\n1 5\n2 10"], "outputs": ["3\n", "3", "3\n", "2\n", "6\n", "4\n", "5\n", "1\n"]} | 383 | 138 |
coding | Solve the programming task below in a Python markdown code block.
Three numbers A, B and C are the inputs. Write a program to find second largest among them.
-----Input-----
The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains three integers A, B and C.
-----O... | {"inputs": ["3 \n0 7 27\n11308 32 23\n0 1 39", "3 \n0 5 766\n5757 312 12\n6 0 40", "3 \n0 5 766\n5757 317 12\n6 0 40", "3 \n0 7 766\n5757 317 12\n6 0 40", "3 \n0 7 766\n5757 596 16\n6 0 40", "3 \n1 5 766\n5352 312 19\n1 0 40", "3 \n9 10 68\n10213 56 13\n10 0 3", "3 \n0 7 27\n11308 317 23\n0 1 39"], "outputs": ["7\n32\n... | 177 | 332 |
coding | Solve the programming task below in a Python markdown code block.
Those days, many boys use beautiful girls' photos as avatars in forums. So it is pretty hard to tell the gender of a user at the first glance. Last year, our hero went to a forum and had a nice chat with a beauty (he thought so). After that they talked v... | {"inputs": ["oh\n", "oh\n", "nh\n", "rhh\n", "rhh\n", "hhr\n", "pezu\n", "kmsk\n"], "outputs": ["CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "CHAT WITH HER!\n", "IGNORE HIM!\n"]} | 371 | 99 |
coding | Solve the programming task below in a Python markdown code block.
Here your task is to Create a (nice) Christmas Tree.
You don't have to check errors or incorrect input values, every thing is ok without bad tricks, only one int parameter as input and a string to return;-)...
So what to do?First three easy examples:
``... | {"functional": "_inputs = [[5], [10], [8], [2]]\n_outputs = [[' *\\r\\n ***\\r\\n*****\\r\\n ###'], [' *\\r\\n ***\\r\\n *****\\r\\n ***\\r\\n *****\\r\\n *******\\r\\n *****\\r\\n *******\\r\\n*********\\r\\n ###'], [' *\\r\\n ***\\r\\n *****\\r\\n ***\\r\\n *****\\r\\n*******\\r\\n ###'], ['']]\nimp... | 314 | 279 |
coding | Solve the programming task below in a Python markdown code block.
What adds up
===========
Given three arrays of integers your task is to create an algorithm that finds the numbers in the first two arrays whose sum is equal to any number in the third. The return value should be an array containing the values from the ... | {"functional": "_inputs = [[[], [1, 2, 3], [5, 2, 3]], [[1, 3, 4], [], [4, 6, 5]], [[1, 2, 3], [4, 5, 6], []]]\n_outputs = [[[]], [[]], [[]]]\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(... | 466 | 214 |
coding | Solve the programming task below in a Python markdown code block.
Appleman has a tree with n vertices. Some of the vertices (at least one) are colored black and other vertices are colored white.
Consider a set consisting of k (0 ≤ k < n) edges of Appleman's tree. If Appleman deletes these edges from the tree, then it ... | {"inputs": ["2\n0\n1 0\n", "2\n0\n1 0\n", "3\n0 0\n0 1 1\n", "3\n0 0\n1 1 1\n", "3\n0 1\n0 1 1\n", "3\n0 0\n0 1 1\n", "5\n0 1 1 3\n0 0 0 1 1\n", "5\n0 1 1 3\n0 0 0 1 1\n"], "outputs": ["1\n", "1", "2\n", "1\n", "1\n", "2", "1\n", "1"]} | 467 | 155 |
coding | Solve the programming task below in a Python markdown code block.
Mikhail walks on a 2D plane. He can go either up or right. You are given a sequence of Mikhail's moves. He thinks that this sequence is too long and he wants to make it as short as possible.
In the given sequence moving up is described by character U an... | {"inputs": ["1\nR\n", "1\nU\n", "1\nR\n", "1\nU\n", "2\nUR\n", "2\nUR\n", "2\nRU\n", "3\nRUR\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "2\n"]} | 295 | 87 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array nums of n integers where nums[i] is in the range [1, n], return an array of all the integers in the range [1, n] that do not appear in nums.
Please complete the following python code precisely:
```pyt... | {"functional": "def check(candidate):\n assert candidate(nums = [4,3,2,7,8,2,3,1]) == [5,6]\n assert candidate(nums = [1,1]) == [2]\n\n\ncheck(Solution().findDisappearedNumbers)"} | 93 | 65 |
coding | Solve the programming task below in a Python markdown code block.
Chef has a sequence of N$N$ integers A1,A2,...,AN$A_1, A_2, ..., A_N$.
Chef thinks that a triplet of integers (i,j,k)$(i,j,k)$ is good if 1≤i<j<k≤N$1 \leq i < j < k \leq N$ and P$P$ in the following expression contains an odd number of ones in its binar... | {"inputs": ["1\n4\n1 1 2 3"], "outputs": ["1"]} | 532 | 22 |
coding | Solve the programming task below in a Python markdown code block.
My little sister came back home from school with the following task:
given a squared sheet of paper she has to cut it in pieces
which, when assembled, give squares the sides of which form
an increasing sequence of numbers.
At the beginning it was lot of ... | {"functional": "_inputs = [[12], [6], [50], [44], [625], [5], [7100], [123456], [1234567], [7654321], [4], [7654322]]\n_outputs = [[[1, 2, 3, 7, 9]], [None], [[1, 3, 5, 8, 49]], [[2, 3, 5, 7, 43]], [[2, 5, 8, 34, 624]], [[3, 4]], [[2, 3, 5, 119, 7099]], [[1, 2, 7, 29, 496, 123455]], [[2, 8, 32, 1571, 1234566]], [[6, 10... | 580 | 418 |
coding | 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"]} | 376 | 113 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums consisting of n elements, and an integer k.
Find a contiguous subarray whose length is equal to k that has the maximum average value and return this value. Any answer with a calcula... | {"functional": "def check(candidate):\n assert candidate(nums = [1,12,-5,-6,50,3], k = 4) == 12.75\n assert candidate(nums = [5], k = 1) == 5.00000\n\n\ncheck(Solution().findMaxAverage)"} | 109 | 76 |
coding | Solve the programming task below in a Python markdown code block.
Once Bob saw a string. It contained so many different letters, that the letters were marked by numbers, but at the same time each letter could be met in the string at most 10 times. Bob didn't like that string, because it contained repeats: a repeat of l... | {"inputs": ["1\n0\n", "2\n1 2\n", "2\n4 2\n", "2\n2 2\n", "6\n1 2 3 1 2 3\n", "7\n1 2 3 1 2 3 1\n", "7\n4 5 6 5 6 5 7\n", "7\n4 5 6 5 9 5 7\n"], "outputs": ["1\n0 ", "2\n1 2 ", "2\n4 2\n", "1\n2\n", "3\n1 2 3 ", "4\n1 2 3 1 ", "4\n5 6 5 7\n", "7\n4 5 6 5 9 5 7\n"]} | 357 | 182 |
coding | Solve the programming task below in a Python markdown code block.
Given an amount A, we want you to compute the number of ways in which you
can gather A rupees if you have an infinite supply of each of C = {1, 3, 5} valued rupee coins.
Input:
First line contains T, the number of test-cases. This is followed by T lin... | {"inputs": ["100\n0\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n48\n49\n50\n51\n52\n53\n54\n55\n56\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n... | 204 | 1,286 |
coding | Solve the programming task below in a Python markdown code block.
FizzBuzz is a game in which integers of 1 or more are spoken in order according to the following rules.
* "Fizz" when divisible by 3
* "Buzz" when divisible by 5
* "FizzBuzz" when divisible by both 3 and 5
* At other times, that number
An example... | {"inputs": ["8", "2", "4", "3", "6", "5", "7", "9"], "outputs": ["BuzzFizz78FizzBuzz11\n", "2Fizz4BuzzFizz78Fizz\n", "izz4BuzzFizz78FizzBu\n", "Fizz4BuzzFizz78FizzB\n", "z4BuzzFizz78FizzBuzz\n", "zz4BuzzFizz78FizzBuz\n", "4BuzzFizz78FizzBuzz1\n", "uzzFizz78FizzBuzz11F\n"]} | 336 | 120 |
coding | Solve the programming task below in a Python markdown code block.
Chef has planned that he will drink exactly X liters of tea daily. He has an empty jar having a capacity of Y liters.
Chef can visit the tea shop to refill the jar. In each refill, the jar is completely filled to the brim and Chef is charged Z rupees.
... | {"inputs": ["4\n3 3 3\n6 3 3\n5 7 2\n9 4 5\n"], "outputs": ["3\n6\n2\n15\n"]} | 485 | 45 |
coding | Solve the programming task below in a Python markdown code block.
# Task
"AL-AHLY" and "Zamalek" are the best teams in Egypt, but "AL-AHLY" always wins the matches between them. "Zamalek" managers want to know what is the best match they've played so far.
The best match is the match they lost with the minimum goal ... | {"functional": "_inputs = [[[6, 4], [1, 2]], [[1], [0]], [[1, 2, 3, 4, 5], [0, 1, 2, 3, 4]], [[3, 4, 3], [1, 1, 2]], [[4, 3, 4], [1, 1, 1]]]\n_outputs = [[1], [0], [4], [2], [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=... | 405 | 247 |
coding | Solve the programming task below in a Python markdown code block.
Yash likes playing with numbers. He has a challenge for you. Yash gives
you a number that he made by multiplying two numbers. He claims that the
possible sum of the two numbers he multiplied is as minimum as possible. He
challenges you to find that minim... | {"inputs": ["1\n852140"], "outputs": ["1929"]} | 230 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Luke Skywalker gave Chewbacca an integer number x. Chewbacca isn't good at numbers but he loves inverting digits in them. Inverting digit t means replacing it with digit 9 - t.
Help Chewbacca to transform the initial number x to the minimum possible po... | {"inputs": ["1\n", "9\n", "9\n", "1\n", "5\n", "8\n", "27\n", "81\n"], "outputs": ["1\n", "9\n", "9\n", "1\n", "4\n", "1\n", "22\n", "11\n"]} | 187 | 74 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array a_1, a_2, ..., a_{n} consisting of n integers, and an integer k. You have to split the array into exactly k non-empty subsegments. You'll then compute the minimum integer on each subsegment, and take the maximum integer over the k ... | {"inputs": ["2 1\n1 2\n", "2 2\n5 2\n", "2 2\n5 2\n", "2 1\n1 2\n", "2 3\n5 2\n", "2 6\n5 2\n", "2 6\n5 0\n", "2 6\n1 0\n"], "outputs": ["1\n", "5\n", "5\n", "1\n", "5\n", "5\n", "5\n", "1\n"]} | 626 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Chef visited a grocery store for fresh supplies. There are N items in the store where the i^{th} item has a freshness value A_{i} and cost B_{i}.
Chef has decided to purchase all the items having a freshness value greater than equal to X. Find the total... | {"inputs": ["4\n2 20\n15 67\n10 90\n3 1\n1 2 3\n1 2 3\n3 100\n10 90 50\n30 7 93\n4 50\n12 78 50 40\n40 30 20 10\n"], "outputs": ["90\n6\n0\n50\n"]} | 554 | 107 |
coding | Solve the programming task below in a Python markdown code block.
Gotham city is in danger. All the people from Gotham were airlifted and they are going to be dropped at different districts of a new safe city.
There are $N$ districts located at position $(1, 2, \ldots, N)$ in a straight line in this newly built safe c... | {"inputs": ["4\n5 5 6 1\n2\n2 11\n2 3\n"], "outputs": ["6\n2\n"]} | 568 | 35 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums = [0,1,2,4,5,6,7] might become:
[4,5,6,7,0,1,2] if it was rotated 4 times.
[0,1,2,4,5,6,7] if it wa... | {"functional": "def check(candidate):\n assert candidate(nums = [3,4,5,1,2]) == 1\n assert candidate(nums = [4,5,6,7,0,1,2]) == 0\n assert candidate(nums = [11,13,15,17]) == 11\n\n\ncheck(Solution().findMin)"} | 228 | 86 |
coding | 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, where each node is numbered between 0 and n - 1. You are given a 2D array graph, where graph[u] is an array of nodes that node u is adjacent to. More formally, for each v in ... | {"functional": "def check(candidate):\n assert candidate(graph = [[1,2,3],[0,2],[0,1,3],[0,2]]) == False\n assert candidate(graph = [[1,3],[0,2],[1,3],[0,2]]) == True\n\n\ncheck(Solution().isBipartite)"} | 260 | 76 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are playing a game that contains multiple characters, and each of the characters has two main properties: attack and defense. You are given a 2D integer array properties where properties[i] = [attacki, defensei] r... | {"functional": "def check(candidate):\n assert candidate(properties = [[5,5],[6,3],[3,6]]) == 0\n assert candidate(properties = [[2,2],[3,3]]) == 1\n assert candidate(properties = [[1,5],[10,4],[4,3]]) == 1\n\n\ncheck(Solution().numberOfWeakCharacters)"} | 172 | 83 |
coding | Solve the programming task below in a Python markdown code block.
In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly n Berland dollars. Also the following restriction has been i... | {"inputs": ["8\n", "7\n", "9\n", "6\n", "1\n", "2\n", "5\n", "3\n"], "outputs": ["8 4 2 1\n", "7 1\n", "9 3 1\n", "6 3 1\n", "1\n", "2 1\n", "5 1\n", "3 1\n"]} | 269 | 92 |
coding | Solve the programming task below in a Python markdown code block.
Students are taught to add multi-digit numbers from right-to-left one digit at a time.
Many find the "carry" operation - in which 1 is carried from one digit position
to be added to the next - to be a significant challenge. Your job is to
count the numb... | {"inputs": ["3\n123 456\n555 555\n123 594", "3\n5555555555 5555555555\n1111111111 1111111111\n5111111111 5111111111"], "outputs": ["No carry operation\n3 carry operations\n1 carry operation", "10 carry operations\nNo carry operation\n1 carry operation"]} | 264 | 129 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
Lately, Chef has been inspired by the "pawri" meme. Therefore, he decided to take a string $S$ and change each of its substrings that spells "party" to "pawr... | {"inputs": ["3\npart\npartypartiparty\nyemaihuyemericarhaiauryahapartyhorahihai"], "outputs": ["part\npawripartipawri\nyemaihuyemericarhaiauryahapawrihorahihai"]} | 335 | 67 |
coding | Solve the programming task below in a Python markdown code block.
You are given three strings A, B and C. Each of these is a string of length N consisting of lowercase English letters.
Our objective is to make all these three strings equal. For that, you can repeatedly perform the following operation:
* Operation: Ch... | {"inputs": ["4\nwest\neast\nw`it", "4\nwesu\neast\nw`it", "4\nwetu\neast\nw`it", "4\nwetv\n`est\ntiaw", "4\ntewv\n`ftt\nsaiw", "4\nwetu\ne`st\nw`it", "4\nwetu\n`est\nw`it", "4\nwetu\n`est\nwait"], "outputs": ["4\n", "5\n", "6\n", "7\n", "8\n", "5\n", "5\n", "5\n"]} | 252 | 144 |
coding | Solve the programming task below in a Python markdown code block.
The courier charges for a courier company are set according to size and weight as shown in the table below.
A size | B size | C size | D size | E size | F size
--- | --- | --- | --- | --- | --- | ---
Size | 60 cm or less | 80 cm or less | 100 cm or less... | {"inputs": ["2\n26 1 8 2\n80 82 0 0\n3\n18 0 0 24\n4 0 4 3\n30 30 1 1\n0", "2\n51 1 5 5\n80 82 3 0\n3\n7 2 0 24\n2 0 12 3\n30 30 0 11\n0", "2\n51 2 5 5\n80 82 3 0\n3\n7 2 0 24\n2 0 12 3\n30 30 0 11\n0", "2\n51 1 5 5\n80 82 3 0\n3\n10 2 0 24\n2 0 12 3\n30 30 0 11\n0", "2\n51 2 5 5\n80 82 3 0\n3\n7 2 0 24\n2 0 12 3\n30 3... | 555 | 527 |
coding | Solve the programming task below in a Python markdown code block.
As usual, Sereja has array a, its elements are integers: a[1], a[2], ..., a[n]. Let's introduce notation:
$f(a, l, r) = \sum_{i = l}^{r} a [ i ] ; m(a) = \operatorname{max}_{1 \leq l \leq r \leq n} f(a, l, r)$
A swap operation is the following sequence... | {"inputs": ["1 1\n1\n", "1 1\n1\n", "1 1\n-1\n", "1 10\n1\n", "1 10\n1\n", "1 1\n-1\n", "1 16\n1\n", "1 2\n-2\n"], "outputs": ["1\n", "1\n", "-1\n", "1\n", "1\n", "-1\n", "1\n", "-2\n"]} | 328 | 108 |
coding | Solve the programming task below in a Python markdown code block.
You are given two positive integers $n$ and $s$. Find the maximum possible median of an array of $n$ non-negative integers (not necessarily distinct), such that the sum of its elements is equal to $s$.
A median of an array of integers of length $m$ is t... | {"inputs": ["8\n1 5\n1 9\n3 5\n2 1\n14 0\n4 2\n1 1010010000\n1000100000 1\n", "8\n1 9\n1 9\n3 5\n2 1\n14 0\n4 2\n1 1010010000\n1000100000 1\n", "8\n1 9\n1 9\n3 7\n2 1\n14 0\n6 2\n1 1010010000\n1000100000 1\n", "8\n1 9\n1 9\n3 7\n3 2\n14 0\n6 2\n1 1010010000\n1000100000 1\n", "8\n1 5\n1 9\n3 5\n2 1\n14 0\n4 2\n2 1010010... | 476 | 661 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer n, you must transform it into 0 using the following operations any number of times:
Change the rightmost (0th) bit in the binary representation of n.
Change the ith bit in the binary representation o... | {"functional": "def check(candidate):\n assert candidate(n = 3) == 2\n assert candidate(n = 6) == 4\n\n\ncheck(Solution().minimumOneBitOperations)"} | 142 | 45 |
coding | Solve the programming task below in a Python markdown code block.
In this kata, your task is to write a function `to_bytes(n)` (or `toBytes(n)` depending on language) that produces a list of bytes that represent a given non-negative integer `n`. Each byte in the list is represented by a string of `'0'` and `'1'` of len... | {"functional": "_inputs = [[0], [1]]\n_outputs = [[['00000000']], [['00000001']]]\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 Fals... | 136 | 176 |
coding | Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is constraints.
Ivan plays a computer game that contains some microtransactions to make characters look cooler. Since Ivan wants his character to be really cool, he wants to use some of these microtrans... | {"inputs": ["5 3\n4 2 1 3 2\n3 5\n4 2\n2 5\n", "5 3\n4 2 1 3 0\n3 5\n4 2\n2 5\n", "5 3\n2 2 1 3 2\n3 5\n4 2\n2 5\n", "5 3\n4 2 1 5 0\n3 5\n4 2\n2 5\n", "5 3\n2 2 1 3 2\n3 5\n4 3\n2 5\n", "5 3\n4 2 1 0 2\n3 5\n4 2\n2 5\n", "5 3\n4 2 2 5 0\n3 5\n4 2\n2 5\n", "5 3\n1 2 1 3 2\n3 5\n4 3\n2 5\n"], "outputs": ["20\n", "18\n",... | 655 | 270 |
coding | Solve the programming task below in a Python markdown code block.
Sultan, the freestyle wrestler, you all know him. He broke multiple records in the history of all wrestling leagues. Now 20 years have passed, Sultan has grown old. He has two sons, he wants them to be like him. Sultan being orthodox goes to his astrolog... | {"inputs": ["2\n7\n2 3\n4 5 7 8 9 10 14\n6\n5 7\n1 2 8 9 10 11"], "outputs": ["Yes\nMultan\nNo"]} | 599 | 59 |
coding | Solve the programming task below in a Python markdown code block.
You are given $n$ integers $a_1, a_2, \ldots, a_n$. Find the maximum value of $max(a_l, a_{l + 1}, \ldots, a_r) \cdot min(a_l, a_{l + 1}, \ldots, a_r)$ over all pairs $(l, r)$ of integers for which $1 \le l < r \le n$.
-----Input-----
The first line c... | {"inputs": ["1\n2\n44841 417\n", "1\n2\n44841 2653\n", "1\n2\n44841 66241\n", "1\n2\n44841 83433\n", "1\n2\n29981 18424\n", "1\n2\n23338 18424\n", "1\n2\n23338 34273\n", "1\n2\n11672 34273\n"], "outputs": ["18698697\n", "118963173\n", "2970312681\n", "3741219153\n", "552369944\n", "429979312\n", "799863274\n", "4000344... | 663 | 244 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese , Russian and Vietnamese as well.
Chef belongs to a very rich family which owns many gold mines. Today, he brought N gold coins and decided to form a triangle using these coins. Isn't it strange?
Chef has a... | {"inputs": ["3\n3\n5\n7", "3\n5\n9\n2", "3\n5\n5\n2", "3\n2\n5\n2", "3\n5\n5\n7", "3\n5\n5\n3", "3\n5\n7\n7", "3\n5\n7\n5"], "outputs": ["2\n2\n3", "2\n3\n1\n", "2\n2\n1\n", "1\n2\n1\n", "2\n2\n3\n", "2\n2\n2\n", "2\n3\n3\n", "2\n3\n2\n"]} | 423 | 141 |
coding | Solve the programming task below in a Python markdown code block.
You are given a board of size $n \times n$, where $n$ is odd (not divisible by $2$). Initially, each cell of the board contains one figure.
In one move, you can select exactly one figure presented in some cell and move it to one of the cells sharing a s... | {"inputs": ["1\n2119\n", "1\n9693\n", "1\n2569\n", "1\n69791\n", "1\n69791\n", "1\n54111\n", "1\n39575\n", "1\n47045\n"], "outputs": ["3171549680\n", "303566175288\n", "5651594480\n", "113312287936960\n", "113312287936960\n", "52812341771840\n", "20660532731600\n", "34707166856360\n"]} | 496 | 211 |
coding | Solve the programming task below in a Python markdown code block.
After the hundred years of war started by the Fire Nation, its time for the Water Tribes to bring it to an end. Avatar asked Sokka to go to the Southern WarZone from The Northern WarZone and gave him some money in a bag for his journey. Sokka has the Wor... | {"inputs": ["2\n5\n2"], "outputs": ["200000002\n0"]} | 679 | 26 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin chinese, Russian and Vietnamese as well.
Gritukan likes to take cyclic trips around the world. There are $N$ countries numbered $1$ through $N$ in the world. Before starting his travels, Gritukan chooses a permutati... | {"inputs": ["2\n6\n1 1 1 1 1 1\n6\n6 6 6 6 6 6"], "outputs": ["1\n120"]} | 595 | 44 |
coding | Solve the programming task below in a Python markdown code block.
As a New Year's gift, Dolphin received a string s of length 19.
The string s has the following format: [five lowercase English letters],[seven lowercase English letters],[five lowercase English letters].
Dolphin wants to convert the comma-separated str... | {"inputs": ["happy,newyear,enjoy\n", "haiku,atcoder,tasks\n", "abcde,fghihgf,edcba\n", "mzbmw,yydiadt,coueg\n", "dbyfw,rpwbpuv,ifnua\n", "wyndm,tqvkgkb,tytsz\n", "twfle,sjzzszf,tzfpn\n", "cguem,rczqxyc,vdqnk\n"], "outputs": ["happy newyear enjoy\n", "haiku atcoder tasks\n", "abcde fghihgf edcba\n", "mzbmw yydiadt coueg... | 184 | 196 |
coding | Solve the programming task below in a Python markdown code block.
Two children, Lily and Ron, want to share a chocolate bar. Each of the squares has an integer on it.
Lily decides to share a contiguous segment of the bar selected such that:
The length of the segment matches Ron's birth month, and,
The sum of the in... | {"inputs": ["1\n4\n4 1\n", "5\n1 2 1 3 2\n3 2\n", "6\n1 1 1 1 1 1\n3 2\n"], "outputs": ["1\n", "2\n", "0\n"]} | 620 | 66 |
coding | 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)"} | 120 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Let N be a positive integer. You are given a string s of length N - 1, consisting of `<` and `>`.
Find the number of permutations (p_1, p_2, \ldots, p_N) of (1, 2, \ldots, N) that satisfy the following condition, modulo 10^9 + 7:
* For each i (1 \leq i... | {"inputs": ["4\n<<>", "4\n<><", "5\n<<><", "5\n><<<", "5\n<<<<", "20\n>><<>>><>><>>><>>>>", "20\n>><<>>><>>>>>><>>><", "20\n>>>><>>>>><<>>><<>>"], "outputs": ["3\n", "5", "9\n", "4\n", "1", "217136290\n", "415929071\n", "784400335\n"]} | 285 | 132 |
coding | Solve the programming task below in a Python markdown code block.
It's hard times now. Today Petya needs to score 100 points on Informatics exam. The tasks seem easy to Petya, but he thinks he lacks time to finish them all, so he asks you to help with one..
There is a glob pattern in the statements (a string consistin... | {"inputs": ["a\nab\n1\na\n", "a\na\n1\nab\n", "b\naa\n1\na\n", "c\na\n1\nab\n", "a\na\n1\nab\n", "b\naa\n1\na\n", "c\na\n1\nab\n", "a\nab\n1\na\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 678 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Chef has been working in a restaurant which has N floors. He wants to minimize the time it takes him to go from the N-th floor to ground floor. He can either take the elevator or the stairs.
The stairs are at an angle of 45 degrees and Chef's velocity... | {"inputs": ["3\n5 10 15\n2 10 14\n7 14 10"], "outputs": ["Elevator\nStairs\nStairs"]} | 362 | 43 |
coding | Solve the programming task below in a Python markdown code block.
You are given a prime number p, n integers a_1, a_2, …, a_n, and an integer k.
Find the number of pairs of indexes (i, j) (1 ≤ i < j ≤ n) for which (a_i + a_j)(a_i^2 + a_j^2) ≡ k mod p.
Input
The first line contains integers n, p, k (2 ≤ n ≤ 3 ⋅ 10^5... | {"inputs": ["2 2 1\n1 0\n", "2 2 0\n1 0\n", "2 2 2\n1 0\n", "2 3 2\n1 0\n", "2 4 0\n1 0\n", "2 37 0\n3 1\n", "2 56 0\n3 1\n", "2 56 0\n6 1\n"], "outputs": ["1", "0", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 358 | 135 |
coding | Solve the programming task below in a Python markdown code block.
# Summation Of Primes
The sum of the primes below or equal to 10 is **2 + 3 + 5 + 7 = 17**. Find the sum of all the primes **_below or equal to the number passed in_**.
From Project Euler's [Problem #10](https://projecteuler.net/problem=10 "Project Eul... | {"functional": "_inputs = [[5], [6], [7], [8], [9], [10], [20], [30], [40], [50], [100], [200], [300], [400], [500], [1000], [2000], [3000], [4000], [5000], [25000]]\n_outputs = [[10], [10], [17], [17], [17], [17], [77], [129], [197], [328], [1060], [4227], [8275], [13887], [21536], [76127], [277050], [593823], [101350... | 125 | 375 |
coding | Solve the programming task below in a Python markdown code block.
Consider an array A of length N. You know that for all 1 ≤ i ≤ N, 0 ≤ A_{i} ≤ 10^{5}. We construct an array B of length N-1 such that, for all 1 ≤ i ≤ N - 1, B_{i} = min(A_{i}, A_{i + 1}).
You are given the array B, you need to find out the total number... | {"inputs": ["3\n2\n100\n5\n3 9 8 4\n3\n10 12"], "outputs": ["199801\n199983\n199977"]} | 532 | 55 |
coding | Solve the programming task below in a Python markdown code block.
There are 2000001 stones placed on a number line. The coordinates of these stones are -1000000, -999999, -999998, \ldots, 999999, 1000000.
Among them, some K consecutive stones are painted black, and the others are painted white.
Additionally, we know th... | {"inputs": ["9 7", "5 5", "9 3", "2 4", "2 6", "1 4", "4 7", "6 5"], "outputs": ["-1 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\n", "1 2 3 4 5 6 7 8 9\n", "-5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10 11\n", "3 4 5\n", "5 6 7\n", "4\n", "4 5 6 7 8 9 10\n", "0 1 2 3 4 5 6 7 8 9 10\n"]} | 346 | 209 |
coding | Solve the programming task below in a Python markdown code block.
The Smart Beaver from ABBYY began to develop a new educational game for children. The rules of the game are fairly simple and are described below.
The playing field is a sequence of n non-negative integers ai numbered from 1 to n. The goal of the game i... | {"inputs": ["4\n0 0 1 2\n", "4\n1 0 1 2\n", "5\n4 1 4 7 6\n", "5\n4 1 1 7 6\n", "5\n4 1 0 1 2\n", "5\n4 2 0 1 2\n", "5\n8 2 0 1 2\n", "5\n4 1 1 7 2\n"], "outputs": ["0\n0\n1\n", "1\n1\n3\n", "4\n5\n9\n17\n", "4\n5\n6\n14\n", "4\n5\n5\n7\n", "4\n6\n6\n9\n", "8\n10\n10\n13\n", "4\n5\n6\n14\n"]} | 583 | 196 |
coding | Solve the programming task below in a Python markdown code block.
There is a tree with N vertices numbered 1 through N.
The i-th edge connects Vertex x_i and y_i.
Each vertex is painted white or black.
The initial color of Vertex i is represented by a letter c_i.
c_i = W represents the vertex is white; c_i = B represen... | {"inputs": ["1\nB", "1\nB\n", "5\n1 2\n0 3\n2 4\n4 5\nWBBWW", "5\n1 2\n2 3\n2 5\n4 5\nWBBWW", "5\n1 2\n1 3\n2 4\n4 5\nWBBWW", "5\n1 3\n2 3\n2 5\n4 5\nWBBWW", "5\n1 2\n1 3\n3 4\n4 5\nWBBWW", "5\n1 2\n2 3\n2 4\n4 5\nWBBWW"], "outputs": ["0", "0\n", "5\n", "5\n", "5\n", "7\n", "5\n", "5"]} | 435 | 185 |
coding | Solve the programming task below in a Python markdown code block.
If you have completed the Tribonacci sequence kata, you would know by now that mister Fibonacci has at least a bigger brother. If not, give it a quick look to get how things work.
Well, time to expand the family a little more: think of a Quadribonacci s... | {"functional": "_inputs = [[[0, 1], 10], [[1, 1], 10], [[0, 0, 0, 0, 1], 10], [[1, 0, 0, 0, 0, 0, 1], 10], [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0], 20], [[0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0], 10], [[0.5, 0, 0, 0, 0, 0, 0, 0, 0, 0], 20], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 20], [[1, 2, 3, 4, 5, 6, 7, 8, 9, 0], 9], [[1, 2, 3, 4, 5, 6, ... | 361 | 806 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit c... | {"inputs": ["2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 4 1 4", "2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 5 1 4", "2\n2\n2 2\n2 1\n4\n2 1 4 1\n4 4 1 4", "2\n2\n1 2\n2 1\n4\n1 1 4 1\n2 5 1 4", "2\n2\n2 2\n2 1\n4\n2 1 4 1\n2 4 1 4", "2\n2\n2 2\n2 1\n4\n2 1 4 1\n1 4 1 4", "2\n2\n1 2\n2 1\n4\n1 1 1 1\n2 5 1 4", "2\n2\n2 2\n2 1\n3\n2 1 4 1\n1 4 1 ... | 459 | 301 |
coding | Solve the programming task below in a Python markdown code block.
You are taking a computer-based examination. The examination consists of N questions, and the score allocated to the i-th question is s_i. Your answer to each question will be judged as either "correct" or "incorrect", and your grade will be the sum of t... | {"inputs": ["3\n2\n0\n2", "3\n2\n1\n2", "3\n0\n0\n3", "3\n1\n8\n1", "3\n2\n8\n0", "3\n2\n3\n1", "3\n2\n3\n2", "3\n2\n8\n2"], "outputs": ["4\n", "5\n", "3\n", "9\n", "8\n", "6\n", "7\n", "12\n"]} | 321 | 111 |
coding | Solve the programming task below in a Python markdown code block.
# Write Number in Expanded Form - Part 2
This is version 2 of my ['Write Number in Exanded Form' Kata](https://www.codewars.com/kata/write-number-in-expanded-form).
You will be given a number and you will need to return it as a string in [Expanded Form... | {"functional": "_inputs = [[1.24], [7.304], [0.04], [1.04], [7.3004], [0.004], [693.230459]]\n_outputs = [['1 + 2/10 + 4/100'], ['7 + 3/10 + 4/1000'], ['4/100'], ['1 + 4/100'], ['7 + 3/10 + 4/10000'], ['4/1000'], ['600 + 90 + 3 + 2/10 + 3/100 + 4/10000 + 5/100000 + 9/1000000']]\nimport math\ndef _deep_eq(a, b, tol=1e-5... | 202 | 332 |
coding | Solve the programming task below in a Python markdown code block.
Two integers A and B are the inputs. Write a program to find GCD and LCM of A and B.
-----Input-----
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer A and B.
-----Output-----
Display... | {"inputs": ["3\n120 140\n10213 312\n10 30"], "outputs": ["20 840\n1 3186456\n10 30"]} | 188 | 57 |
coding | Solve the programming task below in a Python markdown code block.
Problem Statement
We can describe detailed direction by repeating the directional names: north, south, east and west. For example, northwest is the direction halfway between north and west, and northnorthwest is between north and northwest.
In this pro... | {"inputs": ["north\nwest\nnorthwest\nnorthnorthwest\nwestwestwestnorth\n#"], "outputs": ["0\n90\n45\n45/2\n315/4"]} | 461 | 45 |
coding | Solve the programming task below in a Python markdown code block.
We have a country containing _N _cities. Each day we choose 2 cities such that there is no road between them and build a road between them. We choose each pair of nonadjacent cities with equal probability. Let X be the number of days before we obtain a c... | {"inputs": ["3\n", "4\n"], "outputs": ["2\n", "3\n"]} | 311 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Gematria is an Assyro-Babylonian-Greek system of code and numerology later adopted into Jewish culture. The system assigns numerical value to a word or a phrase in the belief that words or phrases with identical numerical values bear some relation to eac... | {"functional": "_inputs = [['love'], ['jaels'], ['JAELS'], ['Devil'], ['Coding is fun']]\n_outputs = [[775], [716], [716], [738], [458]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (l... | 334 | 195 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian], [Mandarin Chinese], [Bengali], and [Vietnamese] as well.
Let's define a function F(X) as follows:
F(X) = \frac{X}{Y}
where Y is the largest perfect square that divides X.
For example,
The largest perfect squar... | {"inputs": ["3\n3\n2 3 12\n4 \n1 2 3 4\n3\n2 3 7"], "outputs": ["2\n5\n3"]} | 707 | 44 |
coding | Solve the programming task below in a Python markdown code block.
Consider a number X on which K Mag-Inc operations are to be performed. In a Mag-Inc operation, the number X undergoes an increment of A/B times of X where A and B are two integers.
There is a numerator and a denominator array of size K which contain the... | {"inputs": ["2\n100 1\n1\n4\n100 2\n1 1\n2 3"], "outputs": ["20\n50"]} | 434 | 40 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads where roads[i] = [ai, bi, distancei] indicates that there is a bidirectional road between cities ai an... | {"functional": "def check(candidate):\n assert candidate(n = 4, roads = [[1,2,9],[2,3,6],[2,4,5],[1,4,7]]) == 5\n assert candidate(n = 4, roads = [[1,2,2],[1,3,4],[3,4,7]]) == 2\n\n\ncheck(Solution().minScore)"} | 219 | 91 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array $a$ consisting of $n$ integers. Each $a_i$ is one of the six following numbers: $4, 8, 15, 16, 23, 42$.
Your task is to remove the minimum number of elements to make this array good.
An array of length $k$ is called good if $k$ i... | {"inputs": ["1\n4\n", "1\n4\n", "1\n8\n", "1\n42\n", "1\n42\n", "1\n15\n", "1\n16\n", "1\n23\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 690 | 91 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two strings word1 and word2, return the minimum number of steps required to make word1 and word2 the same.
In one step, you can delete exactly one character in either string.
Please complete the following pyth... | {"functional": "def check(candidate):\n assert candidate(word1 = \"leetcode\", word2 = \"etco\") == 4\n\n\ncheck(Solution().minDistance)"} | 93 | 39 |
coding | Solve the programming task below in a Python markdown code block.
Vasya used to be an accountant before the war began and he is one of the few who knows how to operate a computer, so he was assigned as the programmer.
We all know that programs often store sets of integers. For example, if we have a problem about a wei... | {"inputs": ["1\nint\n", "2\nint int\n", "1\npair iot\n", "1\npair ins\n", "1\npair int\n", "2\npair int int\n", "2\nint pair int\n", "1\nint pair pair\n"], "outputs": ["int\n", "Error occurred\n", "Error occurred\n", "Error occurred\n", "Error occurred\n", "pair<int,int>\n", "Error occurred\n", "Error occurred\n"]} | 632 | 106 |
coding | Solve the programming task below in a Python markdown code block.
Subodh is having N branches, where each branches have positive integral student. A minimize operation is performed on the branch such that all of them are reduced by the minimum number student in a branch.
Suppose we have 5 branches and all of them have... | {"inputs": ["6\n5 4 4 2 2 8"], "outputs": ["6\n4\n2\n1"]} | 278 | 30 |
coding | Solve the programming task below in a Python markdown code block.
You are a skier (marked below by the `X`). You have made it to the Olympics! Well done.
```
\_\_\_X\_
\*\*\*\*\*\
\*\*\*\*\*\*\
\*\*\*\*\*\*\*\
\*\*\*\*\*\*\*\*\
\*\*\*\*\*\*\*\*\*\\.\_\_\_\_/
```
Your job in this kata is to calculate the maximum speed... | {"functional": "_inputs = [[['*']], [['*', '**', '***']], [['*', '**', '***', '****', '*****', '******']], [['*', '**', '***', '****', '*****', '******', '*******', '********']]]\n_outputs = [[\"1.35 metres: He's crap!\"], [\"12.15 metres: He's ok!\"], [\"48.60 metres: He's flying!\"], ['86.40 metres: Gold!!']]\nimport... | 449 | 254 |
coding | Solve the programming task below in a Python markdown code block.
Given a string of words, you need to find the highest scoring word.
Each letter of a word scores points according to its position in the alphabet: `a = 1, b = 2, c = 3` etc.
You need to return the highest scoring word as a string.
If two words score t... | {"functional": "_inputs = [['man i need a taxi up to ubud'], ['what time are we climbing up the volcano'], ['take me to semynak'], ['massage yes massage yes massage'], ['take two bintang and a dance please']]\n_outputs = [['taxi'], ['volcano'], ['semynak'], ['massage'], ['bintang']]\nimport math\ndef _deep_eq(a, b, tol... | 123 | 215 |
coding | Solve the programming task below in a Python markdown code block.
Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartments that are numbered from 1 to n and are arranged in a row. Two apartments are adjacent if their indices differ by 1. Some of the apartments can already ... | {"inputs": ["6 3\n", "8 0\n", "8 8\n", "1 0\n", "1 1\n", "2 0\n", "2 1\n", "2 2\n"], "outputs": ["1 3\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "0 0\n", "1 1\n", "0 0\n"]} | 307 | 102 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well.
A tuple $(a, b, c)$ is considered good if it consists of three prime numbers $a$, $b$ and $c$ such that $a < b < c ≤ N$ and $a + b = c$.
Two tuples... | {"inputs": ["2\n3\n6"], "outputs": ["0\n1"]} | 352 | 18 |
coding | Solve the programming task below in a Python markdown code block.
Kiyora has $n$ whiteboards numbered from $1$ to $n$. Initially, the $i$-th whiteboard has the integer $a_i$ written on it.
Koxia performs $m$ operations. The $j$-th operation is to choose one of the whiteboards and change the integer written on it to $b... | {"inputs": ["4\n3 2\n1 2 3\n4 5\n2 3\n1 2\n3 4 5\n1 1\n100\n1\n5 3\n1 1 1 1 1\n1000000000 1000000000 1000000000\n"], "outputs": ["12\n9\n1\n3000000002\n"]} | 631 | 115 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.