task_type
stringclasses 1
value | problem
stringlengths 261
3.34k
| answer
stringlengths 35
6.15k
| problem_tokens
int64 62
774
| answer_tokens
int64 12
2.04k
|
|---|---|---|---|---|
coding
|
Solve the programming task below in a Python markdown code block.
Given a set of N natural numbers 1,2,3........N and Q query.For each query you have to calculate the total number of subset in which Ith.
number of set come at Kth postion.Elements of every subset should be in sorted order.
The answer could be very large so you have to print answer modulo 1e9+7.
-----Input:-----
- The first line of input cotains a single integer T denoting the number of test cases.
- For every test case it contains two number N and Q.
- Next Q line contains two number I and K.
-----Output:-----
For each test case print required answer.
-----Constraints and Subtasks:-----
- 1<=T<=5
- 1<=N, K<=4000
- 1<=Q<=1000000
Subtask 3: 5 points
- 1<=T<=5
- 1<=N, K<=16
- 1<=Q<=1000
Subtask 1: 25 points
- T=1
- 1<=N, K<=4000
- 1<=Q<=100000
Subtask 2: 70 points
- Original Constraints.
-----Example:-----
Input:
1
3 3
1 2
2 1
3 2
Output:
0
2
2
-----Explanation:-----
For N=3
total subsets are:
{1}
{2}
{3}
{1,2}
{1,3}
{2,3}
{1,2,3}
Now we can see that for I=1 and K=2 there is no subset in which 1 come at 2nd position so the answer is Zero for that query.
For 2nd query I=2 and K=1 there are two subset i.e {2,3} and {2} in which 2 come at 1st position.
Same for 3rd querry there is two subset i.e{1,3} and {2,3}.
|
{"inputs": ["1\n3 3\n1 2\n2 1\n3 2"], "outputs": ["0\n2\n2"]}
| 461
| 32
|
coding
|
Solve the programming task below in a Python markdown code block.
Your program will receive an array of complex numbers represented as strings. Your task is to write the `complexSum` function which have to return the sum as a string.
Complex numbers can be written in the form of `a+bi`, such as `2-3i` where `2` is the real part, `3` is the imaginary part, and `i` is the "imaginary unit".
When you add two complex numbers, the real and the imaginary part needs to be added separately,so for example `2+3i + 5-i = (2+5)+(3i-i) = 7+2i`
Both the complex and the imaginary part can be 0, so `123`, `-2i` or `i` are also complex numbers.
Complex numbers must be returned in their shortest form, so e.g. `0+1*i` should be just `i`, and `10+0i` should be `10`. This is also how you will get them!
For simplicity, the coefficients will always be integers. If the array is empty, return `0`.
Have fun! :)
Also feel free to reuse/extend the following starter code:
```python
def complexSum(arr):
```
|
{"functional": "_inputs = [[['2+3i', '3-i']], [['2-3i', '3+i']], [['3', '-3+i']], [[]], [['3+4i']], [['123+456i']], [['0']], [['-i']], [['1', '1']], [['-5', '5']], [['1', '10', '100', '1000']], [['5+4i', '11+3i']], [['-2-4i', '-8+6i']], [['-1-i', '7+10i']], [['3+4i', '3-4i']], [['10+i', '10-i', '9']], [['2+3i', '0', '0']], [['2+i', '3+2i', '-5-2i']], [['2+i', '3+2i', '-5-4i']], [['10+5i', '1-i', '-i']], [['i', '2i', '3i']], [['-i', '-3i', '1+i']], [['-1000i', '1000i', '1234']], [['-i', '123', '4-i']], [['-1+i', '7+10i']], [['-7+10i', '7+251i']], [['-25-11i', '25+i']], [['-23', '2500i']]]\n_outputs = [['5+2i'], ['5-2i'], ['i'], ['0'], ['3+4i'], ['123+456i'], ['0'], ['-i'], ['2'], ['0'], ['1111'], ['16+7i'], ['-10+2i'], ['6+9i'], ['6'], ['29'], ['2+3i'], ['i'], ['-i'], ['11+3i'], ['6i'], ['1-3i'], ['1234'], ['127-2i'], ['6+11i'], ['261i'], ['-10i'], ['-23+2500i']]\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(complexSum(*i), o[0])"}
| 272
| 616
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given two strings $s$ and $t$, both consisting only of lowercase Latin letters.
The substring $s[l..r]$ is the string which is obtained by taking characters $s_l, s_{l + 1}, \dots, s_r$ without changing the order.
Each of the occurrences of string $a$ in a string $b$ is a position $i$ ($1 \le i \le |b| - |a| + 1$) such that $b[i..i + |a| - 1] = a$ ($|a|$ is the length of string $a$).
You are asked $q$ queries: for the $i$-th query you are required to calculate the number of occurrences of string $t$ in a substring $s[l_i..r_i]$.
-----Input-----
The first line contains three integer numbers $n$, $m$ and $q$ ($1 \le n, m \le 10^3$, $1 \le q \le 10^5$) — the length of string $s$, the length of string $t$ and the number of queries, respectively.
The second line is a string $s$ ($|s| = n$), consisting only of lowercase Latin letters.
The third line is a string $t$ ($|t| = m$), consisting only of lowercase Latin letters.
Each of the next $q$ lines contains two integer numbers $l_i$ and $r_i$ ($1 \le l_i \le r_i \le n$) — the arguments for the $i$-th query.
-----Output-----
Print $q$ lines — the $i$-th line should contain the answer to the $i$-th query, that is the number of occurrences of string $t$ in a substring $s[l_i..r_i]$.
-----Examples-----
Input
10 3 4
codeforces
for
1 3
3 10
5 6
5 7
Output
0
1
0
1
Input
15 2 3
abacabadabacaba
ba
1 15
3 4
2 14
Output
4
0
3
Input
3 5 2
aaa
baaab
1 3
1 1
Output
0
0
-----Note-----
In the first example the queries are substrings: "cod", "deforces", "fo" and "for", respectively.
|
{"inputs": ["1 1 1\na\na\n1 1\n", "1 1 1\na\nb\n1 1\n", "1 1 1\na\nb\n1 1\n", "1 1 1\na\na\n1 1\n", "1 2 1\na\nb\n1 1\n", "1 2 1\na\nb\n1 0\n", "1 1 1\na\nb\n1 0\n", "1 4 1\na\nb\n1 1\n"], "outputs": ["1\n", "0\n", "0\n", "1\n", "0\n", "0\n", "0\n", "0\n"]}
| 546
| 166
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Alice and Bob, both have to drink water. But they both don't want to go, so they will play a game to decide who will fetch water for both of them. Alice will choose a number randomly between 1 and N (both inclusive) and Bob will choose a number randomly between 1 and M (both inclusive). Both will write their numbers on a slip of paper. If sum of numbers choosen by both is odd, then Alice will go, else Bob will go.
What is probability that Alice will go?
------ Input ------
First line contains, T, the number of testcases. Each testcase consists of N and M in one line, separated by a space.
------ Output ------
For each test case, output a single line containing probability as an irreducible fraction.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ N,M ≤ 10^{9}$
----- Sample Input 1 ------
3
1 1
1 2
2 3
----- Sample Output 1 ------
0/1
1/2
1/2
----- explanation 1 ------
#test1: The only way is when Alice and Bob both choose 1. So, Alice won't have to go because sum is even.
#test2: The different ways are (1,1) and (1,2), where first term denotes the number choosen by Alice. So of all possible cases (ie. 2) in only 1 case Alice has to go. Therefore, probability is 1/2.
#test3: The different ways are (1,1), (1,2), (1,3), (2,1), (2,2), (2,3) where first term denotes the number choosen by Alice. So of all possible cases (ie. 6) in only 3 cases Alice has to go. Therefore, probability is 1/2.
|
{"inputs": ["3\n1 1\n1 2\n2 3", "3\n1 1\n1 3\n2 3", "3\n1 2\n1 3\n2 3", "3\n1 1\n1 1\n2 3", "3\n1 1\n2 1\n2 3", "3\n1 3\n1 3\n2 2", "3\n1 1\n2 1\n1 3", "3\n1 2\n2 1\n2 3"], "outputs": ["0/1\n1/2\n1/2", "0/1\n1/3\n1/2\n", "1/2\n1/3\n1/2\n", "0/1\n0/1\n1/2\n", "0/1\n1/2\n1/2\n", "1/3\n1/3\n1/2\n", "0/1\n1/2\n1/3\n", "1/2\n1/2\n1/2\n"]}
| 428
| 237
|
coding
|
Solve the programming task below in a Python markdown code block.
Little Artem likes electronics. He can spend lots of time making different schemas and looking for novelties in the nearest electronics store. The new control element was delivered to the store recently and Artem immediately bought it.
That element can store information about the matrix of integers size n × m. There are n + m inputs in that element, i.e. each row and each column can get the signal. When signal comes to the input corresponding to some row, this row cyclically shifts to the left, that is the first element of the row becomes last element, second element becomes first and so on. When signal comes to the input corresponding to some column, that column shifts cyclically to the top, that is first element of the column becomes last element, second element becomes first and so on. Rows are numbered with integers from 1 to n from top to bottom, while columns are numbered with integers from 1 to m from left to right.
Artem wants to carefully study this element before using it. For that purpose he is going to set up an experiment consisting of q turns. On each turn he either sends the signal to some input or checks what number is stored at some position of the matrix.
Artem has completed his experiment and has written down the results, but he has lost the chip! Help Artem find any initial matrix that will match the experiment results. It is guaranteed that experiment data is consistent, which means at least one valid matrix exists.
Input
The first line of the input contains three integers n, m and q (1 ≤ n, m ≤ 100, 1 ≤ q ≤ 10 000) — dimensions of the matrix and the number of turns in the experiment, respectively.
Next q lines contain turns descriptions, one per line. Each description starts with an integer ti (1 ≤ ti ≤ 3) that defines the type of the operation. For the operation of first and second type integer ri (1 ≤ ri ≤ n) or ci (1 ≤ ci ≤ m) follows, while for the operations of the third type three integers ri, ci and xi (1 ≤ ri ≤ n, 1 ≤ ci ≤ m, - 109 ≤ xi ≤ 109) are given.
Operation of the first type (ti = 1) means that signal comes to the input corresponding to row ri, that is it will shift cyclically. Operation of the second type (ti = 2) means that column ci will shift cyclically. Finally, operation of the third type means that at this moment of time cell located in the row ri and column ci stores value xi.
Output
Print the description of any valid initial matrix as n lines containing m integers each. All output integers should not exceed 109 by their absolute value.
If there are multiple valid solutions, output any of them.
Examples
Input
2 2 6
2 1
2 2
3 1 1 1
3 2 2 2
3 1 2 8
3 2 1 8
Output
8 2
1 8
Input
3 3 2
1 2
3 2 2 5
Output
0 0 0
0 0 5
0 0 0
|
{"inputs": ["5 5 1\n1 5\n", "5 5 1\n1 4\n", "9 5 1\n1 4\n", "5 6 1\n1 4\n", "4 6 1\n1 4\n", "5 7 1\n1 5\n", "9 5 1\n1 7\n", "9 5 1\n1 5\n"], "outputs": ["0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n", "0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n0 0 0 0 0 0\n", "0 0 0 0 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0\n0 0 0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n", "0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n0 0 0 0 0\n"]}
| 693
| 666
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given $a$ uppercase Latin letters 'A' and $b$ letters 'B'.
The period of the string is the smallest such positive integer $k$ that $s_i = s_{i~mod~k}$ ($0$-indexed) for each $i$. Note that this implies that $k$ won't always divide $a+b = |s|$.
For example, the period of string "ABAABAA" is $3$, the period of "AAAA" is $1$, and the period of "AABBB" is $5$.
Find the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'.
-----Input-----
The first line contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$) — the number of letters 'A' and 'B', respectively.
-----Output-----
Print the number of different periods over all possible strings with $a$ letters 'A' and $b$ letters 'B'.
-----Examples-----
Input
2 4
Output
4
Input
5 3
Output
5
-----Note-----
All the possible periods for the first example: $3$ "BBABBA" $4$ "BBAABB" $5$ "BBBAAB" $6$ "AABBBB"
All the possible periods for the second example: $3$ "BAABAABA" $5$ "BAABABAA" $6$ "BABAAABA" $7$ "BAABAAAB" $8$ "AAAAABBB"
Note that these are not the only possible strings for the given periods.
|
{"inputs": ["2 4\n", "5 3\n", "1 1\n", "1 2\n", "2 1\n", "1 3\n", "3 1\n", "2 2\n"], "outputs": ["4\n", "5\n", "1\n", "2\n", "2\n", "2\n", "2\n", "3\n"]}
| 378
| 86
|
coding
|
Solve the programming task below in a Python markdown code block.
Tattah's youngest brother, Tuftuf, is new to programming.
Since his older brother is such a good programmer, his biggest dream is to outshine him. Tuftuf is a student at the German University in Cairo (GUC) where he learns to write programs in Gava.
Today, Tuftuf was introduced to Gava's unsigned integer datatypes. Gava has n unsigned integer datatypes of sizes (in bits) a1, a2, ... an. The i-th datatype have size ai bits, so it can represent every integer between 0 and 2ai - 1 inclusive.
Tuftuf is thinking of learning a better programming language. If there exists an integer x, such that x fits in some type i (in ai bits) and x·x does not fit in some other type j (in aj bits) where ai < aj, then Tuftuf will stop using Gava.
Your task is to determine Tuftuf's destiny.
Input
The first line contains integer n (2 ≤ n ≤ 105) — the number of Gava's unsigned integer datatypes' sizes. The second line contains a single-space-separated list of n integers (1 ≤ ai ≤ 109) — sizes of datatypes in bits. Some datatypes may have equal sizes.
Output
Print "YES" if Tuftuf will stop using Gava, and "NO" otherwise.
Examples
Input
3
64 16 32
Output
NO
Input
4
4 2 1 3
Output
YES
Note
In the second example, x = 7 (1112) fits in 3 bits, but x2 = 49 (1100012) does not fit in 4 bits.
|
{"inputs": ["2\n1 2\n", "2\n1 1\n", "2\n2 1\n", "2\n1 3\n", "2\n0 1\n", "2\n0 2\n", "2\n0 4\n", "2\n0 7\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 390
| 102
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are two mice and n different types of cheese, each type of cheese should be eaten by exactly one mouse.
A point of the cheese with index i (0-indexed) is:
reward1[i] if the first mouse eats it.
reward2[i] if the second mouse eats it.
You are given a positive integer array reward1, a positive integer array reward2, and a non-negative integer k.
Return the maximum points the mice can achieve if the first mouse eats exactly k types of cheese.
Please complete the following python code precisely:
```python
class Solution:
def miceAndCheese(self, reward1: List[int], reward2: List[int], k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(reward1 = [1,1,3,4], reward2 = [4,4,1,1], k = 2) == 15\n assert candidate(reward1 = [1,1], reward2 = [1,1], k = 2) == 2\n\n\ncheck(Solution().miceAndCheese)"}
| 164
| 89
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
There are buckets buckets of liquid, where exactly one of the buckets is poisonous. To figure out which one is poisonous, you feed some number of (poor) pigs the liquid to see whether they will die or not. Unfortunately, you only have minutesToTest minutes to determine which bucket is poisonous.
You can feed the pigs according to these steps:
Choose some live pigs to feed.
For each pig, choose which buckets to feed it. The pig will consume all the chosen buckets simultaneously and will take no time. Each pig can feed from any number of buckets, and each bucket can be fed from by any number of pigs.
Wait for minutesToDie minutes. You may not feed any other pigs during this time.
After minutesToDie minutes have passed, any pigs that have been fed the poisonous bucket will die, and all others will survive.
Repeat this process until you run out of time.
Given buckets, minutesToDie, and minutesToTest, return the minimum number of pigs needed to figure out which bucket is poisonous within the allotted time.
Please complete the following python code precisely:
```python
class Solution:
def poorPigs(self, buckets: int, minutesToDie: int, minutesToTest: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(buckets = 1000, minutesToDie = 15, minutesToTest = 60) == 5\n assert candidate(buckets = 4, minutesToDie = 15, minutesToTest = 15) == 2\n assert candidate(buckets = 4, minutesToDie = 15, minutesToTest = 30) == 2\n\n\ncheck(Solution().poorPigs)"}
| 272
| 111
|
coding
|
Solve the programming task below in a Python markdown code block.
After learning a lot about space exploration, a little girl named Ana wants to change the subject.
Ana is a girl who loves palindromes (string that can be read the same backwards as forward). She has learned how to check for a given string whether it's a palindrome or not, but soon she grew tired of this problem, so she came up with a more interesting one and she needs your help to solve it:
You are given an array of strings which consist of only small letters of the alphabet. Your task is to find how many palindrome pairs are there in the array. A palindrome pair is a pair of strings such that the following condition holds: at least one permutation of the concatenation of the two strings is a palindrome. In other words, if you have two strings, let's say "aab" and "abcac", and you concatenate them into "aababcac", we have to check if there exists a permutation of this new string such that it is a palindrome (in this case there exists the permutation "aabccbaa").
Two pairs are considered different if the strings are located on different indices. The pair of strings with indices $(i,j)$ is considered the same as the pair $(j,i)$.
-----Input-----
The first line contains a positive integer $N$ ($1 \le N \le 100\,000$), representing the length of the input array.
Eacg of the next $N$ lines contains a string (consisting of lowercase English letters from 'a' to 'z') — an element of the input array.
The total number of characters in the input array will be less than $1\,000\,000$.
-----Output-----
Output one number, representing how many palindrome pairs there are in the array.
-----Examples-----
Input
3
aa
bb
cd
Output
1
Input
6
aab
abcac
dffe
ed
aa
aade
Output
6
-----Note-----
The first example: aa $+$ bb $\to$ abba.
The second example: aab $+$ abcac $=$ aababcac $\to$ aabccbaa aab $+$ aa $=$ aabaa abcac $+$ aa $=$ abcacaa $\to$ aacbcaa dffe $+$ ed $=$ dffeed $\to$ fdeedf dffe $+$ aade $=$ dffeaade $\to$ adfaafde ed $+$ aade $=$ edaade $\to$ aeddea
|
{"inputs": ["3\naa\nbb\ncd\n", "3\naa\nbc\ncd\n", "3\naa\ncc\ncd\n", "3\naa\ncc\ndd\n", "3\naa\ncd\ndd\n", "3\naa\nbb\ncd\n", "6\naab\nabcac\ndffe\ned\naa\naade\n", "6\naab\nabcbc\ndffe\ned\naa\nabde\n"], "outputs": ["1\n", "0\n", "1\n", "3\n", "1\n", "1\n", "6\n", "3\n"]}
| 547
| 143
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef defines a group of three friends as a *perfect* group if the age of one person is equal to the sum of the age of remaining two people.
Given that, the ages of three people in a group are A, B, and C respectively, find whether the group is *perfect*.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of three space-separated integers A, B, and C — the age of the three members of group.
------ Output Format ------
For each test case, output on a new line, YES, if the group is perfect, and NO otherwise.
You may print each character in uppercase or lowercase. For example, the strings YES, yes, Yes, and yES are considered identical.
------ Constraints ------
$1 ≤ T ≤ 200$
$1 ≤ A, B, C ≤ 100$
----- Sample Input 1 ------
4
10 20 30
23 51 17
44 21 23
30 30 30
----- Sample Output 1 ------
YES
NO
YES
NO
----- explanation 1 ------
Test case $1$: The sum of age of first and second person is equal to that of the third person. Thus, the group is *perfect*.
Test case $2$: There exists no member in the group such that the age of one person is equal to the sum of the age of remaining two people. Thus, the group is not *perfect*.
Test case $3$: The sum of age of second and third person is equal to that of the first person. Thus, the group is *perfect*.
Test case $4$: There exists no member in the group such that the age of one person is equal to the sum of the age of remaining two people. Thus, the group is not *perfect*.
|
{"inputs": ["4\n10 20 30\n23 51 17\n44 21 23\n30 30 30\n"], "outputs": ["YES\nNO\nYES\nNO\n"]}
| 424
| 56
|
coding
|
Solve the programming task below in a Python markdown code block.
A number m of the form 10x + y is divisible by 7 if and only if x − 2y is divisible by 7. In other words, subtract twice the last digit
from the number formed by the remaining digits. Continue to do this until a number known to be divisible or not by 7 is obtained;
you can stop when this number has *at most* 2 digits because you are supposed to know if a number of at most 2 digits is divisible by 7 or not.
The original number is divisible by 7 if and only if the last number obtained using this procedure is divisible by 7.
Examples:
1 - `m = 371 -> 37 − (2×1) -> 37 − 2 = 35` ; thus, since 35 is divisible by 7, 371 is divisible by 7.
The number of steps to get the result is `1`.
2 - `m = 1603 -> 160 - (2 x 3) -> 154 -> 15 - 8 = 7` and 7 is divisible by 7.
3 - `m = 372 -> 37 − (2×2) -> 37 − 4 = 33` ; thus, since 33 is not divisible by 7, 372 is not divisible by 7.
The number of steps to get the result is `1`.
4 - `m = 477557101->47755708->4775554->477547->47740->4774->469->28` and 28 is divisible by 7, so is 477557101.
The number of steps is 7.
# Task:
Your task is to return to the function ```seven(m)``` (m integer >= 0) an array (or a pair, depending on the language) of numbers,
the first being the *last* number `m` with at most 2 digits obtained by your function (this last `m` will be divisible or not by 7), the second one being the number of steps to get the result.
## Forth Note:
Return on the stack `number-of-steps, last-number-m-with-at-most-2-digits `
## Examples:
```
seven(371) should return [35, 1]
seven(1603) should return [7, 2]
seven(477557101) should return [28, 7]
```
Also feel free to reuse/extend the following starter code:
```python
def seven(m):
```
|
{"functional": "_inputs = [[1021], [477557101], [477557102], [2340029794923400297949], [1603], [371], [1369851], [483], [483595], [0], [170232833617690725]]\n_outputs = [[[10, 2]], [[28, 7]], [[47, 7]], [[14, 20]], [[7, 2]], [[35, 1]], [[0, 5]], [[42, 1]], [[28, 4]], [[0, 0]], [[0, 16]]]\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(seven(*i), o[0])"}
| 616
| 331
|
coding
|
Solve the programming task below in a Python markdown code block.
For 3 distinct prime integers A, B, and C (1 < A,B,C < 2^{30}), we define positive integers X, Y, and Z as:
X = A\oplus B, Y = B\oplus C, and Z = C\oplus A, where \oplus denotes the [bitwise XOR] operation.
Given only two integers X and Y and the fact that at least one integer amongst X, Y, and Z is odd, find the values of A, B, and C.
Note:
You need to print the integers A, B, and C in ascending order.
It is guaranteed in the input that a unique answer exists.
------ Input Format ------
- The first line contains one integer T — the number of test cases. Then T test cases follow.
- Each test case consists of one line which contains 2 integers X and Y.
------ Output Format ------
- For each test case, print 3 integers — A , B, and C in ascending order where (1 < A,B,C < 2^{30}).
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ X, Y< 2^{30}$
----- Sample Input 1 ------
2
1 6
9 15
----- Sample Output 1 ------
2 3 5
2 11 13
----- explanation 1 ------
Test Case $1$: The answer is $A=2, B=3, C=5$. Thus, $X=2\oplus 3 = 1, Y = 3\oplus 5 = 6, Z = 2\oplus 5 = 7$. Note that $X$ and $Y$ are same as mentioned in input and the values $X$ as well as $Z$ are odd.
Test Case $2$: The answer is $A=11, B=2, C=13$. Thus, $X=11\oplus 2 = 9, Y = 2\oplus 13 = 15, Z = 11\oplus 13 = 6$. Note that $X$ and $Y$ are same as mentioned in input and the values $X$ as well as $Y$ are odd.
Thus, the values of $A, B,$ and $C$ in ascending order are $2, 11,$ and $13$.
|
{"inputs": ["2\n1 6\n9 15"], "outputs": ["2 3 5\n2 11 13"]}
| 540
| 33
|
coding
|
Solve the programming task below in a Python markdown code block.
Welcome
This kata is inspired by This Kata
We have a string s
We have a number n
Here is a function that takes your string, concatenates the even-indexed chars to the front, odd-indexed chars to the back.
Examples
s = "Wow Example!"
result = "WwEapeo xml!"
s = "I'm JomoPipi"
result = "ImJm ii' ooPp"
The Task:
return the result of the string after applying the function to it n times.
example where s = "qwertyuio" and n = 2:
after 1 iteration s = "qetuowryi"
after 2 iterations s = "qtorieuwy"
return "qtorieuwy"
Note
there's a lot of tests, big strings,
and n is greater than a billion
so be ready to optimize.
after doing this: do it's best friend!
# Check out my other kata!
Matrix Diagonal Sort OMG
String -> N iterations -> String
String -> X iterations -> String
ANTISTRING
Array - squareUp b!
Matrix - squareUp b!
Infinitely Nested Radical Expressions
pipi Numbers!
Also feel free to reuse/extend the following starter code:
```python
def jumbled_string(s, n):
```
|
{"functional": "_inputs = [['Such Wow!', 1], ['better example', 2], ['qwertyuio', 2], ['Greetings', 8], ['I like it!', 1234], ['codingisfornerdsyounerd', 10101010], ['this_test_will_hurt_you', 12345678987654321]]\n_outputs = [['Sc o!uhWw'], ['bexltept merae'], ['qtorieuwy'], ['Gtsegenri'], ['Iiei t kl!'], ['criyinodedsgufrnodnoser'], ['ti_etwl_utyuhsts_ilhr_o']]\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(jumbled_string(*i), o[0])"}
| 293
| 298
|
coding
|
Solve the programming task below in a Python markdown code block.
Write a function which converts the input string to uppercase.
~~~if:bf
For BF all inputs end with \0, all inputs are lowercases and there is no space between.
~~~
Also feel free to reuse/extend the following starter code:
```python
def make_upper_case(s):
```
|
{"functional": "_inputs = [['hello'], ['hello world'], ['hello world !'], ['heLlO wORLd !'], ['1,2,3 hello world!']]\n_outputs = [['HELLO'], ['HELLO WORLD'], ['HELLO WORLD !'], ['HELLO WORLD !'], ['1,2,3 HELLO WORLD!']]\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_upper_case(*i), o[0])"}
| 76
| 214
|
coding
|
Solve the programming task below in a Python markdown code block.
You're given an integer N. Write a program to calculate the sum of all the digits of N.
-----Input-----
The first line contains an integer T, the total number of testcases. Then follow T lines, each line contains an integer N.
-----Output-----
For each test case, calculate the sum of digits of N, and display it in a new line.
-----Constraints-----
- 1 ≤ T ≤ 1000
- 1 ≤ N ≤ 1000000
-----Example-----
Input
3
12345
31203
2123
Output
15
9
8
|
{"inputs": ["3 \n595\n1\n8", "3 \n595\n1\n1", "3 \n831\n1\n1", "3 \n831\n1\n2", "3 \n831\n1\n0", "3 \n290\n39\n8", "3 \n562\n39\n8", "3 \n595\n39\n8"], "outputs": ["19\n1\n8\n", "19\n1\n1\n", "12\n1\n1\n", "12\n1\n2\n", "12\n1\n0\n", "11\n12\n8\n", "13\n12\n8\n", "19\n12\n8\n"]}
| 152
| 180
|
coding
|
Solve the programming task below in a Python markdown code block.
Today, Wet Shark is given n integers. Using any of these integers no more than once, Wet Shark wants to get maximum possible even (divisible by 2) sum. Please, calculate this value for Wet Shark.
Note, that if Wet Shark uses no integers from the n integers, the sum is an even integer 0.
-----Input-----
The first line of the input contains one integer, n (1 ≤ n ≤ 100 000). The next line contains n space separated integers given to Wet Shark. Each of these integers is in range from 1 to 10^9, inclusive.
-----Output-----
Print the maximum possible even sum that can be obtained if we use some of the given integers.
-----Examples-----
Input
3
1 2 3
Output
6
Input
5
999999999 999999999 999999999 999999999 999999999
Output
3999999996
-----Note-----
In the first sample, we can simply take all three integers for a total sum of 6.
In the second sample Wet Shark should take any four out of five integers 999 999 999.
|
{"inputs": ["1\n1\n", "1\n4\n", "1\n4\n", "1\n1\n", "1\n5\n", "1\n2\n", "1\n9\n", "1\n3\n"], "outputs": ["0", "4", "4", "0", "0\n", "2\n", "0\n", "0\n"]}
| 300
| 82
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an initial array arr, every day you produce a new array using the array of the previous day.
On the i-th day, you do the following operations on the array of day i-1 to produce the array of day i:
If an element is smaller than both its left neighbor and its right neighbor, then this element is incremented.
If an element is bigger than both its left neighbor and its right neighbor, then this element is decremented.
The first and last elements never change.
After some days, the array does not change. Return that final array.
Please complete the following python code precisely:
```python
class Solution:
def transformArray(self, arr: List[int]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate([6,2,3,4]) == [6,3,3,4]\n assert candidate([1,6,3,4,3,5]) == [1,4,4,4,4,5]\n\n\ncheck(Solution().transformArray)"}
| 166
| 73
|
coding
|
Solve the programming task below in a Python markdown code block.
The translation from the Berland language into the Birland language is not an easy task. Those languages are very similar: a berlandish word differs from a birlandish word with the same meaning a little: it is spelled (and pronounced) reversely. For example, a Berlandish word code corresponds to a Birlandish word edoc. However, it's easy to make a mistake during the «translation». Vasya translated word s from Berlandish into Birlandish as t. Help him: find out if he translated the word correctly.
Input
The first line contains word s, the second line contains word t. The words consist of lowercase Latin letters. The input data do not consist unnecessary spaces. The words are not empty and their lengths do not exceed 100 symbols.
Output
If the word t is a word s, written reversely, print YES, otherwise print NO.
Examples
Input
code
edoc
Output
YES
Input
abb
aba
Output
NO
Input
code
code
Output
NO
|
{"inputs": ["q\nq\n", "z\na\n", "w\nw\n", "q\nr\n", "z\n`\n", "x\nw\n", "r\nq\n", "z\n_\n"], "outputs": ["YES\n", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 232
| 86
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array of unique positive integers nums. Consider the following graph:
There are nums.length nodes, labeled nums[0] to nums[nums.length - 1],
There is an undirected edge between nums[i] and nums[j] if nums[i] and nums[j] share a common factor greater than 1.
Return the size of the largest connected component in the graph.
Please complete the following python code precisely:
```python
class Solution:
def largestComponentSize(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [4,6,15,35]) == 4\n assert candidate(nums = [20,50,9,63]) == 2\n assert candidate(nums = [2,3,6,7,4,12,21,39]) == 8\n\n\ncheck(Solution().largestComponentSize)"}
| 129
| 91
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problem statements in [Russian], [Bengali], and [Mandarin Chinese] as well.
There are $N$ students standing in a canteen queue, numbered $1$ to $N$ from left to right. For each valid $i$, the $i$-th student has a height $h_{i}$.
Two students $i$ and $j$ can see each other if there are no taller students standing between them. Formally, students $i$ and $j$ ($i < j$) can see each other if for each integer $k$ ($i < k < j$), $h_{k} ≤ h_{i}, h_{j}$.
For each valid $i$, determine the number $c_{i}$ of students that have the same height as student $i$ and can be seen by student $i$.
------ 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 $h_{1}, h_{2}, \ldots, h_{N}$.
------ Output ------
For each test case, print a single line containing $N$ space-separated integers $c_{1}, c_{2}, \ldots, c_{N}$.
------ Constraints ------
$1 ≤ T ≤ 10$
$1 ≤ N ≤ 10^{5}$
$1 ≤ h_{i} ≤ 10^{9}$ for each valid $i$
the sum of $N$ over all test cases does not exceed $10^{5}$
------ Subtasks ------
Subtask #1 (30 points): the sum of $N$ over all test cases does not exceed $10^{3}$
Subtask #2 (70 points): original constraints
----- Sample Input 1 ------
1
5
1 2 2 3 2
----- Sample Output 1 ------
0 1 1 0 0
----- explanation 1 ------
Example case 1: Student $3$ can see students $2$ and $4$, but only student $2$ has the same height (height $2$). On the other hand, student $3$ cannot see student $5$ since student $4$ is taller and therefore blocking the view.
|
{"inputs": ["1\n5\n1 2 2 3 2"], "outputs": ["0 1 1 0 0"]}
| 532
| 32
|
coding
|
Solve the programming task below in a Python markdown code block.
Rohit was doing the work of his math class about three days but he is tired of make operations a lot and he should deliver his task tomorrow. His math’s teacher gives two numbers a and b. The problem consist in find the last digit of the potency of base a and index b. Help Rohit with his problem. You are given two integer numbers: the base a (number of digits d, such that 1 ≤ d ≤ 1000) and the index b (0 ≤ b ≤ 922*10^15). You
have to find the last digit of a^b.
Input
The first line of input contains an integer t, the number of test cases (t ≤ 30). t test cases follow. For each test case will appear a and b separated by space.
Output
For each test case output an integer per line representing the result.
SAMPLE INPUT
3
3 10
6 2
150 53
SAMPLE OUTPUT
9
6
0
|
{"inputs": ["5\n19021463561276851735171355238976350962817489980593657752206579555021148207736012355943198456853373185208340964575628990983191088521799365137969929935263986287756454173080642274585186167796948331561682 8017\n4565194923754350257539737098390625395160137517839262785449977071416145818084360997843473461107344162030398108758612300307414026892283955351325583379600824792607328507078826675211721556289028370301673006538038735675826305286824169882265803963400612489910588 7548\n659063812791021229822466317887986314830182981298713688406408219952323376496329790558334383562205851645101036567627640094248414642828587489947352419177965354006293426411310155661553392239311288387504980849027117718084180756049768066833545622421252036303721605124427635581115671776027485400649197935164795996238764238944754340226124265801759598725 25016\n7944991045309106055427559014596076163462461104292082577280636906661771243005701004069484208830658707201450403619350097315884789900881673593619542949311729817918241954937230973652654228682322900953971647610612604397523597506920622541202101904587194119015841016895058098090213533257593171815355632450552368487640293716414605444624295899004982901848269222067709886771010767457947506561997622987092932138779256945414217883380450487880771313180711142283842467387596266457086705618333682050468165401517968013577189435414621461291909110352519665840065620789848862430049969246666721572599947309867590883886617110281174947849409819885035541130639203032839423419 8348\n77171924763039023600462850554682077336895044664648267750601388017634561233309985137435653034778247490059751147763663822282553130788117118002898583676073296810606347680761913122721062674553552472132088599590634626611972436789566210745939 3892"], "outputs": ["2\n6\n5\n1\n1"]}
| 228
| 1,740
|
coding
|
Solve the programming task below in a Python markdown code block.
Two players are playing a game of Tower Breakers! Player $1$ always moves first, and both players always play optimally.The rules of the game are as follows:
Initially there are $n$ towers.
Each tower is of height $m$.
The players move in alternating turns.
In each turn, a player can choose a tower of height $x$ and reduce its height to $y$, where $1\leq y<x$ and $y$ evenly divides $x$.
If the current player is unable to make a move, they lose the game.
Given the values of $n$ and $m$, determine which player will win. If the first player wins, return $1$. Otherwise, return $2$.
Example.
$n=2$
$m=6$
There are $2$ towers, each $6$ units tall. Player $1$ has a choice of two moves:
- remove $3$ pieces from a tower to leave $6$ as $6 \quad modulo \quad 3=0$
- remove $5$ pieces to leave $1$
Let Player $1$ remove $3$. Now the towers are $3$ and $6$ units tall.
Player $2$ matches the move. Now the towers are both $3$ units tall.
Now Player $1$ has only one move.
Player $1$ removes $2$ pieces leaving $1$. Towers are $1$ and $2$ units tall.
Player $2$ matches again. Towers are both $1$ unit tall.
Player $1$ has no move and loses. Return $2$.
Function Description
Complete the towerBreakers function in the editor below.
towerBreakers has the following paramter(s):
int n: the number of towers
int m: the height of each tower
Returns
int: the winner of the game
Input Format
The first line contains a single integer $t$, the number of test cases.
Each of the next $t$ lines describes a test case in the form of $2$ space-separated integers, $n$ and $m$.
Constraints
$1\leq t\leq100$
$1\leq n,m\leq10^6$
Sample Input
STDIN Function
----- --------
2 t = 2
2 2 n = 2, m = 2
1 4 n = 1, m = 4
Sample Output
2
1
Explanation
We'll refer to player $1$ as $P1$ and player $2$ as $P2$
In the first test case, $P1$ chooses one of the two towers and reduces it to $1$. Then $P2$ reduces the remaining tower to a height of $1$. As both towers now have height $1$, $P1$ cannot make a move so $P2$ is the winner.
In the second test case, there is only one tower of height $4$. $P1$ can reduce it to a height of either $1$ or $2$. $P1$ chooses $1$ as both players always choose optimally. Because $P2$ has no possible move, $P1$ wins.
|
{"inputs": ["2\n2 2\n1 4\n"], "outputs": ["2\n1\n"]}
| 706
| 24
|
coding
|
Solve the programming task below in a Python markdown code block.
There are three cities and thus three EVMs. An insider told Chef that his party got A, B, C votes respectively in these three cities according to the EVMs. Also, the total number of votes cast are P, Q, R respectively for the three cities.
Chef, being the party leader, can hack at most one EVM so that his party wins. On hacking a particular EVM all the votes cast in that EVM are counted in favor of Chef's party.
A party must secure strictly more than half of the total number of votes cast in order to be considered the winner. Can Chef achieve his objective of winning by hacking at most one EVM?
------ Input Format ------
- The first line of input contains an integer T, denoting the number of test cases. The description of T test cases follows.
- Each test case consists of a single line of input, containing six space-separated integers — in order, A, B, C, P, Q, R.
------ Output Format ------
For each test case, output in a single line the answer — "YES", if Chef can win the election after hacking at most one EVM and "NO" if not.
You may print each character of the string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 ≤ T ≤ 5 \cdot 10^{3}$
$0 ≤ A < P ≤ 100$
$0 ≤ B < Q ≤ 100$
$0 ≤ C < R ≤ 100$
----- Sample Input 1 ------
3
1 1 1 3 3 3
49 1 49 50 100 50
0 0 0 1 1 1
----- Sample Output 1 ------
YES
YES
NO
----- explanation 1 ------
Test case $1$: Chef can hack any EVM, thus getting a total of $3 + 1 + 1 = 5$ votes which is more than $\frac{3 + 3 + 3}{2} = 4.5$ votes.
Test case $2$: Only hacking the second EVM works, getting a total of $49 + 100 + 49 = 198$ votes which is more than $\frac{50 + 100 + 50}{2} = 100$ votes.
Test case $3$: None of the EVM's can help Chef in winning the election, since maximum number of votes he can secure by doing so is $1 + 0 + 0 = 1$ which is less than $\frac{1 + 1 + 1}{2} = 1.5$.
|
{"inputs": ["3\n1 1 1 3 3 3\n49 1 49 50 100 50\n0 0 0 1 1 1\n"], "outputs": ["YES\nYES\nNO\n"]}
| 610
| 60
|
coding
|
Solve the programming task below in a Python markdown code block.
Suppose you are living with two cats: A and B. There are $n$ napping spots where both cats usually sleep.
Your cats like to sleep and also like all these spots, so they change napping spot each hour cyclically:
Cat A changes its napping place in order: $n, n - 1, n - 2, \dots, 3, 2, 1, n, n - 1, \dots$ In other words, at the first hour it's on the spot $n$ and then goes in decreasing order cyclically;
Cat B changes its napping place in order: $1, 2, 3, \dots, n - 1, n, 1, 2, \dots$ In other words, at the first hour it's on the spot $1$ and then goes in increasing order cyclically.
The cat B is much younger, so they have a strict hierarchy: A and B don't lie together. In other words, if both cats'd like to go in spot $x$ then the A takes this place and B moves to the next place in its order (if $x < n$ then to $x + 1$, but if $x = n$ then to $1$). Cat B follows his order, so it won't return to the skipped spot $x$ after A frees it, but will move to the spot $x + 2$ and so on.
Calculate, where cat B will be at hour $k$?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases.
The first and only line of each test case contains two integers $n$ and $k$ ($2 \le n \le 10^9$; $1 \le k \le 10^9$) — the number of spots and hour $k$.
-----Output-----
For each test case, print one integer — the index of the spot where cat B will sleep at hour $k$.
-----Examples-----
Input
7
2 1
2 2
3 1
3 2
3 3
5 5
69 1337
Output
1
2
1
3
2
2
65
-----Note-----
In the first and second test cases $n = 2$, so:
at the $1$-st hour, A is on spot $2$ and B is on $1$;
at the $2$-nd hour, A moves to spot $1$ and B — to $2$.
If $n = 3$ then:
at the $1$-st hour, A is on spot $3$ and B is on $1$;
at the $2$-nd hour, A moves to spot $2$; B'd like to move from $1$ to $2$, but this spot is occupied, so it moves to $3$;
at the $3$-rd hour, A moves to spot $1$; B also would like to move from $3$ to $1$, but this spot is occupied, so it moves to $2$.
In the sixth test case:
A's spots at each hour are $[5, 4, 3, 2, 1]$;
B's spots at each hour are $[1, 2, 4, 5, 2]$.
|
{"inputs": ["1\n35 950009\n", "1\n2 1615745\n", "1\n6 1687697\n", "1\n59 950009\n", "1\n22 313455\n", "1\n6 2518353\n", "1\n62 950009\n", "1\n35 669530\n"], "outputs": ["26\n", "1\n", "5\n", "4\n", "21\n", "3\n", "45\n", "24\n"]}
| 748
| 154
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff each substring of s with length at least k contains this character c.
You have to find minimum k such that there exists at least one k-dominant character.
-----Input-----
The first line contains string s consisting of lowercase Latin letters (1 ≤ |s| ≤ 100000).
-----Output-----
Print one number — the minimum value of k such that there exists at least one k-dominant character.
-----Examples-----
Input
abacaba
Output
2
Input
zzzzz
Output
1
Input
abcde
Output
3
|
{"inputs": ["a\n", "z\n", "a\n", "z\n", "ab\n", "ob\n", "zx\n", "xx\n"], "outputs": ["1\n", "1\n", "1", "1", "2\n", "2\n", "2\n", "1\n"]}
| 152
| 68
|
coding
|
Solve the programming task below in a Python markdown code block.
$Alien$ likes to give challenges to $Codezen$ team to check their implementation ability, this time he has given a string $S$ and asked to find out whether the given string is a $GOOD$ string or not.
According to the challenge $GOOD$ String is a string that has at least $3$ consecutive vowels and at least $5$ different consonants.
For example $ACQUAINTANCES$ is a $ GOOD $String ,as it contains $3$ consecutive vowels $UAI$ and $5$ different consonants $ {C, Q, N, T, S} $
but $ACQUAINT $ is not ,as it contain $3$ vowels but have only $ 4$ different consonants
${C, Q, N, T}$.
-----Input:-----
A string input is given from Standard Input that consists of only capital letters.
-----Output:-----
Output a single line that is either $GOOD$ (if string is a good string ) or $-1$(if string is not good).
-----Constraints-----
- $8 \leq S \leq 1000$
-----Sample Input 1:-----
AMBITIOUSNESS
-----Sample Output 2:-----
GOOD
-----Sample Input 2:-----
COOEY
-----Sample Output 2:-----
-1
|
{"inputs": ["COOEY", "AMBITIOUSNESS"], "outputs": ["-1", "GOOD"]}
| 298
| 24
|
coding
|
Solve the programming task below in a Python markdown code block.
In the year 4242, the language Haskell has evolved so much that it has become an AI. It can solve very challenging problems, in very little time. Humanity is worried that Haskell will take over the world. All hopes remain tied to the Competitive Programming community as they are the expert in shaving milliseconds off code runtime. Haskell creators have found one particular task that if solved faster than Haskell itself, can be used to hack into Haskell's codebase and thus defeat it. The exact details of the task are as follows,
" Calculate the sum, S(N, K) = , for Q queries. Here Fi is ith Fibonacci number defined as: Fi = i if i = 0 or 1 and Fi = Fi-1 + Fi-2 if i >= 2. "
You being a member of the Competitive Programming community are encouraged to make a submission to this task.
-----Input-----
The first line contains a single integer Q, the number of queries.
Each of the next Q lines contain two integers each, Ni and Ki.
-----Output-----
Output Q lines with one integer each. The ith line should contain the value S(Ni, Ki).
-----Constraints-----
- 1 <= Q <= 5*104
- 1 <= N <= 1018
- 1 <= K <= 1018
-----Example-----
Input:
1
1 1
Output:
1
|
{"inputs": ["1\n1 1"], "outputs": ["1"]}
| 303
| 16
|
coding
|
Solve the programming task below in a Python markdown code block.
The Bitlandians are quite weird people. They do everything differently. They have a different alphabet so they have a different definition for a string.
A Bitlandish string is a string made only of characters "0" and "1".
BitHaval (the mayor of Bitland) loves to play with Bitlandish strings. He takes some Bitlandish string a, and applies several (possibly zero) operations to it. In one operation the mayor may take any two adjacent characters of a string, define one of them as x and the other one as y. Then he calculates two values p and q: p = x xor y, q = x or y. Then he replaces one of the two taken characters by p and the other one by q.
The xor operation means the bitwise excluding OR operation. The or operation is the bitwise OR operation.
So for example one operation can transform string 11 to string 10 or to string 01. String 1 cannot be transformed into any other string.
You've got two Bitlandish strings a and b. Your task is to check if it is possible for BitHaval to transform string a to string b in several (possibly zero) described operations.
-----Input-----
The first line contains Bitlandish string a, the second line contains Bitlandish string b. The strings can have different lengths.
It is guaranteed that the given strings only consist of characters "0" and "1". The strings are not empty, their length doesn't exceed 10^6.
-----Output-----
Print "YES" if a can be transformed into b, otherwise print "NO". Please do not print the quotes.
-----Examples-----
Input
11
10
Output
YES
Input
1
01
Output
NO
Input
000
101
Output
NO
|
{"inputs": ["0\n1\n", "1\n1\n", "0\n0\n", "1\n0\n", "1\n1\n", "0\n0\n", "1\n0\n", "0\n1\n"], "outputs": ["NO\n", "YES\n", "YES\n", "NO\n", "YES\n", "YES\n", "NO\n", "NO\n"]}
| 396
| 86
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef has a standard chocolate of n by m pieces. More formally, chocolate is a rectangular plate consisting of n rows and m columns.
Here you can see an example of a standard 5 by 7 chocolate.
He has two friends and they will play with this chocolate. First friend takes the chocolate and cuts it into two parts by making either a horizontal or vertical cut. Then, the second friend takes one of the available pieces and divides into two parts by either making a horizontal or vertical cut. Then the turn of first friend comes and he can pick any block of the available chocolates and do the same thing again. The player who cannot make a turn loses.
Now Chef is interested in finding which of his friends will win if both of them play optimally. Output "Yes", if the friend who plays first will win, otherwise print "No".
------ 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 only line of each test case contains two space separated integers n and m - the sizes of the chocolate.
------ Output ------
For each test case, output a single line containing one word "Yes" (without quotes) if there is a sequence of moves leading to the winning of the person who moves first and "No" (without quotes) otherwise.
------ Constraints ------
$1 ≤ T ≤ 100$
$1 ≤ n, m ≤ 10^{9}$
------ Subtasks ------
Subtask #1 (10 points):
$1 ≤ n, m ≤ 10$
Subtask #2 (30 points):
$n = 1 or m = 1$
Subtask #3 (60 points): No additional constraints
----- Sample Input 1 ------
2
1 2
1 3
----- Sample Output 1 ------
Yes
No
----- explanation 1 ------
Example case 1. There is only one possible move, so the second player even won't have a chance to make move.
Example case 2. There are only two ways first player can make first move, after each of them only one move left, so the first player cannot win.
|
{"inputs": ["2\n1 2\n1 3"], "outputs": ["Yes\nNo"]}
| 482
| 22
|
coding
|
Solve the programming task below in a Python markdown code block.
Ayoub had an array $a$ of integers of size $n$ and this array had two interesting properties: All the integers in the array were between $l$ and $r$ (inclusive). The sum of all the elements was divisible by $3$.
Unfortunately, Ayoub has lost his array, but he remembers the size of the array $n$ and the numbers $l$ and $r$, so he asked you to find the number of ways to restore the array.
Since the answer could be very large, print it modulo $10^9 + 7$ (i.e. the remainder when dividing by $10^9 + 7$). In case there are no satisfying arrays (Ayoub has a wrong memory), print $0$.
-----Input-----
The first and only line contains three integers $n$, $l$ and $r$ ($1 \le n \le 2 \cdot 10^5 , 1 \le l \le r \le 10^9$) — the size of the lost array and the range of numbers in the array.
-----Output-----
Print the remainder when dividing by $10^9 + 7$ the number of ways to restore the array.
-----Examples-----
Input
2 1 3
Output
3
Input
3 2 2
Output
1
Input
9 9 99
Output
711426616
-----Note-----
In the first example, the possible arrays are : $[1,2], [2,1], [3, 3]$.
In the second example, the only possible array is $[2, 2, 2]$.
|
{"inputs": ["2 1 3\n", "3 2 2\n", "1 1 1\n", "3 1 1\n", "3 1 1\n", "1 1 1\n", "6 1 1\n", "2 1 2\n"], "outputs": ["3\n", "1\n", "0\n", "1\n", "1", "0", "1\n", "2\n"]}
| 373
| 100
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
A shop is selling candies at a discount. For every two candies sold, the shop gives a third candy for free.
The customer can choose any candy to take away for free as long as the cost of the chosen candy is less than or equal to the minimum cost of the two candies bought.
For example, if there are 4 candies with costs 1, 2, 3, and 4, and the customer buys candies with costs 2 and 3, they can take the candy with cost 1 for free, but not the candy with cost 4.
Given a 0-indexed integer array cost, where cost[i] denotes the cost of the ith candy, return the minimum cost of buying all the candies.
Please complete the following python code precisely:
```python
class Solution:
def minimumCost(self, cost: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(cost = [1,2,3]) == 5\n assert candidate(cost = [6,5,7,9,2,2]) == 23\n assert candidate(cost = [5,5]) == 10\n\n\ncheck(Solution().minimumCost)"}
| 198
| 73
|
coding
|
Solve the programming task below in a Python markdown code block.
Problem statement
AOR Ika-chan is in a bad mood lately. Apparently, I don't like the ratio of the number of followers to the number of followers of "Ikatta". Currently, AOR Ika-chan has $ A $ followers, $ B $ followers, and a ratio of $ A: B $.
Therefore, AOR Ika decided to increase or decrease the number of followers so that the ratio of the number of followers to the number of followers would be an integer ratio that she liked. The integer ratio I like is a ratio that can be expressed so that both values included in the ratio are integers of $ 1 $ or more and $ N $ or less.
However, AOR Ika doesn't want to change the number of followers as much as possible, so I want to make the absolute value of the difference from before the change as small as possible. Create a program that asks at least how many followers you need to change to make AOR Ika feel good.
Input constraints
$ 1 \ le A, \ B \ le 10 ^ {12} $
$ 1 \ leq N \ leq 100 $
sample
Sample input 1
19 30 3
Sample output 1
1
Sample input 2
3 7 7
Sample output 2
0
Sample input 3
3 7 1
Sample output 3
Four
Sample input 4
102 30 3
Sample output 4
12
By reducing the number of followers by $ 12 $, it becomes $ 90: 30 \ (= 3: 1) $, and the higher ratio number is $ 3 $ or less.
At this time, the amount of change is $ 12 $.
Sample input 5
3 4 2
Sample output 5
1
If you unfollow one person, it will be $ 2: 4 \ (= 1: 2) $, and if you follow it, it will be $ 4: 4 \ (= 1: 1) $. In both cases, the absolute value of increase / decrease is $ 1 $, which is the answer.
Sample input 6
1 100 2
Sample output 6
49
Please note that at least $ 1 $ people must be following.
input
$ A \ B \ N $
output
Output the minimum absolute value of the amount of change in $ A $, which can be an integer ratio you like.
Example
Input
19 30 3
Output
1
|
{"inputs": ["7 4 3", "30 7 1", "37 7 1", "35 7 1", "35 1 1", "7 26 3", "35 2 1", "19 2 2"], "outputs": ["1\n", "23\n", "30\n", "28\n", "34\n", "6\n", "33\n", "15\n"]}
| 571
| 107
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given a string s, return the maximum number of occurrences of any substring under the following rules:
The number of unique characters in the substring must be less than or equal to maxLetters.
The substring size must be between minSize and maxSize inclusive.
Please complete the following python code precisely:
```python
class Solution:
def maxFreq(self, s: str, maxLetters: int, minSize: int, maxSize: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"aababcaab\", maxLetters = 2, minSize = 3, maxSize = 4) == 2\n assert candidate(s = \"aaaa\", maxLetters = 1, minSize = 3, maxSize = 3) == 2\n assert candidate(s = \"aabcabcab\", maxLetters = 2, minSize = 2, maxSize = 3) == 3\n assert candidate(s = \"abcde\", maxLetters = 2, minSize = 3, maxSize = 3) == 0\n\n\ncheck(Solution().maxFreq)"}
| 110
| 142
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese, Russian and Vietnamese as well.
Chef has a number D containing only digits 0's and 1's. He wants to make the number to have all the digits same. For that, he will change exactly one digit, i.e. from 0 to 1 or from 1 to 0. If it is possible to make all digits equal (either all 0's or all 1's) by flipping exactly 1 digit then output "Yes", else print "No" (quotes for clarity)
------ Input ------
The first line will contain an integer T representing the number of test cases.
Each test case contain a number made of only digits 1's and 0's on newline
------ Output ------
Print T lines with a "Yes" or a "No", depending on whether its possible to make it all 0s or 1s or not.
------ Constraints ------
Subtask #1: (40 points)
$1 ≤ T ≤ 50$
$1 ≤ Length of the number D ≤ 50$
Subtask #2: (60 points)
$1 ≤ T ≤ 10$
$1 ≤ Length of the number D ≤ 10^{5}$
----- Sample Input 1 ------
2
101
11
----- Sample Output 1 ------
Yes
No
----- explanation 1 ------
Example case 1. In 101, the 0 can be flipped to make it all 1..
Example case 2. No matter whichever digit you flip, you will not get the desired string.
|
{"inputs": ["2\n101\n11"], "outputs": ["Yes\nNo"]}
| 351
| 21
|
coding
|
Solve the programming task below in a Python markdown code block.
We have a tree with N vertices. The i-th edge connects Vertex A_i and B_i bidirectionally.
Takahashi is standing at Vertex u, and Aoki is standing at Vertex v.
Now, they will play a game of tag as follows:
- 1. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Takahashi moves to a vertex of his choice that is adjacent to his current vertex.
- 2. If Takahashi and Aoki are standing at the same vertex, the game ends. Otherwise, Aoki moves to a vertex of his choice that is adjacent to his current vertex.
- 3. Go back to step 1.
Takahashi performs his moves so that the game ends as late as possible, while Aoki performs his moves so that the game ends as early as possible.
Find the number of moves Aoki will perform before the end of the game if both Takahashi and Aoki know each other's position and strategy.
It can be proved that the game is bound to end.
-----Constraints-----
- 2 \leq N \leq 10^5
- 1 \leq u,v \leq N
- u \neq v
- 1 \leq A_i,B_i \leq N
- The given graph is a tree.
-----Input-----
Input is given from Standard Input in the following format:
N u v
A_1 B_1
:
A_{N-1} B_{N-1}
-----Output-----
Print the number of moves Aoki will perform before the end of the game.
-----Sample Input-----
5 4 1
1 2
2 3
3 4
3 5
-----Sample Output-----
2
If both players play optimally, the game will progress as follows:
- Takahashi moves to Vertex 3.
- Aoki moves to Vertex 2.
- Takahashi moves to Vertex 5.
- Aoki moves to Vertex 3.
- Takahashi moves to Vertex 3.
Here, Aoki performs two moves.
Note that, in each move, it is prohibited to stay at the current vertex.
|
{"inputs": ["2 1 2\n1 2", "2 1 2\n1 2\n", "5 4 5\n1 2\n1 3\n2 4\n1 5", "5 4 1\n1 2\n1 3\n3 4\n3 5", "5 4 1\n1 2\n2 3\n1 4\n3 5", "5 4 5\n1 2\n1 5\n2 4\n1 5", "5 4 5\n2 2\n1 3\n1 4\n1 5", "5 5 1\n1 2\n2 3\n1 4\n3 5"], "outputs": ["0", "0\n", "2\n", "1\n", "0\n", "2\n", "1\n", "2\n"]}
| 473
| 198
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given four integers $n$, $B$, $x$ and $y$. You should build a sequence $a_0, a_1, a_2, \dots, a_n$ where $a_0 = 0$ and for each $i \ge 1$ you can choose:
either $a_i = a_{i - 1} + x$
or $a_i = a_{i - 1} - y$.
Your goal is to build such a sequence $a$ that $a_i \le B$ for all $i$ and $\sum\limits_{i=0}^{n}{a_i}$ is maximum possible.
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of test cases. Next $t$ cases follow.
The first and only line of each test case contains four integers $n$, $B$, $x$ and $y$ ($1 \le n \le 2 \cdot 10^5$; $1 \le B, x, y \le 10^9$).
It's guaranteed that the total sum of $n$ doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each test case, print one integer — the maximum possible $\sum\limits_{i=0}^{n}{a_i}$.
-----Examples-----
Input
3
5 100 1 30
7 1000000000 1000000000 1000000000
4 1 7 3
Output
15
4000000000
-10
-----Note-----
In the first test case, the optimal sequence $a$ is $[0, 1, 2, 3, 4, 5]$.
In the second test case, the optimal sequence $a$ is $[0, 10^9, 0, 10^9, 0, 10^9, 0, 10^9]$.
In the third test case, the optimal sequence $a$ is $[0, -3, -6, 1, -2]$.
|
{"inputs": ["1\n200000 1 1 1\n", "1\n200000 9 9 9\n", "1\n200000 8 8 8\n", "1\n200000 7 7 7\n", "1\n200000 10 10 10\n", "1\n1000 100 200 300\n", "1\n2000 100 200 300\n", "1\n3000 100 200 300\n"], "outputs": ["100000\n", "900000\n", "800000\n", "700000\n", "1000000\n", "-100000\n", "-200000\n", "-300000\n"]}
| 509
| 230
|
coding
|
Solve the programming task below in a Python markdown code block.
Gorodetskiy is a university student. He is really good at math and really likes solving engaging math problems. In the last exam, his professor gave him really hard math problems to solve, but Gorodetskiy could not solve them and failed the exam, so the professor told him: "These problems are a piece of cake, you should know them from school!" Here is one of the problems from the exam - you can decide if it really was an easy problem or not.
You are given a positive integer $M$. Let's call a positive integer $A$ an interesting number if there is at least one integer $B$ ($A \le B$) such that $A \cdot B$ is divisible by $M$ and $\frac{A \cdot B}{M} = A+B$.
Find all interesting numbers. Let's denote the number of such integers by $K$; it is guaranteed that $K \le 3*10^5$.
-----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 and only line of each test case contains a single integer $M$.
-----Output-----
For each test case:
- First, print a line containing a single integer $K$.
- Then, print $K$ lines. For each valid $i$, the $i$-th of these lines should contain a single integer ― the $i$-th interesting number in increasing order.
-----Constraints-----
- $1 \le T \le 10$
- $1 \le M \le 10^{14}$
-----Subtasks-----
Subtask #1 (20 points): $1 \le M \le 100$
Subtask #2 (20 points): $1 \le M \le 10^7$
Subtask #3 (60 points): original constraints
-----Example Input-----
2
3
6
-----Example Output-----
2
4
6
5
7
8
9
10
12
-----Explanation-----
Example case 1: There are two interesting numbers, $4$ and $6$. For $A = 4$, we can choose $B = 12$ and for $A = 6$, we can choose $B = 6$.
|
{"inputs": ["2\n3\n6"], "outputs": ["2\n4\n6\n5\n7\n8\n9\n10\n12"]}
| 513
| 34
|
coding
|
Solve the programming task below in a Python markdown code block.
Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the size of downloaded data per second.
The guys want to watch the whole video without any pauses, so they have to wait some integer number of seconds for a part of the video to download. After this number of seconds passes, they can start watching. Waiting for the whole video to download isn't necessary as the video can download after the guys started to watch.
Let's suppose that video's length is c seconds and Valeric and Valerko wait t seconds before the watching. Then for any moment of time t0, t ≤ t0 ≤ c + t, the following condition must fulfill: the size of data received in t0 seconds is not less than the size of data needed to watch t0 - t seconds of the video.
Of course, the guys want to wait as little as possible, so your task is to find the minimum integer number of seconds to wait before turning the video on. The guys must watch the video without pauses.
Input
The first line contains three space-separated integers a, b and c (1 ≤ a, b, c ≤ 1000, a > b). The first number (a) denotes the size of data needed to watch one second of the video. The second number (b) denotes the size of data Valeric and Valerko can download from the Net per second. The third number (c) denotes the video's length in seconds.
Output
Print a single number — the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses.
Examples
Input
4 1 1
Output
3
Input
10 3 2
Output
5
Input
13 12 1
Output
1
Note
In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 · 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watching video 1 second, one unit of data will be downloaded and Valerik and Valerko will have 4 units of data by the end of watching. Also every moment till the end of video guys will have more data then necessary for watching.
In the second sample guys need 2 · 10 = 20 units of data, so they have to wait 5 seconds and after that they will have 20 units before the second second ends. However, if guys wait 4 seconds, they will be able to watch first second of video without pauses, but they will download 18 units of data by the end of second second and it is less then necessary.
|
{"inputs": ["2 1 4\n", "2 1 2\n", "5 2 1\n", "2 1 1\n", "6 2 4\n", "2 1 3\n", "5 1 5\n", "6 1 4\n"], "outputs": ["4\n", "2\n", "2\n", "1\n", "8\n", "3\n", "20\n", "20\n"]}
| 659
| 104
|
coding
|
Solve the programming task below in a Python markdown code block.
Lunar New Year is approaching, and Bob is struggling with his homework – a number division problem.
There are $n$ positive integers $a_1, a_2, \ldots, a_n$ on Bob's homework paper, where $n$ is always an even number. Bob is asked to divide those numbers into groups, where each group must contain at least $2$ numbers. Suppose the numbers are divided into $m$ groups, and the sum of the numbers in the $j$-th group is $s_j$. Bob's aim is to minimize the sum of the square of $s_j$, that is $$\sum_{j = 1}^{m} s_j^2.$$
Bob is puzzled by this hard problem. Could you please help him solve it?
-----Input-----
The first line contains an even integer $n$ ($2 \leq n \leq 3 \cdot 10^5$), denoting that there are $n$ integers on Bob's homework paper.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^4$), describing the numbers you need to deal with.
-----Output-----
A single line containing one integer, denoting the minimum of the sum of the square of $s_j$, which is $$\sum_{i = j}^{m} s_j^2,$$ where $m$ is the number of groups.
-----Examples-----
Input
4
8 5 2 3
Output
164
Input
6
1 1 1 2 2 2
Output
27
-----Note-----
In the first sample, one of the optimal solutions is to divide those $4$ numbers into $2$ groups $\{2, 8\}, \{5, 3\}$. Thus the answer is $(2 + 8)^2 + (5 + 3)^2 = 164$.
In the second sample, one of the optimal solutions is to divide those $6$ numbers into $3$ groups $\{1, 2\}, \{1, 2\}, \{1, 2\}$. Thus the answer is $(1 + 2)^2 + (1 + 2)^2 + (1 + 2)^2 = 27$.
|
{"inputs": ["2\n1 1\n", "2\n1 1\n", "2\n2 1\n", "2\n2 0\n", "2\n0 0\n", "2\n669 34\n", "2\n669 52\n", "4\n8 5 2 3\n"], "outputs": ["4\n", "4\n", "9\n", "4\n", "0\n", "494209\n", "519841\n", "164\n"]}
| 519
| 124
|
coding
|
Solve the programming task below in a Python markdown code block.
The average miner Vaganych took refresher courses. As soon as a miner completes the courses, he should take exams. The hardest one is a computer test called "Testing Pants for Sadness".
The test consists of n questions; the questions are to be answered strictly in the order in which they are given, from question 1 to question n. Question i contains ai answer variants, exactly one of them is correct.
A click is regarded as selecting any answer in any question. The goal is to select the correct answer for each of the n questions. If Vaganych selects a wrong answer for some question, then all selected answers become unselected and the test starts from the very beginning, from question 1 again. But Vaganych remembers everything. The order of answers for each question and the order of questions remain unchanged, as well as the question and answers themselves.
Vaganych is very smart and his memory is superb, yet he is unbelievably unlucky and knows nothing whatsoever about the test's theme. How many clicks will he have to perform in the worst case?
Input
The first line contains a positive integer n (1 ≤ n ≤ 100). It is the number of questions in the test. The second line contains space-separated n positive integers ai (1 ≤ ai ≤ 109), the number of answer variants to question i.
Output
Print a single number — the minimal number of clicks needed to pass the test it the worst-case scenario.
Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specificator.
Examples
Input
2
1 1
Output
2
Input
2
2 2
Output
5
Input
1
10
Output
10
Note
Note to the second sample. In the worst-case scenario you will need five clicks:
* the first click selects the first variant to the first question, this answer turns out to be wrong.
* the second click selects the second variant to the first question, it proves correct and we move on to the second question;
* the third click selects the first variant to the second question, it is wrong and we go back to question 1;
* the fourth click selects the second variant to the first question, it proves as correct as it was and we move on to the second question;
* the fifth click selects the second variant to the second question, it proves correct, the test is finished.
|
{"inputs": ["1\n2\n", "1\n3\n", "1\n10\n", "2\n2 1\n", "2\n2 3\n", "2\n1 2\n", "2\n1 1\n", "2\n2 2\n"], "outputs": ["2\n", "3\n", "10\n", "3\n", "7\n", "4\n", "2\n", "5\n"]}
| 545
| 98
|
coding
|
Solve the programming task below in a Python markdown code block.
A participant can make 1 submission every 30 seconds. If a contest lasts for X minutes, what is the maximum number of submissions that the participant can make during it?
It is also given that the participant cannot make any submission in the last 5 seconds of the contest.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a single integer X, denoting the number of minutes.
------ Output Format ------
For each test case, output the maximum number of submissions a participant can make in X minutes.
------ Constraints ------
$1 ≤ T ≤ 30$
$1 ≤ X ≤ 30$
----- Sample Input 1 ------
4
1
2
3
4
----- Sample Output 1 ------
2
4
6
8
----- explanation 1 ------
Test case $1$: The contest lasts for $1$ minute, which is $60$ seconds. A participant can make $2$ submissions during this time — for example, in the $5$-th second and in the $48$-th second. Making $3$ or more submissions is impossible.
Test case $2$: The contest lasts for $2$ minutes, which is $120$ seconds. A participant can make $4$ submissions during this time.
|
{"inputs": ["4\n1\n2\n3\n4\n"], "outputs": ["2\n4\n6\n8\n"]}
| 299
| 28
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given two integer sequences S and T of length N and M, respectively, both consisting of integers between 1 and 10^5 (inclusive).
In how many pairs of a subsequence of S and a subsequence of T do the two subsequences are the same in content?
Here the subsequence of A is a sequence obtained by removing zero or more elements from A and concatenating the remaining elements without changing the order.
For both S and T, we distinguish two subsequences if the sets of the indices of the removed elements are different, even if the subsequences are the same in content.
Since the answer can be tremendous, print the number modulo 10^9+7.
-----Constraints-----
- 1 \leq N, M \leq 2 \times 10^3
- The length of S is N.
- The length of T is M.
- 1 \leq S_i, T_i \leq 10^5
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
N M
S_1 S_2 ... S_{N-1} S_{N}
T_1 T_2 ... T_{M-1} T_{M}
-----Output-----
Print the number of pairs of a subsequence of S and a subsequence of T such that the subsequences are the same in content, modulo 10^9+7.
-----Sample Input-----
2 2
1 3
3 1
-----Sample Output-----
3
S has four subsequences: (), (1), (3), (1, 3).
T has four subsequences: (), (3), (1), (3, 1).
There are 1 \times 1 pair of subsequences in which the subsequences are both (), 1 \times 1 pair of subsequences in which the subsequences are both (1), and 1 \times 1 pair of subsequences in which the subsequences are both (3), for a total of three pairs.
|
{"inputs": ["2 2\n1 6\n3 1", "2 2\n2 6\n3 1", "2 2\n1 1\n1 1", "2 2\n1 3\n3 1", "2 2\n1 3\n3 1\n", "2 2\n1 1\n1 1\n", "4 4\n0 4 5 6\n3 4 5 6", "4 4\n0 4 5 6\n3 4 5 0"], "outputs": ["2\n", "1\n", "6", "3", "3\n", "6\n", "8\n", "5\n"]}
| 445
| 158
|
coding
|
Solve the programming task below in a Python markdown code block.
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.
Petya can ask questions like: "Is the unknown number divisible by number y?".
The game is played by the following rules: first Petya asks all the questions that interest him (also, he can ask no questions), and then Vasya responds to each question with a 'yes' or a 'no'. After receiving all the answers Petya should determine the number that Vasya thought of.
Unfortunately, Petya is not familiar with the number theory. Help him find the minimum number of questions he should ask to make a guaranteed guess of Vasya's number, and the numbers y_{i}, he should ask the questions about.
-----Input-----
A single line contains number n (1 ≤ n ≤ 10^3).
-----Output-----
Print the length of the sequence of questions k (0 ≤ k ≤ n), followed by k numbers — the questions y_{i} (1 ≤ y_{i} ≤ n).
If there are several correct sequences of questions of the minimum length, you are allowed to print any of them.
-----Examples-----
Input
4
Output
3
2 4 3
Input
6
Output
4
2 4 3 5
-----Note-----
The sequence from the answer to the first sample test is actually correct.
If the unknown number is not divisible by one of the sequence numbers, it is equal to 1.
If the unknown number is divisible by 4, it is 4.
If the unknown number is divisible by 3, then the unknown number is 3.
Otherwise, it is equal to 2. Therefore, the sequence of questions allows you to guess the unknown number. It can be shown that there is no correct sequence of questions of length 2 or shorter.
|
{"inputs": ["4\n", "6\n", "1\n", "1\n", "2\n", "3\n", "5\n", "8\n"], "outputs": ["3\n2 4 3 \n", "4\n2 4 3 5 \n", "0\n\n", "0\n", "1\n2 ", "2\n2 3 ", "4\n2 4 3 5 ", "6\n2 4 8 3 5 7 "]}
| 413
| 110
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a string s of length n containing only four kinds of characters: 'Q', 'W', 'E', and 'R'.
A string is said to be balanced if each of its characters appears n / 4 times where n is the length of the string.
Return the minimum length of the substring that can be replaced with any other string of the same length to make s balanced. If s is already balanced, return 0.
Please complete the following python code precisely:
```python
class Solution:
def balancedString(self, s: str) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(s = \"QWER\") == 0\n assert candidate(s = \"QQWE\") == 1\n assert candidate(s = \"QQQW\") == 2\n assert candidate(s = \"QQQQ\") == 3\n\n\ncheck(Solution().balancedString)"}
| 137
| 72
|
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 of length n, and an integer array queries of length m.
Return an array answer of length m where answer[i] is the maximum size of a subsequence that you can take from nums such that the sum of its elements is less than or equal to queries[i].
A subsequence is an array that can be derived from another array by deleting some or no elements without changing the order of the remaining elements.
Please complete the following python code precisely:
```python
class Solution:
def answerQueries(self, nums: List[int], queries: List[int]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [4,5,2,1], queries = [3,10,21]) == [2,3,4]\n assert candidate(nums = [2,3,4,5], queries = [1]) == [0]\n\n\ncheck(Solution().answerQueries)"}
| 143
| 77
|
coding
|
Solve the programming task below in a Python markdown code block.
A problem setter is called an *expert* if at least 50 \% of their problems are approved by Chef.
Munchy submitted X problems for approval. If Y problems out of those were approved, find whether Munchy is an *expert* or not.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of a two space-separated integers X and Y - the number of problems submitted and the number of problems that were approved by Chef.
------ Output Format ------
For each test case, output on a new line YES, if Munchy is an *expert*. Otherwise, print NO.
The output is case-insensitive. Thus, the strings YES, yes, yeS, and Yes are all considered the same.
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ Y ≤X ≤ 10^{6}$
----- Sample Input 1 ------
4
5 3
1 1
4 1
2 1
----- Sample Output 1 ------
YES
YES
NO
YES
----- explanation 1 ------
Test case $1$: We are given that $3$ out of $5$ problems were approved. Thus, $60 \%$ of the problems were approved. Since at least $50 \%$ of the problems were approved, Munchy is an *expert*.
Test case $2$: We are given that $1$ out of $1$ problems were approved. Thus, $100 \%$ of the problems were approved. Since at least $50 \%$ of the problems were approved, Munchy is an *expert*.
Test case $3$: We are given that $1$ out of $4$ problems were approved. Thus, $25 \%$ of the problems were approved. Since at least $50 \%$ of the problems were not approved, Munchy is not an *expert*.
Test case $4$: We are given that $1$ out of $2$ problems were approved. Thus, $50 \%$ of the problems were approved. Since at least $50 \%$ of the problems were approved, Munchy is an *expert*.
|
{"inputs": ["4\n5 3\n1 1\n4 1\n2 1\n"], "outputs": ["YES\nYES\nNO\nYES"]}
| 487
| 35
|
coding
|
Solve the programming task below in a Python markdown code block.
DZY has a sequence a, consisting of n integers.
We'll call a sequence a_{i}, a_{i} + 1, ..., a_{j} (1 ≤ i ≤ j ≤ n) a subsegment of the sequence a. The value (j - i + 1) denotes the length of the subsegment.
Your task is to find the longest subsegment of a, such that it is possible to change at most one number (change one number to any integer you want) from the subsegment to make the subsegment strictly increasing.
You only need to output the length of the subsegment you find.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 10^5). The next line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9).
-----Output-----
In a single line print the answer to the problem — the maximum length of the required subsegment.
-----Examples-----
Input
6
7 2 3 1 5 6
Output
5
-----Note-----
You can choose subsegment a_2, a_3, a_4, a_5, a_6 and change its 3rd element (that is a_4) to 4.
|
{"inputs": ["1\n1\n", "1\n3\n", "1\n1\n", "1\n3\n", "1\n2\n", "1\n5\n", "1\n4\n", "1\n42\n"], "outputs": ["1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n", "1\n"]}
| 287
| 87
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Alice had a 0-indexed array arr consisting of n positive integers. She chose an arbitrary positive integer k and created two new 0-indexed integer arrays lower and higher in the following manner:
lower[i] = arr[i] - k, for every index i where 0 <= i < n
higher[i] = arr[i] + k, for every index i where 0 <= i < n
Unfortunately, Alice lost all three arrays. However, she remembers the integers that were present in the arrays lower and higher, but not the array each integer belonged to. Help Alice and recover the original array.
Given an array nums consisting of 2n integers, where exactly n of the integers were present in lower and the remaining in higher, return the original array arr. In case the answer is not unique, return any valid array.
Note: The test cases are generated such that there exists at least one valid array arr.
Please complete the following python code precisely:
```python
class Solution:
def recoverArray(self, nums: List[int]) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [2,10,6,4,8,12]) == [3,7,11]\n assert candidate(nums = [1,1,3,3]) == [2,2]\n assert candidate(nums = [5,435]) == [220]\n\n\ncheck(Solution().recoverArray)"}
| 238
| 89
|
coding
|
Solve the programming task below in a Python markdown code block.
Pari wants to buy an expensive chocolate from Arya. She has n coins, the value of the i-th coin is c_{i}. The price of the chocolate is k, so Pari will take a subset of her coins with sum equal to k and give it to Arya.
Looking at her coins, a question came to her mind: after giving the coins to Arya, what values does Arya can make with them? She is jealous and she doesn't want Arya to make a lot of values. So she wants to know all the values x, such that Arya will be able to make x using some subset of coins with the sum k.
Formally, Pari wants to know the values x such that there exists a subset of coins with the sum k such that some subset of this subset has the sum x, i.e. there is exists some way to pay for the chocolate, such that Arya will be able to make the sum x using these coins.
-----Input-----
The first line contains two integers n and k (1 ≤ n, k ≤ 500) — the number of coins and the price of the chocolate, respectively.
Next line will contain n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 500) — the values of Pari's coins.
It's guaranteed that one can make value k using these coins.
-----Output-----
First line of the output must contain a single integer q— the number of suitable values x. Then print q integers in ascending order — the values that Arya can make for some subset of coins of Pari that pays for the chocolate.
-----Examples-----
Input
6 18
5 6 1 10 12 2
Output
16
0 1 2 3 5 6 7 8 10 11 12 13 15 16 17 18
Input
3 50
25 25 50
Output
3
0 25 50
|
{"inputs": ["1 79\n79\n", "1 79\n79\n", "1 114\n114\n", "1 114\n114\n", "3 50\n25 25 50\n", "3 50\n25 25 50\n", "5 6\n2 71 7 27 6\n", "5 6\n2 71 7 27 6\n"], "outputs": ["2\n0 79 \n", "2\n0 79 ", "2\n0 114 \n", "2\n0 114 ", "3\n0 25 50 \n", "3\n0 25 50 ", "2\n0 6 \n", "2\n0 6 "]}
| 460
| 197
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given the head of a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list. Return the linked list sorted as well.
Please complete the following python code precisely:
```python
# Definition for singly-linked list.
# class ListNode:
# def __init__(self, val=0, next=None):
# self.val = val
# self.next = next
class Solution:
def deleteDuplicates(self, head: Optional[ListNode]) -> Optional[ListNode]:
```
|
{"functional": "def check(candidate):\n assert is_same_list(candidate(head = list_node([1,2,3,3,4,4,5])), list_node([1,2,5]))\n assert is_same_list(candidate(head = list_node([1,1,1,2,3])), list_node([2,3]))\n\n\ncheck(Solution().deleteDuplicates)"}
| 125
| 85
|
coding
|
Solve the programming task below in a Python markdown code block.
.difference()
The tool .difference() returns a set with all the elements from the set that are not in an iterable.
Sometimes the - operator is used in place of the .difference() tool, but it only operates on the set of elements in set.
Set is immutable to the .difference() operation (or the - operation).
>>> s = set("Hacker")
>>> print s.difference("Rank")
set(['c', 'r', 'e', 'H'])
>>> print s.difference(set(['R', 'a', 'n', 'k']))
set(['c', 'r', 'e', 'H'])
>>> print s.difference(['R', 'a', 'n', 'k'])
set(['c', 'r', 'e', 'H'])
>>> print s.difference(enumerate(['R', 'a', 'n', 'k']))
set(['a', 'c', 'r', 'e', 'H', 'k'])
>>> print s.difference({"Rank":1})
set(['a', 'c', 'e', 'H', 'k', 'r'])
>>> s - set("Rank")
set(['H', 'c', 'r', 'e'])
Task
Students of District College have a subscription to English and French newspapers. Some students have subscribed to only the English newspaper, some have subscribed to only the French newspaper, and some have subscribed to both newspapers.
You are given two sets of student roll numbers. One set has subscribed to the English newspaper, and one set has subscribed to the French newspaper. Your task is to find the total number of students who have subscribed to only English newspapers.
Input Format
The first line contains the number of students who have subscribed to the English newspaper.
The second line contains the space separated list of student roll numbers who have subscribed to the English newspaper.
The third line contains the number of students who have subscribed to the French newspaper.
The fourth line contains the space separated list of student roll numbers who have subscribed to the French newspaper.
Constraints
$0<\textit{Total number of students in college}<1000$
Output Format
Output the total number of students who are subscribed to the English newspaper only.
Sample Input
9
1 2 3 4 5 6 7 8 9
9
10 1 2 3 11 21 55 6 8
Sample Output
4
Explanation
The roll numbers of students who only have English newspaper subscriptions are:
$4,5,7$ and $\mbox{9}$.
Hence, the total is $\begin{array}{c}4\end{array}$ students.
|
{"inputs": ["9\n1 2 3 4 5 6 7 8 9\n9\n10 1 2 3 11 21 55 6 8\n"], "outputs": ["4\n"]}
| 567
| 56
|
coding
|
Solve the programming task below in a Python markdown code block.
Simple transposition is a basic and simple cryptography technique. We make 2 rows and put first a letter in the Row 1, the second in the Row 2, third in Row 1 and so on until the end. Then we put the text from Row 2 next to the Row 1 text and thats it.
Complete the function that receives a string and encrypt it with this simple transposition.
## Example
For example if the text to encrypt is: `"Simple text"`, the 2 rows will be:
Row 1
S
m
l
e
t
Row 2
i
p
e
t
x
So the result string will be: `"Sml etipetx"`
Also feel free to reuse/extend the following starter code:
```python
def simple_transposition(text):
```
|
{"functional": "_inputs = [['Sample text'], ['Simple transposition'], ['All that glitters is not gold'], ['The better part of valor is discretion'], ['Conscience does make cowards of us all'], ['Imagination is more important than knowledge']]\n_outputs = [['Sml etapetx'], ['Sml rnpstoipetasoiin'], ['Alta ltesi o odl htgitr sntgl'], ['Tebte ato ao sdsrtoh etrpr fvlri icein'], ['Cncec osmk oad fu losinede aecwrso sal'], ['Iaiaini oeipratta nwegmgnto smr motn hnkolde']]\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(simple_transposition(*i), o[0])"}
| 186
| 294
|
coding
|
Solve the programming task below in a Python markdown code block.
Kefaa has developed a novel decomposition of a tree. He claims that this decomposition solves many difficult problems related to trees. However, he doesn't know how to find it quickly, so he asks you to help him.
You are given a tree with $N$ vertices numbered $1$ through $N$. Let's denote an edge between vertices $u$ and $v$ by $(u, v)$. The triple-tree decomposition is a partition of edges of the tree into unordered triples of edges $(a, b), (a, c), (a, d)$ such that $a \neq b \neq c \neq d$. Each edge must belong to exactly one triple.
Help Kefaa with this problem — find a triple-tree decomposition of the given tree or determine that no such decomposition exists.
-----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$.
- Each of the following $N-1$ lines contains two space-separated integers $u$ and $v$ describing an edge between vertices $u$ and $v$ of the tree.
-----Output-----
- For each test case, print a line containing the string "YES" if a triple-tree decomposition of the given tree exists or "NO" otherwise.
- If it exists, print $\frac{N-1}{3}$ more lines describing a decomposition.
- Each of these lines should contain four space-separated integers $a$, $b$, $c$ and $d$ describing a triple of edges $(a, b), (a, c), (a, d)$.
If more than one triple-tree decomposition exists, you may output any one.
-----Constraints-----
- $1 \le T \le 100$
- $2 \le N \le 2 \cdot 10^5$
- $1 \le u, v \le N$
- the sum of $N$ over all test cases does not exceed $2 \cdot 10^5$
-----Subtasks-----
Subtask #1 (20 points): $2 \le N \le 10$
Subtask #2 (30 points):$2 \le N \le 5000$ and the sum of $N$ overall testcases doesn't exceed $5000$
Subtask #3 (50 points): original constraints
-----Example Input-----
2
4
1 2
1 3
1 4
7
1 2
2 3
1 4
4 5
1 6
6 7
-----Example Output-----
YES
1 2 3 4
NO
|
{"inputs": ["2\n4\n1 2\n1 3\n1 4\n7\n1 2\n2 3\n1 4\n4 5\n1 6\n6 7"], "outputs": ["YES\n1 2 3 4\nNO"]}
| 593
| 62
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an array of integers citations where citations[i] is the number of citations a researcher received for their ith paper, return the researcher's h-index.
According to the definition of h-index on Wikipedia: The h-index is defined as the maximum value of h such that the given researcher has published at least h papers that have each been cited at least h times.
Please complete the following python code precisely:
```python
class Solution:
def hIndex(self, citations: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(citations = [3,0,6,1,5]) == 3 \n assert candidate(citations = [1,3,1]) == 1\n\n\ncheck(Solution().hIndex)"}
| 120
| 58
|
coding
|
Solve the programming task below in a Python markdown code block.
# Task
Suppose there are `n` people standing in a circle and they are numbered 1 through n in order.
Person 1 starts off with a sword and kills person 2. He then passes the sword to the next person still standing, in this case person 3. Person 3 then uses the sword to kill person 4, and passes it to person 5. This pattern continues around and around the circle until just one person remains.
What is the number of this person?
# Example:
For `n = 5`, the result should be `3`.
```
1 kills 2, passes to 3.
3 kills 4, passes to 5.
5 kills 1, passes to 3.
3 kills 5 and wins.```
# Input/Output
- `[input]` integer `n`
The number of people. 1 through n standing in a circle.
`1 <= n <= 1e9`
- `[output]` an integer
The index of the last person standing.
Also feel free to reuse/extend the following starter code:
```python
def circle_slash(n):
```
|
{"functional": "_inputs = [[5], [11], [1], [2], [3], [4], [8], [16], [15], [31]]\n_outputs = [[3], [7], [1], [1], [3], [1], [1], [1], [15], [31]]\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(circle_slash(*i), o[0])"}
| 256
| 215
|
coding
|
Solve the programming task below in a Python markdown code block.
Snuke has N integers. Among them, the smallest is A, and the largest is B. We are interested in the sum of those N integers. How many different possible sums there are?
Constraints
* 1 ≤ N,A,B ≤ 10^9
* A and B are integers.
Input
Input is given from Standard Input in the following format:
N A B
Output
Print the number of the different possible sums.
Examples
Input
4 4 6
Output
5
Input
5 4 3
Output
0
Input
1 7 10
Output
0
Input
1 3 3
Output
1
|
{"inputs": ["5 5 3", "1 7 7", "4 4 8", "5 4 6", "7 1 2", "5 4 8", "3 0 2", "7 1 4"], "outputs": ["0\n", "1\n", "9\n", "7\n", "6\n", "13\n", "3\n", "16\n"]}
| 154
| 96
|
coding
|
Solve the programming task below in a Python markdown code block.
Watson gives Sherlock two integers, $n$ and $\boldsymbol{\mbox{k}}$, and asks him to count the number of positive integer $\boldsymbol{i}$'s such that:
$i\cdot(n-i)\leq n\cdot k,\ \text{and}\ i<n$
Given $\textit{q}$ queries where each query consists of some $n$ and $\boldsymbol{\mbox{k}}$, print the number of possible $\boldsymbol{i}$'s for each query on a new line.
Input Format
The first line contains an integer, $\textit{q}$, denoting the number of times Watson queries Sherlock.
Each of the $\textit{q}$ subsequent lines contains two space-separated integers denoting the respective values of $n$ and $\boldsymbol{\mbox{k}}$ for a query.
Constraints
$1\leq q\leq10^5$
$1\leq n,k\leq10^9$
Output Format
For each query, print the number of $\boldsymbol{i}$'s satisfying the given formula on a new line.
Sample Input
2
5 1
5 2
Sample Output
2
4
Explanation
Sherlock performs the following $q=2$ queries:
The possible values of $\boldsymbol{i}$ satisfying Watson's formula for $n=5$ and $k=1$ are $\mbox{1}$ and $\begin{array}{c}4\end{array}$. Because there are two such values, we print $2$ on a new line.
The possible values of $\boldsymbol{i}$ satisfying Watson's formula for $n=5$ and $k=2$ are $\mbox{I}$, $2$, $3$, and $\begin{array}{c}4\end{array}$. Because there are four such values, we print $\begin{array}{c}4\end{array}$ on a new line.
|
{"inputs": ["2\n5 1\n5 2\n"], "outputs": ["2\n4\n"]}
| 428
| 24
|
coding
|
Solve the programming task below in a Python markdown code block.
An element in an array is dominant if it is greater than all elements to its right. You will be given an array and your task will be to return a list of all dominant elements. For example:
```Haskell
solve([1,21,4,7,5]) = [21,7,5] because 21, 7 and 5 are greater than elments to their right.
solve([5,4,3,2,1]) = [5,4,3,2,1]
Notice that the last element is always included.
```
More examples in the test cases.
Good luck!
Also feel free to reuse/extend the following starter code:
```python
def solve(arr):
```
|
{"functional": "_inputs = [[[16, 17, 14, 3, 14, 5, 2]], [[92, 52, 93, 31, 89, 87, 77, 105]], [[75, 47, 42, 56, 13, 55]], [[67, 54, 27, 85, 66, 88, 31, 24, 49]], [[76, 17, 25, 36, 29]], [[104, 18, 37, 9, 36, 47, 28]]]\n_outputs = [[[17, 14, 5, 2]], [[105]], [[75, 56, 55]], [[88, 49]], [[76, 36, 29]], [[104, 47, 28]]]\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])"}
| 165
| 378
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given an integer sequence of length n, a_1, ..., a_n.
Let us consider performing the following n operations on an empty sequence b.
The i-th operation is as follows:
- Append a_i to the end of b.
- Reverse the order of the elements in b.
Find the sequence b obtained after these n operations.
-----Constraints-----
- 1 \leq n \leq 2\times 10^5
- 0 \leq a_i \leq 10^9
- n and a_i are integers.
-----Input-----
Input is given from Standard Input in the following format:
n
a_1 a_2 ... a_n
-----Output-----
Print n integers in a line with spaces in between.
The i-th integer should be b_i.
-----Sample Input-----
4
1 2 3 4
-----Sample Output-----
4 2 1 3
- After step 1 of the first operation, b becomes: 1.
- After step 2 of the first operation, b becomes: 1.
- After step 1 of the second operation, b becomes: 1, 2.
- After step 2 of the second operation, b becomes: 2, 1.
- After step 1 of the third operation, b becomes: 2, 1, 3.
- After step 2 of the third operation, b becomes: 3, 1, 2.
- After step 1 of the fourth operation, b becomes: 3, 1, 2, 4.
- After step 2 of the fourth operation, b becomes: 4, 2, 1, 3.
Thus, the answer is 4 2 1 3.
|
{"inputs": ["3\n1 2 3\n", "4\n1 2 3 4\n", "1\n1000000000\n", "6\n0 6 7 6 7 0\n"], "outputs": ["3 1 2\n", "4 2 1 3\n", "1000000000\n", "0 6 6 0 7 7\n"]}
| 384
| 104
|
coding
|
Solve the programming task below in a Python markdown code block.
There are $n$ block towers, numbered from $1$ to $n$. The $i$-th tower consists of $a_i$ blocks.
In one move, you can move one block from tower $i$ to tower $j$, but only if $a_i > a_j$. That move increases $a_j$ by $1$ and decreases $a_i$ by $1$. You can perform as many moves as you would like (possibly, zero).
What's the largest amount of blocks you can have on the tower $1$ after the moves?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases.
The first line of each testcase contains a single integer $n$ ($2 \le n \le 2 \cdot 10^5$) — the number of towers.
The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the number of blocks on each tower.
The sum of $n$ over all testcases doesn't exceed $2 \cdot 10^5$.
-----Output-----
For each testcase, print the largest amount of blocks you can have on the tower $1$ after you make any number of moves (possibly, zero).
-----Examples-----
Input
4
3
1 2 3
3
1 2 2
2
1 1000000000
10
3 8 6 7 4 1 2 4 10 1
Output
3
2
500000001
9
-----Note-----
In the first testcase, you can move a block from tower $2$ to tower $1$, making the block counts $[2, 1, 3]$. Then move a block from tower $3$ to tower $1$, making the block counts $[3, 1, 2]$. Tower $1$ has $3$ blocks in it, and you can't obtain a larger amount.
In the second testcase, you can move a block from any of towers $2$ or $3$ to tower $1$, so that it has $2$ blocks in it.
In the third testcase, you can $500000000$ times move a block from tower $2$ to tower $1$. After that the block countes will be $[500000001, 500000000]$.
|
{"inputs": ["4\n3\n1 2 3\n3\n1 2 2\n2\n1 1000000000\n10\n3 8 6 7 4 1 2 4 10 1\n"], "outputs": ["3\n2\n500000001\n9\n"]}
| 575
| 83
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence.
You must write an algorithm that runs in O(n) time.
Please complete the following python code precisely:
```python
class Solution:
def longestConsecutive(self, nums: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [100,4,200,1,3,2]) == 4\n assert candidate(nums = [0,3,7,2,5,8,4,6,0,1]) == 9\n\n\ncheck(Solution().longestConsecutive)"}
| 83
| 77
|
coding
|
Solve the programming task below in a Python markdown code block.
Given a sequence of numbers, find the largest pair sum in the sequence.
For example
```
[10, 14, 2, 23, 19] --> 42 (= 23 + 19)
[99, 2, 2, 23, 19] --> 122 (= 99 + 23)
```
Input sequence contains minimum two elements and every element is an integer.
Also feel free to reuse/extend the following starter code:
```python
def largest_pair_sum(numbers):
```
|
{"functional": "_inputs = [[[10, 14, 2, 23, 19]], [[-100, -29, -24, -19, 19]], [[1, 2, 3, 4, 6, -1, 2]], [[-10, -8, -16, -18, -19]]]\n_outputs = [[42], [0], [10], [-18]]\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(largest_pair_sum(*i), o[0])"}
| 136
| 247
|
coding
|
Solve the programming task below in a Python markdown code block.
There are N children, numbered 1, 2, ..., N.
Snuke has decided to distribute x sweets among them. He needs to give out all the x sweets, but some of the children may get zero sweets.
For each i (1 \leq i \leq N), Child i will be happy if he/she gets exactly a_i sweets. Snuke is trying to maximize the number of happy children by optimally distributing the sweets. Find the maximum possible number of happy children.
Constraints
* All values in input are integers.
* 2 \leq N \leq 100
* 1 \leq x \leq 10^9
* 1 \leq a_i \leq 10^9
Input
Input is given from Standard Input in the following format:
N x
a_1 a_2 ... a_N
Output
Print the maximum possible number of happy children.
Examples
Input
3 70
20 30 10
Output
2
Input
3 10
20 30 10
Output
1
Input
4 1111
1 10 100 1000
Output
4
Input
2 10
20 20
Output
0
|
{"inputs": ["2 1\n30 1", "2 0\n30 20", "2 1\n30 20", "2 1\n30 26", "2 0\n30 26", "2 10\n20 2", "2 0\n30 17", "2 0\n20 26"], "outputs": ["1\n", "0\n", "0\n", "0\n", "0\n", "1\n", "0\n", "0\n"]}
| 296
| 125
|
coding
|
Solve the programming task below in a Python markdown code block.
There was a power value associated with each soldier of Ram’s troop. It was a known belief that if two soldiers could be paired such that their total power can be divided by 3 perfectly, the pairing becomes ultra-powerful. Ram was curious as to see how many such pairings were possible.
Help Ram find out the number of pairings(not necessarily unique) possible from his troop.
INPUT:
An integer T (1 ≤ T ≤ 1000) : number of testcases
Each test case is represented by a number N(1 ≤ N ≤ 100) denoting the number of soldiers followed by an unordered list of N values representing the soldier’s power P(1 ≤ P ≤ 10000).
OUTPUT:
For each test case T, output the value of number of possible pairs from the given list such that the sum of the values in each pair is a multiple of 3.
SAMPLE INPUT
3
5
3 6 7 2 9
4
2 1 3 4
3
9 9 9
SAMPLE OUTPUT
4
2
3
Explanation
In the first test case, the groups are (3,6),(3,9),(9,6),(7,2).
In the second test case, the groups are (2,1),(2,4)
In the third test case, the groups are (9,9),(9,9),(9,9))
|
{"inputs": ["5\n3\n1 2 3\n9\n2 3 4 5 11 3 5 6 4\n1\n2\n2 \n7 2\n3 \n9 9 9"], "outputs": ["1\n11\n0\n1\n3"]}
| 313
| 70
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer n representing n cities numbered from 1 to n. You are also given a 2D array roads, where roads[i] = [ai, bi, costi] indicates that there is a bidirectional road between cities ai and bi with a cost of traveling equal to costi.
You can buy apples in any city you want, but some cities have different costs to buy apples. You are given the 1-based array appleCost where appleCost[i] is the cost of buying one apple from city i.
You start at some city, traverse through various roads, and eventually buy exactly one apple from any city. After you buy that apple, you have to return back to the city you started at, but now the cost of all the roads will be multiplied by a given factor k.
Given the integer k, return a 1-based array answer of size n where answer[i] is the minimum total cost to buy an apple if you start at city i.
Please complete the following python code precisely:
```python
class Solution:
def minCost(self, n: int, roads: List[List[int]], appleCost: List[int], k: int) -> List[int]:
```
|
{"functional": "def check(candidate):\n assert candidate(n = 4, roads = [[1,2,4],[2,3,2],[2,4,5],[3,4,1],[1,3,4]], appleCost = [56,42,102,301], k = 2) == [54,42,48,51]\n assert candidate(n = 3, roads = [[1,2,5],[2,3,1],[3,1,2]], appleCost = [2,3,1], k = 3) == [2,3,1]\n\n\ncheck(Solution().minCost)"}
| 265
| 151
|
coding
|
Solve the programming task below in a Python markdown code block.
You have three tasks, all of which need to be completed.
First, you can complete any one task at cost 0.
Then, just after completing the i-th task, you can complete the j-th task at cost |A_j - A_i|.
Here, |x| denotes the absolute value of x.
Find the minimum total cost required to complete all the task.
-----Constraints-----
- All values in input are integers.
- 1 \leq A_1, A_2, A_3 \leq 100
-----Input-----
Input is given from Standard Input in the following format:
A_1 A_2 A_3
-----Output-----
Print the minimum total cost required to complete all the task.
-----Sample Input-----
1 6 3
-----Sample Output-----
5
When the tasks are completed in the following order, the total cost will be 5, which is the minimum:
- Complete the first task at cost 0.
- Complete the third task at cost 2.
- Complete the second task at cost 3.
|
{"inputs": ["3 5 2", "4 3 2", "4 3 0", "5 3 0", "0 1 6", "1 1 8", "0 1 8", "1 6 3"], "outputs": ["3\n", "2\n", "4\n", "5\n", "6\n", "7\n", "8\n", "5"]}
| 233
| 93
|
coding
|
Solve the programming task below in a Python markdown code block.
There are n points on a straight line, and the i-th point among them is located at x_{i}. All these coordinates are distinct.
Determine the number m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
-----Input-----
The first line contains a single integer n (3 ≤ n ≤ 100 000) — the number of points.
The second line contains a sequence of integers x_1, x_2, ..., x_{n} ( - 10^9 ≤ x_{i} ≤ 10^9) — the coordinates of the points. All these coordinates are distinct. The points can be given in an arbitrary order.
-----Output-----
Print a single integer m — the smallest number of points you should add on the line to make the distances between all neighboring points equal.
-----Examples-----
Input
3
-5 10 5
Output
1
Input
6
100 200 400 300 600 500
Output
0
Input
4
10 9 0 -1
Output
8
-----Note-----
In the first example you can add one point with coordinate 0.
In the second example the distances between all neighboring points are already equal, so you shouldn't add anything.
|
{"inputs": ["3\n1 4 7\n", "3\n1 4 6\n", "3\n1 2 6\n", "3\n1 3 6\n", "3\n1 4 7\n", "3\n1 3 6\n", "3\n1 4 6\n", "3\n1 2 6\n"], "outputs": ["0\n", "3\n", "3\n", "3\n", "0\n", "3\n", "3\n", "3\n"]}
| 301
| 118
|
coding
|
Solve the programming task below in a Python markdown code block.
One day Sasha visited the farmer 2D and his famous magnetic farm. On this farm, the crop grows due to the influence of a special magnetic field. Maintaining of the magnetic field is provided by $n$ machines, and the power of the $i$-th machine is $a_i$.
This year 2D decided to cultivate a new culture, but what exactly he didn't say. For the successful growth of the new culture, it is necessary to slightly change the powers of the machines. 2D can at most once choose an arbitrary integer $x$, then choose one machine and reduce the power of its machine by $x$ times, and at the same time increase the power of one another machine by $x$ times (powers of all the machines must stay positive integers). Note that he may not do that if he wants. More formally, 2D can choose two such indices $i$ and $j$, and one integer $x$ such that $x$ is a divisor of $a_i$, and change powers as following: $a_i = \frac{a_i}{x}$, $a_j = a_j \cdot x$
Sasha is very curious, that's why he wants to calculate the minimum total power the farmer can reach. There are too many machines, and Sasha can't cope with computations, help him!
-----Input-----
The first line contains one integer $n$ ($2 \le n \le 5 \cdot 10^4$) — the number of machines.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 100$) — the powers of the machines.
-----Output-----
Print one integer — minimum total power.
-----Examples-----
Input
5
1 2 3 4 5
Output
14
Input
4
4 2 4 4
Output
14
Input
5
2 4 2 3 7
Output
18
-----Note-----
In the first example, the farmer can reduce the power of the $4$-th machine by $2$ times, and increase the power of the $1$-st machine by $2$ times, then the powers will be: $[2, 2, 3, 2, 5]$.
In the second example, the farmer can reduce the power of the $3$-rd machine by $2$ times, and increase the power of the $2$-nd machine by $2$ times. At the same time, the farmer can leave is be as it is and the total power won't change.
In the third example, it is optimal to leave it be as it is.
|
{"inputs": ["2\n42 9\n", "2\n42 9\n", "2\n74 1\n", "2\n2 10\n", "2\n2 12\n", "2\n1 12\n", "2\n75 7\n", "2\n42 7\n"], "outputs": ["39\n", "39", "39\n", "9\n", "10\n", "7\n", "46\n", "35\n"]}
| 595
| 115
|
coding
|
Solve the programming task below in a Python markdown code block.
As the title suggests, this is the hard-core version of another neat kata.
The task is simple to explain: simply sum all the numbers from the first parameter being the beginning to the second parameter being the upper limit (possibly included), going in steps expressed by the third parameter:
```python
sequence_sum(2, 2, 2) # 2
sequence_sum(2, 6, 2) # 12 (= 2 + 4 + 6)
sequence_sum(1, 5, 1) # (= 1 + 2 + 3 + 4 + 5)
sequence_sum(1, 5, 3) # 5 (= 1 + 4)
```
If it is an impossible sequence (with the beginning being larger the end and a positive step or the other way around), just return `0`. See the provided test cases for further examples :)
**Note:** differing from the other base kata, much larger ranges are going to be tested, so you should hope to get your algo optimized and to avoid brute-forcing your way through the solution.
Also feel free to reuse/extend the following starter code:
```python
def sequence_sum(b, e, s):
```
|
{"functional": "_inputs = [[2, 6, 2], [1, 5, 1], [1, 5, 3], [-1, -5, -3], [16, 15, 3], [-24, -2, 22], [-2, 4, 658], [780, 6851543, 5], [9383, 71418, 2], [20, 673388797, 5]]\n_outputs = [[12], [15], [5], [-5], [0], [-26], [-2], [4694363402480], [1253127200], [45345247259849570]]\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(sequence_sum(*i), o[0])"}
| 267
| 338
|
coding
|
Solve the programming task below in a Python markdown code block.
Alice and Bob are playing a game on a sequence $a_1, a_2, \dots, a_n$ of length $n$. They move in turns and Alice moves first.
In the turn of each player, he or she should select an integer and remove it from the sequence. The game ends when there is no integer left in the sequence.
Alice wins if the sum of her selected integers is even; otherwise, Bob wins.
Your task is to determine who will win the game, if both players play optimally.
-----Input-----
Each test contains multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 100$) — the number of test cases. The following lines contain the description of each test case.
The first line of each test case contains an integer $n$ ($1 \leq n \leq 100$), indicating the length of the sequence.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($-10^9 \leq a_i \leq 10^9$), indicating the elements of the sequence.
-----Output-----
For each test case, output "Alice" (without quotes) if Alice wins and "Bob" (without quotes) otherwise.
-----Examples-----
Input
4
3
1 3 5
4
1 3 5 7
4
1 2 3 4
4
10 20 30 40
Output
Alice
Alice
Bob
Alice
-----Note-----
In the first and second test cases, Alice always selects two odd numbers, so the sum of her selected numbers is always even. Therefore, Alice always wins.
In the third test case, Bob has a winning strategy that he always selects a number with the same parity as Alice selects in her last turn. Therefore, Bob always wins.
In the fourth test case, Alice always selects two even numbers, so the sum of her selected numbers is always even. Therefore, Alice always wins.
|
{"inputs": ["4\n3\n1 3 5\n4\n1 3 5 7\n4\n1 2 3 4\n4\n10 20 30 40\n", "1\n100\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n"], "outputs": ["Alice\nAlice\nBob\nAlice\n", "Alice\n"]}
| 451
| 274
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an array of integers stones where stones[i] is the weight of the ith stone.
We are playing a game with the stones. On each turn, we choose any two stones and smash them together. Suppose the stones have weights x and y with x <= y. The result of this smash is:
If x == y, both stones are destroyed, and
If x != y, the stone of weight x is destroyed, and the stone of weight y has new weight y - x.
At the end of the game, there is at most one stone left.
Return the smallest possible weight of the left stone. If there are no stones left, return 0.
Please complete the following python code precisely:
```python
class Solution:
def lastStoneWeightII(self, stones: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(stones = [2,7,4,1,8,1]) == 1\n assert candidate(stones = [31,26,33,21,40]) == 5\n\n\ncheck(Solution().lastStoneWeightII)"}
| 187
| 70
|
coding
|
Solve the programming task below in a Python markdown code block.
It's year 2018 and it's Christmas time! Before going for vacations, students of Hogwarts School of Witchcraft and Wizardry had their end semester exams.
$N$ students attended the semester exam. Once the exam was over, their results were displayed as either "Pass" or "Fail" behind their magic jacket which they wore. A student cannot see his/her result but can see everyone else's results. Each of $N$ students count the number of passed students they can see.
Given the number of "Pass" verdicts that each of the $N$ students counted, we have to figure out conclusively, the number of students who failed, or report that there is some inconsistency or that we cannot be sure.
-----Input:-----
- First line will contain $T$, number of testcases. Then the testcases follow.
- The first line of each test case will contain $N$, representing the number of students who attended the exam.
- Next line contains $N$ spaced integers representing the number of "Pass" counted by each of the $N$ students.
-----Output:-----
- For each test case, output the answer in a single line.
- If the counts reported by the students are not consistent with each other or if it's not possible to predict the number of failed students from the given input, then print -1.
-----Constraints-----
- $1 \leq T \leq 50$
- $1 \leq N \leq 10^{5}$
- $0 \leq$ Count given by each Student $\leq 10^{5}$
-----Sample Input:-----
1
4
3 2 2 2
-----Sample Output:-----
1
-----EXPLANATION:-----
There are 4 students, and they counted the number of passed students as 3,2,2,2. The first student can see that all others have passed, and all other students can see only 2 students who have passed. Hence, the first student must have failed, and others have all passed. Hence, the answer is 1.
|
{"inputs": ["1\n4\n3 2 2 2"], "outputs": ["1"]}
| 451
| 22
|
coding
|
Solve the programming task below in a Python markdown code block.
Bobby has decided to hunt some Parrots. There are n horizontal branch of trees aligned parallel to each other. Branches are numbered 1 to n from top to bottom. On each branch there are some parrots sitting next to each other. Supposed there are a[i]$a[i]$ parrots sitting on the i−th$ i-th$ branch.
Sometimes Bobby shots one of the parrot and the parrot dies (suppose that this parrots sat at the i−th$i-th$ branch). Consequently all the parrots on the i−th$i-th$ branch to the left of the dead parrot get scared and jump up on the branch number i − 1$i - 1$, if there exists no upper branch they fly away. Also all the parrots to the right of the dead parrot jump down on branch number i + 1$i + 1$, if there exists no such branch they fly away.
Bobby has shot m parrots. You're given the initial number of parrots on each branch, tell him how many parrots are sitting on each branch after the shots.
-----Input:-----
The first line of the input contains an integer N$N$. The next line contains a list of space-separated integers a1, a2, …, an.
The third line contains an integer M$M$. Each of the next M$M$ lines contains two integers x[i]$x[i]$ and y[i]$y[i]$. The integers mean that for the i-th time Bobby shoot the y[i]-th (from left) parrot on the x[i]-th branch. It's guaranteed there will be at least y[i] parrot on the x[i]-th branch at that moment.
-----Output:-----
On the i−th$i-th$ line of the output print the number of parrots on the i−th$i-th$ branch.
-----Constraints-----
- 1≤N≤100$1 \leq N \leq 100$
- 0≤a[i]≤100$0 \leq a[i] \leq 100$
- 0≤M≤100$0 \leq M \leq 100$
- 1≤x[i]≤n$1 \leq x[i] \leq n$, 1≤y[i]$1 \leq y[i] $
-----Sample Input:-----
5
10 10 10 10 10
5
2 5
3 13
2 12
1 13
4 6
3
2 4 1
1
2 2
-----Sample Output:-----
0
12
5
0
16
3
0
3
|
{"inputs": ["5\n10 10 10 10 10\n5\n2 5\n3 13\n2 12\n1 13\n4 6\n3\n2 4 1\n1\n2 2"], "outputs": ["0\n12\n5\n0\n16\n3\n0\n3"]}
| 617
| 82
|
coding
|
Solve the programming task below in a Python markdown code block.
A prime number is a natural number which has exactly two distinct natural number divisors: 1 and itself. For example, the first four prime numbers are: 2, 3, 5 and 7.
Write a program which reads a list of N integers and prints the number of prime numbers in the list.
Constraints
1 ≤ N ≤ 10000
2 ≤ an element of the list ≤ 108
Input
The first line contains an integer N, the number of elements in the list.
N numbers are given in the following lines.
Output
Print the number of prime numbers in the given list.
Examples
Input
5
2
3
4
5
6
Output
3
Input
11
7
8
9
10
11
12
13
14
15
16
17
Output
4
|
{"inputs": ["5\n2\n4\n7\n5\n6", "5\n2\n3\n7\n5\n6", "5\n2\n7\n7\n5\n6", "5\n2\n2\n4\n5\n6", "5\n4\n3\n7\n5\n6", "5\n2\n3\n4\n5\n6", "5\n2\n12\n7\n5\n6", "5\n2\n7\n7\n5\n11"], "outputs": ["3\n", "4\n", "4\n", "3\n", "3\n", "3", "3\n", "5\n"]}
| 202
| 143
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given a positive integer num consisting of exactly four digits. Split num into two new integers new1 and new2 by using the digits found in num. Leading zeros are allowed in new1 and new2, and all the digits found in num must be used.
For example, given num = 2932, you have the following digits: two 2's, one 9 and one 3. Some of the possible pairs [new1, new2] are [22, 93], [23, 92], [223, 9] and [2, 329].
Return the minimum possible sum of new1 and new2.
Please complete the following python code precisely:
```python
class Solution:
def minimumSum(self, num: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(num = 2932) == 52\n assert candidate(num = 4009) == 13\n\n\ncheck(Solution().minimumSum)"}
| 190
| 51
|
coding
|
Solve the programming task below in a Python markdown code block.
You want to type the string $s$, consisting of $n$ lowercase Latin letters, using your favorite text editor Notepad#.
Notepad# supports two kinds of operations:
append any letter to the end of the string;
copy a continuous substring of an already typed string and paste this substring to the end of the string.
Can you type string $s$ in strictly less than $n$ operations?
-----Input-----
The first line contains a single integer $t$ ($1 \le t \le 10^4$) — the number of testcases.
The first line of each testcase contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the length of the string $s$.
The second line contains a string $s$, consisting of $n$ lowercase Latin letters.
The sum of $n$ doesn't exceed $2 \cdot 10^5$ over all testcases.
-----Output-----
For each testcase, print "YES" if you can type string $s$ in strictly less than $n$ operations. Otherwise, print "NO".
-----Examples-----
Input
6
10
codeforces
8
labacaba
5
uohhh
16
isthissuffixtree
1
x
4
momo
Output
NO
YES
NO
YES
NO
YES
-----Note-----
In the first testcase, you can start with typing "codef" ($5$ operations), then copy "o" ($1$ operation) from an already typed part, then finish with typing "rces" ($4$ operations). That will be $10$ operations, which is not strictly less than $n$. There exist other ways to type "codeforces". However, no matter what you do, you can't do less than $n$ operations.
In the second testcase, you can type "labac" ($5$ operations), then copy "aba" ($1$ operation), finishing the string in $6$ operations.
|
{"inputs": ["1\n3\nyes\n", "6\n10\ncodeforces\n8\nlabacaba\n5\nuohhh\n16\nisthissuffixtree\n1\nx\n4\nmomo\n"], "outputs": ["NO\n", "NO\nYES\nNO\nYES\nNO\nYES\n"]}
| 438
| 73
|
coding
|
Solve the programming task below in a Python markdown code block.
Polycarp plays "Game 23". Initially he has a number $n$ and his goal is to transform it to $m$. In one move, he can multiply $n$ by $2$ or multiply $n$ by $3$. He can perform any number of moves.
Print the number of moves needed to transform $n$ to $m$. Print -1 if it is impossible to do so.
It is easy to prove that any way to transform $n$ to $m$ contains the same number of moves (i.e. number of moves doesn't depend on the way of transformation).
-----Input-----
The only line of the input contains two integers $n$ and $m$ ($1 \le n \le m \le 5\cdot10^8$).
-----Output-----
Print the number of moves to transform $n$ to $m$, or -1 if there is no solution.
-----Examples-----
Input
120 51840
Output
7
Input
42 42
Output
0
Input
48 72
Output
-1
-----Note-----
In the first example, the possible sequence of moves is: $120 \rightarrow 240 \rightarrow 720 \rightarrow 1440 \rightarrow 4320 \rightarrow 12960 \rightarrow 25920 \rightarrow 51840.$ The are $7$ steps in total.
In the second example, no moves are needed. Thus, the answer is $0$.
In the third example, it is impossible to transform $48$ to $72$.
|
{"inputs": ["1 1\n", "1 2\n", "1 4\n", "1 5\n", "1 6\n", "2 5\n", "4 9\n", "2 7\n"], "outputs": ["0\n", "1\n", "2\n", "-1\n", "2\n", "-1\n", "-1\n", "-1\n"]}
| 364
| 86
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a sequence $A_1, A_2, \ldots, A_N$. For each valid $i$, the star value of the element $A_i$ is the number of valid indices $j < i$ such that $A_j$ is divisible by $A_i$.
Chef is a curious person, so he wants to know the maximum star value in the given sequence. Help him find it.
-----Input-----
- The first line of the input contains a single integer $T$ which denotes the number of test cases.
- The first line of each test case contains a single integer $N$ .
- The second line of each test case 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 star value.
-----Constraints-----
- $1 \le T \le 10$
- $1 \le N \le 10^5$
- $1 \le A_i \le 10^6$ for each valid $i$
- Sum of $N$ over all test cases does not exceed $100,000$.
-----Subtasks-----
Subtask #1 (20 points): sum of $N$ over all test cases does not exceed $5,000$
Subtask #2 (80 points): original constraints
-----Example Input-----
1
7
8 1 28 4 2 6 7
-----Example Output-----
3
-----Explanation-----
$A_5 = 2$ divides $4$, $28$ and $8$, so its star value is $3$. There is no element with a higher star value.
|
{"inputs": ["1\n7\n8 1 28 4 2 6 7"], "outputs": ["3"]}
| 383
| 29
|
coding
|
Solve the programming task below in a Python markdown code block.
Read problems statements in Mandarin Chinese and Russian.
Little Elephant from Zoo of Lviv likes to paint.
He has n objects to paint, ordered in a row and numbered form left to right starting from 1. There are totally c colors, numbered from 0 to c-1. At the beggining all objects are colored in color with number 1. When object with color a is painted in color b, the resulting color will have number (a*b) mod c.
Little Elephant is going to make k turns. At i-th (0-based numeration) turn he will randomly choose any subset (even empty) of objects with indices in range [L_{i}; R_{i}] (inclusive) and paint all objects in chosen subset with random color (the same for all objects in the subset).
Little Elephant wants to know the expected sum of all colors over all n objects after making all k turns. Help him.
------ Input ------
First line contain single integer T - the number of test cases. T test cases follow. First line of each test case contains three integers n, c and k. Next k lines of each test case contain k pairs of integers L_{i} and R_{i}, one pair per line.
------ Output ------
In T lines print T real numbers - the answers for the corresponding test cases.
Any results within 10^-6 absolute error will be accepted.
------ Constraints ------
1 ≤ T ≤ 10
1 ≤ n, k ≤ 50
2 ≤ c ≤ 100
1 ≤ L_{i} ≤ R_{i} ≤ n
----- Sample Input 1 ------
2
4 3 4
1 2
2 4
3 3
1 4
7 10 7
7 7
3 4
1 2
5 5
4 5
2 7
3 3
----- Sample Output 1 ------
3.444444444
22.943125000
|
{"inputs": ["2\n4 3 4\n1 2\n2 4\n3 3\n1 4\n7 10 7\n7 7\n3 4\n1 2\n5 5\n4 5\n2 7\n3 3"], "outputs": ["3.444444444\n22.943125000"]}
| 442
| 92
|
coding
|
Solve the programming task below in a Python markdown code block.
You are given a binary string S. You are allowed to perform the following operation at most once:
Pick some [substring] of S
Flip all the values in this substring, i.e, convert 0 to 1 and vice versa
For example, if S = 1\underline{00101}011, you can pick the underlined substring and flip it to obtain S = 1\underline{11010}011.
For the substring of S consisting of all the positions from L to R, we define a function f(L, R) to be the number of 1's in this substring. For example, if S = 100101011, then f(2, 5) = 1 and f(4, 9) = 4 (the respective substrings are 0010 and 101011).
If you perform the given operation optimally, find the maximum possible value of
\sum_{L=1}^N \sum_{R=L}^N f(L, R)
that can be obtained. Note that the substring flip operation can be performed at most once.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of single line of input, containing a binary string S.
------ Output Format ------
For each test case, output on a new line the maximum possible value of \sum_{L=1}^N \sum_{R=L}^N f(L, R) that can be obtained.
------ Constraints ------
$1 ≤ T ≤ 10^{5}$
$1 ≤ |S| ≤ 3\cdot 10^{5}$
- The sum of $|S|$ over all test cases won't exceed $3\cdot 10^{5}$.
----- Sample Input 1 ------
3
111
000
00100
----- Sample Output 1 ------
10
10
26
----- explanation 1 ------
Test case $1$: There is no need to apply the operation since everything is already a $1$. The answer is thus the sum of:
- $f(1, 1) = 1$
- $f(1, 2) = 2$
- $f(1, 3) = 3$
- $f(2, 2) = 1$
- $f(2, 3) = 2$
- $f(3, 3) = 1$
which is $10$.
Test case $2$: Flip the entire string to obtain $111$, whose answer has been computed above.
Test case $3$: Flip the entire string to obtain $11011$. The sum of $f(L, R)$ across all substrings is now $26$, which is the maximum possible.
|
{"inputs": ["3\n111\n000\n00100"], "outputs": ["10\n10\n26"]}
| 640
| 33
|
coding
|
Solve the programming task below in a Python markdown code block.
Given a positive integer N, MoEngage wants you to determine if it is possible to rearrange the digits of N (in decimal representation) and obtain a [multiple] of 5.
For example, when N = 108, we can rearrange its digits to construct 180 = 36 \cdot 5 which is a multiple of 5.
------ Input Format ------
- The first line contains an integer T, the number of test cases. The description of the T test cases follow.
- Each test case consists of two lines
- The first line contains a single integer D, the number of digits in N.
- The second line consists of a string of length D, the number N (in decimal representation). It is guaranteed that the string does not contain leading zeroes and consists only of the characters 0, 1, \dots 9.
------ Output Format ------
- For each test case, print \texttt{Yes} if it is possible to rearrange the digits of N so that it becomes a multiple 5. Otherwise, print \texttt{No}.
You may print each character of the string in uppercase or lowercase (for example, the strings \texttt{YeS}, \texttt{yEs}, \texttt{yes} and \texttt{YES} will all be treated as identical).
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ D ≤ 1000$
$1 ≤ N < 10^{1000}$
- Sum of $D$ over all test cases $≤ 1000$.
----- Sample Input 1 ------
3
3
115
3
103
3
119
----- Sample Output 1 ------
Yes
Yes
No
----- explanation 1 ------
Test Case $1$: The given number is already divisible by $5$, therefore the answer is $\texttt{Yes}$.
Test Case 2: We can obtain $310 = 62 \cdot 5$ by rearranging the digits of $103$, so the answer is $\texttt{Yes}$.
Test Case 3: The only numbers that can be obtained by rearranging the digits of $119$ are $\{119, 191, 911\}$. None of these numbers are multiples of $5$, so the answer is $\texttt{No}$.
|
{"inputs": ["3\n3\n115\n3\n103\n3\n119"], "outputs": ["Yes\nYes\nNo"]}
| 533
| 34
|
coding
|
Solve the programming task below in a Python markdown code block.
There are $n$ districts in the town, the $i$-th district belongs to the $a_i$-th bandit gang. Initially, no districts are connected to each other.
You are the mayor of the city and want to build $n-1$ two-way roads to connect all districts (two districts can be connected directly or through other connected districts).
If two districts belonging to the same gang are connected directly with a road, this gang will revolt.
You don't want this so your task is to build $n-1$ two-way roads in such a way that all districts are reachable from each other (possibly, using intermediate districts) and each pair of directly connected districts belong to different gangs, or determine that it is impossible to build $n-1$ roads to satisfy all the conditions.
You have to answer $t$ independent test cases.
-----Input-----
The first line of the input contains one integer $t$ ($1 \le t \le 500$) — the number of test cases. Then $t$ test cases follow.
The first line of the test case contains one integer $n$ ($2 \le n \le 5000$) — the number of districts. The second line of the test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the gang the $i$-th district belongs to.
It is guaranteed that the sum of $n$ does not exceed $5000$ ($\sum n \le 5000$).
-----Output-----
For each test case, print:
NO on the only line if it is impossible to connect all districts satisfying the conditions from the problem statement. YES on the first line and $n-1$ roads on the next $n-1$ lines. Each road should be presented as a pair of integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n; x_i \ne y_i$), where $x_i$ and $y_i$ are two districts the $i$-th road connects.
For each road $i$, the condition $a[x_i] \ne a[y_i]$ should be satisfied. Also, all districts should be reachable from each other (possibly, using intermediate districts).
-----Example-----
Input
4
5
1 2 2 1 3
3
1 1 1
4
1 1000 101 1000
4
1 2 3 4
Output
YES
1 3
3 5
5 4
1 2
NO
YES
1 2
2 3
3 4
YES
1 2
1 3
1 4
|
{"inputs": ["1\n2\n7 7\n", "1\n2\n7 7\n", "1\n2\n3 7\n", "1\n2\n0 7\n", "1\n2\n11 7\n", "1\n2\n0 13\n", "1\n2\n1 13\n", "1\n2\n1 21\n"], "outputs": ["NO\n", "NO\n", "YES\n1 2\n", "YES\n1 2\n", "YES\n1 2\n", "YES\n1 2\n", "YES\n1 2\n", "YES\n1 2\n"]}
| 621
| 146
|
coding
|
Solve the programming task below in a Python markdown code block.
Takahashi is not good at problems about trees in programming contests, and Aoki is helping him practice.
First, Takahashi created a tree with N vertices numbered 1 through N, and wrote 0 at each edge.
Then, Aoki gave him M queries. The i-th of them is as follows:
* Increment the number written at each edge along the path connecting vertices a_i and b_i, by one.
After Takahashi executed all of the queries, he told Aoki that, for every edge, the written number became an even number. However, Aoki forgot to confirm that the graph Takahashi created was actually a tree, and it is possible that Takahashi made a mistake in creating a tree or executing queries.
Determine whether there exists a tree that has the property mentioned by Takahashi.
Constraints
* 2 ≤ N ≤ 10^5
* 1 ≤ M ≤ 10^5
* 1 ≤ a_i,b_i ≤ N
* a_i ≠ b_i
Input
Input is given from Standard Input in the following format:
N M
a_1 b_1
:
a_M b_M
Output
Print `YES` if there exists a tree that has the property mentioned by Takahashi; print `NO` otherwise.
Examples
Input
4 4
1 2
2 4
1 3
3 4
Output
YES
Input
5 5
1 2
3 5
5 1
3 4
2 3
Output
NO
|
{"inputs": ["4 4\n1 2\n1 4\n1 3\n3 4", "4 4\n2 2\n1 4\n1 3\n3 4", "4 4\n1 2\n2 4\n1 3\n3 4", "5 5\n1 2\n5 5\n5 1\n3 4\n2 3", "5 1\n1 1\n6 5\n5 2\n3 4\n2 3", "5 1\n1 2\n5 5\n5 1\n3 4\n2 3", "5 1\n1 2\n6 5\n5 1\n3 4\n2 3", "5 1\n1 2\n6 5\n5 2\n3 4\n2 3"], "outputs": ["NO\n", "YES\n", "YES", "NO\n", "YES\n", "NO\n", "NO\n", "NO\n"]}
| 340
| 225
|
coding
|
Solve the programming task below in a Python markdown code block.
School holidays come in Berland. The holidays are going to continue for n days. The students of school №N are having the time of their lives and the IT teacher Marina Sergeyevna, who has spent all the summer busy checking the BSE (Berland State Examination) results, has finally taken a vacation break! Some people are in charge of the daily watering of flowers in shifts according to the schedule. However when Marina Sergeyevna was making the schedule, she was so tired from work and so lost in dreams of the oncoming vacation that she perhaps made several mistakes. In fact, it is possible that according to the schedule, on some days during the holidays the flowers will not be watered or will be watered multiple times. Help Marina Sergeyevna to find a mistake.
Input
The first input line contains two numbers n and m (1 ≤ n, m ≤ 100) — the number of days in Berland holidays and the number of people in charge of the watering respectively. The next m lines contain the description of the duty schedule. Each line contains two integers ai and bi (1 ≤ ai ≤ bi ≤ n), meaning that the i-th person in charge should water the flowers from the ai-th to the bi-th day inclusively, once a day. The duty shifts are described sequentially, i.e. bi ≤ ai + 1 for all i from 1 to n - 1 inclusively.
Output
Print "OK" (without quotes), if the schedule does not contain mistakes. Otherwise you have to find the minimal number of a day when the flowers will not be watered or will be watered multiple times, and output two integers — the day number and the number of times the flowers will be watered that day.
Examples
Input
10 5
1 2
3 3
4 6
7 7
8 10
Output
OK
Input
10 5
1 2
2 3
4 5
7 8
9 10
Output
2 2
Input
10 5
1 2
3 3
5 7
7 7
7 10
Output
4 0
Note
Keep in mind that in the second sample the mistake occurs not only on the second day, but also on the sixth day, when nobody waters the flowers. However, you have to print the second day, i.e. the day with the minimal number.
|
{"inputs": ["1 1\n1 1\n", "5 1\n1 5\n", "10 1\n2 3\n", "6 2\n1 5\n6 6\n", "5 2\n1 1\n3 3\n", "5 2\n2 1\n3 3\n", "5 2\n1 1\n3 5\n", "5 2\n1 2\n3 5\n"], "outputs": ["OK\n", "OK\n", "1 0\n", "OK\n", "2 0\n", "1 0\n", "2 0\n", "OK\n"]}
| 528
| 147
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You may recall that an array arr is a mountain array if and only if:
arr.length >= 3
There exists some index i (0-indexed) with 0 < i < arr.length - 1 such that:
arr[0] < arr[1] < ... < arr[i - 1] < arr[i]
arr[i] > arr[i + 1] > ... > arr[arr.length - 1]
Given an integer array arr, return the length of the longest subarray, which is a mountain. Return 0 if there is no mountain subarray.
Please complete the following python code precisely:
```python
class Solution:
def longestMountain(self, arr: List[int]) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(arr = [2,1,4,7,3,2,5]) == 5\n assert candidate(arr = [2,2,2]) == 0\n\n\ncheck(Solution().longestMountain)"}
| 168
| 60
|
coding
|
Solve the programming task below in a Python markdown code block.
Given an alphanumeric string made up of digits and lower case Latin characters only, find the sum of all the digit characters in the string.
-----Input-----
- The first line of the input contains an integer T denoting the number of test cases. Then T test cases follow.
- Each test case is described with a single line containing a string S, the alphanumeric string.
-----Output-----
- For each test case, output a single line containing the sum of all the digit characters in that string.
-----Constraints-----
- 1 ≤ T ≤ 1000
- 1 ≤ |S| ≤ 1000, where |S| is the length of the string S.
-----Example-----
Input:
1
ab1231da
Output:
7
-----Explanation-----
The digits in this string are 1, 2, 3 and 1. Hence, the sum of all of them is 7.
|
{"inputs": ["1\nab1231da"], "outputs": ["7"]}
| 204
| 19
|
coding
|
Solve the programming task below in a Python markdown code block.
Fox Ciel has some flowers: r red flowers, g green flowers and b blue flowers. She wants to use these flowers to make several bouquets. There are 4 types of bouquets:
To make a "red bouquet", it needs 3 red flowers. To make a "green bouquet", it needs 3 green flowers. To make a "blue bouquet", it needs 3 blue flowers. To make a "mixing bouquet", it needs 1 red, 1 green and 1 blue flower.
Help Fox Ciel to find the maximal number of bouquets she can make.
-----Input-----
The first line contains three integers r, g and b (0 ≤ r, g, b ≤ 10^9) — the number of red, green and blue flowers.
-----Output-----
Print the maximal number of bouquets Fox Ciel can make.
-----Examples-----
Input
3 6 9
Output
6
Input
4 4 4
Output
4
Input
0 0 0
Output
0
-----Note-----
In test case 1, we can make 1 red bouquet, 2 green bouquets and 3 blue bouquets.
In test case 2, we can make 1 red, 1 green, 1 blue and 1 mixing bouquet.
|
{"inputs": ["3 6 9\n", "4 4 4\n", "0 0 0\n", "0 3 6\n", "7 8 9\n", "8 8 9\n", "3 5 5\n", "0 1 1\n"], "outputs": ["6\n", "4\n", "0\n", "3\n", "7\n", "8\n", "4\n", "0\n"]}
| 289
| 102
|
coding
|
Solve the programming task below in a Python markdown code block.
After a very long time, the Chef has a vacation. Chef has planned for two trips during this vacation - one with his family and the other with his friends. The family trip will take X days and the trip with friends will take Y days. Currently, the dates are not decided but the vacation will last only for Z days.
Chef can be in at most one trip at any time and once a trip is started, Chef must complete it before the vacation ends. Will Chef be able to go on both these trips if he chooses the dates optimally?
------ Input Format ------
- The first line will contain a single integer T denoting the number of test cases. The description of the test cases follows.
- Each test case consists of a single line of input, which contains three space-separated integers X, Y and Z.
------ Output Format ------
For each test case, output in a single line the answer: "YES" if Chef can go on both the trips and "NO" if not.
You may print each character of each string in uppercase or lowercase (for example, the strings "yEs", "yes", "Yes" and "YES" will all be treated as identical).
------ Constraints ------
$1 ≤ T ≤ 1000$
$1 ≤ X,Y,Z ≤ 1000$
----- Sample Input 1 ------
2
1 2 4
2 2 3
----- Sample Output 1 ------
YES
NO
----- explanation 1 ------
Test case $1$: Chef can go to the family trip on day $1$ and the friends trip on days $2$ and $3$.
Alternatively, Chef can also plan the trip with friends on days $1$ and $2$ and the family trip on day $4$.
Test case $2$: Chef cannot plan both trips within $3$ days.
|
{"inputs": ["2\n1 2 4\n2 2 3"], "outputs": ["YES\nNO"]}
| 399
| 26
|
coding
|
Solve the programming task below in a Python markdown code block.
The last contest held on Johnny's favorite competitive programming platform has been received rather positively. However, Johnny's rating has dropped again! He thinks that the presented tasks are lovely, but don't show the truth about competitors' skills.
The boy is now looking at the ratings of consecutive participants written in a binary system. He thinks that the more such ratings differ, the more unfair is that such people are next to each other. He defines the difference between two numbers as the number of bit positions, where one number has zero, and another has one (we suppose that numbers are padded with leading zeros to the same length). For example, the difference of $5 = 101_2$ and $14 = 1110_2$ equals to $3$, since $0101$ and $1110$ differ in $3$ positions. Johnny defines the unfairness of the contest as the sum of such differences counted for neighboring participants.
Johnny has just sent you the rating sequence and wants you to find the unfairness of the competition. You have noticed that you've got a sequence of consecutive integers from $0$ to $n$. That's strange, but the boy stubbornly says that everything is right. So help him and find the desired unfairness for received numbers.
-----Input-----
The input consists of multiple test cases. The first line contains one integer $t$ ($1 \leq t \leq 10\,000$) — the number of test cases. The following $t$ lines contain a description of test cases.
The first and only line in each test case contains a single integer $n$ ($1 \leq n \leq 10^{18})$.
-----Output-----
Output $t$ lines. For each test case, you should output a single line with one integer — the unfairness of the contest if the rating sequence equals to $0$, $1$, ..., $n - 1$, $n$.
-----Example-----
Input
5
5
7
11
1
2000000000000
Output
8
11
19
1
3999999999987
-----Note-----
For $n = 5$ we calculate unfairness of the following sequence (numbers from $0$ to $5$ written in binary with extra leading zeroes, so they all have the same length): $000$ $001$ $010$ $011$ $100$ $101$
The differences are equal to $1$, $2$, $1$, $3$, $1$ respectively, so unfairness is equal to $1 + 2 + 1 + 3 + 1 = 8$.
|
{"inputs": ["1\n1\n", "1\n1\n", "1\n399462040\n", "1\n338186953\n", "1\n158575687\n", "1\n313577823\n", "1\n247528392\n", "1\n452215226\n"], "outputs": ["1\n", "1\n", "798924063\n", "676373895\n", "317151359\n", "627155631\n", "495056769\n", "904430437\n"]}
| 610
| 182
|
coding
|
Solve the programming task below in a Python markdown code block.
It's the sale season again and Chef bought items worth a total of X rupees. The sale season offer is as follows:
if X ≤ 100, no discount.
if 100 < X ≤ 1000, discount is 25 rupees.
if 1000 < X ≤ 5000, discount is 100 rupees.
if X > 5000, discount is 500 rupees.
Find the final amount Chef needs to pay for his shopping.
------ Input Format ------
- The first line of input will contain a single integer T, denoting the number of test cases.
- Each test case consists of single line of input containing an integer X.
------ Output Format ------
For each test case, output on a new line the final amount Chef needs to pay for his shopping.
------ Constraints ------
$1 ≤ T ≤ 100$
$1 ≤ X ≤ 10000$
----- Sample Input 1 ------
4
15
70
250
1000
----- Sample Output 1 ------
15
70
225
975
----- explanation 1 ------
Test case $1$: Since $X ≤ 100 $, there is no discount.
Test case $3$: Here, $X = 250$. Since $100 < 250 ≤ 1000$, discount is of $25$ rupees. Therefore, Chef needs to pay $250-25 = 225$ rupees.
|
{"inputs": ["4\n15\n70\n250\n1000\n"], "outputs": ["15\n70\n225\n975\n"]}
| 355
| 41
|
coding
|
Solve the programming task below in a Python markdown code block.
Let's call a string good if and only if it consists of only two types of letters — 'a' and 'b' and every two consecutive letters are distinct. For example "baba" and "aba" are good strings and "abb" is a bad string.
You have $a$ strings "a", $b$ strings "b" and $c$ strings "ab". You want to choose some subset of these strings and concatenate them in any arbitrarily order.
What is the length of the longest good string you can obtain this way?
-----Input-----
The first line contains three positive integers $a$, $b$, $c$ ($1 \leq a, b, c \leq 10^9$) — the number of strings "a", "b" and "ab" respectively.
-----Output-----
Print a single number — the maximum possible length of the good string you can obtain.
-----Examples-----
Input
1 1 1
Output
4
Input
2 1 2
Output
7
Input
3 5 2
Output
11
Input
2 2 1
Output
6
Input
1000000000 1000000000 1000000000
Output
4000000000
-----Note-----
In the first example the optimal string is "baba".
In the second example the optimal string is "abababa".
In the third example the optimal string is "bababababab".
In the fourth example the optimal string is "ababab".
|
{"inputs": ["1 1 1\n", "2 1 2\n", "3 5 2\n", "2 2 1\n", "3 1 3\n", "2 2 3\n", "1 1 4\n", "1 1 2\n"], "outputs": ["4\n", "7\n", "11\n", "6\n", "9\n", "10\n", "10\n", "6\n"]}
| 360
| 105
|
coding
|
Solve the programming task below in a Python markdown code block.
G --Derangement / Derangement
Story
Person D is doing research on permutations. At one point, D found a permutation class called "Derangement". "It's cool to have a perfect permutation !!! And it starts with D !!!", the person of D who had a crush on Chunibyo decided to rewrite all the permutations given to him.
Problem
Given a permutation of length n, p = (p_1 p_2 ... p_n). The operation of swapping the i-th element and the j-th element requires the cost of (p_i + p_j) \ times | i-j |. At this time, find the minimum cost required to make p into a perfect permutation using only the above swap operation.
However, the fact that the permutation q is a perfect permutation means that q_i \ neq i holds for 1 \ leq i \ leq n. For example, (5 3 1 2 4) is a perfect permutation, but (3 2 5 4 1) is not a perfect permutation because the fourth number is 4.
Input
The input consists of the following format.
n
p_1 p_2 ... p_n
The first row consists of one integer representing the length n of the permutation. The second line consists of n integers, and the i-th integer represents the i-th element of the permutation p. Each is separated by a single blank character.
Constraints:
* 2 \ leq n \ leq 100
* 1 \ leq p_i \ leq n, i \ neq j ⇔ p_i \ neq p_j
Output
Print the minimum cost to sort p into a complete permutation on one line. Be sure to start a new line at the end of the line.
Sample Input 1
Five
1 2 3 5 4
Sample Output 1
7
After swapping 1 and 2, swapping 1 and 3 yields (2 3 1 5 4), which is a complete permutation.
Sample Input 2
Five
5 3 1 2 4
Sample Output 2
0
It is a perfect permutation from the beginning.
Sample Input 3
Ten
1 3 4 5 6 2 7 8 9 10
Sample Output 3
38
Example
Input
5
1 2 3 5 4
Output
7
|
{"inputs": ["5\n2 1 3 5 4", "5\n2 1 0 5 4", "5\n4 1 0 5 4", "5\n4 1 0 5 6", "5\n4 0 0 5 6", "5\n4 0 0 0 3", "5\n4 0 1 0 3", "5\n7 0 1 0 3"], "outputs": ["4\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n", "0\n"]}
| 526
| 142
|
coding
|
Solve the programming task below in a Python markdown code block.
A new e-mail service "Berlandesk" is going to be opened in Berland in the near future. The site administration wants to launch their project as soon as possible, that's why they ask you to help. You're suggested to implement the prototype of site registration system. The system should work on the following principle.
Each time a new user wants to register, he sends to the system a request with his name. If such a name does not exist in the system database, it is inserted into the database, and the user gets the response OK, confirming the successful registration. If the name already exists in the system database, the system makes up a new user name, sends it to the user as a prompt and also inserts the prompt into the database. The new name is formed by the following rule. Numbers, starting with 1, are appended one after another to name (name1, name2, ...), among these numbers the least i is found so that namei does not yet exist in the database.
Input
The first line contains number n (1 ≤ n ≤ 105). The following n lines contain the requests to the system. Each request is a non-empty line, and consists of not more than 32 characters, which are all lowercase Latin letters.
Output
Print n lines, which are system responses to the requests: OK in case of successful registration, or a prompt with a new name, if the requested name is already taken.
Examples
Input
4
abacaba
acaba
abacaba
acab
Output
OK
OK
abacaba1
OK
Input
6
first
first
second
second
third
third
Output
OK
first1
OK
second1
OK
third1
|
{"inputs": ["1\nn\n", "1\nm\n", "1\nl\n", "1\nk\n", "1\no\n", "1\np\n", "2\nu\nu\n", "2\nv\nu\n"], "outputs": ["OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\n", "OK\nu1\n", "OK\nOK\n"]}
| 378
| 95
|
coding
|
Solve the programming task below in a Python markdown code block.
Create a function which accepts one arbitrary string as an argument, and return a string of length 26.
The objective is to set each of the 26 characters of the output string to either `'1'` or `'0'` based on the fact whether the Nth letter of the alphabet is present in the input (independent of its case).
So if an `'a'` or an `'A'` appears anywhere in the input string (any number of times), set the first character of the output string to `'1'`, otherwise to `'0'`. if `'b'` or `'B'` appears in the string, set the second character to `'1'`, and so on for the rest of the alphabet.
For instance:
```
"a **& cZ" => "10100000000000000000000001"
```
Also feel free to reuse/extend the following starter code:
```python
def change(st):
```
|
{"functional": "_inputs = [['a **& bZ'], ['Abc e $$ z'], ['!!a$%&RgTT'], [''], ['abcdefghijklmnopqrstuvwxyz'], ['aaaaaaaaaaa'], ['&%&%/$%$%$%$%GYtf67fg34678hgfdyd']]\n_outputs = [['11000000000000000000000001'], ['11101000000000000000000001'], ['10000010000000000101000000'], ['00000000000000000000000000'], ['11111111111111111111111111'], ['10000000000000000000000000'], ['00010111000000000001000010']]\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(change(*i), o[0])"}
| 230
| 406
|
coding
|
Solve the programming task below in a Python markdown code block.
A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.
You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 100) — the number of characters in the string.
The second line contains the string. The string consists only of uppercase and lowercase Latin letters.
-----Output-----
Output "YES", if the string is a pangram and "NO" otherwise.
-----Examples-----
Input
12
toosmallword
Output
NO
Input
35
TheQuickBrownFoxJumpsOverTheLazyDog
Output
YES
|
{"inputs": ["1\na\n", "1\na\n", "1\nb\n", "12\ntoosmallword\n", "12\ntoosmallworc\n", "12\ntoosmallword\n", "25\nnxYTzLFwzNolAumjgcAboyxAj\n", "25\nabcdefghijklmnopqrstuvwxy\n"], "outputs": ["NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n", "NO\n"]}
| 210
| 122
|
coding
|
Solve the programming task below in a Python markdown code block.
Snuke is buying a lamp.
The light of the lamp can be adjusted to m levels of brightness, represented by integers from 1 through m, by the two buttons on the remote control.
The first button is a "forward" button. When this button is pressed, the brightness level is increased by 1, except when the brightness level is m, in which case the brightness level becomes 1.
The second button is a "favorite" button. When this button is pressed, the brightness level becomes the favorite brightness level x, which is set when the lamp is purchased.
Snuke is thinking of setting the favorite brightness level x so that he can efficiently adjust the brightness.
He is planning to change the brightness n-1 times. In the i-th change, the brightness level is changed from a_i to a_{i+1}. The initial brightness level is a_1.
Find the number of times Snuke needs to press the buttons when x is set to minimize this number.
-----Constraints-----
- 2 \leq n,m \leq 10^5
- 1 \leq a_i\leq m
- a_i \neq a_{i+1}
- n, m and a_i are integers.
-----Input-----
Input is given from Standard Input in the following format:
n m
a_1 a_2 … a_n
-----Output-----
Print the minimum number of times Snuke needs to press the buttons.
-----Sample Input-----
4 6
1 5 1 4
-----Sample Output-----
5
When the favorite brightness level is set to 1, 2, 3, 4, 5 and 6, Snuke needs to press the buttons 8, 9, 7, 5, 6 and 9 times, respectively.
Thus, Snuke should set the favorite brightness level to 4.
In this case, the brightness is adjusted as follows:
- In the first change, press the favorite button once, then press the forward button once.
- In the second change, press the forward button twice.
- In the third change, press the favorite button once.
|
{"inputs": ["4 8\n1 5 1 4", "4 8\n1 5 1 5", "1 8\n1 5 2 1", "4 6\n0 5 1 4", "4 6\n2 3 2 1", "2 8\n1 5 1 5", "2 8\n1 5 1 0", "2 8\n1 5 1 1"], "outputs": ["7\n", "6\n", "0\n", "5\n", "4\n", "1\n", "1\n", "1\n"]}
| 462
| 142
|
coding
|
Solve the programming task below in a Python markdown code block.
Chef's brother likes to put words in Chef's mouth.
Chef hates it about him of course.
He has decided to become extremely careful about what he speaks.
Fortunately, he knows how his brother transforms the words, that Chef uses.
He has decided to use only those words which remain the same even after his brother's transformation!
If Chef speaks an N letter word, his brother moves all the letters which are at even positions (assuming, numbering of positions starts from 1), to the beginning of the word; and the rest of the letters follow as they appeared in the word. Eg. abdef becomes beadf; cdcd becomes ddcc.
Chef wants to know how many words can he use, provided that each word is composed of exactly N lowercase letters of the English alphabet. They use an ancient language in Byteland, which allows all possible words within the above definition!
Input format
The first line contains the number T, the number of test cases. In the following lines, T test cases follow. Every test case is a single line, that contains a single positive integer, N,
which is the length of the words that Chef wants to use.
Output format
For each test case, print the number of words of length N that Chef can use; that is, number of words, which remain the same after brother's transformation.
Since the result can be quite large, output the result modulo 1000000007.
------ Constraints ------
1 ≤ T ≤ 100
1 ≤ N ≤ 100000
----- Sample Input 1 ------
3
1
14
45
----- Sample Output 1 ------
26
456976
827063120
|
{"inputs": ["3\n1\n14\n45"], "outputs": ["26\n456976\n827063120"]}
| 378
| 38
|
coding
|
Solve the programming task below in a Python markdown code block.
Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?
-----Input-----
The single line contains four space-separated integers n, m, a, b (1 ≤ n, m, a, b ≤ 1000) — the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.
-----Output-----
Print a single integer — the minimum sum in rubles that Ann will need to spend.
-----Examples-----
Input
6 2 1 2
Output
6
Input
5 2 2 3
Output
8
-----Note-----
In the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.
|
{"inputs": ["6 2 1 2\n", "5 2 2 3\n", "1 1 1 1\n", "6 4 1 3\n", "8 5 2 8\n", "6 4 1 3\n", "1 1 1 1\n", "8 5 2 8\n"], "outputs": ["6\n", "8\n", "1\n", "5\n", "14\n", "5\n", "1\n", "14\n"]}
| 260
| 120
|
coding
|
Please solve the programming task below using a self-contained code snippet in a markdown code block.
You are given an integer array nums and an integer k.
For each index i where 0 <= i < nums.length, change nums[i] to be either nums[i] + k or nums[i] - k.
The score of nums is the difference between the maximum and minimum elements in nums.
Return the minimum score of nums after changing the values at each index.
Please complete the following python code precisely:
```python
class Solution:
def smallestRangeII(self, nums: List[int], k: int) -> int:
```
|
{"functional": "def check(candidate):\n assert candidate(nums = [1], k = 0) == 0\n assert candidate(nums = [0,10], k = 2) == 6\n assert candidate(nums = [1,3,6], k = 3) == 3\n\n\ncheck(Solution().smallestRangeII)"}
| 127
| 79
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.