source
stringclasses
1 value
task_type
stringclasses
1 value
in_source_id
stringlengths
1
4
problem
stringlengths
488
6.07k
gold_standard_solution
stringlengths
19
30.1k
verification_info
dict
metadata
dict
problem_id
stringlengths
5
9
contaminated_aime_2024
bool
1 class
contaminated_aime_2025
bool
1 class
contaminated_math_500
bool
1 class
contaminated_gpqa
bool
1 class
contaminated_lcb
bool
2 classes
apps
verifiable_code
786
Solve the following coding problem using the programming language python: The chef was not happy with the binary number system, so he designed a new machine which is having 6 different states, i.e. in binary there is a total of 2 states as 0 and 1. Now, the chef is confused about how to correlate this machine to get an interaction with Integer numbers, when N(Integer number) is provided to the system, what will be the Nth number that system will return(in Integer form), help the chef to design this system. -----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, $N$. -----Output:----- For each test case, output in a single line answer given by the system. -----Constraints----- - $1 \leq T \leq 10^5$ - $1 \leq N \leq 10^5$ -----Sample Input:----- 2 3 5 -----Sample Output:----- 7 37 -----EXPLANATION:----- Initial numbers for system = [1, 6, 7, 36, 37, 42, 43, 216, ….. For 1) 3rd Number for the system will be 7. For 2) 5th Number for the system will be 37. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from sys import stdin, stdout #from math import gcd as g #a,b = map(int, stdin.readline().split()) #l1 = list(map(int, stdin.readline().split())) l = [1,6,7] c = 1 for x in range(3,100001): if x%2==1: a = l[c]*6 l.append(a) else: l.append(a+1) c+=1 n = int(stdin.readline()) for _ in range(n): s = int(stdin.readline()) print(l[s-1]) ```
{ "language": "python", "test_cases": [ { "input": "2\n3\n5\n", "output": "7\n37\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PBK22020/problems/ITGUY23" }
vfc_1986
false
false
false
false
false
apps
verifiable_code
787
Solve the following coding problem using the programming language python: Limak is a little polar bear. He is playing a video game and he needs your help. There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively. The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells). The only possible command is choosing a soldier and telling him to move to the right as far as possible. Choosing a soldier takes 1 second, and a soldier moves with the speed of a cell per second. The soldier stops immediately if he is in the last cell of the row or the next cell is already occupied. Limak isn't allowed to choose a soldier that can't move at all (the chosen soldier must move at least one cell to the right). Limak enjoys this game very much and wants to play as long as possible. In particular, he doesn't start a new command while the previously chosen soldier moves. Can you tell him, how many seconds he can play at most? -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. The only line of each test case contains a string S describing the row with N cells. Each character is either '0' or '1', denoting an empty cell or a cell with a soldier respectively. -----Output----- For each test case, output a single line containing one integer — the maximum possible number of seconds Limak will play the game. -----Constraints----- - 1 ≤ T ≤ 5 - 1 ≤ N ≤ 105 (N denotes the length of the string S) -----Subtasks----- - Subtask #1 (25 points): 1 ≤ N ≤ 10 - Subtask #2 (25 points): 1 ≤ N ≤ 2000 - Subtask #3 (50 points): Original constraints. -----Example----- Input: 4 10100 1100001 000000000111 001110100011010 Output: 8 10 0 48 -----Explanation----- Test case 1. The initial string is 10100. There are N = 5 cells. There is one soldier in the first cell, and one soldier in the third cell. The following scenario maximizes the total time: - Limak chooses the soldier in the first cell. This soldier can move only one cell to the right. It takes 1 second to choose a soldier and 1 second for a soldier to move to the next cell (2 seconds in total). The string is 01100 now. - Limak has only one choice. He must choose the soldier in the third cell because the other soldier can't move at all (the soldier in the second cell can't move to the right because the next cell is already occupied). Choosing a soldier takes 1 second. The chosen soldier moves from the third cell to the fifth cell, which takes 2 seconds. This operation takes 1 + 2 = 3 seconds in total. The string is 01001 now. - Limak has only one choice again. Since the soldier in the last row can't move further to the right, the soldier in the second cell must be chosen. He will move 2 cells to the right. This operation takes 1 + 2 = 3 seconds in total. The string become 00011 and the game is over. The total time is 2 + 3 + 3 = 8. Test case 2. The initial string is 1100001. There is only one possible scenario: - 1100001 is changed to 1000011 in 5 seconds (1 second to choose a soldier and 4 seconds for the soldier to move 4 cells to the right). - 1000011 is changed to 0000111 in 5 seconds. The total time is 5 + 5 = 10 seconds. Test case 3. The game is over immediately because all soldiers occupy rightmost cells already. 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 for _ in range(int(input())): l=list(map(int,input().strip())) for j in range(len(l)-1,-1,-1): if l[j]==1: l.pop() else: break if l.count(1): time,prev,z,c=0,0,0,0 for j in range(len(l)-1,-1,-1): if l[j]==0: z+=1 continue if prev!=z: prev=z c+=1 time+=c+z print(time) else: print(0) ```
{ "language": "python", "test_cases": [ { "input": "4\n10100\n1100001\n000000000111\n001110100011010\n", "output": "8\n10\n0\n48\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/ROWSOLD" }
vfc_1990
false
false
false
false
false
apps
verifiable_code
788
Solve the following coding problem using the programming language python: If Give an integer N . Write a program to obtain the sum of the first and last digits of this number. -----Input----- The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains an integer N. -----Output----- For each test case, display the sum of first and last digits of N in a new line. -----Constraints----- - 1 ≤ T ≤ 1000 - 1 ≤ N ≤ 1000000 -----Example----- Input 3 1234 124894 242323 Output 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 = int(input()) for i in range(n): s = input() l = len(s) n1 = int(s[0]) n2 = int(s[l-1]) print(n1+n2) ```
{ "language": "python", "test_cases": [ { "input": "3\n1234\n124894\n242323\n", "output": "5\n5\n5\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/FLOW004" }
vfc_1994
false
false
false
false
false
apps
verifiable_code
789
Solve the following coding problem using the programming language python: Rani is teaching Raju maths via a game called N-Cube, which involves three sections involving N. Rani gives Raju a number N, and Raju makes a list of Nth powers of integers in increasing order (1^N, 2^N, 3^N.. so on). This teaches him exponentiation. Then Raju performs the following subtraction game N times : Take all pairs of consecutive numbers in the list and take their difference. These differences then form the new list for the next iteration of the game. Eg, if N was 6, the list proceeds as [1, 64, 729, 4096 ... ] to [63, 685, 3367 ...], and so on 5 more times. After the subtraction game, Raju has to correctly tell Rani the Nth element of the list. This number is the value of the game. After practice Raju became an expert in the game. To challenge him more, Rani will give two numbers M (where M is a prime) and R instead of just a single number N, and the game must start from M^(R - 1) instead of N. Since the value of the game can now become large, Raju just have to tell the largest integer K such that M^K divides this number. Since even K can be large, output K modulo 1000000007 (109+7). -----Input----- First line will contain T, number of testcases. Then the testcases follow Each testcase contains of a single line of input, two integers M R -----Output----- For each testcase, output in a single line answer given by Raju to Rani modulo 1000000007. -----Constraints----- 1<=T<=1000 2<=M<=109 30 points : 1<=R<=10000 70 points : 1<=R<=109 M is a prime number -----Example----- Input: 1 2 2 Output: 1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python tc=int(input()) for case in range(tc): m,r=list(map(int,input().split())) n=m**(r-1) a=[i**n for i in range(1,2*n+1)] tmp=2*n-1 for i in range(n): for j in range(tmp-i): a[j]=a[j+1]-a[j] print((a[n-1]/m)%1000000007) ```
{ "language": "python", "test_cases": [ { "input": "1\n2 2\n", "output": "1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CDST2016/problems/CDS2" }
vfc_1998
false
false
false
false
false
apps
verifiable_code
790
Solve the following coding problem using the programming language python: Bob has n heap(s) of gravel (initially there are exactly c piece(s) in each). He wants to do m operation(s) with that heaps, each maybe: - adding pieces of gravel onto the heaps from u to v, exactly k pieces for each, - or querying "how many pieces of gravel are there in the heap p now?". -----Request----- Help Bob do operations of the second type. -----Input----- - The first line contains the integers n,m,c, respectively. - m following lines, each forms: - S u v k to describe an operation of the first type. - Q p to describe an operation of the second type. (Each integer on a same line, or between the characters S, Q and the integers is separated by at least one space character) -----Output----- For each operation of the second type, output (on a single line) an integer answering to the respective query (follows the respective Input order). -----Example-----Input: 7 5 0 Q 7 S 1 7 1 Q 3 S 1 3 1 Q 3 Output: 0 1 2 -----Limitations----- - 0<n≤106 - 0<m≤250 000 - 0<u≤v≤n - 0≤c,k≤109 - 0<p≤n The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python N,M,C = list(map(int, input().split())) tree = [0] * (N+1) def add(u,k): while u < len(tree): tree[u] += k u += u&-u def query(k): ans = 0 while k: ans += tree[k] k -= k&-k return ans def solve(): for _ in range(M): op = input().split() if op[0] == 'Q': print(query(int(op[1])) + C) else: u,v,k = int(op[1]), int(op[2]), int(op[3]) add(u, k) add(v+1, -k) def __starting_point(): solve() __starting_point() ```
{ "language": "python", "test_cases": [ { "input": "7 5 0\nQ 7\nS 1 7 1\nQ 3\nS 1 3 1\nQ 3\n", "output": "0\n1\n2\nLimitations\n0<n≤10 6\n0<m≤250 000\n0<u≤v≤n\n0≤c,k≤10 9\n0<p≤n\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/SPREAD" }
vfc_2002
false
false
false
false
false
apps
verifiable_code
791
Solve the following coding problem using the programming language python: Chef's dog Snuffles has so many things to play with! This time around, Snuffles has an array A containing N integers: A1, A2, ..., AN. Bad news: Snuffles only loves to play with an array in which all the elements are equal. Good news: We have a mover of size D. ! A mover of size D is a tool which helps to change arrays. Chef can pick two existing elements Ai and Aj from the array, such that i + D = j and subtract 1 from one of these elements (the element should have its value at least 1), and add 1 to the other element. In effect, a single operation of the mover, moves a value of 1 from one of the elements to the other. Chef wants to find the minimum number of times she needs to use the mover of size D to make all the elements of the array A equal. Help her find this out. -----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 two integers N and D, denoting the number of elements in the array and the size of the mover. - The second line of each testcase contains N space-separated integers: A1, A2, ..., AN, denoting the initial elements of the array. -----Output----- - For each test case, output a single line containing the minimum number of uses or -1 if it is impossible to do what Snuffles wants. -----Constraints----- - 1 ≤ T ≤ 10 - 2 ≤ N ≤ 105 - 1 ≤ D < N - 1 ≤ Ai ≤ 109 -----Subtasks----- - Subtask 1 (30 points) : N ≤ 103 - Subtask 2 (70 points) : Original constraints -----Example----- Input: 3 5 2 1 4 5 2 3 3 1 1 4 1 4 2 3 4 3 5 Output: 3 2 -1 -----Explanation----- Testcase 1: Here is a possible sequence of usages of the mover: - Move 1 from A3 to A1 - Move 1 from A3 to A1 - Move 1 from A2 to A4 At the end, the array becomes (3, 3, 3, 3, 3), which Snuffles likes. And you cannot achieve this in fewer moves. Hence the answer is 3. Testcase 2: Here is a possible sequence of usages of the mover: - Move 1 from A2 to A1 - Move 1 from A2 to A3 At the end, the array becomes (2, 2, 2), which Snuffles likes. And you cannot achieve this in fewer moves. Hence the answer is 2. Testcase 3: It is impossible to make all the elements equal. Hence 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 tc=int(input()) for case in range(tc): n,d=list(map(int,input().split())) a=list(map(int,input().split())) sm=sum(a) f=True if sm%n==0: avg=sm/n for i in range(d): tmp_sm=0 tmp_n=0 for j in range(i,n,d): tmp_sm=tmp_sm+a[j] tmp_n+=1 if tmp_sm%tmp_n==0: if avg!=tmp_sm/tmp_n: f=False break else: f=False break else: f=False if f: ans=0 cur=0 for i in range(d): for j in range(i,n,d): cur=cur+avg-a[j] ans=ans+abs(cur) print(ans) else: print(-1) ```
{ "language": "python", "test_cases": [ { "input": "3\n5 2\n1 4 5 2 3\n3 1\n1 4 1\n4 2\n3 4 3 5\n", "output": "3\n2\n-1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/AUG17/problems/CHEFMOVR" }
vfc_2006
false
false
false
false
false
apps
verifiable_code
792
Solve the following coding problem using the programming language python: Dustin, is the head of an Intelligence agency. He wants to send a secret message S$S$ to his colleague.The message is a single word consisting of only lowercase english letters but he decides to encrypt the message for security reasons. He makes a string M$M$ of length N$N$, such that after deleting a substring of non-zero length from M$M$, the remaining string is S$S$. Calculate the number of all such possible strings he can form. -----Input:----- - First line will contain T$T$, number of testcases. Then the testcases follow. - For each testcase the there is a single line which contains an integer, N$N$ and then a string S$S$. -----Output:----- For each testcase, output the number of possible strings modulo 109+7$10^9+7$. -----Constraints----- - 1≤T≤50$1 \leq T \leq 50$ - 1≤N≤1018$1 \leq N \leq 10^{18}$ - 1≤|S|≤105$1 \leq |S| \leq 10^5$ - S$S$ can contain only lowercase English letters. -----Sample Input:----- 2 3 a 3 ab -----Sample Output:----- 1326 76 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here t = int(input()) for _ in range(t): n,s = input().split() N = int(n) r = N - len(s) count = 0 if N>len(s): count = pow(26, r-1,(10**9+7)) count*= (26+25*len(s)) count = count%(10**9 + 7) print(count) ```
{ "language": "python", "test_cases": [ { "input": "2\n3 a\n3 ab\n", "output": "1326\n76\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/ICL1904" }
vfc_2010
false
false
false
false
false
apps
verifiable_code
793
Solve the following coding problem using the programming language python: As lockdown is going on so no is allowed to go outside , so Chef has come with an innovative idea for food home delivery using drone. But there is an issue with it , the drone can move forward or backward a fix number of steps $x$ . All the houses and chef restaurant are all in a straight line . Homes which need delivery are located at $H[i]$ and chef is located at $y$ coordinate . If Drone is at a location $R$, then it can move to $R-x$ or $R+x$ . Help chef find maximum value of $x$ to complete all the deliveries as he is busy managing the orders. -----Input:----- - First line will contain $n$ and $R$, number of houses that need delivery and the correct coordinate of chef (Drone). - Second line contains $n$ integers , the coordinate of all homes that need delivery. -----Output:----- - The maximum value of $x$ , so that drone delivers to all houses. -----Constraints----- - $1 \leq n \leq 1000$ - $1 \leq R \leq 10^9$ - $1 \leq hi \leq 10^9$ - $1 \leq x \leq 10^9$ -----Sample Input:----- 3 1 3 5 11 -----Sample Output:----- 2 -----EXPLANATION:----- Chef's drone is at 1 initially and he needs to visit 3,5,11 , so optimal solution will be (maximum value of x ) equal to 2. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here import math try: n,d=map( int,input().split() ) a=list(map(int,input().split())) a.sort() z=abs(a[0]-d) for j in range(n): x=abs(a[j]-d) z=math.gcd(x,z) print(z) except: pass ```
{ "language": "python", "test_cases": [ { "input": "3 1\n3 5 11\n", "output": "2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/LDT42020/problems/DRONEDEL" }
vfc_2014
false
false
false
false
false
apps
verifiable_code
794
Solve the following coding problem using the programming language python: One day, Tanya was studying graph theory. She is very inquisitive, so the following problem soon came to her mind. Find the number of undirected unweighted connected simple graphs with $N$ vertices (numbered $1$ through $N$) and $M$ edges, such that for each $i$ ($2 \le i \le N$), the shortest path from vertex $1$ to vertex $i$ is unique and its length is equal to $A_i$. In other words, for each $i$ ($2 \le i \le N$), there should be exactly one path with length $A_i$ between vertices $1$ and $i$, and there should be no paths with smaller length between these vertices. Two graphs with $N$ vertices are distinct if we can find two vertices $u$ and $v$ such that there is an edge between these vertices in one graph, but not in the other graph. Since the answer could be very large, compute it modulo $1,000,000,007$ ($10^9 + 7$). -----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$. - The second line contains $N - 1$ space-separated integers $A_2, A_3, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer ― the number of graphs modulo $10^9 + 7$. -----Constraints----- - $1 \le T \le 1,000$ - $2 \le N \le 10^5$ - $N-1 \le M \le \mathrm{min}\left(2\cdot 10^5, \frac{N(N-1)}{2}\right)$ - $1 \le A_i \le N-1$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $2 \cdot 10^5$ - the sum of $M$ over all test cases does not exceed $2 \cdot 10^5$ -----Subtasks----- Subtask #1 (50 points): $M = N-1$ Subtask #2 (50 points): original constraints -----Example Input----- 3 4 3 1 2 1 4 6 1 2 1 3 2 2 2 -----Example Output----- 2 0 0 -----Explanation----- Example case 1: The two graphs which satisfy all conditions are: The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def multiple_input(): return map(int, input().split()) def list_input(): return list(map(int, input().split())) mod = int(1e9) + 7 for _ in range(int(input())): n, m = multiple_input() a = list_input() a.sort() max_level = a[-1] + 1 levels = [0] * max_level levels[0] = 1 for i in a: levels[i] += 1 ans = 1 for i in range(1, max_level): ans = (ans * (pow(levels[i - 1], levels[i], mod))) % mod print(ans) ```
{ "language": "python", "test_cases": [ { "input": "3\n4 3\n1 2 1\n4 6\n1 2 1\n3 2\n2 2\n", "output": "2\n0\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CNTGRP" }
vfc_2018
false
false
false
false
false
apps
verifiable_code
795
Solve the following coding problem using the programming language python: In a cricket game, an over is a set of six valid deliveries of balls performed by one player ― the bowler for this over. Consider a cricket game with a series of $N$ overs (numbered $1$ through $N$) played by $K$ players (numbered $1$ through $K$). Each player may be the bowler for at most $L$ overs in total, but the same player may not be the bowler for any two consecutive overs. Assign exactly one bowler to each over in such a way that these rules are satisfied or determine that no such assignment exists. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains three space-separated integers $N$, $K$ and $L$. -----Output----- For each test case: - If there is no valid assignment of bowlers to overs, print a single line containing the integer $-1$. - Otherwise, print a single line containing $N$ space-separated integers. For each valid $i$, the $i$-th of these integers should be the number of the player assigned as the bowler for the $i$-th over. -----Constraints----- - $1 \le T \le 30$ - $1 \le N, K, L \le 10,000$ -----Example Input----- 2 4 3 2 5 4 1 -----Example Output----- 1 2 3 2 -1 -----Explanation----- Example case 1: The following is a valid assignment: - Bowler 1 bowls the $1$-st over. - Bowler 2 bowls the $2$-nd and $4$-th overs. - Bowler 3 bowls the $3$-rd over. It is valid since no bowler bowls more than $2$ overs and each two consecutive overs have different bowlers. Example case 2: There is no valid assignment in which each of $4$ players bowls at most $1$ over out of $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): n,k,l=map(int,input().split()) if k*l<n: print(-1) elif (k==1 and n>1): print(-1) else: for j in range(n): print((j%k)+1,end=' ') print() ```
{ "language": "python", "test_cases": [ { "input": "2\n4 3 2\n5 4 1\n", "output": "1 2 3 2\n-1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/BOWLERS" }
vfc_2022
false
false
false
false
false
apps
verifiable_code
796
Solve the following coding problem using the programming language python: There's an array A consisting of N non-zero integers A1..N. A subarray of A is called alternating if any two adjacent elements in it have different signs (i.e. one of them should be negative and the other should be positive). For each x from 1 to N, compute the length of the longest alternating subarray that starts at x - that is, a subarray Ax..y for the maximum possible y ≥ x. The length of such a subarray is y-x+1. -----Input----- - The first line of the input contains an integer T - the number of test cases. - The first line of each test case contains N. - The following line contains N space-separated integers A1..N. -----Output----- For each test case, output one line with N space-separated integers - the lengths of the longest alternating subarray starting at x, for each x from 1 to N. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N ≤ 105 - -109 ≤ Ai ≤ 109 -----Example----- Input: 3 4 1 2 3 4 4 1 -5 1 -5 6 -5 -1 -1 2 -2 -3 Output: 1 1 1 1 4 3 2 1 1 1 3 2 1 1 -----Explanation----- Example case 1. No two elements have different signs, so any alternating subarray may only consist of a single number. Example case 2. Every subarray is alternating. Example case 3. The only alternating subarray of length 3 is A3..5. 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()) for i in range(test): n=int(input()) a=list(map(int,input().split())) b=[0]*(n+2) b[n-1]=1 for i in range(n-2,-1,-1): if(a[i]*a[i+1]<0): b[i]=b[i+1]+1 else: b[i]=1 for i in range(n): print(b[i], end=' ') print() ```
{ "language": "python", "test_cases": [ { "input": "3\n4\n1 2 3 4\n4\n1 -5 1 -5\n6\n-5 -1 -1 2 -2 -3\n", "output": "1 1 1 1\n4 3 2 1\n1 1 3 2 1 1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COOK68/problems/ALTARAY" }
vfc_2026
false
false
false
false
false
apps
verifiable_code
797
Solve the following coding problem using the programming language python: Chef is a very experienced and well-known cook. He has participated in many cooking competitions in the past — so many that he does not even remember them all. One of these competitions lasted for a certain number of days. The first day of the competition was day $S$ of the week (i.e. Monday, Tuesday etc.) and the last day was day $E$ of the week. Chef remembers that the duration of the competition (the number of days between the first and last day, inclusive) was between $L$ days and $R$ days inclusive. Is it possible to uniquely determine the exact duration of the competition? If so, what is this duration? -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains two space-separated strings $S$ and $E$, followed by a space and two space-separated integers $L$ and $R$. -----Output----- For each test case, print a single line containing: - the string "impossible" if there is no duration consistent with all given information - the string "many" if there is more than one possible duration - one integer — the duration of the competition, if its duration is unique -----Constraints----- - $1 \le T \le 10,000$ - $1 \le L \le R \le 100$ - $S$ is one of the strings "saturday", "sunday", "monday", "tuesday", "wednesday", "thursday" or "friday" - $E$ is one of the strings "saturday", "sunday", "monday", "tuesday", "wednesday", "thursday" or "friday" -----Subtasks----- Subtask #1 (100 points): original constraints -----Example Input----- 3 saturday sunday 2 4 monday wednesday 1 20 saturday sunday 3 5 -----Example Output----- 2 many impossible The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here d=["saturday","sunday","monday","tuesday","wednesday","thursday","friday"] t=int(input()) for i in range(t): s,e,l,r=map(str,input().split()) l,r=int(l),int(r) v=(d.index(e)-d.index(s)+8)%7 c=r+1 for i in range(l,r+1): if i%7==v: c=i break if c>r: print('impossible') elif c+7<=r: print('many') else: print(c) ```
{ "language": "python", "test_cases": [ { "input": "3\nsaturday sunday 2 4\nmonday wednesday 1 20\nsaturday sunday 3 5\n", "output": "2\nmany\nimpossible\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/EVENT" }
vfc_2030
false
false
false
false
false
apps
verifiable_code
798
Solve the following coding problem using the programming language python: Zonal Computing Olympiad 2013, 10 Nov 2012 Little Red Riding Hood is carrying a basket with berries through the forest to her grandmother's house. The forest is arranged in the form of a square N × N grid of cells. The top left corner cell, where Little Red Riding Hood starts her journey, is numbered (1,1) and the bottom right corner cell, where her grandmother lives, is numbered (N,N). In each step, she can move either one position right or one position down. The forest is full of dangerous wolves and she is looking for a safe path to reach her destination. Little Red Riding Hood's fairy godmother has placed some special anti-wolf magical charms in some of the cells in the grid. Each charm has a strength. If the charm in cell (i,j) has strength k then its zone of influence is all the cells within k steps of (i,j); that is, all cells (i',j') such that |i - i'| + |j - j'| ≤ k. A cell within the zone of influence of a charm is safe from wolves. A safe path from (1,1) to (N,N) is one in which every cell along the path is safe. Little Red Riding Hood is carrying a basket with berries. In each cell, she drops some berries while pushing her way through the thick forest. However, sometimes she is also able to pick up fresh berries. Each cell is labelled with an integer that indicates the net change in the number of berries in her basket on passing through the cell; that is, the number of berries she picks up in that cell minus the number of berries she drops. You can assume that there are enough berries in her basket to start with so that the basket never becomes empty. Little Red Riding Hood knows the positions and strengths of all the magic charms and is looking for a safe path along which the number of berries she has in the basket when she reaches her grandmother's house is maximized. As an example consider the following grid: 3 3 2 4 3 2 1 -1 -2 2 -1 2 4 3 -3 -2 2 3 2 1 3 -1 2 -1 2 Suppose there are 3 magic charms, at position (1,2) with strength 2, at position (4,5) with strength 2 and one at position (4,2) with strength 1. The positions within the zone of influence of these three charms are indicated in the three grids below using X's. X X X X . . . . . . . . . . . X X X . . . . . . X . . . . . . X . . . . . . X X . X . . . . . . . . . . X X X X X X . . . . . . . . . . X X . X . . . Putting these together, the cells that are under the zone of influence of at least one charm are marked with X below. X X X X . X X X . X . X . X X X X X X X . X . X X Here are two examples of safe paths in this grid, marked using Y's. Y Y X X . Y X X X . X Y X . X Y Y X . X . Y . X X . Y . X X X Y Y Y Y X Y Y Y X . X . X Y . X . Y Y Along the first path, she accumulates 19 berries while on the second path she collects 16 berries. You can verify that among all safe paths, the maximum number of berries she can collect is 19. Your task is to help Little Red Riding Hood find out if there is at least one safe path and, if so, compute the maximum number of berries she can collect among all safe paths (which may be a negative number, in which case it is the minimum number of berries she will lose among all safe paths). -----Input format----- Line 1: Two space separated integers N and M, giving the dimension of the grid and the number of magic charms, respectively Lines 2 to N+1: These N lines desribe the grid. Line i+1 contains N space separated integers, describing the net change in berries in the N cells along row i of the grid. Lines N+2 to N+M+1: These M lines describe the magic charms. Each of these lines has 3 integers: the first two integers describe the position of the charm in the grid and the third integer describes its strength. -----Output format----- The first line of output must either consist of the word YES, if there are safe paths, or the word NO, if there are no safe paths. If the output on the first line is YES then the second line should contain a single integer giving the maximum number of berries Little Red Riding Hood can collect among all safe paths. -----Sample Input----- 5 3 3 3 2 4 3 2 1 -1 -2 2 -1 2 4 3 -3 -2 2 3 2 1 3 -1 2 -1 2 1 2 2 4 5 2 4 2 1 -----Sample Output----- YES 19 -----Test data----- In all subtasks, you may assume that 2 ≤ N ≤ 500. Each value on the grid is guaranteed to have absolute value not more than 1000. Let K denote the maximum strength among all the magic charms. - Subtask 1 (30 marks) : 1 ≤ M ≤ 10, 1 ≤ K ≤ 1,000. - Subtask 2 (70 marks) : 1 ≤ M ≤ 10,000, 1 ≤ K ≤ 10. -----Live evaluation data----- - Subtask 1: Testcases 0,1,2,3,4. - Subtask 2: Testcases 5,6,7,8. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here import sys def dist(a,b): return abs(a[0]-b[0])+abs(a[1]-b[1]) n, m = map(int, input().split()) matrix=[] id_matrix=[[0 for i in range(n)] for i in range(n)] for _ in range(n): matrix.append(list(map(int, input().split()))) charms=[] for _ in range(m): x,y,lungh = map(int, input().split()) x-=1 y-=1 charms.append([x,y,lungh]) if m<=10: for i in range(n): for j in range(n): flag=0 for charm in charms: if dist([i,j],charm[:2])<=charm[2]: flag=1 break if flag==0: matrix[i][j]=-float('Inf') for i in range(1,n): matrix[0][i]+=matrix[0][i-1] matrix[i][0]+=matrix[i-1][0] for i in range(1,n): for j in range(1,n): matrix[i][j]+=max(matrix[i-1][j], matrix[i][j-1]) else: for charm in charms: for i in range(-charm[2],charm[2]+1): appo=charm[2]-abs(i) for j in range(-appo, appo+1): x=i+charm[0] y=j+charm[1] if x>=0 and x<n and y>=0 and y<n: id_matrix[x][y]=1 if id_matrix[0][0]==0: matrix[0][0]=-float('Inf') for i in range(1,n): if id_matrix[0][i]==0: matrix[0][i]=-float('Inf') else: matrix[0][i]+=matrix[0][i-1] if id_matrix[i][0]==0: matrix[i][0]=-float('Inf') else: matrix[i][0]+=matrix[i-1][0] for i in range(1,n): for j in range(1,n): if id_matrix[i][j]==0: matrix[i][j]=-float('Inf') else: matrix[i][j]+=max(matrix[i-1][j], matrix[i][j-1]) if matrix[n-1][n-1]<-10**(10): print('NO') else: print('YES') print(matrix[n-1][n-1]) ```
{ "language": "python", "test_cases": [ { "input": "5 3\n3 3 2 4 3 \n2 1 -1 -2 2 \n-1 2 4 3 -3 \n-2 2 3 2 1 \n3 -1 2 -1 2 \n1 2 2\n4 5 2\n4 2 1\n\n", "output": "YES\n19\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO13002" }
vfc_2034
false
false
false
false
false
apps
verifiable_code
799
Solve the following coding problem using the programming language python: One upon a time there were three best friends Abhinav, Harsh, and Akash decided to form a team and take part in ICPC from KIIT. Participants are usually offered several problems during the programming contest. Long before the start, the friends decided that they will implement a problem if at least two of them are sure about the solution. Otherwise, friends won't write the problem's solution. This contest offers $N$ problems to the participants. For each problem we know, which friend is sure about the solution. Help the KIITians find the number of problems for which they will write a solution. Then n lines contain three integers each, each integer is either 0 or 1. If the first number in the line equals 1, then Abhinav is sure about the problem's solution, otherwise, he isn't sure. The second number shows Harsh's view on the solution, the third number shows Akash's view. The numbers on the lines are -----Input:----- - A single integer will contain $N$, number of problems. -----Output:----- Print a single integer — the number of problems the friends will implement on the contest. -----Constraints----- - $1 \leq N \leq 1000$ -----Sample Input:----- 3 1 1 0 1 1 1 1 0 0 -----Sample Output:----- 2 -----EXPLANATION:----- In the first sample, Abhinav and Harsh are sure that they know how to solve the first problem and all three of them know how to solve the second problem. That means that they will write solutions for these problems. Only Abhinav is sure about the solution for the third problem, but that isn't enough, so the group won't take it. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here n = int(input()) count = 0 for _ in range(n): L = list(map(int, input().split())) if (L.count(1)>=2): count+=1 print(count) ```
{ "language": "python", "test_cases": [ { "input": "3\n1 1 0\n1 1 1\n1 0 0\n", "output": "2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COX22020/problems/ACODEX2" }
vfc_2038
false
false
false
false
false
apps
verifiable_code
800
Solve the following coding problem using the programming language python: Chef has provided with a sequence of integers of length $N$ arranged in an unsorted fashion. The elements of the sequence are ordered as ${A1,A2,A3.....A'N}$ The task of the chef is to identify the highest and lowest value among the given sequence. It is assured that the sequence given contains the highest and the lowest value always Please help chef in finding the desired value. -----Input:----- - First line will contain $N$, number of elements in the sequence. - Next line contains $N$ integers of the sequence . -----Output:----- Print the HIGHEST and LOWEST value of the sequence respectively. -----Constraints----- - $1 \leq N \leq 100$ - $2 \leq {A1,A2,A3.....A'N} \leq 10^4$ -----Sample Input:----- 5 3 2 7 9 4 -----Sample Output:----- 9 2 -----EXPLANATION:----- This list is : [3,2,7,9,4] so the highest value is 9 and lowest is 2 respectively. 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=list(map(int,input().split())) a.sort() print(a[-1],a[0]) ```
{ "language": "python", "test_cases": [ { "input": "5\n3 2 7 9 4\n", "output": "9 2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SPTC2020/problems/CPCEJC2" }
vfc_2042
false
false
false
false
false
apps
verifiable_code
801
Solve the following coding problem using the programming language python: Chefina has two sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_N$. She views two sequences with length $N$ as identical if, after they are sorted in non-decreasing order, the $i$-th element of one sequence is equal to the $i$-th element of the other sequence for each $i$ ($1 \le i \le N$). To impress Chefina, Chef wants to make the sequences identical. He may perform the following operation zero or more times: choose two integers $i$ and $j$ $(1 \le i,j \le N)$ and swap $A_i$ with $B_j$. The cost of each such operation is $\mathrm{min}(A_i, B_j)$. You have to find the minimum total cost with which Chef can make the two sequences identical. -----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$. - The third line contains $N$ space-separated integers $B_1, B_2, \ldots, B_N$. -----Output----- For each test case, print a single line containing one integer ― the minimum cost, or $-1$ if no valid sequence of operations exists. -----Constraints----- - $1 \le T \le 2,000$ - $1 \le N \le 2 \cdot 10^5$ - $1 \le A_i, B_i \le 10^9$ for each valid $i$ - the sum of $N$ over all test cases does not exceed $2 \cdot 10^6$ -----Subtasks----- Subtask #1 (15 points): - $T \le 20$ - $N \le 20$ Subtask #2 (85 points): original constraints -----Example Input----- 3 1 1 2 2 1 2 2 1 2 1 1 2 2 -----Example Output----- -1 0 1 -----Explanation----- Example case 1: There is no way to make the sequences identical, so the answer is $-1$. Example case 2: The sequence are identical initially, so the answer is $0$. Example case 3: We can swap $A_1$ with $B_2$, which makes the two sequences identical, 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 from collections import Counter tc=int(input()) for k in range(tc): n=int(input()) a=list(map(int, input().rstrip().split())) b= list(map(int, input().rstrip().split())) cc=sorted(a+b) #print('cc = ',cc) p=[] q=[] #print('len(cc) = ',len(cc)) #print('len = ',(2*n)) #rx=0 for i in range(0,(2*n),2): p.append(cc[i]) #rx+=1 for i in range(1,(2*n)+1,2): q.append(cc[i]) if(p!=q): print('-1') continue a.sort() b.sort() #print(p) #print(q) if(a==b): print('0') continue xx = list((Counter(a) - Counter(p)).elements()) yy = list((Counter(b) - Counter(p)).elements()) #print('xx = ',xx) #print('yy = ',yy) iu=len(xx) gb=sorted(xx+yy) #print(iu) uu=xx[0] vv=yy[0] #print('uu = ',uu) #print('vv = ',vv) zz=min(cc[0],uu,vv) #print('zz = ',zz) ans=0 for i in range(iu): if(gb[i]<=(zz*2)): ans+=gb[i] else: ans+=(zz*2) print(ans) #a = [1, 1, 1, 2, 3, 3] #b = [1, 1, 2, 2, 3, 4] '''c = [] i, j = 0, 0 while i < len(a) and j < len(b): if a[i] == b[j]: c.append(a[i]) i += 1 j += 1 elif a[i] > b[j]: j += 1 else: i += 1''' #print(c) ```
{ "language": "python", "test_cases": [ { "input": "3\n1\n1\n2\n2\n1 2\n2 1\n2\n1 1\n2 2\n", "output": "-1\n0\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHFNSWPS" }
vfc_2046
false
false
false
false
false
apps
verifiable_code
802
Solve the following coding problem using the programming language python: Chef likes to solve difficult tasks. This time, he tried to solve the Big Famous Unsolvable $A+B=C$. One of his friends played a prank on Chef and randomly shuffled the bits in $A$ and $B$ (independently in each number). However, the funny thing is that the sum of the resulting numbers remained $C$ even after shuffling. Chef is now wondering: in how many ways is it possible to shuffle the bits of $A$ and the bits of $B$ such that their sum after shuffling is equal to $C$? Let's denote the integers obtained by shuffling the bits of $A$ and $B$ by $A_s$ and $B_s$ respectively; two ways $(A_{s1}, B_{s1})$ and $(A_{s2}, B_{s2})$ are considered distinct if $A_{s1} \neq A_{s2}$ or $B_{s1} \neq B_{s2}$. It is allowed to add any number (possibly zero) of leading zeroes, i.e. bits $0$, to $A$ and any number of leading zeroes to $B$ before shuffling the bits. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains three space-separated integers $A$, $B$ and $C$. -----Output----- For each test case, print a single line containing one integer — the number of ways to shuffle the bits. -----Constraints----- - $1 \le T \le 1,000$ - $1 \le A, B, C \le 10^9$ - $A+B = C$ -----Subtasks----- Subtask #1 (50 points): $1 \le A, B, C \le 10^5$ Subtask #2 (50 points): original constraints -----Example Input----- 2 1 2 3 369 428 797 -----Example Output----- 2 56 -----Explanation----- Example case 1: We can consider $A=01$ and $B=10$ in binary. Then, there are two possible ways: swapping the two bits of $A$ and the two bits of $B$ ($A_s=10$, $B_s=01$ in binary, $2$ and $1$ in decimal representation) or not shuffling any bits. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math def csb(n): count = 0 while (n): n &= (n-1) count+= 1 return count def f(ca,cb,i,cf,C,n,dp): if ca<0 or cb<0: return 0 if i==n: if ca==0 and cb==0 and cf==0: return 1 return 0 st=str(ca)+" "+str(cb)+" "+str(cf)+" "+str(i) if dp.get(st)!=None: return dp[st] x=0 if (C&(1<<i))>0: x=1 if x==1: #we will have odd num of set bits if cf==1: dp[st]=f(ca,cb,i+1,0,C,n,dp)+f(ca-1,cb-1,i+1,1,C,n,dp) else: dp[st]=f(ca-1,cb,i+1,0,C,n,dp)+f(ca,cb-1,i+1,0,C,n,dp) else: if cf==1: dp[st]=f(ca-1,cb,i+1,1,C,n,dp)+f(ca,cb-1,i+1,1,C,n,dp) else: dp[st]=f(ca,cb,i+1,0,C,n,dp)+f(ca-1,cb-1,i+1,1,C,n,dp) return dp[st] def ip(): for _ in range(int(input())): a,b,c=list(map(int,input().split())) n=int(math.log(c,2))+1 dp={} print(f(csb(a),csb(b),0,0,c,n,dp)) ip() ```
{ "language": "python", "test_cases": [ { "input": "2\n1 2 3\n369 428 797\n", "output": "2\n56\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFADD" }
vfc_2050
false
false
false
false
false
apps
verifiable_code
803
Solve the following coding problem using the programming language python: In poker, you have 5 cards. There are 10 kinds of poker hands (from highest to lowest): - royal flush - ace, king, queen, jack and ten, all in the same suit - straight flush - five cards of the same suit in sequence, such as 10,9,8,7,6 of clubs; ace can be counted both as the highest card or as the lowest card - A,2,3,4,5 of hearts is a straight flush. But 4,3,2,A,K of hearts is not a straight flush - it's just a flush. - four of a kind - four cards of the same rank, such as four kings. - full house - three cards of one rank plus two cards of another rank - flush - five cards of the same suit (but not a straight flush) - straight - five cards in order - just like the straight flush, but mixed suits - three of a kind - three cards of one rank and two other cards - two pairs - two cards of one rank, two cards of another rank, and one more card - pair - two cards of the same rank - high card - none of the above Write a program that will help you play poker by telling you what kind of hand you have. -----Input----- The first line of input contains the number of test cases (no more than 20). Each test case consists of one line - five space separated cards. Each card is represented by a two-letter (or digit) word. The first character is the rank (A,K,Q,J,T,9,8,7,6,5,4,3 or 2), the second character is the suit (S,H,D,C standing for spades, hearts, diamonds and clubs). The cards can be in any order (but they will not repeat). -----Output----- For each test case output one line describing the type of a hand, exactly like in the list above. -----Example----- Input: 3 AH KH QH TH JH KH 5S 3C 5C 7D QH QD 2S QC 2C Output: royal flush pair full house The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python cards = ['A','2','3','4','5','6','7','8','9','T','J','Q','K'] def royal_flush(arr): nonlocal ans, confirm rf_set = 'TJQKA' rf = 1 for char in arr: if char[0] not in rf_set: rf = 0 break if rf : if len(set(suit)) == 1: ans = 'royal flush' confirm = 1 def straight_flush(arr): # and 'straight' nonlocal ans,confirm sf = 1 for i in range(1,5): if arr[i] - arr[i-1] != 1: sf = 0 break if sf: if len(set(suit)) == 1 : ans = 'straight flush' confirm = 1 else: ans = 'straight' confirm = 1 def four(arr): nonlocal ans, confirm f = 0 for char in arr: if arr.count(char) == 4: f = 1 break if f: confirm = 1 ans = 'four of a kind' def full_house(arr): # and three nonlocal ans, confirm fh = 0 three = 0 two = 0 for char in arr: if arr.count(char) == 3: three = 1 elif arr.count(char) == 2: two = 1 if three and two: confirm = 1 ans = 'full house' elif three: confirm = 1 ans = 'three of a kind' def two_pairs(arr): nonlocal ans, confirm temp = [] for char in arr: if arr.count(char) == 2: if char not in temp: temp.append(char) if len(temp) == 2: confirm = 1 ans = 'two pairs' elif len(temp) == 1: confirm = 1 ans = 'pair' def idex(char_x): return cards.index(char_x) for _ in range(int(input())): onhand = list(input().split()) cards_set = [[],[]] suit = [] confirm = 0 ans = '' for c in onhand: num = idex(c[0]) cards_set[0].append(num) if num == 0: cards_set[1].append(13) else: cards_set[1].append(num) suit.append(c[1]) royal_flush(onhand) if not confirm: cards_set[0] = sorted(cards_set[0]) cards_set[1] = sorted(cards_set[1]) straight_flush(cards_set[0]) straight_flush(cards_set[1]) if not confirm: four(cards_set[0]) four(cards_set[1]) if not confirm: full_house(cards_set[0]) full_house(cards_set[1]) if not confirm: if len(set(suit)) == 1: confirm = 1 ans = 'flush' if not confirm: two_pairs(cards_set[0]) two_pairs(cards_set[1]) print(ans if confirm else 'high card') ```
{ "language": "python", "test_cases": [ { "input": "3\nAH KH QH TH JH\nKH 5S 3C 5C 7D\nQH QD 2S QC 2C\n", "output": "royal flush\npair\nfull house\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/POKER" }
vfc_2054
false
false
false
false
false
apps
verifiable_code
804
Solve the following coding problem using the programming language python: Bitland declared war on Chefland and sent an army to fight them, but Chefland defended efficiently and Bitland's army has been reduced to N$N$ soldiers. They have no chance of winning the war and do not want to surrender, so they are planning to commit group suicide. Josh, the leader of Bitland's remaining soldiers, has different plans — he wants to survive and somehow escape. The soldiers are numbered 1$1$ through N$N$; Josh is soldier N$N$. The soldiers are going to stand in a circle in the order 1,2,…,P−1,N,P,P+1,…,N−1$1, 2, \ldots, P-1, N, P, P+1, \ldots, N-1$. Formally, they are standing in the circle in such a way that if Josh's position is P$P$ (1≤P≤N$1 \le P \le N$), then for each i$i$ (1≤i≤N−2$1 \le i \le N-2$, i≠P−1$i \neq P-1$), soldier i+1$i+1$ is directly to the right of soldier i$i$, soldier P$P$ (if P≤N−1$P \le N-1$) or 1$1$ (if P=N$P = N$) is directly to the right of Josh and Josh is directly to the right of soldier P−1$P-1$ (if P≥2$P \ge 2$) or soldier N−1$N-1$ (if P=1$P = 1$); if 2≤P≤N−2$2 \le P \le N-2$, soldier 1$1$ is also directly to the right of soldier N−1$N-1$. For each i$i$ (1≤i≤N−1$1 \le i \le N-1$), soldier i$i$ has a sword with power Ai$A_i$. Josh plans to take a shield with sufficiently high defense power D$D$. First, the soldiers start to commit group suicide according to the following rules: - Initially, soldier 1$1$ is the attacking soldier. - If the attacking soldier is not Josh, this soldier attacks the soldier that is currently to his right. - When Josh is attacked with power a$a$, the current defense power of his shield decreases by a$a$, and if it becomes negative, Josh dies. When a different soldier is attacked, he does not try to defend and dies immediately. The power of the attacking soldier's sword does not change. - Then, the next living soldier to the right of the current attacking soldier becomes the attacking soldier and the process continues until there is only one soldier left. It is clear that this way, Josh cannot be the last survivor. However, Chefland's general Chef plans to interrupt this process as soon as there are exactly two living soldiers of Bitland left (Josh wants to be one of them) by attacking them with Chefland's full firepower F$F$. Since this attack is unexpected, both attacked soldiers try to defend independently with the weapons they have. Josh survives if the current defense power of his shield is at least F$F$. Any other soldier survives only if the power of his sword is strictly greater than F$F$. Since Chefland does not attack again, if both Josh and another soldier survive, then the other soldier will kill Josh. Therefore, Josh wants to be the only survivor of Chefland's attack. Your task is to find the minimum possible value of D$D$ such that Josh survives if he chooses his position P$P$ optimally (or determine that he cannot survive) and the lowest position P$P$ such that Josh survives if he takes a shield with this defense power D$D$. -----Input----- - The first line of the input contains a single integer T$T$ denoting the number of test cases. The description of T$T$ test cases follows. - The first line of each test case contains a single integer N$N$. - The second line contains N−1$N-1$ space-separated integers A1,A2,…,AN−1$A_1, A_2, \ldots, A_{N-1}$. - The third line contains a single integer F$F$. -----Output----- For each test case, first, print a line containing the string "possible" if Josh can survive or "impossible" if he cannot (without quotes). Then, if he can survive, print a second line containing two space-separated integers P$P$ and D$D$. -----Constraints----- - 1≤T≤1,000$1 \le T \le 1,000$ - 2≤N≤1,000,000$2 \le N \le 1,000,000$ - 1≤Ai≤10,000$1 \le A_i \le 10,000$ for each valid i$i$ - 1≤F≤10,000$1 \le F \le 10,000$ - the sum of N$N$ over all test cases does not exceed 1,000,005$1,000,005$ -----Subtasks----- Subtask #1 (30 points): - 1≤T≤10$1 \le T \le 10$ - 2≤N≤100$2 \le N \le 100$ - 1≤Ai≤100$1 \le A_i \le 100$ for each valid i$i$ - 1≤F≤100$1 \le F \le 100$ Subtask #2 (70 points): original constraints -----Example Input----- 2 5 12 34 45 5 10 5 10 15 43 20 5 -----Example Output----- possible 4 100 impossible -----Explanation----- Example case 1: When Josh is at the position P=4$P = 4$, the soldiers' initial powers in clockwise order around the circle, starting with soldier 1$1$, are [12,34,45,D,5]$[12, 34, 45, D, 5]$ (D$D$ denotes Josh). Then, the following happens: - The soldier with power 12$12$ attacks the soldier with power 34$34$ and kills him. - The soldier with power 45$45$ attacks Josh, who defends. The living soldiers' powers are now [12,45,D−45,5]$[12, 45, D-45, 5]$ and Josh is the attacking soldier. - Josh does not attack, so the soldier to his right (with power 5$5$) becomes the attacking soldier. He attacks the soldier with power 12$12$ and kills him. - The soldier with power 45$45$ attacks Josh again and Josh defends again. - The soldier with power 5$5$ attacks the soldier with power 45$45$ and kills him. - Now, two soldiers are left: Josh (with a shield with defense power D−90$D-90$) and the soldier with a sword with power 5$5$. Each of them is attacked with firepower F=10$F=10$, so the power of Josh's shield drops to D−100$D-100$ and the other soldier dies. If Josh survives, his shield's initial power D$D$ should be at least 45+45+10=100$45+45+10 = 100$. For all other positions P$P$, Josh cannot survive. Example case 2: Regardless of how large D$D$ is and which position Josh chooses, after Chefland's attack, a soldier of Bitland other than Josh will always survive. This soldier will then attack Josh until his shield breaks and he dies. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import numpy as np for _ in range(int(input())): n = int(input())-1;soldiers = [int(j) for j in input().split()] force = int(input());attacks = np.zeros(2*n,dtype=int);attacks[:n] = np.array(soldiers);attacks[n:2*n] = attacks[:n];shield = [0 for _ in range(n)];pow_of_2 = 1 while n // pow_of_2 > 0: pow_of_2 *= 2 soldier_of_attack = (2 * n - pow_of_2) % n;pow_of_2 = attacks[soldier_of_attack] > force for i in range(n): if attacks[i] > force: shield[i] = 10 ** 11 elif n == 1: shield[i] = force elif pow_of_2: shield[i] = force; num_of_survivors = n; soldiers = list(attacks[i:i+n]); starting_soldier = (n - i) % n if (num_of_survivors - starting_soldier) % 2 == 1: shield[i] += soldiers[-1] soldiers = [soldiers[i] for i in range(num_of_survivors) if i < starting_soldier or (i - starting_soldier) % 2 == 0];num_of_survivors = starting_soldier + (num_of_survivors - starting_soldier - 1) // 2 if num_of_survivors > 1: pow_2 = 1 while True: attacker = num_of_survivors - (num_of_survivors % pow_2); pow_2 *= 2 if attacker == 0: break if attacker % pow_2 == 0: shield[i] += soldiers[attacker] elif i == soldier_of_attack: shield[i] = force else: shield[i] = force + 1 shield_needed = min(shield) if shield_needed == 10 ** 11: print("impossible") else: print("possible") for i in range(n): if shield[i] == shield_needed:print(str(i+1) + " " + str(shield_needed));break ```
{ "language": "python", "test_cases": [ { "input": "2\n5\n12 34 45 5\n10\n5\n10 15 43 20\n5\n", "output": "possible\n4 100\nimpossible\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHFWAR" }
vfc_2058
false
false
false
false
false
apps
verifiable_code
805
Solve the following coding problem using the programming language python: in Chefland, there is a very famous street where $N$ types of street food (numbered $1$ through $N$) are offered. For each valid $i$, there are $S_i$ stores that offer food of the $i$-th type, the price of one piece of food of this type is $V_i$ (the same in each of these stores) and each day, $P_i$ people come to buy it; each of these people wants to buy one piece of food of the $i$-th type. Chef is planning to open a new store at this street, where he would offer food of one of these $N$ types. Chef assumes that the people who want to buy the type of food he'd offer will split equally among all stores that offer it, and if this is impossible, i.e. the number of these people $p$ is not divisible by the number of these stores $s$, then only $\left\lfloor\frac{p}{s}\right\rfloor$ people will buy food from Chef. Chef wants to maximise his daily profit. Help Chef choose which type of food to offer and find the maximum daily profit he can make. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - $N$ lines follow. For each $i$ ($1 \le i \le N$), the $i$-th of these lines contains three space-separated integers $S_i$, $P_i$ and $V_i$. -----Output----- For each test case, print a single line containing one integer ― the maximum profit. -----Constraints----- - $1 \le T \le 100$ - $1 \le N \le 100$ - $1 \le S_i, V_i, P_i \le 10,000$ for each valid $i$ -----Subtasks----- Subtask #1 (100 points): original constraints -----Example Input----- 2 3 4 6 8 2 6 6 1 4 3 1 7 7 4 -----Example Output----- 12 0 -----Explanation----- Example case 1: Chef should offer food of the second type. On each day, two people would buy from him, so his daily profit would be $12$. Example case 2: Chef has no option other than to offer the only type of food, but he does not expect anyone to buy from him anyway, so his daily profit is $0$. 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()) while(t): n=int(input()) l=[] for i in range(n): l.append(list(map(int,input().split()))); m=[] for i in l: m.append((i[1]//(i[0]+1))*i[2]) res=max(m) print(res) t=t-1 ```
{ "language": "python", "test_cases": [ { "input": "2\n3\n4 6 8\n2 6 6\n1 4 3\n1\n7 7 4\n", "output": "12\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/STFOOD" }
vfc_2062
false
false
false
false
false
apps
verifiable_code
806
Solve the following coding problem using the programming language python: John was learning mathematics and was very bored. Jane his best friend gave him a problem to solve. The description of the problem was as follows:- You are given a decimal number $N$(1<=$N$<=$10^9$) and three integers $A$, $B$, $C$. Steps to perform: 1) You have to create a $LIST$. 2) You have to initialize the $LIST$ by adding N to the $LIST$ as its first element. 3) Divide$N$ by $A$ and if the first digit of the fractional part is Non-Zero then add this digit to the $LIST$ otherwise add the first digit of the integral part(Leftmost digit). (The integer part or integral part of a decimal is the integer written to the left of the decimal separator. The part from the decimal separator i.e to the right is the fractional part. ) 4) Update $N$ by Last element of the $LIST$. N = Last element of $LIST$ 5) You have to perform the same process from step 3 on $N$ for $B$ and $C$ respectively 6) Repeat from step 3 You have to answer$Q$(1 <= $Q$<= 100 ) queries For each query you are given an integer $i$ (0 <= $i$ <= $10^9$ ). You have to print the element present at the ith position of the $LIST$. Help John solve this problem. -----Input:----- - The First Line of 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 the integer $N$. - The second line of each test case contains three integers $A$, $B$, and $C$ separated by a space - The third line of each test case contains an integer $Q$. - Then the next $Q$ line follows. - An integer $i$ (0 <= $i$ <= 10^9 ) -----Output:----- You have to answer the $Q$ queries in the next $Q$ lines. -----Constraints----- - $1 \leq T \leq 10$ - $1 \leq N \leq 10^9$ - $2 \leq A \leq 10$ - $2 \leq B \leq 10$ - $2 \leq C \leq 10$ - $2 \leq Q \leq 100$ - $0 \leq i \leq 10^9$ -----Sample Input:----- 1 56 3 5 7 4 0 1 2 3 -----Sample Output:----- 56 6 2 2 -----EXPLANATION:----- This list is : $N$ = 56 and $A$ = 3, $B$ = 5, $C$ = 7. Initially $LIST$ = $[ 56 ]$ $N$$/$$A$ = 56/3 = 18.666666666666668 Add 6 to the $LIST$ $LIST$ = $[ 56, 6 ]$ $N$ = 6 $N$$/$$B$ = 6/5 = 1.2 Add 2 to the$LIST$ $LIST$ = $[ 56, 6, 2 ]$ N = 2 $N$$/$$C$ = 2/7 =0. 2857142857142857 Add 2 to the $LIST$. $LIST$ = $[ 56, 6, 2, 2 ]$ $N$ = 2 We have to keep repeating this process. If any of the numbers got by $N$ dividing by either $A$, $B$, $C$ have 0 after the decimal point then we have to take the first digit of the number. for example: if we got 12.005 then here we take 1 and add it to the list and then assign N = 1 Now the queries ask for the elements at index 0, 1, 2, 3 of the $LIST$ which is 56,6, 2, 2 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # Why do we fall ? So we can learn to pick ourselves up. t = int(input()) for _ in range(0,t): n = int(input()) abc = [int(i) for i in input().split()] i = 0 lst = [n] for _ in range(0,100): k = str(lst[-1]/abc[i%3]).split('.') if int(k[1][0]) > 0: lst.append(int(k[1][0])) else: lst.append(int(k[0][0])) i += 1 pattern = [] ind = 0 while len(pattern) == 0: for i in range(ind, len(lst) - 1): check = lst[ind: i + 1] * 50 check = check[:len(lst) - ind] if lst[ind:] == check: pattern = check break if len(pattern): break ind += 1 final_pattern = [] for i in range(0, len(pattern)): couldbe = pattern[:i + 1] check = pattern[:i + 1] * 100 check = check[:len(pattern)] if check == pattern: final_pattern = couldbe break lp = len(final_pattern) q = int(input()) for _ in range(0, q): qq = int(input()) if qq < ind: print(lst[qq]) else: qq -= ind kk = qq % lp print(final_pattern[kk]) """ 1 56 3 5 7 4 0 1 2 3 """ ```
{ "language": "python", "test_cases": [ { "input": "1\n56\n3 5 7\n4\n0\n1\n2\n3\n", "output": "56\n6\n2\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PROC2020/problems/WLIST" }
vfc_2066
false
false
false
false
false
apps
verifiable_code
807
Solve the following coding problem using the programming language python: You are given an array A of size N. Let us list down all the subarrays of the given array. There will be a total of N * (N + 1) / 2 subarrays of the given array. Let us sort each of the subarrays in descending order of the numbers in it. Now you want to sort these subarrays in descending order. You can compare two subarrays B, C, as follows. compare(B, C): Append N - |B| zeros at the end of the array B. Append N - |C| zeros at the end of the array C. for i = 1 to N: if B[i] < C[i]: return B is less than C if B[i] > C[i]: return B is greater than C return B and C are equal. You are given M queries asking for the maximum element in the pth subarray (1-based indexing). -----Input----- The first line of input contains T, the number of test cases. The first line of each test case contains two space separated integers N and M, denoting the array size and the number of queries respectively. The next line contains N space-separated integers denoting the array elements. Each of the next M lines contains a single integer - p. -----Output----- Output a single integer corresponding to the maximum element in the pth subarray. -----Constraints----- - 1 ≤ Ai ≤ 109 - 1 ≤ p ≤ N+1C2 -----Subtasks-----Subtask #1 (20 points): - 1 ≤ T ≤ 20 - 1 ≤ N ≤ 200 - 1 ≤ M ≤ 104 Subtask #2 (30 points): - 1 ≤ T ≤ 20 - 1 ≤ N ≤ 3000 - 1 ≤ M ≤ 104 Subtask #3 (50 points): - 1 ≤ T ≤ 5 - 1 ≤ N ≤ 105 - 1 ≤ M ≤ 105 -----Example----- Input:1 4 2 3 1 2 4 1 5 Output:4 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here for _ in range(int(input())): n,q=map(int,input().split()) l=[int(i) for i in input().split()] qry=[int(input()) for i in range(q)] def cmp(sub1,sub2): for i in range(len(sub1)): if sub1[i]>sub2[i]: return 1 if sub1[i]<sub2[i]: return 2 return 1 maxl=[] for i in range(n): for j in range(i,n): maxl.append(max(l[i:j+1])) maxl.sort(reverse=True) for i in qry: print(maxl[i-1]) ```
{ "language": "python", "test_cases": [ { "input": "1\n4 2\n3 1 2 4\n1\n5\n", "output": "4\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/KTHMAX" }
vfc_2070
false
false
false
false
false
apps
verifiable_code
808
Solve the following coding problem using the programming language python: One day Chef was playing with numbers. He loves Lowest Common Multiple (LCM) too much and he is a very curious guy. He always try to do new things. Now he want to make a large number with it. But he doesn't want to take too many numbers. He is willing to take only three numbers less than or equal to N (not necessarily distinct ) and from those three number he want get the maximum number by taking LCM of the numbers. As he is busy in playing some more tricks of maths, he assign this task to you. -----Input----- First line of input contains an integer t ( t<=1000 ), Number of test cases. t line follows an integer N -----Output----- Print t lines contains a single integer — the maximum possible LCM of three not necessarily distinct positive integers that are not greater than N. -----Constraints----- 1<= N <= 10^6 -----Example----- Input: 2 9 7 Output: 504 210 -----Explanation----- Example case 2. For the last example, we can chose numbers 7, 6, 5 and the LCM of them is 7•6•5 = 210. It is the maximum value we can get. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from fractions import gcd for testCases in range(eval(input())): n = eval(input()) if n == 1: print('1') elif n == 2: print('2') elif n == 3: print('6') else: c = n*(n-1) k = n - 2 while True: if gcd(k,n-1) == 1 and gcd(k,n) == 1: break k -= 1 d = (n-1)*(n - 2) k1 = n - 3 while True: if gcd(k1,n-1) == 1 and gcd(k1,n-2) == 1: break k1 -= 1 print(max(c*k,d*k1)) ```
{ "language": "python", "test_cases": [ { "input": "2\n9\n7\n", "output": "504\n210\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CDX2015/problems/CDXLRG" }
vfc_2074
false
false
false
false
false
apps
verifiable_code
809
Solve the following coding problem using the programming language python: Zaikia has $N$ sticks of distinct positive lengths $A_1,A_2,\dots,A_N$. For no good reason at all, he wants to know if there is a triplet of sticks which when connected end-to-end will form a non-trivial triangle. Here non-trivial refers to a triangle with positive area. Help Zaikia know if such a triplet exists or not. If such a triplet exists, help him find the lexicographically largest applicable triplet.Input - The first line contains an integer $N$. - The second line contains $N$ space-seperated integers $A_1,A_2,\dots,A_N$. Output - In the first line print YES if a triplet exists or NO if it doesn't. - If such a triplet exists, then in the second line print the lexicographically largest applicable triplet.Constraints - $3 \leq N \leq {2}\times{10}^{5}$ - $1 \leq A_i \leq {10}^{9}$ for each valid $i$Sample Input 1 5 4 2 10 3 5 Sample Output 1 YES 5 4 3 Explanation 1 There are three unordered triplets of sticks which can be used to create a triangle: - $4,2,3$ - $4,2,5$ - $4,3,5$ Arranging them in lexicographically largest fashion - $4,3,2$ - $5,4,2$ - $5,4,3$ Here $5,4,3$ is the lexicographically largest so it is the triplet which dristiron wantsSample Input 2 5 1 2 4 8 16 Sample Output 2 NO Explanation 2 There are no triplets of sticks here that can be used to create a triangle. 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 as c n=int(input());l=list(map(int,input().split())) l1=[] if(n<3): print("NO") else: l.sort() for i in range(n-2): if(l[i]+l[i+1]>l[i+2]): l1.append([l[i+2],l[i+1],l[i]]) if(len(l1)!=0): print("YES") print(*max(l1)) else: print("NO") ```
{ "language": "python", "test_cases": [ { "input": "5\n4 2 10 3 5\n", "output": "YES\n5 4 3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COJK2020/problems/CKOJ20A" }
vfc_2078
false
false
false
false
false
apps
verifiable_code
810
Solve the following coding problem using the programming language python: Chef is frustrated in this lockown. So to overcome this he plans to travel various mountains. He is very strange so he sets some conditions for $each$ Type 2 query(mentioned below) (i.e. $1$ $i$) : - Let Chef has travelled till $ith$ mountain from left to right. - He does not like to travel the mountain with the height ,of which he has travelled till now. More formally, Let the height of peak on which he is standing is $a_{i}$ then he can only go to the peak of height $a_{j}$ which is greater than $a_{i}$ and nearest to $ith$ mountain such that there should be no other peak of same height $a_{j}$ till $a_{i}$(height of $ith$ mountain) . -----Input format:----- - The first line contains an integer $T$ denoting the number of test cases. - The second line of consist of a integer $N$ and $Q$ . - The third line contains $N$ not necessarily distinct positive integers $a_{0},a_{1}, . . .,a_{n-1}$ denoting the height of $N$ mountains. - Then next $Q$ lines follows where each line consisting of $either$ of $2$ types of queries: Type 1: $0$ $A$ $B$ i.e. $a_{A} = B$ (where height of $Ath$ mountain will be updated to $B$) Type 2: $1$ $A$ i.e. you have to answer $a_k$ which is greater than $a_{A}$ and nearest to $Ath$ mountain such that there should be no other peak of same height $a_{k}$ till $a_{A}$(height of $Ath$ mountain) . -----Output format:----- - For every query of Type 2 there should be an integer $a_{k}$ on next line for the updated array , If no such $a_{k}$ exists then $a_{k}$= $-1$ , as query of type 1 will have no output . -----Constraints:----- - $1\leq T \leq 10^2$ - $1 \leq N,Q \leq 10^4$ - $0\leq a_{i} \leq 10^6$ - $0\leq B \leq 10^6$ - $0\leq A \leq N-1$ -----Subtasks----- - 1 Point : $1 \leq T,N,Q \leq 10^2$ $0\leq B,a_{i} \leq 10^2$ - 99 Points : Orginal Constraints -----Example:----- -----Input:----- 1 10 5 1 3 5 4 5 6 7 8 4 5 1 7 1 3 1 1 0 2 7 1 3 -----Output:----- -1 6 5 5 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here from bisect import bisect_left def BinarySearch(a, x): i = bisect_left(a, x) if i != len(a) and a[i] == x: return i else: return -1 for _t in range(int(input())): _n, q = list(map(int, input().split())) mounts = list(map(int, input().split())) for _q in range(q): query = list(map(int, input().split())) if query[0] == 0: mounts[query[1]] = query[2] else: curr = query[1] prev = set(mounts[:curr+1]) for m in mounts[curr+1:]: if m > mounts[curr] and m not in prev: print(m) break else: print(-1) ```
{ "language": "python", "test_cases": [ { "input": "1\n10 5\n1 3 5 4 5 6 7 8 4 5\n1 7\n1 3\n1 1\n0 2 7\n1 3\n", "output": "-1\n6\n5\n5\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/STR2020/problems/CHFMNT" }
vfc_2082
false
false
false
false
false
apps
verifiable_code
811
Solve the following coding problem using the programming language python: Indian National Olympiad in Informatics 2013 Calvin wakes up early one morning and finds that all his friends in the hostel are asleep. To amuse himself, he decides to play the following game : he draws a sequence of N squares on the ground, numbered 1 to N, and writes an integer in each square. He starts at square k (1 ≤ k ≤ N). The game consists of one forward phase followed by one backward phase. - In the forward phase, Calvin makes zero or more moves of the following type : if his current position is p, he can jump to p+1 or p+2 as long as he stays within the N squares. - In the backward phase, Calvin makes zero or more moves of the following type : if his current position is p, he can jump to p−1 or p−2 as long as he stays within the N squares. He plays such that he finally ends up at square 1, and then he stops. He starts with a score of 0, and each time he jumps from square i to square j, he adds the integer written in square j to his score. Find the maximum score Calvin can obtain by playing this game. Recall that Calvin must start at square k and end at square 1. The integer on the square where he starts is not included in his score. For example, suppose N = 5 and the numbers in squares are 5, 3, −2, 1, 1. If k = 2, Calvin starts on the second square. He can make a forward move to square 4, another to square 5, a backward move to square 4, another to square 2, and another to square 1. His total score is 1+1+1+3+5 = 11. You can check that this is the maximum score possible. -----Input format----- • Line 1 : Two space-separated integers, N and k, with 1 ≤ k ≤ N. • Line 2 : A space-separated sequence of N integers, the numbers in squares 1, 2 . . . , N . -----Output format----- A single line with a single integer, the maximum score Calvin can obtain by playing the game. -----Test Data----- The testdata is grouped into two subtasks with the following constraints on the inputs. • Subtask 1 [30 points] : 1 ≤ N ≤ 3000. • Subtask 2 [70 points] : 1 ≤ N ≤ 106. In all subtasks, the number in each square is between −1000 and 1000 inclusive. -----Example----- Here is the sample input and output corresponding to the example above. -----Sample input----- 5 2 5 3 -2 1 1 -----Sample output----- 11 Note: Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your final submission. A program with extraneous output will be treated as incorrect! The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python try: n, k=map(int, input().split()) arr=list(map(int, input().split())) forward = [0]*(n+1) backward= [0]*(n+1) backward[0]=arr[0] backward[1]=arr[0]+arr[1] for i in range(k, n): forward[i]=arr[i] +max(forward[i-1],forward[i-2]) for i in range(2, n): backward[i]=arr[i]+max(backward[i-1],backward[i-2]) ans=-float("Inf") for i in range(k-1, n): ans=max(ans, forward[i]+backward[i]-arr[i]) print(ans) except Exception: pass ```
{ "language": "python", "test_cases": [ { "input": "and output corresponding to the example above.\nSample input\n5 2\n5 3 -2 1 1\nSample output\n11\nNote : Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your final submission. A program with extraneous output will be treated as incorrect!\n", "output": "", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/INOIPRAC/problems/INOI1301" }
vfc_2086
false
false
false
false
false
apps
verifiable_code
812
Solve the following coding problem using the programming language python: DevuLand is a very strange place. There are n villages in it. Some of the villages are occupied by dinosaurs while the remaining ones by villagers. You are given the information of DevuLand by an array D of size n. If D[i] is non-negative, it means that there are D[i] villagers in that village. Otherwise, it means that are -D[i] dinosaurs in that village. It is also guaranteed that total number of villagers in DevuLand is equal to total number of dinosaurs. Once dinosaurs got very hungry and started eating villagers. Frightened villagers gathered immediately and met their Sarpanch Deviji. Deviji, being a very daring and negotiable person, met to the head of dinosaurs. Soon both parties called a truce. It was decided that the villagers will provide laddus to the dinosaurs. So everyday, each villager will take exactly one laddu to one of the dinosaurs in such a way that no dinosaur remains hungry (note that this is possible because number of villagers is the same as the number of dinosaurs). Actually, carrying laddus is a quite a tough job. Villagers have to use a bullock cart for that. It takes one unit of grass a bullock to carry a cart with 1 laddu for 1 kilometre. Laddus used to be very heavy in DevuLand, so a bullock cart can not carry more than one laddu. It is also given distance between village indexed i and j is |j - i| (the absolute value) kilometres. Now villagers sat down and found a strategy to feed laddus to dinosaurs so that they need to buy the least amount of grass from the nearby market. They are not very good in calculations, please find out what is the minimum number of units of grass they need to buy. -----Input----- First line of the input contains an integer T denoting number of test cases. For each test case, there are two lines. First line contains a single integer denoting n: number of villages. Second line contains n space separated integers denoting the array D. -----Output----- For each test case, print a single line containing the integer corresponding to answer of the problem. -----Constraints----- - 1 ≤ T ≤ 10^5 - 1 ≤ n ≤ 10^5 - -10^4 ≤ D[i] ≤ 10^4 - Sum of n over all the test cases will be ≤ 10^6 - It is guaranteed that sum of D[i] is zero for a single test case which ensures that there are equal number of villagers and dinosaurs. -----Example----- Input: 3 2 5 -5 2 -5 5 3 1 2 -3 Output: 5 5 4 -----Explanation----- Example case 1. Each villager in village 1, need to walk 1 km to reach to the dinosaur in 2nd village. Example case 2. Each villager in village 2, need to walk 1 km to reach to the dinosaur 1st village. Example case 3. Each villager in village 1, need to walk 2 km to reach to the dinosaur in 3rd village whereas Each villager in village 2, need to walk 1 km to reach to the dinosaur in 3rd village. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here for _ in range(int(input())): n = int(input()) a = list(map(int, input().split())) curr = 0 ans = 0 for x in a: curr += x ans += abs(curr) print(ans) ```
{ "language": "python", "test_cases": [ { "input": "3\n2\n5 -5\n2\n-5 5\n3\n1 2 -3\n", "output": "5\n5\n4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PRLADDU" }
vfc_2090
false
false
false
false
false
apps
verifiable_code
813
Solve the following coding problem using the programming language python: Harsh, like usual, started studying 6 months before for his end semester examinations. He was going to complete his 8th revision of the whole syllabus, when suddenly Pranav showed up in his room with the last year's question paper for their algorithms course. This paper contains a problem which both of them couldn't solve. Frustrated he asked you for help. But you declined him and instead try to do this problem instead: You are given an array $A_1,A_2,\dots,A_N$, a positive integer $K$, and a function $F(x)=\displaystyle\sum_{i=1}^{N}{\left|{\left({x-A_i}\right)^K}\right|}$. Find the smallest integer $x$ such that $F(x)$ is minimum.Input - The first line contains two space-seperated integers , $N$ and $K$ - The second line contains $N$ space-seperated integers $A_1,A_2,\dots,A_N$. Output In the first and only line print the smallest integer $x$ such that $F(x)$ is minimumConstraints - $1 \leq N \leq {10}^{5}$ - $1 \leq K \leq {3}$ - $1 \leq A_i \leq {5}\times{10}^{4}$ for each valid $i$Sample Input 1 3 1 6 1 7 Sample Output 1 6 Explanation 1 $F(6) = \displaystyle\sum_{i=1}^{N}{\left|{\left({6-A_i}\right)^K}\right|} \\ F(6) = \left|{\left({6-6}\right)^1}\right| + \left|{\left({6-1}\right)^1}\right| + \left|{\left({6-7}\right)^1}\right| \\ F(6) = 0 + 5+ 1 \\ F(6) = 6 $ Here $6$ is the minumum value for $F(x)$ for any integer value of $x$.Sample Input 2 3 2 6 1 7 Sample Output 2 5 Explanation 2 $F(5) = \displaystyle\sum_{i=1}^{N}{\left|{\left({5-A_i}\right)^K}\right|} \\F(5) = \left|{\left({5-6}\right)^2}\right| + \left|{\left({5-1}\right)^2}\right| + \left|{\left({5-7}\right)^2}\right| \\F(5) = 1 + 16 + 4 \\F(5) = 21$ Here $21$ is the minumum value for $F(x)$ for any integer value of $x$.Sample Input 3 3 3 6 1 7 Sample Output 3 4 Explanation 3 $F(4) = \displaystyle\sum_{i=1}^{N}{\left|{\left({4-A_i}\right)^K}\right|} \\F(4) = \left|{\left({4-6}\right)^3}\right| + \left|{\left({4-1}\right)^3}\right| + \left|{\left({4-7}\right)^3}\right| \\F(4) = 8 + 27 + 27 \\F(4) = 62 $ Here $62$ is the minumum value for $F(x)$ for any integer value of $x$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python #dt = {} for i in x: dt[i] = dt.get(i,0)+1 import sys;input = sys.stdin.readline inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()] n,k = ip() x = ip() x.sort() if k == 1: a = x[n//2] b = x[n//2-1] else: s = sum(x) a = s//n b = a + 1 sa = sum([abs((a-i)**k) for i in x]) sb = sum([abs((b-i)**k) for i in x]) if sa < sb: print(a) else: print(b) ```
{ "language": "python", "test_cases": [ { "input": "3 1\n6 1 7\n", "output": "6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COJK2020/problems/CKOJ20B" }
vfc_2094
false
false
false
false
false
apps
verifiable_code
814
Solve the following coding problem using the programming language python: Tzuyu gave Nayeon a strip of $N$ cells (numbered $1$ through $N$) for her birthday. This strip is described by a sequence $A_1, A_2, \ldots, A_N$, where for each valid $i$, the $i$-th cell is blocked if $A_i = 1$ or free if $A_i = 0$. Tzuyu and Nayeon are going to use it to play a game with the following rules: - The players alternate turns; Nayeon plays first. - Initially, both players are outside of the strip. However, note that afterwards during the game, their positions are always different. - In each turn, the current player should choose a free cell and move there. Afterwards, this cell becomes blocked and the players cannot move to it again. - If it is the current player's first turn, she may move to any free cell. - Otherwise, she may only move to one of the left and right adjacent cells, i.e. from a cell $c$, the current player may only move to the cell $c-1$ or $c+1$ (if it is free). - If a player is unable to move to a free cell during her turn, this player loses the game. Nayeon and Tzuyu are very smart, so they both play optimally. Since it is Nayeon's birthday, she wants to know if she can beat Tzuyu. Find out who wins. -----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 the string "Yes" if Nayeon wins the game or "No" if Tzuyu wins (without quotes). -----Constraints----- - $1 \le T \le 40,000$ - $2 \le N \le 3\cdot 10^5$ - $0 \le A_i \le 1$ for each valid $i$ - $A_1 = A_N = 1$ - the sum of $N$ over all test cases does not exceed $10^6$ -----Subtasks----- Subtask #1 (50 points): $A_i = 0$ for each $i$ ($2 \le i \le N-1$) Subtask #2 (50 points): original constraints -----Example Input----- 4 7 1 1 0 0 0 1 1 8 1 0 1 1 1 0 0 1 4 1 1 0 1 4 1 1 1 1 -----Example Output----- Yes No Yes No -----Explanation----- Example case 1: Since both Nayeon and Tzuyu play optimally, Nayeon can start e.g. by moving to cell $4$, which then becomes blocked. Tzuyu has to pick either the cell $3$ or the cell $5$, which also becomes blocked. Nayeon is then left with only one empty cell next to cell $4$ (the one Tzuyu did not pick); after she moves there, Tzuyu is unable to move, so she loses the game. Example case 2: Regardless of what cell Nayeon moves to at the start, Tzuyu will always be able to beat her. 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()) def maxConsequtiveOnes(lst): _max = 0 _ones = [0] for i in lst: if i == 0: _max += 1 if i == 1: _max = 0 _ones.append(_max) return max(_ones) a = list(map(int, input().split())) b = maxConsequtiveOnes(a) if (b % 2 == 0): print("No") else: print("Yes") ```
{ "language": "python", "test_cases": [ { "input": "4\n7\n1 1 0 0 0 1 1\n8\n1 0 1 1 1 0 0 1\n4\n1 1 0 1\n4\n1 1 1 1\n", "output": "Yes\nNo\nYes\nNo\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/ARRGAME" }
vfc_2098
false
false
false
false
false
apps
verifiable_code
815
Solve the following coding problem using the programming language python: Johnny has some difficulty memorizing the small prime numbers. So, his computer science teacher has asked him to play with the following puzzle game frequently. The puzzle is a 3x3 board consisting of numbers from 1 to 9. The objective of the puzzle is to swap the tiles until the following final state is reached: 1 2 3 4 5 6 7 8 9 At each step, Johnny may swap two adjacent tiles if their sum is a prime number. Two tiles are considered adjacent if they have a common edge. Help Johnny to find the shortest number of steps needed to reach the goal state. -----Input----- The first line contains t, the number of test cases (about 50). Then t test cases follow. Each test case consists of a 3x3 table describing a puzzle which Johnny would like to solve. The input data for successive test cases is separated by a blank line. -----Output----- For each test case print a single line containing the shortest number of steps needed to solve the corresponding puzzle. If there is no way to reach the final state, print the number -1. -----Example----- Input: 2 7 3 2 4 1 5 6 8 9 9 8 5 2 4 1 3 7 6 Output: 6 -1 -----Output details----- The possible 6 steps in the first test case are described in the following figure: The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here from collections import deque primes = {2,3,5,7,11,13,17} edges = [(0,3),(0,1),(1,2),(1,4),(2,5),(3,4),(3,6),(4,5),(4,7),(5,8),(6,7),(7,8)] x = [1,2,3,4,5,6,7,8,9] avail = {tuple(x):0} q = deque([x]) while q: curr = q.popleft(); for e in edges: if curr[e[0]]+curr[e[1]] in primes: nxt = curr[0:] nxt[e[0]],nxt[e[1]] = nxt[e[1]], nxt[e[0]] nxtt = tuple(nxt) if nxtt not in avail: avail[nxtt] = avail[tuple(curr)]+1 q.append(nxt) t = int(input()) while t: inp = input() grid = [] for i in range(3): inp = input() for j in inp.strip().split(" "): grid.append(int(j)) gridt = tuple(grid) if gridt in avail: print(avail[gridt]) else: print(-1); t-= 1 ```
{ "language": "python", "test_cases": [ { "input": "2\n\n7 3 2 \n4 1 5 \n6 8 9 \n\n9 8 5 \n2 4 1 \n3 7 6 \n\n\n", "output": "6\n-1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/H1" }
vfc_2102
false
false
false
false
true
apps
verifiable_code
816
Solve the following coding problem using the programming language python: This is another problem about Indraneel's library. His library has one long shelf. His books are numbered and he identifies the books by their number. Each book has a distinct number. He has lost many books, since many of his friends borrow his books and never bother to return them. He does not want to lose any more books and has decided to keep a record of all books that he lends to his friends. To make the task of borrowing a book a little difficult, he has given the following instructions to his friends: when they borrow a book, they must record in a register its position from the left among the books currently on the shelf. Suppose there are $5$ books in the library and they are arranged as follows: 261421532614215326 \quad 1 \quad 42 \quad 15 \quad 3 If someone walks in and borrows the book $42$, then he will record $3$ in the register because this book is the third from the left on the shelf. Now the shelf looks like this: 26115326115326 \quad 1 \quad 15 \quad 3 If the next person borrow the book $3$, he writes down $4$ in the register since this is currently the fourth book from the left on the shelf, and so on. Indraneel knows the initial arrangement of the books in his library at the time that he introduced the register system. After a while he examines his register and would like to know which books have been borrowed. Your task is to write a program to help Indraneel solve this problem. -----Input:----- The first line of the input contains a single integer $M$ indicating the number of books in Indraneel's library. The next line contains $M$ distinct positive integers describing the sequence in which the books are arranged on the library shelf. The third line of input contains a single integer $N$ indicating the number of entries in the register. This, in turn, is followed by $N$ lines (lines $4$ to $N+3$), each containing one positive integer. The integer on line $3+i$ indicates the position from left of the book ith book borrowed. (You may assume that the number on line $3+i$ is at most $M-i+1$.) -----Output:----- $N$ lines with one positive integer on each line. The number on line $i$ is the book borrowed by the ith borrower. -----Constraints:----- - $1 \leq M \leq 1000000$. - $1 \leq N \leq 4000$. -----Sample Input----- 5 26 1 42 15 3 2 3 4 -----Sample Output----- 42 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def bookList(): numBooks=int(input()) bookNum=[int(x) for x in input().split()] takenBooks=int(input()) for i in range(takenBooks): takenBookPos=(int(input())) a=bookNum[takenBookPos-1] print(a) bookNum.remove(a) bookList() ```
{ "language": "python", "test_cases": [ { "input": "5\n26 1 42 15 3\n2\n3\n4\n", "output": "42\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/IARCSJUD/problems/BOOKLIST" }
vfc_2106
false
false
false
false
false
apps
verifiable_code
817
Solve the following coding problem using the programming language python: Amit is going on a date and he wants to gift his date an array of positive numbers. But he is running short on money. He already has an array of numbers in design. Cost of an array of numbers is the sum of elements in it. But he wants to minimize the cost of making it. So he does the following number of operations one by one for any number of times: He chooses two adjacent elements ,replace them by one element with value = XOR of the two numbers. This operation reduces length of array (and elements are re-numerated accordingly) Find the minimum amount of money that Amit needs to spend to gift his date. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of $2$ lines of input, first line contains a single integer $N$ and the second line contains $N$ elements - $A1,A2,A3,.....,AN$ -----Output:----- For each testcase, output in a single line answer denoting the minimum cost -----Constraints----- - $1 \leq T \leq 10$ - $1 \leq N \leq 10^5$ - $0 \leq Ai \leq 10^9$ for $1\leq i \leq N$ -----Sample Input:----- 3 5 8 4 1 5 0 5 1 2 4 0 8 2 10 10 -----Sample Output:----- 8 15 0 -----EXPLANATION:----- For first case, This array is : $[8,4,1,5,0] -> [8,4,4,0] -> [8,0,0]$. Sum=$8$ So the answer is 8. 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()) l=list(map(int,input().split())) su=l[0] for i in range(1,n): su^=l[i] print(su) ```
{ "language": "python", "test_cases": [ { "input": "3\n5\n8 4 1 5 0\n5\n1 2 4 0 8\n2\n10 10\n", "output": "8\n15\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/INDC2021/problems/DATEGIFT" }
vfc_2110
false
false
false
false
false
apps
verifiable_code
818
Solve the following coding problem using the programming language python: We all know Gru loves Agnes very much. One day Agnes asked Gru to answer some of her queries. She lined up $N$ minions in a straight line from $1$ to $N$. You are given an array $A$ which contains the height of minions. Agnes will ask him several queries. In each query, Gru has to tell whether the bitwise AND of $A[L \ldots R]$ is EVEN or ODD. Since Gru is busy planning the biggest heist on Earth, he asks for your help. -----Input:----- - First line of the input contains an integer $T$ denoting the number of test cases. For each test case:- - First line contains an integer $N$ denoting the number of elements. - Second line contains $N$ spaced integer representing array elements. - Third line contains $Q$ representing number of query. - Next $Q$ lines contains two integer $L$ and $R$ as defined above. -----Output:----- For each query, output "EVEN" or "ODD" without quotes. -----Constraints----- - $1 \leq T \leq 10$ - $1 \leq N \leq 10^5$ - $1 \leq A_i \leq 10^5$ - $1 \leq Q \leq 10^5$ -----Sample Input:----- 1 5 1 3 2 4 5 3 1 2 1 5 3 4 -----Sample Output:----- ODD EVEN EVEN -----Explanation----- - For the first query, the bitwise AND of 1 and 3 is 1, which is Odd. Hence the first output is ODD. - For the third query, the bitwise AND of 2 and 4 is 0, which is Even. Hence the third output is EVEN. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here for _ in range(int(input())): n=int(input()) a=[int(x) for x in input().split()] sum=0 for i in range(n): if a[i]%2==0: sum+=1 a[i]=sum q=int(input()) while q: l,r=map(int,input().split()) if l!=1: c=a[r-1]-a[l-2] else: c=a[r-1] if c==0: print("ODD") else: print("EVEN") q-=1 ```
{ "language": "python", "test_cases": [ { "input": "1\n5\n1 3 2 4 5\n3\n1 2\n1 5\n3 4\n", "output": "ODD\nEVEN\nEVEN\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/MINIAND" }
vfc_2114
false
false
false
false
false
apps
verifiable_code
819
Solve the following coding problem using the programming language python: Motu wants to learn Cricket from a coach, but firstly coach wants to test his IQ level, so he gave Motu $1$ $Red$ $ball$ and $1$ $Black$ $ball$ , and asked him to buy other $x – 1$ red balls and other $y – 1$ black balls from the market. But he put some conditions on buying balls, that if he has $R$ red and $B$ black balls then he can either buy $B$ red balls or $R$ black balls in one operation. He can perform this operation as many times as he want. But as Motu is not so good in solving problems so he needs your help. So you have to tell him whether his coach’s task possible or not. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, two integers $x , y$. -----Output:----- For each testcase, print $YES$, if it is possible to complete coach task, else print $NO$(without quotes) in a separate line. -----Constraints----- - $1 \leq T \leq 100000$ - $1 \leq x, y \leq$ 10^18 -----Sample Input:----- 2 1 2 2 3 -----Sample Output:----- YES YES 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()) while T: x,y=map(int,input().split()) while(y): x, y = y, x % y if x==1: print("YES") else: print("NO") T-=1 ```
{ "language": "python", "test_cases": [ { "input": "2\n1 2\n2 3\n", "output": "YES\nYES\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CCOD2020/problems/NITGOC" }
vfc_2118
false
false
false
false
false
apps
verifiable_code
820
Solve the following coding problem using the programming language python: The Little Elephant from the Zoo of Lviv is going to the Birthday Party of the Big Hippo tomorrow. Now he wants to prepare a gift for the Big Hippo. He has N balloons, numbered from 1 to N. The i-th balloon has the color Ci and it costs Pi dollars. The gift for the Big Hippo will be any subset (chosen randomly, possibly empty) of the balloons such that the number of different colors in that subset is at least M. Help Little Elephant to find the expected cost of the gift. -----Input----- The first line of the input contains a single integer T - the number of test cases. T test cases follow. The first line of each test case contains a pair of integers N and M. The next N lines contain N pairs of integers Ci and Pi, one pair per line. -----Output----- In T lines print T real numbers - the answers for the corresponding test cases. Your answer will considered correct if it has at most 10^-6 absolute or relative error. -----Constraints----- - 1 ≤ T ≤ 40 - 1 ≤ N, Ci≤ 40 - 1 ≤ Pi ≤ 1000000 - 0 ≤ M ≤ K, where K is the number of different colors in the test case. -----Example----- Input: 2 2 2 1 4 2 7 2 1 1 4 2 7 Output: 11.000000000 7.333333333 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here for _ in range(int(input())): n,m = list(map(int,input().split())) colors = [0]*41; cost = [0]*41 color = 0 for i in range(n): cc,pp = list(map(int,input().split())) colors[cc] += 1 cost[cc] += pp for i in colors: if i>0: color += 1 dp2 = [[0]*41 for i in range(color+1)] dp2[0] = [1]*41 for i in range(1,color+1): for j in range(1,41): dp2[i][j] = dp2[i][j-1]+dp2[i-1][j-1]*(2**colors[j]-1) dp1 = [[0]*41 for i in range(color+1)] for i in range(1,color+1): for j in range(1,41): dp1[i][j] = dp1[i][j-1]+dp1[i-1][j-1]*(2**colors[j]-1)+dp2[i-1][j-1]*cost[j]*(2**(colors[j]-1)) num=den=0 for i in range(m,color+1): num += dp1[i][40] den += dp2[i][40] print(num/den) ```
{ "language": "python", "test_cases": [ { "input": "2\n2 2\n1 4\n2 7\n2 1\n1 4\n2 7\n", "output": "11.000000000\n7.333333333\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/LEBALONS" }
vfc_2122
false
false
false
false
false
apps
verifiable_code
821
Solve the following coding problem using the programming language python: You are given $n$ intervals on the $X$ axis. Each interval $i$ is specified by its ends $[L_i, R_i]$. You want to color each interval either blue or yellow. After coloring all the intervals, the $X$ axis will will have $4$ colors: - White, the part of $X$ axis contained in no interval - Blue, the part of $X$ axis contained in atleast one blue colored interval and no yellow colored interval. - Yellow, the part of $X$ axis contained in atleast one yellow colored interval and no blue colored interval. - Green, the part of $X$ axis contained in at least one blue colored interval and at least one yellow colored interval. You want to color the intervals so that the total length of the part colored green is maximized. If there are multiple ways to color which maximize the green part, you can output any of them. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - The first line of each testcase contains $n$, the number of intervals. - The $i^{\text{th}}$ of the next $n$ lines contains two integers $L_i$ and $R_i$ describing the $i^{\text{th}}$ interval. -----Output:----- For each testcase, output a single string on a new line, whose $i^{\text{th}}$ character is $0$ if you color the $i^{\text{th}}$ interval blue, and $1$ if you color it yellow. -----Constraints----- - $ 1 \leq T \leq 10^5 $ - $ 1 \leq n \leq 10^5 $ - The sum of $n$ over all testcases doesn't exceed $10^5$. - $ 1 \leq L_i \leq R_i \leq 10^9 $ for al $ 1 \leq i \leq n$. -----Sample Input:----- 1 3 3 7 2 5 6 9 -----Sample Output:----- 100 -----Explanation:----- The intervals are $[3, 7]$, $[2, 5]$, $[6, 9]$. It is optimal to color them in yellow, blue and blue respectively. In this coloring: - $[2, 3) \cup (7, 9]$ is colored blue. - $(5, 6)$ is colored yellow. - $[3, 5] \cup [6, 7]$ is colored green, with a total length of $(5 - 3) + (7 - 6) = 3$. - Rest of the $X$ axis is colored white. Please note that colors at the endpoints of the intervals don't matter when computing the lengths, and we can ignore them. Open and closed intervals have been used in the explanation section only for clarity, and it doesn't matter whether they are open or closed. Note that 011 is also a valid output. 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()) ls = [] rs = [] lrs = [] for i in range(n): l, r = map(int, input().split()) ls.append(l) rs.append(r) lrs.append((l, r, i)) lrs.sort() c = 0 maxi = -1 res = [-1] * n for l, r, i in lrs: if ls[i] > maxi: maxi = rs[i] res[i] = c elif rs[i] <= maxi: res[i] = 1^c else: maxi = rs[i] c ^= 1 res[i] = c print(*res, sep='') ```
{ "language": "python", "test_cases": [ { "input": "1\n3\n3 7\n2 5\n6 9\n", "output": "100\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/COLINT" }
vfc_2126
false
false
false
false
false
apps
verifiable_code
822
Solve the following coding problem using the programming language python: Doubleville, a small town in Texas, was attacked by the aliens. They have abducted some of the residents and taken them to the a spaceship orbiting around earth. After some (quite unpleasant) human experiments, the aliens cloned the victims, and released multiple copies of them back in Doubleville. So now it might happen that there are 6 identical person named Hugh F. Bumblebee: the original person and its 5 copies. The Federal Bureau of Unauthorized Cloning (FBUC) charged you with the task of determining how many copies were made from each person. To help you in your task, FBUC have collected a DNA sample from each person. All copies of the same person have the same DNA sequence, and different people have different sequences (we know that there are no identical twins in the town, this is not an issue). -----Input----- The input contains several blocks of test cases. Each case begins with a line containing two integers: the number 1 <= n <= 20000 people, and the length 1 <= m <= 20 of the DNA sequences. The next n lines contain the DNA sequences: each line contains a sequence of m characters, where each character is either 'A', 'C', 'G' or 'T'. The input is terminated by a block with n = m = 0 . -----Output----- For each test case, you have to output n lines, each line containing a single integer. The first line contains the number of different people that were not copied. The second line contains the number of people that were copied only once (i.e., there are two identical copies for each such person.) The third line contains the number of people that are present in three identical copies, and so on: the i -th line contains the number of persons that are present in i identical copies. For example, if there are 11 samples, one of them is from John Smith, and all the others are from copies of Joe Foobar, then you have to print '1' in the first and the tenth lines, and '0' in all the other lines. -----Example----- Input: 9 6 AAAAAA ACACAC GTTTTG ACACAC GTTTTG ACACAC ACACAC TCCCCC TCCCCC 0 0 Output: 1 2 0 1 0 0 0 0 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(): while True: [n, m] = [int(i) for i in input().split()] if n == m and n == 0: break cache = {} for i in range(n): dna = input().rstrip('\n') if dna in cache: cache[dna] = 1 + cache[dna] else: cache[dna] = 1 c = [0 for i in range(n + 1)] for dna in cache: c[cache[dna]] = 1 + c[cache[dna]] for i in range(1, n + 1): print(c[i]) def __starting_point(): main() __starting_point() ```
{ "language": "python", "test_cases": [ { "input": "9 6\nAAAAAA\nACACAC\nGTTTTG\nACACAC\nGTTTTG\nACACAC\nACACAC\nTCCCCC\nTCCCCC\n0 0\n\n\n", "output": "1\n2\n0\n1\n0\n0\n0\n0\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PRFT2012/problems/PD11" }
vfc_2130
false
false
false
false
false
apps
verifiable_code
823
Solve the following coding problem using the programming language python: Chef likes problems which using some math. Now he asks you to solve next one. You have 4 integers, Chef wondering is there non-empty subset which has sum equals 0. -----Input----- The first line of input contains T - number of test cases. Each of the next T lines containing four pairwise distinct integer numbers - a, b, c, d. -----Output----- For each test case output "Yes", if possible to get 0 by choosing non-empty subset of {a, b, c, d} with sum equal 0, or "No" in another case. -----Constraints----- - 1 ≤ T ≤ 103 - -106 ≤ a, b, c, d ≤ 106 -----Example----- Input: 3 1 2 0 3 1 2 4 -1 1 2 3 4 Output: Yes Yes No -----Explanation----- Example case 1. We can choose subset {0} Example case 2. We can choose subset {-1, 1} The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here # cook your dish here t = int(input()) while t: t-=1 c=0 ar=[int(i) for i in input().strip().split()] for i in range(1,16): b=bin(i)[2:].zfill(4) s=0 for i in range(4): if b[i]=='1': s+=ar[i] if(s==0): c=1 break print("Yes" if c==1 else "No") ```
{ "language": "python", "test_cases": [ { "input": "3\n1 2 0 3\n1 2 4 -1\n1 2 3 4\n", "output": "Yes\nYes\nNo\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFSETC" }
vfc_2134
false
false
false
false
false
apps
verifiable_code
824
Solve the following coding problem using the programming language python: Corruption is on the rise in the country of Freedonia, Gru's home. Gru wants to end this for good and for that he needs the help of his beloved minions. This corruption network can be represented in the form of a tree having N$N$ nodes and N−1$N-1$ edges. The nodes are numbered from 1$1$ to N$N$, and the tree is rooted at node 1$1$. These nodes represent the corrupt officials and each corrupt official works under some other corrupt official except the Boss who is represented by node 1$1$. Gru believes in divide and conquer and thinks that this network needs to be divided into as many sub-networks as possible. He commands the minions to kill some of the corrupt officials in order to break the network into maximum sub-networks. But as you know, these corrupt officials are very sharp, and hence these assassinations need to be done very smartly and silently, without leaving any traces. To achieve this Gru devises a strategy, in which he designs an operation, and that operation can be applied by the minions any number of times (even 0). In one operation the minions can select any one leaf node official [that is an official who does not have any other official beneath him] in the graph and kill him along with all his ancestors$ancestors$ officials till the root$root$ of the tree in which the operation is applied (this is done to wipe all traces of the operation). This deleted all those nodes from the graph, and also, while doing so, all the associated edges/connections$edges/connections$ of the leaf node and its ancestors are also destroyed. Hence after applying this operation on any tree, it breaks into some connected components which are also trees, which are the new sub-networks. Now the minions are a bit lazy and will do the task someday, but they need to submit a report to Gru containing the number of the maximum$maximum$ connected$connected$ components$components$ that they could achieve by applying the operation any number of times. To do this, the minions require your help. So help the minions by finding out the maximum$maximum$ no.$no.$ of$of$ connected$connected$ components$components$ that can be achieved. Note: After each operation, the topmost node (node with the lowest level. It can be proved that there will always be a unique node with the lowest level in each tree) of each of the remaining trees becomes the root of that particular tree (that is, after the first operation it can be visualized that the graph converts into a forest of rooted trees) -----Input:----- - First line will contain N$N$, number of nodes in the tree. - Next N−1$N-1$ lines contains 2 integers U$U$, V$V$ denoting the endpoints of the ith$i^{th}$ edge. -----Output:----- - Print the maximum number of connected components you can obtain after doing the operation any number of times. -----Constraints----- - 1≤N≤106$1 \leq N \leq 10^6$ - 1≤U,V≤N$1 \leq U,V \leq N$ -----Sample Input:----- 7 1 2 1 3 2 4 2 5 3 6 3 7 -----Sample Output:----- 2 -----EXPLANATION:----- We have 4 leaf nodes in this tree: 4 5 6 7. Suppose we delete node 5, then along with it we also delete node 2 and node 1. so after the deletion we are left with 2 trees, one consisting of only node 4 as the root node of that particular tree, and the other consisting of node 3,6,7 with node 3 as the root node. This can also be achieved by deleting any of the other leaf nodes and it can be proved that we cannot obtain more than 2 connected components in this example. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from sys import stdin,stdout input=stdin.readline n=int(input()) a=[[] for i in range(n)] for i in range(n-1): u,v=map(int,input().split()) a[u-1].append(v-1) a[v-1].append(u-1) b=[0]*n vis=[0]*n st=[(0,0)] vis[0]=1 pa=[0]*n while st: x,y=st.pop() b[x]=y for i in a[x]: if vis[i]==0: pa[i]=x vis[i]=1 if x==0: st.append((i,y+len(a[x])-1)) else: st.append((i,y+len(a[x])-2)) c=[] for i in range(1,n): if len(a[i])==1: c.append((b[i],i)) c.sort() ans=0 while c: x,y=c.pop() m=y p=0 while y!=0 and pa[y]!=-1: y=pa[y] if pa[y]==-1: break if y!=0: p+=(len(a[y])-2) else: p+=(len(a[y])-1) if p>=1: p=0 while m!=0 and pa[m]!=-1: x=m if pa[m]==-1: break m=pa[m] pa[x]=-1 if m!=0: p+=(len(a[m])-2) else: p+=(len(a[m])-1) if y==0: pa[0]=-1 for i in range(n): if pa[i]!=-1: st=[i] pa[i]=-1 while st: x=st.pop() for j in a[x]: if pa[j]!=-1: pa[j]=-1 st.append(j) ans+=1 print(ans) ```
{ "language": "python", "test_cases": [ { "input": "7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n", "output": "2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/MINIKILL" }
vfc_2138
false
false
false
false
true
apps
verifiable_code
825
Solve the following coding problem using the programming language python: Our Chef is doing what he is best at, COOKING A BARBECUE for his guests. He has invited all of us, and taking the help of his apprentice to smoke the barbecues. The chef has got BBQ sticks, each can take N fillings, and he presents N distinctly filled sticks in front his guests forming a N*N matrix But here is the problem, he has got only two type of fillings, meat and capsicum, but still wants the N sticks to look "presentable", he is very particular about it. As a solution he fills the main diagonal of the N*N matrix with the same type of filling (either meat or capsicum) forming a "presentable" set The Chef's apprentice is a fool, so the Chef asks him to cook M distinctly filled sticks ,so that the Chef is sure that among M there exist N sticks forming a "presentable" set. Your job is to determine smallest possible value of M. -----Input----- T, the number of test cases, followed by T lines. Each line containing the positive integer N >= 4 -----Output----- T lines of output, each line contain the positive integer M -----Example----- Input: 1 4 Output: 5 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python testcase = int(input()) for case in range(testcase): n = int(input()) print(2**(n-2)+1) print('\n') ```
{ "language": "python", "test_cases": [ { "input": "1\n4\n", "output": "5\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/AGTK2012/problems/ALGBBQ" }
vfc_2142
false
false
false
false
false
apps
verifiable_code
826
Solve the following coding problem using the programming language python: Let's consider a rectangular table R consisting of N rows and M columns. Rows are enumerated from 1 to N from top to bottom. Columns are enumerated from 1 to M from left to right. Each element of R is a non-negative integer. R is called steady if the sum of elements in the ith row is not less then the sum of elements in the (i-1)th row for each i where 2 ≤ i ≤ N and the sum of elements in the Nth row is less than or equal to M. Your task is to find the number of different steady tables of size N x M modulo 1 000 000 000. -----Input----- The first line of input contains a single integer T denoting number of test cases. First and the only line of each test case contains two space separated integers N and M denoting the number of rows and columns respectively. -----Output----- For each test case, print a single integer corresponding to the answer. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N, M ≤ 2000 -----Subtasks----- - Subtask 1 : 1 ≤ T ≤ 10 , 1 ≤ N,M ≤ 50 : ( 23 pts ) - Subtask 2 : 1 ≤ T ≤ 10 , 1 ≤ N,M ≤ 500 : ( 29 pts ) - Subtask 3 : 1 ≤ T ≤ 10 , 1 ≤ N,M ≤ 2000 : ( 48 pts ) -----Example----- Input: 3 1 1 2 2 2 3 Output: 2 25 273 -----Explanation----- Test case 1 : There are only 2 such grids possible 0 and 1. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # This is not my code, it's Snehasish Karmakar's. Refer to http://www.codechef    .com/viewsolution/7153774 # for original version. # Submitting it to try and work out if it can be sped up. def compute_nCr(n,r) : C[0][0]=1 for i in range(1,n+1) : # print "i",i C[i][0]=1 for j in range(1,min(i,r)+1) : if i!=j : C[i][j]=(C[i-1][j-1]+C[i-1][j])%MOD else : C[i][j]=1 def solve(n,m) : store=[C[m+i-1][i] for i in range(m+1)] for i in range(1,n+1) : s=1 for j in range(1,m+1) : s=(s+store[j])%MOD store[j]=(s*C[m+j-1][j])%MOD # print "a[%d][%d]=%d"%(i,j,s) return s MOD=1000000000 LIMIT=2000 C=[[0] * (LIMIT + 1) for _ in range(2*LIMIT+1)] compute_nCr(2*LIMIT,LIMIT) t=int(input()) while t : n,m=list(map(int,input().split())) print(solve(n,m)) t-=1 ```
{ "language": "python", "test_cases": [ { "input": "3\n1 1\n2 2\n2 3\n", "output": "2\n25\n273\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/STDYTAB" }
vfc_2146
false
false
false
false
true
apps
verifiable_code
827
Solve the following coding problem using the programming language python: Limak has a string S, that consists of N lowercase English letters. Limak then created a new string by repeating S exactly K times. For example, for S = "abcb" and K = 2, he would get "abcbabcb". Your task is to count the number of subsequences "ab" (not necessarily consecutive) in the new string. In other words, find the number pairs of indices i < j, such that the i-th and j-th characters in the new string are 'a' and 'b' respectively. -----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 two integers N and K, denoting the length of the initial string S and the number of repetitions respectively. The second line contains a string S. Its length is exactly N, and each of its characters is a lowercase English letter. -----Output----- For each test case, output a single line containing one integer — the number of subsequences "ab" in the new string. For the given constraints, it can be proved that the answer fits in the 64-bit signed type. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N ≤ 105 - 1 ≤ N * K ≤ 109 (in other words, the new string has length up to 109) -----Example----- Input: 3 4 2 abcb 7 1 aayzbaa 12 80123123 abzbabzbazab Output: 6 2 64197148392731290 -----Explanation----- Test case 1. Limak repeated the string "abcb" 2 times, and so he got "abcbabcb". There are 6 occurrences of the subsequence "ab": - ABcbabcb (the two letters marked uppercase) - AbcBabcb - AbcbaBcb - AbcbabcB - abcbABcb - abcbAbcB Test case 2. Since K = 1, the new string is equal to the given S ("aayzbaa"). There are 2 occurrences of the subsequence "ab" in this string: AayzBaa and aAyzBaa. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python try: t=int(input()) for i in range(t): n,k=map(int,input().split()) s=input() l=[-1]*len(s) numb=s.count('b') x=numb for j in range(len(s)): if(s[j]=='a'): l[j]=numb if(s[j]=='b'): numb=numb-1 #print(l) count1=0 for j in range(len(l)): if(l[j]>0): count1=count1+(k*(2*l[j]+(k-1)*x))//2 elif(l[j]==0): count1=count1+(k*(2*0+(k-1)*x))//2 print(count1) except: pass ```
{ "language": "python", "test_cases": [ { "input": "3\n4 2\nabcb\n7 1\naayzbaa\n12 80123123\nabzbabzbazab\n\n\n", "output": "6\n2\n64197148392731290\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/ABREPEAT" }
vfc_2150
false
false
false
false
false
apps
verifiable_code
828
Solve the following coding problem using the programming language python: Chef lives in a big apartment in Chefland. The apartment charges maintenance fees that he is supposed to pay monthly on time. But Chef is a lazy person and sometimes misses the deadlines. The apartment charges 1000 Rs per month as maintenance fees. Also, they also charge a one-time fine of 100 Rs for each of the late payments. It does not matter how late the payment is done, the fine is fixed to be Rs.100. Chef has been living in the apartment for N months. Now, he wants to switch the apartment, so he has to pay the entire dues to the apartment. The deadline for the N-th month is also over. From his bank statement, he finds the information whether he paid apartment rent for a particular month for not. You are given this information by an array A of size N, where Ai (can be either 0 or 1) specifies whether he has paid the 1000Rs in the i-th month or not. Assume that Chef paid the fees in the i-th month, then this fees will be considered for the earliest month for which Chef has not yet paid the fees. For example, assume Chef did not pay any money in first month and 1000Rs in the second month. Then this rent of 1000Rs will be considered for 1st month. But this counts as late payment for the first month's fees, and hence he will have to pay Rs. 100 for that. And since the payment he made in the second month is not accounted for the second month, but rather for the first month, he will incur a fine of Rs.100 even for the second month. He has not paid any of the fines so far. Can you please help in finding Chef total due (all the fines, plus all the unpaid maintenance fees) that he has to pay to apartment? -----Input----- First line of the input contains an integer T denoting number of test cases. The description of T test cases follows. The first line of each test cases contains an integer N denoting the number of months for which you have to calculate the total amount of money that Chef has to pay at the end of the n month to clear all of his dues. Next line of each test case contains N space separated integers (each of them can be either 0 or 1) denoting whether Chef paid the 1000Rs fees in the corresponding month or not. If the corresponding integer is 1, it means that Chef paid the maintenance fees for that month, whereas 0 will mean that Chef did not pay the maintenance fees that month. -----Output----- For each test case, output a single integer denoting the total amount including fine that Chef has to pay. -----Constraints-----Constraints - 1 ≤ T ≤ 25 - 0 ≤ Ai ≤ 1 -----Subtasks----- Subtask #1 (30 points) - 1 ≤ N ≤ 103 Subtask #2 (70 points) - 1 ≤ N ≤ 105 -----Example----- Input 4 2 1 1 2 0 0 3 0 1 0 2 0 1 Output 0 2200 2300 1200 -----Explanation----- Example case 1. Chef paid maintenance fees for both the months. So, he does not have any dues left. Example case 2. Chef did not pay the maintenance fees for any of the months. For the first month, he has to pay 1000Rs, and 100Rs fine as a late payment. For second month payments, he just have to pay 1100Rs. So, in total he has a due of 1100 + 1100 = 2200 Rs. Example case 3. In the first month, Chef did not pay his maintenance fees. He paid the maintenance of first in the second month. So, he paid a fine of 100Rs for first month. For second and third month, Chef did not pay the maintenance fees. So, he has to pay 1000Rs + 100Rs (of fine) for second month and only 1000Rs + 100Rs (of fine) for third month. In total, Chef has got to pay 100 + 1100 + 1100 = 2300 Rs. Example case 4. In the first month, Chef did not pay his maintenance fees. He paid the maintenance of first in the second month. So, he paid a fine of 100Rs for first month. For second month, Chef did not pay the maintenance fees. So, he has to pay 1000Rs + 100Rs (of fine) for second month. In total, Chef has got to pay 100 + 1100 = 1200 Rs. 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=int(input()) b=input().split() if '0' in b: print(100*(a-b.index('0'))+b.count('0')*1000) else: print(0) ```
{ "language": "python", "test_cases": [ { "input": "4\n2\n1 1\n2\n0 0\n3\n0 1 0\n2\n0 1\n\n\n", "output": "0\n2200\n2300\n1200\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFAPAR" }
vfc_2154
false
false
false
false
false
apps
verifiable_code
829
Solve the following coding problem using the programming language python: Zonal Computing Olympiad 2013, 10 Nov 2012 N teams participate in a league cricket tournament on Mars, where each pair of distinct teams plays each other exactly once. Thus, there are a total of (N × (N-1))/2 matches. An expert has assigned a strength to each team, a positive integer. Strangely, the Martian crowds love one-sided matches and the advertising revenue earned from a match is the absolute value of the difference between the strengths of the two matches. Given the strengths of the N teams, find the total advertising revenue earned from all the matches. For example, suppose N is 4 and the team strengths for teams 1, 2, 3, and 4 are 3, 10, 3, and 5 respectively. Then the advertising revenues from the 6 matches are as follows: Match Team A Team B Ad revenue 1 1 2 7 2 1 3 0 3 1 4 2 4 2 3 7 5 2 4 5 6 3 4 2 Thus the total advertising revenue is 23. -----Input format----- Line 1 : A single integer, N. Line 2 : N space-separated integers, the strengths of the N teams. -----Output format----- A single integer, the total advertising revenue from the tournament. -----Sample input----- 4 3 10 3 5 -----Sample output----- 23 -----Test data----- In all subtasks, the strength of each team is an integer between 1 and 1,000 inclusive. - Subtask 1 (30 marks) : 2 ≤ N ≤ 1,000. - Subtask 2 (70 marks) : 2 ≤ N ≤ 200,000. -----Live evaluation data----- - Subtask 1: Testcases 0,1,2. - Subtask 2: Testcases 3,4,5. -----Note----- The answer might not fit in a variable of type int. We recommend that type long long be used for computing all advertising revenues. If you use printf and scanf, you can use %lld for long long. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here # cook your dish here from itertools import combinations n = int(input()) t = list(combinations(list(map(int, input().split())), 2)) ar = 0 for i in t: ar += abs(i[0] - i[1]) print(ar) ```
{ "language": "python", "test_cases": [ { "input": "4\n3 10 3 5\nSample output\n23\nTest data\nIn all subtasks, the strength of each team is an integer between 1 and 1,000 inclusive.\nSubtask 1 (30 marks) : 2 ≤ N ≤ 1,000.\nSubtask 2 (70 marks) : 2 ≤ N ≤ 200,000.\nLive evaluation data\nSubtask 1 : Testcases 0,1,2.\nSubtask 2 : Testcases 3,4,5.\nNote\nThe answer might not fit in a variable of type int . We recommend that type long long be used for computing all advertising revenues. If you use printf and scanf , you can use %lld for long long .\n", "output": "", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ZCOPRAC/problems/ZCO13001" }
vfc_2158
false
false
false
false
false
apps
verifiable_code
830
Solve the following coding problem using the programming language python: Vivek was quite bored with the lockdown, so he came up with an interesting task. He successfully completed this task and now, he would like you to solve it. You are given two strings $A$ and $B$, each with length $N$. Let's index the characters in each string from $0$ ― for each $i$ ($0 \le i < N$), the $i+1$-th characters of $A$ and $B$ are denoted by $A_i$ and $B_i$ respectively. You should convert $A$ to $B$ by performing operations of the following type: - Choose a subset $S$ of the set $\{0, 1, \ldots, N-1\}$. - Let $c$ be the alphabetically smallest character among $A_x$ for all $x \in S$. - For each $x \in S$, replace $A_x$ by $c$. You should find the smallest necessary number of operations or report that it is impossible to convert $A$ to $B$. If it is possible, you also need to find one way to convert $A$ to $B$ using this smallest number of operations. If there are multiple solutions, you may find any one. -----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 a single string $A$. - The third line contains a single string $B$. -----Output----- For each test case: - If it is impossible to convert $A$ to $B$, print a single line containing the integer $-1$. - Otherwise, first, print a line containing a single integer $K$ ― the minimum number of operations. - Then, print $K$ lines describing the operations. Each of these lines should contain a positive integer $Z$, followed by a space and $Z$ pairwise distinct space-separated integers from the set $\{0, 1, \ldots, N-1\}$ ― the elements of $S$. -----Constraints----- - $1 \le T \le 20$ - $1 \le N \le 10^3$ - $|A| = |B| = N$ - $A$ and $B$ contain only lowercase English letters -----Subtasks----- Subtask #1 (30 points): $B$ contains only characters 'a' and 'b' Subtask #2 (70 points): original constraints -----Example Input----- 3 5 abcab aabab 3 aaa aab 2 de cd -----Example Output----- 2 3 1 2 4 3 0 1 3 -1 -1 -----Explanation----- Example case 1: - First, we can choose $S = (1, 2, 4)$, so the character $c$ is 'b' and the string $A$ after this operation is "abbab". - Then, we choose $S = (0, 1, 3)$, so $c$ is 'a', and $A$ becomes "aabab". - There is no way to convert $A$ to $B$ in only one operation. Example case 2: We can see that it is impossible to convert $A$ to $B$ since $c$ is always 'a'. Example case 3: We can see again that it is impossible to convert $A$ to $B$ since $c$ cannot be 'c'. 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=input() b=input() l=[] flag=0 for i in range(n): if b[i]!=a[i]: if b[i] in a and b[i]<a[i]: l.append(b[i]) else: flag=1 break if flag==1: print(-1) else: if l==[]: print(0) else: l = sorted(list(set(l)), reverse = True) print(len(l)) for i in range(len(l)): q=[] r=[] for j in range(len(a)): if l[i]==b[j]: q.append(j) r.append(a[j]) if l[i] not in r: for k in range(len(a)): if a[k]==l[i]: q.append(k) print(len(q),*q) ```
{ "language": "python", "test_cases": [ { "input": "3\n5\nabcab\naabab\n3\naaa\naab\n2\nde\ncd\n", "output": "2\n3 1 2 4\n3 0 1 3\n-1\n-1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CONVSTR" }
vfc_2162
false
false
false
false
false
apps
verifiable_code
831
Solve the following coding problem using the programming language python: Bear Limak has a sequence of N non-negative integers A1, A2, ..., AN. He defines the score of a segment (consecutive subsequence) as its sum of elements modulo P (not necessarily prime). Find the maximum score of a non-empty segment, and also find the number of segments with this maximum score. -----Input----- First line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. For each test case, the first line of the input contains two space separated integers, N and P. The second line contains N space separated integers denoting the sequence. -----Output----- For each test case, output two space separated integers denoting the maximum score of a segment and the number of segments with the score, respectively. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N ≤ 105 - 1 ≤ P ≤ 109 - 0 ≤ Ai ≤ 109 Subtask #1: (25 points) - 1 ≤ N ≤ 100 Subtask #2: (25 points) - 1 ≤ N ≤ 1000 Subtask #3: (50 points) - original constraints -----Example----- Input: 4 2 3 1 2 3 5 2 4 3 3 100 1 3 5 4 3 1 2 3 4 Output: 2 1 4 2 9 1 2 2 -----Explanation----- Example case 1. There are three segments - [1], [2] and [1, 2]. Sum of these segments are 1, 2 and 3 respectively. Sum of these segments modulo 3 will be 1, 2 and 0. Maximum score among these is 2. There is also only one segment with this score. Example case 2. There are six segments - [2], [4], [3], [2, 4], [4, 3] and [2, 4, 3]. Sum of these segments are 2, 4, 3, 6, 7, 9 respectively. Sum of these segments modulo 5 will be 2, 4, 3, 1, 2, 4. Maximum score among these is 4. And there are two segments with this score. 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,m=input().split() n,m=int(n),int(m) x=y=c=0 l=list(map(int,input().split())) for i in range(n): for j in range(i,n): x=x+l[j] if (x%m)>y: y=x%m c=1 elif y==(x%m): c+=1 x = 0 print(y,c) ```
{ "language": "python", "test_cases": [ { "input": "4\n2 3\n1 2\n3 5\n2 4 3\n3 100\n1 3 5\n4 3\n1 2 3 4\n", "output": "2 1\n4 2\n9 1\n2 2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/BEARSEG" }
vfc_2166
false
false
false
false
true
apps
verifiable_code
832
Solve the following coding problem using the programming language python: Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of interesting subsequences of the sequence $A$. -----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 one integer ― the number of interesting subsequences. -----Constraints----- - $1 \le T \le 10$ - $1 \le K \le N \le 50$ - $1 \le A_i \le 100$ for each valid $i$ -----Subtasks----- Subtask #1 (30 points): $1 \le N \le 20$ Subtask #2 (70 points): original constraints -----Example Input----- 1 4 2 1 2 3 4 -----Example Output----- 1 -----Explanation----- Example case 1: There are six subsequences with length $2$: $(1, 2)$, $(1, 3)$, $(1, 4)$, $(2, 3)$, $(2, 4)$ and $(3, 4)$. The minimum sum is $3$ and the only subsequence with this sum is $(1, 2)$. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def fact(n): if n<2: return 1 return n * fact(n-1) def ncr(n, r): return fact(n)// (fact(r)*fact(n-r)) t=int(input()) for _ in range(t): n, k = list(map(int, input().split())) a = list(map(int, input().split())) a.sort() count_z = a.count(a[k-1]) count_z_seq = a[:k].count(a[k-1]) print(ncr(count_z, count_z_seq)) ```
{ "language": "python", "test_cases": [ { "input": "1\n4 2\n1 2 3 4\n", "output": "1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFINSQ" }
vfc_2170
false
false
false
false
false
apps
verifiable_code
833
Solve the following coding problem using the programming language python: Galileo's latest project involves determining the density of stars in certain regions of the sky. For this purpose he started looking for datasets online, and discovered a dataset on Newton's blog. Newton had decomposed the night sky into a Voronoi tessellation with the generators arranged in a grid. He has stored the number of stars in a Voronoi cell at a position in a matrix that corresponds to the position of the generator in the grid. This dataset does not directly help Galileo, because he needs to be able to query the number of stars in a rectangular portion of the sky. Galileo tried to write a program that does this on his own, but it turned out to be too slow. Can you help him? -----Input Format----- The first line contains two integers n and m that denote the height and width of the matrix respectively. This is followed by n lines each containing m integers each. The line following this would contain a single integer t, the number of queries to be run. Each query line consists of 4 integers px, py, qx, qy. The first two integers denote the row and column numbers of the upper left corner of the rectangular region, and the second pair of numbers correspond to the lower right corner. -----Output Format----- For each query output a single line containing the number of stars in that rectangular region. -----Example----- Input: 3 3 10 10 10 10 10 10 10 10 10 4 1 1 1 1 1 1 3 3 2 1 3 3 3 1 3 3 Output: 10 90 60 30 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import sys def main(): s=sys.stdin.readline n, m = list(map(int, s().split())) nums={} for i in range(1, n+1): nums[i]=list(map(int, s().split())) cases=int(s()) for case in range(cases): px, py, qx, qy = list(map(int, s().split())) ans=[] for i in range(px, qx+1): for j in range(py-1, qy): ans.append(nums[i][j]) print(sum(ans)) def __starting_point(): main() __starting_point() ```
{ "language": "python", "test_cases": [ { "input": "3 3\n10 10 10\n10 10 10\n10 10 10\n4\n1 1 1 1\n1 1 3 3\n2 1 3 3\n3 1 3 3\n", "output": "10\n90\n60\n30\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/DMNT2012/problems/COUNTSTR" }
vfc_2174
false
false
false
false
false
apps
verifiable_code
834
Solve the following coding problem using the programming language python: Striver$Striver$ wants to strive hard in order to reach his goals, hence asks his mentor to give him a question for which he has to strive hard. The mentor gives Striver$Striver$ a N$N$ X N$N$ matrix consisting of lowercase characters (′a′$'a'$ to ′z′$'z'$) and Q$Q$ queries. Every query consists of X$X$ and Y$Y$. From any position in the matrix, one can either move towards the right or towards down. He asks striver to write down all the paths from (1,1)$(1, 1)$ to (X,Y)$(X, Y)$ and find out which string has the maximum number of character ′a′$'a'$ in it and answer him the number of characters which are not 'a' in that string. Striver wants to strive hard but also wants to impress his mentor. He asks for your help to answer Q$Q$ queries given by his mentor as fast as he can so that he can impress his mentor also. Can you help him to answer the Q queries? -----Input:----- - First line will contain T$T$, number of test cases. Then the test cases follow. - First line of every test case contains a number N$N$ and Q$Q$ which denotes the dimensions of the matrix and number of queries respectively. - N lines follow, which contains N numbers each denoting the elements of the matrix. - Q line follow, every line contains X and Y. -----Output:----- For every test case, print a single integer which prints the answer to mentor's every query. -----Constraints----- - 1≤T≤10$1 \leq T \leq 10$ - 1≤N≤103$1 \leq N \leq 10^3$ - 1≤Q≤105$1 \leq Q \leq 10^5$ - 1≤X,Y≤N$1 \leq X, Y \leq N$ -----Sample Input:----- 1 3 2 a b a a c d b a b 1 3 3 3 -----Sample Output:----- 1 2 -----EXPLANATION:----- Query-1: There is only one path from (1,1) to (1,3) i.e.,"aba" and the number of characters which are not 'a' is 1. Query-2: The path which has the maximum number of 'a' in it is "aabab", hence non 'a' characters are 2. 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 _ in range(a): c,d=list(map(int,input().split())) crr=[[[0,0] for i in range(c+1)] for j in range(c+1)] trr=[] for i in range(c): kk=list(input().split()) trr.append(kk) for i in range(1,c+1): for j in range(1,c+1): if(trr[i-1][j-1]=='a'): crr[i][j][0]=max(crr[i-1][j][0],crr[i][j-1][0])+1 if(j==1): crr[i][j][1]=crr[i-1][j][1]+1 elif(i==1): crr[i][j][1]=crr[i][j-1][1]+1 elif(crr[i-1][j][0]>crr[i][j-1][0]): crr[i][j][1]=crr[i-1][j][1]+1 else: crr[i][j][1]=crr[i][j-1][1]+1 else: crr[i][j][0]=max(crr[i-1][j][0],crr[i][j-1][0]) if(j==1): crr[i][j][1]=crr[i-1][j][1]+1 elif(i==1): crr[i][j][1]=crr[i][j-1][1]+1 elif(crr[i-1][j][0]>crr[i][j-1][0]): crr[i][j][1]=crr[i-1][j][1]+1 else: crr[i][j][1]=crr[i][j-1][1]+1 for i in range(d): m,n=list(map(int,input().split())) print(crr[m][n][1]-crr[m][n][0]) ```
{ "language": "python", "test_cases": [ { "input": "1\n3 2\na b a\na c d\nb a b\n1 3\n3 3\n", "output": "1\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/AARA2018/problems/ARMBH5" }
vfc_2178
false
false
false
false
false
apps
verifiable_code
835
Solve the following coding problem using the programming language python: Chef is stuck in a two dimensional maze having N rows and M columns. He needs to get out of the maze as soon as possible and arrive at the kitchen in order to serve his hungry customers. But, he can get out of the maze only if he is able to successfully find any magical path in the given maze. A path is defined as magical if it starts from any of the cell (a,b) of the maze and ends at the cell (c,d) such that the following conditions are satisfied :- - |a - c| + |b - d| = 1 - All the cells in the maze are traversed exactly once. - It is allowed to move only in the four directions - up, down, left and right from the current cell. -----Input----- - First line of the input contains an integer T denoting the number of different types of scenarios. - Each of the next T lines will contain two integers N, M denoting the dimensions of the maze. -----Output----- For each of the T scenarios, output a single line containing "Yes" or "No" (without quotes) denoting whether the Chef can get out of the maze or not. -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ N, M ≤ 1018 -----Subtasks----- Subtask #1 : (30 points) - 1 ≤ T ≤ 100 - 1 ≤ N, M ≤ 10 Subtask #2 : (70 points) Original Constraints -----Example----- Input: 1 2 2 Output: Yes -----Explanation----- Example case 1. Chef can start from (1,1), move down to (2,1), then move right to (2,2) and finally move upwards to reach (1,2). As, he is able to visit all the cells exactly once and sum of absolute differences of corresponding x and y dimension is 1, we can call this path a magical path. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python t = eval(input()) for _ in range(t): n, m = list(map(int, input().split())) if n*m == 2: print('Yes') elif (n*m)%2 == 0 and m != 1 and n != 1: print('Yes') else: print('No') ```
{ "language": "python", "test_cases": [ { "input": "1\n2 2\n", "output": "Yes\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/APRIL16/problems/CHEFPATH" }
vfc_2182
false
false
false
false
false
apps
verifiable_code
836
Solve the following coding problem using the programming language python: Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he's not sure which movie he should watch. There are n movies to watch during this weekend. Each movie can be characterized by two integers Li and Ri, denoting the length and the rating of the corresponding movie. Egor wants to watch exactly one movie with the maximal value of Li × Ri. If there are several such movies, he would pick a one with the maximal Ri among them. If there is still a tie, he would pick the one with the minimal index among them. Your task is to help Egor to pick a movie to watch during this weekend. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The first line of the test case description contains an integer n. The second line of the test case description contains n integers L1, L2, ...,Ln. The following line contains n integers R1, R2, ..., Rn. -----Output----- For each test case, output a single integer i denoting the index of the movie that Egor should watch during this weekend. Note that we follow 1-based indexing. -----Constraints----- - 1 ≤ T ≤ 5 - 1 ≤ n ≤ 100 - 1 ≤ Li, Ri ≤ 100 -----Example----- Input: 2 2 1 2 2 1 4 2 1 4 1 2 4 1 4 Output: 1 2 -----Explanation----- In the first example case, both films have the same value of L × R, but the first film has a better rating. In the second example case, the second and the fourth movies are equally good, but the second movie has a smaller index. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def bestMovie(): tests=int(input()) for t in range(tests): n = int(input()) L = list(map(int, input().split())) R = list(map(int, input().split())) maxIndex = -1 maxValue = 0 for i in range(n): prod = L[i]*R[i] if maxValue < prod: maxValue = prod maxIndex = i elif maxValue == prod: if R[maxIndex] < R[i]: maxIndex = i print(maxIndex+1) bestMovie() ```
{ "language": "python", "test_cases": [ { "input": "2\n2\n1 2\n2 1\n4\n2 1 4 1\n2 4 1 4\n", "output": "1\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COOK69/problems/MOVIEWKN" }
vfc_2186
false
false
false
false
false
apps
verifiable_code
837
Solve the following coding problem using the programming language python: Find sum of all the numbers that are multiples of 10 and are less than or equal to a given number "N". (quotes for clarity and be careful of integer overflow) -----Input----- Input will start with an integer T the count of test cases, each case will have an integer N. -----Output----- Output each values, on a newline. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N ≤1000000000 -----Example----- Input: 1 10 Output: 10 -----Explanation----- Example case 1. Only integer that is multiple 10 that is less than or equal to 10 is 10 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for t in range(eval(input())): n=eval(input()) n-=n%10 n/=10 print(n*(n+1)/2*10) ```
{ "language": "python", "test_cases": [ { "input": "1\n10\n", "output": "10\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/KQPM2015/problems/SUMMATH" }
vfc_2190
false
false
false
false
false
apps
verifiable_code
838
Solve the following coding problem using the programming language python: Chef and his girlfriend are going to have a promenade. They are walking along the straight road which consists of segments placed one by one. Before walking Chef and his girlfriend stay at the beginning of the first segment, they want to achieve the end of the last segment. There are few problems: - At the beginning Chef should choose constant integer - the velocity of mooving. It can't be changed inside one segment. - The velocity should be decreased by at least 1 after achieving the end of some segment. - There is exactly one shop on each segment. Each shop has an attractiveness. If it's attractiveness is W and Chef and his girlfriend move with velocity V then if V < W girlfriend will run away into the shop and the promenade will become ruined. Chef doesn't want to lose her girl in such a way, but he is an old one, so you should find the minimal possible velocity at the first segment to satisfy all conditions. -----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 a single integer N denoting the number of segments. The second line contains N space-separated integers W1, W2, ..., WN denoting the attractiveness of shops. -----Output----- - For each test case, output a single line containing the minimal possible velocity at the beginning. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N ≤ 10^5 - 1 ≤ Wi ≤ 10^6 -----Example----- Input: 2 5 6 5 4 3 2 5 3 4 3 1 1 Output: 6 5 -----Explanation----- Example case 1. If we choose velocity 6, on the first step we have 6 >= 6 everything is OK, then we should decrease the velocity to 5 and on the 2nd segment we'll receive 5 >= 5, again OK, and so on. Example case 2. If we choose velocity 4, the promanade will be ruined on the 2nd step (we sould decrease our velocity, so the maximal possible will be 3 which is less than 4). 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 = int(input()) l= [int(x) for x in input().split()] t=[] for i in range(len(l)): t.append(l[i]+i) print(max(t)) ```
{ "language": "python", "test_cases": [ { "input": "2\n5\n6 5 4 3 2\n5\n3 4 3 1 1\n", "output": "6\n5\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/WALK" }
vfc_2194
false
false
false
false
false
apps
verifiable_code
839
Solve the following coding problem using the programming language python: Dhiraj loves Chocolates.He loves chocolates so much that he can eat up to $1000$ chocolates a day. But his mom is fed up by this habit of him and decides to take things in her hand. Its diwali Season and Dhiraj has got a lot of boxes of chocolates and Dhiraj's mom is afraid that dhiraj might eat all boxes of chocolates. So she told Dhiraj that he can eat only exactly $k$ number of chocolates and dhiraj has to finish all the chocolates in box selected by him and then move on to next box of chocolate.Now Dhiraj is confused that whether he will be able to eat $k$ number of chocolates or not. Since dhiraj is weak at maths,he asks for your help to tell him whether he can eat $k$ number of chocolates or not. So given number of chocolates are $k$ which dhiraj has to eat and the boxes of chocolates each containing some number of chocolates, tell whether dhiraj will be able to eat $k$ number of chocolates or not. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - $k$, representing the number of chocolates dhiraj has to eat. - the third line contains $N$ representing the no. of boxes of chocolates. - fourth line contains list of $a[]$ size $N$ specifying the number of chocolates in each Box. -----Output:----- - For each testcase, output in a single line answer $0$ or $1$. - $0$ if dhiraj cant eat $k$ chocolates from given combination and $1$ if he can eat $k$ chocolates from given combination. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq K \leq 10^7$ - $1 \leq N \leq 800$ - $1 \leq a[i] \leq 10^3$ -----Sample Input:----- 2 20 5 8 7 2 10 5 11 4 6 8 2 10 -----Sample Output:----- 1 0 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def isSubsetSum(arr, n, sum): subset = [ [False for j in range(sum + 1)] for i in range(3) ] for i in range(n + 1): for j in range(sum + 1): if (j == 0):subset[i % 2][j] = True elif (i == 0):subset[i % 2][j] = False elif (arr[i - 1] <= j):subset[i % 2][j] = subset[(i + 1) % 2][j - arr[i - 1]] or subset[(i + 1)% 2][j] else:subset[i % 2][j] = subset[(i + 1) % 2][j] return subset[n % 2][sum] for _ in range(int(input())): k,n,a = int(input()),int(input()),list(map(int,input().split())) if sum(a) < k or k < min(a):print(0);continue print(1) if isSubsetSum(a, n, k) else print(0) ```
{ "language": "python", "test_cases": [ { "input": "2\n20\n5\n8 7 2 10 5\n11\n4\n6 8 2 10\n", "output": "1\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COFY2020/problems/GKSMNLC" }
vfc_2198
false
false
false
false
false
apps
verifiable_code
840
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(odd) 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 50$ - $1 \leq K \leq 50$ -----Sample Input:----- 4 1 3 5 7 -----Sample Output:----- * * * * * * * * * * * * * * * * -----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 def func(num): for i in range(num): if i < num//2 + 1: print(' '*i, end='') print('*') else: print(' '*(num-i-1), end='') print('*') for _ in range(int(input())): num = int(input()) func(num) ```
{ "language": "python", "test_cases": [ { "input": "4\n1\n3\n5\n7\n", "output": "*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n*\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PSTR2020/problems/ITGUY45" }
vfc_2202
false
false
false
false
false
apps
verifiable_code
841
Solve the following coding problem using the programming language python: The Petrozavodsk camp takes place in about one month. Jafar wants to participate in the camp, but guess what? His coach is Yalalovichik. Yalalovichik is a legendary coach, famous in the history of competitive programming. However, he is only willing to send to the camp students who solve really hard problems on Timus. The deadline that Yalalovichik set before has passed and he refuses to send Jafar to the camp. Jafar decided to make Yalalovichik happy in hopes of changing his decision, so he invented a new sequence of numbers and named them Yalalovichik numbers. Jafar is writing a research paper about their properties and wants to publish it in the Science Eagle yearly journal. A Yalalovichik number is created in the following way: - Consider an integer $N$ in decimal notation; let's call it the base of the Yalalovichik number $Y_N$. $N$ may not contain the digit $0$. - Treat $N$ as a decimal string. Compute all left shifts of this string $N_0, N_1, \ldots, N_{|N|-1}$ ($|N|$ denotes the number of digits of $N$); specifically, $N_k$ denotes the string formed by moving the first $k$ digits of $N$ to the end in the same order. - Concatenate the strings $N_0, N_1, \ldots, N_{|N|-1}$. The resulting string is the decimal notation of $Y_N$. For example, if $N = 123$, the left shifts are $123, 231, 312$ and thus $Y_N = 123231312$. You are given the base $N$. Calculate the value of $Y_N$ modulo $10^9+7$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains a single decimal integer $N$. -----Output----- For each test case, print a single line containing one integer — the value of the Yalalovichik number $Y_N$ modulo $10^9+7$. -----Constraints----- - $1 \le T \le 200$ - $|N| \le 10^5$ - $N$ does not contain the digit $0$ - the sum of $|N|$ over all test cases does not exceed $10^6$ -----Example Input----- 1 123 -----Example Output----- 123231312 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python M = 10 ** 9 + 7 for _ in range(int(input())): s,p,m,r = list(map(int, input())),0,1,0 for d in reversed(s): p += d * m m = m * 10 % M for d in s: r = (r * m + p) % M p = (p * 10 - (m - 1) * d) % M print(r) ```
{ "language": "python", "test_cases": [ { "input": "1\n123\n\n", "output": "123231312\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/YVNUM" }
vfc_2206
false
false
false
false
false
apps
verifiable_code
842
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 5 3 4 -----Sample Output:----- 1 1 2 2 3 4 4 5 5 1 1 2 3 3 1 1 22 33 4 4 -----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 t=int(input()) for _ in range(t): n=int(input()) b=1 if n%2: c=n-2 for j in range(n//2): print(" "*j+str(b) +" "*c+ str(b)) b+=1 c-=2 print(" "*(n//2)+str(b)+" "*(n//2)) b+=1 c=1 for j in range(n//2): print(" "*(n//2-j-1)+str(b)+" "*c+ str(b)) b+=1 c+=2 else: c=n-2 for j in range(n//2): print(" "*j+str(b)+" "*c+str(b)) b+=1 c-=2 c=0 for j in range(n//2): print(" "*(n//2-j-1)+str(b) +" "*c+ str(b)) b+=1 c+=2 ```
{ "language": "python", "test_cases": [ { "input": "3\n5\n3\n4\n", "output": "1 1\n2 2\n3\n4 4\n5 5\n1 1\n2\n3 3\n1 1\n22\n33\n4 4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PTRN2020/problems/ITGUY41" }
vfc_2210
false
false
false
false
false
apps
verifiable_code
843
Solve the following coding problem using the programming language python: You are given N integer sequences A1, A2, ..., AN. Each of these sequences contains N elements. You should pick N elements, one from each sequence; let's denote the element picked from sequence Ai by Ei. For each i (2 ≤ i ≤ N), Ei should be strictly greater than Ei-1. Compute the maximum possible value of E1 + E2 + ... + EN. If it's impossible to pick the elements E1, E2, ..., EN, print -1 instead. -----Input----- - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains a single integer N. - N lines follow. For each valid i, the i-th of these lines contains N space-separated integers Ai1, Ai2, ..., AiN denoting the elements of the sequence Ai. -----Output----- For each test case, print a single line containing one integer — the maximum sum of picked elements. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N ≤ 700 - 1 ≤ sum of N in all test-cases ≤ 3700 - 1 ≤ Aij ≤ 109 for each valid i, j -----Subtasks----- Subtask #1 (18 points): 1 ≤ Aij ≤ N for each valid i, j Subtask #2 (82 points): original constraints -----Example----- Input: 1 3 1 2 3 4 5 6 7 8 9 Output: 18 -----Explanation----- Example case 1: To maximise the score, pick 3 from the first row, 6 from the second row and 9 from the third row. The resulting sum is E1+E2+E3 = 3+6+9 = 18. 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): n=int(input()) grid=[] for _ in range(n): temp=[] temp=list(map(int,input().strip().split())) temp.sort() grid.append(temp) curr=max(grid[n-1]) total=curr for i in range(n-2,0-1,-1): flag=0 for j in range(n-1,0-1,-1): if grid[i][j]<curr: flag=1 curr=grid[i][j] total+=curr break if flag==0: total=-1 break print(total) ```
{ "language": "python", "test_cases": [ { "input": "1\n3\n1 2 3\n4 5 6\n7 8 9\n", "output": "18\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/MAXSC" }
vfc_2214
false
false
false
false
true
apps
verifiable_code
844
Solve the following coding problem using the programming language python: Little kids, Jack and Evan like playing their favorite game Glass-and-Stone. Today they want to play something new and came across Twitter on their father's laptop. They saw it for the first time but were already getting bored to see a bunch of sentences having at most 140 characters each. The only thing they liked to play with it is, closing and opening tweets. There are N tweets on the page and each tweet can be opened by clicking on it, to see some statistics related to that tweet. Initially all the tweets are closed. Clicking on an open tweet closes it and clicking on a closed tweet opens it. There is also a button to close all the open tweets. Given a sequence of K clicks by Jack, Evan has to guess the total number of open tweets just after each click. Please help Evan in this game. -----Input----- First line contains two integers N K, the number of tweets (numbered 1 to N) and the number of clicks respectively (1 ≤ N, K ≤ 1000). Each of the following K lines has one of the following. - CLICK X , where X is the tweet number (1 ≤ X ≤ N) - CLOSEALL -----Output----- Output K lines, where the ith line should contain the number of open tweets just after the ith click. -----Example----- Input: 3 6 CLICK 1 CLICK 2 CLICK 3 CLICK 2 CLOSEALL CLICK 1 Output: 1 2 3 2 0 1 Explanation: Let open[x] = 1 if the xth tweet is open and 0 if its closed. Initially open[1..3] = { 0 , 0 , 0 }. Here is the state of open[1..3] after each click and corresponding count of open tweets. CLICK 1 : { 1, 0, 0 }, open count = 1 CLICK 2 : { 1, 1, 0 }, open count = 2 CLICK 3 : { 1, 1, 1 }, open count = 3 CLICK 2 : { 1, 0, 1 }, open count = 2 CLOSEALL : { 0, 0, 0 }, open count = 0 CLICK 1 : { 1, 0, 0 }, open count = 1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def getInput(): N_k = input().split() N =int(N_k[0]) k =int(N_k[1]) list = [] output = [] count = 0 for i in range(0,k): val = input() if(val!="CLOSEALL"): val=val.split() val = int (val[1]) if val not in list: count= count +1 list.append(val) else: list.remove(val) count= count -1 else: count =0 while len(list) > 0: list.pop() output.append(count) for each in output: print(each) getInput() ```
{ "language": "python", "test_cases": [ { "input": "3 6\nCLICK 1\nCLICK 2\nCLICK 3\nCLICK 2\nCLOSEALL\nCLICK 1\n", "output": "1\n2\n3\n2\n0\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COOK23/problems/TWTCLOSE" }
vfc_2218
false
false
false
false
false
apps
verifiable_code
845
Solve the following coding problem using the programming language python: Give me Biscuit Sunny wants to make slices of biscuit of size c * d into identical pieces. but each piece is a square having maximum possible side length with no left over piece of biscuit. Input Format The first line contains an integer N. N lines follow. Each line contains two space separated integers c and d. which denote length and breadth of the biscuit. Constraints 1 <= N <= 1000 1 <= c,d <= 1000 Output Format N lines, each containing an integer that denotes the number of squares of maximum size, when the biscuit is cut as per the given condition. Sample Input 2 2 2 6 9 Sample Output 1 6 Explanation The 1st testcase has a biscuit whose original dimensions are 2 X 2, the biscuit is uncut and is a square. Hence the answer is 1. The 2nd testcase has a biscuit of size 6 X 9 . We can cut it into 54 squares of size 1 X 1 , 6 of size 3 X 3 . For other sizes we will have leftovers. Hence, the number of squares of maximum size that can be cut is 6. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python def __gcd(a, b): # Everything divides 0 if (a == 0 or b == 0): return 0; # base case if (a == b): return a; # a is greater if (a > b): return __gcd(a - b, b); return __gcd(a, b - a); # Function to find # number of squares def NumberOfSquares(x, y): # Here in built PHP # gcd function is used s = __gcd(x, y); ans = (x * y) / (s * s); return int(ans); n=int(input()) while n: n=n-1 c,d=map(int,input().split()) print(NumberOfSquares(c, d)) ```
{ "language": "python", "test_cases": [ { "input": "2\n2 2\n6 9\n", "output": "1\n6\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COM12020/problems/CODE_00" }
vfc_2222
false
false
false
false
false
apps
verifiable_code
846
Solve the following coding problem using the programming language python: -----Problem Statement----- Harry Potter has one biscuit and zero rupee in his pocket. He will perform the following operations exactly $K$ times in total, in the order he likes: - Hit his pocket, which magically increases the number of biscuits by one. - Exchange $A$ biscuits to $1$ rupee. - Exchange $1$ rupee to $B$ biscuits. Find the maximum possible number of biscuits in Harry's pocket after $K$ operations. -----Input----- Input is given in the following format: K A B -----Output----- Print the maximum possible number of biscuits in Harry's pocket after $K$operations. -----Constraints----- - $1 \leq K, A, B \leq 10^9$ - $K$, $A$ and are integers. -----Sample Input----- 4 2 6 -----Sample Output----- 7 -----EXPLANATION----- The number of biscuits in Harry's pocket after $K$ operations is maximized as follows: - Hit his pocket. Now he has $2$ biscuits and $0$ rupee. - Exchange $2$ biscuits to $1$ rupee in his pocket .Now he has $0$ biscuits and $1$ rupee. - Hit his pocket. Now he has $1$ biscuits and $1$ rupee. - Exchange $1$ rupee to $6$ biscuits. his pocket. Now he has $7$ biscuits and $0$ rupee. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python K,A,B = map(int,input().split()) if A + 2 > B: print(K + 1) return start = A - 1 K -= start ans = K//2 * (B-A) + K%2 + start + 1 print(ans) ```
{ "language": "python", "test_cases": [ { "input": "4 2 6\n", "output": "7\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SCAT2020/problems/SC_04" }
vfc_2226
false
false
false
false
false
apps
verifiable_code
847
Solve the following coding problem using the programming language python: Did you know that the people of America eat around 100 acres of pizza per day ? Having read this fact on internet, two chefs from the Elephant city, Arjuna and Bhima are set to make pizza popular in India. They organized a social awareness camp, where N people ( other than these two ) sit around a large pizza. To make it more interesting, they make some pairs among these N people and the two persons in a pair, feed each other. Each person should be a part of at most one pair and most importantly, to make feeding easy, any two pairs should not cross each other ( see figure for more clarity ). Arjuna and Bhima decided to play a game on making the pairs. In his turn, a player makes a pair ( selects two persons, as long as its valid ) and this pair start feeding each other. Arjuna and Bhima take turns alternately, by making a pair in each turn, and they play optimally ( see Notes for more clarity ). The one who can not make a pair in his turn, loses. Given N, find who wins the game, if Arjuna starts first. -----Notes----- - 'Optimally' means, if there is a possible move a person can take in his turn that can make him win finally, he will always take that. You can assume both are very intelligent. -----Input----- First line contains an integer T ( number of test cases, around 1000 ). Each of the next T lines contains an integer N ( 2 <= N <= 10000 ) -----Output----- For each test case, output the name of the winner ( either "Arjuna" or "Bhima" ( without quotes ) ) in a new line. -----Example----- Input: 4 2 4 5 6 Output: Arjuna Arjuna Bhima Arjuna Explanation: Let the people around the table are numbered 1, 2, ... , N in clock-wise order as shown in the image Case 1 : N = 2. Only two persons and Arjuna makes the only possible pair (1,2) Case 2 : N = 4. Arjuna can make the pair (1,3). Bhima can not make any more pairs ( without crossing the pair (1,3) ) Case 3 : N = 5. No matter which pair Arjuna makes first, Bhima can always make one more pair, and Arjuna can not make any further The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python a= [0, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 0, 5, 2, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 2, 7, 4, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 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"python", "test_cases": [ { "input": "4\n2\n4\n5\n6\n", "output": "Arjuna\nArjuna\nBhima\nArjuna\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/BIGPIZA" }
vfc_2230
false
false
false
false
false
apps
verifiable_code
848
Solve the following coding problem using the programming language python: Coach Moony wants the best team to represent their college in ICPC. He has $N$ students standing in a circle with certain rating $X_i$ on a competitive coding platform. It is an established fact that any coder with more rating on the platform is a better coder. Moony wants to send his best $3$ coders based upon their rating. But all coders only want to have their friends in their team and every coder is friends with four other coders, adjacent two on left side in the circle, and adjacent two on right. So Moony comes up with a solution that team with maximum cumulative rating of all three members in a team shall be representing their college. You need to give the cumulative score of the team that will be representing the college. -----Input:----- - First line will contain $T$, number of testcases. - First line of each test case contains a single integer $N$. - Second line of each test case takes $N$ integers, denoting rating of $ith$ coder. -----Output:----- For each testcase, output a single integer denoting cumulative rating of the team. -----Constraints----- - $1 \leq T \leq 10$ - $7 \leq N \leq 10^5$ - $0 \leq X_i \leq 10^9$ -----Sample Input:----- 1 7 10 40 30 30 20 0 0 -----Sample Output:----- 100 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here #Moony and ICPC team T = int(input()) for i in range(T): N,data = int(input()),list(map(int,input().split())) if(N==3): print(sum(data)) else: best = data[0]+data[1]+data[2] overall = best k=len(data) for i in range(1,k-2): overall=overall - data[i-1] + data[i+2] if(overall>best): best = overall j=max(data[1],data[-2]) l= data[-1]+data[0]+j if(best < l): best = l print(best) ```
{ "language": "python", "test_cases": [ { "input": "1\n7\n10 40 30 30 20 0 0\n", "output": "100\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COG2020/problems/COG2002" }
vfc_2234
false
false
false
false
false
apps
verifiable_code
849
Solve the following coding problem using the programming language python: We all know how great ABD aka AB-DE-VILLIERS is. However his team mates were jealous of him and posed a problem for him to solve.The problem description is as follows : Given an array of integers,find the length of the largest subarray(contiguous) of the given array with the maximum possible GCD (Greatest Common Divisor). For info on GCD ,see this link: https://en.wikipedia.org/wiki/Greatest_common_divisor GCD of the subarray is defined as the GCD of all the elements of the subarray. As ABD is not aware of competitive programming he asks your help. Help him! -----Input----- First line will contain integer N denoting the size of array. Second line will contain N integers denoting array elements. -----Output----- The answer as specified in the problem statement . -----Constraints----- 1 <= N <= 1000000 1 <= array[i] <=100000000000 -----Example----- Input: 4 2 4 8 3 Output: 1 Explanation GCD of all possible subarrays of the given array are : 2 , 2 , 2 , 1 , 4 , 4, 1 , 8 , 1 , 3 Largest GCD possible : 8 Length of the largest subarray with GCD as 8 is 1 Hence 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 n=eval(input()) a=list(map(int,input().split())) c=m=0 maxi=max(a) for i in range(n): if a[i]==maxi: c+=1 m=max(c,m) else: c=0 print(m) ```
{ "language": "python", "test_cases": [ { "input": "4\n2 4 8 3\n", "output": "1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/BYTE2016/problems/BYTES11" }
vfc_2238
false
false
false
false
false
apps
verifiable_code
850
Solve the following coding problem using the programming language python: Chef has a sequence of positive integers $A_1, A_2, \ldots, A_N$. He wants to split this sequence into two non-empty (not necessarily contiguous) subsequences $B$ and $C$ such that $\mathrm{GCD}\,(B) + \mathrm{GCD}\,(C)$ is maximum possible. Help him find this maximum value. Note: The greatest common divisor (GCD) of a sequence of positive integers is the largest positive integer that divides each element of this sequence. For example, the GCD of the sequence $(8, 12)$ is $4$. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first line of each test case contains a single integer $N$. - The second line contains $N$ space-separated integers $A_1, A_2, \ldots, A_N$. -----Output----- For each test case, print a single line containing one integer — the maximum value of $\mathrm{GCD}\,(B) + \mathrm{GCD}\,(C)$. -----Constraints----- - $1 \le T \le 10$ - $2 \le N \le 10^5$ - $1 \le A_i \le 10^9$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): $2 \le N \le 20$ Subtask #2 (80 points): original constraints -----Example Input----- 1 4 4 4 7 6 -----Example Output----- 9 -----Explanation----- Example case 1: For example, the sequence $A$ can be divided into subsequences $B = (4, 4, 6)$ and $C = (7)$. 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 gcd __author__ = 'Prateek' def test(): n = int(input()) a = list(map(int, input().split())) a = list(set(a)) n = len(a) if len(a) == 1: print(2 * a[0]) return g1 = [0 for i in range(n)] g2 = [0 for i in range(n)] g1[0] = a[0] g2[n - 1] = a[n - 1] for i in range(1, n): g1[i] = gcd(g1[i - 1], a[i]) for i in range(n - 2, -1, -1): g2[i] = gcd(g2[i + 1], a[i]) ans = 0 for i in range(n): if i == 0: ans = max(ans, g2[i + 1] + a[i]) elif i == n - 1: ans = max(ans, g1[i - 1] + a[i]) else: ans = max(ans, gcd(g1[i - 1], g2[i + 1]) + a[i]) print(ans) if __author__ == 'Prateek': t = int(input()) for _ in range(t): test() ```
{ "language": "python", "test_cases": [ { "input": "1 \n4 \n4 4 7 6 \n\n", "output": "9\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/SUMAGCD" }
vfc_2242
false
false
false
false
false
apps
verifiable_code
851
Solve the following coding problem using the programming language python: Mr. X has come up with a new string compression algorithm. Consider a string of length N which contains up to K distinct characters. The compression algorithm works as follows: Replace each maximal contiguous substring containing only one distinct character (repeated an arbitrary number of times) and replace it by 2 values: the character and the length of the substring. For example, the string "aabbaaa" will be compressed to "a, 2, b, 2, a, 3". Thus the length of the compressed string is 6. Since Mr. X is living in advanced times, the length of any integer is considered to be 1. For example, if a string is compressed to "a, 111, b, 13", then its length after compression is considered to be 4. To test his algorithm, he needs to know the expected length of the compressed string for given N and K if the input string is randomly uniformly chosen from all possibilities. He wants to run this experiment multiple times for different N, K and needs your help. -----Input----- The first line of the input contains an integer T denoting the number of queries. The description of T test cases follows. The first and only line of each test case contains two integers N and K denoting the number of letters in the input string and the maximum number of distinct characters that can be present in the string. -----Output----- For each test case, output a single line containing the expected length of the compressed string. Your answer will be considered correct if the absolute error is less than 10-2 -----Constraints----- - 1 ≤ T ≤ 105 - 1 ≤ N, K ≤ 109 -----Example----- Input: 2 3 1 3 2 Output: 2.0 4.0 -----Explanation-----Example case 1: There is only one string: aaa with compressed string = a, 3. Therefore length = 2 Example case 2 Input strings: "aaa": "a, 3". Length = 2 "aab": "a, 2, b, 1". Length = 4 "aba": "a, 1, b, 1, a, 1". Length = 6 "abb": "a, 1, b, 2". Length = 4 "baa": "b, 1, a, 2". Length = 4 "bab": "b, 1, a, 1, b, 1". Length = 6 "bba": "b, 2, a, 1". Length = 4 "bbb": "b, 3". Length = 2 Expected value = (2+4+6+4+4+6+4+2)/8 = 32/8 = 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()) print(((2*n*(k-1))+2)/k) ```
{ "language": "python", "test_cases": [ { "input": "2\n3 1\n3 2\n\n", "output": "2.0\n4.0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/COMPEXP" }
vfc_2246
false
false
false
false
false
apps
verifiable_code
852
Solve the following coding problem using the programming language python: The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of input, one integer $K$. -----Output:----- For each test case, output as the pattern. -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq K \leq 100$ -----Sample Input:----- 4 1 2 3 4 -----Sample Output:----- 0 01 10 010 101 010 0101 1010 0101 1010 -----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 t=int(input()) for t in range(t): n=int(input()) for i in range(0,n): for j in range(0,n): if i%2==0: if j%2==0: print(0,end="") else: print(1,end="") else: if j%2==0: print(1,end="") else: print(0,end="") print() ```
{ "language": "python", "test_cases": [ { "input": "4\n1\n2\n3\n4\n", "output": "0\n01\n10\n010\n101\n010\n0101\n1010\n0101\n1010\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PTRN2021/problems/ITGUY56" }
vfc_2250
false
false
false
false
false
apps
verifiable_code
853
Solve the following coding problem using the programming language python: The new Formula 1 season is about to begin and Chef has got the chance to work with the Formula 1 technical team. Recently, the pre-season testing ended and the technical team found out that their timing system for qualifying was a little bit buggy. So, they asked Chef to fix it before the season begins. His task is to write a program to find the starting lineup of the race by taking the timings of the drivers in qualifying. (If you don’t know the rules that make the starting grid in Formula 1, consider that the driver with the least time will start at the front). Note: - Two or more drivers can have the same name. - Every driver will have a distinct time. -----Input:----- - The first line of the input consists of a single integer $T$ denoting the number of test cases. - First line of each test case consists of a single integer $N$ denoting the number of drivers to set a time. - The following $2*N$ lines consists of the driver’s name $S$ in one line and its timing details $X$ (in milliseconds) in the next line. -----Output:----- - For each test case output the starting lineup of the race i.e., name of each driver in the order they will start the race. Print each name in a new line. -----Constraints----- - 1 <= $T$ <= 10 - 1 <= $N$ <= 105 - 1 <= $|S|$ <= 20 - 1 <= $X$ <= 109 -----Subtasks----- Subtask #1 (20 points): - 1 <= $N$ <= 100 Subtask #2 (80 points): - Original Constraints -----Sample Input:----- 2 3 Hamilton 75000 Vettel 76000 Bottas 75500 2 Leclerc 666666 Verstappen 666777 -----Sample Output:----- Hamilton Bottas Vettel Leclerc Verstappen -----EXPLANATION:----- The drivers with the least time are ahead in the lineup. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here t=int(input()) for i in range(t): n=int(input()) if n<101: l1=[] l2=[] d=dict() for i in range(1,2*n+1): if i%2==0: l1.append(int(input())) else: l2.append(str(input())) r1=[] for i in l1: r1.append(i) l1.sort() ind=[] for i in l1: a=r1.index(i) ind.append(a) for i in ind: print(l2[i]) else: print(0) break ```
{ "language": "python", "test_cases": [ { "input": "2\n3\nHamilton\n75000\nVettel\n76000\nBottas\n75500\n2\nLeclerc\n666666\nVerstappen\n666777\n", "output": "Hamilton\nBottas\nVettel\nLeclerc\nVerstappen\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/TCFL2020/problems/TCFL20B" }
vfc_2254
false
false
false
false
false
apps
verifiable_code
854
Solve the following coding problem using the programming language python: A beautiful sequence is defined as a sequence that do not have any repeating elements in it. You will be given any random sequence of integers, and you have to tell whether it is a beautiful sequence or not. -----Input:----- - The first line of the input contains a single integer $T$. $T$ denoting the number of test cases. The description of $T$ test cases is as follows. - The next line of the input contains a single integer $N$. $N$ denotes the total number of elements in the sequence. - The next line of the input contains $N$ space-separated integers $A1, A2, A3...An$ denoting the sequence. -----Output:----- - Print "prekrasnyy"(without quotes) if the given sequence is a beautiful sequence, else print "ne krasivo"(without quotes) Note: each test case output must be printed on new line -----Constraints:----- - $1 \leq T \leq 10^2$ - $1 \leq N \leq 10^3$ - $1 \leq A1, A2, A3...An \leq 10^5$ -----Sample Input:----- 2 4 1 2 3 4 6 1 2 3 5 1 4 -----Sample Output:----- prekrasnyy ne krasivo -----Explanation:----- - As 1st sequence do not have any elements repeating, hence it is a beautiful sequence - As in 2nd sequence the element 1 is repeated twice, hence it is not a beautiful sequence The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here for _ in range(int(input())): n = int(input()) arr = list(map(int,input().split())) l = [] for i in range(0, len(arr)): for j in range(i+1, len(arr)): if(arr[i] == arr[j]): l.append(arr[j]) if (len(l) ==0): print("prekrasnyy") else: print("ne krasivo") ```
{ "language": "python", "test_cases": [ { "input": "2\n4\n1 2 3 4\n6\n1 2 3 5 1 4\n", "output": "prekrasnyy\nne krasivo\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ARYS2020/problems/FREQARRY" }
vfc_2258
false
false
false
false
false
apps
verifiable_code
855
Solve the following coding problem using the programming language python: Accepts a string from the user and print the reverse string as the output without using any built-in function. -----Input:----- Each testcase contains of a single line of input, a string. -----Output:----- For each testcase, output in a single line answer, the reverse string. -----Sample Input:----- 1 Tracy -----Sample Output:----- ycarT The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python oo = int(input()) for i in range(oo): val = input() print(val[::-1]) ```
{ "language": "python", "test_cases": [ { "input": "1\nTracy\n", "output": "ycarT\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SPNT2020/problems/AODLS002" }
vfc_2262
false
false
false
false
false
apps
verifiable_code
856
Solve the following coding problem using the programming language python: You are given a dataset consisting of $N$ items. Each item is a pair of a word and a boolean denoting whether the given word is a spam word or not. We want to use this dataset for training our latest machine learning model. Thus we want to choose some subset of this dataset as training dataset. We want to make sure that there are no contradictions in our training set, i.e. there shouldn't be a word included in the training set that's marked both as spam and not-spam. For example item {"fck", 1}, and item {"fck, 0"} can't be present in the training set, because first item says the word "fck" is a spam, whereas the second item says it is not, which is a contradiction. Your task is to select the maximum number of items in the training set. Note that same pair of {word, bool} can appear multiple times in input. The training set can also contain the same pair multiple times. -----Input----- - First line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains a single integer $N$. - $N$ lines follow. For each valid $i$, the $i$-th of these lines contains a string $w_i$, followed by a space and an integer(boolean) $s_i$, denoting the $i$-th item. -----Output----- For each test case, output an integer corresponding to the maximum number of items that can be included in the training set in a single line. -----Constraints----- - $1 \le T \le 10$ - $1 \le N \le 25,000$ - $1 \le |w_i| \le 5$ for each valid $i$ - $0 \le s_i \le 1$ for each valid $i$ - $w_1, w_2, \ldots, w_N$ contain only lowercase English letters -----Example Input----- 3 3 abc 0 abc 1 efg 1 7 fck 1 fck 0 fck 1 body 0 body 0 body 0 ram 0 5 vv 1 vv 0 vv 0 vv 1 vv 1 -----Example Output----- 2 6 3 -----Explanation----- Example case 1: You can include either of the first and the second item, but not both. The third item can also be taken. This way the training set can contain at the very max 2 items. Example case 2: You can include all the items except the second item in the training set. 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): n = int(input()) a = {} for i in range(n): l = input() if l not in a: a[l] = 1 else: a[l] += 1 done = [] ans = 0 for i in a: if a[i] != 0: temp = [x for x in i.split()] v = temp[0] v0 = v + " 0" v1 = v + " 1" if(v0 in a and v1 in a): if a[v0] > a[v1]: ans += a[v0] else: ans += a[v1] a[v0] = a[v1] = 0 elif(v0 in a): ans += a[v0] a[v0] = 0 elif(v1 in a): ans += a[v1] a[v1] = 0 print(ans) ```
{ "language": "python", "test_cases": [ { "input": "3\n3\nabc 0\nabc 1\nefg 1\n7\nfck 1\nfck 0\nfck 1\nbody 0\nbody 0\nbody 0\nram 0\n5\nvv 1\nvv 0\nvv 0\nvv 1\nvv 1\n\n", "output": "2\n6\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/TRAINSET" }
vfc_2266
false
false
false
false
false
apps
verifiable_code
857
Solve the following coding problem using the programming language python: Problem description. Dominic Toretto has taken his crew to compete in this years' Race Wars, a crew-on-crew tournament in which each member of one crew competes with a member of the other crew in a quarter mile drag race. Each win counts as one point for the winning crew. Draws and loses are awarded zero points. In the end the crew with more points is declared the winner of that round and can advance while the losing crew is knocked out. One member can compete in only one race per round and all crews have the same number of members. Dom and his crew have a reputation of being the best and naturally everyone expects them to win this year as well. However, during the tournament he spots a new crew of racers who are participating for the first time in this event. People expect them to be a dark horse so naturally Dom wants to keep an eye on their performance. Being the experienced racer that he is, Dom has figured out the time in which each racer of the opposing crew completes his quarter mile race. He also knows his own crew inside out and can estimate with absolute certainty, the time it would take each of his members to complete the race. Dominic is the reigning champion and thus has an advantage that he can select the order of the matches i.e.: he can select which member of his crew will go up against which member of the opposition. Given this data he wants to figure out the number of races he will win should his crew come face to face with their newest rivals. Unfortunately he is a racer and not a problem solver so he comes to you for help. Given the time each member of the two crews take to complete the race you have to figure out a way to arrange the matches so that Dominic can win maximum points possible for him. -----Input----- The first line of input is the T, the number of test cases. Each test case starts with a single number N, the number of racers on each crew. This is followed by two lines, each having N space separated integers containing the time taken by each member of Dominic's crew and the rival crew respectively. -----Output----- Output a single integer. The maximum number of points that Dominic can get. -----Constraints----- 1<=T<=100 1<=N<=100 Time taken by each member will be between 1 and 500 -----Example----- Input: 1 3 5 4 1 5 4 1 Output: 2 -----Explanation----- If Dom selects Racer 1 of his team to go against Racer 2 of the other team, Racer 2 of his team against Racer 3 of the other team and Racer 3 of his team against Racer 1 of the other team then he ends up with two wins and a loss which gives him 2 points. ... The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python testcases = int(input()) for i in range(testcases): n = int(input()) my = list(map(int,input().split())) opp = list(map(int,input().split())) my.sort(reverse = True) opp.sort(reverse = True) j = 0 k = 0 while(k < n): if(my[j] > opp[k]): j += 1 k += 1 print(j) ```
{ "language": "python", "test_cases": [ { "input": "1\n3\n5 4 1\n5 4 1\n", "output": "2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/EXCT2015/problems/RACEWARS" }
vfc_2270
false
false
false
false
false
apps
verifiable_code
858
Solve the following coding problem using the programming language python: For Diwali, Chef arranges all $K$ laddus in a row in his sweet shop. Whenever a customer comes to buy laddus, chef follows a rule that each customer must buy all laddus on odd position. After the selection of the laddu, a new row is formed, and again out of these only laddus on odd position are selected. This continues until the chef left with the last laddu. Find out the position of that last laddu in the original row. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, one integer $K$. -----Output:----- For each testcase, print the position of that laddu who is left, in the original row. -----Constraints----- - $1 \leq T \leq 10^5$ - $1 \leq K \leq 10^5$ -----Sample Input:----- 3 1 5 8 -----Sample Output:----- 1 4 8 -----EXPLANATION:----- For 1) Only one laddu which is last so print 1. For 2) Customer 1: [1, 3, 5] New row = [2, 4] Customer 2: [2] Last laddu = 4 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here t=int(input()) while t>0: n=int(input()) if n==1: print(1) else: c,num=1,2 while num<n: num*=2 if num==n: print(num) else: print(num//2) t-=1 ```
{ "language": "python", "test_cases": [ { "input": "3\n1\n5\n8\n", "output": "1\n4\n8\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PBK02020/problems/ITGUY11" }
vfc_2274
false
false
false
false
false
apps
verifiable_code
859
Solve the following coding problem using the programming language python: Voritex a big data scientist collected huge amount of big data having structure of two rows and n columns. Voritex is storing all the valid data for manipulations and pressing invalid command when data not satisfying the constraints. Voritex likes brute force method and he calls it as BT, he decided to run newly created BT engine for getting good result. At each instance when BT engine is outputting a newly created number Voritex calls it as BT number. Voritex is daydreaming and thinking that his engine is extremely optimised and will get an interview call in which he will be explaining the structure of BT engine and which will be staring from 1 and simultaneously performing $i$-th xor operation with $i$ and previously(one step before) obtained BT number. BT engine is outputting the $K$-th highest BT number in the first $N$ natural numbers. Chef : (thinking) I also want to create BT engine…….. -----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 line of each test case contains a two integers $N$ and $K$. -----Output:----- For each test case, print a single line containing integer $K$-th highest number else print -$1$ when invalid command pressed. -----Constraints----- - $1 \leq T \leq 100000$ - $1 \leq N \leq 100000$ - $1 \leq K \leq N$ -----Sample Input:----- 2 4 2 5 5 -----Sample Output:----- 2 0 -----EXPLANATION:----- For first valid constraints generating output as 0 2 1 5 1^1 first BT number is 0 2^0 second BT number is 2 3^2 third BT number is 1 4^1 fourth BT number is 5 Hence the answer is 2. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python import math import os import random import re import sys r = 100000 prev = 1 s = set() for i in range(1, r+1): now = i ^ prev s.add(now) prev = now s = list(s) t = int(input()) while t > 0: t -= 1 n, k = list(map(int, input().split())) if n > 3: if n % 2 == 0: size = (n//2) + 2 else: size = ((n-1)//2) + 2 else: size = n if size - k >= 0: print(s[size-k]) else: print(-1) ```
{ "language": "python", "test_cases": [ { "input": "2\n4 2\n5 5\n", "output": "2\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/CMYC2020/problems/BTENG" }
vfc_2278
false
false
false
false
false
apps
verifiable_code
860
Solve the following coding problem using the programming language python: Minion Chef likes to eat bananas a lot. There are N piles of bananas in front of Chef; for each i (1 ≤ i ≤ N), the i-th pile contains Ai bananas. Chef's mother wants her to eat the bananas and be healthy. She has gone to the office right now and will come back in H hours. Chef would like to make sure that she can finish eating all bananas by that time. Suppose Chef has an eating speed of K bananas per hour. Each hour, she will choose some pile of bananas. If this pile contains at least K bananas, then she will eat K bananas from it. Otherwise, she will simply eat the whole pile (and won't eat any more bananas during this hour). Chef likes to eat slowly, but still wants to finish eating all the bananas on time. Therefore, she would like to choose the minimum K such that she is able to eat all the bananas in H hours. Help Chef find that value of K. -----Input----- - The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. - The first line of each test case contains two space-separated integers N and H denoting the number of piles and the number of hours after which Chef's mom will come home. - The second line contains N space-separated integers A1, A2, ..., AN. -----Output----- For each test case, print a single line containing one integer — the minimum possible value of K. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N ≤ 105 - N ≤ H ≤ 109 - 1 ≤ Ai ≤ 109 for each valid i -----Subtasks----- Subtask #1 (30 points): - 1 ≤ N ≤ 100 - Ai ≤ 103 for each valid i Subtask #2 (70 points): original constraints -----Example----- Input: 3 3 3 1 2 3 3 4 1 2 3 4 5 4 3 2 7 Output: 3 2 4 -----Explanation----- Example case 1: With a speed of K = 3 bananas per hour, Chef can finish eating all the bananas in 3 hours. It's the minimum possible speed with which she can eat all the bananas in 3 hours. With a speed of 2 bananas per hour, she would take at least 4 hours and with a speed of 1 banana per hour, she would take at least 6 hours. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here import math T = int(input()) for _ in range(T): N, H = map(int, input().split()) A = list(map(int, input().split())) low, high = 1, max(A) while low != high: time = 0 mid = (low + high) // 2 for i in range(N): time += math.ceil(A[i] / mid) if time <= H : high = mid else: low = mid + 1 print(high) ```
{ "language": "python", "test_cases": [ { "input": "3\n3 3\n1 2 3\n3 4\n1 2 3\n4 5\n4 3 2 7\n", "output": "3\n2\n4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/MINEAT" }
vfc_2282
false
false
false
false
false
apps
verifiable_code
861
Solve the following coding problem using the programming language python: Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := fn-1 + fn-2 (n>=3) Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a,b]. -----Input----- The input contains several test cases. Each test case consists of two non-negative integer numbers a and b. Input is terminated by a=b=0. Otherwise, a<=b<=10^100. The numbers a and b are given with no superfluous leading zeros. -----Output----- For each test case output on a single line the number of Fibonacci numbers fi with a<=fi<=b. -----Example----- Input: 10 100 1234567890 9876543210 0 0 Output: 5 4 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python #!/usr/bin/env python F = [1,1] def fibo(): for i in range(500): F.append(F[-2] + F[-1]) def main(): fibo() #print len(str(F[-1])) #print len(str(10**100)) while True: try: A, B = list(map(int, input().strip().split()[:2])) if A == 0 and B == 0: break print(len([x for x in F if x >= A and x <= B])) except: break main() ```
{ "language": "python", "test_cases": [ { "input": "10 100\n1234567890 9876543210\n0 0\n", "output": "5\n4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PRFT2012/problems/PD32" }
vfc_2286
false
false
false
false
false
apps
verifiable_code
862
Solve the following coding problem using the programming language python: As we all know, Dhoni loves drinking milk. Once he and Sir Jadeja were invited in the inauguration of a Dairy company in Ranchi. The company had arranged n jars of milk from various breeds of cows , jar number i containing a[i] litres of milk. Since Dhoni loves driking milk more than Sir Jadeja, so Kohli suggested a plan for them. His plan was that each time Dhoni will choose a jar containing the maximum amount of milk. If this jar has less than k litres of milk or if Dhoni has already drunk more than m number of times from this jar, then the milk contained in the jar will be drunk by Sir Jadeja. Sir Jadeja will drink all the milk left in that jar. Otherwise Dhoni will drink exactly k litres of milk from the jar and put it back at its position. Dhoni will do so until he has given all jars to Sir Jadeja. You have to calculate how much milk Sir Jadega will get after Dhoni satisfies his hunger modulo 1,000,000,007. -----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 integer N , M, K denoting the number of milk jars, maximum number of time Dhoni will drink from any jar and maximum amount of milk Dhoni will drink at any time respectively. The second line contains N space-separated integers A1, A2, ..., AN denoting the amount of milk in each jar. -----Output----- - For each test case, output a single line containing the amount of milk Sir Jadega will get modulo 1,000,000,007. -----Constraints----- - 1 ≤ T ≤ 10 - 1 ≤ N ≤ 10^5 - 0 ≤ M ≤ 10^6 - 1 ≤ K ≤ 10^6 - 0 ≤ Ai ≤ 10^9 -----Example----- Input: 1 3 3 3 15 8 10 Output: 9 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python cases = int(input()) for case in range(cases): N, M, K = [int(i) for i in input().split()] A = [int(i) for i in input().split()] jad = 0 P = M*K for milk in A: if(milk>P): jad += milk-P else: jad += milk%K print(jad%1000000007) ```
{ "language": "python", "test_cases": [ { "input": "1\n3 3 3\n15 8 10\n", "output": "9\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/BITC2016/problems/DMILK" }
vfc_2290
false
false
false
false
false
apps
verifiable_code
863
Solve the following coding problem using the programming language python: The government has invited bids from contractors to run canteens at all railway stations. Contractors will be allowed to bid for the catering contract at more than one station. However, to avoid monopolistic price-fixing, the government has declared that no contractor may bid for a pair of neighbouring stations. The railway network has exactly one route between any pair of stations. Each station is directly connected by a railway line to at most $50$ neighbouring stations. To help contractors plan their bids, the government has provided data on the number of passengers who pass through each station each year. Contractors would like to bid for stations with a higher volume of passenger traffic to increase their turnover. For instance, suppose the railway network is as follows, where the volume of passenger traffic is indicated by the side of each station. In this network, the best option for the contractor is to bid for stations $1, 2, 5$ and $6$, for a total passenger volume of $90$. Your task is to choose a set of stations that the contractor should bid for so that the total volume of traffic across all the stations in the bid is maximized. -----Input:----- The first line of the input contains one integer $N$ indicating the number of railways stations in the network. The stations are numbered $1,2,...,N$. This is followed by $N$ lines of input, lines $2, 3,..., N+1$, indicating the volume of traffic at each station. The volume of traffic at station $i, 1 \leq i \leq N$, is given by a single integer in line $i+1$. The next $N-1$ lines of input, lines $N+2, N+3, ..., 2N$, describe the railway network. Each of these lines contains two integers, denoting a pair of stations that are neighbours. -----Output:----- The output should be a single integer, corresponding to the total volume of traffic across the set of stations in the optimal bid made by the contractor. -----Constraints:----- - $1 \leq N \leq 100000$. - Each railway station has at most $50$ neighbours. -----Sample Input----- 6 10 20 25 40 30 30 4 5 1 3 3 4 2 3 6 4 -----Sample Output----- 90 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()) l=[] dp=[] d={} for i in range(n): l.append(int(input())) d[i]=[] dp.append([0,0]) for i in range(n-1): a,b=list(map(int,input().split())) d[a-1].append(b-1) d[b-1].append(a-1) #print(l) #print(d) def dfs(ch,pa,visited): dp[ch][1]=l[ch] #print(dp[ch],ch+1) for i in range(len(d[ch])): if d[ch][i] not in visited: visited.add(d[ch][i]) dfs(d[ch][i],ch,visited) dp[ch][0]+=max(dp[d[ch][i]][0],dp[d[ch][i]][1]) dp[ch][1]+=dp[d[ch][i]][0] #print(ch+1,dp[ch]) v=set() v.add(0) dfs(0,-1,v) #print(dp) print(max(dp[0][0],dp[0][1])) ```
{ "language": "python", "test_cases": [ { "input": "6\n10\n20\n25\n40\n30\n30\n4 5\n1 3\n3 4\n2 3\n6 4\n", "output": "90\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/IARCSJUD/problems/CATERCON" }
vfc_2294
false
false
false
false
false
apps
verifiable_code
864
Solve the following coding problem using the programming language python: These days, chef is very much interested in Mathematics. He has started attending Recitations too! His hunger for problems is increasing day by day! Today, chef was a given a crumpled maths problem, which he is stuck with . He needs your help to do it Here's what his teacher said: "Find sum of all numbers till N, do not include numbers which are powers of K from K, K2, K3... which are less than or equal to N" Easy, right? Can you solve it? -----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 contains two integers N and K, as per the above given problem specification. -----OUTPUT----- For each test case, output a single line printing the sum of the each test case, in format Case #T: S, where T is the Tth test case running and S is sum of corresponding test case. -----CONSTRAINTS----- 10 < T < 50 10 < N < 104 0 < K < 100 -----EXAMPLE----- Input: 2 10 3 20 2 Output: Case #1: 43 Case #2: 180 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python testCases = int(input()) for c in range(testCases): n, k = list(map(int, input().split())) sum = 0 i = 0 power = 1 while i <= n: if k**power == i: power += 1 else: sum += i i +=1 answer = "Case #" + str(c + 1) + ": " + str(sum) print(answer) ```
{ "language": "python", "test_cases": [ { "input": "2\n10 3\n20 2\n", "output": "Case #1: 43\nCase #2: 180\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/GSTS1601/problems/BUG2K16E" }
vfc_2298
false
false
false
false
false
apps
verifiable_code
865
Solve the following coding problem using the programming language python: Given N, count how many permutations of [1, 2, 3, ..., N] satisfy the following property. Let P1, P2, ..., PN denote the permutation. The property we want to satisfy is that there exists an i between 2 and n-1 (inclusive) such that - Pj > Pj + 1 ∀ i ≤ j ≤ N - 1. - Pj > Pj - 1 ∀ 2 ≤ j ≤ i. -----Input----- First line contains T, the number of test cases. Each test case consists of N in one line. -----Output----- For each test case, output the answer modulo 109+7. -----Constraints----- - 1 ≤ T ≤ 100 - 1 ≤ N ≤ 109 -----Subtasks----- - Subtask #1(40 points): 1 ≤ N ≤ 1000 - Subtask #2(60 points): original constraints -----Example----- Input: 2 2 3 Output: 0 2 -----Explanation----- Test case 1: No permutation satisfies. Test case 2: Permutations [1, 3, 2] and [2, 3, 1] satisfy the property. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python try: for _ in range(int(input())): n = int(input()) print(0) if(n==1) else print(pow(2,n-1,10**9+7)-2) except EOFError: pass ```
{ "language": "python", "test_cases": [ { "input": "2\n2\n3\n", "output": "0\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CPERM" }
vfc_2302
false
false
false
false
false
apps
verifiable_code
866
Solve the following coding problem using the programming language python: There are n chef's in Chefland. There is a festival in Chefland in which each chef is asked to vote a person as his best friend. Obviously, a person can't vote himself as his best friend. Note that the best friend relationship is not necessarily bi-directional, i.e. it might be possible that x is best friend of y, but y is not a best friend of x. Devu was the election commissioner who conducted this voting. Unfortunately, he was sleeping during the voting time. So, he could not see the actual vote of each person, instead after the voting, he counted the number of votes of each person and found that number of votes of i-th person was equal to ci. Now he is wondering whether this distribution of votes corresponds to some actual voting or some fraudulent voting has happened. If the current distribution of votes does not correspond to any real voting, print -1. Otherwise, print any one of the possible voting which might have lead to the current distribution. If there are more than one possible ways of voting leading to the current distribution, you can print any one of them. -----Input----- - First line of the input contains a single integer T denoting number of test cases. - First line of each test case, contains a single integer n. - Second line of each test case, contains n space separated integers denoting array c. -----Output----- For each test case, - If there is no real voting corresponding to given distribution of votes, print -1 in a single line. - Otherwise, print n space separated integers denoting a possible voting leading to current distribution of votes. i-th integer should denote the index of the person (1 based indexing) whom i-th person has voted as his best friend. -----Constraints and Subtasks----- - 1 ≤ T ≤ 500 - 1 ≤ n ≤ 50 - 0 ≤ ci ≤ n -----Example----- Input: 3 3 1 1 1 3 3 0 0 3 2 2 0 Output: 2 3 1 -1 -1 -----Explanation----- Example 1: In this example, each person has received one vote. One possible example of real voting leading to this distribution is {2, 3, 1}. In this distribution, number of votes of all three persons are equal to 1. Also it is real voting because no person votes himself as his best friend. You can also output another possible distribution {3, 1, 2} too. Example 2: There is no real voting corresponding to this voting distribution. Example 3: There is no real voting corresponding to this voting distribution. 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): n=int(input()) l=list(map(int,input().split())) if sum(l)!=n or max(l)==n: print('-1') else: d=dict() ans=[-1]*n for i in range(0,n): d[i]=1 for i in range(n): if l[i]!=0: count=l[i] for k,v in list(d.items()): if count>0 and v==1 and i!=k: d[k]=0 ans[k]=i+1 count-=1 ind=-1 for i in range(0,len(ans)): if ans[i]==-1: ind=i if ind==-1: print(*ans) else: for i in range(len(ans)): if ans[i]!=ind+1: ans[ind]=ans[i] ans[i]=ind+1 break print(*ans) ```
{ "language": "python", "test_cases": [ { "input": "3\n3\n1 1 1\n3\n3 0 0\n3\n2 2 0\n", "output": "2 3 1\n-1\n-1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CHEFVOTE" }
vfc_2306
false
false
false
false
false
apps
verifiable_code
867
Solve the following coding problem using the programming language python: For her next karate demonstration, Ada will break some bricks. Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are W1,W2,W3. Ada's strength is S. Whenever she hits a stack of bricks, consider the largest k≥0 such that the sum of widths of the topmost k bricks does not exceed S; the topmost k bricks break and are removed from the stack. Before each hit, Ada may also decide to reverse the current stack of bricks, with no cost. Find the minimum number of hits Ada needs in order to break all bricks if she performs the reversals optimally. You are not required to minimise the number of reversals. Input The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows. The first and only line of each test case contains four space-separated integers S, W1, W2 and W3.Output For each test case, print a single line containing one integer ― the minimum required number of hits.Constraints - 1≤T≤64 - 1≤S≤8 - 1≤Wi≤2 for each valid i it is guaranteed that Ada can break all bricksExample Input 3 3 1 2 2 2 1 1 1 3 2 2 1 Example Output 2 2 2 Explanation Example case 1: Ada can reverse the stack and then hit it two times. Before the first hit, the widths of bricks in the stack (from top to bottom) are (2,2,1). After the first hit, the topmost brick breaks and the stack becomes (2,1). The second hit breaks both remaining bricks. In this particular case, it is also possible to hit the stack two times without reversing. Before the first hit, it is (1,2,2). The first hit breaks the two bricks at the top (so the stack becomes (2)) and the second hit breaks the last brick. 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): W = list(map(int, input().strip().split())) S = W[0] W = W[1:] W = W[::-1] i = 0 c = 0 flag = 0 while (len(W) != 0 or flag != 1) and i<len(W): k = i su = 0 while su <= S and k<len(W)-1: su += W[k] k += 1 if su-W[k-1]<=S: c += 1 else: flag = 1 i += 1 print(c-1) ```
{ "language": "python", "test_cases": [ { "input": "3\n3 1 2 2\n2 1 1 1\n3 2 2 1\n", "output": "2\n2\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/JLUG2020/problems/BRKTBRK" }
vfc_2310
false
false
false
false
false
apps
verifiable_code
868
Solve the following coding problem using the programming language python: "It does not matter how slowly you go as long as you do not stop." - Confucius You are given an array $A_1, A_2, \ldots, A_N$ and an integer $K$. For each subarray $S = [A_l, A_{l+1}, \ldots, A_r]$ ($1 \le l \le r \le N$): - Let's define an array $B$ as $S$ concatenated with itself $m$ times, where $m$ is the smallest integer such that $m(r-l+1) \ge K$. - Next, let's sort $B$ and define $X = B_K$, i.e. as a $K$-th smallest element of $B$. Note that $|B| \ge K$. - Then, let's define $F$ as the number of occurrences of $X$ in $S$. - The subarray $S$ is beautiful if $F$ occurs in $S$ at least once. Find the number of beautiful subarrays of $A$. Two subarrays $A_l, A_{l+1}, \ldots, A_r$ and $A_p, A_{p+1}, \ldots, A_q$ are different if $l \neq p$ or $r \neq q$. -----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 one integer - the number of beautiful subarrays. -----Constraints----- - $1 \le T \le 5$ - $1 \le N \le 2,000$ - $1 \le K \le 10^9$ - $1 \le A_i \le 2000$ for each valid $i$ -----Subtasks----- Subtask #1 (20 points): $1 \le N \le 200$ Subtask #2 (80 points): original constraints -----Example Input----- 1 3 3 1 2 3 -----Example Output----- 3 -----Explanation----- Example case 1: There are six subarrays of $A$: $[1]$, $[2]$, $[3]$, $[1, 2]$, $[2, 3]$, $[1, 2, 3]$. The corresponding arrays $B$ are $[1, 1, 1]$, $[2, 2, 2]$, $[3, 3, 3]$, $[1, 2, 1, 2]$, $[2, 3, 2, 3]$, $[1, 2, 3]$. Three of the subarrays are beautiful: $[1]$, $[1, 2]$ and $[1, 2, 3]$. For these subarrays, $X$ is $1$, $2$ and $3$ respectively (for example, for $S = [1, 2]$, $B = [1, 2, 1, 2]$ is sorted to $[1, 1, 2, 2]$ and $X = 2$ is the $3$-rd element). Then, $F = 1$ for each of these subarrays, and each of these subarrays contains $1$. 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 insort from math import ceil for _ in range(int(input())): n,k=list(map(int,input().split( ))) array=list(map(int,input().split( ))) ans=0 index=[] for i in range(1,n+1): index.append(ceil(k/(ceil(k/i)))) for i in range(n): count=[0]*(2001) temp=[] for j in range(i,n): count[array[j]]+=1 insort(temp,array[j]) #m=ceil(k/(j-i+1)) precalculate thes values in index array #t=ceil(k/m) x=temp[index[j-i]-1] f=count[x] if count[f]: ans+=1 print(ans) ```
{ "language": "python", "test_cases": [ { "input": "1\n3 3\n1 2 3\n", "output": "3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/SUBPRNJL" }
vfc_2314
false
false
false
false
false
apps
verifiable_code
869
Solve the following coding problem using the programming language python: The entire network is under the inspection and direct control of the Decepticons. They have learned our language through the World Wide Web and can easily understand the messages which are being sent. Sam is trying to send the information to Autobots to locate “ALL SPARK” which is the only source of energy that can be used to create universe. He is bit cautious in sending the message. He is sending the messages in a form of special pattern of string that contains important message in form of substrings. But Decepticons have learnt to recognize the Data Mining and string comparison patterns. He is sending a big message in form of a string (say M) and let there are N smaller substrings. Decepticons have to find whether each of these N substrings is a sub-string of M. All strings consist of only alphanumeric characters. -----Input----- Input to the program consists of two line. The first line contains the string M (where size of M should be <=40). The next line contain a string S. -----Output----- Output should consist of a line with a character 'Y'/'N' indicating whether the string S is a sub-string of String M or not. -----Example----- Input: techtrishna online event onlin Output: Y The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python x = input() y = input() z = x.find(y) if z == -1 : print('N') else : print('Y') ```
{ "language": "python", "test_cases": [ { "input": "techtrishna online event\nonlin\n", "output": "Y\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/TCTR2012/problems/NOPC1" }
vfc_2318
false
false
false
false
false
apps
verifiable_code
870
Solve the following coding problem using the programming language python: We say that a binary string (a string containing only characters '0' and '1') is pure if it does not contain either of the strings "0101" or "1010" as a subsequence. Recall that string T is a subsequence of string S if we can delete some of the letters of S (possibly none) such that the resulting string will become T. You are given a binary string $S$ with length $N$. We want to make this string pure by deleting some (possibly zero) characters from it. What is the minimum number of characters we have to delete? -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains a single string $S$ with length $N$. -----Output----- For each test case, print a single line containing one integer — the minimum number of characters we have to delete from $S$. -----Constraints----- - $1 \le T \le 40$ - $1 \le N \le 1,000$ - $S$ contains only characters '0' and '1' -----Example Input----- 4 010111101 1011100001011101 0110 111111 -----Example Output----- 2 3 0 0 -----Explanation----- Example case 1: We can delete the first and third character of our string. There is no way to make the string pure by deleting only one character. Example case 3: The given string is already pure, so the answer is zero. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here import math; from math import gcd,sqrt,floor,factorial,ceil from bisect import bisect_left,bisect_right import bisect; import sys; from sys import stdin,stdout import os sys.setrecursionlimit(pow(10,7)) import collections from collections import defaultdict,Counter from statistics import median # input=stdin.readline # print=stdout.write from queue import Queue inf = float("inf") from operator import neg; mod=pow(10,9)+7 def fun(l): m=[[l[0]]] for i in range(1,n): if m[-1][-1]==l[i]: m[-1]+=[l[i]] else: m.append([l[i]]) count=[] for i in range(len(m)): count.append(len(m[i])) return count; def function(l1,index,prev,count): tuple=(index,prev,count) if tuple in dict: return dict[tuple] n=len(l1) if index==n: return 0; if count>=3: if index%2==prev: dict[tuple]=function(l1,index+1,prev,count) return function(l1,index+1,prev,count) else: dict[tuple]=l1[index]+function(l1,index+1,prev,count); return dict[tuple] if prev==None: skip=l1[index]+function(l1,index+1,prev,count) not_skip=function(l1,index+1,index%2,count+1) maxa=min(skip,not_skip) dict[tuple]=maxa return maxa; if index%2==prev: dict[tuple]=function(l1,index+1,index%2,count) return dict[tuple] if index%2!=prev: skip=l1[index]+function(l1,index+1,prev,count) not_skip=function(l1,index+1,index%2,1+count) maxa = min(skip, not_skip) dict[tuple]=maxa return maxa; t=int(input()) for i in range(t): s=input() l=list(s) n=len(l) l=[int(i) for i in l] l1=fun(l) dict=defaultdict(int) theta=function(l1,0,None,0) print(theta) ```
{ "language": "python", "test_cases": [ { "input": "4\n010111101\n1011100001011101\n0110\n111111\n", "output": "2\n3\n0\n0\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/PRFYIT" }
vfc_2322
false
false
false
false
false
apps
verifiable_code
871
Solve the following coding problem using the programming language python: You are given a grid with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). Initially, each cell of this grid is either empty, contains an ant or an anteater. Each ant is moving in a fixed direction: up, down, left or right. The anteaters do not move. The movement of ants happens in discrete steps. For example, when an ant is in the cell in the $i$-th row and $j$-th column at some point in time (in some step) and it is moving down, then in the next step, it enters the cell in the $(i+1)$-th row and $j$-th column. Two ants meet each other when they enter the same cell at the same point in time (in the same step). When ants meet, they do not interact in any way and keep moving in their fixed directions. If an ant reaches an anteater, that anteater eats the ant, so the ant completely disappears. If an ant attempts to leave the grid, it also disappears. When two ants enter a cell containing an anteater at the same time, they are eaten before they could meet. Calculate the total number of pairs of ants that meet each other. -----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 $R$ and $C$. - Each of the following $R$ lines contains a single string with length $C$. For each valid $i, j$, the $j$-th character in the $i$-th string is: - '#' if the cell in the $i$-th row and $j$-th column of the grid contains an anteater - 'U', 'D', 'L' or 'R' if this cell contains an ant moving up, down, left or right respectively - '-' if this cell is empty -----Output----- For each test case, print a single line containing one integer — the number of pairs of ants that meet. -----Constraints----- - $1 \le T \le 10$ - $1 \le R, C \le 50$ - each string contains only characters 'U', 'D', 'L', 'R', '#' and '-' -----Example Input----- 10 3 3 R-- --- --U 1 4 R--R 2 2 -- -- 1 4 R--L 1 4 -R-L 1 4 -R#L 3 3 R-D -#- R-U 3 3 R-D --- R#U 3 3 -D- R-L -U- 1 7 RLLLLLL -----Example Output----- 1 0 0 0 1 0 3 2 6 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 t = int(input()) # print(t) for _ in range(t): n,m = map(int,input().split()); s = []; for i in range(n): s.append(input()) ans = [] for i in range(n): ans.append([]) for j in range(m): ans[i].append([]) for i in range(n): for j in range(m): c = 0 if s[i][j] == 'U': for k in range(i,-1,-1): if s[k][j] == '#': break ans[k][j].append(c) c+=1 elif s[i][j] == 'D': for k in range(i,n): if s[k][j] == '#': break ans[k][j].append(c) c+=1 elif s[i][j] == 'L': for k in range(j,-1,-1): if s[i][k] == '#': break ans[i][k].append(c) c+=1 elif s[i][j] == 'R': for k in range(j,m): if s[i][k] == '#': break ans[i][k].append(c) c+=1 for i in range(n): for j in range(m): ans[i][j].sort() res = [] for i in range(n): for j in range(m): c= 1 # print(ans[i][j]) for k in range(1,len(ans[i][j])): # print(ans[i][j][k]) if ans[i][j][k] == ans[i][j][k-1]: c+=1 else : if c!=1: res.append(c) c = 1 if k==len(ans[i][j])-1: if c!=1: res.append(c) pairs = 0 # print(res) for i in range(len(res)): pairs += ((res[i]*(res[i]-1))//2) print(pairs) ```
{ "language": "python", "test_cases": [ { "input": "10\n3 3\nR--\n---\n--U\n1 4\nR--R\n2 2\n--\n--\n1 4\nR--L\n1 4\n-R-L\n1 4\n-R#L\n3 3\nR-D\n-#-\nR-U\n3 3\nR-D\n---\nR#U\n3 3\n-D-\nR-L\n-U-\n1 7\nRLLLLLL\n\n", "output": "1\n0\n0\n0\n1\n0\n3\n2\n6\n3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/ANTEATER" }
vfc_2326
false
false
false
false
false
apps
verifiable_code
872
Solve the following coding problem using the programming language python: Appy and Chef are participating in a contest. There are $N$ problems in this contest; each problem has a unique problem code between $1$ and $N$ inclusive. Appy and Chef decided to split the problems to solve between them ― Appy should solve the problems whose problem codes are divisible by $A$ but not divisible by $B$, and Chef should solve the problems whose problem codes are divisible by $B$ but not divisible by $A$ (they decided to not solve the problems whose codes are divisible by both $A$ and $B$). To win, it is necessary to solve at least $K$ problems. You have to tell Appy whether they are going to win or lose. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains four space-separated integers $N$, $A$, $B$ and $K$. -----Output----- For each test case, print a single line containing the string "Win" if they can solve at least $K$ problems or "Lose" otherwise (without quotes). -----Constraints----- - $1 \le T \le 15$ - $1 \le K \le N \le 10^{18}$ - $1 \le A, B \le 10^9$ -----Subtasks----- Subtask #1 (15 points): - $1 \le T \le 15$ - $1 \le K \le N \le 10^6$ - $1 \le A, B \le 10^3$ Subtask #2 (85 points): original constraints -----Example Input----- 1 6 2 3 3 -----Example Output----- Win -----Explanation----- Example case 1: Appy is solving the problems with codes $2$ and $4$, Chef is solving the problem with code $3$. Nobody is solving problem $6$, since $6$ is divisible by both $2$ and $3$. Therefore, they can solve $3$ problems and win. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python for t in range(int(input())): n, a , b , k = map(int,input().split()) solvedbychef = 0 solvedbyappy = 0 for i in range(n+1): if i % a == 0 and i % b == 0 : continue elif i%a == 0 : solvedbyappy+=1 elif i%b == 0: solvedbychef+=1 totalsolved = solvedbychef + solvedbyappy if totalsolved>=k: print("Win") else : print("Lose") ```
{ "language": "python", "test_cases": [ { "input": "1\n6 2 3 3\n", "output": "Win\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/HMAPPY2" }
vfc_2330
false
false
false
false
false
apps
verifiable_code
873
Solve the following coding problem using the programming language python: The following graph G is called a Petersen graph and its vertices have been numbered from 0 to 9. Some letters have also been assigned to vertices of G, as can be seen from the following picture: Let's consider a walk W in graph G, which consists of L vertices W1, W2, ..., WL, such that Wi is connected with Wi + 1 for 1 ≤ i < L. A string S of L letters 'A'-'E' is realized by walk W if the sequence of letters written along W is equal to S. Vertices can be visited multiple times while walking along W. For example, S = 'ABBECCD' is realized by W = (0, 1, 6, 9, 7, 2, 3). Your task is to determine whether there is a walk W which realizes a given string S in graph G, and if so, find the lexicographically least such walk. -----Input----- The first line of the input contains one integer T denoting the number of testcases to process. The only line of each testcase contains one string S. It is guaranteed that S only consists of symbols 'A'-'E'. -----Output----- The output should contain exactly T lines, one line per each testcase in the order of their appearance. For each testcase, if there is no walk W which realizes S, then output -1. Otherwise, you should output the least lexicographical walk W which realizes S. Since all of the vertices are numbered from 0 to 9, then it can be encoded as a string consisting of symbols '0'-'9' (see the "Examples" section for more details). -----Constraints----- 1 ≤ T ≤ 8; 1 ≤ |S| ≤ 100000(105). -----Examples----- Input: 2 AAB AABE Output: 501 -1 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python let_to_num = {'A':[0,5], 'B':[1,6], 'C':[2,7], 'D':[3,8], 'E':[4,9]} num_to_let = {0:'A', 1:'B', 2:'C', 3:'D', 4:'E', 5:'A', 6:'B', 7:'C', 8:'D', 9:'E'} connections = {0:(1,4,5), 1:(0,2,6), 2:(1,3,7), 3:(2,4,8), 4:(0,3,9), 5:(0,7,8), 6:(1,8,9), 7:(2,5,9), 8:(3,5,6), 9:(4,6,7)} T = int(input()) for i in range(T): s = input() out_1, out_2= [],[] flag1, flag2 = True, True for c in range(len(s)): #print out_1, out_2, flag1, flag2 if c == 0: out_1.append(let_to_num[s[c]][0]) out_2.append(let_to_num[s[c]][1]) #print out_1, out_2, '\n' else: if flag1: conn_1 = set(connections[out_1[-1]]) to_conn_1 = set(let_to_num[s[c]]) if len(conn_1.intersection(to_conn_1))==0: flag1 = False else: out_1.extend(list(conn_1.intersection(to_conn_1))) #print 'out1',conn_1, to_conn_1, flag1, conn_1.intersection(to_conn_1) if flag2: conn_2 = set(connections[out_2[-1]]) to_conn_2 = set(let_to_num[s[c]]) if len(conn_2.intersection(to_conn_2))==0: flag2 = False else: out_2.extend(list(conn_2.intersection(to_conn_2))) #print 'out2', conn_2, to_conn_2, flag2, conn_2.intersection(to_conn_2) #print out_1, out_2, flag1, flag2, '\n' if (not flag1) and (not flag2): break if (not flag1) and (not flag2): print(-1) continue elif flag1 and (not flag2): print(''.join(str(k) for k in out_1)) continue elif flag2 and (not flag1): print(''.join(str(k) for k in out_2)) continue else: print(min(''.join(str(k) for k in out_1), ''.join(str(k) for k in out_2))) continue ```
{ "language": "python", "test_cases": [ { "input": "2\nAAB\nAABE\n\n\n", "output": "501\n-1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/COOK52/problems/PETERSEN" }
vfc_2334
false
false
false
false
false
apps
verifiable_code
874
Solve the following coding problem using the programming language python: ZCO is approaching, and you want to be well prepared! There are $N$ topics to cover and the $i^{th}$ topic takes $H_i$ hours to prepare (where $1 \le i \le N$). You have only $M$ days left to prepare, and you want to utilise this time wisely. You know that you can't spend more than $S$ hours in a day preparing, as you get tired after that. You don't want to study more than one topic in a day, and also, don't want to spend more than two days on any topic, as you feel that this is inefficient. Given these constraints, can you find the maximum number of topics you can prepare, if you choose the topics wisely? -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - The first line of each test case contains three space-separated integers: $N$, $M$ and $S$, denoting the number of topics, the number of days remaining and the number of hours you can study in a day. - The second line of each test case contains $N$ space-separated integers $H_i$, denoting the number of hours needed to prepare for the $i^{th}$ topic. -----Output:----- For each testcase, output in a single line: the maximum number of topics you can prepare. -----Constraints----- - $1 \leq T \leq 10$ - $1 \leq N \leq 10^5$ - $1 \leq M \leq 10^5$ - $1 \leq S \leq 16$ - $1 \leq H_i \leq 50$ -----Subtasks----- - 30 points : Every topic takes the same number of hours to prepare (i.e. all $H_i$ are equal). - 70 points : Original constraints. -----Sample Input:----- 2 5 4 10 10 24 30 19 40 5 4 16 7 16 35 10 15 -----Sample Output:----- 2 4 -----Explanation:----- Testcase 1: You can choose topics $1$ and $4$. Topic $1$ will consume a single day , while topic $4$ will consume two days. Thus, you'll be able to prepare these two topics within the 4 remaining days. But you can check that you cannot do any better. Testcase 2: You can choose topics $1$, $2$, $4$, and $5$. Each of them will consume one day each. Thus you'll be able to cover $4$ topics. 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()) for i in range(T): N,M,S=input().split() N=int(N) M=int(M) S=int(S) ls=list(map(int,input().split())) maxx=max(ls) if S<17 and maxx<=50: ls.sort() total_sum = M * S count = 0 sum = 0 for i in ls: if i / S > 2: continue else: sum = sum + math.ceil(i / S) * S if sum <= total_sum: count = count + 1 print(count) # cook your dish here ```
{ "language": "python", "test_cases": [ { "input": "2\n5 4 10\n10 24 30 19 40\n5 4 16\n7 16 35 10 15\n", "output": "2\n4\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/ZCOPREP" }
vfc_2338
false
false
false
false
false
apps
verifiable_code
875
Solve the following coding problem using the programming language python: Vanja and Miksi really like games. After playing one game for a long time, they decided to invent another game! In this game, they have a sequence $A_1, A_2, \dots, A_N$ and two numbers $Z_1$ and $Z_2$. The rules of the game are as follows: - The players take turns alternately, starting with Vanja. - There is an integer $S$; at the beginning, $S = 0$. - In each turn, the current player must choose an arbitrary element of $A$ and either add that number to $S$ or subtract it from $S$. Each element can be selected multiple times. - Afterwards, if $S = Z_1$ or $S = Z_2$, the current player (the player who made $S$ equal to $Z_1$ or $Z_2$) is the winner of the game. - If the game lasts for $10^{10}$ turns, Vanja and Miksi decide to declare it a tie. Can you help the boys determine the winner of the game? Please note that the game can end in a tie (if nobody can make $S = Z_1$ or $S = Z_2$ in the first $10^{10}$ moves). Both players play optimally, i.e. if there is a move which guarantees the current player's victory regardless of the other player's moves, the current player will make such a move. If the current player cannot win and there is a move which guarantees that the game will end in a tie, the current player will make such a move. -----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 three space-separated integers $N$, $Z_1$ and $Z_2$. - The second line contains $N$ space-separated integers $A_1, A_2, \dots, A_N$. -----Output----- - For each test case, print a single line containing one integer — the final result of the game: - $1$ if Vanja (the first player) has a winning strategy - $2$ if Miksi (the second player) has a winning strategy - $0$ if the game ends in a tie -----Constraints----- - $1 \le T \le 50$ - $1 \le N \le 50$ - $|Z_1|, |Z_2| \le 10^9$ - $|A_i| \le 10^9$ for each valid $i$ -----Subtasks----- Subtask #1 (25 points): $N = 2$ Subtask #2 (75 points): original constraints -----Example Input----- 3 2 6 4 -4 10 1 1 -1 2 2 0 7 3 4 -----Example Output----- 1 0 2 -----Explanation----- Example case 1: The first player can choose the value $A_1 = -4$, subtract it from $S = 0$ and obtain $S = - (-4) = 4 = Z_2$. The winner is the first player. Example case 2: It can be proven that neither player is able to reach $S = Z_1$ or $S = Z_2$. The result is a tie. 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 collections import defaultdict as dd from collections import deque from fractions import Fraction as f from copy import * from bisect import * from heapq import * from math import * from itertools import permutations def eprint(*args): print(*args, file=sys.stderr) zz=1 #sys.setrecursionlimit(10**6) if zz: input=sys.stdin.readline else: sys.stdin=open('input.txt', 'r') sys.stdout=open('all.txt','w') def li(): return [int(xx) for xx in input().split()] def fli(): return [float(x) for x in input().split()] def comp(a,b): if(a>b): return 2 return 2 if a==b else 0 def gi(): return [xx for x in input().split()] def fi(): return int(input()) def swap(a,i,j): a[i],a[j]=a[j],a[i] def si(): return list(input().rstrip()) def mi(): return map(int,input().split()) def gh(): sys.stdout.flush() def graph(n,m): for i in range(m): x,y=mi() a[x].append(y) a[y].append(x) def bo(i): return ord(i)-ord('a') t=fi() while t>0: t-=1 n,z1,z2=mi() d={} a=li() flag=0 for i in a: d[i]=1 d[-i]=1 if i==z1 or i==z2 or i==-z1 or i==-z2: flag=1 break if flag: print(1) continue for i in d: p=[i-z1,i-z2] c=1 for j in p: if j in d: c*=0 flag|=c print(0 if flag else 2) ```
{ "language": "python", "test_cases": [ { "input": "3\n2 6 4\n-4 10\n1 1 -1\n2\n2 0 7\n3 4\n", "output": "1\n0\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/JAGAM" }
vfc_2342
false
false
false
false
false
apps
verifiable_code
876
Solve the following coding problem using the programming language python: Rachel has some candies and she decided to distribute them among $N$ kids. The ith kid receives $A_i$ candies. The kids are happy iff the difference between the highest and lowest number of candies received is less than $X$. Find out if the children are happy or not. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - The first line contains $N$ and $X$. - The second line contains $N$ integers $A_1,A_2,...,A_N$. -----Output:----- For each test case print either "YES"(without quotes) if the kids are happy else "NO"(without quotes) -----Constraints----- - $1 \leq T \leq 100$ - $1 \leq N, X \leq 10^5$ - $1 \leq A_i \leq 10^5$ -----Sample Input:----- 2 5 6 3 5 6 8 1 3 10 5 2 9 -----Sample Output:----- NO YES -----EXPLANATION:----- - Example 1: Difference between maximum and minimum candies received is 8-1=7. 7 is greater than 6, therefore, the kids are not happy. 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 t1 in range(t): n,x=map(int,input().split()) a=list(map(int,input().split())) mx=max(a) mn=min(a) if (mx-mn<x): print("YES") else: print("NO") ```
{ "language": "python", "test_cases": [ { "input": "2\n5 6\n3 5 6 8 1\n3 10\n5 2 9\n", "output": "NO\nYES\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ENDE2020/problems/ENCDEC01" }
vfc_2346
false
false
false
false
false
apps
verifiable_code
877
Solve the following coding problem using the programming language python: A policeman wants to catch a thief. Both the policeman and the thief can only move on a line on integer coordinates between $0$ and $N$ (inclusive). Initially, the policeman is at a coordinate $x$ and the thief is at a coordinate $y$. During each second, each of them must move to the left or right (not necessarily both in the same direction) by distance $\textbf{exactly}$ equal to $K$. No one may go to the left of the coordinate $0$ or to the right of $N$. Both the policeman and the thief move simultaneously and they cannot meet while moving, only at the end of each second. Will the policeman be able to catch the thief if they both move optimally? The thief is caught as soon as the policeman and thief meet at the same position at the same time. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows. - The first and only line of each test case contains four space-separated integers $x$, $y$, $K$ and $N$. -----Output----- For each test case, print a single line containing the string "Yes" if the thief can be caught or "No" if the thief cannot be caught (without quotes). -----Constraints----- - $1 \le T \le 1,000$ - $1 \le N \le 10^9$ - $1 \le K \le N$ - $0 \le x, y \le N$ - $x \neq y$ -----Example Input----- 5 0 1 1 1 1 4 1 5 4 2 1 7 3 7 2 10 8 2 3 15 -----Example Output----- No No Yes Yes Yes -----Explanation----- Example case 1: The policeman is at $0$ and the thief is at $1$. After the $1$-st second, the policeman is at $1$ and the thief is at $0$. After the next second, the policeman is again at $0$ and the thief at $1$. They cannot end up at the same coordinate. 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, k, n = [int(x) for x in input().split()] k = k*2 temp = abs(x-y) if(temp%k == 0): print("Yes") else: print("No") ```
{ "language": "python", "test_cases": [ { "input": "5\n0 1 1 1\n1 4 1 5\n4 2 1 7\n3 7 2 10\n8 2 3 15\n", "output": "No\nNo\nYes\nYes\nYes\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CATHIEF" }
vfc_2350
false
false
false
false
false
apps
verifiable_code
878
Solve the following coding problem using the programming language python: There is a big staircase with $N$ steps (numbered $1$ through $N$) in ChefLand. Let's denote the height of the top of step $i$ by $h_i$. Chef Ada is currently under the staircase at height $0$ and she wants to reach the top of the staircase (the top of the last step). However, she can only jump from height $h_i$ to the top of a step at height $h_f$ if $h_f-h_i \le K$. To help Ada, we are going to construct some intermediate steps; each of them may be constructed between any two steps, or before the first step, and have any height. What is the minimum number of steps that need to be added to the staircase so that Ada could reach the top? -----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-seperated integers $h_1, h_2, \dots, h_N$. -----Output----- For each test case, print a single line containing one integer — the minimum required number of steps. -----Constraints----- - $1 \le T \le 64$ - $1 \le N \le 128$ - $1 \le K \le 1,024$ - $1 \le h_i \le 1,024$ for each valid $i$ - $h_i < h_{i+1}$ for each valid $i$ -----Example Input----- 1 4 3 2 4 8 16 -----Example Output----- 3 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here import numpy as np def minstairs(n,k): stairsHeight=[] stairs=0 current = 0 stairsHeight=list(map(int, input().split())) stairsHeight=np.array(stairsHeight) curr=0 for i in range(n): if stairsHeight[i]-curr<=k: curr=stairsHeight[i] else: if (stairsHeight[i]-curr)%k==0: stairs+=((stairsHeight[i]-curr)//k)-1 else: stairs+=(stairsHeight[i]-curr)//k curr=stairsHeight[i] return stairs T=int(input()) for i in range(T): n,k =list(map(int,input().split())) print(minstairs(n,k)) ```
{ "language": "python", "test_cases": [ { "input": "1\n4 3\n2 4 8 16\n", "output": "3\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/ADASTAIR" }
vfc_2354
false
false
false
false
false
apps
verifiable_code
879
Solve the following coding problem using the programming language python: There are $X$ people participating in a quiz competition and their IDs have been numbered from $1$ to $X$ (both inclusive). Beth needs to form a team among these $X$ participants. She has been given an integer $Y$. She can choose participants whose ID numbers are divisible by $Y$. Now that the team is formed, Beth wants to know the strength of her team. The strength of a team is the sum of all the last digits of the team members’ ID numbers. Can you help Beth in finding the strength of her team? -----Input:----- - The first line of the input contains a single integer $T$ denoting the number of test cases. $T$ lines follow - The first line of each test case contains $X$ and $Y$. -----Output:----- - For each test case print the strength of Beth's team -----Constraints----- - $1 \leq T \leq 1000$ - $1 \leq X,Y \leq 10^{20}$ -----Sample Input:----- 2 10 3 15 5 -----Sample Output:----- 18 10 -----EXPLANATION:----- - Example case 1: ID numbers divisible by 3 are 3,6,9 and the sum of the last digits are 3+6+9=18 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())): x, y = map(int, input().split()) ans = 0 for i in range(y, x+1, y): if i%y == 0: ans += i%10 print(ans) ```
{ "language": "python", "test_cases": [ { "input": "2\n10 3\n15 5\n", "output": "18\n10\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/ENDE2020/problems/ENCDEC04" }
vfc_2358
false
false
false
false
false
apps
verifiable_code
880
Solve the following coding problem using the programming language python: Tracy loves Donuts. She purchased a lots of Donuts for her birthday party. She learnt to calculate the area of the circle a few days back and she is fascinated to know the area of the donuts as well !! Help her finding the area of the Donuts….. -----Input:----- - First line will contain, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, where in you have to provide the RADIUS of the Donuts. -----Output:----- For each testcase, output in a single line answer is the AREA of the Donut. -----Constraints----- 1 <= Radius <= 20. -----Sample Input:----- 2 5 12 -----Sample Output:----- 78.5 452.16 The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python oo = int(input()) for i in range(oo): val = int(input()) print((val**2)*3.14) ```
{ "language": "python", "test_cases": [ { "input": "2\n5\n12\n", "output": "78.5\n452.16\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SPNT2020/problems/AODLS001" }
vfc_2362
false
false
false
false
false
apps
verifiable_code
881
Solve the following coding problem using the programming language python: Given an array $A_1, A_2, ..., A_N$, count the number of subarrays of array $A$ which are non-decreasing. A subarray $A[i, j]$, where $1 ≤ i ≤ j ≤ N$ is a sequence of integers $A_i, A_i+1, ..., A_j$. A subarray $A[i, j]$ is non-decreasing if $A_i ≤ A_i+1 ≤ A_i+2 ≤ ... ≤ A_j$. You have to count the total number of such subarrays. -----Input----- - The first line of 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 a single integer $N$ denoting the size of array. - The second line contains $N$ space-separated integers $A_1$, $A_2$, …, $A_N$ denoting the elements of the array. -----Output----- For each test case, output in a single line the required answer. -----Constraints----- - $1 ≤ T ≤ 5$ - $1 ≤ N ≤ 10^5$ - $1 ≤ A_i ≤ 10^9$ -----Subtasks----- - Subtask 1 (20 points) : $1 ≤ N ≤ 100$ - Subtask 2 (30 points) : $1 ≤ N ≤ 1000$ - Subtask 3 (50 points) : Original constraints -----Sample Input:----- 2 4 1 4 2 3 1 5 -----Sample Output:----- 6 1 -----Explanation----- Example case 1. All valid subarrays are $A[1, 1], A[1, 2], A[2, 2], A[3, 3], A[3, 4], A[4, 4]$. Note that singleton subarrays are identically non-decreasing. Example case 2. Only single subarray $A[1, 1]$ is non-decreasing. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python # cook your dish here t=int(input()) for i in range(t): n=int(input()) ar=list(map(int,input().split())) tot=0 st=0 for j in range(1,n): if(ar[j-1]>ar[j]): si=j-st c=(si*(si+1))//2 tot+=c st=j si=n-st c=(si*(si+1))//2 tot+=c print(tot) ```
{ "language": "python", "test_cases": [ { "input": "2\n4\n1 4 2 3\n1\n5\n", "output": "6\n1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/SUBINC" }
vfc_2366
false
false
false
false
false
apps
verifiable_code
882
Solve the following coding problem using the programming language python: As we all know, Chef is cooking string for long days, his new discovery on string is the longest common pattern length. The longest common pattern length between two strings is the maximum number of characters that both strings have in common. Characters are case sensitive, that is, lower case and upper case characters are considered as different. Note that characters can repeat in a string and a character might have one or more occurrence in common between two strings. For example, if Chef has two strings A = "Codechef" and B = "elfedcc", then the longest common pattern length of A and B is 5 (common characters are c, d, e, e, f). Chef wants to test you with the problem described above. He will give you two strings of Latin alphabets and digits, return him the longest common pattern length. -----Input----- The first line of the input contains an integer T, denoting the number of test cases. Then the description of T test cases follows. The first line of each test case contains a string A. The next line contains another character string B. -----Output----- For each test case, output a single line containing a single integer, the longest common pattern length between A and B. -----Constraints----- - 1 ≤ T ≤ 100 - 1 ≤ |A|, |B| ≤ 10000 (104), where |S| denotes the length of the string S - Both of A and B can contain only alphabet characters (both lower and upper case) and digits -----Example----- Input: 4 abcd xyz abcd bcda aabc acaa Codechef elfedcc Output: 0 4 3 5 -----Explanation----- Example case 1. There is no common character. Example case 2. All the characters are same. Example case 3. Three characters (a, a and c) are same. Example case 4. This sample is mentioned by the statement. 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 def solve(A,B): a = Counter(A) b = Counter(B) ans = 0 for i in a: if i in b: ans += min(a[i],b[i]) return ans t = int(input()) for _ in range(t): A = input() B = input() print(solve(A,B)) ```
{ "language": "python", "test_cases": [ { "input": "4\nabcd\nxyz\nabcd\nbcda\naabc\nacaa\nCodechef\nelfedcc\n\n\n", "output": "0\n4\n3\n5\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/LCPESY" }
vfc_2370
false
false
false
false
false
apps
verifiable_code
883
Solve the following coding problem using the programming language python: It's year 2018 and it's Christmas time! Before going for vacations, students of Hogwarts School of Witchcraft and Wizardry had their end semester exams. $N$ students attended the semester exam. Once the exam was over, their results were displayed as either "Pass" or "Fail" behind their magic jacket which they wore. A student cannot see his/her result but can see everyone else's results. Each of $N$ students count the number of passed students they can see. Given the number of "Pass" verdicts that each of the $N$ students counted, we have to figure out conclusively, the number of students who failed, or report that there is some inconsistency or that we cannot be sure. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - The first line of each test case will contain $N$, representing the number of students who attended the exam. - Next line contains $N$ spaced integers representing the number of "Pass" counted by each of the $N$ students. -----Output:----- - For each test case, output the answer in a single line. - If the counts reported by the students are not consistent with each other or if it's not possible to predict the number of failed students from the given input, then print -1. -----Constraints----- - $1 \leq T \leq 50$ - $1 \leq N \leq 10^{5}$ - $0 \leq$ Count given by each Student $\leq 10^{5}$ -----Sample Input:----- 1 4 3 2 2 2 -----Sample Output:----- 1 -----EXPLANATION:----- There are 4 students, and they counted the number of passed students as 3,2,2,2. The first student can see that all others have passed, and all other students can see only 2 students who have passed. Hence, the first student must have failed, and others have all passed. Hence, the answer is 1. 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())) s = set(a) if n == 1 or len(s) > 2: print(-1) continue if len(s) == 1: x = s.pop() if x == 0: print(n) elif x == n-1: print(0) else: print(-1) continue x, y = sorted(s) xc, yc = a.count(x), a.count(y) if xc == y and xc == x + 1: print(yc) else: print(-1) ```
{ "language": "python", "test_cases": [ { "input": "1\n4\n3 2 2 2\n", "output": "1\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/problems/CNTFAIL" }
vfc_2374
false
false
false
false
false
apps
verifiable_code
884
Solve the following coding problem using the programming language python: Write a program that reads two numbers $X$ and $K$. The program first finds the factors of $X$ and then gives the sum of $K$th power of every factor. The program also finds the factor of $k$ and outputs the sum of $X$ times of every factor. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains of a single line of input, two integers $X, R$. -----Output:----- For each testcase, output in a single line the factors of $X$ and the $K$th power of every factor, seperated by a space. -----Constraints----- - $1 \leq T \leq 1000$ - $2 \leq X, K \leq 10^9$ -----Sample Input:----- 1 8 6 -----Sample Output:----- 266304 88 -----EXPLANATION:----- Factors of x = 8 are 2, 4, and 8. Also, factors of k = 6 are 2, 3, and 6. 2^6 + 4^6 + 8^6 = 266304 and 2 × 8 + 3 × 8 + 6 × 8 = 88. (Where a ^b denotes a raised to the power of b). The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python try: for _ in range(int(input())): s,s1=0,0 x,k=[int(i) for i in input().split()] for i in range(2,x+1): if(x%i==0): s=s+i**k for i in range(2,k+1): if(k%i==0): s1+=i*x print(s,s1) except EOFError as e: pass ```
{ "language": "python", "test_cases": [ { "input": "1\n8 6\n", "output": "266304 88\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/SITC2020/problems/FACPOW" }
vfc_2378
false
false
false
false
false
apps
verifiable_code
885
Solve the following coding problem using the programming language python: Chef solved so many hard questions, now he wants to solve some easy problems for refreshment. Chef asks Cheffina for the new question. Cheffina challenges the chef to print the total number of 0's in the binary representation of N(natural number). -----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, $N$. -----Output:----- For each test case, output in a single line answer. -----Constraints----- - $1 \leq T \leq 10^6$ - $1 \leq N \leq 10^6$ -----Sample Input:----- 2 2 4 -----Sample Output:----- 1 2 -----EXPLANATION:----- For 1) Binary representation of 2 is 10. i.e. only one 0 present in it. For 2) Binary representation of 4 is 100, i.e. two 0's present in it. The input will be stdin and you should print your solution to stdout Now solve the problem and return the code.
```python from sys import stdin, stdout input = stdin.readline from collections import defaultdict as dd import math def geti(): return list(map(int, input().strip().split())) def getl(): return list(map(int, input().strip().split())) def gets(): return input() def geta(): return int(input()) def print_s(s): stdout.write(s+'\n') def solve(): for _ in range(geta()): n=geta() n=bin(n).split('b')[1] print(n.count('0')) def __starting_point(): solve() __starting_point() ```
{ "language": "python", "test_cases": [ { "input": "2\n2\n4\n", "output": "1\n2\n", "type": "stdin_stdout" } ] }
{ "difficulty": "interview", "problem_url": "https://www.codechef.com/PBK32020/problems/ITGUY31" }
vfc_2382
false
false
false
false
false