source
stringclasses
4 values
task_type
stringclasses
1 value
in_source_id
stringlengths
0
138
problem
stringlengths
219
13.2k
gold_standard_solution
stringlengths
0
413k
problem_id
stringlengths
5
10
metadata
dict
verification_info
dict
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/assignment-problem3016/1
Solve the following coding problem using the programming language python: You are the head of a firm and you have to assign jobs to people. You have N persons working under you and you have N jobs that are to be done by these persons. Each person has to do exactly one job and each job has to be done by exactly one person. Each person has his own capability (in terms of time taken) to do any particular job. Your task is to assign the jobs to the persons in such a way that the total time taken is minimum. A job can be assigned to only one person and a person can do only one job. Example 1: Input: N = 2 Arr[] = {3, 5, 10, 1} Output: 4 Explanation: The first person takes times 3 and 5 for jobs 1 and 2 respectively. The second person takes times 10 and 1 for jobs 1 and 2 respectively. We can see that the optimal assignment will be to give job 1 to person 1 and job 2 to person 2 for a total for 3+1 = 4. Example 2: Input: N = 3 Arr[] = {2, 1, 2, 9, 8, 1, 1, 1, 1} Output: 3 Explanation: The optimal arrangement would be to assign job 1 to person 3,job 2 to person 1 and job 3 to person 2. Your Task: You don't need to read input or print anything. Your task is to complete the function assignmentProblem() which takes an Integer N and an array Arr[] of size N^{2} as input and returns the time taken for the best possible assignment. Expected Time Complexity: O(N^{2}) Expected Auxiliary Space: O(N^{2}) Constraints: 1 <= N <= 30 1 <= Arr[i] <= 100 Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def assignmentProblem(self, Arr, N): # code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def assignmentProblem(self, Arr, N): n = N l = Arr m = [] mybeg = [] for i in range(n): m.append(l[i * n:(i + 1) * n]) mybeg.append(l[i * n:(i + 1) * n]) def util(): (u, v, ind) = ([0] * n, [0] * n, [-1] * n) for i in range(n): (links, mins, visited) = ([-1] * n, [1000] * n, [False] * n) (marki, markj) = (i, -1) while marki != -1: j = -1 for j1 in range(n): if not visited[j1]: current = m[marki][j1] - u[marki] - v[j1] if current < mins[j1]: mins[j1] = current links[j1] = markj if j == -1 or mins[j1] < mins[j]: j = j1 delta = mins[j] for j1 in range(n): if visited[j1]: u[ind[j1]] += delta v[j1] -= delta else: mins[j1] -= delta u[i] += delta visited[j] = True (markj, marki) = (j, ind[j]) while links[j] != -1: ind[j] = ind[links[j]] j = links[j] ind[j] = i return [(ind[j], j) for j in range(n)] return sum((mybeg[x][y] for (x, y) in util())) ```
vfc_136093
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/assignment-problem3016/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 2\r\nArr[] = {3, 5, 10, 1}", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3\r\nArr[] = {2, 1, 2, 9, 8, 1, 1, 1, 1}", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MEANMEDIAN
Solve the following coding problem using the programming language python: Chef has two numbers X and Y. Chef wants to find three integers A, B, and C such that: -1000 ≤ A, B, C ≤ 1000 mean([A, B, C]) = X median([A, B, C]) = Y Can you help Chef find such three integers? As a reminder, mean([P, Q, R]) = \frac{P + Q + R}{3} and median([P, Q, R]) is the element at the 2^{nd} (middle) position after we sort [P, Q, R] in non-decreasing order. ------ Input Format ------ - The first line contains a single integer T — the number of test cases. Then the test cases follow. - The first and only line of each test case contains two space-separated integers X and Y — the required mean and median of the three integers. ------ Output Format ------ For each test case, output three integers A, B, C which satisfy the given conditions. It is guaranteed that an answer always exists under the given constraints. If multiple answers exist, output any. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $-100 ≤X, Y ≤100$ ----- Sample Input 1 ------ 3 5 5 67 100 4 5 ----- Sample Output 1 ------ 5 5 5 0 100 101 0 5 7 ----- explanation 1 ------ Test Case 1: $mean([5, 5, 5]) = \frac{5 + 5 + 5}{3} = 5$, $median([5, 5, 5]) = 5$. Test Case 2: $mean([0, 100, 101]) = \frac{0 + 100 + 101}{3} = \frac{201}{3} = 67$, $median([0, 100, 101]) = 100$. Test Case 3: $mean([0, 5, 7]) = \frac{0 + 5 + 7}{3} = 4$, $median([0, 5, 7]) = 5$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python T = int(input()) for i in range(T): line = input().split(' ') X = int(line[0]) B = Y = int(line[1]) if X == Y: print(line[0] + ' ' + line[0] + ' ' + line[0]) else: if B > 0: A = 0 elif B == 0: A = -1 else: A = 2 * B C = 3 * X - A - B while C < B: if C <= A: A = A - (B - C) else: A = A + (B - C) C = 3 * X - A - B print(str(A) + ' ' + str(B) + ' ' + str(C)) ```
vfc_136098
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MEANMEDIAN", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n5 5\n67 100\n4 5\n", "output": "5 5 5\n0 100 101\n0 5 7", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/PROC2020/problems/VC711
Solve the following coding problem using the programming language python: Chuck Norris just created a universe. He has already started the space-time continuum. Now he needs to fill the universe with matter and antimatter for the avatar cycle to start. He created $N$ distinct pairs of elementary matter and their corresponding antimatter particles. Annihilations happen only when a matter particle is placed adjacent to its corresponding antimatter particle and not when it is placed adjacent to any other matter or antimatter particle. Thus for every distinct particle of matter in the universe there exist one and only one antimatter particle that can cause its annihilation. Chuck Norris wants to arrange all the particles in a 2-D circular pattern such that a matter particle is placed adjacent only to antimatter particles and vice versa. In how many distinct ways can he arrange them, regardless of the orientation of the arrangement, such that total annihilation of ALL particles doesn't take place i.e., $at least$ $one$ pair remain unannihilated after he arranges them in a circular pattern. Since the total number of distinct ways can be very large, print the result modulo $1000000007$. -----Input:----- - First line has single integer $T$, i.e., the number of test cases - The first and only line of each test case has a single integer $N$ i.e., number of distinct pairs of matter-antimatter particles. -----Output:----- - For of each test case print a single line, i.e., total number of distinct ways. -----Constraints :----- - $1 \leq T \leq 1000$ - $0 \leq N \leq 10^7$ -----Subtasks----- - Subtask 1 : 10 pts - $1 \leq T \leq 100$ - $0 \leq N \leq 100$ - Subtask 2 : 90 pts - Original Constraints -----Sample input :----- 1 3 -----Sample output :----- 8 -----Explanation:----- For 3 pairs of elementary matter and their corresponding antimatter particles, Chuck Norris can arrange them in 8 ways such that at least one pair of matter antimatter particles survive annihilation. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for i in range(int(input())): n = int(input()) if n <= 2 or n > 1000000007: print('0') else: prod = 1 for i in range(2, n): prod *= i if prod > 1000000007: prod = prod % 1000000007 print(prod * (n * prod - 2) % 1000000007) ```
vfc_136102
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PROC2020/problems/VC711", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n3\nSample output :\n8\n", "output": "", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/BULLBEAR
Solve the following coding problem using the programming language python: Chef is on his way to become the new big bull of the stock market but is a bit weak at calculating whether he made a profit or a loss on his deal. Given that Chef bought the stock at value X and sold it at value Y. Help him calculate whether he made a profit, loss, or was it a neutral deal. ------ 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 line of input containing two space-separated integers X and Y, denoting the value at which Chef bought and sold the stock respectively. ------ Output Format ------ For each test case, output PROFIT if Chef made a profit on the deal, LOSS if Chef incurred a loss on the deal, and NEUTRAL otherwise. The checker is case-insensitive so answers like pROfiT, profit, and PROFIT would be considered the same. ------ Constraints ------ $1 ≤ T ≤ 500$ $1 ≤ X, Y ≤ 100$ ----- Sample Input 1 ------ 4 4 2 8 8 3 4 2 1 ----- Sample Output 1 ------ LOSS NEUTRAL PROFIT LOSS ----- explanation 1 ------ Test case $1$: Since the cost price is greater than the selling price, Chef made a loss in the deal. Test case $2$: Since the cost price is equal to the selling price, the deal was neutral. Test case $3$: Since the cost price is less than the selling price, Chef made a profit in the deal. Test case $4$: Since the cost price is greater than the selling price, Chef made a loss in the deal. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python T = int(input()) for _ in range(T): (X, Y) = map(int, input().split()) if X is Y: print('NEUTRAL') elif X > Y: print('LOSS') else: print('PROFIT') ```
vfc_136106
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/BULLBEAR", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 2\n8 8\n3 4\n2 1\n", "output": "LOSS\nNEUTRAL\nPROFIT\nLOSS\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/LOCMAR16/problems/MOD
Solve the following coding problem using the programming language python: You have an array A of size N containing only positive numbers. You have to output the maximum possible value of A[i]%A[j] where 1<=i,j<=N. -----Input----- The first line of each test case contains a single integer N denoting the size of the array. The next N lines contains integers A1, A2, ..., AN denoting the numbers -----Output----- Output a single integer answering what is asked in the problem. -----Subtask 1 (20 points)----- - 1 ≤ N ≤ 5000 - 1 ≤ A[i] ≤ 2*(10^9) -----Subtask 2 (80 points)----- - 1 ≤ N ≤ 1000000 - 1 ≤ A[i] ≤ 2*(10^9) -----Example----- Input: 2 1 2 Output: 1 -----Explanation----- There will be four values, A[0]%A[0] = 0, A[0]%A[1]=1, A[1]%A[0]=0, A[1]%A[1]=0, and hence the output will be the maximum among them all, that is 1. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) a = [] for i in range(n): a.append(int(input())) m1 = 0 m2 = 0 for e in a: if e > m1: m2 = m1 m1 = e elif e > m2 and e != m1: m2 = e ans = 0 for e in a: temp = m1 % e if temp > ans: ans = temp print(max(m2 % m1, ans)) ```
vfc_136110
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/LOCMAR16/problems/MOD", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n1\n2\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1109/A
Solve the following coding problem using the programming language python: Sasha likes programming. Once, during a very long contest, Sasha decided that he was a bit tired and needed to relax. So he did. But since Sasha isn't an ordinary guy, he prefers to relax unusually. During leisure time Sasha likes to upsolve unsolved problems because upsolving is very useful. Therefore, Sasha decided to upsolve the following problem: You have an array $a$ with $n$ integers. You need to count the number of funny pairs $(l, r)$ $(l \leq r)$. To check if a pair $(l, r)$ is a funny pair, take $mid = \frac{l + r - 1}{2}$, then if $r - l + 1$ is an even number and $a_l \oplus a_{l+1} \oplus \ldots \oplus a_{mid} = a_{mid + 1} \oplus a_{mid + 2} \oplus \ldots \oplus a_r$, then the pair is funny. In other words, $\oplus$ of elements of the left half of the subarray from $l$ to $r$ should be equal to $\oplus$ of elements of the right half. Note that $\oplus$ denotes the bitwise XOR operation. It is time to continue solving the contest, so Sasha asked you to solve this task. -----Input----- The first line contains one integer $n$ ($2 \le n \le 3 \cdot 10^5$) — the size of the array. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i < 2^{20}$) — array itself. -----Output----- Print one integer — the number of funny pairs. You should consider only pairs where $r - l + 1$ is even number. -----Examples----- Input 5 1 2 3 4 5 Output 1 Input 6 3 2 2 3 7 6 Output 3 Input 3 42 4 2 Output 0 -----Note----- Be as cool as Sasha, upsolve problems! In the first example, the only funny pair is $(2, 5)$, as $2 \oplus 3 = 4 \oplus 5 = 1$. In the second example, funny pairs are $(2, 3)$, $(1, 4)$, and $(3, 6)$. In the third example, there are no funny pairs. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main(): n = int(input()) a = map(int, input().split()) cnt = [{} for _ in range(2)] xor = 0 result = 0 cnt[1][0] = 1 for (i, x) in enumerate(a): xor ^= x index = i & 1 result += int(cnt[index].get(xor) or 0) cnt[index][xor] = int(cnt[index].get(xor) or 0) + 1 print(result) main() ```
vfc_136114
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1109/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1 2 3 4 5\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6\n3 2 2 3 7 6\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n42 4 2\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n60202 951227\n", "output": "0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/228/B
Solve the following coding problem using the programming language python: You've got two rectangular tables with sizes na × ma and nb × mb cells. The tables consist of zeroes and ones. We will consider the rows and columns of both tables indexed starting from 1. Then we will define the element of the first table, located at the intersection of the i-th row and the j-th column, as ai, j; we will define the element of the second table, located at the intersection of the i-th row and the j-th column, as bi, j. We will call the pair of integers (x, y) a shift of the second table relative to the first one. We'll call the overlap factor of the shift (x, y) value: <image> where the variables i, j take only such values, in which the expression ai, j·bi + x, j + y makes sense. More formally, inequalities 1 ≤ i ≤ na, 1 ≤ j ≤ ma, 1 ≤ i + x ≤ nb, 1 ≤ j + y ≤ mb must hold. If there are no values of variables i, j, that satisfy the given inequalities, the value of the sum is considered equal to 0. Your task is to find the shift with the maximum overlap factor among all possible shifts. Input The first line contains two space-separated integers na, ma (1 ≤ na, ma ≤ 50) — the number of rows and columns in the first table. Then na lines contain ma characters each — the elements of the first table. Each character is either a "0", or a "1". The next line contains two space-separated integers nb, mb (1 ≤ nb, mb ≤ 50) — the number of rows and columns in the second table. Then follow the elements of the second table in the format, similar to the first table. It is guaranteed that the first table has at least one number "1". It is guaranteed that the second table has at least one number "1". Output Print two space-separated integers x, y (|x|, |y| ≤ 109) — a shift with maximum overlap factor. If there are multiple solutions, print any of them. Examples Input 3 2 01 10 00 2 3 001 111 Output 0 1 Input 3 3 000 010 000 1 1 1 Output -1 -1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def mi(): return map(int, input().split()) def mi1(): return map(int, list(input())) (na, ma) = mi() a = [0] * na for i in range(na): a[i] = list(mi1()) (nb, mb) = mi() b = [0] * nb for i in range(nb): b[i] = list(mi1()) ans = -10 ** 10 (ax, ay) = (0, 0) (n, m) = (max(na, nb), max(ma, mb)) for x in range(-n, n + 1): for y in range(-m, m + 1): res = 0 for i in range(na): for j in range(ma): if x + i >= 0 and y + j >= 0 and (x + i < nb) and (y + j < mb): res += a[i][j] * b[x + i][y + j] if res >= ans: (ax, ay) = (x, y) ans = res print(ax, ay) ```
vfc_136119
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/228/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 14\n11110101110010\n50 3\n101\n011\n010\n100\n011\n011\n100\n100\n110\n101\n000\n111\n100\n010\n000\n001\n101\n111\n110\n111\n100\n011\n110\n110\n100\n001\n011\n100\n100\n010\n110\n100\n100\n010\n001\n010\n110\n101\n110\n110\n010\n001\n011\n111\n101\n001\n000\n101\n100\n011\n", "output": "11 -7\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/SQRTCBRT
Solve the following coding problem using the programming language python: Kulyash loves perfect squares and hates perfect cubes. For any natural number N, F(N) = \texttt{number of perfect squares smaller than or equal to } N - \texttt{number of positive perfect cubes smaller than or equal to } N. Kulyash gives you an integer X and asks you to find the minimum value of N, such that F(N) ≥ X. ------ 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 line of input. - The first and only line of each test case contains an integer X. ------ Output Format ------ For each test case, output on a new line, the minimum value of N such that F(N) ≥ X. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ X ≤ 10^{9}$ ----- Sample Input 1 ------ 3 1 3 3151 ----- Sample Output 1 ------ 4 25 11397376 ----- explanation 1 ------ Test case $1$: There are $2$ perfect squares from $1$ to $4$, and $1$ perfect cube from $1$ to $4$, so $F(4) = 2 - 1 = 1$, as required. Test case $2$: There are $5$ perfect squares from $1$ to $25$, and $2$ perfect cubes from $1$ to $25$, so $F(25) = 5 - 2 = 3$, as required. Test case $3$: There are $3376$ perfect squares from $1$ to $11397376$, and $225$ perfect cubes from $1$ to $11397376$, so $F(11397376) = 3376 - 225 = 3151$, as required. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math t = int(input()) while t > 0: x = int(input()) start = x end = 10 ** 10 mid = (start + end) // 2 ans = 10 ** 20 while start <= end: sq = mid zz = mid * mid cb = int(zz ** (1 / 3)) val = cb + 1 val = val ** 3 if val == zz: cb += 1 dif = sq - cb if dif >= x: ans = min(ans, zz) end = mid - 1 mid = (start + end) // 2 else: start = mid + 1 mid = (start + end) // 2 print(ans) t -= 1 ```
vfc_136124
{ "difficulty": "hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SQRTCBRT", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n3\n3151\n", "output": "4\n25\n11397376\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/pair-with-greatest-product-in-array3342/1
Solve the following coding problem using the programming language python: Given an array A of N elements. The task is to find the greatest number S such that it is product of two elements of given array (S cannot be included in pair. Also, pair must be from different indices). Example 1: Input : arr[] = {10, 3, 5, 30, 35} Output: 30 Explanation: 30 is the product of 10 and 3. Example 2: Input : arr[] = {2, 5, 7, 8} Output: -1 Explanation: Since, no such element exists. Example 3: Input : arr[] = {10, 2, 4, 30, 35} Output: -1 Example 4: Input : arr[] = {10, 2, 2, 4, 30, 35} Output: 4 Example 5: Input : arr[] = {17, 2, 1, 35, 30} Output : 35 Your Task: You don't need to read input or print anything. Your task is to complete the function findGreatest() which takes the array arr[] and its size N as inputs and returns the answer. If the answer is not present in the array, return -1. Expected Time Complexity: O(N. Log(N)) Expected Auxiliary Space: O(N) Constraints: 1 ≤ N ≤ 10^{6} 1 ≤ A_{i} ≤ 10^{7} Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def findGreatest(self, arr, n): # Your code goes here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from math import * class Solution: def findGreatest(self, arr, n): m = dict() for i in arr: m[i] = m.get(i, 0) + 1 arr = sorted(arr) for i in range(n - 1, 0, -1): j = 0 if arr[i] == 1: if m[1] > 2: return 1 continue while j < i and arr[j] <= sqrt(arr[i]): if arr[j] == 1: if m[arr[i]] > 1: return arr[i] j += 1 continue if arr[i] % arr[j] == 0: result = arr[i] // arr[j] if result != arr[j] and result in m.keys() and (m[result] > 0): return arr[i] elif result == arr[j] and result in m.keys() and (m[result] > 1): return arr[i] j += 1 return -1 ```
vfc_136128
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/pair-with-greatest-product-in-array3342/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "arr[] = {10, 3, 5, 30, 35}", "output": "30", "type": "stdin_stdout" }, { "fn_name": null, "input": "arr[] = {2, 5, 7, 8}", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": ": arr[] = {10, 2, 4, 30, 35}", "output": "-1", "type": "stdin_stdout" }, { "fn_name": null, "input": "arr[] = {10, 2, 2, 4, 30, 35}", "output": "4", "type": "stdin_stdout" }, { "fn_name": null, "input": ":arr[] = {17, 2, 1, 35, 30}", "output": "35", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/COUNTONES
Solve the following coding problem using the programming language python: Alice recently converted all the positive integers from 1 to 2^{N} - 1 (both inclusive) into binary strings and stored them in an array S. Note that the binary strings do not have leading zeroes. While she was out, Bob sorted all the elements of S in lexicographical increasing order. Let S_{i} denotes the i^{th} string in the sorted array. Alice defined a function F such that F(S_{i}) is equal to the count of 1 in the string S_{i}. For example, F(101) = 2 and F(1000) = 1. Given a positive integer K, find the value of \sum_{i = 1}^K F(S_{i}). String P is lexicographically smaller than string Q if one of the following satisfies: P is a prefix of Q and P \neq Q. There exists an index i such that P_{i} < Q_{i} and for all j < i, P_{j}=Q_{j}. ------ Input Format ------ - The first line will contain an integer T - number of test cases. Then the test cases follow. - The first and only line of each test case contains two integers N and K. ------ Output Format ------ For each test case, output the value \sum_{i = 1}^K F(S_{i}). ------ Constraints ------ $1 ≤ T ≤ 3000$ $1 ≤ N ≤ 50$ $1 ≤ K ≤ 2^{N} - 1$ - Sum of $N$ over all test cases does not exceed $10^{5}$. ----- Sample Input 1 ------ 3 3 2 3 4 3 7 ----- Sample Output 1 ------ 2 5 12 ----- explanation 1 ------ Converting positive integers to Binary Strings: - $1 = 1$ - $2 = 10$ - $3 = 11$ - $4 = 100$ - $5 = 101$ - $6 = 110$ - $7 = 111$ Sorting Binary Strings in lexicographical order: After sorting, the strings will appear in the following order: $[1, 10, 100, 101, 11, 110, 111]$. Test case $1$: $F(S_{1}) + F(S_{2}) = F(1) + F(10) = 1 + 1 = 2$. Test case $2$: $F(S_{1}) + F(S_{2}) + F(S_{3}) + F(S_{4}) = F(1) + F(10) + F(100) + F(101) = 1 + 1 + 1 + 2 = 5$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python z = [0 for _ in range(51)] z[1] = 1 for i in range(2, 51): z[i] = 2 * z[i - 1] + 2 ** (i - 2) b = [0 for i in range(51)] for i in range(1, 51): b[i] = b[i - 1] + z[i] def sol1(target, n): value = 1 sum1 = 1 num1 = 1 abnum = 2 ** (n - 1) - 1 while value != target: if value + abnum > target: value = value + 1 sum1 = sum1 + num1 n = n - 1 abnum = 2 ** (n - 1) - 1 elif value + abnum < target: value = value + abnum + 1 sum1 = sum1 + num1 * abnum n = n - 1 for u in range(1, n): sum1 = sum1 + b[u] num1 = num1 + 1 sum1 = sum1 + num1 abnum = 2 ** (n - 1) - 1 else: value = value + abnum sum1 = sum1 + num1 * abnum n = n - 1 for u in range(1, n): sum1 = sum1 + b[u] return sum1 w = int(input()) for _ in range(w): (n, k) = list(map(int, input().strip().split())) print(sol1(k, n)) ```
vfc_136129
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/COUNTONES", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3 2\n3 4\n3 7", "output": "2\n5\n12\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Rasta calls a number like a Tavas if and only if 1 ≤ a ≤ n and the sum of all primes (like p) that p | a is exactly equal to k. He asks you to find the number of Tavases. Input format The first and only line of input contains two integers, n and k (1 ≤ n, k ≤ 10^6). Output format Print a single integer, the number of Tavases. SAMPLE INPUT 20 7 SAMPLE OUTPUT 3 Explanation The only Tavases are 7, 10 and 20. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python maxn = 1000010 p = [0] * maxn d = [0] * maxn for i in range(2, maxn): if p[i] == 0: for j in range(i, maxn, i): d[j] += i for j in range(2 * i, maxn, i): p[j] = 1 n, k = list(map(int, input().split())) res = 0 for i in range(1, n+1): if d[i] == k: res+=1 print(res) ```
vfc_136137
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1000000 166\n", "output": "381\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000 100\n", "output": "326\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "423496 330\n", "output": "651\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/780/D
Solve the following coding problem using the programming language python: Innokenty is a president of a new football league in Byteland. The first task he should do is to assign short names to all clubs to be shown on TV next to the score. Of course, the short names should be distinct, and Innokenty wants that all short names consist of three letters. Each club's full name consist of two words: the team's name and the hometown's name, for example, "DINAMO BYTECITY". Innokenty doesn't want to assign strange short names, so he wants to choose such short names for each club that: the short name is the same as three first letters of the team's name, for example, for the mentioned club it is "DIN", or, the first two letters of the short name should be the same as the first two letters of the team's name, while the third letter is the same as the first letter in the hometown's name. For the mentioned club it is "DIB". Apart from this, there is a rule that if for some club x the second option of short name is chosen, then there should be no club, for which the first option is chosen which is the same as the first option for the club x. For example, if the above mentioned club has short name "DIB", then no club for which the first option is chosen can have short name equal to "DIN". However, it is possible that some club have short name "DIN", where "DI" are the first two letters of the team's name, and "N" is the first letter of hometown's name. Of course, no two teams can have the same short name. Help Innokenty to choose a short name for each of the teams. If this is impossible, report that. If there are multiple answer, any of them will suit Innokenty. If for some team the two options of short name are equal, then Innokenty will formally think that only one of these options is chosen. -----Input----- The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of clubs in the league. Each of the next n lines contains two words — the team's name and the hometown's name for some club. Both team's name and hometown's name consist of uppercase English letters and have length at least 3 and at most 20. -----Output----- It it is not possible to choose short names and satisfy all constraints, print a single line "NO". Otherwise, in the first line print "YES". Then print n lines, in each line print the chosen short name for the corresponding club. Print the clubs in the same order as they appeared in input. If there are multiple answers, print any of them. -----Examples----- Input 2 DINAMO BYTECITY FOOTBALL MOSCOW Output YES DIN FOO Input 2 DINAMO BYTECITY DINAMO BITECITY Output NO Input 3 PLAYFOOTBALL MOSCOW PLAYVOLLEYBALL SPB GOGO TECHNOCUP Output YES PLM PLS GOG Input 3 ABC DEF ABC EFG ABD OOO Output YES ABD ABE ABO -----Note----- In the first sample Innokenty can choose first option for both clubs. In the second example it is not possible to choose short names, because it is not possible that one club has first option, and the other has second option if the first options are equal for both clubs. In the third example Innokenty can choose the second options for the first two clubs, and the first option for the third club. In the fourth example note that it is possible that the chosen short name for some club x is the same as the first option of another club y if the first options of x and y are different. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) ans = 0 o = [] p = [] for i in range(n): (s, g) = [str(j) for j in input().split()] ss = s[0:3] gg = s[0:2] + g[0] flag = True if ss in o: flag = False o.append(ss) if gg in p and ss not in p and flag: p.append(ss) elif gg not in p: p.append(gg) else: ans = -1 if ans < 0: print('NO') else: print('YES') for i in p: print(i) ```
vfc_136145
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/780/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nDINAMO BYTECITY\nFOOTBALL MOSCOW\n", "output": "YES\nDIN\nFOO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/rotate-page0923/1
Solve the following coding problem using the programming language python: You are given three points a(a1, a2), b(b1, b2) and c(c1, c2) on a page. Find if it’s possible to rotate the page in any direction by any angle, such that the new position of a is same as the old position of b, and the new position of b is same as the old position of c. Example 1: Input: a1 = 1, a2 = 1 b1 = 1, b2 = 1 c1 = 1, c2 = 0 Output: 0 Explanation: Not possible. Example 2: Input: a1 = 0, a2 = 1 b1 = 1, b2 = 1 c1 = 1, c2 = 0 Output: 1 Explanation: Rotate the page by 90 degree. Your Task: You dont need to read input or print anything. Complete the function possibleOrNot() which takes a1, a2, b1, b2, c1 and c2 as input parameters and returns 1 if it is possible to rotate the page or 0 otherwise. Expected Time Complexity: O(1) Expected Auxiliary Space: O(1) Constraints: 0 ≤ a1, a2, b1, b2, c1, c2 ≤ 100 Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def possibleOrNot(self, a1, a2, b1, b2, c1, c2): # code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math class Solution: def possibleOrNot(self, a1, a2, b1, b2, c1, c2): d1 = math.sqrt((b1 - a1) ** 2 + (b2 - a2) ** 2) d2 = math.sqrt((b1 - c1) ** 2 + (b2 - c2) ** 2) if d1 == d2: return 1 else: return 0 ```
vfc_136150
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/rotate-page0923/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "a1 = 1, a2 = 1\nb1 = 1, b2 = 1\nc1 = 1, c2 = 0", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "a1 = 0, a2 = 1\nb1 = 1, b2 = 1\nc1 = 1, c2 = 0", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Short Phrase A Short Phrase (aka. Tanku) is a fixed verse, inspired by Japanese poetry Tanka and Haiku. It is a sequence of words, each consisting of lowercase letters 'a' to 'z', and must satisfy the following condition: > (The Condition for a Short Phrase) > The sequence of words can be divided into five sections such that the total number of the letters in the word(s) of the first section is five, that of the second is seven, and those of the rest are five, seven, and seven, respectively. The following is an example of a Short Phrase. > > do the best > and enjoy today > at acm icpc > In this example, the sequence of the nine words can be divided into five sections (1) "do" and "the", (2) "best" and "and", (3) "enjoy", (4) "today" and "at", and (5) "acm" and "icpc" such that they have 5, 7, 5, 7, and 7 letters in this order, respectively. This surely satisfies the condition of a Short Phrase. Now, Short Phrase Parnassus published by your company has received a lot of contributions. By an unfortunate accident, however, some irrelevant texts seem to be added at beginnings and ends of contributed Short Phrases. Your mission is to write a program that finds the Short Phrase from a sequence of words that may have an irrelevant prefix and/or a suffix. Input The input consists of multiple datasets, each in the following format. > n > w1 > ... > wn > Here, n is the number of words, which is a positive integer not exceeding 40; wi is the i-th word, consisting solely of lowercase letters from 'a' to 'z'. The length of each word is between 1 and 10, inclusive. You can assume that every dataset includes a Short Phrase. The end of the input is indicated by a line with a single zero. Output For each dataset, output a single line containing i where the first word of the Short Phrase is wi. When multiple Short Phrases occur in the dataset, you should output the first one. Sample Input 9 do the best and enjoy today at acm icpc 14 oh yes by far it is wow so bad to me you know hey 15 abcde fghijkl mnopq rstuvwx yzz abcde fghijkl mnopq rstuvwx yz abcde fghijkl mnopq rstuvwx yz 0 Output for the Sample Input 1 2 6 Example Input 9 do the best and enjoy today at acm icpc 14 oh yes by far it is wow so bad to me you know hey 15 abcde fghijkl mnopq rstuvwx yzz abcde fghijkl mnopq rstuvwx yz abcde fghijkl mnopq rstuvwx yz 0 Output 1 2 6 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python tanku = [5, 7, 5, 7, 7] while True: n = int(input()) if n == 0: break w = [len(input()) for i in range(n)] ans = 0 for i in range(n): sum = 0 k = 0 for j in range(i, n): sum += w[j] if sum == tanku[k]: sum = 0 k += 1 if k == 5: ans = i + 1 break elif sum > tanku[k]: break if ans: break print(ans) ```
vfc_136151
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9\ndo\nhte\nbest\nand\nenjoy\ntoday\nat\nacm\nicpc\n14\noh\nyes\nby\nfar\nit\nis\nwow\nso\nbad\nto\nme\nyou\nknow\nhey\n15\nabcde\nfghijkl\nmnopq\nrstuvwx\nyzz\nabcde\nfghijkl\nmnopq\nrstuvwx\nyz\nabcde\nfghijkl\nmnopq\nrstuvwx\nyz\n0", "output": "1\n2\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\ndo\nhet\nbest\n`nd\nenjoy\ntoday\nat\nacm\nicpc\n0\noh\nyes\nby\nfar\nit\nis\nwow\nso\nbda\nto\nmd\nyou\nknow\nhey\n15\nedcba\nfghijkl\nmnopq\nrstuvwx\nyzz\nabcde\nlkkihgf\nmnopq\nxwvutsr\nyz\nabcde\nfghijkl\nmnopq\nrstuvwx\nyz\n0", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\ndo\nhte\nbest\nand\nenjoy\ntoday\nat\nacm\nicpc\n14\noh\nyes\nby\nfar\nit\nis\nwow\nso\nbad\nto\nme\nyou\nknow\nhey\n15\nabcde\nfghijkl\nmnopq\nrstuvwx\nyyz\nabcde\nfghijkl\nmnopq\nrstuvwx\nyz\nabcde\nfghijkl\nmnopq\nrstuvwx\nyz\n0", "output": "1\n2\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\ndo\nhte\nbest\nand\nenjoy\ntoday\nat\nacm\nicpc\n14\noh\nyes\nby\nfar\nit\nis\nwow\nso\nbad\nto\nme\nyou\nknow\nhey\n15\nabcde\nfghijkl\nmnopq\nrstuvwx\nyyz\nabcde\nfghijkl\nmnopq\nrstuvwx\nyz\nabcde\nfghijkl\nmnopq\nrstuvwx\nyy\n0", "output": "1\n2\n6\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/FLOW001
Solve the following coding problem using the programming language python: Shivam is the youngest programmer in the world, he is just 12 years old. Shivam is learning programming and today he is writing his first program. Program is very simple, Given two integers A and B, write a program to add these two numbers. -----Input----- The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains two Integers A and B. -----Output----- For each test case, add A and B and display it in a new line. -----Constraints----- - 1 ≤ T ≤ 1000 - 0 ≤ A,B ≤ 10000 -----Example----- Input 3 1 2 100 200 10 40 Output 3 300 50 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python T = int(input()) for tc in range(T): (a, b) = list(map(int, input().split(' '))) ans = a + b print(ans) ```
vfc_136156
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FLOW001", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2\n100 200\n10 40\n", "output": "3\n300\n50\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/column-name-from-a-given-column-number4244/1
Solve the following coding problem using the programming language python: Given a positive integer, return its corresponding column title as appear in an Excel sheet. Excel columns has a pattern like A, B, C, … ,Z, AA, AB, AC,…. ,AZ, BA, BB, … ZZ, AAA, AAB ….. etc. In other words, column 1 is named as “A”, column 2 as “B”, column 27 as “AA” and so on. Example 1: Input: N = 28 Output: AB Explanation: 1 to 26 are A to Z. Then, 27 is AA and 28 = AB. ​Example 2: Input: N = 13 Output: M Explanation: M is the 13th character of alphabet. Your Task: You don't need to read input or print anything. Your task is to complete the function colName() which takes the column number N as input and returns the column name represented as a string. Expected Time Complexity: O(LogN). Expected Auxiliary Space: O(1). Constraints: 1 <= N <= 4294967295 Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def colName (self, n): # your code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def colName(self, n): str1 = '' while n != 0: if n % 26 == 0: str1 = 'Z' + str1 n = (n - 1) // 26 else: str1 = chr(n % 26 - 1 + 65) + str1 n = n // 26 return str1 ```
vfc_136160
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/column-name-from-a-given-column-number4244/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 28", "output": "AB", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 13", "output": "M", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/python-time-delta/problem
Solve the following coding problem using the programming language python: When users post an update on social media,such as a URL, image, status update etc., other users in their network are able to view this new post on their news feed. Users can also see exactly when the post was published, i.e, how many hours, minutes or seconds ago. Since sometimes posts are published and viewed in different time zones, this can be confusing. You are given two timestamps of one such post that a user can see on his newsfeed in the following format: Day dd Mon yyyy hh:mm:ss +xxxx Here +xxxx represents the time zone. Your task is to print the absolute difference (in seconds) between them. Input Format The first line contains $\mathbf{T}$, the number of testcases. Each testcase contains $2$ lines, representing time $\boldsymbol{t_1}$ and time $t_2$. Constraints Input contains only valid timestamps $year\:\leq3000$. Output Format Print the absolute difference $(t_1-t_2)$ in seconds. Sample Input 0 2 Sun 10 May 2015 13:54:36 -0700 Sun 10 May 2015 13:54:36 -0000 Sat 02 May 2015 19:54:36 +0530 Fri 01 May 2015 13:54:36 -0000 Sample Output 0 25200 88200 Explanation 0 In the first query, when we compare the time in UTC for both the time stamps, we see a difference of 7 hours. which is $7\times3600$ seconds or $25200$ seconds. Similarly, in the second query, time difference is 5 hours and 30 minutes for time zone adjusting for that we have a difference of 1 day and 30 minutes. Or $24\times3600+30\times60\Rightarrow88200$ The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from datetime import datetime, timedelta s = '%a %d %b %Y %H:%M:%S %z' t = int(input()) for _ in range(t): a = datetime.strptime(input(), s) b = datetime.strptime(input(), s) print(int(abs(timedelta.total_seconds(b - a)))) ```
vfc_136165
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/python-time-delta/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\nSun 10 May 2015 13:54:36 -0700\nSun 10 May 2015 13:54:36 -0000\nSat 02 May 2015 19:54:36 +0530\nFri 01 May 2015 13:54:36 -0000\n", "output": "25200\n88200\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/reverse-alternate-levels-of-a-perfect-binary-tree/1
Solve the following coding problem using the programming language python: Given a complete binary tree, reverse the nodes present at alternate levels. Example 1: Input: 1 / \ 3 2 Output: 1 / \ 2 3 Explanation: Nodes at level 2 are reversed. Example 2: Input: 1 / \ 2 3 / \ / \ 42 51 63 72 Output: 1 / \ 3 2 / \ / \ 42 51 63 72 Explanation: Nodes at level 2 are reversed. Level 1 and 3 remain as it is. Your Task: You dont need to read input or print anything. Complete the function reverseAlternate() which takes root node as input parameter and modifies the given tree in-place. Note: If you click on Compile and Test the output will be the in-order traversal of the modified tree. Expected Time Complexity: O(N) Expected Auxiliary Space: O(height of tree) Constraints: 1 ≤ N ≤ 10^4 Write your solution by modifying this code: ```python #User function Template for python3 ''' class Node: def __init__(self,val): self.data = val self.left = None self.right = None ''' def reverseAlternate(root): ''' :param root: root of given tree. ''' # code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def reverseAlternate(root): q = [root] lev = 0 while q: l = len(q) tmp = [] for i in range(l): p = q[i] if lev % 2 == 0: if p.left: tmp.append(p.left.data) if p.right: tmp.append(p.right.data) tmp = tmp[::-1] a = 0 for i in range(l): p = q.pop(0) if lev % 2 == 0: if p.left and p.right: (p.left.data, p.right.data) = (tmp[a], tmp[a + 1]) a += 2 if p.left: q.append(p.left) if p.right: q.append(p.right) lev += 1 ```
vfc_136169
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/reverse-alternate-levels-of-a-perfect-binary-tree/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\r\n / \\\r\n 3 2", "output": "1\r\n / \\\r\n 2 3", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\r\n / \\\r\n 2 3\r\n / \\ / \\\r\n 42 51 63 72", "output": "1\r\n / \\\r\n 2 3\r\n / \\ / \\\r\n 42 51 63 72", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/391/B
Solve the following coding problem using the programming language python: You will receive 5 points for solving this problem. Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part of the string above first part, running in the opposite direction and aligned to the position of the fold. Using this operation, Manao converts the string into a structure that has one more level than there were fold operations performed. See the following examples for clarity. We will denote the positions of folds with '|' characters. For example, the word "ABRACADABRA" written as "AB|RACA|DAB|RA" indicates that it has been folded three times: first, between the leftmost pair of 'B' and 'R' letters; second, between 'A' and 'D'; and third, between the rightmost pair of 'B' and 'R' letters. Here are several examples of folded strings: "ABCDEF|GHIJK" | "A|BCDEFGHIJK" | "AB|RACA|DAB|RA" | "X|XXXXX|X|X|XXXXXX" | | | XXXXXX KJIHG | KJIHGFEDCB | AR | X ABCDEF | A | DAB | X | | ACAR | XXXXX | | AB | X One last example for "ABCD|EFGH|IJ|K": K IJ HGFE ABCD Manao noticed that each folded string can be viewed as several piles of letters. For instance, in the previous example, there are four piles, which can be read as "AHI", "BGJK", "CF", and "DE" from bottom to top. Manao wonders what is the highest pile of identical letters he can build using fold operations on a given word. Note that the pile should not contain gaps and should start at the bottom level. For example, in the rightmost of the four examples above, none of the piles would be considered valid since each of them has gaps, starts above the bottom level, or both. -----Input----- The input will consist of one line containing a single string of n characters with 1 ≤ n ≤ 1000 and no spaces. All characters of the string will be uppercase letters. This problem doesn't have subproblems. You will get 5 points for the correct submission. -----Output----- Print a single integer — the size of the largest pile composed of identical characters that can be seen in a valid result of folding operations on the given string. -----Examples----- Input ABRACADABRA Output 3 Input ABBBCBDB Output 3 Input AB Output 1 -----Note----- Consider the first example. Manao can create a pile of three 'A's using the folding "AB|RACAD|ABRA", which results in the following structure: ABRA DACAR AB In the second example, Manao can create a pile of three 'B's using the following folding: "AB|BB|CBDB". CBDB BB AB Another way for Manao to create a pile of three 'B's with "ABBBCBDB" is the following folding: "AB|B|BCBDB". BCBDB B AB In the third example, there are no folds performed and the string is just written in one line. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python t = {} for (i, c) in enumerate(input()): if c not in t: t[c] = (i, 1) elif t[c][0] - i & 1: t[c] = (i, t[c][1] + 1) print(max((b for (a, b) in list(t.values())))) ```
vfc_136174
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/391/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "ABRACADABRA\n", "output": "3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "ABBBCBDB\n", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/number-of-pairs-1587115620/1
Solve the following coding problem using the programming language python: Given two arrays X and Y of positive integers, find the number of pairs such that x^{y} > y^{x} (raised to power of) where x is an element from X and y is an element from Y. Example 1: Input: M = 3, X[] = [2 1 6] N = 2, Y[] = [1 5] Output: 3 Explanation: The pairs which follow x^{y} > y^{x} are as such: 2^{1} > 1^{2}, 2^{5} > 5^{2} and 6^{1} > 1^{6 .} Example 2: Input: M = 4, X[] = [2 3 4 5] N = 3, Y[] = [1 2 3] Output: 5 Explanation: The pairs for the given input are 2^{1 }> 1^{2} , 3^{1} > 1^{3 }, 3^{2} > 2^{3} , 4^{1} > 1^{4} , 5^{1} > 1^{5 }. Your Task: This is a function problem. You only need to complete the function countPairs() that takes X, Y, M, N as parameters and returns the total number of pairs. Expected Time Complexity: O((N + M)log(N)). Expected Auxiliary Space: O(1). Constraints: 1 ≤ M, N ≤ 10^{5} 1 ≤ X[i], Y[i] ≤ 10^{3} Write your solution by modifying this code: ```python #User function Template for python3 class Solution: #Function to count number of pairs such that x^y is greater than y^x. def countPairs(self,a,b,M,N): #code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def countPairs(self, a, b, M, N): from bisect import bisect as bi a.sort() b.sort() ans = 0 for X in a: if X == 1: continue elif X == 2: ans += bi(b, 1) + N - bi(b, 4) elif X == 3: ans += bi(b, 2) + N - bi(b, 3) else: ans += bi(b, 1) + N - bi(b, X) return ans ```
vfc_136182
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/number-of-pairs-1587115620/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "M = 3, X[] = [2 1 6] \r\nN = 2, Y[] = [1 5]", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/52/B
Solve the following coding problem using the programming language python: You are given a n × m field consisting only of periods ('.') and asterisks ('*'). Your task is to count all right triangles with two sides parallel to the square sides, whose vertices are in the centers of '*'-cells. A right triangle is a triangle in which one angle is a right angle (that is, a 90 degree angle). Input The first line contains two positive integer numbers n and m (1 ≤ n, m ≤ 1000). The following n lines consist of m characters each, describing the field. Only '.' and '*' are allowed. Output Output a single number — total number of square triangles in the field. Please, do not use %lld specificator to read or write 64-bit integers in C++. It is preffered to use cout (also you may use %I64d). Examples Input 2 2 ** *. Output 1 Input 3 4 *..* .**. *.** Output 9 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python (n, m) = map(int, input().split()) grid = [input() for _ in range(n)] a = [[0 for _ in range(m)] for i in range(n)] b = [[0 for _ in range(m)] for i in range(n)] for i in range(n): for j in range(m): a[i][j] = a[i][j - 1] + (grid[i][j] == '*') if i: b[i][j] = b[i - 1][j] b[i][j] += grid[i][j] == '*' ans = 0 for i in range(n): for j in range(m): if grid[i][j] == '*': l = r = u = d = 0 if j: l = a[i][j - 1] r = a[i][-1] - a[i][j] if i: u = b[i - 1][j] d = b[-1][j] - b[i][j] ans += (l + r) * (u + d) print(ans) ```
vfc_136183
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/52/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 3\n*.*\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n*.\n**\n.*\n..\n.*\n", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 2\n**\n**\n**\n*.\n*.\n", "output": "18", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/BUDGET_
Solve the following coding problem using the programming language python: Akshat has X rupees to spend in the current month. His daily expenditure is Y rupees, i.e., he spends Y rupees each day. Given that the current month has 30 days, find out if Akshat has enough money to meet his daily expenditures for this month. ------ Input Format ------ - The first line will contain T - the number of test cases. Then the test cases follow. - The first and only line of each test case contains two integers X, Y - the amount of money Akshat has for the current month and his daily expenditure respectively. ------ Output Format ------ For each test case, output YES if Akshat has enough money to meet his daily expenditure for 30 days of the month, otherwise output NO. You may print each character of YES and NO in uppercase or lowercase (for example, yes, yEs, Yes will be considered identical). ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ X, Y ≤ 10^{5}$ ----- Sample Input 1 ------ 3 1000 10 250 50 1500 50 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test Case $1$: Akshat has $1000$ rupees and he wants to spend $30 \times 10 = 300$ rupees in the entire month. Therefore, he has enough money for the entire month. Test Case $2$: Akshat has $250$ rupees and he wants to spend $30 \times 50 = 1500$ rupees in the entire month. Therefore, he does not have enough money for the entire month. Test Case $3$: Akshat has $1500$ rupees and he wants to spend $30 \times 50 = 1500$ rupees in the entire month. Therefore, he has enough money for the entire month. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for i in range(int(input())): (x, y) = map(int, input().split()) if x >= y * 30: print('YES') else: print('NO') ```
vfc_136187
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/BUDGET_", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1000 10\n250 50\n1500 50\n", "output": "YES\nNO\nYES\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/stickler-theif-1587115621/1
Solve the following coding problem using the programming language python: Stickler the thief wants to loot money from a society having n houses in a single line. He is a weird person and follows a certain rule when looting the houses. According to the rule, he will never loot two consecutive houses. At the same time, he wants to maximize the amount he loots. The thief knows which house has what amount of money but is unable to come up with an optimal looting strategy. He asks for your help to find the maximum money he can get if he strictly follows the rule. Each house has a[i]amount of money present in it. Example 1: Input: n = 6 a[] = {5,5,10,100,10,5} Output: 110 Explanation: 5+100+5=110 Example 2: Input: n = 3 a[] = {1,2,3} Output: 4 Explanation: 1+3=4 Your Task: Complete the functionFindMaxSum()which takes an array arr[] and n as input which returns the maximum money he can get following the rules Expected Time Complexity:O(N). Expected Space Complexity:O(N). Constraints: 1 ≤ n ≤ 10^{4} 1 ≤ a[i] ≤ 10^{4} Write your solution by modifying this code: ```python #User function Template for python3 class Solution: #Function to find the maximum money the thief can get. def FindMaxSum(self,a, n): # code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def FindMaxSum(self, a, n): incl = 0 excl = 0 for i in a: new_excl = max(incl, excl) incl = excl + i excl = new_excl return max(incl, excl) ```
vfc_136199
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/stickler-theif-1587115621/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "n = 6\r\na[] = {5,5,10,100,10,5}", "output": "110", "type": "stdin_stdout" }, { "fn_name": null, "input": "n = 3\r\na[] = {1,2,3}", "output": "4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/544/A
Solve the following coding problem using the programming language python: You are given a string q. A sequence of k strings s_1, s_2, ..., s_{k} is called beautiful, if the concatenation of these strings is string q (formally, s_1 + s_2 + ... + s_{k} = q) and the first characters of these strings are distinct. Find any beautiful sequence of strings or determine that the beautiful sequence doesn't exist. -----Input----- The first line contains a positive integer k (1 ≤ k ≤ 26) — the number of strings that should be in a beautiful sequence. The second line contains string q, consisting of lowercase Latin letters. The length of the string is within range from 1 to 100, inclusive. -----Output----- If such sequence doesn't exist, then print in a single line "NO" (without the quotes). Otherwise, print in the first line "YES" (without the quotes) and in the next k lines print the beautiful sequence of strings s_1, s_2, ..., s_{k}. If there are multiple possible answers, print any of them. -----Examples----- Input 1 abca Output YES abca Input 2 aaacas Output YES aaa cas Input 4 abc Output NO -----Note----- In the second sample there are two possible answers: {"aaaca", "s"} and {"aaa", "cas"}. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) s = input() res = '' dic = set() num = 0 for (i, c) in enumerate(s): if c in dic: res += c else: res += '\n' dic.add(c) num += 1 if num == n: res += s[i:] break else: res += c if num != n: print('NO') else: print('YES' + res) ```
vfc_136200
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/544/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\nabca\n", "output": "YES\nabca\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\naaacas\n", "output": "YES\naaa\ncas\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nabc\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nnddkhkhkdndknndkhrnhddkrdhrnrrnkkdnnndndrdhnknknhnrnnkrrdhrkhkrkhnkhkhhrhdnrndnknrrhdrdrkhdrkkhkrnkk\n", "output": "YES\nn\ndd\nkhkhkdndknndkhrnhddkrdhrnrrnkkdnnndndrdhnknknhnrnnkrrdhrkhkrkhnkhkhhrhdnrndnknrrhdrdrkhdrkkhkrnkk\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "26\nbiibfmmfifmffbmmfmbmbmiimbmiffmffibibfbiffibibiiimbffbbfbifmiibffbmbbbfmfibmibfffibfbffmfmimbmmmfmfm\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\nkydoybxlfeugtrbvqnrjtzshorrsrwsxkvlwyolbaadtzpmyyfllxuciia\n", "output": "YES\nk\ny\ndoybxlfeugtrbvqnrjtzshorrsrwsxkvlwyolbaadtzpmyyfllxuciia\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/detect-cycle-in-an-undirected-graph/1
Solve the following coding problem using the programming language python: Given an undirected graph with V vertices and E edges, check whether it contains any cycle or not. Graph is in the form of adjacency list where adj[i] contains all the nodes ith node is having edge with. Example 1: Input: V = 5, E = 5 adj = {{1}, {0, 2, 4}, {1, 3}, {2, 4}, {1, 3}} Output: 1 Explanation: 1->2->3->4->1 is a cycle. Example 2: Input: V = 4, E = 2 adj = {{}, {2}, {1, 3}, {2}} Output: 0 Explanation: No cycle in the graph. Your Task: You don't need to read or print anything. Your task is to complete the function isCycle() which takes V denoting the number of vertices and adjacency list as input parameters and returns a boolean value denoting if the undirected graph contains any cycle or not, return 1 if a cycle is present else return 0. NOTE: The adjacency list denotes the edges of the graph where edges[i] stores all other vertices to which ith vertex is connected. Expected Time Complexity: O(V + E) Expected Space Complexity: O(V) Constraints: 1 ≤ V, E ≤ 10^{5} Write your solution by modifying this code: ```python from typing import List class Solution: #Function to detect cycle in an undirected graph. def isCycle(self, V: int, adj: List[List[int]]) -> bool: #Code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from typing import List class Solution: def isCyclicHelper(self, si, adj, visited, parent): visited[si] = True for i in adj[si]: if visited[i] is False: if self.isCyclicHelper(i, adj, visited, si): return True elif visited[i] is True and i != parent: return True return False def isCycle(self, V: int, adj: List[List[int]]) -> bool: visited = [False for i in range(V)] for node in range(V): if visited[node] is False: if self.isCyclicHelper(node, adj, visited, 0): return True return False ```
vfc_136205
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/detect-cycle-in-an-undirected-graph/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "V = 5, E = 5\nadj = {{1}, {0, 2, 4}, {1, 3}, {2, 4}, {1, 3}}", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "V = 4, E = 2\nadj = {{}, {2}, {1, 3}, {2}}", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1602/B
Solve the following coding problem using the programming language python: Black is gifted with a Divine array $a$ consisting of $n$ ($1 \le n \le 2000$) integers. Each position in $a$ has an initial value. After shouting a curse over the array, it becomes angry and starts an unstoppable transformation. The transformation consists of infinite steps. Array $a$ changes at the $i$-th step in the following way: for every position $j$, $a_j$ becomes equal to the number of occurrences of $a_j$ in $a$ before starting this step. Here is an example to help you understand the process better: Initial array: $2$ $1$ $1$ $4$ $3$ $1$ $2$ After the $1$-st step: $2$ $3$ $3$ $1$ $1$ $3$ $2$ After the $2$-nd step: $2$ $3$ $3$ $2$ $2$ $3$ $2$ After the $3$-rd step: $4$ $3$ $3$ $4$ $4$ $3$ $4$ ... ... In the initial array, we had two $2$-s, three $1$-s, only one $4$ and only one $3$, so after the first step, each element became equal to the number of its occurrences in the initial array: all twos changed to $2$, all ones changed to $3$, four changed to $1$ and three changed to $1$. The transformation steps continue forever. You have to process $q$ queries: in each query, Black is curious to know the value of $a_x$ after the $k$-th step of transformation. -----Input----- Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 1000$). Description of the test cases follows. The first line of each test case contains an integer $n$ ($1 \le n \le 2000$) — the size of the array $a$. The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le n$) — the initial values of array $a$. The third line of each test case contains a single integer $q$ ($1 \le q \le 100000$) — the number of queries. Next $q$ lines contain the information about queries — one query per line. The $i$-th line contains two integers $x_i$ and $k_i$ ($1 \le x_i \le n$; $0 \le k_i \le 10^9$), meaning that Black is asking for the value of $a_{x_i}$ after the $k_i$-th step of transformation. $k_i = 0$ means that Black is interested in values of the initial array. It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$ and the sum of $q$ over all test cases doesn't exceed $100000$. -----Output----- For each test case, print $q$ answers. The $i$-th of them should be the value of $a_{x_i}$ after the $k_i$-th step of transformation. It can be shown that the answer to each query is unique. -----Examples----- Input 2 7 2 1 1 4 3 1 2 4 3 0 1 1 2 2 6 1 2 1 1 2 1 0 2 1000000000 Output 1 2 3 3 1 2 -----Note----- The first test case was described ih the statement. It can be seen that: $k_1 = 0$ (initial array): $a_3 = 1$; $k_2 = 1$ (after the $1$-st step): $a_1 = 2$; $k_3 = 2$ (after the $2$-nd step): $a_2 = 3$; $k_4 = 1$ (after the $1$-st step): $a_6 = 3$. For the second test case, Initial array: $1$ $1$ After the $1$-st step: $2$ $2$ After the $2$-nd step: $2$ $2$ ... ... It can be seen that: $k_1 = 0$ (initial array): $a_1 = 1$; $k_2 = 1000000000$: $a_2 = 2$; The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys inp = sys.stdin.readline def solve(): n = int(inp()) a = [list(map(int, inp().split()))] while True: c = [0] * (n + 1) for i in a[-1]: c[i] += 1 b = [c[i] for i in a[-1]] if b == a[-1]: break a.append(b) ans = [] for i in range(int(inp())): (x, k) = map(int, inp().split()) ans.append(str(a[min(len(a) - 1, k)][x - 1])) print('\n'.join(ans)) def main(): for i in range(int(inp())): solve() main() ```
vfc_136206
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1602/B", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n7\n2 1 1 4 3 1 2\n4\n3 0\n1 1\n2 2\n6 1\n2\n1 1\n2\n1 0\n2 1000000000\n", "output": "1\n2\n3\n3\n1\n2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-the-maximum-number-of-handshakes2349/1
Solve the following coding problem using the programming language python: There are N people in a room. If two persons shake hands exactly once, find the maximum number of handshakes possible. Example 1: Input: N = 2 Output: 1 Explaination: There are two people and they can shake hands maximum one time. Example 2: Input: N = 3 Output: 3 Explaination: Let the people be person 1, 2 and 3. So the possible handshakes are (1, 2), (2, 3) and (1, 3). Your Task: You do not need to read input or print anything. Your task is to complete the function handShakes() which takes N as input parameter and returns the maximum number of handshakes possible. Expected Time Complexity: O(1) Expected Auxiliary Space: O(1) Constraints: 2 ≤ N ≤ 10^{9} Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def handShakes(self, N): # code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def handShakes(self, N): return N * (N - 1) // 2 ```
vfc_136210
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-the-maximum-number-of-handshakes2349/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 2", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3", "output": "3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1295/D
Solve the following coding problem using the programming language python: You are given two integers $a$ and $m$. Calculate the number of integers $x$ such that $0 \le x < m$ and $\gcd(a, m) = \gcd(a + x, m)$. Note: $\gcd(a, b)$ is the greatest common divisor of $a$ and $b$. -----Input----- The first line contains the single integer $T$ ($1 \le T \le 50$) — the number of test cases. Next $T$ lines contain test cases — one per line. Each line contains two integers $a$ and $m$ ($1 \le a < m \le 10^{10}$). -----Output----- Print $T$ integers — one per test case. For each test case print the number of appropriate $x$-s. -----Example----- Input 3 4 9 5 10 42 9999999967 Output 6 1 9999999966 -----Note----- In the first test case appropriate $x$-s are $[0, 1, 3, 4, 6, 7]$. In the second test case the only appropriate $x$ is $0$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math t = int(input()) def phi(n): res = n i = 2 while i * i <= n: if n % i == 0: res /= i res *= i - 1 while n % i == 0: n /= i i += 1 if n > 1: res /= n res *= n - 1 return int(res) while t: (a, m) = list(map(int, input().split())) g = math.gcd(a, m) print(phi(m // g)) t -= 1 ```
vfc_136211
{ "difficulty": "medium_hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1295/D", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4 9\n5 10\n42 9999999967\n", "output": "6\n1\n9999999966\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n1 2\n1 3\n1 4\n3 5\n3 6\n3 7\n1 8\n7 9\n8 10\n1 11\n", "output": "1\n2\n2\n4\n1\n6\n4\n6\n4\n10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n20 52\n48 53\n36 54\n23 55\n14 56\n54 57\n34 58\n33 59\n10 60\n21 61\n", "output": "12\n52\n2\n40\n2\n18\n28\n58\n2\n60\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/REARRSTR
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian as well. Today is Devu's birthday. He has obtained few colored balloons from his friends. You are given this information by a string s consisting of lower case English Latin letters. Each letter (from 'a' to 'z') denotes a color. e.g. if s = "aab", then it means that he has received two balloons of color 'a' whereas one balloon of color 'b'. Now, Devu wants to decorate the cake by arranging all the balloons linearly from left to right on the cake such that no same colored balloons are nearby/ adjacent to each other. Now Devu wonders whether it is possible to do so or not? Please help him in this. If it is not possible to do so, print -1. Otherwise, print any one of arrangements of the balloons on the cake. If there are more than one possible ways of doing so, you can print any one of them. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. First line of each test case will contain string s ------ Output ------ Print a single line corresponding to the answer of the problem. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $1 ≤ size of string s ≤ 10^{5}$ $Sum of size of string s over all test cases will be less than or equal to ≤ 10^{6}$ ----- Sample Input 1 ------ 3 aab ab aa ----- Sample Output 1 ------ aba ab -1 ----- explanation 1 ------ Example case 1. He can arrange the balloons in the order given by the following string "aba". Example case 2. He can arrange the balloons in the order given by the following string "ab" Example case 3. There is no valid way of decorating cakes with balloon in the desired way. So we print -1. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for _ in range(int(input())): s = list(input()) s.sort() n = len(s) s.append('0') l = [] (a, c) = (s[0], 1) for i in range(1, n + 1): if s[i] != s[i - 1]: l.append([a, c]) (a, c) = (s[i], 1) else: c += 1 s1 = '' a = max(l, key=lambda x: x[1]) a1 = l.index(a) while len(l) > 1: p = a[:] s1 += p[0] p[1] -= 1 del l[a1] a = max(l, key=lambda x: x[1]) a1 = l.index(a) if p[1] > 0: l.append(p) if l[0][1] == 1: s1 += l[0][0] print(s1) else: print(-1) ```
vfc_136215
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/REARRSTR", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\naab\nab\naa", "output": "aba\nab\n-1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/290/B
Solve the following coding problem using the programming language python: [Image] -----Input----- The input contains two integers a_1, a_2 (0 ≤ a_{i} ≤ 32), separated by a single space. -----Output----- Output a single integer. -----Examples----- Input 1 1 Output 0 Input 3 7 Output 0 Input 13 10 Output 1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python (a, b) = map(int, input().split()) b = str(b) c = '' for i in b: c = i + c print(a + int(c)) ```
vfc_136219
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/290/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 7\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "13 10\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 12\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1184/A1
Solve the following coding problem using the programming language python: Melody Pond was stolen from her parents as a newborn baby by Madame Kovarian, to become a weapon of the Silence in their crusade against the Doctor. Madame Kovarian changed Melody's name to River Song, giving her a new identity that allowed her to kill the Eleventh Doctor. Heidi figured out that Madame Kovarian uses a very complicated hashing function in order to change the names of the babies she steals. In order to prevent this from happening to future Doctors, Heidi decided to prepare herself by learning some basic hashing techniques. The first hashing function she designed is as follows. Given two positive integers $(x, y)$ she defines $H(x,y):=x^2+2xy+x+1$. Now, Heidi wonders if the function is reversible. That is, given a positive integer $r$, can you find a pair $(x, y)$ (of positive integers) such that $H(x, y) = r$? If multiple such pairs exist, output the one with smallest possible $x$. If there is no such pair, output "NO". -----Input----- The first and only line contains an integer $r$ ($1 \le r \le 10^{12}$). -----Output----- Output integers $x, y$ such that $H(x,y) = r$ and $x$ is smallest possible, or "NO" if no such pair exists. -----Examples----- Input 19 Output 1 8 Input 16 Output NO The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math n = int(input()) flag = 0 for x in range(1, int(math.sqrt(n))): if (pow(x, 2) + x + 1 - n) / (-2 * x) == int((pow(x, 2) + x + 1 - n) / (-2 * x)): print(x, (pow(x, 2) + x + 1 - n) // -2 * x) flag = 1 break if flag == 0: print('NO') ```
vfc_136227
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1184/A1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "19\n", "output": "1 8\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "16\n", "output": "NO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1287/E1
Solve the following coding problem using the programming language python: This problem is different with hard version only by constraints on total answers length It is an interactive problem Venya joined a tour to the madhouse, in which orderlies play with patients the following game. Orderlies pick a string s of length n, consisting only of lowercase English letters. The player can ask two types of queries: * ? l r – ask to list all substrings of s[l..r]. Substrings will be returned in random order, and in every substring, all characters will be randomly shuffled. * ! s – guess the string picked by the orderlies. This query can be asked exactly once, after that the game will finish. If the string is guessed correctly, the player wins, otherwise he loses. The player can ask no more than 3 queries of the first type. To make it easier for the orderlies, there is an additional limitation: the total number of returned substrings in all queries of the first type must not exceed (n+1)^2. Venya asked you to write a program, which will guess the string by interacting with the orderlies' program and acting by the game's rules. Your program should immediately terminate after guessing the string using a query of the second type. In case your program guessed the string incorrectly, or it violated the game rules, it will receive verdict Wrong answer. Note that in every test case the string is fixed beforehand and will not change during the game, which means that the interactor is not adaptive. Input First line contains number n (1 ≤ n ≤ 100) — the length of the picked string. Interaction You start the interaction by reading the number n. To ask a query about a substring from l to r inclusively (1 ≤ l ≤ r ≤ n), you should output ? l r on a separate line. After this, all substrings of s[l..r] will be returned in random order, each substring exactly once. In every returned substring all characters will be randomly shuffled. In the case, if you ask an incorrect query, ask more than 3 queries of the first type or there will be more than (n+1)^2 substrings returned in total, you will receive verdict Wrong answer. To guess the string s, you should output ! s on a separate line. After printing each query, do not forget to flush the output. Otherwise, you will get Idleness limit exceeded. To flush the output, you can use: * fflush(stdout) or cout.flush() in C++; * System.out.flush() in Java; * flush(output) in Pascal; * stdout.flush() in Python; * see documentation for other languages. If you received - (dash) as an answer to any query, you need to terminate your program with exit code 0 (for example, by calling exit(0)). This means that there was an error in the interaction protocol. If you don't terminate with exit code 0, you can receive any unsuccessful verdict. Hack format To hack a solution, use the following format: The first line should contain one integer n (1 ≤ n ≤ 100) — the length of the string, and the following line should contain the string s. Example Input 4 a aa a cb b c c Output ? 1 2 ? 3 4 ? 4 4 ! aabc The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from bisect import bisect_left as bl from bisect import bisect_right as br import heapq import math from collections import * from functools import reduce, cmp_to_key import sys input = sys.stdin.readline def factors(n): return sorted(list(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))) def li(): return [int(i) for i in input().rstrip('\n').split(' ')] def st(): return input().rstrip('\n') def val(): return int(input().rstrip('\n')) def li2(): return [i for i in input().rstrip('\n').split(' ')] def li3(): return [int(i) for i in input().rstrip('\n')] n = val() cnt1 = Counter() cnt2 = Counter() print('? 1 ' + str(n), flush=True) le = 0 for i in range(n): for j in range(i + 1, n + 1): le += 1 for j in range(le): cnt1[''.join(sorted(st()))] += 1 if n == 1: for i in cnt1.keys(): print('! ' + str(i), flush=True) exit() print('? 2 ' + str(n), flush=True) le = 0 for i in range(1, n): for j in range(i + 1, n + 1): le += 1 for i in range(le): cnt2[''.join(sorted(st()))] += 1 cnt1 -= cnt2 cnt1 = sorted(list(cnt1), key=lambda x: len(x)) s = '' currcount = Counter() for i in cnt1: currcount = Counter(s) for j in i: if not currcount[j]: s += j break currcount[j] -= 1 print('! ' + s, flush=True) ```
vfc_136232
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1287/E1", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "99\nyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy\n", "output": "? 1 99\n? 2 99\n! y\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\nabcd\n", "output": "? 1 4\n? 2 4\n! a\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100\ntssttststtssttsssttsssttttttsttttssstssstsstssstststttssssstttsssttststststtttsssstsstsssssttttttsst\n", "output": "? 1 100\n? 2 100\n! st\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\nrnnnqnnrn\n", "output": "? 1 9\n? 2 9\n! n\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/sum-of-fifth-powers-of-the-first-n-natural-numbers3415/1
Solve the following coding problem using the programming language python: Given a number N.Find the sum of fifth powers of natural numbers till N i.e. 1^{5}+2^{5}+3^{5}+..+N^{5}. Example 1: Input: N=2 Output: 33 Explanation: The sum is calculated as 1^{5}+2^{5}=1+32=33. Example 2: Input: N=3 Output: 276 Explanation: The sum is calculated as 1^{5}+2^{5}+3^{5} =1+32+243=276. Your Task: You don't need to read input or print anything.Your task is to complete the function sumOfFifthPowers() which takes an integer N as input parameter and returns the sum of the fifth powers of Natural numbers till N. Expected Time Complexity:O(1) Expected Auxillary Space:O(1) Constraints: 1<=N<=1000 Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def sumOfFifthPowers(self,N): #code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def sumOfFifthPowers(self, n): return n * n * (n + 1) * (n + 1) * (2 * n * n + 2 * n - 1) // 12 ```
vfc_136236
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/sum-of-fifth-powers-of-the-first-n-natural-numbers3415/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N=2", "output": "33", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/FRCPRT
Solve the following coding problem using the programming language python: Mandarin chinese , Russian and Vietnamese as well. You are given a grid with $n$ rows and $m$ columns. Each cell of this grid can either be empty or it contains one particle. It can never contain more than one particle. Let's denote the cell in the $i$-th row and $j$-th column by $(i, j)$, with the top left corner being $(0, 0)$. From a cell $(i, j)$, a particle could move in one of the following four directions: - to the left, i.e. to the cell $(i, j - 1)$ - to the right, i.e. to the cell $(i, j + 1)$ - up, i.e. to the cell $(i - 1, j)$ - down, i.e. to the cell $(i + 1, j)$ It is not possible for a particle to move to a cell that already contains a particle or to a cell that does not exist (leave the grid). It is possible to apply a force in each of these directions. When a force is applied in a given direction, all particles will simultaneously start moving in this direction as long as it is still possible for them to move. You are given a sequence of forces. Each subsequent force is applied only after all particles have stopped moving. Determine which cells of the grid contain particles after all forces from this sequence are applied in the given order. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains two space-separated integers $n$ and $m$. - $n$ lines describing the initial grid follow. For each $i$ ($1 \le i \le n$), the $i$-th of these lines contains a binary string with length $m$ describing the $i$-th row of the grid. For each $j$ ($1 \le j \le m$), if the $j$-th character of this string is '1', then the cell $(i, j)$ contains a particle, and if it is '0', then the cell $(i, j)$ is empty. - The last line contains a single string $S$ describing the sequence of applied forces. Each character of this string corresponds to applying a force in some direction; forces applied in the directions left, right, up, down correspond to characters 'L', 'R', 'U', 'D' respectively. -----Output----- For each test case, print $n$ lines each containing a binary string of length $m$, describing the resulting grid (after all the forces are applied) in the same format as the input grid. -----Constraints----- - $1 \le T \le 200$ - $1 \le n, m \le 100$ - $1 \le |S| \le 2 \cdot 10^4$ -----Subtasks----- Subtaks #1 (30 points): - $1 \le T \le 10$ - $1 \le n, m \le 10$ - $1 \le |S| \le 100$ Subtask #2 (70 points): Original constraints -----Example Input----- 3 4 4 1010 0010 1001 0100 LRDU 4 3 000 010 001 101 LRL 3 2 01 10 00 D -----Example Output----- 0011 0011 0001 0001 000 100 100 110 00 00 11 -----Explanation----- Example case 1: The initial grid is: 1010 0010 1001 0100 After applying the first force (in the direction "L", i.e. to the left), the grid is: 1100 1000 1100 1000 After applying the second force (in the direction "R"), the grid is: 0011 0001 0011 0001 After applying the third force (in the direction "D"), the grid is: 0001 0001 0011 0011 After applying the fourth force (in the direction "U"), the final grid is: 0011 0011 0001 0001 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main(): for _ in range(int(input())): (rows, column) = map(int, input().split()) arr = [] for i in range(rows): arr.append(list(input())) string = input() last = string[-1] operation = Find(string, last) for i in string[0] + operation: if i == 'L': arr = Left(arr) if i == 'R': arr = Right(arr) if i == 'U': arr = Transpose(arr) arr = Left(arr) arr = Transpose(arr) if i == 'D': arr = Transpose(arr) arr = Right(arr) arr = Transpose(arr) for i in arr: print(i) def Left(arr): for i in range(len(arr)): ans = arr[i].count('1') arr[i] = '1' * ans + (len(arr[i]) - ans) * '0' return arr def Right(arr): for i in range(len(arr)): ans = arr[i].count('1') arr[i] = (len(arr[i]) - ans) * '0' + '1' * ans return arr def Transpose(arr): ansss = [] ans = list(map(list, zip(*arr))) for i in ans: ass = i hello = '' for j in ass: hello += j ansss.append(hello) return ansss def Find(string, last): for i in string[-2::-1]: if last == 'L': if i in ['D', 'U']: last = i + last break if last == 'R': if i in ['D', 'U']: last = i + last break if last == 'D': if i in ['L', 'R']: last = i + last break if last == 'U': if i in ['L', 'R']: last = i + last break return last def __starting_point(): main() __starting_point() ```
vfc_136237
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/FRCPRT", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n4 4\n1010\n0010\n1001\n0100\nLRDU\n4 3\n000\n010\n001\n101\nLRL\n3 2\n01\n10\n00\nD\n", "output": "0011\n0011\n0001\n0001\n000\n100\n100\n110\n00\n00\n11\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/S01E01
Solve the following coding problem using the programming language python: In a New York City coffee house called Central Perk, we're introduced to six friends: chef Monica Geller, data controller Chandler Bing who lives across the hall from Monica, Chandler's roommate/actor Joey Tribbiani, Monica's brother Ross Geller, new ageist Phoebe Buffay, and "born to be a wife" Rachel Green. Chef wants to divide N cookies between the six friends such that: Each friend gets at least one cookie. No two friends get the same number of cookies. Find if it is possible for Chef to do so. ------ Input Format ------ - First line will contain T, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, one integers N. ------ Output Format ------ For each test case print "YES" if Chef can divide the cookies according to the given rules, else print "NO". 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 ≤ 10^{3}$ $1 ≤ N ≤ 10^{3}$ ----- Sample Input 1 ------ 3 42 5 909 ----- Sample Output 1 ------ YES NO YES ----- explanation 1 ------ Test case 1: One possible way of distribution would be $2, 4, 6, 8, 10, 12$. Test case 2: It is impossible to divide $5$ cookies among six friends according to given rules. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for _ in range(int(input())): n = int(input()) if n < 21: print('NO') else: print('YES') ```
vfc_136241
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/S01E01", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n42\n5\n909", "output": "YES\nNO\nYES", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1078/E
Solve the following coding problem using the programming language python: Everyone knows that computers become faster and faster. Recently Berland scientists have built a machine that can move itself back in time! More specifically, it works as follows. It has an infinite grid and a robot which stands on one of the cells. Each cell of the grid can either be empty or contain 0 or 1. The machine also has a program which consists of instructions, which are being handled one by one. Each instruction is represented by exactly one symbol (letter or digit) and takes exactly one unit of time (say, second) to be performed, except the last type of operation (it's described below). Here they are: * 0 or 1: the robot places this number into the cell he is currently at. If this cell wasn't empty before the operation, its previous number is replaced anyway. * e: the robot erases the number into the cell he is at. * l, r, u or d: the robot goes one cell to the left/right/up/down. * s: the robot stays where he is for a unit of time. * t: let x be 0, if the cell with the robot is empty, otherwise let x be one more than the digit in this cell (that is, x = 1 if the digit in this cell is 0, and x = 2 if the digit is 1). Then the machine travels x seconds back in time. Note that this doesn't change the instructions order, but it changes the position of the robot and the numbers in the grid as they were x units of time ago. You can consider this instruction to be equivalent to a Ctrl-Z pressed x times. For example, let the board be completely empty, and the program be sr1t0. Let the robot initially be at (0, 0). * [now is the moment 0, the command is s]: we do nothing. * [now is the moment 1, the command is r]: we are now at (1, 0). * [now is the moment 2, the command is 1]: we are at (1, 0), and this cell contains 1. * [now is the moment 3, the command is t]: we travel 1 + 1 = 2 moments back, that is, to the moment 1. * [now is the moment 1, the command is 0]: we are again at (0, 0), and the board is clear again, but after we follow this instruction, this cell has 0 in it. We've just rewritten the history. The consequences of the third instruction have never happened. Now Berland scientists want to use their machine in practice. For example, they want to be able to add two integers. Assume that the initial state of the machine is as follows: * One positive integer is written in binary on the grid in such a way that its right bit is at the cell (0, 1), from left to right from the highest bit to the lowest bit. * The other positive integer is written in binary on the grid in such a way that its right bit is at the cell (0, 0), from left to right from the highest bit to the lowest bit. * All the other cells are empty. * The robot is at (0, 0). * We consider this state to be always in the past; that is, if you manage to travel to any negative moment, the board was always as described above, and the robot was at (0, 0) for eternity. You are asked to write a program after which * The robot stands on a non-empty cell, * If we read the number starting from the cell with the robot and moving to the right until the first empty cell, this will be a + b in binary, from the highest bit to the lowest bit. Note that there are no restrictions on other cells. In particular, there may be a digit just to the left to the robot after all instructions. In each test you are given up to 1000 pairs (a, b), and your program must work for all these pairs. Also since the machine's memory is not very big, your program must consist of no more than 10^5 instructions. Input The first line contains the only integer t (1≤ t≤ 1000) standing for the number of testcases. Each of the next t lines consists of two positive integers a and b (1≤ a, b < 2^{30}) in decimal. Output Output the only line consisting of no more than 10^5 symbols from 01eslrudt standing for your program. Note that formally you may output different programs for different tests. Example Input 2 123456789 987654321 555555555 555555555 Output 0l1l1l0l0l0l1l1l1l0l1l0l1l1l0l0l0l1l0l1l1l1l0l0l0l1l0l0l0l0l1l0lr The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def C(x, y): return x + '10' + y + 't' + y def CBF(x, y): return x + '01' + y + 't' + y Cr = C('r', 'l') Cl = C('l', 'r') Cu = C('u', 'd') Cd = C('d', 'u') CBFr = CBF('r', 'l') CBFl = CBF('l', 'r') CBFu = CBF('u', 'd') CBFd = CBF('d', 'u') def CE(x, y): return x + x + '0' + x + '1' + y + y + '10' + y + 't' + x + x + 't' + y + x + x + 'e' + x + 'e' + y + y + y def MNE(x, y): return CE(x, y) + x + C(y, x) + 'e' + y def MNEall(n): return (MNE('d', 'u') + 'l') * n + 'r' * n + 'u' + (MNE('u', 'd') + 'l') * n + 'r' * n + 'd' def ADD(): return 'u' + Cu + 'u' + Cu + 'dd' + Cu + 'u' + Cu + 'u' + Cl + '010ltut' + Cd + 'dd' def ADDc(): return ADD() + '0ulrtd' + ADD() + 'lltr' def ADDbit(): return 'u' + Cu + 'u' + Cl + 'll0l1rrr' + ADDc() + 'dd' + Cu + 'u' + Cu + 'u' + Cl + ADDc() + 'dd' def full(n): return MNEall(n) + 'uuu' + '0l' * (n + 1) + 'r' * (n + 1) + 'ddd' + (ADDbit() + 'l') * n + 'uuu' print(full(30)) ```
vfc_136249
{ "difficulty": "very_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1078/E", "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n236675740 987654321\n555555555 555555555\n", "output": "ds10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslsrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrds10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslsrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrruus10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslss10utsusdtedslsrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrdl0r1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrl1010utdtltrs10ltslsrtersl1100utdtltls10rtsrsltelsls10rtsrsltelsrrlrr\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1042/A
Solve the following coding problem using the programming language python: There are $n$ benches in the Berland Central park. It is known that $a_i$ people are currently sitting on the $i$-th bench. Another $m$ people are coming to the park and each of them is going to have a seat on some bench out of $n$ available. Let $k$ be the maximum number of people sitting on one bench after additional $m$ people came to the park. Calculate the minimum possible $k$ and the maximum possible $k$. Nobody leaves the taken seat during the whole process. -----Input----- The first line contains a single integer $n$ $(1 \le n \le 100)$ — the number of benches in the park. The second line contains a single integer $m$ $(1 \le m \le 10\,000)$ — the number of people additionally coming to the park. Each of the next $n$ lines contains a single integer $a_i$ $(1 \le a_i \le 100)$ — the initial number of people on the $i$-th bench. -----Output----- Print the minimum possible $k$ and the maximum possible $k$, where $k$ is the maximum number of people sitting on one bench after additional $m$ people came to the park. -----Examples----- Input 4 6 1 1 1 1 Output 3 7 Input 1 10 5 Output 15 15 Input 3 6 1 6 5 Output 6 12 Input 3 7 1 6 5 Output 7 13 -----Note----- In the first example, each of four benches is occupied by a single person. The minimum $k$ is $3$. For example, it is possible to achieve if two newcomers occupy the first bench, one occupies the second bench, one occupies the third bench, and two remaining — the fourth bench. The maximum $k$ is $7$. That requires all six new people to occupy the same bench. The second example has its minimum $k$ equal to $15$ and maximum $k$ equal to $15$, as there is just a single bench in the park and all $10$ people will occupy it. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) m = int(input()) a = [] for i in range(n): t = int(input()) a.append(t) maxi = max(a) Kmax = maxi + m d = 0 for k in range(n): d += maxi - a[k] if m <= d: Kmin = maxi elif (m - d) % n == 0: Kmin = (m - d) // n + maxi else: Kmin = (m - d) // n + maxi + 1 print(Kmin, Kmax) ```
vfc_136257
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1042/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n6\n1\n1\n1\n1\n", "output": "3 7\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/812/C
Solve the following coding problem using the programming language python: On his trip to Luxor and Aswan, Sagheer went to a Nubian market to buy some souvenirs for his friends and relatives. The market has some strange rules. It contains n different items numbered from 1 to n. The i-th item has base cost a_{i} Egyptian pounds. If Sagheer buys k items with indices x_1, x_2, ..., x_{k}, then the cost of item x_{j} is a_{x}_{j} + x_{j}·k for 1 ≤ j ≤ k. In other words, the cost of an item is equal to its base cost in addition to its index multiplied by the factor k. Sagheer wants to buy as many souvenirs as possible without paying more than S Egyptian pounds. Note that he cannot buy a souvenir more than once. If there are many ways to maximize the number of souvenirs, he will choose the way that will minimize the total cost. Can you help him with this task? -----Input----- The first line contains two integers n and S (1 ≤ n ≤ 10^5 and 1 ≤ S ≤ 10^9) — the number of souvenirs in the market and Sagheer's budget. The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5) — the base costs of the souvenirs. -----Output----- On a single line, print two integers k, T — the maximum number of souvenirs Sagheer can buy and the minimum total cost to buy these k souvenirs. -----Examples----- Input 3 11 2 3 5 Output 2 11 Input 4 100 1 2 5 6 Output 4 54 Input 1 7 7 Output 0 0 -----Note----- In the first example, he cannot take the three items because they will cost him [5, 9, 14] with total cost 28. If he decides to take only two items, then the costs will be [4, 7, 11]. So he can afford the first and second items. In the second example, he can buy all items as they will cost him [5, 10, 17, 22]. In the third example, there is only one souvenir in the market which will cost him 8 pounds, so he cannot buy it. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def Solution(arr, N, S): l = 0 r = N ans = [0, 0] while l <= r: mid = (l + r) // 2 res = isValid(arr, S, mid) if res[0]: l = mid + 1 ans = (mid, res[1]) else: r = mid - 1 return ans def isValid(arr, S, k): tempArr = [] for j in range(len(arr)): tempArr.append(arr[j] + (j + 1) * k) tempArr = sorted(tempArr) tempSum = 0 for i in range(k): tempSum += tempArr[i] if tempSum > S: return [False, 0] return [True, tempSum] (N, S) = map(int, input().split()) arr = list(map(int, input().split())) res = Solution(arr, N, S) print(res[0], res[1]) ```
vfc_136261
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/812/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 11\n2 3 5\n", "output": "2 11\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 100\n1 2 5 6\n", "output": "4 54\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 7\n7\n", "output": "0 0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 7\n5\n", "output": "1 6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1\n", "output": "0 0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/554/E
Solve the following coding problem using the programming language python: There are many anime that are about "love triangles": Alice loves Bob, and Charlie loves Bob as well, but Alice hates Charlie. You are thinking about an anime which has n characters. The characters are labeled from 1 to n. Every pair of two characters can either mutually love each other or mutually hate each other (there is no neutral state). You hate love triangles (A-B are in love and B-C are in love, but A-C hate each other), and you also hate it when nobody is in love. So, considering any three characters, you will be happy if exactly one pair is in love (A and B love each other, and C hates both A and B), or if all three pairs are in love (A loves B, B loves C, C loves A). You are given a list of m known relationships in the anime. You know for sure that certain pairs love each other, and certain pairs hate each other. You're wondering how many ways you can fill in the remaining relationships so you are happy with every triangle. Two ways are considered different if two characters are in love in one way but hate each other in the other. Print this count modulo 1 000 000 007. Input The first line of input will contain two integers n, m (3 ≤ n ≤ 100 000, 0 ≤ m ≤ 100 000). The next m lines will contain the description of the known relationships. The i-th line will contain three integers ai, bi, ci. If ci is 1, then ai and bi are in love, otherwise, they hate each other (1 ≤ ai, bi ≤ n, ai ≠ bi, <image>). Each pair of people will be described no more than once. Output Print a single integer equal to the number of ways to fill in the remaining pairs so that you are happy with every triangle modulo 1 000 000 007. Examples Input 3 0 Output 4 Input 4 4 1 2 1 2 3 1 3 4 0 4 1 0 Output 1 Input 4 4 1 2 1 2 3 1 3 4 0 4 1 1 Output 0 Note In the first sample, the four ways are to: * Make everyone love each other * Make 1 and 2 love each other, and 3 hate 1 and 2 (symmetrically, we get 3 ways from this). In the second sample, the only possible solution is to make 1 and 3 love each other and 2 and 4 hate each other. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class DSU(object): def __init__(self, n): self.father = list(range(n)) self.size = n def union(self, x, s): x = self.find(x) s = self.find(s) if x == s: return self.father[s] = x self.size -= 1 def find(self, x): xf = self.father[x] if xf != x: self.father[x] = self.find(xf) return self.father[x] def is_invalid(a, b, ds): return ds.find(a) == ds.find(b) (n, k) = map(int, input().split()) ds = DSU(n * 2) for i in range(k): (first, second, color) = map(int, input().split()) first -= 1 second -= 1 if color == 0: if is_invalid(first, second, ds): print(0) exit() ds.union(first, second + n) ds.union(first + n, second) else: if is_invalid(first, second + n, ds): print(0) exit() ds.union(first, second) ds.union(first + n, second + n) sum = 1 for i in range(ds.size // 2 - 1): sum = sum * 2 % (10 ** 9 + 7) print(sum) ```
vfc_136266
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/554/E", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 4\n1 2 0\n2 3 0\n2 4 0\n3 4 0\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 6\n1 2 0\n2 3 1\n3 4 0\n4 5 1\n5 6 0\n6 1 1\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n1 2 0\n2 3 0\n3 4 0\n4 5 0\n1 5 0\n", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "9 2\n1 2 0\n2 3 0\n", "output": "64", "type": "stdin_stdout" }, { "fn_name": null, "input": "28567 13\n28079 24675 1\n18409 26720 1\n980 10815 1\n20794 16571 1\n7376 19861 1\n11146 706 1\n4255 16391 1\n27376 18263 1\n10019 28444 1\n6574 28053 1\n5036 16610 1\n3543 7122 1\n512 9554 1\n", "output": "928433852", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/SHUFFLE
Solve the following coding problem using the programming language python: Read problem statements in [Hindi], [Bengali], [Mandarin Chinese], [Russian], and [Vietnamese] as well. Chef got another sequence as a birthday present. He does not like this sequence very much because it is not sorted. Since you are a good programmer, Chef is asking for your help. You are given a sequence $A_{1}, A_{2}, \ldots, A_{N}$ and an integer $K$. You may perform any number of operations of the following type (in any order): choose a valid integer $i$ and swap $A_{i}$ with $A_{i+K}$. Can you sort the sequence this way? ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first line of each test case contains two space-separated integers $N$ and $K$. The second line contains $N$ space-separated integers $A_{1}, A_{2}, \ldots, A_{N}$. ------ Output ------ For each test case, print a single line containing the string "yes" if the sequence can be sorted or "no" otherwise (without quotes). ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ K ≤ N ≤ 10^{5}$ $1 ≤ A_{i} ≤ 10^{9}$ for each valid $i$ the sum of $N$ over all test cases does not exceed $10^{6}$ ------ Subtasks ------ Subtask #1 (50 points): the sequence $A$ is a permutation of the integers $1$ through $N$ Subtask #2 (50 points): original constraints ----- Sample Input 1 ------ 2 4 1 1 4 2 3 4 2 1 4 2 3 ----- Sample Output 1 ------ yes no ----- explanation 1 ------ Example case 1: We may freely swap adjacent elements, so the sequence can be sorted e.g. in the following way: $(1, 4, 2, 3) \rightarrow (1, 2, 4, 3) \rightarrow (1, 2, 3, 4)$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for _ in range(int(input())): (n, k) = map(int, input().split()) arr = list(map(int, input().split())) temp = sorted(arr) res = arr for i in range(k): res[i::k] = sorted(arr[i::k]) if res == temp: print('yes') else: print('no') ```
vfc_136270
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/SHUFFLE", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n4 1\n1 4 2 3\n4 2\n1 4 2 3", "output": "yes\nno", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1332/D
Solve the following coding problem using the programming language python: Bob is playing a game named "Walk on Matrix". In this game, player is given an n × m matrix A=(a_{i,j}), i.e. the element in the i-th row in the j-th column is a_{i,j}. Initially, player is located at position (1,1) with score a_{1,1}. To reach the goal, position (n,m), player can move right or down, i.e. move from (x,y) to (x,y+1) or (x+1,y), as long as player is still on the matrix. However, each move changes player's score to the [bitwise AND](https://en.wikipedia.org/wiki/Bitwise_operation#AND) of the current score and the value at the position he moves to. Bob can't wait to find out the maximum score he can get using the tool he recently learnt — dynamic programming. Here is his algorithm for this problem. <image> However, he suddenly realize that the algorithm above fails to output the maximum score for some matrix A. Thus, for any given non-negative integer k, he wants to find out an n × m matrix A=(a_{i,j}) such that * 1 ≤ n,m ≤ 500 (as Bob hates large matrix); * 0 ≤ a_{i,j} ≤ 3 ⋅ 10^5 for all 1 ≤ i≤ n,1 ≤ j≤ m (as Bob hates large numbers); * the difference between the maximum score he can get and the output of his algorithm is exactly k. It can be shown that for any given integer k such that 0 ≤ k ≤ 10^5, there exists a matrix satisfying the above constraints. Please help him with it! Input The only line of the input contains one single integer k (0 ≤ k ≤ 10^5). Output Output two integers n, m (1 ≤ n,m ≤ 500) in the first line, representing the size of the matrix. Then output n lines with m integers in each line, a_{i,j} in the (i+1)-th row, j-th column. Examples Input 0 Output 1 1 300000 Input 1 Output 3 4 7 3 3 1 4 8 3 6 7 7 7 3 Note In the first example, the maximum score Bob can achieve is 300000, while the output of his algorithm is 300000. In the second example, the maximum score Bob can achieve is 7\&3\&3\&3\&7\&3=3, while the output of his algorithm is 2. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python k = int(input()) arr = [[0, k, 0], [0, 0, k]] length = 0 t = k while t > 0: t >>= 1 length += 1 arr[1][1] = (1 << length) + k arr[1][0] = (1 << length) + ((1 << length) - 1 ^ k) arr[0][0] = (1 << length + 1) - 1 print(2, 3) for i in arr: print(*i) ```
vfc_136274
{ "difficulty": "medium_hard", "memory_limit": "512.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1332/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "79585\n", "output": "2 3\n210657 131072 0\n79585 210657 79585", "type": "stdin_stdout" }, { "fn_name": null, "input": "66536\n", "output": "2 3\n197608 131072 0\n66536 197608 66536", "type": "stdin_stdout" }, { "fn_name": null, "input": "66518\n", "output": "2 3\n197590 131072 0\n66518 197590 66518", "type": "stdin_stdout" }, { "fn_name": null, "input": "66529\n", "output": "2 3\n197601 131072 0\n66529 197601 66529", "type": "stdin_stdout" }, { "fn_name": null, "input": "66517\n", "output": "2 3\n197589 131072 0\n66517 197589 66517", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/111/B
Solve the following coding problem using the programming language python: Little Petya loves looking for numbers' divisors. One day Petya came across the following problem: You are given n queries in the form "xi yi". For each query Petya should count how many divisors of number xi divide none of the numbers xi - yi, xi - yi + 1, ..., xi - 1. Help him. Input The first line contains an integer n (1 ≤ n ≤ 105). Each of the following n lines contain two space-separated integers xi and yi (1 ≤ xi ≤ 105, 0 ≤ yi ≤ i - 1, where i is the query's ordinal number; the numeration starts with 1). If yi = 0 for the query, then the answer to the query will be the number of divisors of the number xi. In this case you do not need to take the previous numbers x into consideration. Output For each query print the answer on a single line: the number of positive integers k such that <image> Examples Input 6 4 0 3 1 5 2 6 2 18 4 10000 3 Output 3 1 1 2 2 22 Note Let's write out the divisors that give answers for the first 5 queries: 1) 1, 2, 4 2) 3 3) 5 4) 2, 6 5) 9, 18 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python maxn = 100000 div = [0] * (maxn + 1) last = [-maxn] * (maxn + 1) for i in range(maxn + 1): div[i] = list() for i in range(2, maxn + 1): for j in range(i, maxn + 1, i): div[j].append(i) t = int(input()) for k in range(0, t): (x_i, y_i) = input().split(' ') x_i = int(x_i) y_i = int(y_i) if y_i == 0: print(len(div[x_i]) + 1) else: print(sum((1 for v in div[x_i] if last[v] < k - y_i))) for d in div[x_i]: last[d] = k ```
vfc_136278
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/111/B", "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "15\n94836 0\n22780 1\n48294 0\n24834 3\n37083 2\n57862 0\n37231 1\n81795 7\n32835 2\n4696 8\n95612 0\n7536 6\n70084 5\n72956 10\n41647 7\n", "output": "24\n21\n12\n4\n6\n8\n3\n27\n12\n5\n24\n15\n8\n21\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "20\n68260 0\n819 1\n54174 1\n20460 1\n25696 2\n81647 4\n17736 4\n91307 5\n5210 4\n87730 2\n4653 8\n11044 6\n15776 4\n17068 7\n73738 7\n36004 12\n83183 7\n75700 12\n84270 14\n16120 5\n", "output": "12\n11\n6\n44\n18\n1\n9\n7\n6\n12\n8\n8\n21\n3\n14\n3\n3\n13\n18\n26\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MEXSUB
Solve the following coding problem using the programming language python: Read problems statements in [Hindi], [Mandarin Chinese], [Russian], [Vietnamese], and [Bengali] as well. Ridbit is given an array $a_{1}, a_{2}, \ldots, a_{N}$. He needs to find the number of ways to divide the array into contiguous subarrays such that: Each element of the sequence $a$ belongs to exactly one of the subarrays. There is an integer $m$ such that the MEX of every subarray is equal to $m$. The MEX of a sequence is the smallest non-negative integer which does not occur in this sequence. Help Ridbit with this task. ------ Input ------ The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. The first line of each test case contains a single integer $N$. The second line contains $N$ space-separated integers $a_{1}, a_{2}, \ldots, a_{N}$. ------ Output ------ For each test case, print a single line containing one integer ― the number of ways to divide the sequence, modulo $10^{9} + 7$. ------ Constraints ------ $1 ≤ T ≤ 10$ $1 ≤ N ≤ 100,000$ $0 ≤ a_{i} ≤ N$ for each valid $i$ ----- Sample Input 1 ------ 2 6 1 0 0 1 0 1 3 1 2 3 ----- Sample Output 1 ------ 5 4 ----- explanation 1 ------ Example case 1: The five valid ways to divide the sequence are: - $[1, 0, 0, 1, 0, 1]$ - $[1, 0], [0, 1, 0, 1]$ - $[1, 0, 0], [1, 0, 1]$ - $[1, 0, 0, 1], [0, 1]$ - $[1, 0], [0, 1], [0, 1]$ The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python mod = 10 ** 9 + 7 t = int(input()) for i in range(t): n = int(input()) arr = [int(x) for x in input().split()] l = sorted(arr) prev = -1 for i in range(n): if l[i] - prev > 1: break prev = l[i] m = prev + 1 d = {} for i in range(n): if arr[i] > m: continue d[arr[i]] = d.get(arr[i], 0) + 1 p = n - 1 while p >= 0: if arr[p] < m: if d[arr[p]] == 1: break else: d[arr[p]] = d[arr[p]] - 1 p = p - 1 p = p + 1 p = max(1, p) dp = [0] * (n + 1) pref = [0] * (n + 1) dp[0] = 1 pref[0] = 1 for i in range(1, p): dp[i] = 0 pref[i] = 1 dp[p] = 1 pref[p] = 2 p = p + 1 prev = 1 while p <= n: if arr[p - 1] < m: d[arr[p - 1]] = d[arr[p - 1]] + 1 while prev < p: if arr[prev - 1] < m: if d[arr[prev - 1]] == 1: break else: d[arr[prev - 1]] = d[arr[prev - 1]] - 1 prev = prev + 1 dp[p] = pref[prev - 1] pref[p] = (pref[p - 1] + dp[p]) % mod p = p + 1 print(dp[n]) ```
vfc_136282
{ "difficulty": "very_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MEXSUB", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n6\n1 0 0 1 0 1\n3\n1 2 3", "output": "5\n4", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: The time was 3xxx, and the highly developed civilization was in a stagnation period. Historians decided to learn the wisdom of the past in an attempt to overcome this situation. What I paid attention to was the material left by the genius of the early days of computers. The calculation formula is written in this material and I would like to know the calculation result, but unfortunately some of the characters are fading and cannot be read. Since there is no help for it, I decided to find the largest possible number as a calculation result. The calculation formula is written in binary numbers, and there are three types of operations: addition, subtraction, and multiplication. Parentheses are also used, but the numbers inside the parentheses are not the only ones. To be exact, it is necessary to satisfy the grammar defined by the following BNF. <expression> :: = <number> | <expression> <operation> <expression> | (<expression> <operation> <expression>) <number> :: = <digit> | <number> <digit> <operation> :: = + |-| * <digit> :: = 0 | 1 Due to the limited computing power of computers at that time, numbers are integers between 0 and 210 and do not go out of this range during calculations. However, the calculation is done in parentheses first, and the multiplication is done before addition / subtraction. In other cases, the calculation is performed in order from the left. Constraints * Formulas must be between 1 and 100 characters * All characters except line breaks are either 01 +-* (). *. Number is 5 or less Input The input consists of one line and is given one formula to decipher. The formula is 1 to 100 characters. Up to 5 characters cannot be read for one formula and are represented by ".". The characters contained in the given formula are either 01 +-* (). Output Find the one that maximizes the calculation result among the original formulas, and output the calculation result in decimal notation. Output -1 if you can't make what you think is the original formula no matter how you fill in the unreadable characters. Examples Input 000 Output 0 Input 0.0 Output 2 Input ... Output 7 Input (1.1) Output 2 Input 0-1. Output -1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from itertools import product import time def ok(s): if '(+' in s or '(-' in s or '(*' in s or ('++' in s) or ('+-' in s) or ('-+' in s) or ('--' in s) or ('**' in s) or ('*+' in s) or ('*-' in s): return False if '(' in s or ')' in s: dic = {} count = -1 for c in s: if c == '(': count += 1 dic[count] = 0 elif c == ')': if dic[count] == 0: return False count -= 1 elif c in '+-*' and count in dic: dic[count] += 1 return True else: return True def check(s): i = 0 ans = '' tmp = [] try: while i < len(s): if s[i] in '01': tmp.append(s[i]) else: if len(tmp): t = ''.join(tmp) t = str(int(t, 2)) if int(t) >= 1024: return -99999999 ans += t ans += s[i] tmp = [] i += 1 if len(tmp): t = ''.join(tmp) t = str(int(t, 2)) ans += t except: return -99999999 try: if ok(ans): xxx = eval(ans) if '-' not in ans and xxx < 1024: return xxx elif '-' in ans and xxx < 1024: for i in range(len(ans)): if ans[i] == '-': mid = i (r, l) = (mid - 1, mid + 1) count = 0 while r >= 0: if ans[r] == ')': count += 1 elif ans[r] == '(': count -= 1 if count < 0: r += 1 break if count == 0 and ans[r] in '+-': r += 1 break r -= 1 r = max(r, 0) count = 0 while l < len(ans): if ans[l] == '(': count += 1 elif ans[l] == ')': count -= 1 if count < 0: break if count == 0 and ans[l] in '+-': break l += 1 (a, b) = (eval(ans[r:mid]), eval(ans[mid + 1:l])) if a >= 1024 or b >= 1024 or a - b < 0: return -99999999 return xxx else: return -99999999 else: return -99999999 except: return -99999999 s = input().split('.') mx = -1 hoge = product('01+-*()', repeat=len(s) - 1) for table in hoge: tmp = s[0] i = 1 for c in table: tmp += c + s[i] i += 1 mx = max(mx, check(tmp)) print(mx) ```
vfc_136286
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "3.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "0.010621136904092388", "output": "-1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "0.1.", "output": "7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "100", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": ".01.", "output": "11\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/TANGDIV
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian. Once Chef decided to divide the tangerine into several parts. At first, he numbered tangerine's segments from 1 to n in the clockwise order starting from some segment. Then he intended to divide the fruit into several parts. In order to do it he planned to separate the neighbouring segments in k places, so that he could get k parts: the 1^{st} - from segment l_{1} to segment r_{1} (inclusive), the 2^{nd} - from l_{2} to r_{2}, ..., the k^{th} - from l_{k} to r_{k} (in all cases in the clockwise order). Suddenly, when Chef was absent, one naughty boy came and divided the tangerine into p parts (also by separating the neighbouring segments one from another): the 1^{st} - from segment a_{1} to segment b_{1}, the 2^{nd} - from a_{2} to b_{2}, ..., the p^{th} - from a_{p} to b_{p} (in all cases in the clockwise order). Chef became very angry about it! But maybe little boy haven't done anything wrong, maybe everything is OK? Please, help Chef to determine whether he is able to obtain the parts he wanted to have (in order to do it he can divide p current parts, but, of course, he can't join several parts into one). Please, note that parts are not cyclic. That means that even if the tangerine division consists of only one part, but that part include more than one segment, there are two segments which were neighbouring in the initial tangerine but are not neighbouring in the division. See the explanation of example case 2 to ensure you understood that clarification. ------ Input ------ The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The first line of each test case contains three space separated integers n, k, p, denoting the number of tangerine's segments and number of parts in each of the two divisions. The next k lines contain pairs of space-separated integers l_{i} and r_{i}. The next p lines contain pairs of space-separated integers a_{i} and b_{i}. It is guaranteed that each tangerine's segment is contained in exactly one of the first k parts and in exactly one of the next p parts. ------ Output ------ For each test case, output a single line containing either "Yes" or "No" (without the quotes), denoting whether Chef is able to obtain the parts he wanted to have.   ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ n ≤ 5 * 10^{7}$ $1 ≤ k ≤ min(500, n)$ $1 ≤ p ≤ min(500, n)$ $1 ≤ l_{i}, r_{i}, a_{i}, b_{i} ≤ n$   ----- Sample Input 1 ------ 2 10 3 2 1 4 5 5 6 10 1 5 6 10 10 3 1 2 5 10 1 6 9 1 10 ----- Sample Output 1 ------ Yes No ----- explanation 1 ------ Example case 1: To achieve his goal Chef should divide the first part (1-5) in two by separating segments 4 and 5 one from another. Example case 2: The boy didn't left the tangerine as it was (though you may thought that way), he separated segments 1 and 10 one from another. But segments 1 and 10 are in one part in Chef's division, so he is unable to achieve his goal. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def snek(c, k): if len(u) > len(c): return False c.sort() u.sort() (x, y) = (0, 0) while x < len(c) and y < len(u): if c[x][0] == k[y][0]: x += 1 y += 1 elif c[x][0] < k[y][0]: x += 1 else: return False return y == len(u) t = int(input()) for i in range(t): (n, k, p) = map(int, input().split()) c = [] u = [] for j in range(k): c.append(list(map(int, input().split()))) for z in range(p): u.append(list(map(int, input().split()))) if snek(c, u): r = 'Yes' else: r = 'No' print(r) ```
vfc_136290
{ "difficulty": "medium_hard", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/TANGDIV", "time_limit": "0.180108 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n10 3 2\n1 4\n5 5\n6 10\n1 5\n6 10\n10 3 1\n2 5\n10 1\n6 9\n1 10", "output": "Yes\nNo", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10 3 2\n1 4\n5 5\n6 10\n1 5\n6 10\n10 3 1\n4 5\n10 1\n6 9\n1 10", "output": "Yes\nNo\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10 3 2\n1 4\n5 5\n6 10\n1 5\n6 10\n10 3 0\n4 5\n10 1\n6 9\n1 10", "output": "Yes\nYes\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10 3 2\n1 4\n5 5\n6 10\n1 4\n6 10\n10 3 1\n2 5\n10 1\n6 9\n1 10", "output": "Yes\nNo\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10 3 2\n1 4\n5 5\n6 10\n1 4\n6 10\n8 3 1\n2 5\n10 1\n6 9\n1 10", "output": "Yes\nNo\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n10 3 2\n1 4\n5 5\n6 10\n1 5\n6 10\n10 3 1\n4 5\n10 1\n6 9\n1 15", "output": "Yes\nNo\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Example Input 4 1 1 2 Output 6 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time, copy, functools sys.setrecursionlimit(10 ** 7) inf = 10 ** 20 eps = 1.0 / 10 ** 13 mod = 10 ** 9 + 7 dd = [(-1, 0), (0, 1), (1, 0), (0, -1)] ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)] def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LF(): return [float(x) for x in sys.stdin.readline().split()] def LS(): return sys.stdin.readline().split() def I(): return int(sys.stdin.readline()) def F(): return float(sys.stdin.readline()) def S(): return input() def pf(s): return print(s, flush=True) def main(): n = I() if n == 1: return 0 a = LI_() b = [0] c = [[None] * 18] for i in range(n - 1): t = a[i] b.append(b[t] + 1) d = [None] * 18 d[0] = t for j in range(1, 18): if c[d[j - 1]][j - 1] is None: break d[j] = c[d[j - 1]][j - 1] c.append(d) ii = [2 ** i for i in range(19)] def f(i, j): if i == j: return 0 if b[i] > b[j]: sa = b[i] - b[j] for k in range(1, 18): if sa < ii[k]: return ii[k - 1] + f(c[i][k - 1], j) if b[i] < b[j]: sa = b[j] - b[i] for k in range(1, 18): if sa < ii[k]: return ii[k - 1] + f(c[j][k - 1], i) for k in range(1, 18): if c[i][k] == c[j][k]: return ii[k] + f(c[i][k - 1], c[j][k - 1]) ba = sorted(zip(b, range(n))) aa = [0] aai = {} aai[0] = 0 i = 1 while i < n: j = i + 1 bi = ba[i][0] while j < n and bi == ba[j][0]: j += 1 aa.extend(list(map(lambda x: x[1], sorted([[aai[c[_][0]], _] for (k, _) in ba[i:j]])))) for k in range(i, j): aai[aa[k]] = k i = j r = 1 for i in range(1, n - 1): r += f(aa[i], aa[i + 1]) return r print(main()) ```
vfc_136294
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1 1", "output": "5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 2", "output": "4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 1", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 2 3", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1450/C2
Solve the following coding problem using the programming language python: The only difference between the easy and hard versions is that tokens of type O do not appear in the input of the easy version. Errichto gave Monogon the following challenge in order to intimidate him from taking his top contributor spot on Codeforces. In a Tic-Tac-Toe grid, there are $n$ rows and $n$ columns. Each cell of the grid is either empty or contains a token. There are two types of tokens: X and O. If there exist three tokens of the same type consecutive in a row or column, it is a winning configuration. Otherwise, it is a draw configuration. The patterns in the first row are winning configurations. The patterns in the second row are draw configurations. In an operation, you can change an X to an O, or an O to an X. Let $k$ denote the total number of tokens in the grid. Your task is to make the grid a draw in at most $\lfloor \frac{k}{3}\rfloor$ (rounding down) operations. You are not required to minimize the number of operations. -----Input----- The first line contains a single integer $t$ ($1\le t\le 100$) — the number of test cases. The first line of each test case contains a single integer $n$ ($1\le n\le 300$) — the size of the grid. The following $n$ lines each contain a string of $n$ characters, denoting the initial grid. The character in the $i$-th row and $j$-th column is '.' if the cell is empty, or it is the type of token in the cell: 'X' or 'O'. It is guaranteed that not all cells are empty. The sum of $n$ across all test cases does not exceed $300$. -----Output----- For each test case, print the state of the grid after applying the operations. We have proof that a solution always exists. If there are multiple solutions, print any. -----Examples----- Input 3 3 .O. OOO .O. 6 XXXOOO XXXOOO XX..OO OO..XX OOOXXX OOOXXX 5 .OOO. OXXXO OXXXO OXXXO .OOO. Output .O. OXO .O. OXXOOX XOXOXO XX..OO OO..XX OXOXOX XOOXXO .OXO. OOXXO XXOXX OXXOO .OXO. -----Note----- In the first test case, there are initially three 'O' consecutive in the second row and the second column. By changing the middle token to 'X' we make the grid a draw, and we only changed $1\le \lfloor 5/3\rfloor$ token. In the second test case, the final grid is a draw. We only changed $8\le \lfloor 32/3\rfloor$ tokens. In the third test case, the final grid is a draw. We only changed $7\le \lfloor 21/3\rfloor$ tokens. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys input = lambda : sys.stdin.readline().rstrip() T = int(input()) for _ in range(T): N = int(input()) X = [[a for a in input()] for _ in range(N)] C = [0] * 3 D = [0] * 3 for i in range(N): Xi = X[i] for j in range(N): if Xi[j] == 'X': C[(i + j) % 3] += 1 elif Xi[j] == 'O': D[(i + j) % 3] += 1 (aaa, bbb) = (0, 0) f = 0 for k in range(3): for l in range(3): if k == l: continue if C[k] + D[l] <= (sum(C) + sum(D)) // 3: for i in range(N): Xi = X[i] for j in range(N): if (i + j) % 3 == k: if Xi[j] == 'X': Xi[j] = 'O' aaa += 1 elif (i + j) % 3 == l: if Xi[j] == 'O': Xi[j] = 'X' bbb += 1 f = 1 break if f: break for x in X: print(''.join(x)) ```
vfc_136302
{ "difficulty": "hard", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1450/C2", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n3\n.O.\nOOO\n.O.\n6\nXXXOOO\nXXXOOO\nXX..OO\nOO..XX\nOOOXXX\nOOOXXX\n5\n.OOO.\nOXXXO\nOXXXO\nOXXXO\n.OOO.\n", "output": ".O.\nOXO\n.O.\nOXXOOX\nXXOOXO\nXO..OO\nOO..XX\nOXOXXO\nXOOXOX\n.XOO.\nXXOXO\nOOXXO\nOXXOX\n.OOX.\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/transform-the-array4344/1
Solve the following coding problem using the programming language python: Given an array arr[] of size N containing integers, zero is considered an invalid number, and rest all other numbers are valid. If two nearest valid numbers are equal then double the value of the first one and make the second number as 0. At last move all the valid numbers on the left. Example 1: Input: N = 12 arr[] = {2, 4, 5, 0, 0, 5, 4, 8, 6, 0, 6, 8} Output: 2 4 10 4 8 12 8 0 0 0 0 0 Explanation: After performing above given operation we get array as, 2 4 10 0 0 0 4 8 12 0 0 8, then shifting all zero's to the right, we get resultant array as - 2 4 10 4 8 12 8 0 0 0 0 0 Example 2: Input: N = 2, arr[] = {0, 0} Output: 0 0 Explanation: All elements in the array are invalid . Your Task: You don't need to read input or print anything. Complete the function valid() that takes array arr[] and integer N as input parameters and returns the resultant array. Expected Time Complexity: O(N) Expected Auxiliary Space: O(1) Constraints: 1 ≤ N ≤ 10^{5} Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def valid(self,arr, n): # code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def valid(self, arr, n): stck = list() count = 0 for i in arr: if i != 0 and (len(stck) == 0 or stck[-1] != i): stck.append(i) elif stck and stck[-1] == i: stck.pop() stck.append(2 * i) count += 1 else: count += 1 zero = [0 for i in range(count)] stck.extend(zero) return stck ```
vfc_136311
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/transform-the-array4344/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 12\r\narr[] = {2, 4, 5, 0, 0, 5, 4, 8, 6, 0, \r\n 6, 8}", "output": "2 4 10 4 8 12 8 0 0 0 0 0", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 2, arr[] = {0, 0}", "output": "0 0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1038/A
Solve the following coding problem using the programming language python: You are given a string $s$ of length $n$, which consists only of the first $k$ letters of the Latin alphabet. All letters in string $s$ are uppercase. A subsequence of string $s$ is a string that can be derived from $s$ by deleting some of its symbols without changing the order of the remaining symbols. For example, "ADE" and "BD" are subsequences of "ABCDE", but "DEA" is not. A subsequence of $s$ called good if the number of occurences of each of the first $k$ letters of the alphabet is the same. Find the length of the longest good subsequence of $s$. -----Input----- The first line of the input contains integers $n$ ($1\le n \le 10^5$) and $k$ ($1 \le k \le 26$). The second line of the input contains the string $s$ of length $n$. String $s$ only contains uppercase letters from 'A' to the $k$-th letter of Latin alphabet. -----Output----- Print the only integer — the length of the longest good subsequence of string $s$. -----Examples----- Input 9 3 ACAABCCAB Output 6 Input 9 4 ABCABCABC Output 0 -----Note----- In the first example, "ACBCAB" ("ACAABCCAB") is one of the subsequences that has the same frequency of 'A', 'B' and 'C'. Subsequence "CAB" also has the same frequency of these letters, but doesn't have the maximum possible length. In the second example, none of the subsequences can have 'D', hence the answer is $0$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main_function(): (n, m) = [int(i) for i in input().split(' ')] s = list(input()) d = {} for i in s: if i in d: d[i] += 1 else: d[i] = 1 if len(d) < m: return 0 f = min(d, key=lambda i: d[i]) return d[f] * m print(main_function()) ```
vfc_136313
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1038/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "9 3\nACAABCCAB\n", "output": "6", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/0-1-knapsack-problem0945/1
Solve the following coding problem using the programming language python: You are given weights and values of N items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. Note that we have only one quantity of each item. In other words, given two integer arrays val[0..N-1] and wt[0..N-1] which represent values and weights associated with N items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of val[] such that sum of the weights of this subset is smaller than or equal to W. You cannot break an item, either pick the complete item or dont pick it (0-1 property). Example 1: Input: N = 3 W = 4 values[] = {1,2,3} weight[] = {4,5,1} Output: 3 Example 2: Input: N = 3 W = 3 values[] = {1,2,3} weight[] = {4,5,6} Output: 0 Your Task: Complete the function knapSack() which takes maximum capacity W, weight array wt[], value array val[], and the number of items n as a parameter and returns the maximum possible value you can get. Expected Time Complexity: O(N*W). Expected Auxiliary Space: O(N*W) Constraints: 1 ≤ N ≤ 1000 1 ≤ W ≤ 1000 1 ≤ wt[i] ≤ 1000 1 ≤ v[i] ≤ 1000 Write your solution by modifying this code: ```python #User function Template for python3 class Solution: #Function to return max value that can be put in knapsack of capacity W. def knapSack(self,W, wt, val, n): # code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def knapSack(self, W, wt, val, n): dp = [[-1 for m in range(W + 1)] for n in range(n + 1)] for i in range(n + 1): dp[i][0] = 0 for j in range(W + 1): dp[0][j] = 0 for i in range(1, n + 1): for j in range(1, W + 1): if wt[i - 1] <= j: dp[i][j] = max(val[i - 1] + dp[i - 1][j - wt[i - 1]], dp[i - 1][j]) else: dp[i][j] = dp[i - 1][j] return dp[n][W] ```
vfc_136317
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/0-1-knapsack-problem0945/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3\r\nW = 4\r\nvalues[] = {1,2,3}\r\nweight[] = {4,5,1}", "output": "3", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 3\r\nW = 3\r\nvalues[] = {1,2,3}\r\nweight[] = {4,5,6}", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/HELLO
Solve the following coding problem using the programming language python: Chef talks a lot on his mobile phone. As a result he exhausts his talk-value (in Rokdas) very quickly. One day at a mobile recharge shop, he noticed that his service provider gives add-on plans which can lower his calling rates (Rokdas/minute). One of the plans said "Recharge for 28 Rokdas and enjoy call rates of 0.50 Rokdas/min for one month". Chef was very pleased. His normal calling rate is 1 Rokda/min. And he talked for 200 minutes in last month, which costed him 200 Rokdas. If he had this plan activated, it would have costed him: 28 + 0.5*200 = 128 Rokdas only! Chef could have saved 72 Rokdas. But if he pays for this add-on and talks for very little in the coming month, he may end up saving nothing or even wasting money. Now, Chef is a simple guy and he doesn't worry much about future. He decides to choose the plan based upon his last month’s usage. There are numerous plans. Some for 1 month, some for 15 months. Some reduce call rate to 0.75 Rokdas/min, some reduce it to 0.60 Rokdas/min. And of course each of them differ in their activation costs. Note - If a plan is valid for M months, then we must pay for (re)activation after every M months (once in M months). Naturally, Chef is confused, and you (as always) are given the task to help him choose the best plan. ------ Input ------ First line contains T- the number of test cases. In each test case, first line contains D- the default rate (Rokdas/minute, real number), U- the number of minutes Chef talked in last month and N- the number of add-on plans available. Then N lines follow, each containing M- the number of months the plan is valid for, R- the calling rate for the plan (Rokdas/minute, real number) and C- the cost of the plan. ------ Output ------ For each test case, output one integer- the number of the best plan (from 1 to N). Output '0' if no plan is advantageous for Chef. No two plans are equally advantageous. ------ Constraints ------ 1 ≤ T ≤ 100 0.5 ≤ D ≤ 10.0 (exactly 2 digits after the decimal point) 1 ≤ U ≤ 10000 1 ≤ N ≤ 100 1 ≤ M ≤ 36 0.05 ≤ R < D (exactly 2 digits after the decimal point) 1 ≤ C ≤ 1000 ----- Sample Input 1 ------ 4 1.00 200 1 1 0.50 28 1.00 200 2 1 0.75 40 3 0.60 100 1.00 50 2 1 0.75 40 3 0.60 100 1.00 100 2 3 0.50 10 2 0.10 20 ----- Sample Output 1 ------ 1 2 0 2 ----- explanation 1 ------ Test Case 1: This test case is same as the example in the problem statement.Test Case 2: This is for you to work out!Test Case 3: Chef's monthly usage is only 50 Rokdas and none of the 2 plans are advantageous, hence the answer is zero '0'.Test Case 4: Again solve it yourself, but NOTE - if Chef had chosen plan 1, he would have to pay 10 Rokdas (Activation cost), after every 3 months and NOT every month. Similarly had he chosen plan 2, he would have to pay 20 Rokdas (Activation cost), after every 2 months. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a = int(input()) for i in range(a): (D, U, P) = list(map(float, input().split())) ans = 0 cost = D * U temp = 1 for k in range(int(P)): (M, R, C) = list(map(float, input().split())) if cost >= C / M + R * U: cost = C / M + R * U ans = temp temp += 1 print(ans) ```
vfc_136318
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/HELLO", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1.00 200 1\n1 0.50 28\n1.00 200 2\n1 0.75 40\n3 0.60 100\n1.00 50 2\n1 0.75 40\n3 0.60 100\n1.00 100 2\n3 0.50 10\n2 0.10 20", "output": "1\n2\n0\n2", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1.00 200 1\n1 0.50 28\n1.00 200 2\n1 0.75 40\n3 0.60 100\n1.00 50 2\n1 0.75 40\n3 0.60 100\n1.00 100 2\n3 0.50 10\n2 0.10 18", "output": "1\n2\n0\n2\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1.00 200 1\n1 1.2860395633010162 28\n1.00 200 2\n1 0.75 40\n3 0.60 101\n1.00 50 2\n1 0.75 65\n3 1.410429553075017 100\n1.00 100 2\n3 0.50 10\n2 0.10 18", "output": "0\n2\n0\n2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1129/C
Solve the following coding problem using the programming language python: In Morse code, an letter of English alphabet is represented as a string of some length from $1$ to $4$. Moreover, each Morse code representation of an English letter contains only dots and dashes. In this task, we will represent a dot with a "0" and a dash with a "1". Because there are $2^1+2^2+2^3+2^4 = 30$ strings with length $1$ to $4$ containing only "0" and/or "1", not all of them correspond to one of the $26$ English letters. In particular, each string of "0" and/or "1" of length at most $4$ translates into a distinct English letter, except the following four strings that do not correspond to any English alphabet: "0011", "0101", "1110", and "1111". You will work with a string $S$, which is initially empty. For $m$ times, either a dot or a dash will be appended to $S$, one at a time. Your task is to find and report, after each of these modifications to string $S$, the number of non-empty sequences of English letters that are represented with some substring of $S$ in Morse code. Since the answers can be incredibly tremendous, print them modulo $10^9 + 7$. -----Input----- The first line contains an integer $m$ ($1 \leq m \leq 3\,000$) — the number of modifications to $S$. Each of the next $m$ lines contains either a "0" (representing a dot) or a "1" (representing a dash), specifying which character should be appended to $S$. -----Output----- Print $m$ lines, the $i$-th of which being the answer after the $i$-th modification to $S$. -----Examples----- Input 3 1 1 1 Output 1 3 7 Input 5 1 0 1 0 1 Output 1 4 10 22 43 Input 9 1 1 0 0 0 1 1 0 1 Output 1 3 10 24 51 109 213 421 833 -----Note----- Let us consider the first sample after all characters have been appended to $S$, so S is "111". As you can see, "1", "11", and "111" all correspond to some distinct English letter. In fact, they are translated into a 'T', an 'M', and an 'O', respectively. All non-empty sequences of English letters that are represented with some substring of $S$ in Morse code, therefore, are as follows. "T" (translates into "1") "M" (translates into "11") "O" (translates into "111") "TT" (translates into "11") "TM" (translates into "111") "MT" (translates into "111") "TTT" (translates into "111") Although unnecessary for this task, a conversion table from English alphabets into Morse code can be found here. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import os, sys nums = list(map(int, os.read(0, os.fstat(0).st_size).split())) MOD = 10 ** 9 + 7 BAD = ([0, 0, 1, 1], [0, 1, 0, 1], [1, 1, 1, 0], [1, 1, 1, 1]) def zfunc(s): z = [0] * len(s) l = r = 0 for i in range(1, len(s)): if i <= r: z[i] = min(r - i + 1, z[i - l]) while i + z[i] < len(s) and s[z[i]] == s[i + z[i]]: z[i] += 1 if i + z[i] - 1 > r: (l, r) = (i, i + z[i] - 1) return z n = nums[0] s = [] sm = 0 ans = [] for i in range(1, n + 1): s.append(nums[i]) cur = 0 f = [0] * (i + 1) f[i] = 1 for j in range(i - 1, -1, -1): f[j] = f[j + 1] if j + 1 < i: f[j] += f[j + 2] if f[j] >= MOD: f[j] -= MOD if j + 2 < i: f[j] += f[j + 3] if f[j] >= MOD: f[j] -= MOD if j + 3 < i and s[j:j + 4] not in BAD: f[j] += f[j + 4] if f[j] >= MOD: f[j] -= MOD z = zfunc(s[::-1]) new = i - max(z) for x in f[:new]: sm += x if sm >= MOD: sm -= MOD ans.append(sm) os.write(1, b'\n'.join((str(x).encode() for x in ans))) ```
vfc_136326
{ "difficulty": "very_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1129/C", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1\n1\n1\n", "output": "1\n3\n7\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n1\n0\n1\n0\n1\n", "output": "1\n4\n10\n22\n43\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "9\n1\n1\n0\n0\n0\n1\n1\n0\n1\n", "output": "1\n3\n10\n24\n51\n109\n213\n421\n833\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n0\n0\n0\n", "output": "1\n3\n7\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/rank-the-permutations2229/1
Solve the following coding problem using the programming language python: Given a string, find the rank of the string amongst its permutations sorted lexicographically. Example 1: Input: S = "abc" Output: 1 Explanation: The order permutations with letters 'a', 'c', and 'b' : abc acb bac bca cab cba Example 2: Input: S = "acb" Output: 2 Your Task: You don't need to read input or print anything. Your task is to complete the function findRank() which takes the string S as input parameter and returns the rank of the string amongst its permutations. It is guaranteed no characters are repeated in the string. Expected Time Complexity: O(|S|*26) Expected Auxiliary Space: O(|S|) Note: |S| represents the length of string S. Constraints: 1 ≤ |S| ≤ 18 Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def findRank(self, S): #Code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def findRank(self, S): n = len(S) inp = [] fact = 1 for i in range(n): inp.append(S[i]) fact *= i + 1 fact = fact // n i = 0 k = 1 inp = sorted(inp) for element in S: block = inp.index(element) k += block * fact inp.pop(block) if i != n - 1: fact = fact // (n - i - 1) i += 1 return k ```
vfc_136330
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/rank-the-permutations2229/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S = \"abc\"", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "S = \"acb\"", "output": "2", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/M1ENROL
Solve the following coding problem using the programming language python: For the upcoming semester, the admins of your university decided to keep a total of X seats for the MATH-1 course. A student interest survey was conducted by the admins and it was found that Y students were interested in taking up the MATH-1 course. Find the minimum number of extra seats that the admins need to add into the MATH-1 course to make sure that every student who is interested in taking the course would be able to do so. ------ Input Format ------ - The first line of input will contain a single integer T, denoting the number of test cases. - Each test case consists of two-space separated integers on a single line, X and Y — the current number of seats up for enrolment and the number of students interested in taking up the course in the upcoming semester, respectively. ------ Output Format ------ For each test case, output on a new line the minimum number of seats required to be added. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ X, Y ≤ 10^{5}$ ----- Sample Input 1 ------ 4 1 1 12 34 50 49 49 50 ----- Sample Output 1 ------ 0 22 0 1 ----- explanation 1 ------ Test case $1$: Exactly $1$ seat is available for enrolment, and exactly $1$ student is interested in taking up the course, hence addition of more seats is not required. Test case $2$: $12$ seats are available for enrolment but $34$ students are interested in taking up the course, hence the admins would have to add $34-12=22$ more seats to make sure that every student interested in the course gets a seat. Test case $3$: $50$ seats are available for enrolment and $49$ students are interested in taking up the course, hence addition of more seats is not required. Test case $4$: $49$ seats are available for enrolment, but $50$ students are interested in taking up the course, hence the admins would have to add $50-49=1$ more seat to make sure that every student interested in the course gets a seat. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python t = int(input()) for i in range(t): (x, y) = map(int, input().split(' ')) if x < y: print(y - x) else: print(0) ```
vfc_136331
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/M1ENROL", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1\n12 34\n50 49\n49 50\n", "output": "0\n22\n0\n1", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Create a program that reads the attendance numbers of students in a class and the data that stores the ABO blood group and outputs the number of people for each blood type. There are four types of ABO blood types: A, B, AB, and O. Input A comma-separated pair of attendance numbers and blood types is given over multiple lines. The attendance number is an integer between 1 and 50, and the blood type is one of the strings "A", "B", "AB" or "O". The number of students does not exceed 50. Output Number of people of type A on the first line Number of people of type B on the second line Number of people of AB type on the 3rd line Number of O-shaped people on the 4th line Is output. Example Input 1,B 2,A 3,B 4,AB 5,B 6,O 7,A 8,O 9,AB 10,A 11,A 12,B 13,AB 14,A Output 5 4 3 2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from collections import Counter import sys d = Counter([i.split(',')[1].strip() for i in sys.stdin]) [print(d[i]) for i in ['A', 'B', 'AB', 'O']] ```
vfc_136335
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1,B\n2,A\n3,B\n4,AB\n5,B\n5,O\n7,A\n8,O\n9,AB\n10,A\n11,A\n12,B\n13,AB\n14,A", "output": "5\n4\n3\n2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Hansa loves dancing and so do her friends. But she has some pretty weird friends. Like this one friend of hers, Jack, jumps forward while dancing. The dance floor is of finite length (L) and there are many people dancing on it. During each song, Jack jumps exactly X steps forward and at the end of the song, he is pushed back Y steps by the other dancers. Every class has a nerd. This one does too. The nerd doesn’t like dancing but in order to kill time he is watching this jumping Jack. He is counting the number of songs that have been played before Jack reaches the end of the dance floor. Tell us how many songs he counted. Note: Even if a song doesn’t complete when he reaches the end of the dance floor, but it has started, then it is counted. Input: Three space separated integers L, X, Y. Output: A single line of output that is the answer to the question. Constraints: 1 ≤ Y < X ≤ L ≤ 10^9 Problem Setter: Chintan Shah SAMPLE INPUT 6 5 1 SAMPLE OUTPUT 2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python s=input().split() s1=int(s[0]) s2=int(s[1]) s3=int(s[2]) c=0 cpy=s2 if s1>=s2 and s1<=pow(10,9) and s2>s3 and s2<=s1 and s3>=1 and s3<s2: while(s1>(s2)): c+=1 s2-=s3 s2+=cpy if s2==s1: print(c) else: print((c+1)) ```
vfc_136340
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "83827465 1219917 36539", "output": "183", "type": "stdin_stdout" }, { "fn_name": null, "input": "871370 25452 8072", "output": "71", "type": "stdin_stdout" }, { "fn_name": null, "input": "3790324 321233 186612", "output": "19", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/absolute-list-sorting/1
Solve the following coding problem using the programming language python: Given a linked list of N nodes, sorted in ascending order based on the absolute values of its data,i.e. negative values are considered as positive ones. Sort the linked list in ascending order according to the actual values, and consider negative numbers as negative and positive numbers as positive. Example 1: Input: List: 1, -2, -3, 4, -5 Output: List: -5, -3, -2, 1, 4 Explanation: Actual sorted order of {1, -2, -3, 4, -5} is {-5, -3, -2, 1, 4} Example 2: Input: List: 5, -10 Output: List: -10, 5 Explanation: Actual sorted order of {5, -10} is {-10, 5} Your Task: You don't need to read or print anything. Your Task is to complete the function sortList() which takes the head of the Linked List as input parameter and sort the list in ascending order and return the head pointer of the sorted list. Expected Time Complexity: O(N) Expected Space Complexity: O(1) Constraints 1 ≤ N ≤ 10^5 -10^5 ≤ node.data ≤ 10^5 Write your solution by modifying this code: ```python #User function Template for python3 class Node: def __init__(self, data): # data -> value stored in node self.data = data self.next = None class Solution: def sortList(self,head): pass ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Node: def __init__(self, data): self.data = data self.next = None class Solution: def sortList(self, head): a = head while a.next: if a.next.data < 0: k = a.next if a.next.next: a.next = a.next.next else: a.next = None k.next = head head = k else: a = a.next return head ```
vfc_136344
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/absolute-list-sorting/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "List:1, -2, -3, 4, -5", "output": "List:-5, -3, -2, 1, 4", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Problem statement Meatishi can increase or decrease the number of fingers. There are n buns in front of Nikunishi-kun. Meatishi is trying to count the number of steamed buns by breaking his finger. There are only two shapes that Nishikun's fingers can take, whether they are broken or not. Nikunishi understands binary numbers. Nikunishi-kun can count numbers by associating each finger with a binary digit. Nikunishi doesn't understand the logarithm. Find the minimum number of fingers needed to count the buns instead of Nishikun. input n Constraint * An integer * 0 ≤ n ≤ 1018 output Print the answer on one line, and print a newline at the end. sample Sample input 1 0 Sample output 1 0 Sample input 2 Four Sample output 2 3 Sample input 3 31 Sample output 3 Five Sample input 4 36028797018963968 Sample output 4 56 Example Input 0 Output 0 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) print(0 * (n == 0) + len(str(bin(n))[2:]) * (n != 0)) ```
vfc_136346
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "5.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/697/E
Solve the following coding problem using the programming language python: As we all know Barney's job is "PLEASE" and he has not much to do at work. That's why he started playing "cups and key". In this game there are three identical cups arranged in a line from left to right. Initially key to Barney's heart is under the middle cup. $\left. \begin{array}{l}{\text{Rey}} \\{\text{to my}} \\{\text{heart}} \end{array} \right.$ Then at one turn Barney swaps the cup in the middle with any of other two cups randomly (he choses each with equal probability), so the chosen cup becomes the middle one. Game lasts n turns and Barney independently choses a cup to swap with the middle one within each turn, and the key always remains in the cup it was at the start. After n-th turn Barney asks a girl to guess which cup contains the key. The girl points to the middle one but Barney was distracted while making turns and doesn't know if the key is under the middle cup. That's why he asked you to tell him the probability that girl guessed right. Number n of game turns can be extremely large, that's why Barney did not give it to you. Instead he gave you an array a_1, a_2, ..., a_{k} such that $n = \prod_{i = 1}^{k} a_{i}$ in other words, n is multiplication of all elements of the given array. Because of precision difficulties, Barney asked you to tell him the answer as an irreducible fraction. In other words you need to find it as a fraction p / q such that $\operatorname{gcd}(p, q) = 1$, where $gcd$ is the greatest common divisor. Since p and q can be extremely large, you only need to find the remainders of dividing each of them by 10^9 + 7. Please note that we want $gcd$ of p and q to be 1, not $gcd$ of their remainders after dividing by 10^9 + 7. -----Input----- The first line of input contains a single integer k (1 ≤ k ≤ 10^5) — the number of elements in array Barney gave you. The second line contains k integers a_1, a_2, ..., a_{k} (1 ≤ a_{i} ≤ 10^18) — the elements of the array. -----Output----- In the only line of output print a single string x / y where x is the remainder of dividing p by 10^9 + 7 and y is the remainder of dividing q by 10^9 + 7. -----Examples----- Input 1 2 Output 1/2 Input 3 1 1 1 Output 0/1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python m = 1000000007 input() (n, d) = (2, 1) for q in map(int, input().split()): (d, n) = (q & d, pow(n, q, m)) n = n * pow(2, m - 2, m) % m k = (n + 1 - 2 * d) * pow(3, m - 2, m) % m print(str(k) + '/' + str(n)) ```
vfc_136350
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/697/E", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\n2\n", "output": "1/2\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: There is an ice cream shop named Ten Ice Cream. At this store, we always have 10 types of ice cream on the shelves. The store manager creates a daily graph showing how well ice cream is selling for reference in product development. For such a store manager, you decided to create a program that displays the number of each ice cream sold in a graph. Enter the total number of ice creams sold in a day and the number of ice creams sold, and create a program that outputs as many * (half-width asterisks) as the number sold for each type of ice cream. However, the type of ice cream is represented by an integer from 0 to 9. Also, for ice cream with zero sales, one- (half-width hyphen) is output. Input A sequence of multiple datasets is given as input. The end of the input is indicated by a single line of zeros. Each dataset is given in the following format: n c1 c2 :: cn The first line gives the total number of ice creams sold per day n (1 ≤ n ≤ 10000). The next n lines are given the i-th ice cream type ci (0 ≤ ci ≤ 9). The number of datasets does not exceed 20. Output For each input dataset, the number of sales is output in numerical order of each ice cream type. Example Input 15 2 6 7 0 1 9 8 7 3 8 9 4 8 2 2 3 9 1 5 0 Output * * *** * * - * ** *** ** - * - - - * - - - * The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python while True: c = [0] * 10 n = int(input()) if n == 0: break for i in range(n): a = int(input()) c[a] += 1 for i in c: if i == 0: print('-') else: print('*' * i) ```
vfc_136354
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "1.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "15\n2\n6\n7\n0\n1\n9\n8\n7\n3\n8\n9\n4\n8\n4\n2\n3\n9\n1\n5\n0", "output": "*\n*\n**\n*\n**\n-\n*\n**\n***\n**\n-\n*\n-\n-\n-\n*\n-\n-\n-\n*\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "15\n2\n6\n7\n0\n0\n9\n8\n7\n3\n8\n9\n4\n8\n2\n2\n3\n9\n1\n5\n0", "output": "**\n-\n***\n*\n*\n-\n*\n**\n***\n**\n-\n*\n-\n-\n-\n*\n-\n-\n-\n*\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/minimum-swaps-required-to-bring-all-elements-less-than-or-equal-to-k-together4847/1
Solve the following coding problem using the programming language python: Given an array arr of n positive integers and a number k. One can apply a swap operation on the array any number of times, i.e choose any two index i and j (i < j) and swap arr[i] , arr[j] . Find the minimum number of swaps required to bring all the numbers less than or equal to k together, i.e. make them a contiguous subarray. Example 1: Input : arr[ ] = {2, 1, 5, 6, 3} K = 3 Output : 1 Explanation: To bring elements 2, 1, 3 together, swap index 2 with 4 (0-based indexing), i.e. element arr[2] = 5 with arr[4] = 3 such that final array will be- arr[] = {2, 1, 3, 6, 5} Example 2: Input : arr[ ] = {2, 7, 9, 5, 8, 7, 4} K = 6 Output : 2 Explanation: To bring elements 2, 5, 4 together, swap index 0 with 2 (0-based indexing) and index 4 with 6 (0-based indexing) such that final array will be- arr[] = {9, 7, 2, 5, 4, 7, 8} Your Task: This is a function problem. The input is already taken care of by the driver code. You only need to complete the function minSwap() that takes an array (arr), sizeOfArray (n), an integer K, and return the minimum swaps required. The driver code takes care of the printing. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 ≤ N ≤ 10^{5} 1 ≤ Arr_{i}, K ≤10^{7} Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def minSwap (self,arr, n, k) : #Complete the function ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys class Solution: def minSwap(self, arr, n, k): cnt = 0 for i in range(n): if arr[i] <= k: cnt += 1 if cnt == 0 or cnt == 1 or cnt == n: return 0 ans = sys.maxsize - 1 badEle = 0 for i in range(cnt): if arr[i] > k: badEle += 1 ans = min(ans, badEle) i = 0 j = cnt while j < n: if arr[i] > k: badEle -= 1 if arr[j] > k: badEle += 1 ans = min(ans, badEle) i += 1 j += 1 return ans ```
vfc_136358
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/minimum-swaps-required-to-bring-all-elements-less-than-or-equal-to-k-together4847/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "arr[ ] = {2, 1, 5, 6, 3} \r\nK = 3", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/check-if-it-is-possible-to-convert-one-string-into-another-with-given-constraints4116/1
Solve the following coding problem using the programming language python: Given two strings S and T, which contains three characters i.e 'A', 'B' and '#' only. Check whether it is possible to convert the first string into another string by performing following operations on string first. 1- A can move towards Left only 2- B can move towards Right only 3- Neither A nor B should cross each other Note: Moving i'th character towards Left one step means swap i'th with (i-1)'th charecter [ i-1>=0 ]. Moving i'th character towards Right one step means swap i'th with (i+1)'th charecter [ i+1< string's length ]. Example 1: Input: S=#A#B#B# T=A###B#B Output: 1 Explanation: A in S is right to the A in T so A of S can move easily towards the left because there is no B on its left positions and for first B in S is left to the B in T so B of T can move easily towards the right because there is no A on its right positions and it is same for next B so S can be easily converted into T. Example 2: Input: S=#A#B# T=#B#A# Output: 0 Explanation: Here first A in S is left to the A in T and according to the condition, A cant move towards right,so S cant be converted into T. Your Task: You don't need to read input or print anything. Your task is to complete the function isItPossible() which takes the two strings S, T and their respective lengths M and N as input parameters and returns 1 if S can be converted into T. Otherwise, it returns 0. Expected Time Complexity: O(M+N) where M is size of string S and N is size of string T. Expected Auxillary Space: O(1) Constraints: 1<=M,N<=100000 Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def isItPossible(sef, S, T, M, N): #code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def isItPossible(sef, S, T, M, N): if M != N: return 0 i = 0 j = 0 if S.count('#') != T.count('#'): return 0 while i < N and j < M: while i < N and S[i] == '#': i += 1 while j < M and T[j] == '#': j += 1 if i < N and j < M: if S[i] != T[j]: return 0 if i < j and S[i] == 'A': return 0 if j < i and S[i] == 'B': return 0 i += 1 j += 1 return 1 ```
vfc_136359
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/check-if-it-is-possible-to-convert-one-string-into-another-with-given-constraints4116/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "S=#A#B#B# \r\nT=A###B#B", "output": "1", "type": "stdin_stdout" }, { "fn_name": null, "input": "S=#A#B# \r\nT=#B#A#", "output": "0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1619/A
Solve the following coding problem using the programming language python: A string is called square if it is some string written twice in a row. For example, the strings "aa", "abcabc", "abab" and "baabaa" are square. But the strings "aaa", "abaaab" and "abcdabc" are not square. For a given string $s$ determine if it is square. -----Input----- The first line of input data contains an integer $t$ ($1 \le t \le 100$) —the number of test cases. This is followed by $t$ lines, each containing a description of one test case. The given strings consist only of lowercase Latin letters and have lengths between $1$ and $100$ inclusive. -----Output----- For each test case, output on a separate line: YES if the string in the corresponding test case is square, NO otherwise. You can output YES and NO in any case (for example, strings yEs, yes, Yes and YES will be recognized as a positive response). -----Examples----- Input 10 a aa aaa aaaa abab abcabc abacaba xxyy xyyx xyxy Output NO YES NO YES YES YES NO NO NO YES -----Note----- None The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n = int(input()) for i in range(n): out = input() if len(out) % 2 == 0: mid = len(out) // 2 a = out[:mid] if a * 2 == out: print('YES') else: print('NO') else: print('NO') ```
vfc_136360
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1619/A", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\na\naa\naaa\naaaa\nabab\nabcabc\nabacaba\nxxyy\nxyyx\nxyxy\n", "output": "NO\nYES\nNO\nYES\nYES\nYES\nNO\nNO\nNO\nYES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nzz\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nacascnakcn\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nababab\n", "output": "NO\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nacascnakcn\n", "output": "NO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/PTRN2020/problems/ITGUY40
Solve the following coding problem using the programming language python: The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of input, one integer $K$. -----Output:----- For each test case, output as the pattern. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq K \leq 100$ -----Sample Input:----- 3 2 3 4 -----Sample Output:----- 21 1 123 21 1 4321 123 21 1 -----EXPLANATION:----- No need, else pattern can be decode easily. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for _ in range(int(input())): n = int(input()) s = '' for i in range(1, n + 1): s += str(i) for i in range(n, 0, -1): if i % 2 == 0: for j in range(i, 0, -1): print(j, end='') else: for j in range(1, i + 1): print(j, end='') print() ```
vfc_136364
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/PTRN2020/problems/ITGUY40", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2\n3\n4\n", "output": "21\n1\n123\n21\n1\n4321\n123\n21\n1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/875/B
Solve the following coding problem using the programming language python: Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation. For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following: He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th. Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one. Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence. The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task. -----Input----- The first line contains single integer n (1 ≤ n ≤ 300 000) — number of coins that Sasha puts behind Dima. Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≤ p_{i} ≤ n) — positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right. -----Output----- Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on. -----Examples----- Input 4 1 3 4 2 Output 1 2 3 2 1 Input 8 6 8 3 4 7 2 1 5 Output 1 2 2 3 4 3 4 5 1 -----Note----- Let's denote as O coin out of circulation, and as X — coin is circulation. At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges. After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process. XOOO → OOOX After replacement of the third coin, Dima's actions look this way: XOXO → OXOX → OOXX After replacement of the fourth coin, Dima's actions look this way: XOXX → OXXX Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def f(n, a): a = list(map(lambda s: s - 1, a)) ar = [0] * (n + 1) l = 0 ans = [1] hi = n - 1 cnt = 0 for i in a: if i == hi: ar[i] = 1 hi -= 1 while ar[hi] == 1: hi -= 1 cnt -= 1 else: ar[i] = 1 cnt += 1 ans.append(cnt + 1) return ans a = int(input()) ls = list(map(int, input().strip().split())) print(*f(a, ls)) ```
vfc_136369
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/875/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 3 4 2\n", "output": "1 2 3 2 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n6 8 3 4 7 2 1 5\n", "output": "1 2 2 3 4 3 4 5 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1\n", "output": "1 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11\n10 8 9 4 6 3 5 1 11 7 2\n", "output": "1 2 3 4 5 6 7 8 9 6 2 1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "11\n10 8 9 4 3 5 1 11 7 2 6\n", "output": "1 2 3 4 5 6 7 8 5 5 6 1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/794/A
Solve the following coding problem using the programming language python: A robber has attempted to rob a bank but failed to complete his task. However, he had managed to open all the safes. Oleg the bank client loves money (who doesn't), and decides to take advantage of this failed robbery and steal some money from the safes. There are many safes arranged in a line, where the i-th safe from the left is called safe i. There are n banknotes left in all the safes in total. The i-th banknote is in safe x_{i}. Oleg is now at safe a. There are two security guards, one of which guards the safe b such that b < a, i.e. the first guard is to the left of Oleg. The other guard guards the safe c so that c > a, i.e. he is to the right of Oleg. The two guards are very lazy, so they do not move. In every second, Oleg can either take all the banknotes from the current safe or move to any of the neighboring safes. However, he cannot visit any safe that is guarded by security guards at any time, becaues he might be charged for stealing. Determine the maximum amount of banknotes Oleg can gather. -----Input----- The first line of input contains three space-separated integers, a, b and c (1 ≤ b < a < c ≤ 10^9), denoting the positions of Oleg, the first security guard and the second security guard, respectively. The next line of input contains a single integer n (1 ≤ n ≤ 10^5), denoting the number of banknotes. The next line of input contains n space-separated integers x_1, x_2, ..., x_{n} (1 ≤ x_{i} ≤ 10^9), denoting that the i-th banknote is located in the x_{i}-th safe. Note that x_{i} are not guaranteed to be distinct. -----Output----- Output a single integer: the maximum number of banknotes Oleg can take. -----Examples----- Input 5 3 7 8 4 7 5 5 3 6 2 8 Output 4 Input 6 5 7 5 1 5 7 92 3 Output 0 -----Note----- In the first example Oleg can take the banknotes in positions 4, 5, 6 (note that there are 2 banknotes at position 5). Oleg can't take the banknotes in safes 7 and 8 because he can't run into the second security guard. Similarly, Oleg cannot take the banknotes at positions 3 and 2 because he can't run into the first security guard. Thus, he can take a maximum of 4 banknotes. For the second sample, Oleg can't take any banknotes without bumping into any of the security guards. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python (a, b, c) = map(int, input().split()) n = int(input()) l = list(map(int, input().split())) count = 0 for i in l: if i > b and i < c: count = count + 1 print(count) ```
vfc_136373
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/794/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 3 7\n8\n4 7 5 5 3 6 2 8\n", "output": "4\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Sheldon Cooper, Leonard Hofstadter and Penny decide to go for drinks at Cheese cake factory. Sheldon proposes to make a game out of this. Sheldon proposes as follows, To decide the amount of beverage they plan to consume, say X. Then order for a random number of different drinks, say {A, B, C, D, E, F} of quantities {a, b, c, d, e, f} respectively. If quantity of any three drinks add up to X then we'll have it else we'll return the order. E.g. If a + d + f = X then True else False. You are given Number of bottles N corresponding to different beverages and hence their sizes. Next line contains the size of bottles present in string format. Last line consists of an integer value, denoted by X above. Your task is to help find out if there can be any combination of three beverage sizes that can sum up to the quantity they intend to consume. If such a combination is possible print True else False Input Format First line contains number of bottles ordered denoted by N. Next line contains the size of bottles(a) present in string format. Last line contains the quantity they intend to consume denoted by X in text above. Output Format True, if combination is possible False, if combination is not possible. constraints N ≥ 3 X,a ≤ 30000 SAMPLE INPUT 6 1 4 45 6 10 8 22 SAMPLE OUTPUT True Explanation The sum of 2nd, 5th and 6th beverage size is equal to 22. So the output will be True. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python n=eval(input()) a=list(map(int,input().split())) m=eval(input()) b=[ a[x]+a[y]+a[z] for x in range(n-2) for y in range(x+1,n-1) for z in range(y+1,n)] print("True" if m in b else "False") ```
vfc_136377
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n45 55 5 7 23 4\n107", "output": "True", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n4 8 9 7 45 6 3 27\n56", "output": "True", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n2 5 4 9 7 33 6\n44", "output": "True", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4 3 25 5\n33", "output": "True", "type": "stdin_stdout" }, { "fn_name": null, "input": "8\n4 8 9 7 45 6 3 27\n156", "output": "False", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n55 45 2 23\n58", "output": "False", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1613/C
Solve the following coding problem using the programming language python: Monocarp is playing yet another computer game. In this game, his character has to kill a dragon. The battle with the dragon lasts $100^{500}$ seconds, during which Monocarp attacks the dragon with a poisoned dagger. The $i$-th attack is performed at the beginning of the $a_i$-th second from the battle start. The dagger itself does not deal damage, but it applies a poison effect on the dragon, which deals $1$ damage during each of the next $k$ seconds (starting with the same second when the dragon was stabbed by the dagger). However, if the dragon has already been poisoned, then the dagger updates the poison effect (i.e. cancels the current poison effect and applies a new one). For example, suppose $k = 4$, and Monocarp stabs the dragon during the seconds $2$, $4$ and $10$. Then the poison effect is applied at the start of the $2$-nd second and deals $1$ damage during the $2$-nd and $3$-rd seconds; then, at the beginning of the $4$-th second, the poison effect is reapplied, so it deals exactly $1$ damage during the seconds $4$, $5$, $6$ and $7$; then, during the $10$-th second, the poison effect is applied again, and it deals $1$ damage during the seconds $10$, $11$, $12$ and $13$. In total, the dragon receives $10$ damage. Monocarp knows that the dragon has $h$ hit points, and if he deals at least $h$ damage to the dragon during the battle — he slays the dragon. Monocarp has not decided on the strength of the poison he will use during the battle, so he wants to find the minimum possible value of $k$ (the number of seconds the poison effect lasts) that is enough to deal at least $h$ damage to the dragon. -----Input----- The first line contains a single integer $t$ ($1 \le t \le 1000$) — the number of test cases. The first line of the test case contains two integers $n$ and $h$ ($1 \le n \le 100; 1 \le h \le 10^{18}$) — the number of Monocarp's attacks and the amount of damage that needs to be dealt. The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le 10^9; a_i < a_{i + 1}$), where $a_i$ is the second when the $i$-th attack is performed. -----Output----- For each test case, print a single integer — the minimum value of the parameter $k$, such that Monocarp will cause at least $h$ damage to the dragon. -----Examples----- Input 4 2 5 1 5 3 10 2 4 10 5 3 1 2 4 5 7 4 1000 3 25 64 1337 Output 3 4 1 470 -----Note----- In the first example, for $k=3$, damage is dealt in seconds $[1, 2, 3, 5, 6, 7]$. In the second example, for $k=4$, damage is dealt in seconds $[2, 3, 4, 5, 6, 7, 10, 11, 12, 13]$. In the third example, for $k=1$, damage is dealt in seconds $[1, 2, 4, 5, 7]$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from __future__ import division, print_function import math import sys import os from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() (self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b'\n') + (not b) ptr = self.buffer.tell() (self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) (self.buffer.truncate(0), self.buffer.seek(0)) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode('ascii')) self.read = lambda : self.buffer.read().decode('ascii') self.readline = lambda : self.buffer.readline().decode('ascii') def print(*args, **kwargs): (sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout)) at_start = True for x in args: if not at_start: file.write(sep) file.write(str(x)) at_start = False file.write(kwargs.pop('end', '\n')) if kwargs.pop('flush', False): file.flush() if sys.version_info[0] < 3: (sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout)) else: (sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout)) input = lambda : sys.stdin.readline().rstrip('\r\n') def inp(): return int(input()) def inps(): return input().strip() def inlt(): return list(map(int, input().split())) def insr(): s = input().strip() return list(s[:len(s)]) def invr(): return map(int, input().split()) def good(k): val = k for i in range(1, n): val += min(k, l[i] - l[i - 1]) if val >= h: return 1 return 0 for _ in range(inp()): (n, h) = invr() l = inlt() mn = 1 mx = 10 ** 20 while mn < mx - 1: mid = (mn + mx) // 2 if good(mid): mx = mid else: mn = mid if good(mn): print(mn) else: print(mx) ```
vfc_136381
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1613/C", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n2 5\n1 5\n3 10\n2 4 10\n5 3\n1 2 4 5 7\n4 1000\n3 25 64 1337\n", "output": "3\n4\n1\n470\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 1000000000000000000\n1000000\n", "output": "1000000000000000000\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Champernown constant is an irrational number represented in decimal by "0." followed by concatenation of all positive integers in the increasing order. The first few digits of this constant are: 0.123456789101112... Your task is to write a program that outputs the K digits of Chapnernown constant starting at the N-th place for given two natural numbers K and N. Input The input has multiple lines. Each line has two positive integers N and K (N ≤ 109, K ≤ 100) separated by a space. The end of input is indicated by a line with two zeros. This line should not be processed. Output For each line, output a line that contains the K digits. Example Input 4 5 6 7 0 0 Output 45678 6789101 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from collections import defaultdict from collections import deque from heapq import heappush, heappop import sys import math import bisect import random def LI(): return list(map(int, sys.stdin.readline().split())) def I(): return int(sys.stdin.readline()) def LS(): return list(map(list, sys.stdin.readline().split())) def S(): return list(sys.stdin.readline())[:-1] def IR(n): l = [None for i in range(n)] for i in range(n): l[i] = I() return l def LIR(n): l = [None for i in range(n)] for i in range(n): l[i] = LI() return l def SR(n): l = [None for i in range(n)] for i in range(n): l[i] = S() return l def LSR(n): l = [None for i in range(n)] for i in range(n): l[i] = LS() return l sys.setrecursionlimit(1000000) mod = 1000000007 def A(): n = I() li = list('ixcm') k = [1, 10, 100, 1000] d = {'i': 1, 'x': 10, 'c': 100, 'm': 1000} f = ['i', 'x', 'c', 'm'] for _ in range(n): (a, b) = LS() s = 0 for i in range(len(a)): if a[i] in li: a[i] = d[a[i]] if i > 0 and a[i - 1] not in k: s += a[i - 1] * a[i] else: s += a[i] else: a[i] = int(a[i]) for i in range(len(b)): if b[i] in li: b[i] = d[b[i]] if i > 0 and b[i - 1] not in k: s += b[i - 1] * b[i] else: s += b[i] else: b[i] = int(b[i]) ans = [] while s != 0: i = int(math.log(s + 0.1, 10)) m = s // k[i] s %= k[i] if m != 1: ans.append(m) ans.append(f[i]) for i in ans: print(i, end='') print() return def B(): d = [(0, 1), (0, -1), (1, 0), (-1, 0), (1, 1), (-1, -1)] while 1: (t, n) = LI() if t == n == 0: break f = defaultdict(lambda : 1) for i in range(n): (x, y) = LI() f[x, y] = 0 (x, y) = LI() bfs = defaultdict(lambda : 1) q = deque() q.append((x, y, 0)) bfs[x, y] = 0 ans = 1 while q: (x, y, turn) = q.popleft() if turn < t: for (dx, dy) in d: x2 = x + dx y2 = y + dy if bfs[x2, y2]: if f[x2, y2]: ans += 1 bfs[x2, y2] = 0 q.append((x2, y2, turn + 1)) print(ans) return def C(): return def D(): def f(n): if d[n] != None: return d[n] else: i = int(math.log(n + 0.1, 10)) d[n] = d[10 ** i] m = n - 10 ** i d[n] += (i + 1) * m return d[n] lis = [1] for i in range(10): lis.append(lis[-1] + (i + 1) * 9 * 10 ** i) d = defaultdict(lambda : None) for i in range(11): d[10 ** i] = lis[i] while 1: (n, k) = LI() if n == k == 0: break l = 0 r = 1000000000 while r - l > 1: m = (r + l) // 2 if n < f(m): r = m else: l = m s = str(l)[n - f(l):] n = l while len(s) <= k: k -= len(s) print(s, end='') n += 1 s = str(n) print(s[:k]) return def E(): return def F(): return def G(): return def H(): return def I_(): return def J(): return D() ```
vfc_136385
{ "difficulty": "unknown_difficulty", "memory_limit": "134.217728 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 5\n6 7\n0 0", "output": "34567\n6789101\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n1 7\n0 0", "output": "45678\n1234567\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4 5\n1 13\n0 0", "output": "45678\n1234567891011\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 5\n1 13\n0 0", "output": "23456\n1234567891011\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "8 5\n6 7\n0 0", "output": "89101\n6789101\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 5\n6 5\n0 0", "output": "34567\n67891\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/733/D
Solve the following coding problem using the programming language python: Kostya is a genial sculptor, he has an idea: to carve a marble sculpture in the shape of a sphere. Kostya has a friend Zahar who works at a career. Zahar knows about Kostya's idea and wants to present him a rectangular parallelepiped of marble from which he can carve the sphere. Zahar has n stones which are rectangular parallelepipeds. The edges sizes of the i-th of them are a_{i}, b_{i} and c_{i}. He can take no more than two stones and present them to Kostya. If Zahar takes two stones, he should glue them together on one of the faces in order to get a new piece of rectangular parallelepiped of marble. Thus, it is possible to glue a pair of stones together if and only if two faces on which they are glued together match as rectangles. In such gluing it is allowed to rotate and flip the stones in any way. Help Zahar choose such a present so that Kostya can carve a sphere of the maximum possible volume and present it to Zahar. -----Input----- The first line contains the integer n (1 ≤ n ≤ 10^5). n lines follow, in the i-th of which there are three integers a_{i}, b_{i} and c_{i} (1 ≤ a_{i}, b_{i}, c_{i} ≤ 10^9) — the lengths of edges of the i-th stone. Note, that two stones may have exactly the same sizes, but they still will be considered two different stones. -----Output----- In the first line print k (1 ≤ k ≤ 2) the number of stones which Zahar has chosen. In the second line print k distinct integers from 1 to n — the numbers of stones which Zahar needs to choose. Consider that stones are numbered from 1 to n in the order as they are given in the input data. You can print the stones in arbitrary order. If there are several answers print any of them. -----Examples----- Input 6 5 5 5 3 2 4 1 4 1 2 1 3 3 2 4 3 3 4 Output 1 1 Input 7 10 7 8 5 10 3 4 2 6 5 5 5 10 2 8 4 2 1 7 7 7 Output 2 1 5 -----Note----- In the first example we can connect the pairs of stones: 2 and 4, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 2 and 5, the size of the parallelepiped: 3 × 2 × 8 or 6 × 2 × 4 or 3 × 4 × 4, the radius of the inscribed sphere 1, or 1, or 1.5 respectively. 2 and 6, the size of the parallelepiped: 3 × 5 × 4, the radius of the inscribed sphere 1.5 4 and 5, the size of the parallelepiped: 3 × 2 × 5, the radius of the inscribed sphere 1 5 and 6, the size of the parallelepiped: 3 × 4 × 5, the radius of the inscribed sphere 1.5 Or take only one stone: 1 the size of the parallelepiped: 5 × 5 × 5, the radius of the inscribed sphere 2.5 2 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1 3 the size of the parallelepiped: 1 × 4 × 1, the radius of the inscribed sphere 0.5 4 the size of the parallelepiped: 2 × 1 × 3, the radius of the inscribed sphere 0.5 5 the size of the parallelepiped: 3 × 2 × 4, the radius of the inscribed sphere 1 6 the size of the parallelepiped: 3 × 3 × 4, the radius of the inscribed sphere 1.5 It is most profitable to take only the first stone. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from itertools import combinations def sides_pairs(box): return set((tuple(sorted(side)) for side in combinations(box.dimensions, 2))) def two_integer_tuple_hash(t, hash_mul): value = 3430008 for item in t: value = value * hash_mul ^ item return value class Box: def __init__(self, dimensions, ind): self.dimensions = dimensions self.ind = ind class HashTable: def __init__(self, hash_function, hash_mul=None): self.hash_function = hash_function self.table = [None] * 2 ** 20 self.keys_set = set() if not hash_mul: self.hash_mul = 1000003 else: self.hash_mul = hash_mul def __getitem__(self, key): try: key_hash = self.hash_function(key, self.hash_mul) except: raise KeyError(key) ind = key_hash & len(self.table) - 1 if self.table[ind]: for item in self.table[ind]: if item[0] == key: return item[1] raise KeyError(key) def __setitem__(self, key, value): try: key_hash = self.hash_function(key, self.hash_mul) except: raise KeyError(key) ind = key_hash & len(self.table) - 1 if not self.table[ind]: self.table[ind] = [] self.table[ind].append((key, value)) self.keys_set.add(key) else: replaced = False for (i, item) in enumerate(self.table[ind]): if item[0] == key: self.table[ind][i] = (key, value) replaced = True break if not replaced: self.table[ind].append((key, value)) self.keys_set.add(key) def __repr__(self): items = [] for item_list in self.table: if not item_list: continue for item in item_list: items.append(item) items_repr = [list(map(repr, item)) for item in items] return '{{{}}}'.format(', '.join(map(lambda item: '{}: {}'.format(*item), items_repr))) def keys(self): return self.keys_set class HashSolver: def __init__(self): self.table = HashTable(two_integer_tuple_hash) self.best_boxes = [] self.diam = 0 def insert(self, box): box_diam = min(box.dimensions) if box_diam > self.diam: self.diam = box_diam self.best_boxes = [box.ind] surfaces = sides_pairs(box) for surface_sides in surfaces: if self.diam > min(surface_sides): continue third_side = box.dimensions[:] for side in surface_sides: third_side.remove(side) third_side = third_side[0] if surface_sides not in self.table.keys(): self.table[surface_sides] = (box, third_side) continue (hashed_box, hashed_side) = self.table[surface_sides] stacking_diam = min([third_side + hashed_side] + list(surface_sides)) if stacking_diam > self.diam: self.diam = stacking_diam self.best_boxes = [box.ind, hashed_box.ind] if third_side > hashed_side: self.table[surface_sides] = (box, third_side) hash_table = HashSolver() n_boxes = int(input()) for box_num in range(1, n_boxes + 1): box = Box(list(map(int, input().split())), box_num) hash_table.insert(box) print(len(hash_table.best_boxes)) print(' '.join(map(str, sorted(hash_table.best_boxes)))) ```
vfc_136389
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/733/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6\n5 5 5\n3 2 4\n1 4 1\n2 1 3\n3 2 4\n3 3 4\n", "output": "1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "7\n10 7 8\n5 10 3\n4 2 6\n5 5 5\n10 2 8\n4 2 1\n7 7 7\n", "output": "2\n1 5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n1 1 1\n", "output": "1\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2\n2 3 1\n2 2 3\n", "output": "2\n2 1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: There is a sale in the market on clothes , so as usual N girls gathered there to grab great deals.But due to huge popularity of sale crowd has gone uncontrollable. You being head of management team of the mall has been assigned the task to make them form a queue so that everyone can shop turn-wise. Since queue is going to be very long and knowing that its gonna take time for their turn there are M pair of girls who want to stand together in the queue so that they can discuss their personal stuff meanwhile. Now you need to make them form a queue so that none of them gets disappointed. INPUT: First line of input contains T number of test-cases , first line of each test-case contains two elements N , M total number of girls and number of pair of girls who wants to stand together. Next M line will contain pair of integers x y , which mean in queue they either stand as x y or y x . OUTPUT: For each test-case in a new line output "NO" ( without quotes ) if there is no possible arrangement such that no one gets disappointed if such a arrangement is possible print "YES" ( without quotes ) . Constraints: 1 ≤ T ≤ 10 N , M ≤ 10 ^ 5 SAMPLE INPUT 2 5 3 1 2 3 4 2 5 4 3 1 2 1 3 1 4 SAMPLE OUTPUT YES NO The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python test = int(input()) def solve(v,a,visit,parent): visit[v] = 1 # color[v] = val # print v,a[v] for i in a[v]: if visit[i] == 0: if solve(i,a,visit,v): # print v,i,parent return True else: if i != parent: # print v,i,parent return True return False while test > 0: flag = 0 visit = [0 for i in range(100002)] # color = [-1 for i in range(2020)] n,m = list(map(int, input().split(' '))) a =[[] for i in range(100002)] for i in range(m): x,y = list(map(int, input().split(' '))) a[x].append(y) a[y].append(x) check = 0 for x in range(1,n+2): if visit[x] == 0: check = solve(x,a,visit,-1) if len(a[x]) > 2: check = 1 if check == 1: break if check == 1: print("NO") else: print("YES") test = test - 1 ```
vfc_136393
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": null, "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "10\n384 71\n106 116\n210 128\n203 109\n298 206\n315 44\n243 380\n228 71\n253 67\n341 377\n156 105\n232 142\n375 219\n303 356\n308 32\n330 283\n103 307\n270 184\n50 89\n164 347\n166 94\n262 24\n345 362\n351 213\n300 307\n78 71\n284 309\n213 274\n15 3\n245 194\n34 190\n93 136\n369 234\n191 34\n194 354\n253 232\n319 130\n255 280\n363 93\n364 279\n272 313\n349 171\n237 49\n316 252\n51 176\n61 85\n237 25\n92 221\n131 283\n127 324\n124 251\n171 59\n252 298\n210 231\n262 61\n125 21\n374 345\n63 98\n10 378\n221 60\n41 154\n16 278\n178 108\n370 180\n262 368\n376 257\n234 34\n187 102\n203 12\n204 81\n329 328\n357 318\n4 4\n3 1\n1 4\n1 2\n3 2\n347 255\n69 347\n292 158\n167 48\n311 94\n234 165\n111 303\n338 81\n3 187\n228 108\n50 240\n240 211\n147 215\n116 115\n8 287\n229 244\n194 297\n7 138\n217 173\n296 290\n266 182\n107 139\n138 207\n219 140\n157 209\n10 206\n102 13\n179 11\n227 57\n126 344\n343 117\n4 190\n176 10\n90 45\n292 38\n97 320\n330 314\n112 230\n283 93\n132 202\n65 142\n61 276\n154 2\n286 143\n59 174\n140 164\n290 143\n6 118\n262 206\n272 206\n243 132\n178 335\n98 52\n217 143\n255 112\n345 319\n253 168\n10 169\n169 295\n311 337\n122 213\n154 174\n8 269\n292 32\n127 326\n237 23\n110 178\n120 317\n339 337\n113 246\n101 220\n327 116\n40 336\n284 208\n47 10\n308 278\n223 114\n104 340\n35 158\n135 162\n137 134\n294 9\n311 66\n89 66\n165 311\n74 28\n183 54\n143 222\n152 189\n192 308\n309 152\n238 294\n28 105\n49 63\n262 183\n334 161\n317 280\n170 43\n108 258\n108 36\n221 182\n63 166\n345 316\n40 259\n267 341\n220 228\n146 220\n174 283\n324 333\n345 239\n168 94\n52 137\n136 331\n180 244\n4 50\n279 334\n341 104\n152 338\n72 301\n295 232\n329 203\n214 266\n138 191\n251 246\n192 71\n339 6\n318 128\n337 260\n134 340\n72 175\n327 66\n278 241\n56 113\n195 68\n214 142\n62 305\n107 276\n223 244\n229 236\n252 73\n70 244\n78 40\n134 177\n62 267\n280 133\n94 22\n198 134\n262 17\n246 109\n194 112\n13 256\n70 119\n294 55\n126 285\n291 30\n10 13\n36 197\n162 169\n27 223\n198 69\n118 291\n90 316\n78 4\n95 86\n223 288\n198 235\n306 30\n117 252\n84 5\n189 137\n144 308\n149 180\n158 73\n111 294\n295 309\n15 66\n15 104\n144 92\n217 238\n178 92\n178 138\n90 137\n167 316\n151 13\n320 103\n150 116\n173 61\n58 93\n134 169\n39 191\n240 163\n19 254\n29 272\n109 9\n162 49\n100 103\n296 299\n2 225\n267 262\n237 2\n127 149\n228 300\n320 285\n45 106\n216 194\n59 108\n119 188\n125 148\n112 343\n156 274\n44 18\n139 339\n317 140\n216 346\n164 215\n111 291\n17 338\n243 336\n38 50\n204 254\n243 25\n124 15\n212 11\n272 324\n6 190\n13 159\n207 151\n260 286\n53 238\n48 326\n106 158\n269 232\n258 274\n330 295\n87 296\n311 329\n320 88\n106 185\n208 140\n271 214\n329 283\n135 299\n196 48\n237 11\n285 47\n336 153\n204 21\n37 114\n57 129\n172 143\n77 135\n235 160\n222 103\n107 193\n243 30\n59 334\n306 57\n224 304\n48 145\n266 65\n112 27\n190 125\n57 209\n216 93\n70 255\n53 194\n187 256\n198 43\n39 70\n198 36\n91 144\n111 4\n201 207\n1 120\n45 138\n56 28\n164 246\n152 93\n148 62\n57 217\n188 109\n282 246\n59 45\n289 97\n114 52\n4 76\n68 292\n79 140\n192 257\n259 108\n88 9\n136 252\n254 159\n38 273\n92 94\n55 280\n74 31\n219 132\n253 73\n100 61\n303 281\n8 64\n267 87\n203 24\n37 155\n4 303\n35 11\n120 288\n169 157\n254 261\n122 181\n106 195\n211 196\n199 29\n455 34\n414 332\n81 224\n365 183\n343 164\n177 344\n269 5\n363 273\n95 81\n167 398\n376 213\n92 242\n300 324\n32 199\n299 174\n8 210\n79 422\n413 31\n190 194\n85 404\n357 262\n164 171\n138 72\n315 105\n152 26\n47 400\n110 10\n186 409\n205 89\n152 375\n134 160\n2 213\n453 414\n243 187\n153 328\n282 148\n19 98\n123 155\n103 112\n76 100\n225 282\n104 226\n69 228\n21 162\n34 78\n131 238\n131 29\n245 154\n274 197\n109 202\n65 122\n68 15\n220 122\n169 254\n166 245\n71 108\n176 106\n265 177\n52 217\n56 17\n13 118\n254 143\n78 149\n229 70\n277 269\n203 59\n73 260\n42 241\n231 139\n135 234\n246 29\n271 160\n205 254\n95 192\n270 107\n28 174\n181 105\n40 59\n106 34\n46 241\n24 86\n160 28\n63 133\n268 225\n271 53\n108 166\n13 97\n44 149\n68 138\n58 270\n244 17\n161 74\n54 200\n133 159\n165 178\n49 120\n263 209\n147 257\n273 132\n131 262\n116 239\n145 128\n267 120\n276 266\n257 266\n253 150\n282 131\n224 53\n262 6\n144 76\n183 192\n195 95\n50 59\n1 41\n123 63\n234 238\n19 96\n16 217\n148 223\n201 122\n206 171\n204 138\n234 77\n190 213\n82 51\n221 264\n175 133\n8 224\n192 8\n264 246\n2 147\n201 21\n175 148\n169 40\n89 87\n93 226\n190 14\n81 141\n90 203\n3 171\n185 223\n84 77\n6 91\n19 129\n30 214\n92 32\n79 224\n266 253\n90 84\n224 110\n171 34\n53 10\n48 66\n150 69\n268 84\n240 170\n239 255\n179 244\n278 197\n22 239\n60 113\n202 70\n54 117\n201 195\n184 89\n161 237\n98 208\n234 179\n208 219\n194 97\n38 150\n70 216\n43 65\n62 64\n235 54\n108 155\n123 162\n271 27\n236 189\n153 138\n209 31\n24 24\n170 257\n134 96\n63 49\n9 13\n22 52\n37 60\n33 60\n37 1\n56 19\n8 48\n25 42\n32 59\n36 38\n8 10\n36 58\n56 62\n48 6\n59 20\n54 5\n33 11\n54 4\n7 24\n63 43\n24 56\n61 29\n40 22\n7 6\n16 40\n43 23\n50 13\n12 61\n45 5\n18 34\n9 48\n44 61\n51 48\n21 48\n27 42\n40 23\n5 14\n42 11\n19 55\n49 60\n13 33\n9 28\n9 18\n25 53\n21 29\n22 62\n26 9\n46 44\n57 8\n234 166\n3 206\n36 60\n44 196\n50 81\n102 143\n140 55\n206 67\n216 147\n27 92\n50 30\n200 143\n163 234\n60 222\n142 169\n153 16\n13 60\n75 56\n22 124\n8 123\n32 147\n177 109\n213 31\n128 111\n122 177\n140 87\n85 175\n193 169\n48 18\n156 189\n58 75\n204 70\n6 150\n231 27\n146 4\n150 177\n150 198\n158 234\n228 51\n111 222\n227 122\n180 183\n62 10\n118 215\n133 145\n169 191\n219 10\n26 97\n160 23\n123 71\n26 144\n119 48\n108 148\n47 207\n198 29\n66 62\n151 12\n11 84\n21 234\n65 154\n144 105\n110 1\n221 135\n97 146\n29 219\n88 55\n1 78\n102 108\n226 20\n186 189\n155 18\n17 71\n29 133\n26 155\n132 196\n74 147\n173 55\n147 159\n62 9\n176 90\n100 29\n144 100\n106 117\n79 97\n9 30\n52 163\n153 174\n105 53\n72 130\n208 75\n198 153\n221 136\n80 6\n166 141\n14 107\n230 219\n135 12\n190 112\n234 140\n81 8\n42 4\n170 194\n177 40\n13 120\n42 92\n194 111\n10 52\n118 89\n57 49\n101 177\n155 97\n33 161\n214 223\n144 213\n128 224\n221 169\n227 28\n68 13\n160 215\n104 225\n91 219\n43 208\n180 99\n22 46\n147 48\n14 180\n80 227\n168 95\n78 167\n85 64\n208 183\n91 208\n224 30\n92 149\n10 67\n12 100\n51 54\n179 102\n24 72\n20 43\n119 33\n222 70\n132 27\n165 209\n193 121\n38 38\n175 234\n11 164\n136 208\n185 145\n40 196\n117 197\n121 167\n64 16\n5 83\n58 123\n222 45\n65 119\n199 8\n93 108\n45 33\n107 162\n197 8\n135 19\n25 175\n86 13\n137 206\n97 34\n87 78\n83 62\n66 57\n51 7\n64 33\n58 63\n28 5\n79 69\n80 17\n23 67\n33 95\n67 88\n57 81\n30 29\n95 80\n62 19\n92 78\n14 91\n68 64\n97 34\n30 57\n96 88\n92 77\n60 8\n94 82\n75 60\n79 44\n81 69\n59 13\n31 87\n26 27\n39 20\n7 52\n50 43\n241 111\n192 119\n12 150\n154 84\n101 179\n219 6\n120 227\n215 191\n102 140\n224 67\n107 188\n20 211\n163 64\n76 241\n178 23\n107 1\n5 58\n232 16\n79 144\n212 51\n82 190\n56 73\n47 30\n136 20\n41 118\n86 19\n64 218\n230 227\n154 64\n98 203\n199 204\n75 203\n133 65\n219 212\n209 189\n134 162\n9 190\n234 55\n91 128\n75 131\n118 32\n150 181\n122 10\n38 147\n186 135\n108 143\n211 183\n104 102\n119 194\n185 86\n14 78\n119 22\n139 225\n190 229\n224 136\n231 100\n39 11\n40 160\n133 190\n178 77\n197 158\n91 38\n212 67\n11 89\n19 196\n47 32\n145 165\n167 42\n148 115\n142 131\n9 3\n230 47\n14 141\n79 146\n203 128\n95 158\n44 185\n67 14\n123 77\n103 142\n144 21\n45 47\n185 211\n201 92\n197 214\n94 205\n217 82\n124 230\n95 74\n6 56\n201 100\n85 117\n157 151\n2 38\n227 104\n51 130\n237 209\n48 181\n178 8\n144 134\n221 237\n210 68\n190 205\n56 43\n37 175\n211 110\n33 54\n226 61\n76 227\n212 62\n203 134\n63 198\n10", "output": "NO\nNO\nYES\nYES\nNO\nNO\nNO\nNO\nNO\nNO", "type": "stdin_stdout" }, { "fn_name": null, "input": "10\n74 73\n6 10\n20 36\n67 53\n60 32\n73 18\n29 54\n42 3\n51 19\n11 53\n30 5\n10 4\n67 7\n13 60\n56 12\n28 31\n11 11\n18 8\n46 11\n38 31\n26 48\n67 46\n29 43\n42 39\n74 71\n22 9\n1 14\n67 65\n73 26\n2 26\n57 12\n15 52\n71 60\n40 34\n69 38\n47 20\n11 40\n43 17\n60 11\n34 37\n7 55\n45 59\n46 38\n49 44\n63 51\n47 23\n40 61\n53 37\n25 18\n48 71\n55 21\n68 44\n38 37\n38 1\n47 49\n7 60\n16 52\n1 64\n73 42\n18 46\n64 58\n10 20\n72 12\n16 23\n8 48\n21 2\n69 58\n16 33\n37 62\n59 74\n70 66\n59 11\n43 60\n53 42\n7 5\n5 6\n7 6\n5 1\n5 2\n3 1\n2 1\n2 1\n45 5\n25 35\n33 27\n18 41\n10 17\n23 12\n18 11\n6 12\n13 8\n9 8\n18 2\n4 8\n15 3\n4 16\n7 10\n3 11\n8 8\n18 3\n87 68\n11 14\n34 52\n70 7\n9 64\n45 70\n55 72\n27 6\n50 57\n59 28\n18 45\n87 44\n49 69\n4 30\n50 40\n31 77\n21 33\n3 46\n84 64\n53 84\n41 2\n66 8\n73 5\n5 28\n53 63\n55 63\n20 46\n19 60\n27 14\n82 69\n54 25\n58 66\n49 52\n24 45\n28 68\n42 60\n70 12\n67 47\n17 63\n74 61\n38 42\n36 50\n79 46\n14 19\n60 8\n87 18\n24 49\n83 72\n13 19\n22 32\n79 55\n5 61\n66 63\n20 74\n31 7\n48 60\n40 75\n22 31\n26 28\n41 77\n27 32\n7 51\n80 2\n27 84\n12 40\n21 3\n7 17\n55 65\n71 75\n27 26\n16 21\n26 10\n27 9\n14 10\n12 26\n8 21\n12 15\n12 12\n22 3\n18 13\n1 20\n4 11\n15 2\n18 18\n16 18\n16 20\n18 26\n23 5\n24 23\n3 20\n5 3\n7 16\n14 17\n3 8\n13 22\n23 25\n79 46\n11 74\n35 50\n16 15\n31 12\n46 73\n53 77\n53 49\n21 42\n60 51\n29 69\n73 11\n33 77\n77 44\n40 16\n36 9\n36 46\n58 71\n16 73\n60 21\n59 26\n69 32\n23 17\n1 18\n58 36\n68 7\n79 61\n71 33\n59 68\n51 73\n59 61\n27 60\n60 17\n28 40\n38 7\n40 2\n13 62\n18 14\n1 75\n24 43\n57 23\n25 48\n30 58\n12 1\n51 45\n61 28\n34 62\n72 19\n49 46\n64 42\n58 22\n7 34\n45 40\n6 43\n43 59\n29 66\n39 57\n46 15\n33 59\n5 43\n7 19\n5 57\n19 2\n19 11\n48 11\n48 2\n26 20\n3 2\n3 3\n1 1", "output": "NO\nYES\nNO\nNO", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n6 5\n1 2\n2 3\n3 4\n4 1\n5 6\n5 3\n1 2\n2 3\n3 4\n7 4\n2 3\n3 4\n5 4\n6 4\n10 4\n1 2\n2 3\n3 4\n2 4", "output": "NO\nYES\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/567/D
Solve the following coding problem using the programming language python: Alice and Bob love playing one-dimensional battle ships. They play on the field in the form of a line consisting of n square cells (that is, on a 1 × n table). At the beginning of the game Alice puts k ships on the field without telling their positions to Bob. Each ship looks as a 1 × a rectangle (that is, it occupies a sequence of a consecutive squares of the field). The ships cannot intersect and even touch each other. After that Bob makes a sequence of "shots". He names cells of the field and Alice either says that the cell is empty ("miss"), or that the cell belongs to some ship ("hit"). But here's the problem! Alice like to cheat. May be that is why she responds to each Bob's move with a "miss". Help Bob catch Alice cheating — find Bob's first move, such that after it you can be sure that Alice cheated. -----Input----- The first line of the input contains three integers: n, k and a (1 ≤ n, k, a ≤ 2·10^5) — the size of the field, the number of the ships and the size of each ship. It is guaranteed that the n, k and a are such that you can put k ships of size a on the field, so that no two ships intersect or touch each other. The second line contains integer m (1 ≤ m ≤ n) — the number of Bob's moves. The third line contains m distinct integers x_1, x_2, ..., x_{m}, where x_{i} is the number of the cell where Bob made the i-th shot. The cells are numbered from left to right from 1 to n. -----Output----- Print a single integer — the number of such Bob's first move, after which you can be sure that Alice lied. Bob's moves are numbered from 1 to m in the order the were made. If the sought move doesn't exist, then print "-1". -----Examples----- Input 11 3 3 5 4 8 6 1 11 Output 3 Input 5 1 3 2 1 5 Output -1 Input 5 1 3 1 3 Output 1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python (n, k, a) = list(map(int, input().split())) m = int(input()) + 1 x = list(map(int, input().split())) + [0] (l, r) = (0, m) while r - l > 1: d = (l + r) // 2 y = sorted(x[:d]) if sum(((q - p) // (a + 1) for (p, q) in zip([0] + y, y + [n + 1]))) >= k: l = d else: r = d print(r % m - (r == m)) ```
vfc_136398
{ "difficulty": "medium_hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/567/D", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11 3 3\n5\n4 8 6 1 11\n", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
Solve the following coding problem using the programming language python: Look for the Winner! The citizens of TKB City are famous for their deep love in elections and vote counting. Today they hold an election for the next chairperson of the electoral commission. Now the voting has just been closed and the counting is going to start. The TKB citizens have strong desire to know the winner as early as possible during vote counting. The election candidate receiving the most votes shall be the next chairperson. Suppose for instance that we have three candidates A, B, and C and ten votes. Suppose also that we have already counted six of the ten votes and the vote counts of A, B, and C are four, one, and one, respectively. At this moment, every candidate has a chance to receive four more votes and so everyone can still be the winner. However, if the next vote counted is cast for A, A is ensured to be the winner since A already has five votes and B or C can have at most four votes at the end. In this example, therefore, the TKB citizens can know the winner just when the seventh vote is counted. Your mission is to write a program that receives every vote counted, one by one, identifies the winner, and determines when the winner gets ensured. Input The input consists of at most 1500 datasets, each consisting of two lines in the following format. n c1 c2 … cn n in the first line represents the number of votes, and is a positive integer no greater than 100. The second line represents the n votes, separated by a space. Each ci (1 ≤ i ≤ n) is a single uppercase letter, i.e. one of 'A' through 'Z'. This represents the election candidate for which the i-th vote was cast. Counting shall be done in the given order from c1 to cn. You should assume that at least two stand as candidates even when all the votes are cast for one candidate. The end of the input is indicated by a line containing a zero. Output For each dataset, unless the election ends in a tie, output a single line containing an uppercase letter c and an integer d separated by a space: c should represent the election winner and d should represent after counting how many votes the winner is identified. Otherwise, that is, if the election ends in a tie, output a single line containing `TIE'. Sample Input 1 A 4 A A B B 5 L M N L N 6 K K K K K K 6 X X X Y Z X 10 A A A B A C A C C B 10 U U U U U V V W W W 0 Output for the Sample Input A 1 TIE TIE K 4 X 5 A 7 U 8 Example Input 1 A 4 A A B B 5 L M N L N 6 K K K K K K 6 X X X Y Z X 10 A A A B A C A C C B 10 U U U U U V V W W W 0 Output A 1 TIE TIE K 4 X 5 A 7 U 8 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from collections import Counter while True: n = int(input()) if n == 0: quit() elif n == 1: print(input(), 1) else: c = list(input().split()) h = [0 for i in range(26)] flag = 0 for i in range(n): h[ord(c[i]) - 65] += 1 if sorted(h)[-1] - sorted(h)[-2] >= n - i: print(chr(h.index(max(h)) + 65), i + 1) flag = 1 break if flag == 0: print('TIE') ```
vfc_136402
{ "difficulty": "unknown_difficulty", "memory_limit": "268.435456 megabytes", "memory_limit_bytes": null, "problem_url": null, "time_limit": "8.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n10\nV U U U U V V W W W\n0", "output": "A 1\nTIE\nTIE\nK 4\nX 5\nA 7\nU 10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n10\nV U U U U V V W V W\n0", "output": "A 1\nTIE\nTIE\nK 4\nX 5\nA 7\nTIE\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nB A A B A C A C C B\n10\nV U U U U V V W V W\n0", "output": "A 1\nTIE\nTIE\nK 4\nX 5\nA 10\nTIE\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nB A A B A C A C C B\n10\nV U U U U W V W V W\n0", "output": "A 1\nTIE\nTIE\nK 4\nX 5\nA 10\nU 10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nA\n4\nA A B B\n5\nL M N L N\n6\nK K K K K K\n6\nX X X Y Z X\n10\nB A A B A B A C C B\n10\nV U U U U W V W V W\n0", "output": "A 1\nTIE\nTIE\nK 4\nX 5\nTIE\nU 10\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\nA\n4\nA A B B\n5\nL M N L N\n6\nK J K K K K\n6\nX X X Y Z X\n10\nA A A B A C A C C B\n10\nV U U U U V V W W W\n0", "output": "A 1\nTIE\nTIE\nK 5\nX 5\nA 7\nU 10\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/range-of-composite-numbers/1
Solve the following coding problem using the programming language python: Given an integer n, we need to find a range of positive integers such that all the number in that range are composite and length of that range is n. You may return anyone range in the case of more than one answer. Input: First line consists of T test cases. Only line, consists of an Integer N. Output: Single line output, "1" if range found else "0". Constraints: 1<=T<=100 1<=N<=100 Example: Input: 2 3 5 Output: 1 1 Write your solution by modifying this code: ```python #User function Template for python3 def Range(n): #return 1/0 #code here ``` Your solution should implemented in the function "Range". The inputs will be passed to it and it should return the correct solution. Now solve the problem and return the code.
```python def Range(n): return 1 ```
vfc_136406
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/range-of-composite-numbers/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": "Range", "input": "2\r\n\n3\r\n\n5", "output": "1\n1", "type": "function_call" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/swap-nodes-algo/problem
Solve the following coding problem using the programming language python: A binary tree is a tree which is characterized by one of the following properties: It can be empty (null). It contains a root node only. It contains a root node with a left subtree, a right subtree, or both. These subtrees are also binary trees. In-order traversal is performed as Traverse the left subtree. Visit root. Traverse the right subtree. For this in-order traversal, start from the left child of the root node and keep exploring the left subtree until you reach a leaf. When you reach a leaf, back up to its parent, check for a right child and visit it if there is one. If there is not a child, you've explored its left and right subtrees fully. If there is a right child, traverse its left subtree then its right in the same manner. Keep doing this until you have traversed the entire tree. You will only store the values of a node as you visit when one of the following is true: it is the first node visited, the first time visited it is a leaf, should only be visited once all of its subtrees have been explored, should only be visited once while this is true it is the root of the tree, the first time visited Swapping: Swapping subtrees of a node means that if initially node has left subtree L and right subtree R, then after swapping, the left subtree will be R and the right subtree, L. For example, in the following tree, we swap children of node 1. Depth 1 1 [1] / \ / \ 2 3 -> 3 2 [2] \ \ \ \ 4 5 5 4 [3] In-order traversal of left tree is 2 4 1 3 5 and of right tree is 3 5 1 2 4. Swap operation: We define depth of a node as follows: The root node is at depth 1. If the depth of the parent node is d, then the depth of current node will be d+1. Given a tree and an integer, k, in one operation, we need to swap the subtrees of all the nodes at each depth h, where h ∈ [k, 2k, 3k,...]. In other words, if h is a multiple of k, swap the left and right subtrees of that level. You are given a tree of n nodes where nodes are indexed from [1..n] and it is rooted at 1. You have to perform t swap operations on it, and after each swap operation print the in-order traversal of the current state of the tree. Function Description Complete the swapNodes function in the editor below. It should return a two-dimensional array where each element is an array of integers representing the node indices of an in-order traversal after a swap operation. swapNodes has the following parameter(s): - indexes: an array of integers representing index values of each $node[i]$, beginning with $node[1]$, the first element, as the root. - queries: an array of integers, each representing a $\boldsymbol{\mbox{k}}$ value. Input Format The first line contains n, number of nodes in the tree. Each of the next n lines contains two integers, a b, where a is the index of left child, and b is the index of right child of i^{th} node. Note: -1 is used to represent a null node. The next line contains an integer, t, the size of $queries$. Each of the next t lines contains an integer $\textit{queries}[i]$, each being a value $\boldsymbol{\mbox{k}}$. Output Format For each k, perform the swap operation and store the indices of your in-order traversal to your result array. After all swap operations have been performed, return your result array for printing. Constraints $1\leq n\leq1024$ $1\leq t\leq100$ $1\leq k\leq n$ Either $a=-1$ or $2<=a<=n$ Either $b=-1$ or $2<=b<=n$ The index of a non-null child will always be greater than that of its parent. Sample Input 0 3 2 3 -1 -1 -1 -1 2 1 1 Sample Output 0 3 1 2 2 1 3 Explanation 0 As nodes 2 and 3 have no children, swapping will not have any effect on them. We only have to swap the child nodes of the root node. 1 [s] 1 [s] 1 / \ -> / \ -> / \ 2 3 [s] 3 2 [s] 2 3 Note: [s] indicates that a swap operation is done at this depth. Sample Input 1 5 2 3 -1 4 -1 5 -1 -1 -1 -1 1 2 Sample Output 1 4 2 1 5 3 Explanation 1 Swapping child nodes of node 2 and 3 we get 1 1 / \ / \ 2 3 [s] -> 2 3 \ \ / / 4 5 4 5 Sample Input 2 11 2 3 4 -1 5 -1 6 -1 7 8 -1 9 -1 -1 10 11 -1 -1 -1 -1 -1 -1 2 2 4 Sample Output 2 2 9 6 4 1 3 7 5 11 8 10 2 6 9 4 1 3 7 5 10 8 11 Explanation 2 Here we perform swap operations at the nodes whose depth is either 2 or 4 for $K=2$ and then at nodes whose depth is 4 for $K=4$. 1 1 1 / \ / \ / \ / \ / \ / \ 2 3 [s] 2 3 2 3 / / \ \ \ \ / / \ \ \ \ 4 5 -> 4 5 -> 4 5 / / \ / / \ / / \ / / \ / / \ / / \ 6 7 8 [s] 6 7 8 [s] 6 7 8 \ / \ / / \ \ / \ \ / \ / / \ \ / \ 9 10 11 9 11 10 9 10 11 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def inorder(T): stack = [1] result = [] while stack: i = stack.pop() if i > 0: if T[i][1] > 0: stack.append(T[i][1]) stack.append(-i) if T[i][0] > 0: stack.append(T[i][0]) else: result.append(-i) return result def swap(T, K): (toVisit, depth) = ([1], 1) while toVisit: if depth % K == 0: for i in toVisit: T[i] = (T[i][1], T[i][0]) toVisit_ = [] for i in toVisit: if T[i][0] > 0: toVisit_.append(T[i][0]) if T[i][1] > 0: toVisit_.append(T[i][1]) toVisit = toVisit_ depth += 1 N = int(input()) T = [None] + [tuple((int(_) for _ in input().split())) for _ in range(N)] N = int(input()) for _ in range(N): swap(T, int(input())) print(' '.join((str(_) for _ in inorder(T)))) ```
vfc_136407
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/swap-nodes-algo/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n2 3\n-1 -1\n-1 -1\n2\n1\n1\n", "output": "3 1 2\n2 1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 3\n-1 4\n-1 5\n-1 -1\n-1 -1\n1\n2\n", "output": "4 2 1 5 3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/manasa-and-pizza/problem
Solve the following coding problem using the programming language python: With the college fest approaching soon, Manasa is following a strict dieting regime . Today, she just cannot resist her temptation for having a pizza. An inner conflict ensues, and she decides that she will have a pizza, only if she comes up with a solution to the problem stated below. Help her get the pizza for herself. Given a list L of N numbers, where L = { a_{1}, a_{2}, a_{3}, a_{4} .... , a_{N}} Find the value of M that is computed as described below. Input Format The first line contains an integer N i.e. size of the list L. The next line contains N space separated integers, each representing an element of the list L. Output Format Print the value of M _modulo (10^{9} + 7)_. Constraints 1 ≤ N ≤ 5100 0 ≤ a_{i} ≤ 10^{15} , where i ∈ [1 .. N] Sample Input 00 3 1 2 3 Sample Output 00 40392 Explanation There are 8 subsets of given set, S = {1,2,3} and L - S ={0} value of F(6) = 19601 S = {1,2} and L - S ={3} value of F(0) = 1 S = {1,3} and L - S ={2} value of F(2) = 17 S = {2,3} and L - S ={1} value of F(4) = 577 S = {1} and L - S ={2,3} value of F(4) = 577 S = {2} and L - S ={1,3} value of F(2) = 17 S = {3} and L - S ={1,2} value of F(0) = 1 S = {} and L - S ={1,2,3} value of F(6) = 19601 Adding all these values, we get M = 40392. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from random import randint from collections import Counter from functools import reduce from itertools import accumulate, combinations, takewhile, product home = 0 lire = 1 trace = 0 mp = 10 ** 6 if home: from mesures import ch modo = 10 ** 9 + 7 pars = [] class Lucmat: def __init__(s, P, Q, Iv, modo): (s.matBase, s.modo, s.pows, po, s.Iv) = ([[P, -Q], [1, 0]], modo, {}, 1, Iv) s.pows[1] = s.matBase s.mbl = 1 s.modo = modo def sqmatmulmod(s, m1, m2): mr = list(([0] * 2 for _ in range(2))) for l in range(len(m1)): for c in range(len(m1)): mr[l][c] = sum((m1[l][ix] * m2[ix][c] for ix in range(len(m1)))) % s.modo return mr def do(s, po): if po < 2: return s.Iv[po] if trace & 1: print('expMat', po) for bl in range(s.mbl, po.bit_length()): s.pows[bl + 1] = s.sqmatmulmod(s.pows[bl], s.pows[bl]) if trace & 2: print('\t', s.pows) s.mbl = po.bit_length() pc = 1 while not po & 1: (po, pc) = (po >> 1, pc + 1) (rm, pc, po) = (s.pows[pc], pc + 1, po >> 1) while po: if trace & 2: print(po, pc) if po & 1: rm = s.sqmatmulmod(s.pows[pc], rm) (pc, po) = (pc + 1, po >> 1) return rm[0][0] * s.Iv[0] + rm[0][1] * s.Iv[1] def faire(s): Fm = Lucmat(6, 1, (1, 3), modo) r = 1 for v in s: r = 2 * r * Fm.do(v) % modo return r if home and (not lire): cr = ch() for Nbs in ((1, 2, 3), (1, 2, 3, 4), (1, 2, 3, 4, 5), (100, 103, 207, 209), (100, 103, 207, 209, 709), (100, 103, 207, 209, 709, 713), (100, 103, 207, 209, 709, 713, 1003), (100, 103, 207, 209, 709, 713, 1003, 2041)): print(Nbs) for f in (stupid, stupidm1, stupid4, stupid5): cr.rst() r = f(Nbs) t = cr.lap() print('\t', f.__name__, sum(Nbs), r, t) else: input() Nbs = list((int(i) for i in input().strip().split())) print(faire(Nbs)) ```
vfc_136411
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/manasa-and-pizza/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 3\n", "output": "40392\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1154/A
Solve the following coding problem using the programming language python: Polycarp has guessed three positive integers $a$, $b$ and $c$. He keeps these numbers in secret, but he writes down four numbers on a board in arbitrary order — their pairwise sums (three numbers) and sum of all three numbers (one number). So, there are four numbers on a board in random order: $a+b$, $a+c$, $b+c$ and $a+b+c$. You have to guess three numbers $a$, $b$ and $c$ using given numbers. Print three guessed integers in any order. Pay attention that some given numbers $a$, $b$ and $c$ can be equal (it is also possible that $a=b=c$). -----Input----- The only line of the input contains four positive integers $x_1, x_2, x_3, x_4$ ($2 \le x_i \le 10^9$) — numbers written on a board in random order. It is guaranteed that the answer exists for the given number $x_1, x_2, x_3, x_4$. -----Output----- Print such positive integers $a$, $b$ and $c$ that four numbers written on a board are values $a+b$, $a+c$, $b+c$ and $a+b+c$ written in some order. Print $a$, $b$ and $c$ in any order. If there are several answers, you can print any. It is guaranteed that the answer exists. -----Examples----- Input 3 6 5 4 Output 2 1 3 Input 40 40 40 60 Output 20 20 20 Input 201 101 101 200 Output 1 100 100 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python my_list = list(map(int, input().split())) sum_of_3 = max(my_list) answer = [] for i in my_list: if i != sum_of_3: answer.append(sum_of_3 - i) print(*answer) ```
vfc_136415
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1154/A", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3 6 5 4\n", "output": "1 2 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "40 40 40 60\n", "output": "20 20 20\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "201 101 101 200\n", "output": "1 100 100\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000000000 666666667 666666667 666666666\n", "output": "333333333 333333333 333333334\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "600000000 900000000 500000000 1000000000\n", "output": "100000000 400000000 500000000\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/DNASTRAND
Solve the following coding problem using the programming language python: You are given the sequence of Nucleotides of one strand of DNA through a string S of length N. S contains the character A, T, C, and G only. Chef knows that: A is complementary to T. T is complementary to A. C is complementary to G. G is complementary to C. Using the string S, determine the sequence of the complementary strand of the DNA. ------ Input Format ------ - First line will contain T, number of test cases. Then the test cases follow. - First line of each test case contains an integer N - denoting the length of string S. - Second line contains N characters denoting the string S. ------ Output Format ------ For each test case, output the string containing N characters - sequence of nucleotides of the complementary strand. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ N ≤ 100$ $S$ contains A, T, C, and G only ----- Sample Input 1 ------ 4 4 ATCG 4 GTCC 5 AAAAA 3 TAC ----- Sample Output 1 ------ TAGC CAGG TTTTT ATG ----- explanation 1 ------ Test case $1$: Based on the rules, the complements of A, T, C, and G are T, A, G, and C respectively. Thus, the complementary string of the given string ATCG is TAGC. Test case $2$: Based on the rules, the complements of G, T, and C are C, A, and G respectively. Thus, the complementary string of the given string GTCC is CAGG. Test case $3$: Based on the rules, the complement of A is T. Thus, the complementary string of the given string AAAAA is TTTTT. Test case $4$: Based on the rules, the complements of T, A, and C are A, T, and G respectively. Thus, the complementary string of the given string TAC is ATG. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python T = int(input()) for i in range(0, T): n = int(input()) s = input() for i in range(0, n): if s[i] == 'A': print('T', end='') elif s[i] == 'T': print('A', end='') elif s[i] == 'G': print('C', end='') elif s[i] == 'C': print('G', end='') print() ```
vfc_136419
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/DNASTRAND", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4\nATCG\n4\nGTCC\n5\nAAAAA\n3\nTAC\n", "output": "TAGC\nCAGG\nTTTTT\nATG\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/8/B
Solve the following coding problem using the programming language python: The whole world got obsessed with robots,and to keep pace with the progress, great Berland's programmer Draude decided to build his own robot. He was working hard at the robot. He taught it to walk the shortest path from one point to another, to record all its movements, but like in many Draude's programs, there was a bug — the robot didn't always walk the shortest path. Fortunately, the robot recorded its own movements correctly. Now Draude wants to find out when his robot functions wrong. Heh, if Draude only remembered the map of the field, where he tested the robot, he would easily say if the robot walked in the right direction or not. But the field map was lost never to be found, that's why he asks you to find out if there exist at least one map, where the path recorded by the robot is the shortest. The map is an infinite checkered field, where each square is either empty, or contains an obstruction. It is also known that the robot never tries to run into the obstruction. By the recorded robot's movements find out if there exist at least one such map, that it is possible to choose for the robot a starting square (the starting square should be empty) such that when the robot moves from this square its movements coincide with the recorded ones (the robot doesn't run into anything, moving along empty squares only), and the path from the starting square to the end one is the shortest. In one movement the robot can move into the square (providing there are no obstrutions in this square) that has common sides with the square the robot is currently in. Input The first line of the input file contains the recording of the robot's movements. This recording is a non-empty string, consisting of uppercase Latin letters L, R, U and D, standing for movements left, right, up and down respectively. The length of the string does not exceed 100. Output In the first line output the only word OK (if the above described map exists), or BUG (if such a map does not exist). Examples Input LLUUUR Output OK Input RRUULLDD Output BUG The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python __author__ = 'runekri3' def cells_touching(cell_1, cell_2): abs_x = abs(cell_1[0] - cell_2[0]) if abs_x > 1: return False abs_y = abs(cell_1[1] - cell_2[1]) if abs_y > 1: return False if not (abs_x == 1 and abs_y == 1): return True movements = input() total_movements = len(movements) cur_cell = [0, 0] visited_cells = [(0, 0)] last_movement = '' bug = False for movement in movements: if movement == 'U': cur_cell[1] += 1 elif movement == 'D': cur_cell[1] -= 1 elif movement == 'R': cur_cell[0] += 1 else: cur_cell[0] -= 1 for visited_cell in visited_cells[:-1]: if cells_touching(cur_cell, visited_cell): bug = True break visited_cells.append(tuple(cur_cell)) if bug: print('BUG') else: print('OK') ```
vfc_136423
{ "difficulty": "medium", "memory_limit": "64.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/8/B", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "DDUL\n", "output": "BUG\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "LLLLLLLLRRRRDDDDDDDUUUUUU\n", "output": "BUG\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "UULLDLUR\n", "output": "BUG\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "URRRLULUURURLRLLLLULLRLRURLULRLULLULRRUU\n", "output": "BUG\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/rotate-a-linked-list/1
Solve the following coding problem using the programming language python: Given a singly linked list of size N. The task is to left-shift the linked list by k nodes, where k is a given positive integer smaller than or equal to length of the linked list. Example 1: Input: N = 5 value[] = {2, 4, 7, 8, 9} k = 3 Output: 8 9 2 4 7 Explanation: Rotate 1: 4 -> 7 -> 8 -> 9 -> 2 Rotate 2: 7 -> 8 -> 9 -> 2 -> 4 Rotate 3: 8 -> 9 -> 2 -> 4 -> 7 Example 2: Input: N = 8 value[] = {1, 2, 3, 4, 5, 6, 7, 8} k = 4 Output: 5 6 7 8 1 2 3 4 Your Task: You don't need to read input or print anything. Your task is to complete the function rotate() which takes a head reference as the first argument and k as the second argument, and returns the head of the rotated linked list. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1 <= N <= 10^{3} 1 <= k <= N Write your solution by modifying this code: ```python # Your task is to complete this function ''' class Node: def __init__(self, data): self.data = data self.next = None ''' class Solution: #Function to rotate a linked list. def rotate(self, head, k): # code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def rotate(self, head, k): if head == None or k == 0: return head prev = head while prev.next: prev = prev.next for i in range(k): prev.next = head head = head.next prev = prev.next prev.next = None return head ```
vfc_136427
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/rotate-a-linked-list/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5\r\nvalue[] = {2, 4, 7, 8, 9}\r\nk = 3", "output": "8 9 2 4 7", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 8\r\nvalue[] = {1, 2, 3, 4, 5, 6, 7, 8}\r\nk = 4", "output": "5 6 7 8 1 2 3 4", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1433/B
Solve the following coding problem using the programming language python: There is a bookshelf which can fit $n$ books. The $i$-th position of bookshelf is $a_i = 1$ if there is a book on this position and $a_i = 0$ otherwise. It is guaranteed that there is at least one book on the bookshelf. In one move, you can choose some contiguous segment $[l; r]$ consisting of books (i.e. for each $i$ from $l$ to $r$ the condition $a_i = 1$ holds) and: Shift it to the right by $1$: move the book at index $i$ to $i + 1$ for all $l \le i \le r$. This move can be done only if $r+1 \le n$ and there is no book at the position $r+1$. Shift it to the left by $1$: move the book at index $i$ to $i-1$ for all $l \le i \le r$. This move can be done only if $l-1 \ge 1$ and there is no book at the position $l-1$. Your task is to find the minimum number of moves required to collect all the books on the shelf as a contiguous (consecutive) segment (i.e. the segment without any gaps). For example, for $a = [0, 0, 1, 0, 1]$ there is a gap between books ($a_4 = 0$ when $a_3 = 1$ and $a_5 = 1$), for $a = [1, 1, 0]$ there are no gaps between books and for $a = [0, 0,0]$ there are also no gaps between books. You have to answer $t$ independent test cases. -----Input----- The first line of the input contains one integer $t$ ($1 \le t \le 200$) — the number of test cases. Then $t$ test cases follow. The first line of the test case contains one integer $n$ ($1 \le n \le 50$) — the number of places on a bookshelf. The second line of the test case contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 1$), where $a_i$ is $1$ if there is a book at this position and $0$ otherwise. It is guaranteed that there is at least one book on the bookshelf. -----Output----- For each test case, print one integer: the minimum number of moves required to collect all the books on the shelf as a contiguous (consecutive) segment (i.e. the segment without gaps). -----Example----- Input 5 7 0 0 1 0 1 0 1 3 1 0 0 5 1 1 0 0 1 6 1 0 0 0 0 1 5 1 1 0 1 1 Output 2 0 2 4 1 -----Note----- In the first test case of the example, you can shift the segment $[3; 3]$ to the right and the segment $[4; 5]$ to the right. After all moves, the books form the contiguous segment $[5; 7]$. So the answer is $2$. In the second test case of the example, you have nothing to do, all the books on the bookshelf form the contiguous segment already. In the third test case of the example, you can shift the segment $[5; 5]$ to the left and then the segment $[4; 4]$ to the left again. After all moves, the books form the contiguous segment $[1; 3]$. So the answer is $2$. In the fourth test case of the example, you can shift the segment $[1; 1]$ to the right, the segment $[2; 2]$ to the right, the segment $[6; 6]$ to the left and then the segment $[5; 5]$ to the left. After all moves, the books form the contiguous segment $[3; 4]$. So the answer is $4$. In the fifth test case of the example, you can shift the segment $[1; 2]$ to the right. After all moves, the books form the contiguous segment $[2; 5]$. So the answer is $1$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) l = 0 an = 0 p = [] for i in range(n): if a[i] == 1: p.append(i) l += 1 if l == 1: an = 0 else: for i in range(l - 1): for j in range(p[i], p[i + 1]): if a[j] == 0: an += 1 print(an) ```
vfc_136428
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1433/B", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n7\n0 0 1 0 1 0 1\n3\n1 0 0\n5\n1 1 0 0 1\n6\n1 0 0 0 0 1\n5\n1 1 0 1 1\n", "output": "2\n0\n2\n4\n1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n8\n0 0 0 1 1 1 1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n8\n0 0 0 1 1 1 1 1\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n8\n0 0 0 1 1 0 1 1\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n7\n0 0 1 0 1 0 1\n3\n1 0 0\n5\n1 1 0 1 1\n6\n1 0 0 0 0 1\n5\n1 1 0 1 1\n", "output": "2\n0\n1\n4\n1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1070/K
Solve the following coding problem using the programming language python: Polycarp took $n$ videos, the duration of the $i$-th video is $a_i$ seconds. The videos are listed in the chronological order, i.e. the $1$-st video is the earliest, the $2$-nd video is the next, ..., the $n$-th video is the last. Now Polycarp wants to publish exactly $k$ ($1 \le k \le n$) posts in Instabram. Each video should be a part of a single post. The posts should preserve the chronological order, it means that the first post should contain one or more of the earliest videos, the second post should contain a block (one or more videos) going next and so on. In other words, if the number of videos in the $j$-th post is $s_j$ then: $s_1+s_2+\dots+s_k=n$ ($s_i>0$), the first post contains the videos: $1, 2, \dots, s_1$; the second post contains the videos: $s_1+1, s_1+2, \dots, s_1+s_2$; the third post contains the videos: $s_1+s_2+1, s_1+s_2+2, \dots, s_1+s_2+s_3$; ... the $k$-th post contains videos: $n-s_k+1,n-s_k+2,\dots,n$. Polycarp is a perfectionist, he wants the total duration of videos in each post to be the same. Help Polycarp to find such positive integer values $s_1, s_2, \dots, s_k$ that satisfy all the conditions above. -----Input----- The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 10^5$). The next line contains $n$ positive integer numbers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^4$), where $a_i$ is the duration of the $i$-th video. -----Output----- If solution exists, print "Yes" in the first line. Print $k$ positive integers $s_1, s_2, \dots, s_k$ ($s_1+s_2+\dots+s_k=n$) in the second line. The total duration of videos in each post should be the same. It can be easily proven that the answer is unique (if it exists). If there is no solution, print a single line "No". -----Examples----- Input 6 3 3 3 1 4 1 6 Output Yes 2 3 1 Input 3 3 1 1 1 Output Yes 1 1 1 Input 3 3 1 1 2 Output No Input 3 1 1 10 100 Output Yes 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def main(): (n, k) = map(int, input().split()) v = list(map(int, input().split())) d = sum(v) / k j = 0 res = '' sumpart = 0 for i in range(len(v)): sumpart += v[i] if sumpart == d: res += str(i + 1 - j) + ' ' j = i + 1 sumpart = 0 if j >= len(v): break elif sumpart > d: print('No') return res.rstrip() print('Yes') print(res) main() ```
vfc_136432
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1070/K", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "6 3\n3 3 1 4 1 6\n", "output": "Yes\n2 3 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 1 1\n", "output": "Yes\n1 1 1 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 3\n1 1 2\n", "output": "No", "type": "stdin_stdout" }, { "fn_name": null, "input": "3 1\n1 10 100\n", "output": "Yes\n3 ", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n3\n", "output": "Yes\n1 ", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/90/D
Solve the following coding problem using the programming language python: Vasya writes his own library for building graphical user interface. Vasya called his creation VTK (VasyaToolKit). One of the interesting aspects of this library is that widgets are packed in each other. A widget is some element of graphical interface. Each widget has width and height, and occupies some rectangle on the screen. Any widget in Vasya's library is of type Widget. For simplicity we will identify the widget and its type. Types HBox and VBox are derivatives of type Widget, so they also are types Widget. Widgets HBox and VBox are special. They can store other widgets. Both those widgets can use the pack() method to pack directly in itself some other widget. Widgets of types HBox and VBox can store several other widgets, even several equal widgets — they will simply appear several times. As a result of using the method pack() only the link to the packed widget is saved, that is when the packed widget is changed, its image in the widget, into which it is packed, will also change. We shall assume that the widget a is packed in the widget b if there exists a chain of widgets a = c1, c2, ..., ck = b, k ≥ 2, for which ci is packed directly to ci + 1 for any 1 ≤ i < k. In Vasya's library the situation when the widget a is packed in the widget a (that is, in itself) is not allowed. If you try to pack the widgets into each other in this manner immediately results in an error. Also, the widgets HBox and VBox have parameters border and spacing, which are determined by the methods set_border() and set_spacing() respectively. By default both of these options equal 0. <image> The picture above shows how the widgets are packed into HBox and VBox. At that HBox and VBox automatically change their size depending on the size of packed widgets. As for HBox and VBox, they only differ in that in HBox the widgets are packed horizontally and in VBox — vertically. The parameter spacing sets the distance between adjacent widgets, and border — a frame around all packed widgets of the desired width. Packed widgets are placed exactly in the order in which the pack() method was called for them. If within HBox or VBox there are no packed widgets, their sizes are equal to 0 × 0, regardless of the options border and spacing. The construction of all the widgets is performed using a scripting language VasyaScript. The description of the language can be found in the input data. For the final verification of the code Vasya asks you to write a program that calculates the sizes of all the widgets on the source code in the language of VasyaScript. Input The first line contains an integer n — the number of instructions (1 ≤ n ≤ 100). Next n lines contain instructions in the language VasyaScript — one instruction per line. There is a list of possible instructions below. * "Widget [name]([x],[y])" — create a new widget [name] of the type Widget possessing the width of [x] units and the height of [y] units. * "HBox [name]" — create a new widget [name] of the type HBox. * "VBox [name]" — create a new widget [name] of the type VBox. * "[name1].pack([name2])" — pack the widget [name2] in the widget [name1]. At that, the widget [name1] must be of type HBox or VBox. * "[name].set_border([x])" — set for a widget [name] the border parameter to [x] units. The widget [name] must be of type HBox or VBox. * "[name].set_spacing([x])" — set for a widget [name] the spacing parameter to [x] units. The widget [name] must be of type HBox or VBox. All instructions are written without spaces at the beginning and at the end of the string. The words inside the instruction are separated by exactly one space. There are no spaces directly before the numbers and directly after them. The case matters, for example, "wiDget x" is not a correct instruction. The case of the letters is correct in the input data. All names of the widgets consist of lowercase Latin letters and has the length from 1 to 10 characters inclusive. The names of all widgets are pairwise different. All numbers in the script are integers from 0 to 100 inclusive It is guaranteed that the above-given script is correct, that is that all the operations with the widgets take place after the widgets are created and no widget is packed in itself. It is guaranteed that the script creates at least one widget. Output For each widget print on a single line its name, width and height, separated by spaces. The lines must be ordered lexicographically by a widget's name. Please, do not use the %lld specificator to read or write 64-bit integers in C++. It is preferred to use cout stream (also you may use %I64d specificator) Examples Input 12 Widget me(50,40) VBox grandpa HBox father grandpa.pack(father) father.pack(me) grandpa.set_border(10) grandpa.set_spacing(20) Widget brother(30,60) father.pack(brother) Widget friend(20,60) Widget uncle(100,20) grandpa.pack(uncle) Output brother 30 60 father 80 60 friend 20 60 grandpa 120 120 me 50 40 uncle 100 20 Input 15 Widget pack(10,10) HBox dummy HBox x VBox y y.pack(dummy) y.set_border(5) y.set_spacing(55) dummy.set_border(10) dummy.set_spacing(20) x.set_border(10) x.set_spacing(10) x.pack(pack) x.pack(dummy) x.pack(pack) x.set_border(0) Output dummy 0 0 pack 10 10 x 40 10 y 10 10 Note In the first sample the widgets are arranged as follows: <image> The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys from array import array import re def input(): return sys.stdin.buffer.readline().decode('utf-8') class Widget(object): def __init__(self, x, y): self.x = x self.y = y class Box(object): def __init__(self): self.children = [] self.border = 0 self.spacing = 0 self._x = -1 self._y = -1 def set_border(self, size): self.border = size def set_spacing(self, size): self.spacing = size def pack(self, widget): self.children.append(widget) @property def x(self): if self._x == -1: self._x = max((child.x for child in self.children)) + self.border * 2 if self.children else 0 return self._x @property def y(self): if self._y == -1: self._y = max((child.y for child in self.children)) + self.border * 2 if self.children else 0 return self._y class HBox(Box): @property def x(self): if self._x == -1: if not self.children: return 0 a = [child.x for child in self.children] self._x = self.border * 2 + sum(a) + self.spacing * (len(a) - 1) return self._x class VBox(Box): @property def y(self): if self._y == -1: if not self.children: return 0 a = [child.y for child in self.children] self._y = self.border * 2 + sum(a) + self.spacing * (len(a) - 1) return self._y n = int(input()) namespace = {} pattern = re.compile('([^(]+?)\\(([^)]+?)\\)') def parse(s): return re.search(pattern, s).groups() for _ in range(n): command = input().split() if command[0] == 'Widget': (name, args) = parse(command[1]) namespace[name] = Widget(*tuple(map(int, args.split(',')))) elif command[0] == 'VBox': namespace[command[1]] = VBox() elif command[0] == 'HBox': namespace[command[1]] = HBox() else: (name, method) = command[0].split('.') (method, args) = parse(method) if method == 'set_border': namespace[name].set_border(int(args)) elif method == 'set_spacing': namespace[name].set_spacing(int(args)) elif method == 'pack': namespace[name].pack(namespace[args]) for name in sorted(namespace.keys()): print(f'{name} {namespace[name].x} {namespace[name].y}') ```
vfc_136436
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/90/D", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "1\nVBox abcdefghij\n", "output": "abcdefghij 0 0\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/COLOUR
Solve the following coding problem using the programming language python: For the human eye, primary colours are red, green, and blue. Combining 1 drop each of any two primary colours produces a new type of secondary colour. For example, mixing red and green gives yellow, mixing green and blue gives cyan, and, mixing red and blue gives magenta. You have X, Y, and Z drops of red, green, and blue colours respectively. Find the maximum total number of distinct colours (both primary and secondary) you can have at any particular moment. Note: You cannot mix a secondary colour with a primary or another secondary colour to get a new type of colour. ------ 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 X, Y, and Z, the number of drops of red, green, and blue colours respectively. ------ Output Format ------ For each test case, output on a new line the maximum total number of colours (both primary and secondary) you can have using the given primary colours. ------ Constraints ------ $1 ≤ T ≤ 10^{5}$ $0 ≤ X, Y, Z≤ 100$ ----- Sample Input 1 ------ 4 1 0 1 3 3 0 1 1 1 0 0 0 ----- Sample Output 1 ------ 2 3 3 0 ----- explanation 1 ------ Test case $1$: We have $1$ drop each of red and blue colour. If we mix these colours, we will have magenta but no red or blue. Thus, to maximize the total number of colours, it is better that we keep the red and blue colours as it is. The maximum number of colours we can have is $2$. Test case $2$: We have $3$ drops each of red and green colour. We can use $1$ drop each of red and green to have yellow. We still have $2$ drops each of red and green left. Thus, we have $3$ different types of colours now. Test case $3$: If we mix any two colours, we will loose two colours and get only one colour in return. Thus, it is best to keep all colours as it is and keep $3$ different varieties of colours. Test case $4$: There are no types of colours available. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python test = int(input()) while test > 0: test = test - 1 (X, Y, Z) = map(int, input().split()) list1 = [X, Y, Z] ans = 0 if list1[0] > 0: ans += 1 list1[0] -= 1 if list1[1] > 0: ans += 1 list1[1] -= 1 if list1[2] > 0: ans += 1 list1[2] -= 1 list1.sort() list1.reverse() if list1[0] > 0 and list1[1] > 0: ans += 1 list1[0] -= 1 list1[1] -= 1 if list1[0] > 0 and list1[2] > 0: ans += 1 list1[0] -= 1 list1[2] -= 1 if list1[1] > 0 and list1[2] > 0: ans += 1 list1[1] -= 1 list1[2] -= 1 print(ans) ```
vfc_136445
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/COLOUR", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 0 1\n3 3 0\n1 1 1\n0 0 0\n", "output": "2\n3\n3\n0", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/MAXCOUNT
Solve the following coding problem using the programming language python: Given an array A of length N, your task is to find the element which repeats in A maximum number of times as well as the corresponding count. In case of ties, choose the smaller element first. ------ Input ------ First line of input contains an integer T, denoting the number of test cases. Then follows description of T cases. Each case begins with a single integer N, the length of A. Then follow N space separated integers in next line. Assume that 1 ≤ T ≤ 100, 1 ≤ N ≤ 100 and for all i in [1..N] : 1 ≤ A[i] ≤ 10000 ------ Output ------ For each test case, output two space separated integers V & C. V is the value which occurs maximum number of times and C is its count. ----- Sample Input 1 ------ 2 5 1 2 3 2 5 6 1 2 2 1 1 2 ----- Sample Output 1 ------ 2 2 1 3 ----- explanation 1 ------ In first case 2 occurs twice whereas all other elements occur only once. In second case, both 1 and 2 occur 3 times but 1 is smaller than 2. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for i in range(int(input())): n = int(input()) l = list(map(int, input().split())) k = [0] * 10001 for i in range(n): k[l[i]] += 1 c = max(k) index = k.index(c) print(index, c) ```
vfc_136449
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/MAXCOUNT", "time_limit": "0.207865 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "2\n5\n1 2 3 2 5\n6\n1 2 2 1 1 2", "output": "2 2\n1 3", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/CSTR2020/problems/MALLTILE
Solve the following coding problem using the programming language python: Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a. What is the least number of flagstones needed to pave the Square? It's allowed to cover the surface larger than the Theatre Square, but the Square has to be covered. It's not allowed to break the flagstones. The sides of flagstones should be parallel to the sides of the Square. Input The input contains three positive integer numbers in the first line: n,  m and a (1 ≤  n, m, a ≤ 10^9). Output Print the needed number of flagstones in new line. Examples input 6 6 4 output 4 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python try: (n, m, a) = map(int, input().split()) if n % a != 0: number1 = n // a + 1 else: number1 = n // a if m % a != 0: number2 = m // a + 1 else: number2 = m // a print(number1 * number2) except: pass ```
vfc_136458
{ "difficulty": "unknown_difficulty", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/CSTR2020/problems/MALLTILE", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "s\ninput\n6 6 4\noutput\n4\n", "output": "", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/circle-of-strings4530/1
Solve the following coding problem using the programming language python: Given an array of lowercase strings A[] of size N, determine if the strings can be chained together to form a circle. A string X can be chained together with another string Y if the last character of X is same as first character of Y. If every string of the array can be chained with exactly two strings of the array(one with the first character and second with the last character of the string), it will form a circle. For example, for the array arr[] = {"for", "geek", "rig", "kaf"} the answer will be Yes as the given strings can be chained as "for", "rig", "geek" and "kaf" Example 1: Input: N = 3 A[] = { "abc", "bcd", "cdf" } Output: 0 Explaination: These strings can't form a circle because no string has 'd'at the starting index. Example 2: Input: N = 4 A[] = { "ab" , "bc", "cd", "da" } Output: 1 Explaination: These strings can form a circle of strings. Your Task: You don't need to read input or print output. Your task is to complete the function isCircle() which takes the length of the array N and the array A as input parameters and returns 1 if we can form a circle or 0 if we cannot. Expected Time Complexity: O(N) Expected Auxiliary Space: O(N) Constraints: 1 ≤ N ≤ 10^{4} 1 ≤ Length of strings ≤ 20 Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def isCircle(self, N, A): # code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def dfs(node, adj, vis): vis[node] = 1 for i in adj[node]: if not vis[i]: dfs(i, adj, vis) def detectCycle(src, adj, mark): vis = [0] * 26 dfs(src, adj, vis) for i in range(26): if not vis[i] and mark[i] == 1: return 0 return 1 class Solution: def isCircle(self, N, A): mark = [0] * 26 adj = [[] for _ in range(26)] in_degree = [0] * 26 out_degree = [0] * 26 for i in A: u = ord(i[0]) - ord('a') v = ord(i[-1]) - ord('a') adj[u].append(v) mark[u] = mark[v] = 1 in_degree[v] += 1 out_degree[u] += 1 for i in range(26): if in_degree[i] != out_degree[i]: return 0 return detectCycle(ord(A[0][0]) - ord('a'), adj, mark) ```
vfc_136462
{ "difficulty": "medium", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/circle-of-strings4530/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 3\nA[] = { \"abc\", \"bcd\", \"cdf\" }", "output": "0", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 4\nA[] = { \"ab\" , \"bc\", \"cd\", \"da\" }", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/774/J
Solve the following coding problem using the programming language python: Well, the series which Stepan watched for a very long time, ended. In total, the series had n episodes. For each of them, Stepan remembers either that he definitely has watched it, or that he definitely hasn't watched it, or he is unsure, has he watched this episode or not. Stepan's dissatisfaction is the maximum number of consecutive series that Stepan did not watch. Your task is to determine according to Stepan's memories if his dissatisfaction could be exactly equal to k. -----Input----- The first line contains two integers n and k (1 ≤ n ≤ 100, 0 ≤ k ≤ n) — the number of episodes in the series and the dissatisfaction which should be checked. The second line contains the sequence which consists of n symbols "Y", "N" and "?". If the i-th symbol equals "Y", Stepan remembers that he has watched the episode number i. If the i-th symbol equals "N", Stepan remembers that he hasn't watched the epizode number i. If the i-th symbol equals "?", Stepan doesn't exactly remember if he has watched the episode number i or not. -----Output----- If Stepan's dissatisfaction can be exactly equal to k, then print "YES" (without qoutes). Otherwise print "NO" (without qoutes). -----Examples----- Input 5 2 NYNNY Output YES Input 6 1 ????NN Output NO -----Note----- In the first test Stepan remembers about all the episodes whether he has watched them or not. His dissatisfaction is 2, because he hasn't watch two episodes in a row — the episode number 3 and the episode number 4. The answer is "YES", because k = 2. In the second test k = 1, Stepan's dissatisfaction is greater than or equal to 2 (because he remembers that he hasn't watch at least two episodes in a row — number 5 and number 6), even if he has watched the episodes from the first to the fourth, inclusive. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys (n, k) = list(map(int, input().split(' '))) s = input() def max_streak(s): result = 0 for i in range(len(s)): j = i while j < len(s) and s[j] == 'N': j += 1 result = max(result, j - i) return result for i in range(n - k + 1): cur = list(s) for j in range(i, i + k): if cur[j] == '?': cur[j] = 'N' for j in range(i): if cur[j] == '?': cur[j] = 'Y' for j in range(i + k, n): if cur[j] == '?': cur[j] = 'Y' if max_streak(cur) == k: print('YES') return print('NO') ```
vfc_136463
{ "difficulty": "hard", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/774/J", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 2\nNYNNY\n", "output": "YES\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "6 1\n????NN\n", "output": "NO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1389/A
Solve the following coding problem using the programming language python: Let $LCM(x, y)$ be the minimum positive integer that is divisible by both $x$ and $y$. For example, $LCM(13, 37) = 481$, $LCM(9, 6) = 18$. You are given two integers $l$ and $r$. Find two integers $x$ and $y$ such that $l \le x < y \le r$ and $l \le LCM(x, y) \le r$. -----Input----- The first line contains one integer $t$ ($1 \le t \le 10000$) — the number of test cases. Each test case is represented by one line containing two integers $l$ and $r$ ($1 \le l < r \le 10^9$). -----Output----- For each test case, print two integers: if it is impossible to find integers $x$ and $y$ meeting the constraints in the statement, print two integers equal to $-1$; otherwise, print the values of $x$ and $y$ (if there are multiple valid answers, you may print any of them). -----Example----- Input 4 1 1337 13 69 2 4 88 89 Output 6 7 14 21 2 4 -1 -1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import os import sys from io import BytesIO, IOBase BUFSIZE = 8192 class FastIO(IOBase): newlines = 0 def __init__(self, file): self._fd = file.fileno() self.buffer = BytesIO() self.writable = 'x' in file.mode or 'r' not in file.mode self.write = self.buffer.write if self.writable else None def read(self): while True: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) if not b: break ptr = self.buffer.tell() (self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)) self.newlines = 0 return self.buffer.read() def readline(self): while self.newlines == 0: b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE)) self.newlines = b.count(b'\n') + (not b) ptr = self.buffer.tell() (self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)) self.newlines -= 1 return self.buffer.readline() def flush(self): if self.writable: os.write(self._fd, self.buffer.getvalue()) (self.buffer.truncate(0), self.buffer.seek(0)) class IOWrapper(IOBase): def __init__(self, file): self.buffer = FastIO(file) self.flush = self.buffer.flush self.writable = self.buffer.writable self.write = lambda s: self.buffer.write(s.encode('ascii')) self.read = lambda : self.buffer.read().decode('ascii') self.readline = lambda : self.buffer.readline().decode('ascii') (sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout)) input = lambda : sys.stdin.readline().rstrip('\r\n') from collections import Counter import heapq from collections import Counter for _ in range(int(input())): (n, k) = map(int, input().split()) if 2 * n <= k: print(n, 2 * n) else: print(-1, -1) ```
vfc_136467
{ "difficulty": "easy", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1389/A", "time_limit": "2 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n1 1337\n13 69\n2 4\n88 89\n", "output": "1 2\n13 26\n2 4\n-1 -1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n55556 55557\n", "output": "-1 -1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5\n2 4\n2 4\n2 4\n2 4\n2 4\n", "output": "2 4\n2 4\n2 4\n2 4\n2 4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n78788 157576\n", "output": "78788 157576\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n8743 17489\n", "output": "8743 17486\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1\n96777 19555557\n", "output": "96777 193554\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/ADVANCE
Solve the following coding problem using the programming language python: Chef's current rating is X, and he wants to improve it. It is generally recommended that a person with rating X should solve problems whose difficulty lies in the range [X, X+200], i.e, problems whose difficulty is at least X and at most X+200. You find out that Chef is currently solving problems with a difficulty of Y. Is Chef following the recommended practice or not? ------ Input Format ------ - The first line of input 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, containing two space-separated integers X, Y. ------ Output Format ------ For each test case, output on a new line YES if Chef is following the recommended practice style, and NO otherwise. Each letter of the output may be printed in either lowercase or uppercase. For example, the strings YES, yEs, and Yes will be considered identical. ------ Constraints ------ $1 ≤ T ≤ 100$ $1 ≤ X, Y ≤ 4000$ ----- Sample Input 1 ------ 5 1300 1500 1201 1402 300 4000 723 805 1330 512 ----- Sample Output 1 ------ YES NO NO YES NO ----- explanation 1 ------ Test case $1$: Chef's current rating is $1300$, so he should solve problems with difficulty lying in $[1300,1500]$. Since $1500$ lies in $[1300,1500]$, Chef is doing his practice in a recommended way :) Test case $2$: Chef's current rating is $1201$, so he should solve problems with difficulty lying in $[1201,1401]$. Since $1402$ does not lie in $[1201,1401]$, Chef is not doing his practice in a recommended way :( Test case $3$: Chef's current rating is $300$, so he should solve problems with difficulty lying in $[300,500]$. Since $4000$ does not lie in $[300,500]$, Chef is not doing his practice in a recommended way :( Test case $4$: Chef's current rating is $723$, so he should solve problems with difficulty lying in $[723,923]$. Since $805$ lies in $[723,923]$, Chef is doing his practice in a recommended way :) Test case $5$: Chef's current rating is $1330$, so he should solve problems with difficulty lying in $[1330,1530]$. Since $512$ does not lie in $[1330,1530]$, Chef is not doing his practice in a recommended way :( The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for i in range(int(input())): (a, b) = map(int, input().split()) if b >= a and b <= a + 200: print('YES') else: print('NO') ```
vfc_136471
{ "difficulty": "easy", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ADVANCE", "time_limit": "0.5 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5\n1300 1500\n1201 1402\n300 4000\n723 805\n1330 512\n", "output": "YES\nNO\nNO\nYES\nNO\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/doubling-the-value4859/1
Solve the following coding problem using the programming language python: Given an array and an integer B, traverse the array (from the beginning) and if the element in array is B, double B and continue traversal. Find the value of B after the complete traversal. Example 1: Input: N = 5, B = 2 arr[] = {1 2 3 4 8} Output: 16 Explanation: B is initially 2. We get 2 at the 1st index, hence B becomes 4. Next, we get B at the 3rd index, hence B becomes 8. Next, we get B at 4-th index, hence B becomes 16. Example 1: Input: N = 5, B = 3 arr[] = {1 2 3 4 8} Output: 6 Explanation: B is initially 3. We get 3 at the 2nd index, hence B becomes 6. Your Task: You don't need to read input or print anything. Your task is to complete the function solve () which takes the array arr[], its size N and an integer B as inputs and returns the final value of B after the complete traversal of the array. Expected Time Complexity: O(N). Expected Auxiliary Space: O(1). Constraints: 1<=N<=50 1<=B<=1000 1<=arr[i]<=10^{18} Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def solve(self,n : int, a : list, b : int): # Complete this function ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def solve(self, n: int, a: list, b: int): for i in a: if i == b: b *= 2 return b ```
vfc_136475
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/doubling-the-value4859/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 5, B = 2\r\narr[] = {1 2 3 4 8}", "output": "16", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 5, B = 3\r\narr[] = {1 2 3 4 8}", "output": "6", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/transpose-of-matrix-1587115621/1
Solve the following coding problem using the programming language python: Write a program to find the transpose of a square matrix of size N*N. Transpose of a matrix is obtained by changing rows to columns and columns to rows. Example 1: Input: N = 4 mat[][] = {{1, 1, 1, 1}, {2, 2, 2, 2} {3, 3, 3, 3} {4, 4, 4, 4}} Output: {{1, 2, 3, 4}, {1, 2, 3, 4} {1, 2, 3, 4} {1, 2, 3, 4}} Example 2: Input: N = 2 mat[][] = {{1, 2}, {-9, -2}} Output: {{1, -9}, {2, -2}} Your Task: You dont need to read input or print anything. Complete the function transpose() which takes matrix[][] and N as input parameter and finds the transpose of the input matrix. You need to do this in-place. That is you need to update the original matrix with the transpose. Expected Time Complexity: O(N * N) Expected Auxiliary Space: O(1) Constraints: 1 <= N <= 10^{3} -10^{9} <= mat[i][j] <= 10^{9} Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def transpose(self, matrix, n): # Write Your code here ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def transpose(self, mat, n): for i in range(n): for j in range(i + 1, n): (mat[i][j], mat[j][i]) = (mat[j][i], mat[i][j]) return mat ```
vfc_136476
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/transpose-of-matrix-1587115621/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N = 4\nmat[][] = {{1, 1, 1, 1},\n {2, 2, 2, 2}\n {3, 3, 3, 3}\n {4, 4, 4, 4}}", "output": "{{1, 2, 3, 4}, \n {1, 2, 3, 4} \n {1, 2, 3, 4}\n {1, 2, 3, 4}} \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "N = 2\nmat[][] = {{1, 2},\n {-9, -2}}", "output": "{{1, -9}, \n {2, -2}}\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.hackerrank.com/challenges/np-min-and-max/problem
Solve the following coding problem using the programming language python: min The tool min returns the minimum value along a given axis. import numpy my_array = numpy.array([[2, 5], [3, 7], [1, 3], [4, 0]]) print numpy.min(my_array, axis = 0) #Output : [1 0] print numpy.min(my_array, axis = 1) #Output : [2 3 1 0] print numpy.min(my_array, axis = None) #Output : 0 print numpy.min(my_array) #Output : 0 By default, the axis value is None. Therefore, it finds the minimum over all the dimensions of the input array. max The tool max returns the maximum value along a given axis. import numpy my_array = numpy.array([[2, 5], [3, 7], [1, 3], [4, 0]]) print numpy.max(my_array, axis = 0) #Output : [4 7] print numpy.max(my_array, axis = 1) #Output : [5 7 3 4] print numpy.max(my_array, axis = None) #Output : 7 print numpy.max(my_array) #Output : 7 By default, the axis value is None. Therefore, it finds the maximum over all the dimensions of the input array. Task You are given a 2-D array with dimensions $N$X$\mbox{M}$. Your task is to perform the min function over axis $\mbox{I}$ and then find the max of that. Input Format The first line of input contains the space separated values of $N$ and $\mbox{M}$. The next $N$ lines contains $\mbox{M}$ space separated integers. Output Format Compute the min along axis $\mbox{I}$ and then print the max of that result. Sample Input 4 2 2 5 3 7 1 3 4 0 Sample Output 3 Explanation The min along axis $\mbox{I}$ = $[2,3,1,0]$ The max of $[2,3,1,0]$ = $3$ The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import numpy (n, m) = list(map(int, input().split())) arr = numpy.array([list(map(int, input().split())) for i in range(n)]) print(numpy.max(numpy.min(arr, axis=1), axis=0)) ```
vfc_136477
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://www.hackerrank.com/challenges/np-min-and-max/problem", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 2\n2 5\n3 7\n1 3\n4 0\n", "output": "3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://www.codechef.com/problems/ROTATION
Solve the following coding problem using the programming language python: Read problems statements in Mandarin Chinese and Russian. You are given an array A of N integers. You are to fulfill M queries. Each query has one of the following three types: C d : Rotate the array A clockwise by d units. A d : Rotate the array A anticlockwise by d units. R d : Query for the value of the element, currently being the d-th in the array A. ------ Input ------ The first line contains two numbers - N and M respectively. The next line contains N space separated Integers, denoting the array A. Each of the following M lines contains a query in the one of the forms described above. ------ Output ------ For each query of type R output the answer on a separate line. ------ Constraints ------ $1 ≤ N ≤ 100000 $ $1 ≤ M ≤ 100000 $ $1 ≤ d ≤ N, in all the queries$ $1 ≤ elements of A ≤ 1000000$ $The array A and the queries of the type R are 1-based. $  ----- Sample Input 1 ------ 5 5 5 4 3 3 9 R 1 C 4 R 5 A 3 R 2 ----- Sample Output 1 ------ 5 3 3 ----- explanation 1 ------ The initial array : 5 4 3 3 9 The answer for R 1 : 5 The array after C 4 : 9 5 4 3 3 The answer for R 5 : 3 The array after A 3 : 4 3 3 9 5 The answer for R 2 : 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python (N, M) = map(int, input().split(' ')) arr = list(map(int, input().split(' '))) query = [] for _ in range(M): query.append(list(input().split())) pointer = 0 for each in query: if each[0] == 'C': pointer += int(each[1]) elif each[0] == 'A': pointer -= int(each[1]) else: print(arr[(pointer + int(each[1]) - 1) % N]) ```
vfc_136481
{ "difficulty": "medium", "memory_limit": "50000 bytes", "memory_limit_bytes": null, "problem_url": "https://www.codechef.com/problems/ROTATION", "time_limit": "1 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "5 5\n5 4 3 3 9\nR 1\nC 4\nR 5\nA 3\nR 2", "output": "5\n3\n3", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n5 4 3 3 9\nR 1\nC 4\nR 5\nA 6\nR 2", "output": "5\n3\n9\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n5 4 3 3 9\nR 1\nC 4\nR 5\nA 3\nR 0", "output": "5\n3\n5\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n5 4 3 3 9\nR 1\nC 1\nR 5\nA 6\nR 2", "output": "5\n5\n4\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "5 5\n5 3 3 3 9\nR 1\nC 1\nR 5\nA 6\nR 2", "output": "5\n5\n3\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/203/C
Solve the following coding problem using the programming language python: Valera's lifelong ambition was to be a photographer, so he bought a new camera. Every day he got more and more clients asking for photos, and one day Valera needed a program that would determine the maximum number of people he can serve. The camera's memory is d megabytes. Valera's camera can take photos of high and low quality. One low quality photo takes a megabytes of memory, one high quality photo take b megabytes of memory. For unknown reasons, each client asks him to make several low quality photos and several high quality photos. More formally, the i-th client asks to make xi low quality photos and yi high quality photos. Valera wants to serve as many clients per day as possible, provided that they will be pleased with his work. To please the i-th client, Valera needs to give him everything he wants, that is, to make xi low quality photos and yi high quality photos. To make one low quality photo, the camera must have at least a megabytes of free memory space. Similarly, to make one high quality photo, the camera must have at least b megabytes of free memory space. Initially the camera's memory is empty. Valera also does not delete photos from the camera so that the camera's memory gradually fills up. Calculate the maximum number of clients Valera can successfully serve and print the numbers of these clients. Input The first line contains two integers n and d (1 ≤ n ≤ 105, 1 ≤ d ≤ 109) — the number of clients and the camera memory size, correspondingly. The second line contains two integers a and b (1 ≤ a ≤ b ≤ 104) — the size of one low quality photo and of one high quality photo, correspondingly. Next n lines describe the clients. The i-th line contains two integers xi and yi (0 ≤ xi, yi ≤ 105) — the number of low quality photos and high quality photos the i-th client wants, correspondingly. All numbers on all lines are separated by single spaces. Output On the first line print the answer to the problem — the maximum number of clients that Valera can successfully serve. Print on the second line the numbers of the client in any order. All numbers must be distinct. If there are multiple answers, print any of them. The clients are numbered starting with 1 in the order in which they are defined in the input data. Examples Input 3 10 2 3 1 4 2 1 1 0 Output 2 3 2 Input 3 6 6 6 1 1 1 0 1 0 Output 1 2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python (n, d) = map(int, input().split()) (d1, d2) = map(int, input().split()) arr = [0] * n for i in range(n): (a, b) = map(int, input().split()) arr[i] = [d1 * a + d2 * b, i + 1] arr.sort() (res, idx) = (0, '') for i in arr: if d - i[0] < 0: break d -= i[0] res += 1 idx += str(i[1]) + ' ' print(res) print(idx) ```
vfc_136486
{ "difficulty": "medium", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/203/C", "time_limit": "2.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "50 50\n6 10\n10 0\n1 9\n8 2\n4 9\n0 7\n2 0\n7 5\n4 8\n10 7\n2 4\n5 6\n6 8\n3 2\n4 6\n7 8\n6 9\n7 7\n7 3\n9 5\n3 10\n7 2\n4 3\n2 0\n6 5\n5 3\n1 7\n1 7\n9 1\n10 4\n10 5\n4 2\n10 10\n0 7\n1 2\n10 1\n1 7\n3 7\n8 7\n5 2\n6 1\n3 1\n4 7\n7 10\n1 5\n10 8\n5 5\n5 1\n3 3\n1 6\n2 1\n", "output": "3\n6 23 50\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1436/C
Solve the following coding problem using the programming language python: Andrey thinks he is truly a successful developer, but in reality he didn't know about the binary search algorithm until recently. After reading some literature Andrey understood that this algorithm allows to quickly find a certain number $x$ in an array. For an array $a$ indexed from zero, and an integer $x$ the pseudocode of the algorithm is as follows: BinarySearch(a, x) left = 0 right = a.size() while left < right middle = (left + right) / 2 if a[middle] <= x then left = middle + 1 else right = middle if left > 0 and a[left - 1] == x then return true else return false Note that the elements of the array are indexed from zero, and the division is done in integers (rounding down). Andrey read that the algorithm only works if the array is sorted. However, he found this statement untrue, because there certainly exist unsorted arrays for which the algorithm find $x$! Andrey wants to write a letter to the book authors, but before doing that he must consider the permutations of size $n$ such that the algorithm finds $x$ in them. A permutation of size $n$ is an array consisting of $n$ distinct integers between $1$ and $n$ in arbitrary order. Help Andrey and find the number of permutations of size $n$ which contain $x$ at position $pos$ and for which the given implementation of the binary search algorithm finds $x$ (returns true). As the result may be extremely large, print the remainder of its division by $10^9+7$. -----Input----- The only line of input contains integers $n$, $x$ and $pos$ ($1 \le x \le n \le 1000$, $0 \le pos \le n - 1$) — the required length of the permutation, the number to search, and the required position of that number, respectively. -----Output----- Print a single number — the remainder of the division of the number of valid permutations by $10^9+7$. -----Examples----- Input 4 1 2 Output 6 Input 123 42 24 Output 824071958 -----Note----- All possible permutations in the first test case: $(2, 3, 1, 4)$, $(2, 4, 1, 3)$, $(3, 2, 1, 4)$, $(3, 4, 1, 2)$, $(4, 2, 1, 3)$, $(4, 3, 1, 2)$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import bisect import math def binsearch(arr, x): left = 0 right = len(arr) big = 0 small = 0 while left < right: middle = int((left + right) / 2) if arr[middle] < x: left = middle + 1 small += 1 elif arr[middle] == x: left = middle + 1 else: right = middle big += 1 return (big, small) pass def solve(n, x, pos): p = 10 ** 9 + 7 arr = [int(x) for x in range(n)] (big, small) = binsearch(arr, pos) k1 = math.factorial(small) * math.comb(x - 1, small) k2 = math.factorial(big) * math.comb(n - x, big) per = math.factorial(n - (small + big + 1)) return k1 % p * k2 % p * per % p % p pass t = 1 ans = [] for i in range(t): s = [int(x) for x in input().split()] n = s[0] x = s[1] pos = s[2] ans.append(solve(n, x, pos)) for a in ans: print(a) ```
vfc_136492
{ "difficulty": "medium", "memory_limit": "256 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1436/C", "time_limit": "1 second" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4 1 2\n", "output": "6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "123 42 24\n", "output": "824071958\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1 0\n", "output": "1\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 501 501\n", "output": "646597996\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1000 999 799\n", "output": "0\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "2 1 1\n", "output": "1\n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/161/B
Solve the following coding problem using the programming language python: One day Polycarpus stopped by a supermarket on his way home. It turns out that the supermarket is having a special offer for stools. The offer is as follows: if a customer's shopping cart contains at least one stool, the customer gets a 50% discount on the cheapest item in the cart (that is, it becomes two times cheaper). If there are several items with the same minimum price, the discount is available for only one of them! Polycarpus has k carts, and he wants to buy up all stools and pencils from the supermarket. Help him distribute the stools and the pencils among the shopping carts, so that the items' total price (including the discounts) is the least possible. Polycarpus must use all k carts to purchase the items, no shopping cart can remain empty. Each shopping cart can contain an arbitrary number of stools and/or pencils. Input The first input line contains two integers n and k (1 ≤ k ≤ n ≤ 103) — the number of items in the supermarket and the number of carts, correspondingly. Next n lines describe the items as "ci ti" (without the quotes), where ci (1 ≤ ci ≤ 109) is an integer denoting the price of the i-th item, ti (1 ≤ ti ≤ 2) is an integer representing the type of item i (1 for a stool and 2 for a pencil). The numbers in the lines are separated by single spaces. Output In the first line print a single real number with exactly one decimal place — the minimum total price of the items, including the discounts. In the following k lines print the descriptions of the items in the carts. In the i-th line print the description of the i-th cart as "t b1 b2 ... bt" (without the quotes), where t is the number of items in the i-th cart, and the sequence b1, b2, ..., bt (1 ≤ bj ≤ n) gives the indices of items to put in this cart in the optimal distribution. All indices of items in all carts should be pairwise different, each item must belong to exactly one cart. You can print the items in carts and the carts themselves in any order. The items are numbered from 1 to n in the order in which they are specified in the input. If there are multiple optimal distributions, you are allowed to print any of them. Examples Input 3 2 2 1 3 2 3 1 Output 5.5 2 1 2 1 3 Input 4 3 4 1 1 2 2 2 3 2 Output 8.0 1 1 2 4 2 1 3 Note In the first sample case the first cart should contain the 1st and 2nd items, and the second cart should contain the 3rd item. This way each cart has a stool and each cart has a 50% discount for the cheapest item. The total price of all items will be: 2·0.5 + (3 + 3·0.5) = 1 + 4.5 = 5.5. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python (n, k) = list(map(int, input().split())) p = [[], []] for i in range(1, n + 1): (c, t) = map(int, input().split()) p[t > 1].append((c, i)) if k > len(p[0]): l = k - len(p[0]) - 1 print(sum((c for (c, i) in p[0])) / 2 + sum((c for (c, i) in p[1]))) print('\n'.join(('1 ' + str(i) for (c, i) in p[0]))) print('\n'.join(('1 ' + str(i) for (c, i) in p[1][:l]))) print(len(p[1]) - l, ' '.join((str(i) for (c, i) in p[1][l:]))) else: p[1].sort() p[0].sort(reverse=True) print(sum((c for (c, i) in p[0][:k - 1])) / 2 + sum((c for (c, i) in p[0][k - 1:])) + sum((c for (c, i) in p[1])) - min((c for (c, i) in p[1] + p[0][k - 1:])) / 2) print('\n'.join(('1 ' + str(i) for (c, i) in p[0][:k - 1]))) print(n - k + 1, ' '.join((str(i) for (c, i) in p[0][k - 1:])), ' '.join((str(i) for (c, i) in p[1]))) ```
vfc_136496
{ "difficulty": "medium_hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/161/B", "time_limit": "3.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "11 11\n6 2\n6 2\n1 2\n2 2\n3 1\n6 2\n1 1\n1 1\n3 1\n3 1\n6 2\n", "output": "32.5\n1 10\n1 9\n1 5\n1 8\n1 7\n1 11\n1 6\n1 2\n1 1\n1 4\n1 3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "21 7\n14 1\n882797755 2\n17 1\n906492329 2\n209923513 2\n802927469 2\n949195463 2\n677323647 2\n2129083 2\n2 1\n13 1\n539523264 2\n7 1\n8 1\n12 1\n363470241 2\n9838294 2\n18716193 2\n30 1\n17 1\n24 1\n", "output": "5362337336.5\n1 19 \n1 21 \n1 3 \n1 20 \n1 1 \n1 11 \n15 15 14 13 10 7 4 2 6 8 12 16 5 18 17 9 \n", "type": "stdin_stdout" }, { "fn_name": null, "input": "1 1\n1 1\n", "output": "0.5\n1 1 \n", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1248/B
Solve the following coding problem using the programming language python: Gardener Alexey teaches competitive programming to high school students. To congratulate Alexey on the Teacher's Day, the students have gifted him a collection of wooden sticks, where every stick has an integer length. Now Alexey wants to grow a tree from them. The tree looks like a polyline on the plane, consisting of all sticks. The polyline starts at the point $(0, 0)$. While constructing the polyline, Alexey will attach sticks to it one by one in arbitrary order. Each stick must be either vertical or horizontal (that is, parallel to $OX$ or $OY$ axis). It is not allowed for two consecutive sticks to be aligned simultaneously horizontally or simultaneously vertically. See the images below for clarification. Alexey wants to make a polyline in such a way that its end is as far as possible from $(0, 0)$. Please help him to grow the tree this way. Note that the polyline defining the form of the tree may have self-intersections and self-touches, but it can be proved that the optimal answer does not contain any self-intersections or self-touches. -----Input----- The first line contains an integer $n$ ($1 \le n \le 100\,000$) — the number of sticks Alexey got as a present. The second line contains $n$ integers $a_1, \ldots, a_n$ ($1 \le a_i \le 10\,000$) — the lengths of the sticks. -----Output----- Print one integer — the square of the largest possible distance from $(0, 0)$ to the tree end. -----Examples----- Input 3 1 2 3 Output 26 Input 4 1 1 2 2 Output 20 -----Note----- The following pictures show optimal trees for example tests. The squared distance in the first example equals $5 \cdot 5 + 1 \cdot 1 = 26$, and in the second example $4 \cdot 4 + 2 \cdot 2 = 20$. [Image] [Image] The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def f(l): l.sort() h = len(l) // 2 y = sum(l[:h]) x = sum(l[h:]) return x * x + y * y _ = input() l = list(map(int, input().split())) print(f(l)) ```
vfc_136504
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1248/B", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "3\n1 2 3\n", "output": "26", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n1 1 2 2\n", "output": "20", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://practice.geeksforgeeks.org/problems/find-pairs-with-given-relation1540/1
Solve the following coding problem using the programming language python: Given an array of distinct integers, write a program to find if there exist two pairs (a, b) and (c, d) such that ab = cd, where a, b, c and d are distinct elements. If such pairs exists then print 1 else -1. Example 1: Input: N=7 arr[] = {3, 4, 7, 1, 2, 9, 8} Output: 1 Explanation: Product of 4 and 2 is 8 and also, the product of 1 and 8 is 8. Example 2: Input: N=6 arr[] = {1, 6, 3, 9, 2, 10} Output: 1 Your Task: Since, this is a function problem. You don't need to take any input, as it is already accomplished by the driver code. You just need to complete the function findPairs() that takes array arr and n as parameters and return 1 if any such pair is found otherwise return -1. Expected Time Complexity: O(N^{2}). Expected Auxiliary Space: O(N^{2}). Constraints: 1 ≤ N ≤ 10^{3} Write your solution by modifying this code: ```python #User function Template for python3 class Solution: def findPairs(self,a,n): #code here. ``` The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python class Solution: def findPairs(self, arr, n): H = dict() for i in range(n): for j in range(i + 1, n): prod = arr[i] * arr[j] if prod not in H.keys(): H[prod] = [i, j] else: return 1 return -1 ```
vfc_136508
{ "difficulty": "easy", "memory_limit": null, "memory_limit_bytes": null, "problem_url": "https://practice.geeksforgeeks.org/problems/find-pairs-with-given-relation1540/1", "time_limit": "None" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "N=7\narr[] = {3, 4, 7, 1, 2, 9, 8}", "output": "1", "type": "stdin_stdout" } ] }
taco
verifiable_code
https://codeforces.com/problemset/problem/1399/E1
Solve the following coding problem using the programming language python: Easy and hard versions are actually different problems, so we advise you to read both statements carefully. You are given a weighted rooted tree, vertex 1 is the root of this tree. A tree is a connected graph without cycles. A rooted tree has a special vertex called the root. A parent of a vertex v is the last different from v vertex on the path from the root to the vertex v. Children of vertex v are all vertices for which v is the parent. A vertex is a leaf if it has no children. The weighted tree is such a tree that each edge of this tree has some weight. The weight of the path is the sum of edges weights on this path. The weight of the path from the vertex to itself is 0. You can make a sequence of zero or more moves. On each move, you select an edge and divide its weight by 2 rounding down. More formally, during one move, you choose some edge i and divide its weight by 2 rounding down (w_i := \left⌊(w_i)/(2)\right⌋). Your task is to find the minimum number of moves required to make the sum of weights of paths from the root to each leaf at most S. In other words, if w(i, j) is the weight of the path from the vertex i to the vertex j, then you have to make ∑_{v ∈ leaves} w(root, v) ≤ S, where leaves is the list of all leaves. You have to answer t independent test cases. Input The first line of the input contains one integer t (1 ≤ t ≤ 2 ⋅ 10^4) — the number of test cases. Then t test cases follow. The first line of the test case contains two integers n and S (2 ≤ n ≤ 10^5; 1 ≤ S ≤ 10^{16}) — the number of vertices in the tree and the maximum possible sum of weights you have to obtain. The next n-1 lines describe edges of the tree. The edge i is described as three integers v_i, u_i and w_i (1 ≤ v_i, u_i ≤ n; 1 ≤ w_i ≤ 10^6), where v_i and u_i are vertices the edge i connects and w_i is the weight of this edge. It is guaranteed that the sum of n does not exceed 10^5 (∑ n ≤ 10^5). Output For each test case, print the answer: the minimum number of moves required to make the sum of weights of paths from the root to each leaf at most S. Example Input 3 3 20 2 1 8 3 1 7 5 50 1 3 100 1 5 10 2 3 123 5 4 55 2 100 1 2 409 Output 0 8 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys import math import bisect from sys import stdin, stdout from math import gcd, floor, sqrt, log2, ceil from collections import defaultdict from bisect import bisect_left as bl, bisect_right as br from collections import Counter from collections import deque from heapq import heappush, heappop, heapify def addEdge(a, b): graph[a].append(b) graph[b].append(a) def Bfs(src): q = deque([]) q.append(src) visited[src] = True dist[src] = 0 while q: node = q.popleft() flag = True for neighbour in graph[node]: if not visited[neighbour]: flag = False q.append(neighbour) visited[neighbour] = True dist[neighbour] = dist[node] + 1 parent[neighbour] = node level[dist[neighbour]].append(neighbour) if flag: leaf.append(node) ip = lambda : int(stdin.readline()) inp = lambda : map(int, stdin.readline().split()) ips = lambda : stdin.readline().rstrip() t = ip() for _ in range(t): (n, s) = inp() graph = [[] for i in range(n)] visited = [False] * n leaf = [] dist = [0] * n parent = [-1] * n level = defaultdict(list) val = {} for i in range(n - 1): (a, b, v) = inp() (a, b) = (a - 1, b - 1) if a > b: (a, b) = (b, a) val[a, b] = v addEdge(a, b) Bfs(0) ch = sorted(list(level), reverse=True) ct = [0] * n for i in leaf: ct[i] = 1 sums = [] checksum = 0 for i in ch: for j in level[i]: par = parent[j] ct[par] += ct[j] (a, b) = (j, par) if a > b: (a, b) = (b, a) weight = val[a, b] checksum += weight * ct[j] while weight: impact = (weight - weight // 2) * ct[j] weight = weight // 2 sums.append(impact) sums.sort(reverse=True) idx = 0 ans = 0 while checksum > s: checksum -= sums[idx] idx += 1 ans += 1 print(ans) ```
vfc_136509
{ "difficulty": "hard", "memory_limit": "256.0 megabytes", "memory_limit_bytes": null, "problem_url": "https://codeforces.com/problemset/problem/1399/E1", "time_limit": "3.0 seconds" }
{ "language": "python", "test_cases": [ { "fn_name": null, "input": "4\n4 18\n2 1 9 2\n3 2 4 1\n4 1 1 2\n3 20\n2 1 8 1\n3 1 7 2\n5 50\n1 3 100 1\n1 5 10 2\n2 3 123 2\n5 4 55 1\n2 100\n1 2 409 2\n", "output": "0\n0\n11\n6\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4 22\n2 1 9 2\n3 2 4 1\n4 1 1 2\n3 20\n2 1 8 1\n3 1 7 2\n5 50\n1 3 100 1\n1 5 10 2\n2 3 123 2\n5 4 55 1\n2 100\n1 2 409 2\n", "output": "0\n0\n0\n47\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 20\n2 1 8\n3 2 7\n5 50\n1 3 100\n1 5 10\n2 3 123\n5 4 55\n2 100\n1 2 409\n", "output": "0\n8\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 20\n2 1 8\n3 2 7\n5 50\n1 3 100\n1 5 10\n2 2 123\n5 4 55\n2 100\n1 2 409\n", "output": "0\n4\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "3\n3 20\n2 1 8\n3 2 7\n5 89\n1 3 100\n1 5 10\n2 2 123\n5 4 55\n2 101\n1 2 409\n", "output": "0\n2\n3\n", "type": "stdin_stdout" }, { "fn_name": null, "input": "4\n4 22\n2 1 9 2\n3 2 4 1\n4 1 1 2\n3 20\n2 1 8 1\n3 2 7 2\n5 50\n1 3 100 1\n1 5 10 2\n2 3 123 2\n5 4 55 1\n2 100\n1 2 409 2\n", "output": "0\n0\n0\n83\n", "type": "stdin_stdout" } ] }