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.
We are given a list nums of integers representing a list compressed with run-length encoding.
Consider each adjacent pair of elements [freq, val] = [nums[2*i], nums[2*i+1]] (with i >= 0). For each such pair, there are freq elements with value val concatenated in a sublist. Concatenate all the sublists from left to right to generate the decompressed list.
Return the decompressed list.
Please complete the following python code precisely:
```python
class Solution:
def decompressRLElist(self, nums: List[int]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4]) == [2,4,4,4]\n assert candidate(nums = [1,1,2,3]) == [1,3,3]\n\n\ncheck(Solution().decompressRLElist)"}
| 143
| 70
|
coding
|
Solve the programming task below in a Python markdown code block.
You are living on an infinite plane with the Cartesian coordinate system on it. In one move you can go to any of the four adjacent points (left, right, up, down).
More formally, if you are standing at the point $(x, y)$, you can:
go left, and move to $(x - 1, y)$, or
go right, and move to $(x + 1, y)$, or
go up, and move to $(x, y + 1)$, or
go down, and move to $(x, y - 1)$.
There are $n$ boxes on this plane. The $i$-th box has coordinates $(x_i,y_i)$. It is guaranteed that the boxes are either on the $x$-axis or the $y$-axis. That is, either $x_i=0$ or $y_i=0$.
You can collect a box if you and the box are at the same point. Find the minimum number of moves you have to perform to collect all of these boxes if you have to start and finish at the point $(0,0)$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 100$) — the number of test cases.
The first line of each test case contains a single integer $n$ ($1 \le n \le 100$) — the number of boxes.
The $i$-th line of the following $n$ lines contains two integers $x_i$ and $y_i$ ($-100 \le x_i, y_i \le 100$) — the coordinate of the $i$-th box. It is guaranteed that either $x_i=0$ or $y_i=0$.
Do note that the sum of $n$ over all test cases is not bounded.
-----Output-----
For each test case output a single integer — the minimum number of moves required.
-----Examples-----
Input
3
4
0 -2
1 0
-1 0
0 2
3
0 2
-3 0
0 -1
1
0 0
Output
12
12
0
-----Note-----
In the first test case, a possible sequence of moves that uses the minimum number of moves required is shown below.
$$(0,0) \to (1,0) \to (1,1) \to (1, 2) \to (0,2) \to (-1,2) \to (-1,1) \to (-1,0) \to (-1,-1) \to (-1,-2) \to (0,-2) \to (0,-1) \to (0,0)$$
In the second test case, a possible sequence of moves that uses the minimum number of moves required is shown below.
$$(0,0) \to (0,1) \to (0,2) \to (-1, 2) \to (-2,2) \to (-3,2) \to (-3,1) \to (-3,0) \to (-3,-1) \to (-2,-1) \to (-1,-1) \to (0,-1) \to (0,0)$$
In the third test case, we can collect all boxes without making any moves.
|
{"inputs": ["1\n4\n0 -1\n0 -2\n0 -3\n0 -4\n", "2\n3\n-6 0\n6 0\n0 -7\n3\n0 -6\n1 0\n0 3\n", "2\n3\n-2 0\n0 -5\n0 -1\n3\n3 0\n-2 0\n0 1\n", "3\n4\n0 -2\n1 0\n-1 0\n0 2\n3\n0 2\n-3 0\n0 -1\n1\n0 0\n"], "outputs": ["8\n", "38\n20\n", "14\n12\n", "12\n12\n0\n"]}
| 737
| 169
|
coding
|
Solve the programming task below in a Python markdown code block.
Vasya is writing an operating system shell, and it should have commands for working with directories. To begin with, he decided to go with just two commands: cd (change the current directory) and pwd (display the current directory).
Directories in Vasya's operating system form a traditional hierarchical tree structure. There is a single root directory, denoted by the slash character "/". Every other directory has a name — a non-empty string consisting of lowercase Latin letters. Each directory (except for the root) has a parent directory — the one that contains the given directory. It is denoted as "..".
The command cd takes a single parameter, which is a path in the file system. The command changes the current directory to the directory specified by the path. The path consists of the names of directories separated by slashes. The name of the directory can be "..", which means a step up to the parent directory. «..» can be used in any place of the path, maybe several times. If the path begins with a slash, it is considered to be an absolute path, that is, the directory changes to the specified one, starting from the root. If the parameter begins with a directory name (or ".."), it is considered to be a relative path, that is, the directory changes to the specified directory, starting from the current one.
The command pwd should display the absolute path to the current directory. This path must not contain "..".
Initially, the current directory is the root. All directories mentioned explicitly or passed indirectly within any command cd are considered to exist. It is guaranteed that there is no attempt of transition to the parent directory of the root directory.
Input
The first line of the input data contains the single integer n (1 ≤ n ≤ 50) — the number of commands.
Then follow n lines, each contains one command. Each of these lines contains either command pwd, or command cd, followed by a space-separated non-empty parameter.
The command parameter cd only contains lower case Latin letters, slashes and dots, two slashes cannot go consecutively, dots occur only as the name of a parent pseudo-directory. The command parameter cd does not end with a slash, except when it is the only symbol that points to the root directory. The command parameter has a length from 1 to 200 characters, inclusive.
Directories in the file system can have the same names.
Output
For each command pwd you should print the full absolute path of the given directory, ending with a slash. It should start with a slash and contain the list of slash-separated directories in the order of being nested from the root to the current folder. It should contain no dots.
Examples
Input
7
pwd
cd /home/vasya
pwd
cd ..
pwd
cd vasya/../petya
pwd
Output
/
/home/vasya/
/home/
/home/petya/
Input
4
cd /a/b
pwd
cd ../a/b
pwd
Output
/a/b/
/a/a/b/
|
{"inputs": ["1\npwd\n", "4\ncd /b/b\npwd\ncd ../a/b\npwd\n", "4\ncd /a/b\npwd\ncd ../a/b\npwd\n", "5\npwd\ncd ztb/kag\npwd\npwd\npwd\n", "5\npwd\ncd gak/btz\npwd\npwd\npwd\n", "6\ncd a/a/b/b\npwd\ncd ../..\npwd\ncd ..\npwd\n", "5\npwd\ncd /xgztbykka\npwd\ncd /gia/kxfls\npwd\n", "5\npwd\ncd /xgztbzkka\npwd\ncd /gia/kxfls\npwd\n"], "outputs": ["/\n", "/b/b/\n/b/a/b/\n", "/a/b/\n/a/a/b/\n", "/\n/ztb/kag/\n/ztb/kag/\n/ztb/kag/\n", "/\n/gak/btz/\n/gak/btz/\n/gak/btz/\n", "/a/a/b/b/\n/a/a/\n/a/\n", "/\n/xgztbykka/\n/gia/kxfls/\n", "/\n/xgztbzkka/\n/gia/kxfls/\n"]}
| 631
| 304
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given two arrays of integers with equal lengths, return the maximum value of:
|arr1[i] - arr1[j]| + |arr2[i] - arr2[j]| + |i - j|
where the maximum is taken over all 0 <= i, j < arr1.length.
Please complete the following python code precisely:
```python
class Solution:
def maxAbsValExpr(self, arr1: List[int], arr2: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(arr1 = [1,2,3,4], arr2 = [-1,4,5,6]) == 13\n assert candidate(arr1 = [1,-2,-5,0,10], arr2 = [0,-2,-1,-7,-4]) == 20\n\n\ncheck(Solution().maxAbsValExpr)"}
| 117
| 90
|
coding
|
Solve the programming task below in a Python markdown code block.
Little Petya loves counting. He wants to count the number of ways to paint a rectangular checkered board of size n × m (n rows, m columns) in k colors. Besides, the coloring should have the following property: for any vertical line that passes along the grid lines and divides the board in two non-empty parts the number of distinct colors in both these parts should be the same. Help Petya to count these colorings.
Input
The first line contains space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 106) — the board's vertical and horizontal sizes and the number of colors respectively.
Output
Print the answer to the problem. As the answer can be quite a large number, you should print it modulo 109 + 7 (1000000007).
Examples
Input
2 2 1
Output
1
Input
2 2 2
Output
8
Input
3 2 2
Output
40
|
{"inputs": ["6 6 8\n", "5 3 1\n", "3 3 2\n", "4 6 8\n", "5 3 2\n", "3 2 1\n", "4 2 2\n", "3 6 8\n"], "outputs": [" 522449402\n", " 1\n", " 290\n", "373895490\n", "28802\n", "1\n", "200\n", "199449441\n"]}
| 237
| 140
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Alexey is trying to develop a program for a very simple microcontroller. It makes readings from various sensors over time, and these readings must happen at specific regular times. Unfortunately, if two of these readings occur at the same time, the microcontroller freezes and must be reset.
There are N different sensors that read data on a regular basis. For each i from 1 to N, the reading from sensor i will occur every A_{i} milliseconds with the first reading occurring exactly A_{i} milliseconds after the microcontroller is powered up. Each reading takes precisely one millisecond on Alexey's microcontroller.
Alexey wants to know when the microcontroller will freeze after he turns it on.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first line contains single integer N denoting the number of sensors.
The second line contains N space-separated integers A_{1}, A_{2}, ..., A_{N} denoting frequency of measurements. Namely, sensor i will be read every A_{i} milliseconds with the first reading occurring A_{i} milliseconds after the microcontroller is first turned on.
------ Output ------
For each test case, output a single line containing the number of milliseconds until the microcontroller freezes.
------ Constraints ------
$1 ≤ T ≤ 10$
$2 ≤ N ≤ 500$
$1 ≤ A_{i} ≤ 10^{9}$
------ Subtasks ------
Subtask #1 (10 points) 1 ≤ T ≤ 10, 2 ≤ N ≤ 9, 1 ≤ A_{i} ≤ 500
Subtask #2 (20 points) 1 ≤ T ≤ 10, 2 ≤ N ≤ 500, 1 ≤ A_{i} ≤ 1000
Subtask #3 (70 points) original constraints
----- Sample Input 1 ------
3
3
2 3 5
4
1 8 7 11
4
4 4 5 6
----- Sample Output 1 ------
6
7
4
----- explanation 1 ------
Case 1: in 6 milliseconds, the third reading will be attempted from the 1st sensor and the second reading will be attempted from the 2nd sensor.
Case 2: in 7 milliseconds the seventh reading will be attempted from the 1st sensor and the first reading will be attempted from the 3rd sensor.
Case 3: in 4 milliseconds, the first readings from the first two sensors will be attempted.
|
{"inputs": ["3\n3\n2 3 5\n4\n1 8 7 11\n4\n4 4 5 6"], "outputs": ["6\n7\n4"]}
| 585
| 45
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array of n integers arr.
The interval between two elements in arr is defined as the absolute difference between their indices. More formally, the interval between arr[i] and arr[j] is |i - j|.
Return an array intervals of length n where intervals[i] is the sum of intervals between arr[i] and each element in arr with the same value as arr[i].
Note: |x| is the absolute value of x.
Please complete the following python code precisely:
```python
class Solution:
def getDistances(self, arr: List[int]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(arr = [2,1,3,1,2,3,3]) == [4,2,7,2,4,4,5]\n assert candidate(arr = [10,5,10,10]) == [5,0,3,4]\n\n\ncheck(Solution().getDistances)"}
| 145
| 85
|
coding
|
Solve the programming task below in a Python markdown code block.
# Sentence Smash
Write a function that takes an array of words and smashes them together into a sentence and returns the sentence. You can ignore any need to sanitize words or add punctuation, but you should add spaces between each word. **Be careful, there shouldn't be a space at the beginning or the end of the sentence!**
## Example
```
['hello', 'world', 'this', 'is', 'great'] => 'hello world this is great'
```
Also feel free to reuse/extend the following starter code:
```python
def smash(words):
```
|
{"functional": "_inputs = [[[]], [['hello']], [['hello', 'world']], [['hello', 'amazing', 'world']], [['this', 'is', 'a', 'really', 'long', 'sentence']]]\n_outputs = [[''], ['hello'], ['hello world'], ['hello amazing world'], ['this is a really long sentence']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(smash(*i), o[0])"}
| 133
| 211
|
coding
|
Solve the programming task below in a Python markdown code block.
Problem :
Chotu's father is the owner of a Vada Pav shop. One Sunday, his father takes him to the shop. Father tells him that at the end of the day, Chotu has to give him a list consisting of the names of all the customers on that day who bought Vada Pav(s) from the shop. The list should not have the names of any of the customers being repeated and it should be such that the lexicographically smallest name comes first, ie., the names should be sorted in dictionary order.
As and when a particular customer buys a Vada Pav, Chotu writes down the name of that particular customer. Chotu's initial list is ready, but, he is confused as to how to make the list Father expects from him. Chotu comes to you for help. Your job now is to create the final list, as Father expects from Chotu.
Input :
First line consists of N, the number of names of customers in Chotu's initial list. The next N lines are such that each line consists of a customer's name.
Output :
On the first line, print the total number of names appearing in Chotu's final list. Then print the list such that every customer's name is printed on a new line.
Constraints :
1 ≤ N ≤ 10^6
1 ≤ Length of names of customers ≤ 5
Customers' names consist only of lower case English alphabets (a-z).
Note : Some test files contain large data. Use scanf/printf instead of cin/cout .
SAMPLE INPUT
11
babu
anand
rani
aarti
nandu
rani
rani
ap
anand
babu
nandu
SAMPLE OUTPUT
6
aarti
anand
ap
babu
nandu
rani
|
{"inputs": ["74\ngvny\ndk\nvc\nb\nsuvo\nbljl\nh\nnomnb\nzfv\noy\ngqdld\nrgq\nfia\nyhxbj\nyk\ngunj\nnqe\nmopv\nocgq\njwx\no\no\nh\njbsx\nhby\nnq\ndkp\nf\nnu\nnhl\nb\nrki\nefmlq\nlut\nwcem\nzz\niwevs\nwtpr\nvwn\nwwjjw\na\nqjevs\nsumon\nee\nv\nc\nwip\nylr\ny\nfn\nxlgw\njwwcy\nvdh\nx\nh\nurtoq\nlxc\nxc\nltfhu\nslv\nw\nuims\no\nvtx\neya\nwr\nahpr\nir\nrom\nzy\niu\ntxyi\nqj\nbxkwf\n", "234\nljio\nj\nhfwod\nydgr\nrc\nlzh\nvnhwm\nnyunx\nohjz\nmiyj\nd\ncqk\nzttn\ng\nug\nscw\nmkc\nqa\nmnfj\noiexd\nesez\nwip\npsp\nss\ny\nnimxh\ne\nrsyav\nqhyj\neps\nnvl\na\nd\ngkgb\nnm\nhipsv\nfj\nrzsj\nboxq\noee\nsquak\nd\nl\nkzz\nauk\nwxt\nnsbr\naiyfp\ny\namfb\nwg\npy\noibfa\nbn\nvn\nlp\nmslj\njijt\nbuv\nzkjs\nwcsp\nanky\nk\njgl\nv\ntgfqj\npx\nmy\nf\noiv\nkutxb\nmjy\nvpe\nu\nxh\nodi\nixb\nl\ng\nrs\ntyn\nbosc\nodepm\nssaiu\ncuf\nziok\ni\noyo\ntvpn\nik\nrjjrq\nd\nagafb\nq\ntyn\nmj\ni\nahtnj\nlvrk\nrdcyd\naxa\na\nvsz\nlhdn\nl\nuozq\npj\ncvkr\noju\ndaybm\nkdf\nknh\nvadoi\ndyx\nmpf\ncfww\nhb\nlp\nlb\nldjw\ntdacj\nw\nvicjh\ndkmc\naypd\nvt\niacl\ndh\nx\ndxip\nwtz\ni\nsyv\nrg\nu\nqzys\nuor\ndtpjo\nah\nv\ncy\np\nrqm\ndxs\nyo\nuyzh\nojww\nj\ny\nijzsm\nzg\nuj\ntan\nycxx\nekntm\npvz\nji\nqfkmo\nhkk\nliqw\napjmb\ncb\np\ntijrb\ny\np\njp\npr\nzlony\nfqy\nkucy\ndt\naidg\niklk\nbg\nqpa\na\nzfq\nf\naibr\ntli\nf\nwzuh\nw\nkqnc\nvnop\nq\nk\nnrx\nz\nzrd\neec\nf\nodkk\nhzksk\np\nybyg\nzaw\nkp\nwsh\noclnc\nwbpu\njy\neq\nblh\na\nfulok\ne\nmgrn\nwtpg\nordy\nsql\nyf\nf\nuzth\nr\nrxt\nymmud\nssr\nudqy\nt\nie\nbcmf\ngrxd\nj\nebmal\nzpzf\nvd\nu\nslzi\ntq\ntbrg\nvyogy\nckira\n"], "outputs": ["69\na\nahpr\nb\nbljl\nbxkwf\nc\ndk\ndkp\nee\nefmlq\neya\nf\nfia\nfn\ngqdld\ngunj\ngvny\nh\nhby\nir\niu\niwevs\njbsx\njwwcy\njwx\nltfhu\nlut\nlxc\nmopv\nnhl\nnomnb\nnq\nnqe\nnu\no\nocgq\noy\nqj\nqjevs\nrgq\nrki\nrom\nslv\nsumon\nsuvo\ntxyi\nuims\nurtoq\nv\nvc\nvdh\nvtx\nvwn\nw\nwcem\nwip\nwr\nwtpr\nwwjjw\nx\nxc\nxlgw\ny\nyhxbj\nyk\nylr\nzfv\nzy\nzz\n", "202\na\nagafb\nah\nahtnj\naibr\naidg\naiyfp\namfb\nanky\napjmb\nauk\naxa\naypd\nbcmf\nbg\nblh\nbn\nbosc\nboxq\nbuv\ncb\ncfww\nckira\ncqk\ncuf\ncvkr\ncy\nd\ndaybm\ndh\ndkmc\ndt\ndtpjo\ndxip\ndxs\ndyx\ne\nebmal\neec\nekntm\neps\neq\nesez\nf\nfj\nfqy\nfulok\ng\ngkgb\ngrxd\nhb\nhfwod\nhipsv\nhkk\nhzksk\ni\niacl\nie\nijzsm\nik\niklk\nixb\nj\njgl\nji\njijt\njp\njy\nk\nkdf\nknh\nkp\nkqnc\nkucy\nkutxb\nkzz\nl\nlb\nldjw\nlhdn\nliqw\nljio\nlp\nlvrk\nlzh\nmgrn\nmiyj\nmj\nmjy\nmkc\nmnfj\nmpf\nmslj\nmy\nnimxh\nnm\nnrx\nnsbr\nnvl\nnyunx\noclnc\nodepm\nodi\nodkk\noee\nohjz\noibfa\noiexd\noiv\noju\nojww\nordy\noyo\np\npj\npr\npsp\npvz\npx\npy\nq\nqa\nqfkmo\nqhyj\nqpa\nqzys\nr\nrc\nrdcyd\nrg\nrjjrq\nrqm\nrs\nrsyav\nrxt\nrzsj\nscw\nslzi\nsql\nsquak\nss\nssaiu\nssr\nsyv\nt\ntan\ntbrg\ntdacj\ntgfqj\ntijrb\ntli\ntq\ntvpn\ntyn\nu\nudqy\nug\nuj\nuor\nuozq\nuyzh\nuzth\nv\nvadoi\nvd\nvicjh\nvn\nvnhwm\nvnop\nvpe\nvsz\nvt\nvyogy\nw\nwbpu\nwcsp\nwg\nwip\nwsh\nwtpg\nwtz\nwxt\nwzuh\nx\nxh\ny\nybyg\nycxx\nydgr\nyf\nymmud\nyo\nz\nzaw\nzfq\nzg\nziok\nzkjs\nzlony\nzpzf\nzrd\nzttn\n"]}
| 398
| 1,703
|
coding
|
Solve the programming task below in a Python markdown code block.
Problem statement
Cards with ranks of $ 2 $ and $ 8 $ are powerful in card game millionaires. Therefore, we call an integer consisting of only the numbers $ 2 $ and $ 8 $ in $ 10 $ decimal notation a good integer. The best integers are listed from the smallest to $ 2, 8, 22, 28, 82, 88, \ cdots $.
Let $ n $ be a positive integer. When $ n $ can be expressed in the form of a product of good integers, find the maximum product. If you can't, output $ -1 $.
Constraint
$ 1 \ leq n \ leq 10 ^ {18} $
sample
Sample input 1
1
Sample output 1
-1
Sample input 2
2
Sample output 2
1
Sample input 3
88
Sample output 3
3
It can be expressed as $ 2 \ times 2 \ times 22 $.
Sample input 4
100
Sample output 4
-1
Sample input 5
173553147234869248
Sample output 5
11
It can be expressed as $ 2 ^ 6 \ times 28 \ times 2222 ^ 3 \ times 8828 $.
input
$ n $
output
Print the answer on the $ 1 $ line.
Example
Input
1
Output
-1
|
{"inputs": ["2", "4", "8", "6", "3", "7", "9", "5"], "outputs": ["1\n", "2\n", "3\n", "-1\n", "-1\n", "-1\n", "-1\n", "-1\n"]}
| 346
| 62
|
coding
|
Solve the programming task below in a Python markdown code block.
Permutation p is an ordered set of integers p1, p2, ..., pn, consisting of n distinct positive integers not larger than n. We'll denote as n the length of permutation p1, p2, ..., pn.
Your task is to find such permutation p of length n, that the group of numbers |p1 - p2|, |p2 - p3|, ..., |pn - 1 - pn| has exactly k distinct elements.
Input
The single line of the input contains two space-separated positive integers n, k (1 ≤ k < n ≤ 105).
Output
Print n integers forming the permutation. If there are multiple answers, print any of them.
Examples
Input
3 2
Output
1 3 2
Input
3 1
Output
1 2 3
Input
5 2
Output
1 3 2 4 5
Note
By |x| we denote the absolute value of number x.
|
{"inputs": ["2 1\n", "4 2\n", "5 4\n", "7 5\n", "4 1\n", "9 8\n", "8 2\n", "5 3\n"], "outputs": ["1 2 \n", "1 3 2 4 ", "1 5 2 4 3 \n", "1 6 2 5 3 4 7 ", "1 2 3 4 \n", "1 9 2 8 3 7 4 6 5 \n", "1 3 2 4 5 6 7 8 ", "1 4 2 3 5 "]}
| 220
| 159
|
coding
|
Solve the programming task below in a Python markdown code block.
Dawid has four bags of candies. The $i$-th of them contains $a_i$ candies. Also, Dawid has two friends. He wants to give each bag to one of his two friends. Is it possible to distribute the bags in such a way that each friend receives the same amount of candies in total?
Note, that you can't keep bags for yourself or throw them away, each bag should be given to one of the friends.
-----Input-----
The only line contains four integers $a_1$, $a_2$, $a_3$ and $a_4$ ($1 \leq a_i \leq 100$) — the numbers of candies in each bag.
-----Output-----
Output YES if it's possible to give the bags to Dawid's friends so that both friends receive the same amount of candies, or NO otherwise. Each character can be printed in any case (either uppercase or lowercase).
-----Examples-----
Input
1 7 11 5
Output
YES
Input
7 3 2 5
Output
NO
-----Note-----
In the first sample test, Dawid can give the first and the third bag to the first friend, and the second and the fourth bag to the second friend. This way, each friend will receive $12$ candies.
In the second sample test, it's impossible to distribute the bags.
|
{"inputs": ["7 3 2 5\n", "1 1 1 1\n", "1 1 2 1\n", "2 4 1 1\n", "4 4 4 5\n", "2 6 3 2\n", "7 3 6 3\n", "2 4 6 6\n"], "outputs": ["NO\n", "YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 304
| 118
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given two strings s and p where p is a subsequence of s. You are also given a distinct 0-indexed integer array removable containing a subset of indices of s (s is also 0-indexed).
You want to choose an integer k (0 <= k <= removable.length) such that, after removing k characters from s using the first k indices in removable, p is still a subsequence of s. More formally, you will mark the character at s[removable[i]] for each 0 <= i < k, then remove all marked characters and check if p is still a subsequence.
Return the maximum k you can choose such that p is still a subsequence of s after the removals.
A subsequence of a string is a new string generated from the original string with some characters (can be none) deleted without changing the relative order of the remaining characters.
Please complete the following python code precisely:
```python
class Solution:
def maximumRemovals(self, s: str, p: str, removable: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"abcacb\", p = \"ab\", removable = [3,1,0]) == 2\n assert candidate(s = \"abcbddddd\", p = \"abcd\", removable = [3,2,1,4,5,6]) == 1\n assert candidate(s = \"abcab\", p = \"abc\", removable = [0,1,2,3,4]) == 0\n\n\ncheck(Solution().maximumRemovals)"}
| 240
| 114
|
coding
|
Solve the programming task below in a Python markdown code block.
## Grade book
Complete the function so that it finds the mean of the three scores passed to it and returns the letter value associated with that grade.
Numerical Score | Letter Grade
--- | ---
90 <= score <= 100 | 'A'
80 <= score < 90 | 'B'
70 <= score < 80 | 'C'
60 <= score < 70 | 'D'
0 <= score < 60 | 'F'
Tested values are all between 0 and 100. Theres is no need to check for negative values or values greater than 100.
Also feel free to reuse/extend the following starter code:
```python
def get_grade(s1, s2, s3):
```
|
{"functional": "_inputs = [[95, 90, 93], [100, 85, 96], [92, 93, 94], [100, 100, 100], [70, 70, 100], [82, 85, 87], [84, 79, 85], [70, 70, 70], [75, 70, 79], [60, 82, 76], [65, 70, 59], [66, 62, 68], [58, 62, 70], [44, 55, 52], [48, 55, 52], [58, 59, 60], [0, 0, 0]]\n_outputs = [['A'], ['A'], ['A'], ['A'], ['B'], ['B'], ['B'], ['C'], ['C'], ['C'], ['D'], ['D'], ['D'], ['F'], ['F'], ['F'], ['F']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(get_grade(*i), o[0])"}
| 181
| 405
|
coding
|
Solve the programming task below in a Python markdown code block.
Xorgon is an extremely delicious treat formed by the sequence $S$ of binary integers $s_1, s_2,..,s_N$. A really interesting property found in a Xorgon is that the xor of all elements in any contiguous subsequence of length $K$ in $S$ will result in $1$.
Chef has been asked to prepare a Xorgon. However, he has at his disposal a binary sequence $X$ containing the binary integers $x_1, x_2, ...x_N$. To prepare a Xorgon, the chef may flip the value of as many binary digits in $X$ as required.(i.e. turn a $1$ to a $0$ and $0$ to a $1$). Unfortunately, flipping a digit takes a lot of time and the chef has to serve many orders. Can you help the chef calculate the minimum number of flips required to cook a Xorgon from the given $X$?
-----Input:-----
- The first line will contain two space-separated integers $N, K$.
- Next line contains N space-separated integers $x_1, x_2, ...,x_N$.
-----Output:-----
Output in a single line minimum number of flips required to turn $X$ into a Xorgon.
-----Constraints-----
- $1 \leq K \leq N \leq 3*10^6$
- $0 \leq x_i \leq 1$
-----Sample Input:-----
7 5
1 0 0 1 1 1 1
-----Sample Output:-----
1
-----EXPLANATION:-----
Flip the last bit from 1 to 0 to obtain a Xorgon.
|
{"inputs": ["7 5\n1 0 0 1 1 1 1"], "outputs": ["1"]}
| 375
| 28
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an integer array nums (0-indexed) and two integers target and start, find an index i such that nums[i] == target and abs(i - start) is minimized. Note that abs(x) is the absolute value of x.
Return abs(i - start).
It is guaranteed that target exists in nums.
Please complete the following python code precisely:
```python
class Solution:
def getMinDistance(self, nums: List[int], target: int, start: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,2,3,4,5], target = 5, start = 3) == 1\n assert candidate(nums = [1], target = 1, start = 0) == 0\n assert candidate(nums = [1,1,1,1,1,1,1,1,1,1], target = 1, start = 0) == 0\n\n\ncheck(Solution().getMinDistance)"}
| 123
| 112
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
For the given set `S` its powerset is the set of all possible subsets of `S`.
Given an array of integers nums, your task is to return the powerset of its elements.
Implement an algorithm that does it in a depth-first search fashion. That is, for every integer in the set, we can either choose to take or not take it. At first, we choose `NOT` to take it, then we choose to take it(see more details in exampele).
# Example
For `nums = [1, 2]`, the output should be `[[], [2], [1], [1, 2]].`
Here's how the answer is obtained:
```
don't take element 1
----don't take element 2
--------add []
----take element 2
--------add [2]
take element 1
----don't take element 2
--------add [1]
----take element 2
--------add [1, 2]```
For `nums = [1, 2, 3]`, the output should be
`[[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]]`.
# Input/Output
`[input]` integer array `nums`
Array of positive integers, `1 ≤ nums.length ≤ 10`.
[output] 2D integer array
The powerset of nums.
Also feel free to reuse/extend the following starter code:
```python
def powerset(nums):
```
|
{"functional": "_inputs = [[[1, 2]], [[1, 2, 3]], [[1]], [[125, 15, 155, 15, 158]], [[1, 2, 3, 4]]]\n_outputs = [[[[], [2], [1], [1, 2]]], [[[], [3], [2], [2, 3], [1], [1, 3], [1, 2], [1, 2, 3]]], [[[], [1]]], [[[], [158], [15], [15, 158], [155], [155, 158], [155, 15], [155, 15, 158], [15], [15, 158], [15, 15], [15, 15, 158], [15, 155], [15, 155, 158], [15, 155, 15], [15, 155, 15, 158], [125], [125, 158], [125, 15], [125, 15, 158], [125, 155], [125, 155, 158], [125, 155, 15], [125, 155, 15, 158], [125, 15], [125, 15, 158], [125, 15, 15], [125, 15, 15, 158], [125, 15, 155], [125, 15, 155, 158], [125, 15, 155, 15], [125, 15, 155, 15, 158]]], [[[], [4], [3], [3, 4], [2], [2, 4], [2, 3], [2, 3, 4], [1], [1, 4], [1, 3], [1, 3, 4], [1, 2], [1, 2, 4], [1, 2, 3], [1, 2, 3, 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(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(powerset(*i), o[0])"}
| 348
| 732
|
coding
|
Solve the programming task below in a Python markdown code block.
As bad weather continues and vegetable prices soar, Seven-Eleven is offering customers bulk purchase sales of vegetables. The store is very busy, as you can get vegetables that are hard to find in stores at reasonable prices.
One day, a group of three good friends living in the Matsunaga housing complex bloomed with an advertisement for Seven-Eleven. Since this sale was called "Customer Thanksgiving Day", the highlight is that the cheapest vegetables in the bag are free. When I read the advertisement, it looks like the following sale.
* Up to m vegetables can be packed in one bag.
* For bags packed with m vegetables, the cheapest vegetables are free.
* Bags with less than m vegetables are not eligible for the discount.
The three went shopping at Seven Mart immediately.
When the three people who met outside the store after shopping were satisfied with the fact that they were able to buy a lot at a low price, they apparently found that they were all buying the same vegetables. One person said, "It's really cheap, isn't it? This is XXX yen!", And the other was surprised, "What? I was ** yen higher than that! Why?", And the rest One of them saw the receipt and noticed that he bought the cheapest one.
Now, how can you pack the bag at the lowest purchase price? Enter the number of vegetables to purchase, the number of vegetables in the bag, and the price of each vegetable, and create a program that outputs the minimum purchase price.
Input
A sequence of multiple datasets is given as input. The end of the input is indicated by two lines of zeros. Each dataset is given in the following format:
n m
p1 p2 ... pn
The first line gives the number of vegetables to buy n (1 ≤ n ≤ 1000) and the number of vegetables to put in the bag m (1 ≤ m ≤ 1000). The second line gives the price pi (10 ≤ pi ≤ 10000) for each vegetable.
The number of datasets does not exceed 100.
Output
Prints the minimum purchase price on one line for each input dataset.
Example
Input
4 2
50 40 100 80
7 3
400 300 100 700 200 600 500
0 0
Output
150
2100
|
{"inputs": ["4 1\n50 77 110 80\n7 3\n3 300 110 194 77 600 75\n0 0", "4 1\n50 77 110 80\n7 6\n3 300 110 194 77 600 75\n0 0", "4 3\n50 59 100 80\n7 3\n400 290 000 700 4 600 57\n0 0", "4 4\n50 59 100 80\n7 3\n400 290 000 700 4 600 57\n0 0", "4 2\n50 40 101 80\n7 4\n400 45 000 700 87 650 57\n0 0", "4 1\n27 77 100 80\n7 3\n24 300 100 194 77 600 57\n0 0", "4 2\n50 40 100 35\n7 4\n400 284 010 700 701 0 57\n0 0", "4 3\n50 6 100 80\n7 3\n400 300 100 194 24 600 57\n0 0"], "outputs": ["0\n1090\n", "0\n1284\n", "230\n1647\n", "239\n1647\n", "151\n1852\n", "0\n1101\n", "140\n1868\n", "186\n1318\n"]}
| 522
| 494
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef hates unoptimized codes and people who write such codes. One fine day he decided to look through the kitchen's codebase and found a function whose pseudo-code is given here:
input: integer N, list X[1, 2, ..., N], list Y[1, 2, ..., N]
output: integer res
function:
set res = 0;
for i := 1 to N do
for j := 1 to N do
for k := 1 to N do
if (X[i] = X[j]) OR (X[j] = X[k]) OR (X[k] = X[i])
continue
else
set res = max(res, Y[i] + Y[j] + Y[k])
return res
Luckily enough this code gets triggered only if the Head Chef makes a submission. But still there is a possibility that this can crash the judge. So help Chef by writing a new function which does the same thing but is faster.
-----Input-----
- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
- The first line of each test case contains an integer N denoting the number of elements in the two lists.
- The i-th of the next N lines contains a pair of space-separated integers denoting the values of X[i] and Y[i] respectively.
-----Output-----
For each test case, output an integer corresponding to the return value of the function.
-----Constraints-----
- 1 ≤ T ≤ 10
- 1 ≤ N ≤ 105
- 1 ≤ X[i], Y[i] ≤ 108
-----Example-----
Input
2
3
1 3
3 1
1 2
5
1 3
2 4
1 2
3 2
3 4
Output
0
11
-----Explanation-----
Testcase 2: The maximum is attained when i = 1, j = 2 and k = 5. This leads to res being 3 + 4 + 4 = 11. This value is attained in other iterations as well, but it never exceeds this, and hence this is the answer.
|
{"inputs": ["2\n3\n1 3\n3 1\n1 2\n5\n1 3\n2 4\n1 2\n3 2\n3 4"], "outputs": ["0\n11"]}
| 474
| 51
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You have information about n different recipes. You are given a string array recipes and a 2D string array ingredients. The ith recipe has the name recipes[i], and you can create it if you have all the needed ingredients from ingredients[i]. Ingredients to a recipe may need to be created from other recipes, i.e., ingredients[i] may contain a string that is in recipes.
You are also given a string array supplies containing all the ingredients that you initially have, and you have an infinite supply of all of them.
Return a list of all the recipes that you can create. You may return the answer in any order.
Note that two recipes may contain each other in their ingredients.
Please complete the following python code precisely:
```python
class Solution:
def findAllRecipes(self, recipes: List[str], ingredients: List[List[str]], supplies: List[str]) -> List[str]:
```
|
{"functional": "def check(candidate):\n assert candidate(recipes = [\"bread\"], ingredients = [[\"yeast\",\"flour\"]], supplies = [\"yeast\",\"flour\",\"corn\"]) == [\"bread\"]\n assert candidate(recipes = [\"bread\",\"sandwich\"], ingredients = [[\"yeast\",\"flour\"],[\"bread\",\"meat\"]], supplies = [\"yeast\",\"flour\",\"meat\"]) == [\"bread\",\"sandwich\"]\n assert candidate(recipes = [\"bread\",\"sandwich\",\"burger\"], ingredients = [[\"yeast\",\"flour\"],[\"bread\",\"meat\"],[\"sandwich\",\"meat\",\"bread\"]], supplies = [\"yeast\",\"flour\",\"meat\"]) == [\"bread\",\"sandwich\",\"burger\"]\n assert candidate(recipes = [\"bread\"], ingredients = [[\"yeast\",\"flour\"]], supplies = [\"yeast\"]) == []\n\n\ncheck(Solution().findAllRecipes)"}
| 198
| 221
|
coding
|
Solve the programming task below in a Python markdown code block.
We have N voting papers. The i-th vote (1 \leq i \leq N) has the string S_i written on it.
Print all strings that are written on the most number of votes, in lexicographical order.
-----Constraints-----
- 1 \leq N \leq 2 \times 10^5
- S_i (1 \leq i \leq N) are strings consisting of lowercase English letters.
- The length of S_i (1 \leq i \leq N) is between 1 and 10 (inclusive).
-----Input-----
Input is given from Standard Input in the following format:
N
S_1
:
S_N
-----Output-----
Print all strings in question in lexicographical order.
-----Sample Input-----
7
beat
vet
beet
bed
vet
bet
beet
-----Sample Output-----
beet
vet
beet and vet are written on two sheets each, while beat, bed, and bet are written on one vote each. Thus, we should print the strings beet and vet.
|
{"inputs": ["4\nushi\ntaou\nnichia\nkun", "4\nihsu\ntaou\nnichia\nkun", "4\nihsu\ntaou\nmichia\nkun", "4\nihsu\ntaou\nmichia\nnuk", "4\nihsu\ntaou\nmichia\nmuk", "4\nihsu\nuoat\nmichia\nmuk", "4\nihsu\nuoat\nmichia\nkum", "4\nihsu\nuoat\nmichia\nluk"], "outputs": ["kun\nnichia\ntaou\nushi\n", "ihsu\nkun\nnichia\ntaou\n", "ihsu\nkun\nmichia\ntaou\n", "ihsu\nmichia\nnuk\ntaou\n", "ihsu\nmichia\nmuk\ntaou\n", "ihsu\nmichia\nmuk\nuoat\n", "ihsu\nkum\nmichia\nuoat\n", "ihsu\nluk\nmichia\nuoat\n"]}
| 240
| 276
|
coding
|
Solve the programming task below in a Python markdown code block.
Appleman and Toastman play a game. Initially Appleman gives one group of n numbers to the Toastman, then they start to complete the following tasks: Each time Toastman gets a group of numbers, he sums up all the numbers and adds this sum to the score. Then he gives the group to the Appleman. Each time Appleman gets a group consisting of a single number, he throws this group out. Each time Appleman gets a group consisting of more than one number, he splits the group into two non-empty groups (he can do it in any way) and gives each of them to Toastman.
After guys complete all the tasks they look at the score value. What is the maximum possible value of score they can get?
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 3·10^5). The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^6) — the initial group that is given to Toastman.
-----Output-----
Print a single integer — the largest possible score.
-----Examples-----
Input
3
3 1 5
Output
26
Input
1
10
Output
10
-----Note-----
Consider the following situation in the first example. Initially Toastman gets group [3, 1, 5] and adds 9 to the score, then he give the group to Appleman. Appleman splits group [3, 1, 5] into two groups: [3, 5] and [1]. Both of them should be given to Toastman. When Toastman receives group [1], he adds 1 to score and gives the group to Appleman (he will throw it out). When Toastman receives group [3, 5], he adds 8 to the score and gives the group to Appleman. Appleman splits [3, 5] in the only possible way: [5] and [3]. Then he gives both groups to Toastman. When Toastman receives [5], he adds 5 to the score and gives the group to Appleman (he will throws it out). When Toastman receives [3], he adds 3 to the score and gives the group to Appleman (he will throws it out). Finally Toastman have added 9 + 1 + 8 + 5 + 3 = 26 to the score. This is the optimal sequence of actions.
|
{"inputs": ["1\n3\n", "1\n5\n", "1\n2\n", "1\n1\n", "1\n10\n", "1\n10\n", "2\n1 2\n", "2\n2 3\n"], "outputs": ["3\n", "5\n", "2\n", "1\n", "10\n", "10\n", "6\n", "10\n"]}
| 534
| 95
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array nums consisting of positive integers. You can choose two indices i and j, such that i != j, and the sum of digits of the number nums[i] is equal to that of nums[j].
Return the maximum value of nums[i] + nums[j] that you can obtain over all possible indices i and j that satisfy the conditions.
Please complete the following python code precisely:
```python
class Solution:
def maximumSum(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [18,43,36,13,7]) == 54\n assert candidate(nums = [10,12,19,14]) == -1\n\n\ncheck(Solution().maximumSum)"}
| 125
| 66
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
Your task is to write a function for calculating the score of a 10 pin bowling game. The input for the function is a list of pins knocked down per roll for one player. Output is the player's total score.
# Rules
## General rules
Rules of bowling in a nutshell:
* A game consists of 10 frames. In each frame the player rolls 1 or 2 balls, except for the 10th frame, where the player rolls 2 or 3 balls.
* The total score is the sum of your scores for the 10 frames
* If you knock down fewer than 10 pins with 2 balls, your frame score is the number of pins knocked down
* If you knock down all 10 pins with 2 balls (spare), you score the amount of pins knocked down plus a bonus - amount of pins knocked down with the next ball
* If you knock down all 10 pins with 1 ball (strike), you score the amount of pins knocked down plus a bonus - amount of pins knocked down with the next 2 balls
## Rules for 10th frame
As the 10th frame is the last one, in case of spare or strike there will be no next balls for the bonus. To account for that:
* if the last frame is a spare, player rolls 1 bonus ball.
* if the last frame is a strike, player rolls 2 bonus balls.
These bonus balls on 10th frame are only counted as a bonus to the respective spare or strike.
# More information
http://en.wikipedia.org/wiki/Ten-pin_bowling#Scoring
# Input
You may assume that the input is always valid. This means:
* input list length is correct
* number of pins knocked out per roll is valid
Also feel free to reuse/extend the following starter code:
```python
def bowling_score(rolls):
```
|
{"functional": "_inputs = [[[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]], [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]], [[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4]], [[9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9, 1, 9]], [[10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10]], [[10, 5, 5, 10, 5, 5, 10, 5, 5, 10, 5, 5, 10, 5, 5, 10]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 1, 0]], [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10, 1, 0]], [[10, 10, 2, 8, 10, 9, 1, 10, 10, 4, 6, 0, 10, 7, 3, 7]]]\n_outputs = [[0], [20], [80], [190], [300], [200], [11], [12], [190]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(bowling_score(*i), o[0])"}
| 416
| 710
|
coding
|
Solve the programming task below in a Python markdown code block.
When you look at photographs of watches and clocks, you'll find that they almost always show the time 10:10. There are lots of theories and even urban legends about this. For example, when showing 10:10, the hands look like a smile, and so you are more inclined to buy the watch or clock :D (a form of subliminal advertising).
Now, you are given $N$ and ${M}$. You are to find the number of sequences $A_{1},A_{2},\ldots,A_{N}$ such that:
${A_1}$ is a number of the form ${1010}^K$ for some $1\leq K\leq M$,
If $P=A_2\cdot A_3\cdots A_N$, then ${A_1}$ is divisible by ${P}$, and $\mbox{P}$ is divisible by ${1010}$, and
$A_2,A_3,\ldots,A_N$ are squarefree.
Since the number can be very large, only give the number modulo ${2000003}$.
Input Format
The first line of input contains a single integer ${T}$, which is the number of test cases. The following lines contain the test cases.
Each test case consists of one line containing two integers, $N$ and ${M}$.
Constraints
$1\leq T\leq10^5$
$2\leq N\leq M\leq10^{12}$
Output Format
For each test case, output a single line containing the answer.
Sample Input
2
2 3
3 3
Sample Output
3
62
Explanation
For the first test case, the possible sequences are:
$\{1010,1010\}$,
$\{1020100,1010\}$,
${103031000},{1010}$
|
{"inputs": ["2\n2 3\n3 3\n"], "outputs": ["3\n62\n"]}
| 445
| 25
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef has an array A having N elements. Chef wants to make all the elements of the array equal by repeating the following move.
Choose any integer K between 1 and N (inclusive). Then choose K distinct indices i_{1} , i_{2}, \dots, i_{K}, and increase the values of A_{i_{1}} , A_{i_{2}} , \dots , A_{i_{K}} by 1.
Find the minimum number of moves required to make all the elements of the array equal.
------ Input Format ------
- The first line contains T denoting the number of test cases. Then the test cases follow.
- The first line of each test case contains a single integer N denoting the number of elements in A.
- The second line of each test case contains N space separated integers A_{1}, A_{2}, \dots, A_{N}.
------ Output Format ------
For each test case, print a single line containing one integer denoting the minimum number of moves required to make all the elements of the array equal.
------ Constraints ------
$1 ≤ T ≤ 10^{4}$
$1 ≤ N ≤ 10^{5}$
$1 ≤ A_{i} ≤ 10^{5}$
- The sum of $N$ over all test cases does not exceed $10^{5}$.
----- Sample Input 1 ------
2
3
1 3 1
3
2 2 2
----- Sample Output 1 ------
2
0
----- explanation 1 ------
- Test Case $1$: In the first move, Chef can choose $K = 2$, and choose the indices $\{1 , 3\}$. After increasing $A_{1}$ and $A_{3}$ by $1$, the array will become $[2 , 3 , 2]$.
In the second move, Chef can choose $K = 2$, and choose the indices $\{1 , 3\}$. After increasing $A_{1}$ and $A_{3}$ by $1$, the array will become $[3 , 3 , 3]$, and hence all the elements become equal.
- Test Case $2$: All the elements of the array are equal, hence no move is required.
|
{"inputs": ["2\n3\n1 3 1\n3\n2 2 2"], "outputs": ["2\n0"]}
| 494
| 30
|
coding
|
Solve the programming task below in a Python markdown code block.
We have a sequence of N integers A~=~A_0,~A_1,~...,~A_{N - 1}.
Let B be a sequence of K \times N integers obtained by concatenating K copies of A. For example, if A~=~1,~3,~2 and K~=~2, B~=~1,~3,~2,~1,~3,~2.
Find the inversion number of B, modulo 10^9 + 7.
Here the inversion number of B is defined as the number of ordered pairs of integers (i,~j)~(0 \leq i < j \leq K \times N - 1) such that B_i > B_j.
Constraints
* All values in input are integers.
* 1 \leq N \leq 2000
* 1 \leq K \leq 10^9
* 1 \leq A_i \leq 2000
Input
Input is given from Standard Input in the following format:
N K
A_0 A_1 ... A_{N - 1}
Output
Print the inversion number of B, modulo 10^9 + 7.
Examples
Input
2 2
2 1
Output
3
Input
3 5
1 1 1
Output
0
Input
10 998244353
10 9 8 7 5 6 3 4 2 1
Output
185297239
|
{"inputs": ["2 2\n2 2", "2 2\n0 2", "2 2\n2 0", "2 4\n2 0", "2 2\n2 1", "3 5\n1 1 0", "3 5\n1 2 0", "2 -4\n2 -1"], "outputs": ["0\n", "1\n", "3\n", "10\n", "3", "30\n", "40\n", "6\n"]}
| 357
| 116
|
coding
|
Solve the programming task below in a Python markdown code block.
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array $a$ of length $n$, consisting only of the numbers $0$ and $1$, and the number $k$. Exactly $k$ times the following happens: Two numbers $i$ and $j$ are chosen equiprobable such that ($1 \leq i < j \leq n$). The numbers in the $i$ and $j$ positions are swapped.
Sonya's task is to find the probability that after all the operations are completed, the $a$ array will be sorted in non-decreasing order. She turned to you for help. Help Sonya solve this problem.
It can be shown that the desired probability is either $0$ or it can be represented as $\dfrac{P}{Q}$, where $P$ and $Q$ are coprime integers and $Q \not\equiv 0~\pmod {10^9+7}$.
-----Input-----
The first line contains two integers $n$ and $k$ ($2 \leq n \leq 100, 1 \leq k \leq 10^9$) — the length of the array $a$ and the number of operations.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 1$) — the description of the array $a$.
-----Output-----
If the desired probability is $0$, print $0$, otherwise print the value $P \cdot Q^{-1}$ $\pmod {10^9+7}$, where $P$ and $Q$ are defined above.
-----Examples-----
Input
3 2
0 1 0
Output
333333336
Input
5 1
1 1 1 0 0
Output
0
Input
6 4
1 0 0 1 1 0
Output
968493834
-----Note-----
In the first example, all possible variants of the final array $a$, after applying exactly two operations: $(0, 1, 0)$, $(0, 0, 1)$, $(1, 0, 0)$, $(1, 0, 0)$, $(0, 1, 0)$, $(0, 0, 1)$, $(0, 0, 1)$, $(1, 0, 0)$, $(0, 1, 0)$. Therefore, the answer is $\dfrac{3}{9}=\dfrac{1}{3}$.
In the second example, the array will not be sorted in non-decreasing order after one operation, therefore the answer is $0$.
|
{"inputs": ["2 1\n0 1\n", "2 1\n1 0\n", "2 1\n1 1\n", "2 1\n0 0\n", "2 1\n1 0\n", "2 1\n0 1\n", "2 1\n1 1\n", "2 1\n0 0\n"], "outputs": ["0", "1", "1", "1", "1\n", "0\n", "1\n", "1\n"]}
| 645
| 114
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef Ada is building a new restaurant in the following way:
- First, $N$ points $X_1, X_2, \ldots, X_N$ are chosen on the $x$-axis.
- Then, $N$ columns (numbered $1$ through $N$) are made. For simplicity, the columns are represented as vertical segments; for each valid $i$, the height of the $i$-th segment is $H_i$.
- Ada assigns a column to each of the points $X_1, X_2, \ldots, X_N$ in an arbitrary way (each column must be assigned to exactly one point).
- Finally, Ada constructs the roof of the restaurant, represented by a polyline with $N$ vertices. Let's denote the column assigned to the $i$-th point by $P_i$. For each valid $i$, the $i$-th of these vertices is $(X_i, H_{P_i})$, i.e. the polyline joins the tops of the columns from left to right.
Ada wants the biggest restaurant. Help her choose the positions of the columns in such a way that the area below the roof is the biggest possible. Formally, she wants to maximise the area of the polygon whose perimeter is formed by the roof and the segments $(X_N, H_{P_N}) - (X_N, 0) - (X_1, 0) - (X_1, H_{P_1})$. Let $S$ be this maximum area; you should compute $2 \cdot S$ (it is guaranteed that $2 \cdot S$ is an integer).
-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- $N$ lines follow. For each valid $i$, the $i$-th of these lines contains two space-separated integers $X_i$ and $H_i$.
-----Output-----
For each test case, print a single line containing one integer $2 \cdot S$.
-----Constraints-----
- $1 \le T \le 3 \cdot 10^5$
- $2 \le N \le 10^5$
- $0 \le X_1 < X_2 < \ldots < X_N \le 2 \cdot 10^9$
- $1 \le H_i \le 10^9$ for each valid $i$
- the sum of $N$ over all test cases does not exceed $10^6$
-----Example Input-----
1
5
1 1
2 2
3 3
4 4
5 5
-----Example Output-----
27
-----Explanation-----
|
{"inputs": ["1\n5\n1 1\n2 2\n3 3\n4 4\n5 5"], "outputs": ["27"]}
| 614
| 35
|
coding
|
Solve the programming task below in a Python markdown code block.
You've got string s, consisting of small English letters. Some of the English letters are good, the rest are bad.
A substring s[l...r] (1 ≤ l ≤ r ≤ |s|) of string s = s_1s_2...s_{|}s| (where |s| is the length of string s) is string s_{l}s_{l} + 1...s_{r}.
The substring s[l...r] is good, if among the letters s_{l}, s_{l} + 1, ..., s_{r} there are at most k bad ones (look at the sample's explanation to understand it more clear).
Your task is to find the number of distinct good substrings of the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their content is different, i.e. s[x...y] ≠ s[p...q].
-----Input-----
The first line of the input is the non-empty string s, consisting of small English letters, the string's length is at most 1500 characters.
The second line of the input is the string of characters "0" and "1", the length is exactly 26 characters. If the i-th character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
The third line of the input consists a single integer k (0 ≤ k ≤ |s|) — the maximum acceptable number of bad characters in a good substring.
-----Output-----
Print a single integer — the number of distinct good substrings of string s.
-----Examples-----
Input
ababab
01000000000000000000000000
1
Output
5
Input
acbacbacaa
00000000000000000000000000
2
Output
8
-----Note-----
In the first example there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second example there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
|
{"inputs": ["a\n00000000000000000000000000\n0\n", "a\n00000000000000000000000000\n0\n", "a\n00000000000000000100000000\n0\n", "aaaa\n00000000000000000000000000\n0\n", "aaaa\n00000000000000000000000000\n0\n", "aaaa\n10000000000000000000000000\n0\n", "ababab\n01000000000000000000000000\n1\n", "aaaaaa\n00000000000000000000000000\n1\n"], "outputs": ["0\n", "0", "0\n", "0\n", "0", "4\n", "5\n", "1\n"]}
| 529
| 303
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a sequence $A_1, A_2, \ldots, A_N$. You have to split the array into maximum number of non-empty subarrays such that the gcd of elements of each subarray is equal to 1.
-----Input:-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
- The first line of each test case contains a single integer $N$.
- The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$.
-----Output:-----
For each test case, print a single line containing one integer ― the maximum number of subarrays formed, or $-1$ if the array cannot be split while satisfying the above condition.
-----Constraints-----
- $1 \le T \le 3$
- $1 \le N \le 5 \cdot 10^5$
- $1 \le A_i \le 10^6$ for each valid $i$
-----Sample Input:-----
2
3
2 2 3
4
2 3 3 2
-----Sample Output:-----
1
2
|
{"inputs": ["2\n3\n2 2 3\n4\n2 3 3 2"], "outputs": ["1\n2"]}
| 272
| 32
|
coding
|
Solve the programming task below in a Python markdown code block.
The football season has just ended in Berland. According to the rules of Berland football, each match is played between two teams. The result of each match is either a draw, or a victory of one of the playing teams. If a team wins the match, it gets w points, and the opposing team gets 0 points. If the game results in a draw, both teams get d points.
The manager of the Berland capital team wants to summarize the results of the season, but, unfortunately, all information about the results of each match is lost. The manager only knows that the team has played n games and got p points for them.
You have to determine three integers x, y and z — the number of wins, draws and loses of the team. If there are multiple answers, print any of them. If there is no suitable triple (x, y, z), report about it.
Input
The first line contains four integers n, p, w and d (1 ≤ n ≤ 10^{12}, 0 ≤ p ≤ 10^{17}, 1 ≤ d < w ≤ 10^{5}) — the number of games, the number of points the team got, the number of points awarded for winning a match, and the number of points awarded for a draw, respectively. Note that w > d, so the number of points awarded for winning is strictly greater than the number of points awarded for draw.
Output
If there is no answer, print -1.
Otherwise print three non-negative integers x, y and z — the number of wins, draws and losses of the team. If there are multiple possible triples (x, y, z), print any of them. The numbers should meet the following conditions:
* x ⋅ w + y ⋅ d = p,
* x + y + z = n.
Examples
Input
30 60 3 1
Output
17 9 4
Input
10 51 5 4
Output
-1
Input
20 0 15 5
Output
0 0 20
Note
One of the possible answers in the first example — 17 wins, 9 draws and 4 losses. Then the team got 17 ⋅ 3 + 9 ⋅ 1 = 60 points in 17 + 9 + 4 = 30 games.
In the second example the maximum possible score is 10 ⋅ 5 = 50. Since p = 51, there is no answer.
In the third example the team got 0 points, so all 20 games were lost.
|
{"inputs": ["10 2 5 3\n", "10 2 5 4\n", "100 1 5 4\n", "10 6 10 9\n", "27 60 3 1\n", "20 0 28 5\n", "101 1 5 4\n", "10 2 10 9\n"], "outputs": ["-1\n", "-1\n", "-1\n", "-1\n", "20 0 7\n", "0 0 20\n", "-1\n", "-1\n"]}
| 583
| 143
|
coding
|
Solve the programming task below in a Python markdown code block.
Passer ratings are the generally accepted standard for evaluating NFL quarterbacks.
I knew a rating of 100 is pretty good, but never knew what makes up the rating.
So out of curiosity I took a look at the wikipedia page and had an idea or my first kata: https://en.wikipedia.org/wiki/Passer_rating
## Formula
There are four parts to the NFL formula:
```python
A = ((Completions / Attempts) - .3) * 5
B = ((Yards / Attempts) - 3) * .25
C = (Touchdowns / Attempt) * 20
D = 2.375 - ((Interceptions / Attempts) * 25)
```
However, if the result of any calculation is greater than `2.375`, it is set to `2.375`. If the result is a negative number, it is set to zero.
Finally the passer rating is: `((A + B + C + D) / 6) * 100`
Return the rating rounded to the nearest tenth.
## Example
Last year Tom Brady had 432 attempts, 3554 yards, 291 completions, 28 touchdowns, and 2 interceptions.
His passer rating was 112.2
Happy coding!
Also feel free to reuse/extend the following starter code:
```python
def passer_rating(att, yds, comp, td, ints):
```
|
{"functional": "_inputs = [[432, 3554, 291, 28, 2], [5, 76, 4, 1, 0], [48, 192, 19, 2, 3], [1, 2, 1, 1, 0], [34, 172, 20, 1, 1], [10, 17, 2, 0, 1]]\n_outputs = [[112.2], [158.3], [39.6], [118.8], [69.7], [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 return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(passer_rating(*i), o[0])"}
| 325
| 296
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an array of positive integers a_1, a_2, ..., a_{n} × T of length n × T. We know that for any i > n it is true that a_{i} = a_{i} - n. Find the length of the longest non-decreasing sequence of the given array.
-----Input-----
The first line contains two space-separated integers: n, T (1 ≤ n ≤ 100, 1 ≤ T ≤ 10^7). The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 300).
-----Output-----
Print a single number — the length of a sought sequence.
-----Examples-----
Input
4 3
3 1 4 2
Output
5
-----Note-----
The array given in the sample looks like that: 3, 1, 4, 2, 3, 1, 4, 2, 3, 1, 4, 2. The elements in bold form the largest non-decreasing subsequence.
|
{"inputs": ["1 1\n5\n", "1 1\n5\n", "1 1\n10\n", "1 1\n12\n", "2 1\n1 2\n", "2 2\n1 2\n", "2 2\n1 2\n", "2 1\n1 2\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "2\n", "3\n", "3\n", "2\n"]}
| 249
| 112
|
coding
|
Solve the programming task below in a Python markdown code block.
Lucy likes letters. She studied the definition of the lexicographical order at school and plays with it.
At first, she tried to construct the lexicographically smallest word out of given letters. It was so easy! Then she tried to build multiple words and minimize one of them. This was much harder!
Formally, Lucy wants to make n words of length l each out of the given n ⋅ l letters, so that the k-th of them in the lexicographic order is lexicographically as small as possible.
Input
The first line contains three integers n, l, and k (1≤ k ≤ n ≤ 1 000; 1 ≤ l ≤ 1 000) — the total number of words, the length of each word, and the index of the word Lucy wants to minimize.
The next line contains a string of n ⋅ l lowercase letters of the English alphabet.
Output
Output n words of l letters each, one per line, using the letters from the input. Words must be sorted in the lexicographic order, and the k-th of them must be lexicographically as small as possible. If there are multiple answers with the smallest k-th word, output any of them.
Examples
Input
3 2 2
abcdef
Output
af
bc
ed
Input
2 3 1
abcabc
Output
aab
bcc
|
{"inputs": ["1 1 1\nv\n", "1 1 1\nn\n", "1 1 1\nz\n", "1 1 1\nd\n", "1 1 1\nb\n", "1 1 1\ny\n", "1 1 1\nc\n", "1 1 1\nx\n"], "outputs": ["v\n", "n\n", "z\n", "d\n", "b\n", "y\n", "c\n", "x\n"]}
| 306
| 118
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array ribbons, where ribbons[i] represents the length of the ith ribbon, and an integer k. You may cut any of the ribbons into any number of segments of positive integer lengths, or perform no cuts at all.
For example, if you have a ribbon of length 4, you can:
Keep the ribbon of length 4,
Cut it into one ribbon of length 3 and one ribbon of length 1,
Cut it into two ribbons of length 2,
Cut it into one ribbon of length 2 and two ribbons of length 1, or
Cut it into four ribbons of length 1.
Your goal is to obtain k ribbons of all the same positive integer length. You are allowed to throw away any excess ribbon as a result of cutting.
Return the maximum possible positive integer length that you can obtain k ribbons of, or 0 if you cannot obtain k ribbons of the same length.
Please complete the following python code precisely:
```python
class Solution:
def maxLength(self, ribbons: List[int], k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(ribbons = [9,7,5], k = 3) == 5\n assert candidate(ribbons = [7,5,9], k = 4) == 4\n assert candidate(ribbons = [5,7,9], k = 22) == 0\n\n\ncheck(Solution().maxLength)"}
| 250
| 88
|
coding
|
Solve the programming task below in a Python markdown code block.
Prefix function of string $t = t_1 t_2 \ldots t_n$ and position $i$ in it is defined as the length $k$ of the longest proper (not equal to the whole substring) prefix of substring $t_1 t_2 \ldots t_i$ which is also a suffix of the same substring.
For example, for string $t = $ abacaba the values of the prefix function in positions $1, 2, \ldots, 7$ are equal to $[0, 0, 1, 0, 1, 2, 3]$.
Let $f(t)$ be equal to the maximum value of the prefix function of string $t$ over all its positions. For example, $f($abacaba$) = 3$.
You are given a string $s$. Reorder its characters arbitrarily to get a string $t$ (the number of occurrences of any character in strings $s$ and $t$ must be equal). The value of $f(t)$ must be minimized. Out of all options to minimize $f(t)$, choose the one where string $t$ is the lexicographically smallest.
-----Input-----
Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^5$). Description of the test cases follows.
The only line of each test case contains string $s$ ($1 \le |s| \le 10^5$) consisting of lowercase English letters.
It is guaranteed that the sum of lengths of $s$ over all test cases does not exceed $10^5$.
-----Output-----
For each test case print a single string $t$.
The multisets of letters in strings $s$ and $t$ must be equal. The value of $f(t)$, the maximum of prefix functions in string $t$, must be as small as possible. String $t$ must be the lexicographically smallest string out of all strings satisfying the previous conditions.
-----Examples-----
Input
3
vkcup
abababa
zzzzzz
Output
ckpuv
aababab
zzzzzz
-----Note-----
A string $a$ is lexicographically smaller than a string $b$ if and only if one of the following holds:
$a$ is a prefix of $b$, but $a \ne b$;
in the first position where $a$ and $b$ differ, the string $a$ has a letter that appears earlier in the alphabet than the corresponding letter in $b$.
In the first test case, $f(t) = 0$ and the values of prefix function are $[0, 0, 0, 0, 0]$ for any permutation of letters. String ckpuv is the lexicographically smallest permutation of letters of string vkcup.
In the second test case, $f(t) = 1$ and the values of prefix function are $[0, 1, 0, 1, 0, 1, 0]$.
In the third test case, $f(t) = 5$ and the values of prefix function are $[0, 1, 2, 3, 4, 5]$.
|
{"inputs": ["3\nvkcup\nabababa\nzzzzzz\n"], "outputs": ["ckpuv\naababab\nzzzzzz\n"]}
| 708
| 36
|
coding
|
Solve the programming task below in a Python markdown code block.
We want to know the index of the vowels in a given word, for example, there are two vowels in the word super (the second and fourth letters).
So given a string "super", we should return a list of [2, 4].
Some examples:
Mmmm => []
Super => [2,4]
Apple => [1,5]
YoMama -> [1,2,4,6]
**NOTES:**
* Vowels in this context refers to: a e i o u y (including upper case)
* This is indexed from `[1..n]` (not zero indexed!)
Also feel free to reuse/extend the following starter code:
```python
def vowel_indices(word):
```
|
{"functional": "_inputs = [['mmm'], ['apple'], ['super'], ['orange'], ['grapes'], ['supercalifragilisticexpialidocious'], ['123456'], ['crIssUm'], ['Implied'], ['rIc'], ['UNDISARMED'], ['bialy'], ['stumpknocker'], ['narboonnee'], ['carlstadt'], ['ephodee'], ['spicery'], ['oftenness'], ['bewept'], ['capsized']]\n_outputs = [[[]], [[1, 5]], [[2, 4]], [[1, 3, 6]], [[3, 5]], [[2, 4, 7, 9, 12, 14, 16, 19, 21, 24, 25, 27, 29, 31, 32, 33]], [[]], [[3, 6]], [[1, 5, 6]], [[2]], [[1, 4, 6, 9]], [[2, 3, 5]], [[3, 8, 11]], [[2, 5, 6, 9, 10]], [[2, 7]], [[1, 4, 6, 7]], [[3, 5, 7]], [[1, 4, 7]], [[2, 4]], [[2, 5, 7]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(vowel_indices(*i), o[0])"}
| 168
| 458
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given three strings a, b, and c, your task is to find a string that has the minimum length and contains all three strings as substrings.
If there are multiple such strings, return the lexicographically smallest one.
Return a string denoting the answer to the problem.
Notes
A string a is lexicographically smaller than a string b (of the same length) if in the first position where a and b differ, string a has a letter that appears earlier in the alphabet than the corresponding letter in b.
A substring is a contiguous sequence of characters within a string.
Please complete the following python code precisely:
```python
class Solution:
def minimumString(self, a: str, b: str, c: str) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(a = \"abc\", b = \"bca\", c = \"aaa\") == \"aaabca\"\n assert candidate(a = \"ab\", b = \"ba\", c = \"aba\") == \"aba\"\n\n\ncheck(Solution().minimumString)"}
| 173
| 68
|
coding
|
Solve the programming task below in a Python markdown code block.
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single line of input, one integer $K$.
-----Output:-----
For each test case, output as the pattern.
-----Constraints-----
- $1 \leq T \leq 100$
- $1 \leq K \leq 100$
-----Sample Input:-----
4
1
2
3
4
-----Sample Output:-----
1
13
57
135
7911
131517
1357
9111315
17192123
25272931
-----EXPLANATION:-----
No need, else pattern can be decode easily.
|
{"inputs": ["4\n1\n2\n3\n4"], "outputs": ["1\n13\n57\n135\n7911\n131517\n1357\n9111315\n17192123\n25272931"]}
| 231
| 73
|
coding
|
Solve the programming task below in a Python markdown code block.
Abhishek is fond of playing cricket very much. One morning, he is playing cricket with his friends. Abhishek is a right-hand batsman
.He has to face all types of balls either good or bad. There are total 26 balls in the game and each ball is represented
by one of the following two ways:-
1. "g" denotes a good ball.
2. "b" denotes a bad ball.
All 26 balls are represented by lower case letters (a,b,.....z).
Balls faced by Abhishek are represented as a string s, all the characters of which are lower case i.e, within 26 above mentioned balls.
A substring s[l...r] (1≤l≤r≤|s|) of string s=s1s2...s|s| (where |s| is the length of string s) is string slsl+1...sr.
The substring s[l...r] is good, if among the letters slsl+1...sr, there are at most k bad ones (refer sample explanation ).
Your task is to find out the number of distinct good substrings for the given string s. Two substrings s[x...y] and s[p...q] are considered distinct if their contents are different, i.e. s[x...y]≠s[p...q].
-----Input Format-----
First Line contains an integer T, number of test cases. For each test case, first line contains a string - a sequence of balls faced by Abhishek.
And, next line contains a string of characters "g" and "b" of length 26 characters. If the ith character of this string equals "1", then the i-th English letter is good, otherwise it's bad. That is, the first character of this string corresponds to letter "a", the second one corresponds to letter "b" and so on.
And, the third line of the test case consists of a single integer k (0≤k≤|s|) — the maximum acceptable number of bad characters in a good substring.
-----Output Format -----
For each test case, print a single integer — the number of distinct good substrings of string s.
-----Constraints-----
- 1<=T<=1000
- 1<=|s|<=2000
- 0<=k<=|s|
-----Subtasks-----
Subtask 1 : 20 Points
- 1<=T<=10
- 1<=|s|<=20
- 0<=k<=|s|
Subtask 2 : 80 Points
Original Constraints
Sample Input
2
ababab
bgbbbbbbbbbbbbbbbbbbbbbbbb
1
acbacbacaa
bbbbbbbbbbbbbbbbbbbbbbbbbb
2
Sample Output
5
8
Explanation
In the first test case there are following good substrings: "a", "ab", "b", "ba", "bab".
In the second test case there are following good substrings: "a", "aa", "ac", "b", "ba", "c", "ca", "cb".
|
{"inputs": ["2\nababab\nbgbbbbbbbbbbbbbbbbbbbbbbbb\n1\nacbacbacaa\nbbbbbbbbbbbbbbbbbbbbbbbbbb\n2"], "outputs": ["5\n8"]}
| 673
| 43
|
coding
|
Solve the programming task below in a Python markdown code block.
Gottfried learned about binary number representation. He then came up with this task and presented it to you.
You are given a collection of $n$ non-negative integers $a_1, \ldots, a_n$. You are allowed to perform the following operation: choose two distinct indices $1 \leq i, j \leq n$. If before the operation $a_i = x$, $a_j = y$, then after the operation $a_i = x~\mathsf{AND}~y$, $a_j = x~\mathsf{OR}~y$, where $\mathsf{AND}$ and $\mathsf{OR}$ are bitwise AND and OR respectively (refer to the Notes section for formal description). The operation may be performed any number of times (possibly zero).
After all operations are done, compute $\sum_{i=1}^n a_i^2$ — the sum of squares of all $a_i$. What is the largest sum of squares you can achieve?
-----Input-----
The first line contains a single integer $n$ ($1 \leq n \leq 2 \cdot 10^5$).
The second line contains $n$ integers $a_1, \ldots, a_n$ ($0 \leq a_i < 2^{20}$).
-----Output-----
Print a single integer — the largest possible sum of squares that can be achieved after several (possibly zero) operations.
-----Examples-----
Input
1
123
Output
15129
Input
3
1 3 5
Output
51
Input
2
349525 699050
Output
1099509530625
-----Note-----
In the first sample no operation can be made, thus the answer is $123^2$.
In the second sample we can obtain the collection $1, 1, 7$, and $1^2 + 1^2 + 7^2 = 51$.
If $x$ and $y$ are represented in binary with equal number of bits (possibly with leading zeros), then each bit of $x~\mathsf{AND}~y$ is set to $1$ if and only if both corresponding bits of $x$ and $y$ are set to $1$. Similarly, each bit of $x~\mathsf{OR}~y$ is set to $1$ if and only if at least one of the corresponding bits of $x$ and $y$ are set to $1$. For example, $x = 3$ and $y = 5$ are represented as $011_2$ and $101_2$ (highest bit first). Then, $x~\mathsf{AND}~y = 001_2 = 1$, and $x~\mathsf{OR}~y = 111_2 = 7$.
|
{"inputs": ["1\n0\n", "1\n0\n", "1\n1\n", "1\n42\n", "1\n17\n", "1\n123\n", "1\n167\n", "1\n123\n"], "outputs": ["0\n", "0\n", "1\n", "1764\n", "289\n", "15129\n", "27889\n", "15129\n"]}
| 649
| 111
|
coding
|
Solve the programming task below in a Python markdown code block.
n people came to a party. Then those, who had no friends among people at the party, left. Then those, who had exactly 1 friend among those who stayed, left as well. Then those, who had exactly 2, 3, ..., n - 1 friends among those who stayed by the moment of their leaving, did the same.
What is the maximum amount of people that could stay at the party in the end?
Input
The first input line contains one number t — amount of tests (1 ≤ t ≤ 105). Each of the following t lines contains one integer number n (1 ≤ n ≤ 105).
Output
For each test output in a separate line one number — the maximum amount of people that could stay in the end.
Examples
Input
1
3
Output
1
|
{"inputs": ["1\n4\n", "1\n2\n", "1\n7\n", "1\n5\n", "1\n6\n", "1\n9\n", "1\n8\n", "1\n1\n"], "outputs": ["2\n", "0\n", "5\n", "3\n", "4\n", "7\n", "6\n", "0\n"]}
| 185
| 86
|
coding
|
Solve the programming task below in a Python markdown code block.
### Description:
Remove all exclamation marks from sentence except at the end.
### Examples
```
remove("Hi!") == "Hi!"
remove("Hi!!!") == "Hi!!!"
remove("!Hi") == "Hi"
remove("!Hi!") == "Hi!"
remove("Hi! Hi!") == "Hi Hi!"
remove("Hi") == "Hi"
```
Also feel free to reuse/extend the following starter code:
```python
def remove(s):
```
|
{"functional": "_inputs = [['Hi!'], ['Hi!!!'], ['!Hi'], ['!Hi!'], ['Hi! Hi!'], ['Hi']]\n_outputs = [['Hi!'], ['Hi!!!'], ['Hi'], ['Hi!'], ['Hi Hi!'], ['Hi']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(remove(*i), o[0])"}
| 108
| 196
|
coding
|
Solve the programming task below in a Python markdown code block.
Complete the function, which calculates how much you need to tip based on the total amount of the bill and the service.
You need to consider the following ratings:
- Terrible: tip 0%
- Poor: tip 5%
- Good: tip 10%
- Great: tip 15%
- Excellent: tip 20%
The rating is **case insensitive** (so "great" = "GREAT"). If an unrecognised rating is received, then you need to return:
* `"Rating not recognised"` in Javascript, Python and Ruby...
* ...or `null` in Java
* ...or `-1` in C#
Because you're a nice person, you **always round up** the tip, regardless of the service.
Also feel free to reuse/extend the following starter code:
```python
def calculate_tip(amount, rating):
```
|
{"functional": "_inputs = [[30, 'poor'], [20, 'Excellent'], [20, 'hi'], [107.65, 'GReat'], [20, 'great!']]\n_outputs = [[2], [4], ['Rating not recognised'], [17], ['Rating not recognised']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(calculate_tip(*i), o[0])"}
| 192
| 212
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n friends that are playing a game. The friends are sitting in a circle and are numbered from 1 to n in clockwise order. More formally, moving clockwise from the ith friend brings you to the (i+1)th friend for 1 <= i < n, and moving clockwise from the nth friend brings you to the 1st friend.
The rules of the game are as follows:
Start at the 1st friend.
Count the next k friends in the clockwise direction including the friend you started at. The counting wraps around the circle and may count some friends more than once.
The last friend you counted leaves the circle and loses the game.
If there is still more than one friend in the circle, go back to step 2 starting from the friend immediately clockwise of the friend who just lost and repeat.
Else, the last friend in the circle wins the game.
Given the number of friends, n, and an integer k, return the winner of the game.
Please complete the following python code precisely:
```python
class Solution:
def findTheWinner(self, n: int, k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 5, k = 2) == 3\n assert candidate(n = 6, k = 5) == 1\n\n\ncheck(Solution().findTheWinner)"}
| 251
| 54
|
coding
|
Solve the programming task below in a Python markdown code block.
# Summation
Write a program that finds the summation of every number from 1 to num. The number will always be a positive integer greater than 0.
For example:
```if-not:racket
~~~
summation(2) -> 3
1 + 2
summation(8) -> 36
1 + 2 + 3 + 4 + 5 + 6 + 7 + 8
~~~
```
```if:racket
~~~racket
(summation 2) ; 3 (+ 1 2)
(summation 8) ; 36 (+ 1 2 3 4 5 6 7 8)
~~~
```
Also feel free to reuse/extend the following starter code:
```python
def summation(num):
```
|
{"functional": "_inputs = [[1], [8], [22], [100], [213]]\n_outputs = [[1], [36], [253], [5050], [22791]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(summation(*i), o[0])"}
| 189
| 194
|
coding
|
Solve the programming task below in a Python markdown code block.
Champa loved traveling the world. He loved going from one city to the other. Being the miser that he is, he never wishes spend any money. Champa, instead, jumps from one city to the other. Also he likes trips of high quality.
He can start at any city of his choice. Given that he has visited the i^th city, he will not visit it again, he will only visit the remaining unvisited cities. This means that Champa will jump n - 1 times in total, so that he can visit all of the n cities.
Given two cities at heights, A and B, the amount of money spent is Q * |A - B| where Q is the quality of a trip. Champa has a list of cities he's dying to visit. Can you tell the minimum amount of money Champa would have to spend to visit all of the cities?
Input
The first line contains T, the number of test cases.
Each test case is described by two lines.
The first line of each test case contains N describing the number of cities that Champa wishes to visit, followed by Q, which is the quality of the whole trip.
The following line contains N space separated integers Hi which describes the height of the i^th city.
Output
T lines each containing a single integer such that the answer to the i^th line contains the answer to the i^th test case.
Constraints
1 ≤ T, Q, N ≤ 10^3
1 ≤ Hi ≤ 3 * 10^6
SAMPLE INPUT
2
2 4
2 1
1 5
3
SAMPLE OUTPUT
4
0
Explanation
In the first test case, there are two cities that Champa wishes to visit. The difference in heights between the two cities is 1 and the quality of the trip is 4.
So, the output is 4 * 1 = 4.
In the second test case, there is just one city. As a result of this there is no jump.
So, the output is 0 * 5 = 0.
|
{"inputs": ["1\n2 1000\n1 3000000\n"], "outputs": ["2999999000\n"]}
| 450
| 40
|
coding
|
Solve the programming task below in a Python markdown code block.
The [Sharkovsky's Theorem](https://en.wikipedia.org/wiki/Sharkovskii%27s_theorem) involves the following ordering of the natural numbers:
```math
3≺5≺7≺9≺ ...\\
≺2·3≺2·5≺2·7≺2·9≺...\\
≺2^n·3≺2^n·5≺2^n·7≺2^n·9≺...\\
≺2^{(n+1)}·3≺2^{(n+1)}·5≺2^{(n+1)}·7≺2^{(n+1)}·9≺...\\
≺2^n≺2^{(n-1)}≺...\\
≺4≺2≺1\\
```
Your task is to complete the function which returns `true` if `$a≺b$` according to this ordering, and `false` otherwise.
You may assume both `$a$` and `$b$` are non-zero positive integers.
Also feel free to reuse/extend the following starter code:
```python
def sharkovsky(a, b):
```
|
{"functional": "_inputs = [[18, 12], [3, 9], [10, 16], [1, 22], [32, 1024], [17, 17]]\n_outputs = [[True], [True], [True], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(sharkovsky(*i), o[0])"}
| 250
| 214
|
coding
|
Solve the programming task below in a Python markdown code block.
Jon Snow now has to fight with White Walkers. He has n rangers, each of which has his own strength. Also Jon Snow has his favourite number x. Each ranger can fight with a white walker only if the strength of the white walker equals his strength. He however thinks that his rangers are weak and need to improve. Jon now thinks that if he takes the bitwise XOR of strengths of some of rangers with his favourite number x, he might get soldiers of high strength. So, he decided to do the following operation k times:
Arrange all the rangers in a straight line in the order of increasing strengths.
Take the bitwise XOR (is written as $\oplus$) of the strength of each alternate ranger with x and update it's strength.
Suppose, Jon has 5 rangers with strengths [9, 7, 11, 15, 5] and he performs the operation 1 time with x = 2. He first arranges them in the order of their strengths, [5, 7, 9, 11, 15]. Then he does the following:
The strength of first ranger is updated to $5 \oplus 2$, i.e. 7.
The strength of second ranger remains the same, i.e. 7.
The strength of third ranger is updated to $9 \oplus 2$, i.e. 11.
The strength of fourth ranger remains the same, i.e. 11.
The strength of fifth ranger is updated to $15 \oplus 2$, i.e. 13.
The new strengths of the 5 rangers are [7, 7, 11, 11, 13]
Now, Jon wants to know the maximum and minimum strength of the rangers after performing the above operations k times. He wants your help for this task. Can you help him?
-----Input-----
First line consists of three integers n, k, x (1 ≤ n ≤ 10^5, 0 ≤ k ≤ 10^5, 0 ≤ x ≤ 10^3) — number of rangers Jon has, the number of times Jon will carry out the operation and Jon's favourite number respectively.
Second line consists of n integers representing the strengths of the rangers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^3).
-----Output-----
Output two integers, the maximum and the minimum strength of the rangers after performing the operation k times.
-----Examples-----
Input
5 1 2
9 7 11 15 5
Output
13 7
Input
2 100000 569
605 986
Output
986 605
|
{"inputs": ["1 1 1\n1\n", "1 1 1\n1\n", "1 2 1\n1\n", "2 3 5\n1 2\n", "2 1 5\n1 2\n", "2 1 5\n1 2\n", "2 3 5\n1 2\n", "2 1 5\n1 1\n"], "outputs": ["0 0", "0 0\n", "1 1\n", "7 1", "4 2", "4 2\n", "7 1\n", "4 1\n"]}
| 608
| 141
|
coding
|
Solve the programming task below in a Python markdown code block.
Little Petya very much likes playing with little Masha. Recently he has received a game called "Zero-One" as a gift from his mother. Petya immediately offered Masha to play the game with him.
Before the very beginning of the game several cards are lain out on a table in one line from the left to the right. Each card contains a digit: 0 or 1. Players move in turns and Masha moves first. During each move a player should remove a card from the table and shift all other cards so as to close the gap left by the removed card. For example, if before somebody's move the cards on the table formed a sequence 01010101, then after the fourth card is removed (the cards are numbered starting from 1), the sequence will look like that: 0100101.
The game ends when exactly two cards are left on the table. The digits on these cards determine the number in binary notation: the most significant bit is located to the left. Masha's aim is to minimize the number and Petya's aim is to maximize it.
An unpleasant accident occurred before the game started. The kids spilled juice on some of the cards and the digits on the cards got blurred. Each one of the spoiled cards could have either 0 or 1 written on it. Consider all possible variants of initial arrangement of the digits (before the juice spilling). For each variant, let's find which two cards are left by the end of the game, assuming that both Petya and Masha play optimally. An ordered pair of digits written on those two cards is called an outcome. Your task is to find the set of outcomes for all variants of initial digits arrangement.
Input
The first line contains a sequence of characters each of which can either be a "0", a "1" or a "?". This sequence determines the initial arrangement of cards on the table from the left to the right. The characters "?" mean that the given card was spoiled before the game. The sequence's length ranges from 2 to 105, inclusive.
Output
Print the set of outcomes for all possible initial digits arrangements. Print each possible outcome on a single line. Each outcome should be represented by two characters: the digits written on the cards that were left by the end of the game. The outcomes should be sorted lexicographically in ascending order (see the first sample).
Examples
Input
????
Output
00
01
10
11
Input
1010
Output
10
Input
1?1
Output
01
11
Note
In the first sample all 16 variants of numbers arrangement are possible. For the variant 0000 the outcome is 00. For the variant 1111 the outcome is 11. For the variant 0011 the outcome is 01. For the variant 1100 the outcome is 10. Regardless of outcomes for all other variants the set which we are looking for will contain all 4 possible outcomes.
In the third sample only 2 variants of numbers arrangement are possible: 111 and 101. For the variant 111 the outcome is 11. For the variant 101 the outcome is 01, because on the first turn Masha can remove the first card from the left after which the game will end.
|
{"inputs": ["11\n", "??\n", "00\n", "10?\n", "01?\n", "1?1\n", "0101\n", "000?\n"], "outputs": ["11\n", "00\n01\n10\n11\n", "00\n", "00\n01\n", "00\n01\n", "01\n11\n", "01\n", "00\n"]}
| 735
| 111
|
coding
|
Solve the programming task below in a Python markdown code block.
Simple, remove the spaces from the string, then return the resultant string.
~~~if:c
For C, you must return a new dynamically allocated string.
~~~
Also feel free to reuse/extend the following starter code:
```python
def no_space(x):
```
|
{"functional": "_inputs = [['8 j 8 mBliB8g imjB8B8 jl B'], ['8 8 Bi fk8h B 8 BB8B B B B888 c hl8 BhB fd'], ['8aaaaa dddd r '], ['jfBm gk lf8hg 88lbe8 '], ['8j aam']]\n_outputs = [['8j8mBliB8gimjB8B8jlB'], ['88Bifk8hB8BB8BBBB888chl8BhBfd'], ['8aaaaaddddr'], ['jfBmgklf8hg88lbe8'], ['8jaam']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(no_space(*i), o[0])"}
| 68
| 303
|
coding
|
Solve the programming task below in a Python markdown code block.
Fibonacci numbers have the following form:
$\begin{aligned}F_1&-1\\ F_2&=1\\ F_3&=2\\ \vdots\\ F_n&=F_{n-2}+F_{n-1}\end{aligned}$
We have an array $a_1,a_2,\ldots,a_N$ which contains $N$ elements.
We want to find $\text{gcd}(F_{a_1},F_{a_2},F_{a_3},...,F_{a_N})$.
Input Format
The first line contains $N$, where $N$ denotes size of the array.
Each of the next $N$ lines contains a number: the $i^{th}$ line contains $a_i$.
Output Format
Print a single integer — the remainder of the division of the resulting number by $10^9+7$.
Constraints
$1\leq N\leq2\times10^5$
$1\leq a_i\leq10^{12}$
Sample Input 1
3
2
3
5
Sample Output 1
1
Explanation 1
$F_{2}=1$
$F_3=2$
$F_5=5$
$\text{gcd}(1,2,5)=1$
Sample Input 2
2
3
6
Sample Output 2
2
Explanation 2
$F_3=2$
$F_6=8$
$\text{gcd}(2,8)=2$
|
{"inputs": ["2\n3\n6\n", "3\n2\n3\n5\n"], "outputs": ["2\n", "1\n"]}
| 356
| 32
|
coding
|
Solve the programming task below in a Python markdown code block.
Find the symmetric difference of two sets $A = \\{a_0, a_1, ..., a_{n-1}\\}$ and $B = \\{b_0, b_1, ..., b_{m-1}\\}$.
Constraints
* $1 \leq n, m \leq 200,000$
* $0 \leq a_0 < a_1 < ... < a_{n-1} \leq 10^9$
* $0 \leq b_0 < b_1 < ... < b_{m-1} \leq 10^9$
Input
The input is given in the following format.
$n$
$a_0 \; a_1 \; ... \; a_{n-1}$
$m$
$b_0 \; b_1 \; ... \; b_{m-1}$
Elements in $A$ and $B$ are given in ascending order. There are no duplicate elements in each set.
Output
Print elements in the symmetric difference in ascending order. Print an element in a line.
Example
Input
7
1 2 3 4 5 6 7
4
2 4 6 8
Output
1
3
5
7
8
|
{"inputs": ["7\n1 2 3 4 5 6 8\n4\n2 4 6 8", "7\n1 2 3 4 5 6 7\n4\n1 4 6 8", "7\n1 2 3 4 5 6 8\n0\n4 9 6 9", "7\n1 2 3 4 5 6 7\n4\n2 4 6 8", "7\n1 2 3 4 5 6 7\n4\n2 4 6 11", "7\n1 2 3 4 5 6 7\n1\n2 4 6 11", "7\n1 2 3 4 5 6 10\n4\n1 4 6 8", "7\n1 2 3 4 5 6 10\n3\n1 4 6 8"], "outputs": ["1\n3\n5\n", "2\n3\n5\n7\n8\n", "1\n2\n3\n4\n5\n6\n8\n", "1\n3\n5\n7\n8", "1\n3\n5\n7\n11\n", "1\n3\n4\n5\n6\n7\n", "2\n3\n5\n8\n10\n", "2\n3\n5\n10\n"]}
| 288
| 324
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements [Bengali] , [Mandarin chinese] , [Russian] and [Vietnamese] as well.
There are two sequences $A_{1}, A_{2}, \dots, A_{N}$ and $B_{1}, B_{2}, \dots, B_{N}$. Answer $Q$ queries on these sequences.
In each query, you should calculate the dot product of subsequences $A_{x}, A_{x+1}, \dots, A_{x+l-1}$ and $B_{y}, B_{y+1}, \dots, B_{y+l-1}$, i.e. the value of the expression
$$\sum_{k=0}^{l-1} A_{x+k} B_{y+k} \,.$$
------ Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $Q$.
The second line contains $N$ space-separated integers $A_{1}, A_{2}, \dots, A_{N}$.
The third line contains $N$ space-separated integers $B_{1}, B_{2}, \dots, B_{N}$.
Each of the following $Q$ lines contains three space-separated integers $x$, $y$ and $l$ describing one query.
------ Output ------
For each query, print a single line containing one integer — the answer to the query (the dot product).
------ Constraints ------
$1 ≤ T ≤ 30,000$
$1 ≤ N, Q ≤ 10^{5}$
$1 ≤ A_{i}, B_{i} ≤ 10^{4}$ for each valid $i$
the sum of $N$ for all test cases does not exceed $10^{5}$
the sum of $Q$ for all test cases does not exceed $10^{5}$
----- Sample Input 1 ------
1
5 2
4 6 5 2 7
3 2 4 6 3
2 4 2
1 1 1
----- Sample Output 1 ------
51
12
|
{"inputs": ["1\n5 2\n4 6 5 2 7\n3 2 4 6 3\n2 4 2\n1 1 1"], "outputs": ["51\n12"]}
| 498
| 52
|
coding
|
Solve the programming task below in a Python markdown code block.
The Free Meteor Association (FMA) has got a problem: as meteors are moving, the Universal Cosmic Descriptive Humorous Program (UCDHP) needs to add a special module that would analyze this movement.
UCDHP stores some secret information about meteors as an n × m table with integers in its cells. The order of meteors in the Universe is changing. That's why the main UCDHP module receives the following queries:
* The query to swap two table rows;
* The query to swap two table columns;
* The query to obtain a secret number in a particular table cell.
As the main UCDHP module is critical, writing the functional of working with the table has been commissioned to you.
Input
The first line contains three space-separated integers n, m and k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 500000) — the number of table columns and rows and the number of queries, correspondingly.
Next n lines contain m space-separated numbers each — the initial state of the table. Each number p in the table is an integer and satisfies the inequality 0 ≤ p ≤ 106.
Next k lines contain queries in the format "si xi yi", where si is one of the characters "с", "r" or "g", and xi, yi are two integers.
* If si = "c", then the current query is the query to swap columns with indexes xi and yi (1 ≤ x, y ≤ m, x ≠ y);
* If si = "r", then the current query is the query to swap rows with indexes xi and yi (1 ≤ x, y ≤ n, x ≠ y);
* If si = "g", then the current query is the query to obtain the number that located in the xi-th row and in the yi-th column (1 ≤ x ≤ n, 1 ≤ y ≤ m).
The table rows are considered to be indexed from top to bottom from 1 to n, and the table columns — from left to right from 1 to m.
Output
For each query to obtain a number (si = "g") print the required number. Print the answers to the queries in the order of the queries in the input.
Examples
Input
3 3 5
1 2 3
4 5 6
7 8 9
g 3 2
r 3 2
c 2 3
g 2 2
g 3 2
Output
8
9
6
Input
2 3 3
1 2 4
3 1 5
c 2 1
r 1 2
g 1 3
Output
5
Note
Let's see how the table changes in the second test case.
After the first operation is fulfilled, the table looks like that:
2 1 4
1 3 5
After the second operation is fulfilled, the table looks like that:
1 3 5
2 1 4
So the answer to the third query (the number located in the first row and in the third column) will be 5.
|
{"inputs": ["1 2 1\n0 0\nc 1 2\n", "1 2 3\n1 2\nc 1 2\ng 1 1\ng 1 2\n", "2 1 3\n1\n2\nr 1 2\ng 1 1\ng 2 1\n", "1 2 3\n1 2\nc 1 2\ng 1 1\ng 1 1\n", "1 2 3\n0 2\nc 1 2\ng 1 1\ng 1 2\n", "1 2 3\n1 2\nc 1 2\ng 1 2\ng 1 2\n", "2 3 3\n1 0 4\n3 1 5\nc 2 1\nr 1 2\ng 1 3\n", "2 3 3\n1 2 4\n3 1 5\nc 2 2\nr 1 1\ng 1 3\n"], "outputs": ["\n", "2\n1\n", "2\n1\n", "2\n2\n", "2\n0\n", "1\n1\n", "5\n", "4\n"]}
| 695
| 292
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given four digits N_1, N_2, N_3 and N_4. Determine if these can be arranged into the sequence of digits "1974".
Constraints
* 0 \leq N_1, N_2, N_3, N_4 \leq 9
* N_1, N_2, N_3 and N_4 are integers.
Input
Input is given from Standard Input in the following format:
N_1 N_2 N_3 N_4
Output
If N_1, N_2, N_3 and N_4 can be arranged into the sequence of digits "1974", print `YES`; if they cannot, print `NO`.
Examples
Input
1 7 9 4
Output
YES
Input
1 9 7 4
Output
YES
Input
1 2 9 1
Output
NO
Input
4 9 0 8
Output
NO
|
{"inputs": ["1 2 3 1", "0 7 9 4", "1 3 3 1", "1 2 3 2", "1 0 3 2", "1 0 4 2", "1 0 0 2", "1 0 0 1"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 226
| 110
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Sereja have array A' that contain N integers. Now Sereja want to permute elements of the array, he want to use some permutation p, such that A[i] = A'[p[i]], where A - new array.
Lets function f(A,i) = S - A[i] - A[i +1] - ... - A[j], where j is the maximum possible index, such that A[i] + A[i + 1] + ... + A[j] ≤ S, if A[i] > S, f(A, i) = S.
Help Sereja to find such permutation p, such that (f(A, 1) + f(A, 2) + ... f(A, k))/k will be as low as possible.
------ Input ------
First line of input contain integer T - number of testcases. Next lines contain T testcases. First line of each testcase contain three integers N, k, S. Next line contain N integers - array A'.
------ Output ------
For each testcase output N numbers in one line - permutation p.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 2000$
$1 ≤ k ≤ N$
$1 ≤ A'[i] ≤ 10^{4}$
$1 ≤ S ≤ 10^{9}$
------ Example ------
Input:
2
3 2 4
3 4 1
4 4 1
1 1 1 1
Output:
2 1 3
4 3 2 1
------ Scoring ------
Suppose Sum will be sum of yours (f(A, 1) + f(A, 2) + ... f(A, k))/k per each testcase.
Lets B will be the smallest such sum. Your score will be equal to B/Sum. Lower scores will earn more points.
We have 20 official test files. You must correctly solve all test files to receive OK. During the contest, your overall score is the sum of the scores on the first 4 test files. After the contest, all solutions will be rescored by the sum of the scores on the rest 16 test files. Note, that public part of the tests may not contain some border cases.
|
{"inputs": ["2\n3 2 4\n3 4 1\n4 4 1\n1 1 1 1"], "outputs": ["2 1 3\n4 3 2 1"]}
| 510
| 50
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a rooted tree on N vertices. The nodes are numbered from 1 to N, and Node 1 is the root. Each node u has an associated value attached to it: Au.
For each vertex v, we consider the path going upwards from v to the root. Suppose that path is v1, v2, .., vk, where v1 = v and vk = 1. The cost of any node on this path is equal to the minimum value among all the nodes to its left in the path sequence, including itself. That is, cost(vi) = min1 <= j <= i{Avj}. And the cost of the path is the sum of costs of all the nodes in it.
For every node in the tree, find the cost of the path from that node to the root.
-----Input-----
- The first line of the input contains a single integer, N, denoting the number of nodes in the tree.
- The next line contains N-1 integers, the i-th of which denotes the parent of node i+1.
- The next line contains N integers, the i-th of which denotes Ai.
-----Output-----
Output a single line containing N integers, the i-th of which should be the cost of the path from node i to the root.
-----Constraints-----
- 1 ≤ N ≤ 100,000
- -1,000,000,000 ≤ Av ≤ 1,000,000,000
-----Subtasks-----
- Subtask #1 (30 points): 1 ≤ N ≤ 2000
- Subtask #2 (70 points): Original constraints.
-----Example-----
Input:
8
1 1 1 1 5 8 6
1 2 3 4 5 15 70 10
Output:
1 3 4 5 6 21 96 26
-----Explanation-----
For example, take a look at the path from vertex 7: The path is 7 -> 8 -> 6 -> 5 -> 1.
Cost(7) has no choice but to be A7. So Cost(7) = 70.
Cost(8) will be minimum of A7 and A8, which turns out to be A8. So Cost(8) = 10.
Cost(6) = minimum {A7, A8, A6} = minimum {70, 10, 15} = 10.
Cost(5) = minimum {70, 10, 15, 5} = 5.
Cost(1) = minimum {70, 10, 15, 5, 1} = 1.
So, the cost of the path from 7 to the root is 70 + 10 + 10 + 5 + 1 = 96.
|
{"inputs": ["8\n1 1 1 1 5 8 6\n1 2 3 4 5 15 70 10"], "outputs": ["1 3 4 5 6 21 96 26"]}
| 644
| 62
|
coding
|
Solve the programming task below in a Python markdown code block.
Alice has a binary string. She thinks a binary string is beautiful if and only if it doesn't contain the substring $\text{"010"}$.
In one step, Alice can change a $0$ to a $1$ or vice versa. Count and print the minimum number of steps needed to make Alice see the string as beautiful.
Example
$b=\textbf{010}$
She can change any one element and have a beautiful string.
Function Description
Complete the beautifulBinaryString function in the editor below.
beautifulBinaryString has the following parameter(s):
string b: a string of binary digits
Returns
int: the minimum moves required
Input Format
The first line contains an integer $n$, the length of binary string.
The second line contains a single binary string $\boldsymbol{b}$.
Constraints
$1\leq n\leq100$
$b[i]\in\{0,1\}$.
Output Format
Print the minimum number of steps needed to make the string beautiful.
Sample Input 0
STDIN Function
----- --------
7 length of string n = 7
0101010 b = '0101010'
Sample Output 0
2
Explanation 0:
In this sample, $b=\text{"0101010"}$
The figure below shows a way to get rid of each instance of $\text{"010"}$:
Make the string beautiful by changing $2$ characters ($b[2]$ and $b\left[5\right]$).
Sample Input 1
5
01100
Sample Output 1
0
Sample Case 1:
In this sample $b=\text{"01100"}$
Explanation 1
The substring $\text{"010"}$ does not occur in $\boldsymbol{b}$, so the string is already beautiful in $0$ moves.
Sample Input 2
10
0100101010
Sample Output 2
3
Explanation 2
In this sample $b=\text{"0100101010"}$
One solution is to change the values of $b[2],b[5]\:\text{and}\:b[9]$ to form a beautiful string.
|
{"inputs": ["5\n01100\n", "7\n0101010\n", "10\n0100101010\n"], "outputs": ["0\n", "2 \n", "3\n"]}
| 508
| 58
|
coding
|
Solve the programming task below in a Python markdown code block.
>When no more interesting kata can be resolved, I just choose to create the new kata, to solve their own, to enjoy the process --myjinxin2015 said
# Description:
Give you two number `m` and `n`(two positive integer, m < n), make a triangle pattern with number sequence `m to n`. The order is clockwise, starting from the top corner, like this:
```
When m=1 n=10 triangle is:
1
9 2
8 0 3
7 6 5 4
```
Note: The pattern only uses the last digit of each number; Each row separated by "\n"; Each digit separated by a space; Left side may need pad some spaces, but don't pad the right side; If `m to n` can not make the triangle, return `""`.
# Some examples:
```
makeTriangle(1,3) should return:
1
3 2
makeTriangle(6,20) should return:
6
7 7
6 8 8
5 0 9 9
4 3 2 1 0
makeTriangle(1,12) should return ""
```
Also feel free to reuse/extend the following starter code:
```python
def make_triangle(m,n):
```
|
{"functional": "_inputs = [[1, 12], [1, 100]]\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(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(make_triangle(*i), o[0])"}
| 313
| 167
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There is a malfunctioning keyboard where some letter keys do not work. All other keys on the keyboard work properly.
Given a string text of words separated by a single space (no leading or trailing spaces) and a string brokenLetters of all distinct letter keys that are broken, return the number of words in text you can fully type using this keyboard.
Please complete the following python code precisely:
```python
class Solution:
def canBeTypedWords(self, text: str, brokenLetters: str) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(text = \"hello world\", brokenLetters = \"ad\") == 1\n assert candidate(text = \"leet code\", brokenLetters = \"lt\") == 1\n assert candidate(text = \"leet code\", brokenLetters = \"e\") == 0\n\n\ncheck(Solution().canBeTypedWords)"}
| 124
| 78
|
coding
|
Solve the programming task below in a Python markdown code block.
```if-not:ruby
Create a function, that accepts an arbitrary number of arrays and returns a single array generated by alternately appending elements from the passed in arguments. If one of them is shorter than the others, the result should be padded with empty elements.
```
```if:ruby
Create a function, that accepts an arbitrary number of arrays and returns a single array generated by alternately appending elements from the passed in arguments. If one of them is shorter than the others, the result should be padded with `nil`s.
```
Examples:
```python
interleave([1, 2, 3], ["c", "d", "e"]) == [1, "c", 2, "d", 3, "e"]
interleave([1, 2, 3], [4, 5]) == [1, 4, 2, 5, 3, None]
interleave([1, 2, 3], [4, 5, 6], [7, 8, 9]) == [1, 4, 7, 2, 5, 8, 3, 6, 9]
interleave([]) == []
```
Also feel free to reuse/extend the following starter code:
```python
def interleave(*args):
```
|
{"functional": "_inputs = [[[1, 2, 3], ['c', 'd', 'e']], [[1, 2, 3], [4, 5]], [[1, 2], [3, 4, 5]], [[None], [None, None], [None, None, None]], [[1, 2, 3], [4, 5, 6], [7, 8, 9]], [[]]]\n_outputs = [[[1, 'c', 2, 'd', 3, 'e']], [[1, 4, 2, 5, 3, None]], [[1, 3, 2, 4, None, 5]], [[None, None, None, None, None, None, None, None, None]], [[1, 4, 7, 2, 5, 8, 3, 6, 9]], [[]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(interleave(*i), o[0])"}
| 289
| 340
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
John is a programmer. He treasures his time very much. He lives on the `n` floor of a building. Every morning he will go downstairs as quickly as possible to begin his great work today.
There are two ways he goes downstairs: walking or taking the elevator.
When John uses the elevator, he will go through the following steps:
```
1. Waiting the elevator from m floor to n floor;
2. Waiting the elevator open the door and go in;
3. Waiting the elevator close the door;
4. Waiting the elevator down to 1 floor;
5. Waiting the elevator open the door and go out;
(the time of go in/go out the elevator will be ignored)
```
Given the following arguments:
```
n: An integer. The floor of John(1-based).
m: An integer. The floor of the elevator(1-based).
speeds: An array of integer. It contains four integer [a,b,c,d]
a: The seconds required when the elevator rises or falls 1 floor
b: The seconds required when the elevator open the door
c: The seconds required when the elevator close the door
d: The seconds required when John walks to n-1 floor
```
Please help John to calculate the shortest time to go downstairs.
# Example
For `n = 5, m = 6 and speeds = [1,2,3,10]`, the output should be `12`.
John go downstairs by using the elevator:
`1 + 2 + 3 + 4 + 2 = 12`
For `n = 1, m = 6 and speeds = [1,2,3,10]`, the output should be `0`.
John is already at 1 floor, so the output is `0`.
For `n = 5, m = 4 and speeds = [2,3,4,5]`, the output should be `20`.
John go downstairs by walking:
`5 x 4 = 20`
Also feel free to reuse/extend the following starter code:
```python
def shortest_time(n, m, speeds):
```
|
{"functional": "_inputs = [[5, 6, [1, 2, 3, 10]], [1, 6, [1, 2, 3, 10]], [5, 5, [1, 2, 3, 10]], [2, 2, [1, 2, 3, 10]], [2, 2, [2, 3, 4, 10]], [5, 4, [1, 2, 3, 10]], [5, 4, [2, 3, 4, 5]], [1, 6, [0, 0, 0, 0]], [1, 6, [0, 2, 0, 0]], [1, 6, [20, 0, 10, 0]]]\n_outputs = [[12], [0], [11], [8], [10], [12], [20], [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_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(shortest_time(*i), o[0])"}
| 464
| 372
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A sequence of numbers is called an arithmetic progression if the difference between any two consecutive elements is the same.
Given an array of numbers arr, return true if the array can be rearranged to form an arithmetic progression. Otherwise, return false.
Please complete the following python code precisely:
```python
class Solution:
def canMakeArithmeticProgression(self, arr: List[int]) -> bool:
```
|
{"functional": "def check(candidate):\n assert candidate(arr = [3,5,1]) == True\n assert candidate(arr = [1,2,4]) == False\n\n\ncheck(Solution().canMakeArithmeticProgression)"}
| 100
| 53
|
coding
|
Solve the programming task below in a Python markdown code block.
Petya and Vasya decided to play a little. They found n red cubes and m blue cubes. The game goes like that: the players take turns to choose a cube of some color (red or blue) and put it in a line from left to right (overall the line will have n + m cubes). Petya moves first. Petya's task is to get as many pairs of neighbouring cubes of the same color as possible. Vasya's task is to get as many pairs of neighbouring cubes of different colors as possible.
The number of Petya's points in the game is the number of pairs of neighboring cubes of the same color in the line, the number of Vasya's points in the game is the number of neighbouring cubes of the different color in the line. Your task is to calculate the score at the end of the game (Petya's and Vasya's points, correspondingly), if both boys are playing optimally well. To "play optimally well" first of all means to maximize the number of one's points, and second — to minimize the number of the opponent's points.
-----Input-----
The only line contains two space-separated integers n and m (1 ≤ n, m ≤ 10^5) — the number of red and blue cubes, correspondingly.
-----Output-----
On a single line print two space-separated integers — the number of Petya's and Vasya's points correspondingly provided that both players play optimally well.
-----Examples-----
Input
3 1
Output
2 1
Input
2 4
Output
3 2
-----Note-----
In the first test sample the optimal strategy for Petya is to put the blue cube in the line. After that there will be only red cubes left, so by the end of the game the line of cubes from left to right will look as [blue, red, red, red]. So, Petya gets 2 points and Vasya gets 1 point.
If Petya would choose the red cube during his first move, then, provided that both boys play optimally well, Petya would get 1 point and Vasya would get 2 points.
|
{"inputs": ["3 1\n", "2 4\n", "1 1\n", "2 1\n", "4 4\n", "1 2\n", "4 4\n", "1 2\n"], "outputs": ["2 1\n", "3 2\n", "0 1\n", "1 1\n", "3 4\n", "1 1\n", "3 4\n", "1 1\n"]}
| 476
| 102
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 2D integer array tiles where tiles[i] = [li, ri] represents that every tile j in the range li <= j <= ri is colored white.
You are also given an integer carpetLen, the length of a single carpet that can be placed anywhere.
Return the maximum number of white tiles that can be covered by the carpet.
Please complete the following python code precisely:
```python
class Solution:
def maximumWhiteTiles(self, tiles: List[List[int]], carpetLen: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(tiles = [[1,5],[10,11],[12,18],[20,25],[30,32]], carpetLen = 10) == 9\n assert candidate(tiles = [[10,11],[1,1]], carpetLen = 2) == 2\n\n\ncheck(Solution().maximumWhiteTiles)"}
| 128
| 93
|
coding
|
Solve the programming task below in a Python markdown code block.
Tim likes Math. He likes it so much that he always brings his tablets with him and reads math e-books everywhere, even during parties.
Tim found an interesting exercise in one of the e-books he is reading. But you want him to join the party, so you decide to answer the question for him.
The problem is: Given ${D}$ and ${P}$, how many ordered pairs of integers are there whose absolute difference is ${D}$ and whose product is ${P}$? In other words, how many pairs of integers $(A,B)$ are there such that:
$|A-B|=D$
$A\times B=P$
Input Format
The first line of input contains ${T}$, the number of test cases. The next ${T}$ lines describe the test cases.
Each test case consists of a single line containing two integers ${D}$ and ${P}$ separated by a single space.
Output Format
For each test case, output a single line containing a single integer which is the answer for that test case.
Constraints
$1\leq T\leq20000$
$|D|\leq10^9$
$|P|\leq10^9$
Sample Input
3
1 2
0 4
-1 1
Sample Output
4
2
0
Explanation
Case 1: There are four pairs of integers with absolute difference ${1}$ and product $2$, namely $(1,2)$, $(2,1)$, $(-1,-2)$, $(-2,-1)$.
Case 2: There are two pairs of integers with absolute difference ${0}$ and product ${4}$, namely $(2,2)$, $(-2,-2)$.
Case 3: There are no pairs of integers with absolute difference $-1$, because the absolute value is never negative.
|
{"inputs": ["3\n1 2\n0 4\n-1 1\n"], "outputs": ["4\n2\n0\n"]}
| 402
| 31
|
coding
|
Solve the programming task below in a Python markdown code block.
# Problem
In China,there is an ancient mathematical book, called "The Mathematical Classic of Sun Zi"(《孙子算经》). In the book, there is a classic math problem: “今有物不知其数,三三数之剩二,五五数之剩三,七七数之剩二,问物几何?”
Ahh, Sorry. I forgot that you don't know Chinese. Let's translate it to English:
There is a unkown positive integer `n`. We know:
`n % 3 = 2`, and `n % 5 = 3`, and `n % 7 = 2`.
What's the minimum possible positive integer `n`?
The correct answer is `23`.
# Task
You are given three non-negative integers `x,y,z`. They represent the remainders of the unknown positive integer `n` divided by 3,5,7.
That is: `n % 3 = x, n % 5 = y, n % 7 = z`
Your task is to find the minimum possible positive integer `n` and return it.
# Example
For `x = 2, y = 3, z = 2`, the output should be `23`
`23 % 3 = 2, 23 % 5 = 3, 23 % 7 = 2`
For `x = 1, y = 2, z = 3`, the output should be `52`
`52 % 3 = 1, 52 % 5 = 2, 52 % 7 = 3`
For `x = 1, y = 3, z = 5`, the output should be `103`
`103 % 3 = 1, 103 % 5 = 3, 103 % 7 = 5`
For `x = 0, y = 0, z = 0`, the output should be `105`
For `x = 1, y = 1, z = 1`, the output should be `1`
# Note
- `0 <= x < 3, 0 <= y < 5, 0 <= z < 7`
- Happy Coding `^_^`
Also feel free to reuse/extend the following starter code:
```python
def find_unknown_number(x,y,z):
```
|
{"functional": "_inputs = [[2, 3, 2], [1, 2, 3], [1, 3, 5], [0, 0, 0], [1, 1, 1]]\n_outputs = [[23], [52], [103], [105], [1]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(find_unknown_number(*i), o[0])"}
| 530
| 215
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
The median is the middle value in an ordered integer list. If the size of the list is even, there is no middle value. So the median is the mean of the two middle values.
For examples, if arr = [2,3,4], the median is 3.
For examples, if arr = [1,2,3,4], the median is (2 + 3) / 2 = 2.5.
You are given an integer array nums and an integer k. There is a sliding window of size k which is moving from the very left of the array to the very right. You can only see the k numbers in the window. Each time the sliding window moves right by one position.
Return the median array for each window in the original array. Answers within 10-5 of the actual value will be accepted.
Please complete the following python code precisely:
```python
class Solution:
def medianSlidingWindow(self, nums: List[int], k: int) -> List[float]:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1,3,-1,-3,5,3,6,7], k = 3) == [1.00000,-1.00000,-1.00000,3.00000,5.00000,6.00000]\n assert candidate(nums = [1,2,3,4,2,3,1,4,2], k = 3) == [2.00000,3.00000,3.00000,3.00000,2.00000,3.00000,2.00000]\n\n\ncheck(Solution().medianSlidingWindow)"}
| 230
| 187
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian as well.
Petr, Nikita G. and Nikita are the most influential music critics in Saint-Petersburg. They have recently downloaded their favorite band's new album and going to listen to it. Nikita claims that the songs of entire album should be listened strictly in the same order as they are given, because there is the secret message from the author in the songs' order. Petr, being chaotic, does not think so, hence he loves listening to songs in a random order. Petr is pretty good in convincing other people, so after a two-hours discussion Nikita accepted listening in random order(the discussion's duration was like three times longer thatn the album's one). In this context random order means following: There are N songs in the album. In the very beginning random song is chosen(here and further "random song" means that every song has equal probability to be chosen). After some song is over the next one is chosen randomly and independently of what have been played before.
Nikita G., being the only one who is not going to drop out from the university, wonders, what is the expected number of songs guys have to listen to until every song is played at least once.
------ Input ------
The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows.
The first and only line of each test case contains a single integer N denoting the number of songs in the album.
------ Output ------
For each test case, output a single line containing the expected number of songs the guys will listen to. Your answer will be considered as correct if it has an absolute or relative error less than 10^{−1}. More formally if the expected output is A and your output is B, your output will be considered as correct if and only if
|A − B| ≤ 10^{−1} * max{|A|, |B|, 1}.
------ Constraints ------
1 ≤ T ≤ 100
1 ≤ N ≤ 3000
----- Sample Input 1 ------
3
1
2
3
----- Sample Output 1 ------
1.0
3.0
5.5
------ Explanation 0 ------
Example case 2 After playing the first song there is 1/2 chance to finish the album each time new song is played. So the expected number of songs is 2/2 + 3/4 + 4/8... = 3
|
{"inputs": ["3\n1\n2\n3", "3\n1\n2\n2", "3\n1\n2\n6", "3\n2\n2\n2", "3\n1\n3\n2", "3\n1\n3\n6", "3\n1\n1\n2", "3\n1\n1\n6"], "outputs": ["1.0\n3.0\n5.5", "1.0\n3.0\n3.0\n", "1.0\n3.0\n14.7\n", "3.0\n3.0\n3.0\n", "1.0\n5.5\n3.0\n", "1.0\n5.5\n14.7\n", "1.0\n1.0\n3.0\n", "1.0\n1.0\n14.7\n"]}
| 543
| 192
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n projects numbered from 0 to n - 1. You are given an integer array milestones where each milestones[i] denotes the number of milestones the ith project has.
You can work on the projects following these two rules:
Every week, you will finish exactly one milestone of one project. You must work every week.
You cannot work on two milestones from the same project for two consecutive weeks.
Once all the milestones of all the projects are finished, or if the only milestones that you can work on will cause you to violate the above rules, you will stop working. Note that you may not be able to finish every project's milestones due to these constraints.
Return the maximum number of weeks you would be able to work on the projects without violating the rules mentioned above.
Please complete the following python code precisely:
```python
class Solution:
def numberOfWeeks(self, milestones: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(milestones = [1,2,3]) == 6\n assert candidate(milestones = [5,2,1]) == 7\n\n\ncheck(Solution().numberOfWeeks)"}
| 207
| 56
|
coding
|
Solve the programming task below in a Python markdown code block.
The goal is to write a pair of functions the first of which will take a string of binary along with a specification of bits, which will return a numeric, signed complement in two's complement format. The second will do the reverse. It will take in an integer along with a number of bits, and return a binary string.
https://en.wikipedia.org/wiki/Two's_complement
Thus, to_twos_complement should take the parameters binary = "0000 0001", bits = 8 should return 1. And, binary = "11111111", bits = 8 should return -1 . While, from_twos_complement should return "00000000" from the parameters n = 0, bits = 8 . And, "11111111" from n = -1, bits = 8.
You should account for some edge cases.
Also feel free to reuse/extend the following starter code:
```python
def to_twos_complement(binary, bits):
```
|
{"functional": "_inputs = [['00000001', 8], ['00000010', 8], ['01111110', 8], ['01111111', 8], ['11111111', 8], ['11111110', 8], ['10000010', 8], ['1000 0000', 8], ['1010 1010 0010 0010 1110 1010 0010 1110', 32], ['1000 0000 1110 1111 0011 0100 1100 1010', 32], ['10110001000100000101100011111000', 32]]\n_outputs = [[1], [2], [126], [127], [-1], [-2], [-126], [-128], [-1440552402], [-2131807030], [-1324328712]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(to_twos_complement(*i), o[0])"}
| 238
| 452
|
coding
|
Solve the programming task below in a Python markdown code block.
Polycarp analyzes the prices of the new berPhone. At his disposal are the prices for $n$ last days: $a_1, a_2, \dots, a_n$, where $a_i$ is the price of berPhone on the day $i$.
Polycarp considers the price on the day $i$ to be bad if later (that is, a day with a greater number) berPhone was sold at a lower price. For example, if $n=6$ and $a=[3, 9, 4, 6, 7, 5]$, then the number of days with a bad price is $3$ — these are days $2$ ($a_2=9$), $4$ ($a_4=6$) and $5$ ($a_5=7$).
Print the number of days with a bad price.
You have to answer $t$ independent data sets.
-----Input-----
The first line contains an integer $t$ ($1 \le t \le 10000$) — the number of sets of input data in the test. Input data sets must be processed independently, one after another.
Each input data set consists of two lines. The first line contains an integer $n$ ($1 \le n \le 150000$) — the number of days. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^6$), where $a_i$ is the price on the $i$-th day.
It is guaranteed that the sum of $n$ over all data sets in the test does not exceed $150000$.
-----Output-----
Print $t$ integers, the $j$-th of which should be equal to the number of days with a bad price in the $j$-th input data set.
-----Example-----
Input
5
6
3 9 4 6 7 5
1
1000000
2
2 1
10
31 41 59 26 53 58 97 93 23 84
7
3 2 1 2 3 4 5
Output
3
0
1
8
2
|
{"inputs": ["5\n6\n3 9 2 6 7 5\n1\n1000000\n2\n2 1\n10\n31 5 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "5\n6\n3 5 4 6 7 4\n1\n1000000\n2\n2 0\n10\n2 41 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "5\n6\n3 9 2 6 7 5\n1\n1000000\n2\n2 1\n10\n31 5 59 26 53 58 97 93 23 84\n7\n3 2 1 2 4 4 5\n", "5\n6\n3 9 4 6 7 5\n1\n1000000\n2\n2 1\n10\n31 41 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "5\n6\n3 9 4 6 7 5\n1\n1000000\n2\n2 0\n10\n31 41 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "5\n6\n3 9 2 6 7 5\n1\n1000000\n2\n2 1\n10\n31 41 59 26 53 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "5\n6\n3 5 4 6 7 5\n1\n1000000\n2\n2 0\n10\n31 41 59 26 15 58 97 93 23 84\n7\n3 2 1 2 3 4 5\n", "5\n6\n3 5 4 7 7 5\n1\n1000000\n2\n2 0\n10\n31 41 59 26 53 58 97 93 23 84\n7\n1 2 1 2 3 4 5\n"], "outputs": ["4\n0\n1\n7\n2\n", "3\n0\n1\n7\n2\n", "4\n0\n1\n7\n2\n", "3\n0\n1\n8\n2\n", "3\n0\n1\n8\n2\n", "4\n0\n1\n8\n2\n", "3\n0\n1\n7\n2\n", "3\n0\n1\n8\n1\n"]}
| 523
| 763
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a 0-indexed array of strings words and a 2D array of integers queries.
Each query queries[i] = [li, ri] asks us to find the number of strings present in the range li to ri (both inclusive) of words that start and end with a vowel.
Return an array ans of size queries.length, where ans[i] is the answer to the ith query.
Note that the vowel letters are 'a', 'e', 'i', 'o', and 'u'.
Please complete the following python code precisely:
```python
class Solution:
def vowelStrings(self, words: List[str], queries: List[List[int]]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(words = [\"aba\",\"bcb\",\"ece\",\"aa\",\"e\"], queries = [[0,2],[1,4],[1,1]]) == [2,3,0]\n assert candidate(words = [\"a\",\"e\",\"i\"], queries = [[0,2],[0,1],[2,2]]) == [3,2,1]\n\n\ncheck(Solution().vowelStrings)"}
| 160
| 101
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are n dominoes in a line, and we place each domino vertically upright. In the beginning, we simultaneously push some of the dominoes either to the left or to the right.
After each second, each domino that is falling to the left pushes the adjacent domino on the left. Similarly, the dominoes falling to the right push their adjacent dominoes standing on the right.
When a vertical domino has dominoes falling on it from both sides, it stays still due to the balance of the forces.
For the purposes of this question, we will consider that a falling domino expends no additional force to a falling or already fallen domino.
You are given a string dominoes representing the initial state where:
dominoes[i] = 'L', if the ith domino has been pushed to the left,
dominoes[i] = 'R', if the ith domino has been pushed to the right, and
dominoes[i] = '.', if the ith domino has not been pushed.
Return a string representing the final state.
Please complete the following python code precisely:
```python
class Solution:
def pushDominoes(self, dominoes: str) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(dominoes = \"RR.L\") == \"RR.L\"\n assert candidate(dominoes = \".L.R...LR..L..\") == \"LL.RR.LLRRLL..\"\n\n\ncheck(Solution().pushDominoes)"}
| 274
| 67
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the root of a complete binary tree, return the number of the nodes in the tree.
According to Wikipedia, every level, except possibly the last, is completely filled in a complete binary tree, and all nodes in the last level are as far left as possible. It can have between 1 and 2h nodes inclusive at the last level h.
Design an algorithm that runs in less than O(n) time complexity.
Please complete the following python code precisely:
```python
# Definition for a binary tree node.
# class TreeNode:
# def __init__(self, val=0, left=None, right=None):
# self.val = val
# self.left = left
# self.right = right
class Solution:
def countNodes(self, root: Optional[TreeNode]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(root = tree_node([1,2,3,4,5,6])) == 6\n assert candidate(root = tree_node([])) == 0\n assert candidate(root = tree_node([1])) == 1\n\n\ncheck(Solution().countNodes)"}
| 188
| 70
|
coding
|
Solve the programming task below in a Python markdown code block.
Given an integer `n`, find two integers `a` and `b` such that:
```Pearl
A) a >= 0 and b >= 0
B) a + b = n
C) DigitSum(a) + Digitsum(b) is maximum of all possibilities.
```
You will return the digitSum(a) + digitsum(b).
```
For example:
solve(29) = 11. If we take 15 + 14 = 29 and digitSum = 1 + 5 + 1 + 4 = 11. There is no larger outcome.
```
`n` will not exceed `10e10`.
More examples in test cases.
Good luck!
Also feel free to reuse/extend the following starter code:
```python
def solve(n):
```
|
{"functional": "_inputs = [[18], [29], [45], [1140], [7019], [50000000], [15569047737], [2452148459], [1], [0]]\n_outputs = [[18], [11], [18], [33], [35], [68], [144], [116], [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, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(solve(*i), o[0])"}
| 191
| 253
|
coding
|
Solve the programming task below in a Python markdown code block.
It is September 9 in Japan now.
You are given a two-digit integer N. Answer the question: Is 9 contained in the decimal notation of N?
-----Constraints-----
- 10≤N≤99
-----Input-----
Input is given from Standard Input in the following format:
N
-----Output-----
If 9 is contained in the decimal notation of N, print Yes; if not, print No.
-----Sample Input-----
29
-----Sample Output-----
Yes
The one's digit of 29 is 9.
|
{"inputs": ["1", "0", "8", "3", "2", "4", "7", "6"], "outputs": ["No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n", "No\n"]}
| 124
| 62
|
coding
|
Solve the programming task below in a Python markdown code block.
In this Kata, you will be given a multi-dimensional array containing `2 or more` sub-arrays of integers. Your task is to find the maximum product that can be formed by taking any one element from each sub-array.
```
Examples:
solve( [[1, 2],[3, 4]] ) = 8. The max product is given by 2 * 4
solve( [[10,-15],[-1,-3]] ) = 45, given by (-15) * (-3)
solve( [[1,-1],[2,3],[10,-100]] ) = 300, given by (-1) * 3 * (-100)
```
More examples in test cases. Good luck!
Also feel free to reuse/extend the following starter code:
```python
def solve(arr):
```
|
{"functional": "_inputs = [[[[1, 2], [3, 4]]], [[[10, -15], [-1, -3]]], [[[-1, 2, -3, 4], [1, -2, 3, -4]]], [[[-11, -6], [-20, -20], [18, -4], [-20, 1]]], [[[14, 2], [0, -16], [-12, -16]]], [[[-3, -4], [1, 2, -3]]], [[[-2, -15, -12, -8, -16], [-4, -15, -7], [-10, -5]]]]\n_outputs = [[8], [45], [12], [17600], [3584], [12], [-40]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(solve(*i), o[0])"}
| 192
| 343
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, remove duplicate letters so that every letter appears once and only once. You must make sure your result is the smallest in lexicographical order among all possible results.
Please complete the following python code precisely:
```python
class Solution:
def removeDuplicateLetters(self, s: str) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"bcabc\") == \"abc\"\n assert candidate(s = \"cbacdcbc\") == \"acdb\"\n\n\ncheck(Solution().removeDuplicateLetters)"}
| 85
| 50
|
coding
|
Solve the programming task below in a Python markdown code block.
Modern text editors usually show some information regarding the document being edited. For example, the number of words, the number of pages, or the number of characters.
In this problem you should implement the similar functionality.
You are given a string which only consists of: uppercase and lowercase English letters, underscore symbols (they are used as separators), parentheses (both opening and closing).
It is guaranteed that each opening parenthesis has a succeeding closing parenthesis. Similarly, each closing parentheses has a preceding opening parentheses matching it. For each pair of matching parentheses there are no other parenthesis between them. In other words, each parenthesis in the string belongs to a matching "opening-closing" pair, and such pairs can't be nested.
For example, the following string is valid: "_Hello_Vasya(and_Petya)__bye_(and_OK)".
Word is a maximal sequence of consecutive letters, i.e. such sequence that the first character to the left and the first character to the right of it is an underscore, a parenthesis, or it just does not exist. For example, the string above consists of seven words: "Hello", "Vasya", "and", "Petya", "bye", "and" and "OK". Write a program that finds: the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), the number of words inside the parentheses (print 0, if there is no word inside the parentheses).
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 255) — the length of the given string. The second line contains the string consisting of only lowercase and uppercase English letters, parentheses and underscore symbols.
-----Output-----
Print two space-separated integers: the length of the longest word outside the parentheses (print 0, if there is no word outside the parentheses), the number of words inside the parentheses (print 0, if there is no word inside the parentheses).
-----Examples-----
Input
37
_Hello_Vasya(and_Petya)__bye_(and_OK)
Output
5 4
Input
37
_a_(_b___c)__de_f(g_)__h__i(j_k_l)m__
Output
2 6
Input
27
(LoooonG)__shOrt__(LoooonG)
Output
5 2
Input
5
(___)
Output
0 0
-----Note-----
In the first sample, the words "Hello", "Vasya" and "bye" are outside any of the parentheses, and the words "and", "Petya", "and" and "OK" are inside. Note, that the word "and" is given twice and you should count it twice in the answer.
|
{"inputs": ["1\n_\n", "1\na\n", "1\n_\n", "1\na\n", "1\nb\n", "1\nc\n", "1\nd\n", "1\ne\n"], "outputs": ["0 0\n", "1 0\n", "0 0\n", "1 0\n", "1 0\n", "1 0\n", "1 0\n", "1 0\n"]}
| 596
| 102
|
coding
|
Solve the programming task below in a Python markdown code block.
Given two strings, $a$ and $\boldsymbol{b}$, find and print the total number of ways to insert a character at any position in string $\class{ML__boldsymbol}{\boldsymbol{a}}$ such that the length of the Longest Common Subsequence of characters in the two strings increases by one.
Input Format
The first line contains a single string denoting $\class{ML__boldsymbol}{\boldsymbol{a}}$.
The second line contains a single string denoting $\boldsymbol{b}$.
Constraints
Scoring
$1\leq|a|,|b|\leq5000$
Strings $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{b}$ are alphanumeric (i.e., consisting of arabic digits and/or upper and lower case English letters).
The new character being inserted must also be alphanumeric (i.e., a digit or upper/lower case English letter).
Subtask
$1\le|a|,|b|\le1000$ for $\boldsymbol{66.67\%}$ of the maximum score.
Output Format
Print a single integer denoting the total number of ways to insert a character into string $\class{ML__boldsymbol}{\boldsymbol{a}}$ in such a way that the length of the longest common subsequence of $\class{ML__boldsymbol}{\boldsymbol{a}}$ and $\boldsymbol{b}$ increases by one.
Sample Input
aa
baaa
Sample Output
4
Explanation
The longest common subsequence shared by $a=\text{"a}\textbf{a}$ and $b=\text{"baaa''}$ is aa, which has a length of $2$. There are two ways that the length of the longest common subsequence can be increased to $3$ by adding a single character to $\class{ML__boldsymbol}{\boldsymbol{a}}$:
There are $3$ different positions in string $\class{ML__boldsymbol}{\boldsymbol{a}}$ where we could insert an additional a to create longest common subsequence aaa (i.e., at the beginning, middle, and end of the string).
We can insert a b at the beginning of the string for a new longest common subsequence of baa.
As we have $3+1=4$ ways to insert an alphanumeric character into $\class{ML__boldsymbol}{\boldsymbol{a}}$ and increase the length of the longest common subsequence by one, we print $\begin{array}{c}4\end{array}$ on a new line.
|
{"inputs": ["aa\nbaaa\n"], "outputs": ["4\n"]}
| 568
| 17
|
coding
|
Solve the programming task below in a Python markdown code block.
Write a program which reads $n$ items and sorts them. Each item has attributes $\\{value, weight, type, date, name\\}$ and they are represented by $\\{$ integer, integer, upper-case letter, integer, string $\\}$ respectively. Sort the items based on the following priorities.
1. first by value (ascending)
2. in case of a tie, by weight (ascending)
3. in case of a tie, by type (ascending in lexicographic order)
4. in case of a tie, by date (ascending)
5. in case of a tie, by name (ascending in lexicographic order)
Constraints
* $1 \leq n \leq 100,000$
* $0 \leq v_i \leq 1,000,000,000$
* $0 \leq w_i \leq 1,000,000,000$
* $t_i$ is a upper-case letter
* $0 \leq d_i \leq 2,000,000,000,000$
* $1 \leq $ size of $s_i \leq 20$
* $s_i \ne s_j$ if $(i \ne j)$
Input
The input is given in the following format.
$n$
$v_0 \; w_0 \; t_0 \; d_0 \; s_0$
$v_1 \; w_1 \; t_1 \; d_1 \; s_1$
:
$v_{n-1} \; w_{n-1} \; t_{n-1} \; d_{n-1} \; s_{n-1}$
In the first line, the number of items $n$. In the following $n$ lines, attributes of each item are given. $v_i \; w_i \; t_i \; d_i \; s_i$ represent value, weight, type, date and name of the $i$-th item respectively.
Output
Print attributes of each item in order. Print an item in a line and adjacency attributes should be separated by a single space.
Example
Input
5
105 24 C 1500000000000 white
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
110 25 B 1500000000000 black
110 20 A 1300000000000 gree
Output
100 23 C 1500000000000 blue
105 23 A 1480000000000 pink
105 24 C 1500000000000 white
110 20 A 1300000000000 gree
110 25 B 1500000000000 black
|
{"inputs": ["5\n27 21 D 745654582374 hwftj\n000 15 C 393121129811 clue\n51 133 A 44541605340 nijo\n101 11 A 63613510230 lcalb\n111 1 C 3157365261 eerg", "5\n26 21 D 745654582374 hwftj\n000 15 C 393121129811 clue\n51 133 A 44541605340 nijo\n101 11 A 63613510230 lcalb\n111 1 C 3157365261 eerg", "5\n26 21 D 745654582374 hwgtj\n000 15 C 393121129811 clue\n51 133 A 44541605340 nijo\n101 11 A 63613510230 lcalb\n111 1 C 3157365261 eerg", "5\n26 21 D 745654582374 hwgtj\n000 15 C 393121129811 clue\n51 133 A 44541605340 nijo\n101 17 A 63613510230 lcalb\n111 1 C 3157365261 eerg", "5\n26 21 D 745654582374 hwgtj\n000 15 C 393121129811 clue\n51 133 A 44541605340 nijo\n101 17 A 63613510230 lcalb\n111 1 C 3157365261 gree", "5\n26 21 D 745654582374 hwgtj\n000 15 C 393121129811 clue\n51 133 A 44541605340 nijo\n101 17 A 63613510230 lcalb\n101 1 C 3157365261 gree", "5\n26 21 D 745654582374 hwgtj\n000 15 C 393121129811 clue\n51 133 A 74744010652 nijo\n101 17 A 63613510230 lcalb\n101 1 C 3157365261 gree", "5\n26 21 D 745654582374 hwgtj\n000 15 C 393121129811 clue\n51 133 A 74744010652 nijo\n101 17 A 63613510230 lcalb\n101 1 D 3157365261 gree"], "outputs": ["0 15 C 393121129811 clue\n27 21 D 745654582374 hwftj\n51 133 A 44541605340 nijo\n101 11 A 63613510230 lcalb\n111 1 C 3157365261 eerg\n", "0 15 C 393121129811 clue\n26 21 D 745654582374 hwftj\n51 133 A 44541605340 nijo\n101 11 A 63613510230 lcalb\n111 1 C 3157365261 eerg\n", "0 15 C 393121129811 clue\n26 21 D 745654582374 hwgtj\n51 133 A 44541605340 nijo\n101 11 A 63613510230 lcalb\n111 1 C 3157365261 eerg\n", "0 15 C 393121129811 clue\n26 21 D 745654582374 hwgtj\n51 133 A 44541605340 nijo\n101 17 A 63613510230 lcalb\n111 1 C 3157365261 eerg\n", "0 15 C 393121129811 clue\n26 21 D 745654582374 hwgtj\n51 133 A 44541605340 nijo\n101 17 A 63613510230 lcalb\n111 1 C 3157365261 gree\n", "0 15 C 393121129811 clue\n26 21 D 745654582374 hwgtj\n51 133 A 44541605340 nijo\n101 1 C 3157365261 gree\n101 17 A 63613510230 lcalb\n", "0 15 C 393121129811 clue\n26 21 D 745654582374 hwgtj\n51 133 A 74744010652 nijo\n101 1 C 3157365261 gree\n101 17 A 63613510230 lcalb\n", "0 15 C 393121129811 clue\n26 21 D 745654582374 hwgtj\n51 133 A 74744010652 nijo\n101 1 D 3157365261 gree\n101 17 A 63613510230 lcalb\n"]}
| 731
| 1,790
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of strings words and a string chars.
A string is good if it can be formed by characters from chars (each character can only be used once).
Return the sum of lengths of all good strings in words.
Please complete the following python code precisely:
```python
class Solution:
def countCharacters(self, words: List[str], chars: str) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(words = [\"cat\",\"bt\",\"hat\",\"tree\"], chars = \"atach\") == 6\n assert candidate(words = [\"hello\",\"world\",\"leetcode\"], chars = \"welldonehoneyr\") == 10\n\n\ncheck(Solution().countCharacters)"}
| 99
| 74
|
coding
|
Solve the programming task below in a Python markdown code block.
# Valid HK Phone Number
## Overview
In Hong Kong, a valid phone number has the format ```xxxx xxxx``` where ```x``` is a decimal digit (0-9). For example:
## Task
Define two functions, ```isValidHKPhoneNumber``` and ```hasValidHKPhoneNumber```, that ```return```s whether a given string is a valid HK phone number and contains a valid HK phone number respectively (i.e. ```true/false``` values).
If in doubt please refer to the example tests.
Also feel free to reuse/extend the following starter code:
```python
def is_valid_HK_phone_number(number):
```
|
{"functional": "_inputs = [['1234 5678'], ['2359 1478'], ['85748475'], ['3857 4756'], ['sklfjsdklfjsf'], [' 1234 5678 '], ['abcd efgh'], ['9684 2396'], ['836g 2986'], ['0000 0000'], ['123456789'], [' 987 634 '], [' 6 '], ['8A65 2986'], ['8368 2aE6'], ['8c65 2i86']]\n_outputs = [[True], [True], [False], [False], [False], [False], [False], [True], [False], [True], [False], [False], [False], [False], [False], [False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(is_valid_HK_phone_number(*i), o[0])"}
| 142
| 368
|
coding
|
Solve the programming task below in a Python markdown code block.
Three candidates take part in a TV show.
In order to decide who will take part in the final game and probably become rich, they have to roll the Wheel of Fortune!
The Wheel of Fortune is divided into 20 sections, each with a number from 5 to 100 (only mulitples of 5).
Each candidate can roll the wheel once or twice and sum up the score of each roll.
The winner one that is closest to 100 (while still being lower or equal to 100).
In case of a tie, the candidate that rolled the wheel first wins.
You receive the information about each candidate as an array of objects: each object should have a `name` and a `scores` array with the candidate roll values.
Your solution should return the name of the winner or `false` if there is no winner (all scored more than 100).
__Example:__
```python
c1 = {"name": "Bob", "scores": [10, 65]}
c2 = {"name": "Bill", "scores": [90, 5]}
c3 = {"name": "Charlie", "scores": [40, 55]}
winner([c1, c2, c3]) #Returns "Bill"
```
Please note that inputs may be invalid: in this case, the function should return false.
Potential errors derived from the specifications are:
- More or less than three candidates take part in the game.
- A candidate did not roll the wheel or rolled it more than twice.
- Scores are not valid.
- Invalid user entry (no name or no score).
Also feel free to reuse/extend the following starter code:
```python
def winner(candidates):
```
|
{"functional": "_inputs = [[[]]]\n_outputs = [[False]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(winner(*i), o[0])"}
| 377
| 154
|
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. The adjacent integers in nums will perform the float division.
For example, for nums = [2,3,4], we will evaluate the expression "2/3/4".
However, you can add any number of parenthesis at any position to change the priority of operations. You want to add these parentheses such the value of the expression after the evaluation is maximum.
Return the corresponding expression that has the maximum value in string format.
Note: your expression should not contain redundant parenthesis.
Please complete the following python code precisely:
```python
class Solution:
def optimalDivision(self, nums: List[int]) -> str:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1000,100,10,2]) == \"1000/(100/10/2)\"\n assert candidate(nums = [2,3,4]) == \"2/(3/4)\"\n\n\ncheck(Solution().optimalDivision)"}
| 152
| 80
|
coding
|
Solve the programming task below in a Python markdown code block.
Given an integer x, find 2 integers a and b such that:
* 1 ≤ a,b ≤ x
* b divides a (a is divisible by b).
* a ⋅ b>x.
* a/b<x.
Input
The only line contains the integer x (1 ≤ x ≤ 100).
Output
You should output two integers a and b, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes).
Examples
Input
10
Output
6 3
Input
1
Output
-1
|
{"inputs": ["8\n", "7\n", "9\n", "4\n", "2\n", "5\n", "6\n", "3\n"], "outputs": ["3 3\n", "3 3\n", "4 4\n", "4 2\n", "2 2\n", "3 3\n", "3 3\n", "2 2\n"]}
| 148
| 86
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a string $s$, consisting of $n$ letters, each letter is either 'a' or 'b'. The letters in the string are numbered from $1$ to $n$.
$s[l; r]$ is a continuous substring of letters from index $l$ to $r$ of the string inclusive.
A string is called balanced if the number of letters 'a' in it is equal to the number of letters 'b'. For example, strings "baba" and "aabbab" are balanced and strings "aaab" and "b" are not.
Find any non-empty balanced substring $s[l; r]$ of string $s$. Print its $l$ and $r$ ($1 \le l \le r \le n$). If there is no such substring, then print $-1$ $-1$.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of testcases.
Then the descriptions of $t$ testcases follow.
The first line of the testcase contains a single integer $n$ ($1 \le n \le 50$) — the length of the string.
The second line of the testcase contains a string $s$, consisting of $n$ letters, each letter is either 'a' or 'b'.
-----Output-----
For each testcase print two integers. If there exists a non-empty balanced substring $s[l; r]$, then print $l$ $r$ ($1 \le l \le r \le n$). Otherwise, print $-1$ $-1$.
-----Examples-----
Input
4
1
a
6
abbaba
6
abbaba
9
babbabbaa
Output
-1 -1
1 6
3 6
2 5
-----Note-----
In the first testcase there are no non-empty balanced subtrings.
In the second and third testcases there are multiple balanced substrings, including the entire string "abbaba" and substring "baba".
|
{"inputs": ["1\n6\nbaaaaaaaaabaaaa`aaaaababaabaa\n", "1\n8\naaaaaabaaaab`aaaaa`aaabaaaaaa\n", "1\n3\naabaababaaaaaaaaaabaaaaaaaaab\n", "1\n8\naabaaaaaaaaaaaaaaaaaaaaaaaaaa\n", "1\n5\naabaababaaaaaaaaaabaaaaaaaaaa\n", "1\n3\naabaababaaaaa`aaaabaaaaaaaaab\n", "1\n8\naabaaaaaaaaaaaaaaa`aaaaaaaaaa\n", "1\n6\naabaababaaaaa`aaaabaaaaaaaaab\n"], "outputs": ["1 2\n", "6 7\n", "2 3\n", "2 3\n", "2 3\n", "2 3\n", "2 3\n", "2 3\n"]}
| 450
| 183
|
coding
|
Solve the programming task below in a Python markdown code block.
Pasha loves his phone and also putting his hair up... But the hair is now irrelevant.
Pasha has installed a new game to his phone. The goal of the game is following. There is a rectangular field consisting of n row with m pixels in each row. Initially, all the pixels are colored white. In one move, Pasha can choose any pixel and color it black. In particular, he can choose the pixel that is already black, then after the boy's move the pixel does not change, that is, it remains black. Pasha loses the game when a 2 × 2 square consisting of black pixels is formed.
Pasha has made a plan of k moves, according to which he will paint pixels. Each turn in his plan is represented as a pair of numbers i and j, denoting respectively the row and the column of the pixel to be colored on the current move.
Determine whether Pasha loses if he acts in accordance with his plan, and if he does, on what move the 2 × 2 square consisting of black pixels is formed.
-----Input-----
The first line of the input contains three integers n, m, k (1 ≤ n, m ≤ 1000, 1 ≤ k ≤ 10^5) — the number of rows, the number of columns and the number of moves that Pasha is going to perform.
The next k lines contain Pasha's moves in the order he makes them. Each line contains two integers i and j (1 ≤ i ≤ n, 1 ≤ j ≤ m), representing the row number and column number of the pixel that was painted during a move.
-----Output-----
If Pasha loses, print the number of the move when the 2 × 2 square consisting of black pixels is formed.
If Pasha doesn't lose, that is, no 2 × 2 square consisting of black pixels is formed during the given k moves, print 0.
-----Examples-----
Input
2 2 4
1 1
1 2
2 1
2 2
Output
4
Input
2 3 6
2 3
2 2
1 3
2 2
1 2
1 1
Output
5
Input
5 3 7
2 3
1 2
1 1
4 1
3 1
5 3
3 2
Output
0
|
{"inputs": ["1 1 1\n1 1\n", "1 1 1\n1 1\n", "1 2 1\n1 1\n", "2 2 4\n1 1\n1 2\n2 1\n2 2\n", "2 2 4\n1 1\n1 2\n2 1\n2 2\n", "2 2 5\n1 1\n2 1\n2 1\n1 2\n2 2\n", "1 1 5\n1 1\n1 1\n1 1\n1 1\n1 1\n", "1 5 5\n1 1\n1 2\n1 3\n1 4\n1 5\n"], "outputs": ["0\n", "0", "0\n", "4\n", "4", "5\n", "0\n", "0\n"]}
| 523
| 204
|
coding
|
Solve the programming task below in a Python markdown code block.
At the annual family gathering, the family likes to find the oldest living family member’s age and the youngest family member’s age and calculate the difference between them.
You will be given an array of all the family members' ages, in any order. The ages will be given in whole numbers, so a baby of 5 months, will have an ascribed ‘age’ of 0. Return a new array (a tuple in Python) with [youngest age, oldest age, difference between the youngest and oldest age].
Also feel free to reuse/extend the following starter code:
```python
def difference_in_ages(ages):
```
|
{"functional": "_inputs = [[[16, 22, 31, 44, 3, 38, 27, 41, 88]], [[5, 8, 72, 98, 41, 16, 55]], [[57, 99, 14, 32]], [[62, 0, 3, 77, 88, 102, 26, 44, 55]], [[2, 44, 34, 67, 88, 76, 31, 67]], [[46, 86, 33, 29, 87, 47, 28, 12, 1, 4, 78, 92]], [[66, 73, 88, 24, 36, 65, 5]], [[12, 76, 49, 37, 29, 17, 3, 65, 84, 38]], [[0, 110]], [[33, 33, 33]]]\n_outputs = [[[3, 88, 85]], [[5, 98, 93]], [[14, 99, 85]], [[0, 102, 102]], [[2, 88, 86]], [[1, 92, 91]], [[5, 88, 83]], [[3, 84, 81]], [[0, 110, 110]], [[33, 33, 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 return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(difference_in_ages(*i), o[0])"}
| 145
| 541
|
coding
|
Solve the programming task below in a Python markdown code block.
```if-not:racket
Write a function called `repeat_str` which repeats the given string `src` exactly `count` times.
```
```if:racket
Write a function called `repeat-string` which repeats the given string `str` exactly `count` times.
```
Also feel free to reuse/extend the following starter code:
```python
def repeat_str(repeat, string):
```
|
{"functional": "_inputs = [[4, 'a'], [3, 'hello '], [2, 'abc']]\n_outputs = [['aaaa'], ['hello hello hello '], ['abcabc']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(repeat_str(*i), o[0])"}
| 96
| 181
|
coding
|
Solve the programming task below in a Python markdown code block.
The "BerCorp" company has got n employees. These employees can use m approved official languages for the formal correspondence. The languages are numbered with integers from 1 to m. For each employee we have the list of languages, which he knows. This list could be empty, i. e. an employee may know no official languages. But the employees are willing to learn any number of official languages, as long as the company pays their lessons. A study course in one language for one employee costs 1 berdollar.
Find the minimum sum of money the company needs to spend so as any employee could correspond to any other one (their correspondence can be indirect, i. e. other employees can help out translating).
-----Input-----
The first line contains two integers n and m (2 ≤ n, m ≤ 100) — the number of employees and the number of languages.
Then n lines follow — each employee's language list. At the beginning of the i-th line is integer k_{i} (0 ≤ k_{i} ≤ m) — the number of languages the i-th employee knows. Next, the i-th line contains k_{i} integers — a_{ij} (1 ≤ a_{ij} ≤ m) — the identifiers of languages the i-th employee knows. It is guaranteed that all the identifiers in one list are distinct. Note that an employee may know zero languages.
The numbers in the lines are separated by single spaces.
-----Output-----
Print a single integer — the minimum amount of money to pay so that in the end every employee could write a letter to every other one (other employees can help out translating).
-----Examples-----
Input
5 5
1 2
2 2 3
2 3 4
2 4 5
1 5
Output
0
Input
8 7
0
3 1 2 3
1 1
2 5 4
2 6 7
1 3
2 7 4
1 1
Output
2
Input
2 2
1 2
0
Output
1
-----Note-----
In the second sample the employee 1 can learn language 2, and employee 8 can learn language 4.
In the third sample employee 2 must learn language 2.
|
{"inputs": ["2 2\n0\n0\n", "2 2\n0\n0\n", "2 2\n1 2\n0\n", "3 3\n0\n0\n0\n", "3 3\n0\n0\n0\n", "3 2\n0\n0\n0\n", "3 4\n0\n0\n0\n", "2 2\n1 2\n0\n"], "outputs": ["2\n", "2", "1\n", "3\n", "3", "3\n", "3\n", "1"]}
| 493
| 127
|
coding
|
Solve the programming task below in a Python markdown code block.
Divya's watch of worth Rs10 cr is abducted by N thieves(1,2....i...N). The fight over the watch leads to a final decision that it should belong to the thief who wins a simple game. The rules of the game state that every thief registers a time in the format HH:MM:SS . Accordingly the average A of three clockwise angles between the hours , minutes and seconds hands is calculated . Thus the ith thief with the maximum A wins the game and gets to keep the watch.
The thieves are poor in mathematics and will need your help . Given the number of thieves and their registered time resolves the conflict and help them in choosing the winner
-----Input-----
First line of input contains T which denotes the number of test cases.
The first line of each test case consists of an integer which denotes the number of thieves thereby N line follow which give the time choosen by each thieve in the format HH:MM:SS.
-----Output:-----
Output single integer i which denotes the ith thief.
-----Constraints:-----
1<=T<=100
1<=N<=50
01<=HH<=12
00<=MM<=60
00<=SS<=60
-----Example:-----
Input:
2
3
12:28:26
07:26:04
11:23:17
2
07:43:25
06:23:34
Output:
3
1
|
{"inputs": ["2\n3\n12:28:26\n07:26:04\n11:23:17\n2\n07:43:25\n06:23:34"], "outputs": ["3\n1"]}
| 329
| 63
|
coding
|
Solve the programming task below in a Python markdown code block.
This function takes two numbers as parameters, the first number being the coefficient, and the second number being the exponent.
Your function should multiply the two numbers, and then subtract 1 from the exponent. Then, it has to print out an expression (like 28x^7). `"^1"` should not be truncated when exponent = 2.
For example:
```
derive(7, 8)
```
In this case, the function should multiply 7 and 8, and then subtract 1 from 8. It should output `"56x^7"`, the first number 56 being the product of the two numbers, and the second number being the exponent minus 1.
```
derive(7, 8) --> this should output "56x^7"
derive(5, 9) --> this should output "45x^8"
```
**Notes:**
* The output of this function should be a string
* The exponent will never be 1, and neither number will ever be 0
Also feel free to reuse/extend the following starter code:
```python
def derive(coefficient, exponent):
```
|
{"functional": "_inputs = [[7, 8], [5, 9]]\n_outputs = [['56x^7'], ['45x^8']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(derive(*i), o[0])"}
| 256
| 174
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef has a square-shaped chart paper with the side length equal to N. He wants to cut out K \times K squares from this chart paper.
Find the maximum number of K \times K squares he can cut from the entire chart paper.
Note that, some part of the chart paper might not be a included in any K \times K cutout square.
------ Input Format ------
- The first line contains a single integer T — the number of test cases. Then the test cases follow.
- The first and only line of each test case contains two space-separated integers N and K — the side length of the entire chart paper and the side length of the cutout squares.
------ Output Format ------
For each test case, output on a new line the maximum number of K \times K squares Chef can cut from the entire chart paper.
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ K ≤N ≤ 1000$
----- Sample Input 1 ------
3
5 1
2 2
5 2
----- Sample Output 1 ------
25
1
4
----- explanation 1 ------
Test case 1: Chef can cut out $25$ squares of size $1 \times 1$ from the entire $5 \times 5$ chart paper.
Test case 2: Chef can cut out $1$ square of size $2 \times 2$ from the entire $2 \times 2$ chart paper.
Test case 3: Chef can cut out $4$ squares of size $2 \times 2$ from the entire $5 \times 5$ chart paper.
|
{"inputs": ["3\n5 1\n2 2\n5 2\n"], "outputs": ["25\n1\n4\n"]}
| 359
| 31
|
coding
|
Solve the programming task below in a Python markdown code block.
A binary string is called *alternating* if no two adjacent characters of the string are equal. Formally, a binary string T of length M is called alternating if T_{i} \neq T_{i +1} for each 1 ≤ i < M.
For example, 0, 1, 01, 10, 101, 010, 1010 are alternating strings while 11, 001, 1110 are not.
You are given a binary string S of length N. You would like to rearrange the characters of S such that the length of the longest alternating substring of S is maximum. Find this maximum value.
A binary string is a string that consists of characters 0 and 1. A string a is a [substring] of a string b if a can be obtained from b by deletion of several (possibly, zero or all) characters from the beginning and several (possibly, zero or all) characters from the end.
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The T test cases then follow:
- The first line of each test case contains an integer N.
- The second line of each test case contains the binary string S.
------ Output Format ------
For each test case, output the maximum possible length of the longest alternating substring of S after rearrangement.
------ Constraints ------
$1 ≤ T ≤ 10^{4}$
$1 ≤ N ≤ 10^{5}$
$S$ contains only the characters 0 and 1.
- Sum of $N$ over all test cases does not exceed $2 \cdot 10^{5}$.
----- Sample Input 1 ------
4
3
110
4
1010
4
0000
7
1101101
----- Sample Output 1 ------
3
4
1
5
----- explanation 1 ------
Test case $1$: Swapping the second and third characters makes $S=101$. Hence the length of the longest alternating substring is $3$ (choosing the entire string as a substring).
Test case $2$: The given string $S=1010$ is an alternating string of length $4$.
Test case $3$: The length of the longest alternating substring is $1$ for any rearrangement of $S=0000$.
Test case $4$: One possible rearrangement of $S$ is $1\underline{10101}1$, which has an alternating substring of length $5$ (the substring starting at index $2$ and ending at index $6$).
|
{"inputs": ["4\n3\n110\n4\n1010\n4\n0000\n7\n1101101\n"], "outputs": ["3\n4\n1\n5\n"]}
| 590
| 50
|
coding
|
Solve the programming task below in a Python markdown code block.
Complete the method/function so that it converts dash/underscore delimited words into camel casing. The first word within the output should be capitalized **only** if the original word was capitalized (known as Upper Camel Case, also often referred to as Pascal case).
## Examples
```python
to_camel_case("the-stealth-warrior") # returns "theStealthWarrior"
to_camel_case("The_Stealth_Warrior") # returns "TheStealthWarrior"
```
Also feel free to reuse/extend the following starter code:
```python
def to_camel_case(text):
```
|
{"functional": "_inputs = [[''], ['the_stealth_warrior'], ['The-Stealth-Warrior'], ['A-B-C']]\n_outputs = [[''], ['theStealthWarrior'], ['TheStealthWarrior'], ['ABC']]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(to_camel_case(*i), o[0])"}
| 137
| 192
|
coding
|
Solve the programming task below in a Python markdown code block.
Mrs Jefferson is a great teacher. One of her strategies that helped her to reach astonishing results in the learning process is to have some fun with her students. At school, she wants to make an arrangement of her class to play a certain game with her pupils. For that, she needs to create the arrangement with **the minimum amount of groups that have consecutive sizes**.
Let's see. She has ```14``` students. After trying a bit she could do the needed arrangement:
```[5, 4, 3, 2]```
- one group of ```5``` students
- another group of ```4``` students
- then, another one of ```3```
- and finally, the smallest group of ```2``` students.
As the game was a success, she was asked to help to the other classes to teach and show the game. That's why she desperately needs some help to make this required arrangements that make her spend a lot of time.
To make things worse, she found out that there are some classes with some special number of students that is impossible to get that arrangement.
Please, help this teacher!
Your code will receive the number of students of the class. It should output the arrangement as an array with the consecutive sizes of the groups in decreasing order.
For the special case that no arrangement of the required feature is possible the code should output ```[-1] ```
The value of n is unknown and may be pretty high because some classes joined to to have fun with the game.
You may see more example tests in the Example Tests Cases Box.
Also feel free to reuse/extend the following starter code:
```python
def shortest_arrang(n):
```
|
{"functional": "_inputs = [[10], [14], [16], [22], [65]]\n_outputs = [[[4, 3, 2, 1]], [[5, 4, 3, 2]], [[-1]], [[7, 6, 5, 4]], [[33, 32]]]\nimport math\ndef _deep_eq(a, b, tol=1e-5):\n if isinstance(a, float) or isinstance(b, float):\n return math.isclose(a, b, rel_tol=tol, abs_tol=tol)\n if isinstance(a, (list, tuple)):\n if len(a) != len(b): return False\n return all(_deep_eq(x, y, tol) for x, y in zip(a, b))\n return a == b\n\nfor i, o in zip(_inputs, _outputs):\n assert _deep_eq(shortest_arrang(*i), o[0])"}
| 364
| 218
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.