task_type stringclasses 1
value | problem stringlengths 209 3.39k | answer stringlengths 35 6.15k | problem_tokens int64 60 774 | answer_tokens int64 12 2.04k |
|---|---|---|---|---|
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed integer array nums. An index i is part of a hill in nums if the closest non-equal neighbors of i are smaller than nums[i]. Similarly, an index i is part of a valley in nums if the closest non... | {"functional": "def check(candidate):\n assert candidate(nums = [2,4,1,1,6,5]) == 3\n assert candidate(nums = [6,6,5,5,4,1]) == 0\n\n\ncheck(Solution().countHillValley)"} | 179 | 66 |
coding | Solve the programming task below in a Python markdown code block.
You are given a string s, consisting of small Latin letters. Let's denote the length of the string as |s|. The characters in the string are numbered starting from 1.
Your task is to find out if it is possible to rearrange characters in string s so that... | {"inputs": ["z\n", "abc\n", "abcc\n", "abcd\n", "xxxyyxx\n", "xxxyxxx\n", "hfihihhfh\n", "hgihihhfh\n"], "outputs": ["YES\nz", "YES\nabc", "YES\nacbc\n", "NO\n", "YES\nxxxxyxy\n", "YES\nxxxxxxy\n", "NO\n", "NO\n"]} | 341 | 97 |
coding | Solve the programming task below in a Python markdown code block.
You've arrived at a carnival and head straight for the duck shooting tent. Why wouldn't you?
You will be given a set amount of ammo, and an aim rating of between 1 and 0. No your aim is not always perfect - hey maybe someone fiddled with the sights on t... | {"functional": "_inputs = [[4, 0.64, '|~~2~~~22~2~~22~2~~~~2~~~|'], [9, 0.22, '|~~~~~~~2~2~~~|'], [6, 0.41, '|~~~~~22~2~~~~~|'], [8, 0.05, '|2~~~~|'], [8, 0.92, '|~~~~2~2~~~~~22~~2~~~~2~~~2|']]\n_outputs = [['|~~X~~~X2~2~~22~2~~~~2~~~|'], ['|~~~~~~~X~2~~~|'], ['|~~~~~XX~2~~~~~|'], ['|2~~~~|'], ['|~~~~X~X~~~~~XX~~X~~~~X... | 214 | 328 |
coding | Solve the programming task below in a Python markdown code block.
Kulyash stays in room that has a single bulb and N buttons. The bulb is initially on.
The initial states of the buttons are stored in a binary string S of length N — if S_{i} is 0, the i-th button is off, and if S_{i} is 1, the i-th button is on. If Kul... | {"inputs": ["2\n3\n000\n001\n2\n00\n11\n"], "outputs": ["0\n1\n"]} | 450 | 34 |
coding | Solve the programming task below in a Python markdown code block.
You are given an array A of size N. In one operation, you can do the following:
Select indices i and j (i\neq j) and set A_{i} = A_{j}.
Find the minimum number of operations required to make all elements of the array equal.
------ Input Format ------... | {"inputs": ["3\n3\n1 2 3\n4\n2 2 3 1\n4\n3 1 2 4\n"], "outputs": ["2\n2\n3\n"]} | 634 | 46 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Little Churu is a naughty child, who likes to play with balls. He has N buckets. Each bucket contains one or more balls. He has numbered his buckets 1 to N (both inclusive). ... | {"inputs": ["1\n3\n11 13 15", "1\n3\n11 13 15"], "outputs": ["3", "3"]} | 405 | 40 |
coding | Solve the programming task below in a Python markdown code block.
Implement the function unique_in_order which takes as argument a sequence and returns a list of items without any elements with the same value next to each other and preserving the original order of elements.
For example:
```python
unique_in_order('AAA... | {"functional": "_inputs = [[''], ['A'], ['AA'], ['AAAABBBCCDAABBB'], ['AADD'], ['AAD'], ['ADD'], ['ABBCcAD'], [[1, 2, 3, 3]], [['a', 'b', 'b']]]\n_outputs = [[[]], [['A']], [['A']], [['A', 'B', 'C', 'D', 'A', 'B']], [['A', 'D']], [['A', 'D']], [['A', 'D']], [['A', 'B', 'C', 'c', 'A', 'D']], [[1, 2, 3]], [['a', 'b']]]\n... | 164 | 283 |
coding | Solve the programming task below in a Python markdown code block.
There are N integers, A_1, A_2, ..., A_N, written on the blackboard.
You will choose one of them and replace it with an integer of your choice between 1 and 10^9 (inclusive), possibly the same as the integer originally written.
Find the maximum possible ... | {"inputs": ["3\n7 6 7", "3\n4 8 7", "3\n4 2 5", "3\n7 6 8", "3\n7 6 8\n", "3\n4 6 9\n", "3\n9 28 18", "3\n9 28 30"], "outputs": ["7\n", "4\n", "2\n", "2", "2\n", "3\n", "9\n", "3\n"]} | 234 | 115 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s consisting of lowercase English letters. Perform the following operation:
Select any non-empty substring then replace every letter of the substring with the preceding letter of the English alphabet. ... | {"functional": "def check(candidate):\n assert candidate(s = \"cbabc\") == \"baabc\"\n assert candidate(s = \"acbbc\") == \"abaab\"\n assert candidate(s = \"leetcode\") == \"kddsbncd\"\n\n\ncheck(Solution().smallestString)"} | 117 | 67 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A maze consists of n rooms numbered from 1 to n, and some rooms are connected by corridors. You are given a 2D integer array corridors where corridors[i] = [room1i, room2i] indicates that there is a corridor connectin... | {"functional": "def check(candidate):\n assert candidate(n = 5, corridors = [[1,2],[5,2],[4,1],[2,4],[3,1],[3,4]]) == 2\n assert candidate(n = 4, corridors = [[1,2],[3,4]]) == 0\n\n\ncheck(Solution().numberOfPaths)"} | 250 | 81 |
coding | Solve the programming task below in a Python markdown code block.
Mishka is a little polar bear. As known, little bears loves spending their free time playing dice for chocolates. Once in a wonderful sunny morning, walking around blocks of ice, Mishka met her friend Chris, and they started playing the game.
Rules of t... | {"inputs": ["1\n1 1\n", "1\n1 1\n", "1\n1 0\n", "1\n2 1\n", "2\n6 1\n1 6\n", "2\n6 1\n1 8\n", "2\n6 1\n1 6\n", "3\n3 5\n2 1\n4 2\n"], "outputs": ["Friendship is magic!^^", "Friendship is magic!^^\n", "Mishka\n", "Mishka\n", "Friendship is magic!^^", "Friendship is magic!^^\n", "Friendship is magic!^^\n", "Mishka"]} | 539 | 153 |
coding | Solve the programming task below in a Python markdown code block.
Joisino is planning to record N TV programs with recorders.
The TV can receive C channels numbered 1 through C.
The i-th program that she wants to record will be broadcast from time s_i to time t_i (including time s_i but not t_i) on Channel c_i.
Here, t... | {"inputs": ["3 4\n1 3 2\n2 4 4\n1 4 3", "3 4\n1 3 2\n2 4 4\n1 5 3", "3 4\n1 3 2\n3 4 4\n1 4 3", "3 4\n1 3 2\n3 4 4\n1 4 3\n", "3 2\n1 7 2\n7 8 1\n8 12 1", "3 2\n1 7 2\n7 8 1\n8 12 1\n", "3 2\n1 7 2\n7 12 1\n8 12 1", "3 2\n2 7 2\n7 12 1\n8 12 1"], "outputs": ["3\n", "3\n", "3", "3\n", "2", "2\n", "2\n", "2\n"]} | 446 | 228 |
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 and a positive integer k. You can choose any subsequence of the array and sum all of its elements together.
We define the K-Sum of the array as the kth largest subsequence sum that ... | {"functional": "def check(candidate):\n assert candidate(nums = [2,4,-2], k = 5) == 2\n assert candidate(nums = [1,-2,3,4,-10,12], k = 16) == 10\n\n\ncheck(Solution().kSum)"} | 161 | 71 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Haku has been newly hired by Chef to clean tables at his restaurant. So whenever a customer wants a table, Haku must clean it.
But Haku happens to be a lazy boy. So in the morning, when the res... | {"inputs": ["4\n2 4\n1 2 3 4\n3 2\n4 1\n3 6\n1 2 1 3 4 1\n3 5\n1 2 1 3 4"], "outputs": ["4\n2\n4\n4"]} | 706 | 68 |
coding | Solve the programming task below in a Python markdown code block.
# Introduction
You are the developer working on a website which features a large counter on its homepage, proudly displaying the number of happy customers who have downloaded your companies software.
You have been tasked with adding an effect to this c... | {"functional": "_inputs = [['1250'], ['0050'], ['0000']]\n_outputs = [[[[0, 1], [0, 1, 2], [0, 1, 2, 3, 4, 5], [0]]], [[[0], [0], [0, 1, 2, 3, 4, 5], [0]]], [[[0], [0], [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_to... | 257 | 245 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements [Hindi] ,[Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
The Euler totient function $\varphi(N)$ is defined as the number of integers between $1$ and $N$ (inclusive) which are coprime with $N$.
You are give... | {"inputs": ["2\n6 2\n8 4"], "outputs": ["2\n2 1\n3 1\n1\n2 3"]} | 452 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Andrewid the Android is a galaxy-famous detective. He is now chasing a criminal hiding on the planet Oxa-5, the planet almost fully covered with water.
The only dry land there is an archipelago of n narrow islands located in a row. For more comfort let'... | {"inputs": ["2 1\n1 2\n5 6\n1\n", "2 1\n1 2\n5 6\n1\n", "2 1\n1 2\n5 3\n2\n", "2 1\n0 2\n5 3\n2\n", "2 1\n1 2\n5 6\n0\n", "2 1\n1 2\n5 10\n1\n", "2 1\n1 2\n5 10\n2\n", "2 1\n1 1\n100 100\n5\n"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 741 | 172 |
coding | Solve the programming task below in a Python markdown code block.
One day, Chef prepared D brand new dishes. He named the i-th dish by a string Si. After the cooking, he decided to categorize each of these D dishes as special or not.
A dish Si is called special if it's name (i.e. the string Si) can be represented in t... | {"inputs": ["3\naba\nabac\nabcd", "3\naba\nabac\naacd", "3\nbca\nb`dc\naabd", "3\ncdd\n_a_a\n_ed[", "3\nfda\n`a`a\nb`Ze", "3\naba\nabac\ndaca", "3\naba\nabac\ndaac", "3\naba\nabac\nadac"], "outputs": ["YES\nNO\nNO", "YES\nNO\nNO\n", "NO\nNO\nNO\n", "YES\nYES\nNO\n", "NO\nYES\nNO\n", "YES\nNO\nNO\n", "YES\nNO\nNO\n", "Y... | 494 | 163 |
coding | Solve the programming task below in a Python markdown code block.
Given an empty array A of infinite length and a positive integer K you have to process
Q queries of type:
- ! l r x: Fill the value x in all the empty places in the array from index l to r (both inclusive).
- ? l r: Print the number of prime factor... | {"inputs": ["20 5\n? 1 5\n! 3 5 4\n? 1 5\n! 1 4 15\n? 1 5"], "outputs": ["0\n1\n2"]} | 483 | 54 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
After IOI Ilya decided to make a business. He found a social network called "TheScorpyBook.com". It currently has N registered users. As in any social network two users can be friends. ... | {"inputs": ["4\n0111\n1000\n1000\n1000", "4\n1111\n1000\n1000\n1000", "4\n0111\n1100\n0000\n1001", "4\n1111\n1010\n1000\n1010", "4\n0011\n0000\n0000\n1001", "4\n1111\n1100\n0000\n1001", "4\n0110\n1000\n0000\n1001", "4\n0011\n1000\n0000\n1000"], "outputs": ["6", "6\n", "2\n", "4\n", "0\n", "2\n", "2\n", "2\n"]} | 362 | 221 |
coding | Solve the programming task below in a Python markdown code block.
There are initially X people in a room.
You are given an array A of length N which describes the following events:
If A_{i} ≥ 0, then A_{i} people enter the room at i-th minute. For e.g. if A_{2} = 3, then 3 people enter the room at the 2-nd minute.
If... | {"inputs": ["3\n5 8\n0 3 3 -13 5\n4 5\n0 -2 2 3\n3 5\n-2 5 -2\n"], "outputs": ["14\n8\n8\n"]} | 572 | 57 |
coding | Solve the programming task below in a Python markdown code block.
poly
The poly tool returns the coefficients of a polynomial with the given sequence of roots.
print numpy.poly([-1, 1, 1, 10]) #Output : [ 1 -11 9 11 -10]
roots
The roots tool returns the roots of a polynomial with the given coefficients... | {"inputs": ["1.1 2 3\n0\n"], "outputs": ["3.0\n"]} | 508 | 24 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
On an 2 x 3 board, there are five tiles labeled from 1 to 5, and an empty square represented by 0. A move consists of choosing 0 and a 4-directionally adjacent number and swapping it.
The state of the board is solved ... | {"functional": "def check(candidate):\n assert candidate(board = [[1,2,3],[4,0,5]]) == 1\n assert candidate(board = [[1,2,3],[5,4,0]]) == -1\n assert candidate(board = [[4,1,2],[5,0,3]]) == 5\n\n\ncheck(Solution().slidingPuzzle)"} | 168 | 87 |
coding | 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"]} | 408 | 22 |
coding | Solve the programming task below in a Python markdown code block.
Monocarp has decided to buy a new TV set and hang it on the wall in his flat. The wall has enough free space so Monocarp can buy a TV set with screen width not greater than $a$ and screen height not greater than $b$. Monocarp is also used to TV sets with... | {"inputs": ["4 2 6 4\n", "1 1 1 1\n", "3 3 2 4\n", "3 3 2 6\n", "4 2 4 3\n", "5 5 1 1\n", "3 3 2 4\n", "4 2 4 3\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "0\n", "5\n", "1\n", "0\n"]} | 628 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian] and [Mandarin Chinese]
Chef is playing Need For Speed. Currently, his car is running on a straight road with a velocity $U$ metres per second and approaching a $90^{\circ}$ turn which is $S$ metres away from him. To ... | {"inputs": ["3\n1 1 1 1\n2 1 1 1\n2 2 1 1"], "outputs": ["Yes\nNo\nYes"]} | 568 | 40 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array arr that represents a permutation of numbers from 1 to n.
You have a binary string of size n that initially has all its bits set to zero. At each step i (assuming both the binary string and arr are 1-in... | {"functional": "def check(candidate):\n assert candidate(arr = [3,5,1,2,4], m = 1) == 4\n assert candidate(arr = [3,1,5,4,2], m = 2) == -1\n assert candidate(arr = [1], m = 1) == 1\n assert candidate(arr = [2,1], m = 2) == 2\n\n\ncheck(Solution().findLatestStep)"} | 197 | 106 |
coding | Solve the programming task below in a Python markdown code block.
The next lecture in a high school requires two topics to be discussed. The $i$-th topic is interesting by $a_i$ units for the teacher and by $b_i$ units for the students.
The pair of topics $i$ and $j$ ($i < j$) is called good if $a_i + a_j > b_i + b_j$... | {"inputs": ["3\n2 3 4\n1 2 3\n", "3\n2 3 4\n1 2 3\n", "3\n2 3 2\n0 2 3\n", "3\n2 3 2\n1 2 3\n", "3\n2 3 2\n0 0 3\n", "3\n2 3 1\n0 0 3\n", "3\n0 3 1\n0 0 3\n", "3\n0 3 1\n0 0 2\n"], "outputs": ["3\n", "3\n", "2\n", "1\n", "3\n", "2\n", "2\n", "2\n"]} | 347 | 166 |
coding | Solve the programming task below in a Python markdown code block.
Consider writing each of the integers from 1 to N \times M in a grid with N rows and M columns, without duplicates. Takahashi thinks it is not fun enough, and he will write the numbers under the following conditions:
* The largest among the values in th... | {"inputs": ["0 2\n4 3\n3 4", "2 2\n6 4\n4 4", "2 2\n6 4\n5 4", "0 2\n8 3\n3 4", "2 2\n6 1\n5 4", "0 2\n8 3\n3 0", "2 2\n6 2\n5 4", "0 2\n7 3\n3 0"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "1\n", "0\n", "1\n"]} | 464 | 142 |
coding | Solve the programming task below in a Python markdown code block.
Valera loves his garden, where n fruit trees grow.
This year he will enjoy a great harvest! On the i-th tree b_{i} fruit grow, they will ripen on a day number a_{i}. Unfortunately, the fruit on the tree get withered, so they can only be collected on day... | {"inputs": ["1 3\n5 3\n", "1 3\n5 3\n", "1 3\n1 3\n", "1 3\n1 6\n", "1 1\n2 4\n", "1 1\n3 4\n", "1 0\n3 4\n", "1 0\n3 2\n"], "outputs": ["3\n", "3\n", "3\n", "6\n", "2\n", "2\n", "0\n", "0\n"]} | 486 | 118 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
Two strings word1 and word2 are considered almost equivalent if the differences between the frequencies of each letter from 'a' to 'z' between word1 and word2 is at most 3.
Given two strings word1 and word2, each of l... | {"functional": "def check(candidate):\n assert candidate(word1 = \"aaaa\", word2 = \"bccb\") == False\n assert candidate(word1 = \"abcdeef\", word2 = \"abaaacc\") == True\n assert candidate(word1 = \"cccddabba\", word2 = \"babababab\") == True\n\n\ncheck(Solution().checkAlmostEquivalent)"} | 141 | 85 |
coding | Solve the programming task below in a Python markdown code block.
In this Kata, you will be given a number and your task will be to return the nearest prime number.
```Haskell
solve(4) = 3. The nearest primes are 3 and 5. If difference is equal, pick the lower one.
solve(125) = 127
```
We'll be testing for numbers ... | {"functional": "_inputs = [[3], [11], [4], [110], [1110], [3000], [35000], [350000], [3500000], [10000000000]]\n_outputs = [[3], [11], [3], [109], [1109], [2999], [34981], [350003], [3499999], [10000000019]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n retur... | 186 | 276 |
coding | Solve the programming task below in a Python markdown code block.
There are N islands lining up from west to east, connected by N-1 bridges.
The i-th bridge connects the i-th island from the west and the (i+1)-th island from the west.
One day, disputes took place between some islands, and there were M requests from the... | {"inputs": ["2 1\n1 2\n", "5 2\n2 4\n2 5", "5 2\n1 5\n2 5", "5 1\n1 5\n2 5", "5 1\n0 5\n2 5", "5 2\n1 4\n2 8", "5 2\n0 5\n2 5", "4 1\n1 5\n2 5"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 302 | 139 |
coding | Solve the programming task below in a Python markdown code block.
Takahashi lives in another world. There are slimes (creatures) of 10000 colors in this world. Let us call these colors Color 1, 2, ..., 10000.
Takahashi has N slimes, and they are standing in a row from left to right. The color of the i-th slime from th... | {"inputs": ["3\n0 2 1", "3\n1 2 2", "3\n1 4 2", "3\n1 3 2", "3\n2 3 2", "3\n2 3 1", "3\n2 2 1", "3\n2 2 2"], "outputs": ["0\n", "1\n", "0\n", "0\n", "0\n", "0\n", "1\n", "1\n"]} | 341 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Almost every text editor has a built-in function of center text alignment. The developers of the popular in Berland text editor «Textpad» decided to introduce this functionality into the fourth release of the product.
You are to implement the alignment ... | {"inputs": ["U\n", "T\n", "V\n", "W\n", "X\n", "Y\n", "Z\n", "0\n2\n"], "outputs": ["***\n*U*\n***", "***\n*T*\n***\n", "***\n*V*\n***\n", "***\n*W*\n***\n", "***\n*X*\n***\n", "***\n*Y*\n***\n", "***\n*Z*\n***\n", "***\n*0*\n*2*\n***"]} | 351 | 127 |
coding | Solve the programming task below in a Python markdown code block.
There is a new prodigy in town and he has challenged people to a game. They have to give him an integer N and he will immediately respond with a number which has more than N factors.
What the prodigy really does is to do some complex calculations in his ... | {"inputs": ["3\n3\n5\n12345678"], "outputs": ["win 6\nwin 12\nlose"]} | 308 | 34 |
coding | Solve the programming task below in a Python markdown code block.
Manao is taking part in a quiz. The quiz consists of n consecutive questions. A correct answer gives one point to the player. The game also has a counter of consecutive correct answers. When the player answers a question correctly, the number on this cou... | {"inputs": ["2 0 2\n", "2 2 2\n", "3 2 2\n", "2 1 2\n", "3 3 2\n", "2 2 3\n", "3 3 3\n", "6 3 2\n"], "outputs": [" 0", " 4", " 2", " ... | 543 | 107 |
coding | Solve the programming task below in a Python markdown code block.
Recently, Chef visited his doctor. The doctor advised Chef to drink at least 2000 ml of water each day.
Chef drank X ml of water today. Determine if Chef followed the doctor's advice or not.
------ Input Format ------
- The first line contains a sin... | {"inputs": ["3\n2999\n1450\n2000\n"], "outputs": ["YES\nNO\nYES\n"]} | 356 | 33 |
coding | Solve the programming task below in a Python markdown code block.
Chef went shopping and bought items worth X rupees (1 ≤ X ≤ 100). Unfortunately, Chef only has a single 100 rupees note.
Since Chef is weak at maths, can you help Chef in calculating what money he should get back after paying 100 rupees for those items?... | {"inputs": ["3\n1\n25\n100\n"], "outputs": ["99\n75\n0\n"]} | 282 | 29 |
coding | Solve the programming task below in a Python markdown code block.
Write function bmi that calculates body mass index (bmi = weight / height ^ 2).
if bmi <= 18.5 return "Underweight"
if bmi <= 25.0 return "Normal"
if bmi <= 30.0 return "Overweight"
if bmi > 30 return "Obese"
Also feel free to reuse/extend the follo... | {"functional": "_inputs = [[50, 1.8], [80, 1.8], [90, 1.8], [110, 1.8], [50, 1.5]]\n_outputs = [['Underweight'], ['Normal'], ['Overweight'], ['Obese'], ['Normal']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=to... | 103 | 212 |
coding | Solve the programming task below in a Python markdown code block.
Complete the solution so that it returns the number of times the search_text is found within the full_text.
```python
search_substr( fullText, searchText, allowOverlap = true )
```
so that overlapping solutions are (not) counted. If the searchText is e... | {"functional": "_inputs = [['aa_bb_cc_dd_bb_e', 'bb'], ['aaabbbcccc', 'bbb'], ['aaacccbbbcccc', 'cc'], ['aaa', 'aa'], ['aaa', 'aa', False], ['aaabbbaaa', 'bb', False], ['a', ''], ['', 'a'], ['', ''], ['', '', False]]\n_outputs = [[2], [1], [5], [2], [1], [1], [0], [0], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-... | 199 | 249 |
coding | Solve the programming task below in a Python markdown code block.
Some integral numbers are odd. All are more odd, or less odd, than others.
Even numbers satisfy `n = 2m` ( with `m` also integral ) and we will ( completely arbitrarily ) think of odd numbers as `n = 2m + 1`.
Now, some odd numbers can be more odd than... | {"functional": "_inputs = [[[1, 2]], [[1, 3]], [[1, 5]], [[0]], [[1, 3, 5, 7]], [[2, 4]], [[-1]], [[-1, 0, 1]], [[-3, 3]], [[-5, 3]], [[-42, -41, -40, -39, -38, -37, -36, -35, -34, -33, -32, -31, -30, -29, -28, -27, -26, -25, -24, -23, -22, -21, -20, -19, -18, -17, -16, -15, -14, -13, -12, -11, -10, -9, -8, -7, -6, -5,... | 265 | 570 |
coding | Solve the programming task below in a Python markdown code block.
Babidi has summoned Majin Vegeta. He orders him to kill Supreme Kai. But Vegeta wants to get out of his control.
Babidi has laid out a trap. Vegeta is standing at the $nth$ level of mind control. In order to defeat Babidi's trap, he needs to reach $mth$... | {"inputs": ["2\n3 7\n1 1023"], "outputs": ["5\n2177"]} | 429 | 28 |
coding | Solve the programming task below in a Python markdown code block.
One day Vasya painted a Cartesian coordinate system on a piece of paper and marked some set of points (x1, y1), (x2, y2), ..., (xn, yn). Let's define neighbors for some fixed point from the given set (x, y):
* point (x', y') is (x, y)'s right neighbo... | {"inputs": ["1\n262 5\n", "1\n357 5\n", "1\n271 5\n", "1\n520 5\n", "1\n206 5\n", "1\n206 8\n", "1\n487 56\n", "1\n143 75\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 506 | 120 |
coding | Solve the programming task below in a Python markdown code block.
The research center Q has developed a new multi-core processor. The processor consists of n cores and has k cells of cache memory. Consider the work of this processor.
At each cycle each core of the processor gets one instruction: either do nothing, or ... | {"inputs": ["1 1 1\n0\n", "1 1 1\n1\n", "1 1 1\n1\n", "1 1 2\n1\n", "1 1 1\n0\n", "2 1 1\n1\n1\n", "2 1 1\n1\n0\n", "2 1 1\n0\n1\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "1\n1\n", "0\n0\n", "0\n0\n"]} | 602 | 130 |
coding | Solve the programming task below in a Python markdown code block.
Santa Claus likes palindromes very much. There was his birthday recently. k of his friends came to him to congratulate him, and each of them presented to him a string s_{i} having the same length n. We denote the beauty of the i-th string by a_{i}. It ca... | {"inputs": ["1 1\ne -1\n", "1 2\nyy 1\n", "1 2\nyy 1\n", "1 1\ne -1\n", "1 2\nzy 1\n", "1 1\nf -1\n", "0 1\nf -1\n", "0 1\ne -1\n"], "outputs": ["0\n", "1\n", "1\n", "0\n", "0\n", "0\n", "0\n", "0\n"]} | 506 | 118 |
coding | Solve the programming task below in a Python markdown code block.
Ken loves ken-ken-pa (Japanese version of hopscotch). Today, he will play it on a directed graph G.
G consists of N vertices numbered 1 to N, and M edges. The i-th edge points from Vertex u_i to Vertex v_i.
First, Ken stands on Vertex S. He wants to reac... | {"inputs": ["3 0\n1 2", "6 0\n1 2", "2 0\n1 2", "2 0\n1 2\n", "3 3\n1 2\n2 3\n2 1\n1 2", "3 1\n1 1\n3 3\n3 1\n1 2", "3 3\n1 1\n2 3\n3 1\n1 2", "3 3\n1 2\n2 1\n2 1\n1 2"], "outputs": ["-1\n", "-1\n", "-1", "-1\n", "1\n", "0\n", "-1\n", "1\n"]} | 514 | 159 |
coding | Solve the programming task below in a Python markdown code block.
# Task
You're given a substring s of some cyclic string. What's the length of the smallest possible string that can be concatenated to itself many times to obtain this cyclic string?
# Example
For` s = "cabca"`, the output should be `3`
`"cabca"` i... | {"functional": "_inputs = [['cabca'], ['aba'], ['ccccccccccc'], ['abaca']]\n_outputs = [[3], [2], [1], [4]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len... | 165 | 177 |
coding | Solve the programming task below in a Python markdown code block.
There are N squares arranged in a row from left to right. The height of the i-th square from the left is H_i.
For each square, you will perform either of the following operations once:
- Decrease the height of the square by 1.
- Do nothing.
Determine i... | {"inputs": ["1\n1\n", "4\n1 5 2 1", "4\n1 5 2 2", "4\n0 5 2 2", "4\n0 8 2 2", "4\n0 8 4 2", "4\n0 1 4 2", "4\n0 1 4 1"], "outputs": ["Yes\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 244 | 121 |
coding | Solve the programming task below in a Python markdown code block.
Polycarp plays a well-known computer game (we won't mention its name). In this game, he can craft tools of two types — shovels and swords. To craft a shovel, Polycarp spends two sticks and one diamond; to craft a sword, Polycarp spends two diamonds and o... | {"inputs": ["1\n2 75\n", "1\n543 1\n", "1\n531 2\n", "1\n531 0\n", "1\n6 176\n", "1\n543 0\n", "1\n2 176\n", "1\n723 1\n"], "outputs": ["2\n", "1\n", "2\n", "0\n", "6\n", "0\n", "2\n", "1\n"]} | 307 | 117 |
coding | Solve the programming task below in a Python markdown code block.
You are a teacher at a cram school for elementary school pupils.
One day, you showed your students how to calculate division of fraction in a class of mathematics. Your lesson was kind and fluent, and it seemed everything was going so well - except for ... | {"inputs": ["1 3\n1 6\n3 9\n2 200\n7 99\n0 0", "1 3\n1 6\n6 9\n2 377\n7 99\n0 0", "1 3\n1 2\n6 9\n2 377\n7 99\n0 0", "2 3\n1 6\n6 9\n2 200\n7 24\n0 0", "1 3\n1 6\n6 18\n2 457\n7 2\n0 0", "1 5\n1 6\n6 18\n2 457\n7 2\n0 0", "2 7\n2 8\n3 4\n2 200\n2 62\n0 0", "2 7\n2 8\n5 8\n2 200\n2 62\n0 0"], "outputs": ["0 1\n1 1\n0 1\... | 476 | 414 |
coding | Solve the programming task below in a Python markdown code block.
> In information theory and computer science, the Levenshtein distance is a string metric for measuring the difference between two sequences. Informally, the Levenshtein distance between two words is the minimum number of single-character edits (i.e. ins... | {"functional": "_inputs = [['kitten', 'sitting'], ['book', 'back'], ['book', 'book'], ['qlzcfayxiz', 'vezkvgejzb'], ['nayvyedosf', 'sjxen'], ['sjxen', 'sjxen'], ['peter', 'peter']]\n_outputs = [[3], [2], [0], [9], [9], [0], [0]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, f... | 137 | 238 |
coding | Solve the programming task below in a Python markdown code block.
Chef wants to cross a hallway of N doors. These N doors are represented as a string. Each door is initially either open or close, represented by 1 or 0 respectively. Chef is required to go through all the doors one by one in the order that they appear, s... | {"inputs": ["3\n111\n010\n10011"], "outputs": ["0\n3\n2"]} | 522 | 30 |
coding | Solve the programming task below in a Python markdown code block.
Consider the numbers `6969` and `9116`. When you rotate them `180 degrees` (upside down), these numbers remain the same. To clarify, if we write them down on a paper and turn the paper upside down, the numbers will be the same. Try it and see! Some numbe... | {"functional": "_inputs = [[0, 10], [10, 100], [100, 1000], [1000, 10000], [10000, 15000], [15000, 20000], [60000, 70000], [60000, 130000]]\n_outputs = [[3], [4], [12], [20], [6], [9], [15], [55]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.iscl... | 329 | 273 |
coding | Solve the programming task below in a Python markdown code block.
The only difference between easy and hard versions is that you should complete all the projects in easy version but this is not necessary in hard version.
Polycarp is a very famous freelancer. His current rating is $r$ units.
Some very rich customers a... | {"inputs": ["2 4\n2 -3\n4 -3\n", "2 4\n2 -3\n4 -3\n", "2 4\n1 -3\n4 -3\n", "3 1\n3 -4\n3 4\n3 4\n", "3 1\n3 -4\n3 4\n3 4\n", "3 1\n2 -4\n3 4\n3 4\n", "3 4\n4 6\n10 -2\n8 -1\n", "3 4\n2 6\n10 -2\n8 -1\n"], "outputs": ["1\n", "1", "1\n", "0\n", "0", "0\n", "3\n", "3\n"]} | 525 | 170 |
coding | Solve the programming task below in a Python markdown code block.
Write a function called `LCS` that accepts two sequences and returns the longest subsequence common to the passed in sequences.
### Subsequence
A subsequence is different from a substring. The terms of a subsequence need not be consecutive terms of the ... | {"functional": "_inputs = [['a', 'b'], ['a', 'a'], ['abc', 'ac'], ['abcdef', 'abc'], ['abcdef', 'acf'], ['anothertest', 'notatest'], ['132535365', '123456789'], ['finaltest', 'zzzfinallyzzz']]\n_outputs = [[''], ['a'], ['ac'], ['abc'], ['acf'], ['nottest'], ['12356'], ['final']]\nimport math\ndef _deep_eq(a, b, tol=1e-... | 424 | 249 |
coding | Solve the programming task below in a Python markdown code block.
We have a deck consisting of N cards. Each card has an integer written on it. The integer on the i-th card from the top is a_i.
Two people X and Y will play a game using this deck. Initially, X has a card with Z written on it in his hand, and Y has a ca... | {"inputs": ["5 1 1\n1 0 1 1 1", "5 1 4\n0 1 6 0 2", "5 2 1\n1 1 1 1 1", "5 1 1\n1 0 1 1 0", "5 0 1\n0 0 2 1 1", "5 1 4\n1 1 6 0 2", "5 2 1\n1 1 1 1 0", "5 1 1\n1 0 1 1 2"], "outputs": ["0\n", "2\n", "0\n", "1\n", "0\n", "2\n", "1\n", "1\n"]} | 407 | 174 |
coding | Solve the programming task below in a Python markdown code block.
Write a function called that takes a string of parentheses, and determines if the order of the parentheses is valid. The function should return `true` if the string is valid, and `false` if it's invalid.
## Examples
```
"()" => true
")(()... | {"functional": "_inputs = [[')'], ['('], [''], ['hi)('], ['hi(hi)'], ['hi(hi)('], ['((())()())'], ['(c(b(a)))(d)'], ['hi(hi))('], ['())(()']]\n_outputs = [[False], [False], [True], [False], [True], [False], [True], [True], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isi... | 211 | 233 |
coding | Solve the programming task below in a Python markdown code block.
Reziba has many magic gems. Each magic gem can be split into $M$ normal gems. The amount of space each magic (and normal) gem takes is $1$ unit. A normal gem cannot be split.
Reziba wants to choose a set of magic gems and split some of them, so the tota... | {"inputs": ["4 2\n", "3 2\n", "1 2\n", "1 3\n", "1 4\n", "1 5\n", "2 2\n", "2 3\n"], "outputs": ["5\n", "3\n", "1\n", "1\n", "1\n", "1\n", "2\n", "1\n"]} | 531 | 86 |
coding | Solve the programming task below in a Python markdown code block.
You are given positive integers N and K.
You have to construct an array A of length N such that :
1 ≤ A_{i} ≤ 10^{18}
\sum_{i=1}^{N} \sum_{j=i}^{N} F(i,j) = K, where F(i,j) denotes the [gcd] of all elements of the subarray A[i, j].
If multiple such ar... | {"inputs": ["3\n1 5\n2 4\n3 1\n"], "outputs": ["5\n1 2\n-1\n"]} | 542 | 33 |
coding | Solve the programming task below in a Python markdown code block.
Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array.... | {"inputs": ["4 1 2\n", "1 1 0\n", "2 1 1\n", "2 2 0\n", "3 1 2\n", "3 2 2\n", "3 3 1\n", "4 2 0\n"], "outputs": ["6\n", "1\n", "1\n", "0\n", "0\n", "1\n", "0\n", "2\n"]} | 604 | 102 |
coding | Solve the programming task below in a Python markdown code block.
In this challenge, you will be given an array $\mbox{B}$ and must determine an array $\mbox{A}$. There is a special rule: For all $\boldsymbol{i}$, $A[i]\leq B[i]$. That is, $A[i]$ can be any number you choose such that $1\leq A[i]\leq B[i]$. Your ta... | {"inputs": ["1\n5\n10 1 10 1 10\n"], "outputs": ["36\n"]} | 681 | 30 |
coding | Solve the programming task below in a Python markdown code block.
Sheldon is a little geek living in Texas. While his friends like to play outside, little Sheldon likes to play around with ICs and lasers in his house. He decides to build N clap activated toggle machines each with one power inlet and one outlet. Each ma... | {"inputs": ["4\n4 0\n4 47\n1 0\n1 1"], "outputs": ["OFF\nON\nOFF\nON"]} | 616 | 35 |
coding | Solve the programming task below in a Python markdown code block.
# Task
You know the slogan `p`, which the agitators have been chanting for quite a while now. Roka has heard this slogan a few times, but he missed almost all of them and grasped only their endings. You know the string `r` that Roka has heard.
You n... | {"functional": "_inputs = [['glorytoukraine', 'ukraineaineaine'], ['glorytoukraine', 'ukraineaineainee'], ['glorytoukraine', 'einene'], ['programming', 'ingmingmming'], ['mcoecqwmjdudc', 'dcoecqwmjdudcdcudc'], ['erjernhxvbqfjsj', 'ernhxvbqfjsjjrnhxvbqfjsjjernhxvbqfjsj'], ['dhgusdlifons', 'lifonsssdlifonsgusdlifonssnsdl... | 307 | 316 |
coding | Solve the programming task below in a Python markdown code block.
"Teishi-zushi", a Japanese restaurant, is a plain restaurant with only one round counter. The outer circumference of the counter is C meters. Customers cannot go inside the counter.
Nakahashi entered Teishi-zushi, and he was guided to the counter. Now, t... | {"inputs": ["3 20\n2 80\n9 120\n16 1\n", "3 20\n2 80\n9 1\n16 120\n", "1 100000000000000\n50000000000000 1\n", "15 10000000000\n400000000 1000000000\n800000000 1000000000\n1900000000 1000000000\n2400000000 1000000000\n2900000000 1000000000\n3300000000 1000000000\n3700000000 1000000000\n3800000000 1000000000\n4000000000... | 613 | 463 |
coding | Solve the programming task below in a Python markdown code block.
There are three sticks with integer lengths $l_1, l_2$ and $l_3$.
You are asked to break exactly one of them into two pieces in such a way that:
both pieces have positive (strictly greater than $0$) integer length;
the total length of the pieces is eq... | {"inputs": ["1\n1 98 99\n", "1\n1 98 99\n", "1\n1 98 186\n", "1\n2 98 186\n", "1\n2 98 239\n", "1\n1 98 239\n", "1\n1 98 108\n", "1\n2465 1 1\n"], "outputs": ["YES\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]} | 530 | 140 |
coding | Solve the programming task below in a Python markdown code block.
### Happy Holidays fellow Code Warriors!
Now, Dasher! Now, Dancer! Now, Prancer, and Vixen! On, Comet! On, Cupid! On, Donder and Blitzen! That's the order Santa wanted his reindeer...right? What do you mean he wants them in order by their last names!? L... | {"functional": "_inputs = [[['Kenjiro Mori', 'Susumu Tokugawa', 'Juzo Okita', 'Akira Sanada']], [[]], [['Yasuo Kodai', 'Kenjiro Sado', 'Daisuke Aihara', 'Susumu Shima', 'Akira Sanada', 'Yoshikazu Okita', 'Shiro Yabu', 'Sukeharu Nanbu', 'Sakezo Yamamoto', 'Hikozaemon Ohta', 'Juzo Mori', 'Saburo Tokugawa']], [['Daisuke M... | 338 | 548 |
coding | Solve the programming task below in a Python markdown code block.
You are given a text that consists of lowercase Latin letters, spaces and punctuation marks (dot, comma, exclamation mark and question mark). A word is defined as a sequence of consecutive Latin letters.
Your task is to add spaces to the text by the fol... | {"inputs": ["x\n", "w\n", "y\n", "xx\n", "yx\n", "xy\n", "wy\n", "x,x\n"], "outputs": ["x\n", "w\n", "y\n", "xx\n", "yx\n", "xy\n", "wy\n", "x, x\n"]} | 291 | 73 |
coding | Solve the programming task below in a Python markdown code block.
Alice, Bob, and Charlie have X, Y, and Z chocolates respectively.
Find whether you can redistribute the chocolates such that:
Each person has at least one chocolate;
No two people have same number of chocolates;
No chocolate is left after redistributio... | {"inputs": ["4\n1 2 3\n1 1 1\n2 2 2\n2 1 1\n"], "outputs": ["YES\nNO\nYES\nNO\n"]} | 412 | 44 |
coding | Solve the programming task below in a Python markdown code block.
You are given a polynomial of degree N with integer coefficients: f(x)=a_Nx^N+a_{N-1}x^{N-1}+...+a_0. Find all prime numbers p that divide f(x) for every integer x.
Constraints
* 0 \leq N \leq 10^4
* |a_i| \leq 10^9(0\leq i\leq N)
* a_N \neq 0
* All va... | {"inputs": ["0\n8", "0\n5", "0\n3", "0\n7", "0\n63", "0\n56", "0\n15", "0\n54"], "outputs": ["2\n", "5\n", "3\n", "7\n", "3\n7\n", "2\n7\n", "3\n5\n", "2\n3\n"]} | 229 | 90 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Let's say that `"g" is happy` in the given string, if there is another "g" immediately to the right or to the left of it.
Find out if all "g"s in the given string are happy.
# Example
For `str = "gg0gg3gg0gg"`, the output should be `true`.
... | {"functional": "_inputs = [['gg0gg3gg0gg'], ['gog'], ['ggg ggg g ggg'], ['A half of a half is a quarter.'], ['good grief'], ['bigger is ggooder'], ['gggggggggg']]\n_outputs = [[True], [False], [False], [True], [False], [True], [True]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstanc... | 180 | 222 |
coding | Solve the programming task below in a Python markdown code block.
Heidi's friend Jenny is asking Heidi to deliver an important letter to one of their common friends. Since Jenny is Irish, Heidi thinks that this might be a prank. More precisely, she suspects that the message she is asked to deliver states: "Send the foo... | {"inputs": ["4\n0 1 4\n0 2 2\n2 3 3\n", "3\n1 0 5987\n2 0 8891\n", "3\n1 0 5987\n2 0 8891\n", "3\n1 0 5987\n2 1 8891\n", "4\n0 1 4\n0 2 2\n1 3 3\n", "4\n0 1 4\n0 2 4\n2 3 4\n", "4\n0 1 6\n0 2 4\n1 3 4\n", "3\n1 0 1844\n2 0 8891\n"], "outputs": ["5\n", "8891\n", "8891\n", "14878\n", "7\n", "8\n", "10\n", "8891\n"]} | 639 | 228 |
coding | Solve the programming task below in a Python markdown code block.
We define f(x)=\begin{cases} f(x \oplus reverse(x))+1 & \text{if } x \neq 0 \\ 0 & \text{otherwise} \end{cases}
Here, \oplus denotes the [bitwise XOR operation] and reverse is a function that takes a postive integer, reverses its binary representation... | {"inputs": ["8\n1\n2\n3\n5\n8\n13\n21\n34\n"], "outputs": ["1\n4\n10\n58\n578\n20098\n5236738\n24641495\n"]} | 673 | 68 |
coding | Solve the programming task below in a Python markdown code block.
Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When he comes home in the evening, Vasya takes off the used socks and throws them away. Every m-th day (at days with numbers m, 2m, 3m, .... | {"inputs": ["2 2\n", "9 3\n", "1 2\n", "2 3\n", "4 4\n", "4 4\n", "1 2\n", "4 4\n"], "outputs": ["3\n", "13\n", "1\n", "2\n", "5\n", "5\n", "1\n", "5\n"]} | 308 | 87 |
coding | Solve the programming task below in a Python markdown code block.
You are given $n$ sticks with positive integral length $a_1, a_2, \ldots, a_n$.
You can perform the following operation any number of times (possibly zero):
choose one stick, then either increase or decrease its length by $1$. After each operation, all... | {"inputs": ["4\n3\n1 2 3\n4\n7 3 7 3\n5\n3 4 2 1 1\n8\n3 1 4 1 5 9 2 6\n"], "outputs": ["2\n4\n1\n1\n"]} | 482 | 68 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
We have n cities labeled from 1 to n. Two different cities with labels x and y are directly connected by a bidirectional road if and only if x and y share a common divisor strictly greater than some threshold. More fo... | {"functional": "def check(candidate):\n assert candidate(n = 6, threshold = 2, queries = [[1,4],[2,5],[3,6]]) == [False,False,True]\n assert candidate(n = 6, threshold = 0, queries = [[4,5],[3,4],[3,2],[2,6],[1,3]]) == [True,True,True,True,True]\n assert candidate(n = 5, threshold = 1, queries = [[4,5],[4,5],[... | 247 | 144 |
coding | Solve the programming task below in a Python markdown code block.
Chef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.
Let F_{d}(x) equals to the number o... | {"inputs": ["3\n2\n6\n011", "3\n0\n6\n010", "3\n0\n3\n010", "3\n1\n3\n010", "3\n1\n1\n010", "3\n2\n1\n010", "3\n2\n1\n011", "3\n2\n1\n111"], "outputs": ["3\n9\n39\n", "0\n9\n31\n", "0\n6\n31\n", "1\n6\n31\n", "1\n1\n31\n", "3\n1\n31\n", "3\n1\n39\n", "3\n1\n1709\n"]} | 323 | 168 |
coding | Solve the programming task below in a Python markdown code block.
Zonal Computing Olympiad 2015, 29 Nov 2014
We say that two integers x and y have a variation of at least K, if |x − y| ≥ K (the absolute value of their difference is at least K). Given a sequence of N integers a1,a2,...,aN and K, the total variation cou... | {"inputs": ["3 1\n3 1 3"], "outputs": ["2"]} | 378 | 20 |
coding | Solve the programming task below in a Python markdown code block.
You are given strings s and t, consisting of lowercase English letters.
You will create a string s' by freely rearranging the characters in s.
You will also create a string t' by freely rearranging the characters in t.
Determine whether it is possible to... | {"inputs": ["x\nww", "y\nww", "y\nvw", "z\nvw", "z\nvv", "{\nvv", "z\nwv", "y\nwv"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]} | 363 | 80 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
All bandits are afraid of Sheriff. Sheriff constantly fights crime, but when bandits lay low, he gets bored and starts to entertain himself.
This time Sheriff gathered all the bandits in his ga... | {"inputs": ["2\n3\n1 2 3\n5\n2 3 1 5 4", "2\n2\n1 2 3\n5\n2 3 1 5 4", "2\n3\n1 2 3\n5\n4 3 1 5 2", "2\n3\n2 1 3\n5\n4 3 1 5 2", "2\n2\n1 2 3\n5\n4 3 1 5 2", "2\n1\n1 2 3\n5\n2 3 1 5 4", "2\n1\n1 2 3\n5\n4 3 1 5 2", "2\n2\n2 1 3\n5\n4 3 1 5 2"], "outputs": ["1\n6", "1\n6\n", "1\n5\n", "2\n5\n", "1\n5\n", "1\n6\n", "1\n5... | 516 | 237 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n availabe seats and n students standing in a room. You are given an array seats of length n, where seats[i] is the position of the ith seat. You are also given the array students of length n, where students... | {"functional": "def check(candidate):\n assert candidate(seats = [3,1,5], students = [2,7,4]) == 4\n assert candidate(seats = [4,1,5,9], students = [1,3,2,6]) == 7\n assert candidate(seats = [2,2,6,6], students = [1,3,2,6]) == 4\n\n\ncheck(Solution().minMovesToSeat)"} | 204 | 107 |
coding | Solve the programming task below in a Python markdown code block.
Animesh and Mohit are playing a game. They have $N$ balls in front of them. All the balls are numbered, not necessarily in any order. Animesh picks a set of ${K}$ balls from the lot each time, checks this set, puts it back into the lot, and repeats this ... | {"inputs": ["4 2\n10 20 30 40\n"], "outputs": ["100\n"]} | 406 | 30 |
coding | Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Sereja has an array A that contains n integers: A_{1}, A_{2}, ..., A_{n}.
Sereja also has an array B that contains n integers B_{1}, B_{2}, ..., B_{n}.
In a single step Sereja can choose two i... | {"inputs": ["1\n5\n2 1 3 0 3\n2 2 0 1 0"], "outputs": ["1"]} | 373 | 34 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A fancy string is a string where no three consecutive characters are equal.
Given a string s, delete the minimum possible number of characters from s to make it fancy.
Return the final string after the deletion. It ca... | {"functional": "def check(candidate):\n assert candidate(s = \"leeetcode\") == \"leetcode\"\n assert candidate(s = \"aaabaaaa\") == \"aabaa\"\n assert candidate(s = \"aab\") == \"aab\"\n\n\ncheck(Solution().makeFancyString)"} | 102 | 64 |
coding | Solve the programming task below in a Python markdown code block.
A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa" and "bb" are not.
Ahcl wants to construct a beautiful string. He has a string $s$, consisting of... | {"inputs": ["3\na???cb\na??bbc\na?b?c\n", "3\na???cb\na??bbc\nc?b?a\n", "3\na???cb\na??bbc\ncab??\n", "3\na???cb\na??bbb\na?b?c\n", "3\na???cb\na??bbc\nc?a?a\n", "3\na???cb\na??bbb\na?c?b\n", "3\na???cb\nbbb??a\na>c?b\n", "3\na???cb\na??bbb\na?a?c\n"], "outputs": ["ababcb\n-1\nacbac\n", "ababcb\n-1\ncabca\n", "ababcb\n... | 524 | 244 |
coding | Solve the programming task below in a Python markdown code block.
Little Petya likes to play very much. And most of all he likes to play the following game:
He is given a sequence of N integer numbers. At each step it is allowed to increase the value of any number by 1 or to decrease it by 1. The goal of the game is t... | {"inputs": ["1\n7\n", "1\n11\n", "1\n13\n", "1\n26\n", "1\n28\n", "2\n10 2\n", "2\n10 4\n", "2\n15 4\n"], "outputs": ["0\n", "0\n", "0\n", "0\n", "0\n", "8\n", "6\n", "11\n"]} | 247 | 100 |
coding | Solve the programming task below in a Python markdown code block.
$n$ students are taking an exam. The highest possible score at this exam is $m$. Let $a_{i}$ be the score of the $i$-th student. You have access to the school database which stores the results of all students.
You can change each student's score as long... | {"inputs": ["2\n4 7\n1 4 0 4\n4 5\n1 1 3 4\n", "2\n4 8\n1 2 3 4\n4 1\n1 4 2 4\n", "2\n4 4\n1 3 3 3\n4 5\n1 2 4 4\n", "2\n4 2\n1 3 3 3\n4 5\n1 2 4 4\n", "2\n4 3\n1 2 5 0\n4 8\n1 2 3 4\n", "2\n4 9\n2 3 3 4\n4 5\n1 2 3 4\n", "2\n4 9\n2 3 3 4\n4 5\n1 2 3 7\n", "2\n4 7\n1 4 0 4\n4 5\n1 1 3 8\n"], "outputs": ["7\n5\n", "8\n1... | 497 | 278 |
coding | Solve the programming task below in a Python markdown code block.
Write a program that will calculate the number of trailing zeros in a factorial of a given number.
`N! = 1 * 2 * 3 * ... * N`
Be careful `1000!` has 2568 digits...
For more info, see: http://mathworld.wolfram.com/Factorial.html
## Examples
```pyth... | {"functional": "_inputs = [[0], [6], [30], [100], [1000], [100000], [1000000000]]\n_outputs = [[0], [1], [7], [24], [249], [24999], [249999998]]\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 isinstan... | 208 | 225 |
coding | Solve the programming task below in a Python markdown code block.
Snuke found a random number generator. It generates an integer between 0 and 2^N-1 (inclusive). An integer sequence A_0, A_1, \cdots, A_{2^N-1} represents the probability that each of these integers is generated. The integer i (0 \leq i \leq 2^N-1) is ge... | {"inputs": ["2\n1 1 1 2", "2\n1 2 1 3", "2\n1 1 1 3", "2\n2 2 1 3", "2\n2 1 1 1", "2\n2 2 1 5", "2\n4 1 1 1", "2\n0 2 1 5"], "outputs": ["0\n166374063\n166374063\n332748121\n", "0\n532396992\n582309210\n449209962\n", "0\n499122181\n499122181\n3\n", "0\n465847369\n665496240\n798595486\n", "0\n5\n5\n5\n", "0\n903173467\n... | 757 | 294 |
coding | Solve the programming task below in a Python markdown code block.
There is an infinite 2-dimensional grid. The robot stands in cell $(0, 0)$ and wants to reach cell $(x, y)$. Here is a list of possible commands the robot can execute:
move north from cell $(i, j)$ to $(i, j + 1)$;
move east from cell $(i, j)$ to $(i +... | {"inputs": ["1\n44 4\n", "1\n7 362\n", "1\n7 454\n", "1\n7 576\n", "1\n9 374\n", "1\n9 525\n", "1\n9 535\n", "1\n9 510\n"], "outputs": ["87\n", "723\n", "907\n", "1151\n", "747\n", "1049\n", "1069\n", "1019\n"]} | 505 | 136 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
A 0-indexed array derived with length n is derived by computing the bitwise XOR (⊕) of adjacent values in a binary array original of length n.
Specifically, for each index i in the range [0, n - 1]:
If i = n - 1, the... | {"functional": "def check(candidate):\n assert candidate(derived = [1,1,0]) == True\n assert candidate(derived = [1,1]) == True\n assert candidate(derived = [1,0]) == False\n\n\ncheck(Solution().doesValidArrayExist)"} | 191 | 65 |
coding | Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of integers arr and an integer target.
You have to find two non-overlapping sub-arrays of arr each with a sum equal target. There can be multiple answers so you have to find an answer where the ... | {"functional": "def check(candidate):\n assert candidate(arr = [3,2,2,4,3], target = 3) == 2\n assert candidate(arr = [7,3,4,7], target = 7) == 2\n assert candidate(arr = [4,3,2,6,2,3,4], target = 6) == -1\n assert candidate(arr = [5,5,4,4,5], target = 3) == -1\n assert candidate(arr = [3,1,1,1,5,1,2,1],... | 144 | 155 |
coding | Solve the programming task below in a Python markdown code block.
Mishka wants to buy some food in the nearby shop. Initially, he has $s$ burles on his card.
Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number $1 \le x \le s$, buy food that costs exactl... | {"inputs": ["6\n1\n1\n44\n3360\n3467\n1100000000\n", "6\n1\n1\n58\n3360\n3467\n1100000000\n", "6\n2\n3\n83\n1320\n7153\n1000000000\n", "6\n1\n1\n58\n3360\n6281\n1100000000\n", "6\n1\n1\n5\n3553\n12345\n1100000100\n", "6\n1\n1\n3\n6735\n12345\n1100000000\n", "6\n1\n1\n18\n3360\n6281\n1100000000\n", "6\n1\n1\n5\n1772\n12... | 497 | 502 |
coding | Solve the programming task below in a Python markdown code block.
Chef is playing a game on the non-negative x-axis. It takes him $1$ second to reach from $i^{th}$ position to $(i-1)^{th}$ position or $(i+1)^{th}$ position. The chef never goes to the negative x-axis. Also, Chef doesn't stop at any moment of time.
The m... | {"inputs": ["5\n0 1\n1 1\n2 1\n1 3\n4 6"], "outputs": ["0\n1\n4\n5\n46"]} | 742 | 41 |
coding | Solve the programming task below in a Python markdown code block.
I have a lot of friends. Every friend is very small.
I often go out with my friends. Put some friends in your backpack and go out together.
Every morning I decide which friends to go out with that day. Put friends one by one in an empty backpack.
I'm not... | {"inputs": ["4 1\n1\n2\n7\n9", "4 1\n1\n2\n7\n2", "4 1\n1\n1\n7\n9", "3 1\n1\n2\n7\n9", "4 1\n1\n2\n8\n2", "4 1\n1\n3\n7\n2", "3 1\n1\n4\n7\n9", "4 1\n1\n2\n8\n4"], "outputs": ["1\n", "1\n", "2\n", "1\n", "1\n", "1\n", "1\n", "1\n"]} | 447 | 142 |
coding | Solve the programming task below in a Python markdown code block.
# Task
Given some sticks by an array `V` of positive integers, where V[i] represents the length of the sticks, find the number of ways we can choose three of them to form a triangle.
# Example
For `V = [2, 3, 7, 4]`, the result should be `1`.
There ... | {"functional": "_inputs = [[[2, 3, 7, 4]], [[5, 6, 7, 8]], [[2, 2, 2, 2]], [[1, 2, 5]], [[1, 2, 3, 10, 20, 30, 4]], [[1, 2, 3]]]\n_outputs = [[1], [4], [4], [0], [1], [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, ab... | 249 | 246 |
coding | Solve the programming task below in a Python markdown code block.
# Task
The sequence of `Chando` is an infinite sequence of all Chando's numbers in ascending order.
A number is called `Chando's` if it is an integer that can be represented as a sum of different positive integer powers of 5.
The first Chando's numb... | {"functional": "_inputs = [[1], [2], [9], [123], [23]]\n_outputs = [[5], [25], [630], [97530], [3280]]\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) !... | 239 | 195 |
coding | Solve the programming task below in a Python markdown code block.
Write a program which identifies the number of combinations of three integers which satisfy the following conditions:
* You should select three distinct integers from 1 to n.
* A total sum of the three integers is x.
For example, there are two combin... | {"inputs": ["5 7\n0 0", "2 7\n0 0", "7 9\n0 0", "5 6\n0 0", "7 6\n0 0", "2 2\n0 0", "7 2\n0 0", "6 9\n0 0"], "outputs": ["1\n", "0\n", "3\n", "1\n", "1\n", "0\n", "0\n", "3\n"]} | 205 | 110 |
coding | Solve the programming task below in a Python markdown code block.
Given a string, swap the case for each of the letters.
e.g. CodEwArs --> cODeWaRS
### Examples
```
"" -> ""
"CodeWars" -> "cODEwARS"
"abc" -> "ABC"
"ABC" -> "abc"
"123235" -> "123235"
```
Also feel free to reuse... | {"functional": "_inputs = [['HelloWorld'], ['CodeWars'], ['ThIs iS A l0NG sENTence witH nUMbERs in IT 123 456'], [''], [' '], [' '], [' 1a1 '], ['H_E_l-l_0 WO|||Rld'], ['TeSt'], ['EeEEeeEEEeee']]\n_outputs = [['hELLOwORLD'], ['cODEwARS'], ['tHiS Is a L0ng SentENCE WITh NumBerS IN it 123 456'], [''], [' '], [' '], [' ... | 123 | 311 |
coding | Solve the programming task below in a Python markdown code block.
Problem statement:
Kiran P.S wrote some text on a piece of paper and now he wants to know
how many star characters are in the text.
If you think of the paper as the plane and a letter as a curve on the plane, then each letter divides the plane into re... | {"inputs": ["5\nBACKTOTHEFUTURE\nPIRAMIDOFEGYPT\nROMANCE\nINSTITUTEOFELECTRICALANDELECTRONICSENGINEERING\nTHISISTHETESTCASEEERING", "5\nOAXTJYRHRPXKBZCRTSQTUSTQPQZWOMXGPUPMYTOZEKFJPANKMK\nGATLIOYAJSKNAAQVRBDVCXJNLRKSGWANRIIVIEMCIIYZJJMXNSNZXWYSQLXFNHTLJKDR\nHWOKJWVEHBKRYRDIKVHLAVCCKV\nUPHWPQKUBCUDOQNVKBAPIGDCZFOZEGCDPO... | 302 | 227 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.