problem_id
stringlengths
32
32
name
stringclasses
1 value
problem
stringlengths
200
14k
solutions
stringlengths
12
1.12M
test_cases
stringlengths
37
74M
difficulty
stringclasses
3 values
language
stringclasses
1 value
source
stringclasses
7 values
num_solutions
int64
12
1.12M
starter_code
stringlengths
0
956
f83b5f546ab2c143f0230070b38b61ca
UNKNOWN
You are given an array of N integers a1, a2, ..., aN and an integer K. Find the number of such unordered pairs {i, j} that - i ≠ j - |ai + aj - K| is minimal possible Output the minimal possible value of |ai + aj - K| (where i ≠ j) and the number of such pairs for the given array and the integer K. -----Input-----...
["for _ in range(int(input())):\n n,k=list(map(int, input().split()))\n l=list(map(int, input().split()))\n l.sort()\n \n c=0\n mn=abs(l[0]+l[1]-k)\n for i in range(n-1):\n for j in range(i+1, n):\n temp=abs(l[i]+l[j]-k)\n if temp==mn:\n c+=1 \n \n elif temp<mn:\n mn=temp\n c=1 \n \n elif l[i]+l...
{"inputs": [["1", "4 9", "4 4 2 6"]], "outputs": [["1 4"]]}
INTERVIEW
PYTHON3
CODECHEF
8,328
96e6ffa9833fa0e9fb81b5c8a98a4159
UNKNOWN
Mr. Wire Less is not that good at implementing circuit in a breadboard. In his Digital Logic Design course, he has to implement several boolean functions using the breadboard. In a breadboard, inputs are given through the switches and outputs are taken through the LEDs. Each input switch can be either in ground state o...
["# cook your dish here\nmod=8589934592\nlist1=[]\nfor i in range(int(input())):\n x=int(input())\n ans=(pow(2,x,mod)-1)%mod\n list1.append((i+1,ans))\nfor i in list1:\n print(f'Case {i[0]}: {i[1]}')", "# cook your dish here\nfor i in range(int(input())):\n x=int(input())\n ans=(pow(2, x, 8589934592)-...
{"inputs": [["2", "1", "2", "", ""]], "outputs": [["Case 1: 1", "Case 2: 3"]]}
INTERVIEW
PYTHON3
CODECHEF
2,800
de0528d65c08aa3a3deb867457a48629
UNKNOWN
An even sequence has the following property: each maximal contiguous subsequence which contains only equal integers (i.e. the same integer repeated a number of times) has an even length. In particular, the empty sequence is even. A subsequence is maximal if it is not contained in a larger contiguous subsequence which c...
["'''Author- Akshit Monga'''\nfrom sys import stdin, stdout\ninput = stdin.readline\nt=int(input())\nfor _ in range(t):\n n=int(input())\n a=[int(x) for x in input().split()]\n ans=0\n dp=[-1 for i in range(0,n+1)]\n for i in a:\n var1=dp[i]\n var2=ans\n ans=max(ans,var1+1)\n dp[i]=max(dp[i],var2+1)\n print(n-ans)"...
{"inputs": [["2", "4", "1 1 2 1", "11", "2 2 2 10 2 10 1 1 5 3 5"]], "outputs": [["2", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
11,645
20c8162c831c151dce0c0c0c7401cea6
UNKNOWN
You are teaching a class of $N$ students. Today, during the morning prayer, all the students are standing in a line. You are given a string $s$ with length $N$; for each valid $i$, the $i$-th character of this string is 'b' if the $i$-th student in the line is a boy or 'g' if this student is a girl. The awkwardness of ...
["from collections import Counter \nfor _ in range(int(input())):\n s = input()\n c = Counter(list(s))\n if len(c) == 1:\n print(0)\n else:\n m = min(c['b'], c['g'])\n ma = max(c['b'], c['g'])\n l = (ma - m + 1) // 2\n r = (ma - m + 1) // 2 + (ma - m + 1) % 2\n res = (l * (l + 1)) // 2\n re = res\n for i in ran...
{"inputs": [["3", "gb", "bgg", "bbgg"]], "outputs": [["1", "2", "6"]]}
INTERVIEW
PYTHON3
CODECHEF
4,463
d1832e9a097df69b31b13a64cdfd3cd0
UNKNOWN
Doctor Kunj installed new software on cyborg Shresth. This software introduced Shresth to range minimum queries. Cyborg Shresth thought of T$T$ different problems in each of which you will be given an array A$A$ of length N$N$ and an array B$B$ of length M$M$. In each of these problems, you have to calculate: ∑mi=1∑mj=...
["def f(a,n):\n l,r,s1,s2 = [0]*n, [0]*n, [], []\n \n for i in range(n):\n count = 1\n while(len(s1)>0 and a[i]<s1[-1][0]):\n count += s1[-1][1]\n s1.pop()\n s1.append((a[i],count))\n l[i] = count\n \n for i in range(n-1,-1,-1):\n count = 1\n while(len(s2)>0 and a[i]<=s2[-1][0...
{"inputs": [["1", "7 3", "10 3 7 9 1 19 2", "1 4 6"]], "outputs": [["43"]]}
INTERVIEW
PYTHON3
CODECHEF
529
e894066c45ced4f03584f305bdb6f6fc
UNKNOWN
Chef has three baskets and two of them have multiple balls(Natural numbers written on them). The first basket has N balls, the second basket has M balls and the third basket is empty. Chef starts choosing all the unique balls(only occurring once in both the baskets) and puts into the third basket and throw the repetiti...
["t = int(input())\nfor i in range(t):\n n, m = map(int, input().split())\n arr1 = list(map(int, input().split()))\n arr2 = list(map(int, input().split()))\n hmap = {}\n for i in range(n):\n if arr1[i] in hmap:\n hmap[arr1[i]] += 1\n else:\n hmap[arr1[i]] = 1\n \n ...
{"inputs": [["1", "4 5", "1 2 3 4", "2 3 4 5 6"]], "outputs": [["1 5 6"]]}
INTERVIEW
PYTHON3
CODECHEF
11,174
6767afba6b247becb253ed84f5b9993a
UNKNOWN
Like all minions Dave also like to eat bananas. So as to his obsession, he is eating banana, but this time in different way. There are N bananas in dish. Dave wants to eat all of them. He starts eating at speed 1 banana/second. He can increase or decrease speed of eating by one only. The condition is that he must end e...
["t=int(input())\nwhile(t):\n k=1\n j=0\n n=int(input())\n while(n>0):\n if(n<=k):\n j+=1\n n=0\n elif n>2*k:\n j+=2\n n=n-2*k\n k+=1\n else:\n j+=2\n n=0\n print(j)\n t-=1", "import math\nfor t in range(int(input())):\n n=int(input())\n x=math.sqrt(n)-1\n print(int(math.ceil(2*x+1)))\n"]
{"inputs": [["2", "2", "4"]], "outputs": [["2", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
306
eecfba00bc4c4240d2ca1d51b37a97d9
UNKNOWN
Given an empty array A of infinite length and a positive integer K you have to process Q queries of type: - ! l r x: Fill the value x in all the empty places in the array from index l to r (both inclusive). - ? l r: Print the number of prime factors of K which is also a prime factor of at least one number in A[l]...
["# cook your dish here\n# cook your dish here\n\nimport math\ndef distinctPrimeFactors(num) :\n primes,sqrt = set(),int(math.sqrt(num))\n if (num == 2) :primes.add(num)\n for j in range(2, sqrt + 1) :\n if (num % j == 0) :\n primes.add(j)\n while (num % j == 0) :num //= j\n if ...
{"inputs": [["20 5", "? 1 5", "! 3 5 4", "? 1 5", "! 1 4 15", "? 1 5"]], "outputs": [["0", "1", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
30,934
8271a5528d1de3f103d7fd99bc642a9d
UNKNOWN
Petr is organizing Petr Mitrichev Contest #11. The top N coders according to codechef ratings (excluding Petr himself) agreed to participate in the contest. The participants have been ranked from 0 to N-1 according to their ratings. Petr had asked each participant to choose a coder with rating higher than himself/ hers...
["import math\ndef comb(n,r):\n f = math.factorial\n return f(n) / f(r) / f(n-r)\nt=int(input())\nfor i in range(1,t+1):\n n=int(input())\n arr = list(map(int, input().split()))\n m=0\n ans=0.0\n for i in range(0,n):\n if (arr[i]==-1):\n m=m+1\n for i in range(0,m):\n ans=ans+((m-i)*comb(m-1,m-1-i))\n ans=ans/pow(2...
{"inputs": [["1", "5", "-1 -1 1 2 1"]], "outputs": [["1.5"]]}
INTERVIEW
PYTHON3
CODECHEF
358
67908517ae004ddd592a92dba2375ab1
UNKNOWN
Today is Chocolate day and Kabir and Tara are visiting a Valentine fair. Upon arriving, they find a stall with an interesting game. There are N$N$ jars having some chocolates in them. To win the game, one has to select the maximum number of consecutive jars such that the sum of count of chocolates in maximum and second...
["# cook your dish here\nfor u in range(int(input())):\n n,r=list(map(int,input().split()))\n l=list(map(int,input().split()))\n m=0\n for i in range(n-1):\n d=[]\n d.append(l[i])\n c=1\n while(i+c<n):\n d.append(l[i+c])\n d.sort(reverse=True)\n i...
{"inputs": [["1", "6 5", "1 3 3 1 1 5"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
1,731
12ae47c0fc9825d6d44254e2b4b1a7de
UNKNOWN
Mohit(Ex GenSec ) is the most active member of the roasting club who loves giving tasks to other members. One day he observed that none of the members were paying attention to the online classes, so he decided to have some fun and overcome the boring lectures. He wrote N numbers on the virtual board (where the first nu...
["n, m = map(int, input().split())\nl = n\nf = 1\ns = ((n)*(n+1))//2 - l - f\nfor _ in range(m):\n k = int(input())\n if 2 <= k <= n-1 or k in [f, l]:\n l, f = f, l\n else:\n l = k\n print(s+l+f)", "# cook your dish here\n\nn,m=tuple(map(int,input().split()))\nif(n>2):\n arr=[1,n]\nelif(n==1):\n arr=[1]\nelif(n==2):\...
{"inputs": [["5 4", "7", "12", "10", "1"]], "outputs": [["17", "22", "20", "20"]]}
INTERVIEW
PYTHON3
CODECHEF
3,728
65d80708aa6cd312f3cc20f2681198b5
UNKNOWN
Being a crewmate in the Among Us game, you will have to solve a task to win against the imposter. The task : You are given a certain number of bulbs(Say n) which are initially in OFF position. The bulbs are numbered from 1 to n. There will be n current fluctuations in such a way that in the 1st fluctuation all bulbs ...
["import math\r\ndef CountSquares(a, b):\r\n return (math.floor(math.sqrt(b)) - math.ceil(math.sqrt(a)) + 1)\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n val=CountSquares(1,n)\r\n ans=val-val//3\r\n print(ans)", "import math\r\ndef CountSquares(a, b):\r\n return (math.floor(math.sqrt(b)) - ...
{"inputs": [["2", "2", "20"]], "outputs": [["1", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
4,297
97ab1bf11d4733b9f82699f66b1aec9b
UNKNOWN
You are given a tree with $N$ vertices (numbered $1$ through $N$) and a bag with $N$ markers. There is an integer written on each marker; each of these integers is $0$, $1$ or $2$. You must assign exactly one marker to each vertex. Let's define the unattractiveness of the resulting tree as the maximum absolute differen...
["# cook your dish here\nimport numpy as np\ntests = int(input())\nfor _ in range(tests):\n n = int(input())\n weights = [int(j) for j in input().split()]\n edges = [[0] for _ in range(n-1)]\n for i in range(n-1):\n edges[i] = [int(j)-1 for j in input().split()]\n vertex_set = [[] for _ in range(n)]\n ...
{"inputs": [["3", "3", "0 1 1", "1 2", "1 3", "3", "0 1 2", "1 2", "1 3", "4", "2 2 2 2", "1 2", "1 3", "3 4"]], "outputs": [["1", "1", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
1,744
782bbcceae425e75a696f1a35ad1e8ee
UNKNOWN
Consider the following $4 \times 4$ pattern: 1 2 4 7 3 5 8 11 6 9 12 14 10 13 15 16 You are given an integer $N$. Print the $N \times N$ pattern of the same kind (containing integers $1$ through $N^2$). -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases...
["for i in range(int(input())):\n t=int(input())\n n=0\n for i in range(1,t+1):\n n=n+i\n x=[n]\n y=n\n for j in range(i,t+i-1):\n if j<t:\n z=y+j\n else:\n z=y+(2*t-j-1)\n x.append(z)\n y=z\n print(*x)", "for i in range(int(input())):\n n=int(input())\n t=0\n for i in range(1,n+1):\n t=t+i\n m=[t]...
{"inputs": [["1", "4"]], "outputs": [["1 2 4 7", "3 5 8 11", "6 9 12 14", "10 13 15 16"]]}
INTERVIEW
PYTHON3
CODECHEF
9,654
41191c5f3fac1662f1d9a55c5f8039de
UNKNOWN
One day, Delta, the dog, got very angry. He has $N$ items with different values, and he decided to destroy a few of them. However, Delta loves his hooman as well. So he only destroyed those items whose Least Significant Bit in binary representation is 0. Can you help Delta to find the total damage he did so he could m...
["# cook your dish here\nfor test in range(int(input())):\n n = int(input())\n ar = list(map(int, input().split()))\n \n count = 0\n for item in ar:\n if bin(item)[-1] == '0':\n count += item\n \n print(count)", "def bit(x):\n s=0\n for i in range(len(x)):\n p=bool((x...
{"inputs": [["1", "5", "1 2 3 4 5"]], "outputs": [["6"]]}
INTERVIEW
PYTHON3
CODECHEF
6,414
dc2018a216a750432ba6e970911348f0
UNKNOWN
There are two friends Alice and Bob. They have a packet of $n$ candies. They want to split the candies between them, and to do so, they kept them all in a single line. The $i^{\text{th}}$ candy in the line has a sweetness value of $a_i$. They decided to take turns in picking the candies. Alice has the first turn. In a ...
["from sys import setrecursionlimit\nsetrecursionlimit(10 ** 9)\n\ndef solve(i, j, c=0):\n if i > j:\n return 0\n\n if (i, j) in dp:\n return dp[i, j]\n\n x0 = solve(i+1, j, c^1)\n x1 = solve(i, j-1, c^1)\n\n if c == 0:\n y = 1 << (j - i)\n x0 += a[i] * y\n x1 += a[j] * y\n\n dp[i, j] = x0 + x1\n return dp[i, j]\n...
{"inputs": [["2", "2", "1 2", "3", "1 2 3"]], "outputs": [["1.500000000000000", "4.000000000000000"]]}
INTERVIEW
PYTHON3
CODECHEF
2,403
10d18eb004894cca601418625ee999f4
UNKNOWN
Chef develops his own computer program for playing chess. He is at the very beginning. At first he needs to write the module that will receive moves written by the players and analyze it. The module will receive a string and it should report at first whether this string represents the correct pair of cells on the chess...
["#!/usr/bin/env python2\n \ndef gc(c):\n return 'a' <= c <= 'h'\ndef gd(c):\n return '1' <= c <= '8'\n \nt = int(input())\nfor i in range(t):\n line = input()\n if len(line) != 5:\n print(\"Error\")\n continue\n if line[2] != '-':\n print(\"Error\")\n continue\n x1 = line[0]\n y1 = line[1]\n x2 = l...
{"inputs": [["4", "a1-b3", "d2-h8", "a3 c4", "ErrorError"]], "outputs": [["Yes", "No", "Error", "Error"]]}
INTERVIEW
PYTHON3
CODECHEF
1,169
ac21f99eb9db50f859db79ab697698a9
UNKNOWN
Given a triplet of integers (X , Y , Z), such that X ≤ Y and Y ≥ Z, we define f(X , Y , Z) to be (X + Y) * (Y + Z). If either X > Y or Y < Z, or both, then f(X , Y , Z) is defined to be 0. You are provided three arrays A , B and C of any length (their lengths may or may not be equal). Your task is to find the sum ...
["T=int(input()) # cook your dish here\nfor i in range(T): \n n=list(map(int,input().split()))\n a=n[0]\n b=n[1]\n c=n[2]\n l=[]\n A=list(map(int,input().split()))\n B=list(map(int,input().split()))\n C=list(map(int,input().split()))\n for i in range(b):\n for j in range(a):\n ...
{"inputs": [["1 ", "3 1 3", "1 2 3", "5", "4 5 6", "", ""]], "outputs": [["399"]]}
INTERVIEW
PYTHON3
CODECHEF
15,331
b534d6c3e80d19d1adc6bf54979f8323
UNKNOWN
Chef Two and Chef Ten are playing a game with a number $X$. In one turn, they can multiply $X$ by $2$. The goal of the game is to make $X$ divisible by $10$. Help the Chefs find the smallest number of turns necessary to win the game (it may be possible to win in zero turns) or determine that it is impossible. -----Inp...
["# cook your dish here\nt=int(input())\nfor i in range(t):\n x=int(input())\n if x%10==0:\n print(0)\n elif x%5==0:\n print(1)\n else:\n print(-1)", "t=int(input())\nfor i in range(t):\n n=int(input())\n if n%10==0:\n print(0)\n elif n%5==0:\n print(1)\n else: \n print(-1)\n \n", "# cook your dish here\nb=int(i...
{"inputs": [["3", "10", "25", "1"]], "outputs": [["0", "1", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
3,962
7d99c1728996f58a5e6dda8c118b7e3c
UNKNOWN
Chef Ada has a matrix with $N$ rows (numbered $1$ through $N$ from top to bottom) and $N$ columns (numbered $1$ through $N$ from left to right) containing all integers between $1$ and $N^2$ inclusive. For each valid $i$ and $j$, let's denote the cell in the $i$-th row and $j$-th column by $(i,j)$. Ada wants to sort the...
["for _ in range(int(input())):\n n=int(input())\n a=[]\n l=0\n for i in range(n):\n a.append(list(map(int,input().split())))\n for i in range(n-1,0,-1):\n r=a[i][i-1]+1\n if a[i][i]!=r:\n l+=1\n n=i+1\n for j in range(n):\n for k in range(j,n):\n a[j][k],a[k][j]=a[k][j],a[j][k]\n \n print(l)\n", "fo...
{"inputs": [["1", "4", "1 2 9 13", "5 6 10 14", "3 7 11 15", "4 8 12 16"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
9,865
df65e32ab63162172c3a9c14d6e60e5f
UNKNOWN
Chef's daily routine is very simple. He starts his day with cooking food, then he eats the food and finally proceeds for sleeping thus ending his day. Chef carries a robot as his personal assistant whose job is to log the activities of Chef at various instants during the day. Today it recorded activities that Chef was ...
["# cook your dish here\nt=int(input())\nfor _ in range(t):\n s=input()\n k=len(s)\n count=0\n for i in range(k-1):\n if(s[i]==\"C\"):\n if(s[i+1]=='E'or s[i+1]=='S' or s[i+1]==\"C\"):\n count+=1 \n elif(s[i]==\"E\"):\n if(s[i+1]==\"S\"or s[i+1]=='E'):\n count+=1 \n elif(s[i]==\"S\"):\n if(s[i+1]==\"S\")...
{"inputs": [["5", "CES", "CS", "CCC", "SC", "ECCC"]], "outputs": [["yes", "yes", "yes", "no", "no"]]}
INTERVIEW
PYTHON3
CODECHEF
5,830
b40101f6acf2821caa27a1ccc1eedbbc
UNKNOWN
Chef has an array A consisting of N elements. He wants to find number of pairs of non-intersecting segments [a, b] and [c, d] (1 ≤ a ≤ b < c ≤ d ≤ N) such there is no number that occurs in the subarray {Aa, Aa+1, ... , Ab} and {Ac, Ac+1, ... , Ad} simultaneously. Help Chef to find this number. -----Input----- - The...
["t=int(input())\nfor q in range(t):\n n=int(input())\n x=list(map(int,input().split()))\n dic={}\n dic2={}\n for i in range(n):\n dic2[x[i]]=1\n #print dic2\n if len(dic2)==n:\n n+=2\n print((n*(n-1)*(n-2)*(n-3))/24)\n continue \n counter=0\n for i in range(n-1):\n if x[i] in dic:\n dic[x[i]]+=1\n else:\n di...
{"inputs": [["2", "3", "1 2 3", "4", "1 2 1 2"]], "outputs": [["5", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
12,639
b37f1b32a5bebaac52c34382afcf131e
UNKNOWN
Chef loves lucky numbers. Everybody knows that lucky numbers are positive integers whose decimal representation contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Let F(X) equals to the number of lucky digits in decimal representation of X. Chef wants to know the ...
["lucky = {4, 774, 7, 744, 777, 74, 747, 44, 77, 47, 474, 444, 477, 447}\nfrom functools import lru_cache\nimport sys \nsys.setrecursionlimit(10 ** 6)\nmod = 10 ** 9 + 7\nfact = [1]\nfor i in range(1, 1001):\n fact.append(fact[-1] * i % mod)\ninv = [pow(i, mod-2, mod) for i in fact]\nC = lambda k, n: fact[n] * inv[n...
{"inputs": [["4", "1 100", "1 10000", "1 100000", "4444 4447", "", ""]], "outputs": [["0", "16", "640", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
2,326
fc21a6364393908ddea86e7717c996a3
UNKNOWN
Chef has a circular plot of land of radius $R$ on which he wants to construct a swimming pool. He wants the swimming pool to be square in shape with maximum possible area,so that he along with his friends can enjoy themselves during their summer vacations. Help Chef to find out the maximum area of the swimming pool tha...
["T=int(input())\r\nl=[]\r\nfor t in range(T):\r\n R=int(input())\r\n a=2*(R**2)\r\n l.append(a)\r\nfor s in l:\r\n print(s)", "# cook your dish here\nn = int(input())\nfor i in range(n):\n m = int(input())\n print(2 * m * m)", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(inpu...
{"inputs": [["2", "5", "10"]], "outputs": [["50", "200"]]}
INTERVIEW
PYTHON3
CODECHEF
2,724
cc80edc73efe5b02ca5edfc622402650
UNKNOWN
You are given two positive integers $A$ and $B$. Find the number of pairs of positive integers $(X, Y)$ such that $1 \le X \le A$, $1 \le Y \le B$ and $X + Y$ is even. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follow...
["try:\n t=int(input())\n while t>0:\n [a,b]=[int(x) for x in input().split()]\n if a==1 and b==1:\n print(1)\n continue\n if a%2==0:\n o1=a//2\n e1=a//2\n else:\n o1=a//2+1\n e1=a//2\n \n if b%2==0:\n o2=b//2\n e2=b//2\n else:\n o2=b//2+1\n e2=b//2\n \n print(e1*e2+o1*o2)\n t-=1\nexcept:...
{"inputs": [["4", "1 1", "2 3", "4 6", "8 9"]], "outputs": [["1", "3", "12", "36"]]}
INTERVIEW
PYTHON3
CODECHEF
8,045
03918834eb3cbe2c538ec167eacf829b
UNKNOWN
You are given $N$ integers in an array: $A[1], A[2], \ldots, A[N]$. You also have another integer $L$. Consider a sequence of indices ($i_1, i_2, \ldots, i_k$). Note that a particular index can occur multiple times in the sequence, and there is no order in which these indices have to occur. ($i_1, i_2, \ldots, i_k$) is...
["# cook your dish here\n# from queue import PriorityQueue\n# import bisect\ndef insort(l, v):\n s = 0\n e = len(l)\n while True:\n mid = (s+e)//2\n if s == e or mid > len(l):\n break\n if l[mid][0] < v[0]:\n s = mid+1\n elif l[mid][0] > v[0]:\n e = ...
{"inputs": [["1", "6 3", "2 4 1 12 3 5"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
5,698
4a6b8c747292dc17875d36856ccbccb1
UNKNOWN
Tejas has invited the Clash Team for a Dinner Party. He places V empty plates (numbered from 1 to V inclusive) in a straight line on a table. He has prepared 2 kinds of Delicious Dishes named dish A and dish B. He has exactly V servings of Dish A and W servings of dish B. Now he wants to serve the dishes in such a w...
["# cook your dish here\nt=int(input())\nfor i in range(t):\n v,w=list(map(int,input().strip().split(\" \")))\n if v==w:\n print(v+1)\n elif v<w:\n print(v+1)\n else:\n print(w+1)\n #s=\"a\"\n #s=s*v\n #l=list(s)\n #print(l)\n ct=0\n #for i in r...
{"inputs": [["1", "3 3"]], "outputs": [["4"]]}
INTERVIEW
PYTHON3
CODECHEF
3,886
ac465c6710105dae9190aab94e4e8e8a
UNKNOWN
Given an array $A$ of length $N$. We have to find the $maximum$ sum of elements of the subarray between $two$ nearest occurrences of $same$ elements (excluding both). If both the elements are $even$ then the total number of $even$ elements in that subarray should be $even$ then and then only we consider that subarray a...
["# cook your dish here\nfrom sys import stdin, stdout\nfrom collections import defaultdict\nfor _ in range(int(stdin.readline())):\n n=int(stdin.readline())\n lst=list(map(int, stdin.readline().split()))\n prefix_odd=[0]*n\n prefix_even=[0]*n\n odd_val=0\n even_val=0\n for i in range(n):\n ...
{"inputs": [["1", "10", "1 2 3 2 1 5 1 2 8 2"]], "outputs": [["7"]]}
INTERVIEW
PYTHON3
CODECHEF
14,992
de9237e12d57810a9125350b7d932b99
UNKNOWN
Now that Chef has finished baking and frosting his cupcakes, it's time to package them. Chef has N cupcakes, and needs to decide how many cupcakes to place in each package. Each package must contain the same number of cupcakes. Chef will choose an integer A between 1 and N, inclusive, and place exactly A cupcakes into ...
["for i in range(int(input())):\n n=int(input())\n print(n//2+1)", "# cook your dish here\nt = int(input())\nwhile t>0:\n n = int(input())\n print(n//2+1)\n t = t-1", "for _ in range (int(input())):\n n = int(input())\n print(n//2+1)\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n ...
{"inputs": [["2", "2", "5"]], "outputs": [["2", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
3,024
8c3f875482d2add4e5049f4eaf5df72e
UNKNOWN
There are $N$ buckets numbered $1$ through $N$. The buckets contain balls; each ball has a color between $1$ and $K$. Let's denote the number of balls with color $j$ that are initially in bucket $i$ by $a_{i, j}$. For each $i$ from $1$ to $N-1$ (in this order), someone draws a ball uniformly at random from bucket $i$ a...
["import sys\nimport math\n\ndef main(arr):\n \n k=len(arr[0])\n n=len(arr)\n dp=[[0]*k for i in range(n+1)]\n \n summation_arr=[]\n for i in range(len(arr)):\n a=1 if i!=0 else 0\n summation_arr.append(sum(arr[i])+a)\n \n for i in range(1,len(dp)):\n for j in range(len(dp[0])):\n dp[i][j]=(dp[i-1][j]+arr[i-1][j])...
{"inputs": [["2 2", "0 1", "1 1"]], "outputs": [["0.333333 0.666667"]]}
INTERVIEW
PYTHON3
CODECHEF
4,787
58ffedea87223ecc5735c5fecfbb257f
UNKNOWN
In this problem we are concerned with words constructed using the lowercase letters of the English alphabet - that is, a,b,c,…,z. These words need not necessarily be meaningful: any sequence of letters forms a word. For example, abbca is a word. We say that we can "hop" from the word $w_1$ to the word $w_2$ if they are...
["def codn1(s1,s2,p):\r\n\tc=0\r\n\tind=0\r\n\tfor i in range(len(s1)):\r\n\t\tif s1[i]!=s2[i]:\r\n\t\t\tc+=1\r\n\t\t\tind=i\r\n\tif c>1 or ind==len(s1)-1:\r\n\t\treturn 0\r\n\tif s1[ind]>s2[ind] and s1[ind] in s2[ind+1:]:\r\n\t\tp[0]=True\r\n\tif s1[ind]<s2[ind] and s2[ind] in s1[ind+1:]:\r\n\t\tp[1]=True\r\n\treturn ...
{"inputs": [["11", "abacd", "bcdada", "dd", "abcd", "bcdd", "adcd", "addd", "aa", "ccd", "add", "ad"]], "outputs": [["7"]]}
INTERVIEW
PYTHON3
CODECHEF
1,393
fc40ccdbb2aa9db0f729f5a793504903
UNKNOWN
Chang's new maths teacher is very enthusiastic about making sure that students understand the concept rather than remembering it. On her first day at teaching, she gives an assignment to all the students to test their potential. Chang wants to demonstrate that he understands the concept rather than rote learning. Help ...
["from math import sqrt\n\na, b = map(int, input().split())\npairs = 0\n\nfor i in range(1, a+1):\n for j in range(1, b+1):\n root = sqrt(i**2 + j)\n\n if not root - int(root):\n pairs += 1\n\nprint(pairs)", "#just code here\nimport math \n \ndef isPerfectSquare(x): \n \n # Find floating point value of \n # square...
{"inputs": [["4 4"]], "outputs": [["1"]]}
INTERVIEW
PYTHON3
CODECHEF
5,137
13db9431a16dabc5df73376b688b74ed
UNKNOWN
Fizza is a cute girl and she wants to be more beautiful. So she approached a magician to increase her beauty magically. But the magician's glasses accidently got locked inside the locker and he forgot the password. Without glasses he can't help her. The password is hidden in N integers i.e. $a[1], a[2], ..... a[N]$ w...
["def check(l,n):\n m = 0\n for i in range(n-1):\n x = l[i]\n c = 0\n j = i\n while (j+2<n and l[j+2]==x) or (j+1<n and l[j+1] == x):\n if l[j+1] == x:\n j = j+1\n else:\n j+=2\n c+=1\n if m<c:\n m = c\n ...
{"inputs": [["3", "8", "6 3 6 4 5 4 3 6", "9", "5 5 4 5 2 1 3 4 2", "6", "1 2 3 4 5 6"]], "outputs": [["1", "2", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
8,204
6041946275328f006dab8899785d361c
UNKNOWN
A repetition-free number is one in which each digit $\{1,2,3,…,9\}$ appears at most once and the digit $0$ does not appear. A repetition-free number can have at most nine digits, but may also have fewer than nine digits. Some examples of repetition-free numbers are $9, 32, 489, 98761$ and $983245$. You will be given an...
["N = int(input())\r\ni = N + 1\r\nflag = 0\r\nfor i in range(N+1, 987654321):\r\n a = str(i)\r\n b = list(a)\r\n c = set(a)\r\n if '0' not in b:\r\n if len(b) == len(c):\r\n print(i)\r\n flag += 1\r\n break\r\n \r\nif flag < 1:\r\n print(0)\r\n \r\n ...
{"inputs": [["99", "Sample output", "123"]], "outputs": [[]]}
INTERVIEW
PYTHON3
CODECHEF
1,848
62bea221591df0224dc83fa9f3595af3
UNKNOWN
IIST is thinking of acquiring some land nearby to build its new state of the art labs. The land it has chosen incidentaly has some abandoned college buildings which IIST wants to use. The administration decide the value of the building based on the amount of work that has to be done to get it in shape (lower amount of ...
["import math\r\nfrom itertools import permutations as p\r\ndef diff(li1, li2): \r\n li_dif = [i for i in li1 if i not in li2]\r\n return li_dif \r\ndef segments(b):\r\n \"\"\"A sequence of (x,y) numeric coordinates pairs \"\"\"\r\n poly = [(i[0],i[1]) for i in b]\r\n return zip(poly, poly[1:...
{"inputs": [["2", "6", "0 0 8 3", "1 4 3 2", "2 1 7 1", "4 1 2 3", "3 5 4 6", "2 3 9 8", "3", "3 0 10 2", "5 5 20 25", "7 -3 30 32"]], "outputs": [["2 4 5", "3.16", "2", "15.00"]]}
INTERVIEW
PYTHON3
CODECHEF
1,259
64b704e4d058ade723d1927cb3b101bb
UNKNOWN
Chef has a string of size $N$ which consists only lowercase English alphabet. The chef doesn't like the consonant alphabet at all. So he is thinking of changing every single consonant alphabet to any vowel alphabet. There is some cost for performing this operation. - Number all alphabet [a,b,c,……,z] as [1,2,3,…..,26] -...
["# cook your dish here\r\nstr1=int(input())\r\nfor i in range(str1):\r\n l1=[]\r\n str2=input()\r\n for i in str2:\r\n l1.append(i)\r\n \r\n count=0\r\n d=dict()\r\n d={'a':1,'b':2,'c':3,'d':4,'e':5,'f':6,'g':7,'h':8,'i':9,'j':10,'k':11,'l':12,'m':13,'n':14}\r\n d1={'o':15,'p':16,'q':17,...
{"inputs": [["2", "aeiou", "dbcc"]], "outputs": [["0", "6"]]}
INTERVIEW
PYTHON3
CODECHEF
12,599
8add9ff881a08d59e77368cf3afd9c74
UNKNOWN
Chef has $N$ doggo (dogs) , Lets number them $1$ to $N$. Chef decided to build houses for each, but he soon realizes that keeping so many dogs at one place may be messy. So he decided to divide them into several groups called doggo communities. Let the total no. of groups be $K$ . In a community, paths between pairs ...
["# cook your dish here\nimport sys\ndef get_array(): return list(map(int , sys.stdin.readline().strip().split()))\ndef get_ints(): return list(map(int, sys.stdin.readline().strip().split()))\ndef input(): return sys.stdin.readline().strip()\nimport math\nfrom collections import defaultdict\nfrom itertools import combi...
{"inputs": [["1", "4"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
3,870
e05d69744f73f32f3fea9f07c2785725
UNKNOWN
Chef has an old machine if the chef enters any natural number, the machine will display 1, 2, …n, n-1, n-2, n-3,…1 series and in next line prints sum of cubes of each number in the series. Chef wants to create a computer program which can replicate the functionality of the machine. Help the chef to code. -----Input:--...
["t=int(input())\r\nwhile(t!=0):\r\n t=t-1\r\n n=int(input())\r\n ans=0\r\n for i in range(1,n+1,1):\r\n sum=0;\r\n for j in range(1,i+1,1):\r\n sum=sum+j\r\n s=sum-i\r\n sum=sum+s\r\n if(i!=n):\r\n ans=ans+2*sum*i\r\n else:\r\n ans=...
{"inputs": [["2", "1", "3"]], "outputs": [["1", "45"]]}
INTERVIEW
PYTHON3
CODECHEF
5,338
ce8a8f93fe8ba35e4888b4ca844f9ede
UNKNOWN
-----Problem Statement----- Levy's conjecture, named after Hyman Levy, states that all odd integers greater than 5 can be represented as the sum of an odd prime number and an even semiprime. To put it algebraically, 2n + 1 = p + 2q always has a solution in primes p and q (not necessary to be distinct) for n > 2. (Sourc...
["isPrime=[1 for i in range(10001)]\ncnt=[0 for i in range(10001)]\nisPrime[0]=0\nisPrime[1]=0\nprime=[]\nfor i in range(2,10001):\n if isPrime[i]:\n prime.append(i)\n for j in range(i*i,10001,i):\n isPrime[j]=0\n#print(prime)\nfor i in prime:\n for j in prime:\n if (i + 2*j)>10000:\n break\n else:\n cnt[i + ...
{"inputs": [["3", "2", "7", "11"]], "outputs": [["0", "1", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
7,243
0591581444ea521ce2a835abad987c07
UNKNOWN
You are given a convex polygon $P$ with vertices $P_0, P_1, \ldots, P_{n-1}$, each having integer coordinates. On each edge $P_{i} P_{(i+1) \% n}$ of the polygon, choose a point $R_i$ uniformly at random. What is the expected area of the convex hull of these $n$ chosen points $R_0, R_1, \ldots R_{n-1}$ ? -----Note----...
["# cook your dish here\nn=int(input())\nx=[]\ny=[]\nfor _ in range(n):\n s=input().split(' ')\n x.append(int(s[0]))\n y.append(int(s[1]))\nq=x[0]\nw=y[0]\nfor t in range(n-1):\n x[t]=(x[t]+x[t+1])/2 \n y[t]=(y[t]+y[t+1])/2 \nx[n-1]=(x[n-1]+q)/2 \ny[n-1]=(y[n-1]+w)/2 \ni=0\na=0\nwhile(i<n-1):\n a+=(x[i]*y[i+1]-y[i]*x[i...
{"inputs": [["3", "0 0", "1 0", "0 1"]], "outputs": [["0.1250000000"]]}
INTERVIEW
PYTHON3
CODECHEF
2,880
0b69b0266ddb935cb6bb4707dd150c77
UNKNOWN
Tired of the overpopulated world, Miu - The introverted cat visits a new continent in search for a new house. There are $N$ houses lying on the X-axis. Their positions are given by $X$$i$ , where $i$ refers to the $i$th house. ( $1 <= i <= N$ ) Each of these positions are pairwise distinct Miu is supposed to choos...
["n = int(input())\nfor i in range(n) :\n t = int(input())\n li = sorted(list(map(int , input().split())))\n ans = 1\n dp = [li[1]-li[0]] + [0] * (t-2) + [li[t-1] - li[t-2]]\n for i in range(1 , t-1) :\n dp[i] = min(li[i] - li[i-1] , li[i+1] - li[i])\n print(max(dp))\n", "n=int(input())\nfor i in range(n):\n p=int(inp...
{"inputs": [["2", "6", "7 -1 2 13 -5 15", "4", "6 10 3 12"]], "outputs": [["5", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
2,895
cb7b61b58f0cb859aea89bab2647a195
UNKNOWN
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 ...
["from sys import stdin, stdout\r\nfrom collections import Counter\r\nn = int(stdin.readline())\r\n#l = list(map(int, stdin.readline().split()))\r\n#l = [int(stdin.readline()) for _ in range(n)]\r\n#a, b = map(int, stdin.readline().split())\r\nfor _ in range(n):\r\n n1 = int(stdin.readline())\r\n if n1==1:\r\n ...
{"inputs": [["5", "1", "2", "3", "4", "5"]], "outputs": [["*", "*", "***", "*", "* *", "*****", "*", "* *", "* *", "*******", "*", "* *", "* *", "* *", "*********"]]}
INTERVIEW
PYTHON3
CODECHEF
10,910
a2c5adf5bb037e7677c52d1b41efd860
UNKNOWN
You are given an array with $N$ integers: $A[1], A[2], \ldots, A[N]$ (where $N$ is even). You are allowed to permute the elements however you want. Say, after permuting the elements, you end up with the array $A'[1], A'[2], \ldots, A'[N]$. Your goal is to maximize the following sum: |A′[1]−A′[2]| + |A′[3]−A′[4]| + ... ...
["for i in range(int(input())):\n n=int(input())\n m=list(map(int,input().split()))[:n]\n m.sort()\n t=0\n for j in range(n//2):\n t+=abs(m[j]-m[n-j-1])\n print(t)\n", "T=int(input())\nfor i in range(T):\n N=int(input())\n L=list(map(int,input().split()))[:N]\n L.sort()\n c=0\n for j in range(N//2):\n c+=abs(L[j]-L[N...
{"inputs": [["1", "4", "1 -3 2 -3"]], "outputs": [["9"]]}
INTERVIEW
PYTHON3
CODECHEF
4,769
e7dbef22ca7c1cf786e66da89168db57
UNKNOWN
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 ...
["t = int(input())\r\n\r\nfor _ in range(t):\r\n k = int(input())\r\n count = 1\r\n for _ in range(k):\r\n output = []\r\n for index in range(1,k+1):\r\n output.append(bin(count).replace(\"0b\", \"\"))\r\n count += 1\r\n print(*output)", "# cook your dish here\nfor _ ...
{"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["1", "1 10", "11 100", "1 10 11", "100 101 110", "111 1000 1001", "1 10 11 100", "101 110 111 1000", "1001 1010 1011 1100", "1101 1110 1111 10000"]]}
INTERVIEW
PYTHON3
CODECHEF
5,264
037cae9b4fd5392adccef684d6beee85
UNKNOWN
The chef has one array of N natural numbers (might be in sorted order). Cheffina challenges chef to find the total number of inversions in the array. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains two lines of input, $N$. - N space-separ...
["# cook your dish here\ndef mergeSort(arr, n): \n # A temp_arr is created to store \n # sorted array in merge function \n temp_arr = [0]*n \n return _mergeSort(arr, temp_arr, 0, n-1) \n \n# This Function will use MergeSort to count inversions \n \ndef _mergeSort(arr, temp_arr, left, right): \n \n # A...
{"inputs": [["1", "5", "5 4 1 3 2"]], "outputs": [["8"]]}
INTERVIEW
PYTHON3
CODECHEF
19,682
2b0a6d69abd49041e92dc54280a965ca
UNKNOWN
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 ...
["for _ in range(int(input())):\n n = int(input())\n s = ''\n for i in range(1, n + 1): s += str(i)\n for i in range(n, 0, -1):\n if i % 2 == 0:\n for j in range(i, 0, -1): print(j, end = '')\n else:\n for j in range(1, i + 1): print(j, end = '')\n print()\n\n\n", "# cook your dish here\nfor _ in range(int(input...
{"inputs": [["3", "2", "3", "4"]], "outputs": [["21", "1", "123", "21", "1", "4321", "123", "21", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
4,179
c5453d290d22f7efb31664b6b89b878e
UNKNOWN
In ChefLand, there is a mountain range consisting of $N$ hills (numbered $1$ through $N$) in a straight line. Let's denote the height of the $i$-th hill from the left by $h_i$. Ada is working on the water supply system of ChefLand. On some of the hills, she wants to place water reservoirs; then, for each reservoir, she...
["def solve(l):\r\n m = l.index(max(l))\r\n if m == 0 or m == len(l) - 1:\r\n return 1\r\n return 1 + min(solve(l[0:m]), solve(l[m+1:]))\r\n\r\ntc = int(input())\r\nfor test in range(tc):\r\n n = int(input())\r\n l = list(map(int, input().split()))\r\n print(solve(l))", "def solve(l):\r\n m = l.index...
{"inputs": [["1", "6", "4 16 32 6 8 2", ""]], "outputs": [["2 "]]}
INTERVIEW
PYTHON3
CODECHEF
10,099
5151984a0a7b8f4656ce2f5306de07f2
UNKNOWN
-----Problem----- There is an infinite one dimensional array ranging from (-infinity, infinity).A Zombie is currently at cell number 0. The zombie wants to reach cell number H. The Zombie moves in only two ways. The Zombie either Makes U steps to the right (positive side) or Makes D steps to the left (negative side)...
["import fractions\nfor t in range(int(input())):\n h,u,d = list(map(int,input().split()))\n g = fractions.gcd(u,d)\n if (h%g!=0):\n print(-1)\n else:\n m = 0\n n = 0\n while (True):\n n = (float(m)*u-h)/d\n if (n>0 and int(n) == n):\n break\n m+=1\n print(int(m+n))", "import fractions\nfor t in range(int...
{"inputs": [["2", "3 2 1", "3 2 2"]], "outputs": [["3", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
565
c48f640f876585746c12595fecab14b0
UNKNOWN
Cyael is a teacher at a very famous school in Byteland and she is known by her students for being very polite to them and also to encourage them to get good marks on their tests. Then, if they get good marks she will reward them with candies :) However, she knows they are all very good at Mathematics, so she decided to...
["# cook your dish here\ntry:\n t = int(input())\n for _ in range(t):\n n, k = map(int, input().split())\n if k == 0:\n print(0, n)\n else:\n print(n//k, n%k)\nexcept:\n pass", "T = int(input())\n\nfor _ in range(T):\n N, K = map(int, input().split())\n if K == 0:\n print(0, N)\n else:\n print(N//K, N % K)", "...
{"inputs": [["2", "10 2", "100 3"]], "outputs": [["5 0", "33 1"]]}
INTERVIEW
PYTHON3
CODECHEF
3,896
1c99c823f45abe48548e619bd1bd4235
UNKNOWN
There are N hills in a row numbered 1 through N from left to right. Each hill has a height; for each valid i, the height of the i-th hill is Hi. Chef is initially on the leftmost hill (hill number 1). He can make an arbitrary number of jumps (including zero) as long as the following conditions are satisfied: - Chef ca...
["for _ in range(int(input())):\n N,U,D=list(map(int,input().split()))\n H=list(map(int,input().split()))\n jumps=0\n paracount=0\n for i in range(len(H)-1):\n if H[i+1]-H[i]<=U and H[i+1]>=H[i]:\n jumps+=1\n elif H[i]>=H[i+1] and H[i]-H[i+1]<=D:\n jumps+=1\n elif H[i]-H[i+1]>D and paracount==0:\n jumps+=1\n ...
{"inputs": [["3", "5 3 2", "2 5 2 6 3", "5 2 3", "4 4 4 4 4", "5 2 7", "1 4 3 2 1"]], "outputs": [["3", "5", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
9,892
9640dd1d5be3d0133d6b9efe662972df
UNKNOWN
Since due to COVID 19, India has undergone a complete 21 day lockdown. So Amol was attending an online lecture where his professor asked him to solve a question. Amol was unable to solve the question so he asked you to solve the question and give him the correct answer. The question was asked a such that his professo...
["try:\n def countsubsetsum(S,arr,n):\n k=[[0 for i in range(S+1)] for i in range(n+1)]\n for i in range(n+1):\n for j in range(S+1):\n if(j==0):\n k[i][j]=1\n elif(i==0):\n k[i][j]=0\n elif(arr[i-1]<=j):\n ...
{"inputs": [["2", "4", "16", "2 4 6 10", "4", "20", "2 8 12 10"]], "outputs": [["2", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
9,682
d4bd07cd2b6dd7a193d917f8fc48ab2a
UNKNOWN
You are given a rooted tree on N vertices. The nodes are numbered from 1 to N, and Node 1 is the root. Each node u has an associated value attached to it: Au. For each vertex v, we consider the path going upwards from v to the root. Suppose that path is v1, v2, .., vk, where v1 = v and vk = 1. The cost of any node on t...
["import sys\nn = eval(input())\nparents = [int(x)-1 for x in input().split(' ')]\nvalues = list(map(int , input().split(' ')))\nparents = [0]+parents\n# print(parents)\n# print(values)\ndef single_node_cost(i):\n cost = 0\n # print('started with ',i)\n min_value = sys.maxsize\n while i != 0:\n min_value = min(min_val...
{"inputs": [["8", "1 1 1 1 5 8 6", "1 2 3 4 5 15 70 10"]], "outputs": [["1 3 4 5 6 21 96 26"]]}
INTERVIEW
PYTHON3
CODECHEF
1,010
11e8bc9c994e08d75ff725938d1306ad
UNKNOWN
You might have heard about our new goodie distribution program aka the "Laddu Accrual System". This problem is designed to give you a glimpse of its rules. You can read the page once before attempting the problem if you wish, nonetheless we will be providing all the information needed here itself. Laddu Accrual Syste...
["for i in range(int(input())):\n n,k=input().split()\n laddus=0\n for j in range(int(n)):\n t=input().split()\n if t[0]=='CONTEST_WON':\n if(int(t[1])<=20):\n laddus+=300+20-int(t[1])\n else:\n laddus+=300\n elif t[0]=='TOP_CONTRIBUTOR':\n laddus+=300\n elif t[0]=='BUG_FOUND':\n laddus+=int(t[1])\n ...
{"inputs": [["2", "4 INDIAN", "CONTEST_WON 1", "TOP_CONTRIBUTOR", "BUG_FOUND 100", "CONTEST_HOSTED", "4 NON_INDIAN", "CONTEST_WON 1", "TOP_CONTRIBUTOR", "BUG_FOUND 100", "CONTEST_HOSTED"]], "outputs": [["3", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
12,500
149330b403e150bf109ee26e85f59785
UNKNOWN
You may have helped Chef and prevented Doof from destroying the even numbers. But, it has only angered Dr Doof even further. However, for his next plan, he needs some time. Therefore, Doof has built $N$ walls to prevent Chef from interrupting him. You have to help Chef by telling him the number of walls he needs to des...
["def posSearch(arr, num):\n l = 0\n r = len(arr)\n if num < arr[l]:\n return 0\n elif num > arr[r-1]:\n return r\n while l < r:\n m = (l+r)//2\n if arr[m] == num:\n return -1\n if arr[m] < num < arr[m+1]:\n return m+1\n if arr[m] > num:\n r = m\n elif arr[m] < num:\n l = m+1 \n \nfor _ in range(int(inpu...
{"inputs": [["1", "2", "1 3", "5", "0 0", "2 0", "0 4", "1 1", "1 2"]], "outputs": [["0", "1", "2", "1", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
12,069
33e6aff4515d3186fc1b72bba9626348
UNKNOWN
You are given a sequence $A_1, A_2, \ldots, A_N$. You want all the elements of the sequence to be equal. In order to achieve that, you may perform zero or more moves. In each move, you must choose an index $i$ ($1 \le i \le N$), then choose $j = i-1$ or $j = i+1$ (it is not allowed to choose $j = 0$ or $j = N+1$) and c...
["for _ in range(int(input())):\n n=int(input())\n a=[int(z) for z in input().split()]\n m=0\n a1=list(set(a))\n for i in range(len(a1)):\n if a.count(a1[i])>m:\n m=a.count(a1[i])\n print(n-m)\n \n \n", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n d={}\n l=list(map(int,input().split()))...
{"inputs": [["3", "5", "1 1 1 1 1", "4", "9 8 1 8", "2", "1 9"]], "outputs": [["0", "2", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
6,089
427483a0d16166196cc6e3f1de593019
UNKNOWN
----- HALLOWEEN EVE ----- In some other world, today is Halloween Eve.There are N trees planted in Mr. Smith’s garden. The height of the i-th tree (1≤i≤N) is h i meters. He decides to choose K trees from these trees and decorate them with electric lights. To make the scenery more beautiful, the heights of the decorate...
["try:\n a=list(map(int,input().split()))\n n=a[0]\n k=a[1]\n hi=[]\n for i in range(n):\n hi.append(int(input()))\n hi.sort()\n diff=[]\n for i in range(n-k+1):\n diff.append(hi[i+k-1]-hi[i])\n print(min(diff))\nexcept:\n pass", "N,K=map(int,input().split())\nl=[]\ni=0\nwhil...
{"inputs": [["5 3", "10", "15", "11", "14", "12"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
7,057
dedc8c8a7675bfaed4a7682c864b697e
UNKNOWN
You are given an $array$ of size $N$ and an integer $K$ ( $N > 1 , K > 0$ ). Each element in the array can be incremented by $K$ or decremented by $K$ $at$ $most$ $once$. So there will be $3^n$ possible combinations of final array. (As there are 3 options for every element). Out of these combinations, you have to sel...
["# cook your dish here\ntestcases=int(input())\n\nfor _ in range(testcases):\n (N,K)=list(map(int,input().split()))\n array=list(map(int,input().split()))\n \n max=array[0]\n min=array[0]\n \n for i in array:\n if i>max:\n max=i\n if i<min:\n min=i\n ...
{"inputs": [["2", "4 3", "4 2 5 1", "3 5", "2 5 3"]], "outputs": [["10", "13"]]}
INTERVIEW
PYTHON3
CODECHEF
5,369
4e8e90637bdb915a5bf45cee6cc3bee2
UNKNOWN
Mr. Pr and Ms. Ad are at $a$ and $b$ respectively on an infinite number line. Mr. Pr wants to meet Ms. Ad. Mr. Pr can choose to move $c$ or $d$ units in 1 second. If Mr. Pr moves $c$ units then Ms. Ad will move $d$ units and vice versa. (Both of them always moved in positive x-direction) You have to determine if Mr. P...
["for _ in range(int(input())):\r\n a,b,c,d=list(map(int,input().split()))\r\n if(a==b):\r\n print('YES')\r\n elif(c==d):\r\n print('NO')\r\n \r\n else:\r\n if(abs(a-b)%abs(c-d)==0):\r\n print('YES')\r\n else:\r\n print('NO')\r\n", "# cook your dish here\...
{"inputs": [["2", "3 4 1 2", "10 20 3 7"]], "outputs": [["YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
9,961
37967e5c675dd0b1df0e8a739d647aae
UNKNOWN
The ZCO scholarship contest offers scholarships to first time ZCO participants. You are participating in it for the first time. So you want to know the number of participants who'll get the scholarship. You know that the maximum number of scholarships offered is $R$ and there are a total of $N$ participants numbered fr...
["for _ in range(int(input())):\n n,r,x,y=map(int,input().split())\n if x>0:\n a=list(map(int,input().split()))\n if y>0:\n b=list(map(int,input().split()))\n if x>0 and y>0:\n a=a+b\n c=n-len(list(set(a)))\n else:\n l=x+y\n c=n-l\n x=min(c,r)\n print(x)", "t = int(input())\nfor _ in range(t):\n xi, yi = [], []\n...
{"inputs": [["3", "5 3 0 1", "4", "10 2 4 6", "3 1 7 6", "4 3 1 5 9 7", "10 4 4 6", "3 1 7 6", "4 3 1 5 9 7"]], "outputs": [["3", "2", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
9,471
1d872160a45ae8c4a9f858f9801339ad
UNKNOWN
Zonal Computing Olympiad 2012, 26 Nov 2011 We consider sequences of opening and closing brackets with two types of brackets, () and []. A bracket sequence is well-bracketed if we can pair up each opening bracket with a matching closing bracket in the usual sense. For instance, the sequences (), [] ([]) and []([]) ar...
["# cook your dish here\nn=int(input())\nstringa=list(map(int,input().split()))\ncounter=0\ncounter1=0\ncounter3=0\nsomma1=0\nsomma2=0\nmassimo=0\nmassimo1=0\nmassimo3=0 \nstack=[]\nfor par in stringa:\n if par==1 or par==3:\n if counter1==0 and par==1:\n counter1=1\n somma1=1\n ...
{"inputs": [["14", "1 1 3 4 2 2 3 3 3 1 2 4 4 4"]], "outputs": [["2 6 8"]]}
INTERVIEW
PYTHON3
CODECHEF
28,263
e5f657386b544feea0a854011fb98a48
UNKNOWN
Chef recently graduated Computer Science in university, so he was looking for a job. He applied for several job offers, but he eventually settled for a software engineering job at ShareChat. Chef was very enthusiastic about his new job and the first mission assigned to him was to implement a message encoding feature to...
["# cook your dish here\ntry:\n for _ in range(int(input())):\n n = int(input())\n li = [i for i in input()]\n a = 0\n while a+1<len(li):\n li[a],li[a+1] = li[a+1],li[a]\n a+=2\n li2 = li.copy()\n for i in li2:\n fh = 109\n sh = 110\n li.remove(i)\n if ord(i)>fh:\n li.append(chr(fh-(ord(i)-sh)))\n ...
{"inputs": [["2", "9", "sharechat", "4", "chef"]], "outputs": [["shizxvzsg", "sxuv"]]}
INTERVIEW
PYTHON3
CODECHEF
5,402
7f0a234f4fd25192624216d5fc430f73
UNKNOWN
Chuck Norris just created a universe. He has already started the space-time continuum. Now he needs to fill the universe with matter and antimatter for the avatar cycle to start. He created $N$ distinct pairs of elementary matter and their corresponding antimatter particles. Annihilations happen only when a matter part...
["for i in range(int(input())):\n n=int(input())\n if(n<=2 or n>1000000007):\n print(\"0\")\n else:\n prod=1\n for i in range(2,n):\n prod*=i\n if(prod>1000000007):\n prod=prod%1000000007\n print(((prod)*(n*prod-2))%1000000007)\n", "import math\nfor i in range(int(input())):\n n=int(input())\n if(n<=2 or n>1...
{"inputs": [["1", "3", "Sample output :", "8"]], "outputs": [[]]}
INTERVIEW
PYTHON3
CODECHEF
590
dae950bdc259fbf74a30b25fb94a38e7
UNKNOWN
You are given a grid of size M x N, where each square is colored with some random color among K colors with each having equal probability. A Good Rectangle is defined as one where all squares lying on the inner border are of the same color. What is the expected number of Good Rectangles in the given grid. -----Input...
["def for1(M,k):\n ret = 0.0\n x = k*k+0.0\n z=x\n for m in range(1,M):\n ret+=(M-m)/x\n x*=z\n return ret \n \ndef for2(M,k):\n ret = 0.0\n x = k+0.0\n for m in range(1,M):\n ret+=(M-m)/x\n \n x*=k\n return ret \n \ndef ans(M,N,K):\n\n return int(round(M*N+M*for2(N,K)+N*for2(M,K)+K*for1(M,K)*for1(N,K),0))\nM,N,...
{"inputs": [["1 3 1"]], "outputs": [["6"]]}
INTERVIEW
PYTHON3
CODECHEF
1,179
e3620fd7f713a914701e5abc0c6f96c4
UNKNOWN
Jem is famous for his laziness at school. He always leaves things to last minute. Now Jem has N problems in the assignment of "Advanced topics in algorithm" class to solved. The assignment is due tomorrow and as you may guess he hasn't touch any of the problems. Fortunately he got a plan as always. The first step will...
["for t in range(int(input())):\n n,b,m = list(map(int,input().split()))\n ans = 0\n while n>0:\n ans+=b\n half = (n+1)/2 if n%2 else n/2\n ans+=m*half\n m*=2\n n=n-half\n print(ans-b)\n \n", "# cook your code here\nt= int(input())\nwhile (t>0):\n t=t-1\n T=0\n N,B,M = list(map(int,input().split()))\n while(N!=0):...
{"inputs": [["2", "9 1 2", "123456 123456 123456"]], "outputs": [["45", "131351258112"]]}
INTERVIEW
PYTHON3
CODECHEF
4,359
3921b38f89c0d1e083f8c89b24841136
UNKNOWN
Chef is very fond of horses. He enjoys watching them race. As expected, he has a stable full of horses. He, along with his friends, goes to his stable during the weekends to watch a few of these horses race. Chef wants his friends to enjoy the race and so he wants the race to be close. This can happen only if the horse...
["t=eval(input())\nfor q in range(t):\n l=eval(input())\n a=input().split()\n a=[int(x) for x in a]\n a=sorted(a)\n for i in range(l-1):\n a[i]=(a[i+1]-a[i]) \n print(min(a[0:l-1]))\n", "def main():\n t = (int)(input())\n for tt in range(0,t):\n totnums = (int)(input())\n nums = input()\n nnn = list(map((int),list(...
{"inputs": [["1", "5", "4 9 1 32 13"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
4,866
f0d7dac61610f3764f52c8c02ff26883
UNKNOWN
Special Numbers Mani has encountered a problem on Special numbers in Bytecode. A number S is called a special number if its digits are in an arithmetic progression modulo 10. He has an array consisting of all numbers from 1 to N and needs your help to find the number of special numbers in the array. He has promised yo...
["# cook your code here\nn=input()\nx=len(n)\nno=list(map(int,n))\ntemp=[0]*x\nif (x>2):\n sum=99\n for i in range(3,x):\n sum=sum+90\n sum=sum+10*(int(n[0])-1)\n sum=sum+int(n[1])\n f=int(n[0])%10\n \n s=int(n[1])%10\n \n cd=s-f\n \n temp[0]=n[0]\n temp[1]=n[1]\n for i in range(2,x):\n nxt=(s+cd)%10\n temp[i]=(chr(...
{"inputs": [["123"]], "outputs": [["102"]]}
INTERVIEW
PYTHON3
CODECHEF
427
4efe9de535484fc005375d120e56e9c7
UNKNOWN
Omy and Ish were learning the pattern printing. In order to learn they give themselves a task. In this task they are given a string and they have to form a pyramid with the pattern as follows: RowNumber are one based indexed. - If (RowNumber % 3 == 0) then string is written in left to right while in other cases it is ...
["import sys\r\n\r\nn = int(sys.stdin.readline().strip())\r\ns = sys.stdin.readline().strip()\r\n\r\nalph = \"ABCDEFGHIJKLMNOPQRSTUVWXYZ\"\r\n\r\narr = [0]*26\r\npref = []\r\n\r\nfor i in range(len(s)):\r\n\tfor j in range(26):\r\n\t\tif alph[j] == s[i]:\r\n\t\t\tarr[j] += 1\r\n\t\t\tbreak\r\n\tpref += [arr[:]]\r\n\r\n...
{"inputs": [["5", "CODING", "2", "1 C", "2 D"]], "outputs": [["1", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
1,075
b46c9f348965b6a73b10281dbf081d0a
UNKNOWN
Given an array $A$ of size $N$ , count number of pairs of index $i,j$ such that $A_i$ is even, $A_j$ is odd and $i < j$ -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. - The first line of each test case contains integer $N$. - The second line of eac...
["t = int(input())\nfor i in range(t):\n n = int(input())\n l = list(map(int, input().split()))\n counter = 0\n even = 0\n for num in l:\n if num % 2 == 0:\n even += 1 \n if num % 2 == 1:\n counter += even\n print(counter)\n \n", "for t in range(int(input())):\n n = int(input())\n numberlist = list(map(int,input(...
{"inputs": [["2", "4", "1 2 1 3", "5", "5 4 1 2 3"]], "outputs": [["2", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
5,711
fc2f6eca7ef923711a06510b4494ae95
UNKNOWN
This problem is about sequences of positive integers $a_1,a_2,...,a_N$. A subsequence of a sequence is anything obtained by dropping some of the elements. For example, $3,7,11,3$ is a subsequence of $6,3,11,5,7,4,3,11,5,3$ , but $3,3,7$ is not a subsequence of $6,3,11,5,7,4,3,11,5,3$ . A fully dividing sequence is a se...
["# coding: utf-8\n# Your code here!\n\nn=int(input())\na=[]\nfor i in range(n):\n x=int(input())\n a.append(x)\n \n# print(a)\nans=0\nm=[1]*n\nfor i in range(n):\n for j in range(i):\n if a[i]%a[j]==0:\n m[i]=max(m[i],m[j]+1)\n \n \n \nprint(max(m))", "#au...
{"inputs": [["9", "2", "3", "7", "8", "14", "39", "145", "76", "320", "Sample output 1:", "3", "Sample input 2:", "14", "2", "11", "16", "12", "36", "60", "71", "17", "29", "144", "288", "129", "432", "993", "Sample output 2:", "5"]], "outputs": [[]]}
INTERVIEW
PYTHON3
CODECHEF
1,869
ec94b76ef52abc36a03d5b42d7099db8
UNKNOWN
Problem Statement:Captain America and Iron Man are at WAR and the rage inside Iron Man is rising. But Iron Man faces a problem to identify the location of Captain America. There are N buildings situtaed adjacently to each other and Captain America can be at any building. Iron Man has to arrange the Buildings from 1 ...
["t = int(input())\nwhile t> 0:\n t =t -1\n n,k = list(map(int,input().split()))\n a = [0]*n\n done = True\n\n def swap(z):\n for j in range(0,n):\n if a[j] == 0:\n a[j] = z\n done = True\n break\n else:\n if a[j] > z:\n swap(j)\n a[j] = z\n else:\n done = False\n break\n\n for i in ...
{"inputs": [["3", "2 1", "3 0", "3 2"]], "outputs": [["2 1", "1 2 3", "CAPTAIN AMERICA EVADES"]]}
INTERVIEW
PYTHON3
CODECHEF
1,583
3e813bcb74981a3ea6f6abf2d57a6c1a
UNKNOWN
Back in 2015, Usain Bolt announced that he'll be retiring after the 2017 World Championship. Though his final season did not end gloriously, we all know that he is a true legend and we witnessed his peak during 2008 - 2013. Post retirement, Usain Bolt is still leading an adventurous life. He's exploring the unexplored...
["for i in range(int(input())):\n finish,distanetobolt,tigerAcceleration,boltspeed=map(int,input().split())\n t1=((2*(finish+distanetobolt)/(tigerAcceleration))**0.5)\n t2=(finish/boltspeed)\n if t1>t2:\n print(\"Bolt\")\n elif t1<t2:\n print(\"Tiger\")\n else:\n print(\"Tiger\")", "for i in range(int(input())):\n f...
{"inputs": [["2", "10 100 10 10", "100 10 5 10"]], "outputs": [["Bolt", "Tiger"]]}
INTERVIEW
PYTHON3
CODECHEF
4,678
e8b0add59de49d82ed6a6e346fba808c
UNKNOWN
You are given a sequence of non-negative integers $A_1, A_2, \ldots, A_N$. At most once, you may choose a non-negative integer $X$ and for each valid $i$, change $A_i$ to $A_i \oplus X$ ($\oplus$ denotes bitwise XOR). Find the minimum possible value of the sum of all elements of the resulting sequence. -----Input-----...
["# cook your dish here\n# cook your dish here\ntest=int(input())\nfor _ in range(test):\n n=int(input())\n a=[(bin(int(x))[2:][::-1]+(\"0\")*32)for x in input().split()]\n res=\"\"\n mysum=0\n for i in range(32):\n mycount=0\n for j in range(n):\n if(a[j][i]==\"0\"):\n mycount+=1\n if(mycount==n):\n break\n ...
{"inputs": [["3", "5", "2 3 4 5 6", "4", "7 7 7 7", "3", "1 1 3"]], "outputs": [["14", "0", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
10,915
d46c82eb7cd871f71935746508d30c41
UNKNOWN
Chef and Paja are bored, so they are playing an infinite game of ping pong. The rules of the game are as follows: - The players play an infinite number of games. At the end of each game, the player who won it scores a point. - In each game, one of the players serves. Chef serves in the first game. - After every $K$ poi...
["n=int(input())\nwhile(n>0):\n x,y,z=map(int,input().split())\n t=(x+y)//z\n if t%2==0:\n print('Chef')\n else:\n print('Paja')\n n-=1", "t=int(input())\nwhile(t>0):\n a,b,c=map(int,input().split())\n n=(a+b)//c\n if n%2==0:\n print(\"Chef\")\n else:\n print(\"Paja\")\n t-=1", "# cook your dish here\nt=int(input()...
{"inputs": [["3", "1 3 3", "5 7 2", "38657 76322 564"]], "outputs": [["Paja", "Chef", "Paja"]]}
INTERVIEW
PYTHON3
CODECHEF
4,207
efdc8aa4399048c7cbe6b263b75f5350
UNKNOWN
Theatre Square in the capital city of Berland has a rectangular shape with the size n × m meters. On the occasion of the city's anniversary, a decision was taken to pave the Square with square granite flagstones. Each flagstone is of the size a × a. What is the least number of flagstones needed to pave the Square? It's...
["try:\r\n n,m,a=map(int,input().split())\r\n if n%a!=0:\r\n number1=(n//a)+1\r\n else:\r\n number1=(n//a)\r\n if m%a!=0:\r\n number2=(m//a)+1\r\n else:\r\n number2=(m//a)\r\n print(number1*number2)\r\nexcept:\r\n pass"]
{"inputs": [["s", "input", "6 6 4", "output", "4"]], "outputs": [[]]}
INTERVIEW
PYTHON3
CODECHEF
269
6ed028e33e9228bc754087a84151922e
UNKNOWN
The Chef once decided to prepare some nice dishes on his birthday. There are N items kept on his shelf linearly from position 1 to N. Taste of the i-th item is denoted by a integer Ai. He wants to make Q dishes. A dish will be made using some ingredients in the continuous range AL, AL + 1, , , AR (1-base indexing). Qu...
["n,k, q = list(map(int, input().split()))\nmod = 10 ** 9 + 7\nA = [0] * n\na, b, c, d, e, f, r, s, t, m, x = list(map(int, input().split())) \nA[0] = x \n\nfor x in range(1, n):\n if pow(t, x+1, s) <= r:\n A[x] = (a*pow(A[x-1], 2, m) + b*A[x-1] + c) % m\n else:\n A[x] = (d*pow(A[x-1], 2, m) + e*A[x-1] + f) % m\n \n...
{"inputs": [["4 2 1", "1 1 1 1 1 1 1 1 1 100 1", "1 1 1 3 1 1 1 2"]], "outputs": [["13 13"]]}
INTERVIEW
PYTHON3
CODECHEF
1,740
40d035ef560427e0f5c31f38ae3559e0
UNKNOWN
January and February are usually very cold in ChefLand. The temperature may reach -20 and even -30 degrees Celsius. Because of that, many people seal up windows in their houses. Sergey also lives in ChefLand. He wants to seal the window in his house. The window has the shape of a simple convex polygon with N vertices...
["from math import sqrt\nimport sys\nsys.setrecursionlimit(10**8)\nintMax = 10**18\ndef knapsack(rl,l,c,m):\n if m==0 and rl>0:\n return intMax\n if rl<=0:\n return 0\n return min(c[m-1]+knapsack(rl-l[m-1],l,c,m),knapsack(rl,l,c,m-1))\nfor _ in range(int(input())):\n n= int(input())\n cost=[]\n length=[]\n sides=[]\n...
{"inputs": [["1", "4", "0 0", "1000 0", "1000 2000", "0 2000", "2", "1000 10", "2000 15"]], "outputs": [["50"]]}
INTERVIEW
PYTHON3
CODECHEF
860
41e7cdb0049a1d808d31a2049fd7db76
UNKNOWN
Supermarket Dilemma Chef is going to local supermarket but there appears a problem with chef as he is confused about which Supermarket he can choose to go as he is not able to decide whether he can park his car in that particular supermarket’s parking lot or not! There are N parking slots in each supermarket which are ...
["import math\r\n\r\ndef check(s):\r\n if s==2:\r\n return 1\r\n \r\n for i in range(2,math.ceil(math.sqrt(s))+1):\r\n if s%i == 0:\r\n return 0\r\n \r\n return 1\r\n \r\n\r\ndef Solve(slots):\r\n if slots<3:\r\n return 0\r\n \r\n #check\r\n s = math.sqrt(slots)...
{"inputs": [["2", "4", "5"]], "outputs": [["YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
586
63988e14db12217742dfe1c590462b51
UNKNOWN
You are given an integer sequence $A_1, A_2, \ldots, A_N$ and an integer $X$. Consider a $N \times N$ matrix $B$, where $B_{i,j} = A_i + A_j$ for each valid $i$ and $j$. You need to find the number of square submatrices of $B$ such that the sum of their elements is $X$. Formally, find the number of quartets $(x_1, y_1,...
["# cook your dish here\nimport sys\ninput=sys.stdin.readline\nfor _ in range(int(input())):\n n,x=list(map(int,input().split()))\n l=[0]\n pre=[0]*(n+1)\n sum=0\n i=1\n for m in input().split():\n l.append(int(m))\n sum+=int(m)\n pre[i]=sum\n i+=1\n dict={}\n k=[]\n i=1\n while (i*i)<=x:\n if x%i==0:\n k.append...
{"inputs": [["2", "5 36", "1 2 3 1 12", "4 54", "3 3 3 3"]], "outputs": [["6", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
23,908
9fe0e86e10b49846da6b4af25940b5de
UNKNOWN
Mr. Krabs loves money. He enters a bank and sees that there are n rooms arranged in a row. The only rooms with doors are the two rooms on either corner. Initially, all the rooms are locked (including the corner ones). To enter a room, it must be unlocked with a key. Mr. Krabs is able to steal k keys from the sleeping n...
["rooms=int(input())\r\nmoney=list(map(int,input().split()))\r\nkeys=int(input())\r\nrev=-1\r\na,b=0,-1\r\ntot=[]\r\n#print(money[-3:-1])\r\nx=0\r\nfor i in range(keys):\r\n #print(money[b:-1],money[0:a])\r\n x=sum(money[b:])+sum(money[0:keys-abs(b)])\r\n tot.append(x)\r\n b-=1\r\nprint(max(tot))\r\n", "# c...
{"inputs": [["7", "1 2 3 4 5 6 1", "3"]], "outputs": [["12"]]}
INTERVIEW
PYTHON3
CODECHEF
5,522
432262807b3a0af93f75959f075d687f
UNKNOWN
The game of billiards involves two players knocking 3 balls around on a green baize table. Well, there is more to it, but for our purposes this is sufficient. The game consists of several rounds and in each round both players obtain a score, based on how well they played. Once all the rounds have been played, the total...
["s1=s2=lead=0\nmlead1=mlead2=0\nfor _ in range(int(input())):\n x, y= list(map(int, input().split()))\n s1, s2= s1+x, s2+y\n if(s1>s2):\n lead=(s1-s2)\n mlead1= max(mlead1, lead)\n else:\n lead=(s2-s1)\n mlead2= max(mlead2, lead)\nif(mlead1<(mlead2)):\n print('2', mlead2)\nel...
{"inputs": [["5", "140 82", "89 134", "90 110", "112 106", "88 90"]], "outputs": [["1 58"]]}
INTERVIEW
PYTHON3
CODECHEF
8,285
450bfae7b0b36f4ae73f7b634fe84916
UNKNOWN
Dr. S. De teaches computer architecture in NIT Patna. Whenever he comes across any good question(with complexity $k$), he gives that question to students within roll number range $i$ and $j$ At the start of semester he assigns score of $10$ to every student in his class if a student submits a question of complexity $k$...
["try:\n t=int(input())\n for a in range(t):\n l=input().split()\n n=int(l[0])\n m=int(l[1])\n d={}\n s=0\n for b in range(m):\n l1=input().split()\n i=int(l1[0])\n j=int(l1[1])\n k=int(l1[2])\n for c in range(i,j+1):\n if c not in d:\n d[c]=10\n for c in range(i,j+1):\n d[c]=d[c]*k\n for i...
{"inputs": [["1", "5 3", "1 3 5", "2 5 2", "3 4 7"]], "outputs": [["202"]]}
INTERVIEW
PYTHON3
CODECHEF
7,998
6a3c4d80f2610484e28e596c1168e483
UNKNOWN
You are given an N × N grid initially filled by zeros. Let the rows and columns of the grid be numbered from 1 to N, inclusive. There are two types of operations can be applied to the grid: - RowAdd R X: all numbers in the row R should be increased by X. - ColAdd C X: all numbers in the column C should be increased by...
["n,q=map(int,input().split())\ndr={}\ndc={}\nfor i in range(1,n+1):\n dr[i]=0\n dc[i]=0\nmer=0\nmec=0\nfor i in range(q):\n s,j,k=input().split()\n j=int(j)\n k=int(k)\n if s==\"RowAdd\":\n dr[j]+=k\n if dr[j]>mer:\n mer=dr[j]\n else:\n dc[j]+=k\n if mec<dc[j]:\n mec=dc[j]\n# m=max(list(dr.values()))+max(list(...
{"inputs": [["2 4", "RowAdd 1 3", "ColAdd 2 1", "ColAdd 1 4", "RowAdd 2 1"]], "outputs": [["7"]]}
INTERVIEW
PYTHON3
CODECHEF
7,355
8029f5bb9aec1cf8091015c0479852f3
UNKNOWN
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 inp...
["try:\n for _ in range(int(input())):\n k=int(input())\n for i in range(1,k+1):\n print(\" \"*(k-i),end=\"\")\n if i%2==1:\n for j in range(0,i):\n print(chr(65+j),end=\"\")\n else:\n for j in range(0,i):\n print(j+1,end=\"\")\n print()\n \n \nexcept:\n pass", "# cook your dish here\nfor _ i...
{"inputs": [["2", "2", "4"]], "outputs": [["A", "12", "A", "12", "ABC", "1234"]]}
INTERVIEW
PYTHON3
CODECHEF
6,366
3e057bf155caef7671e964fc75751f91
UNKNOWN
The activity of a panipuri seller is "making a panipuri and putting it on the palte of his customer". $N$ customers are eating panipuri, Given an array $A$ of length $N$, $i^{th}$ customer takes $A_i$ seconds to eat a panipuri. The Speed of Panipuri seller refers to the number of customers served per second. D...
["# cook your dish here\nfrom math import ceil\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n ans=ceil(n/min(a))\n print(int(ans))", "from math import *\nfor i in range(int(input())):\n n=int(input())\n arr=[int(i) for i in input().split()]\n print(ceil(n/min(a...
{"inputs": [["2", "4", "2 4 6 3", "5", "2 3 4 6 5"]], "outputs": [["2", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
6,640
1a38052d5140348a4a11bbf861971965
UNKNOWN
Chef wants to buy a new phone, but he is not willing to spend a lot of money. Instead, he checks the price of his chosen model everyday and waits for the price to drop to an acceptable value. So far, he has observed the price for $N$ days (numbere $1$ through $N$); for each valid $i$, the price on the $i$-th day was $P...
["for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n g=1\n for j in range(1,n):\n if j-5<0:\n mi=min(a[0:j])\n #print(a[0:j])\n if mi>a[j]:\n g=g+1\n else:\n mi=min(a[j-5:j])\n #print(a[j-5:j])\n if mi>a[j]:\n g=g+1\n print(g)\n", "# cook your dish here\nt = int(inpu...
{"inputs": [["1", "7", "375 750 723 662 647 656 619"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
5,432
291390bbcc990f63cdef25948d99a4d1
UNKNOWN
Chef works in a similar way to a travelling salesman ― he always travels to new cities in order to sell his delicious dishes. Today, Chef is planning to visit $N$ cities (numbered $1$ through $N$). There is a direct way to travel between each pair of cities. Each city has a specific temperature; let's denote the temper...
["# cook your dish here\ndef solution(b,n1,d):\n first=b[0]\n b.sort()\n for j in range(n1-1):\n if(a[j+1]-a[j]>d):\n return \"NO\"\n for j in range(n1):\n if(b[j]==first):\n pos=j\n if(pos==0 or pos==n1-1):\n return \"YES\"\n rec=1\n for j in range(pos-1,n1-2):\n if(a[j+2]-a[j]>d):\n rec=0\n break\n if(...
{"inputs": [["2", "5 3", "3 2 1 4 5", "5 4", "10 1 3 2 9"]], "outputs": [["YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
5,749
6bf1055f0ed70c05a7e2713fc5e88704
UNKNOWN
In the world of DragonBool there are fierce warriors called Soints. Also there are even fiercer warriors called Sofloats – the mortal enemies of Soints. The power of each warrior is determined by the amount of chakra he possesses which is some positive integer. Warriors with zero level of chakra are dead warriors :) W...
["t=eval(input())\nfor i in range(0,t):\n x=input()\n nm=x.split(' ')\n nm[0]=int(nm[0])\n nm[1]=int(nm[1])\n csoint=[]\n lsoint=[]\n csofloat=[]\n lsofloat=[]\n for j in range(0,nm[0]):\n a=input()\n b=a.split(' ')\n b[0]=int(b[0])\n b[1]=int(b[1])\n csoint...
{"inputs": [["2", "2 3", "10 1", "20 2", "5 2", "5 2", "18 1", "5 5", "73 87", "69 13", "36 36", "77 46", "43 93", "49 46", "74 93", "78 87", "99 13", "59 36", "", ""]], "outputs": [["8", "89"]]}
INTERVIEW
PYTHON3
CODECHEF
31,919
458afa4cc9c291a2571a0765a8cda0b8
UNKNOWN
A group of rebels travelling on a square hoverboard is ambushed by Imperial Stormtroopers.Their big hoverboard is an easy target, so they decide to split the board into smaller square hoverboards so that they can bolt away easily.But they should also make sure they don't get too spread out.Help the rebels split the cra...
["a=int(input())\nif(a%2==0):\n print(\"4\")\n print(a/2,a/2,a/2,a/2)\nelse:\n print(\"6\")\n print((a-1)/2,(a-1)/2,(a-1)/2,(a-1)/2,(a-1)/2,(a+1)/2)"]
{"inputs": [["3"]], "outputs": [["6", "1 1 1 1 1 2"]]}
INTERVIEW
PYTHON3
CODECHEF
150
cef8dec02ea7442a7e1225c2a535ad26
UNKNOWN
Takaki Tono is a Computer Programmer in Tokyo. His boss at work shows him an online puzzle, which if solved would earn the solver a full expense paid trip to Los Angeles, California. Takaki really wants to solve this, as the love of his life, Akari, lives in Los Angeles and he hasn't met her since four years. Upon read...
["MAXX = 10**9+1\nN = eval(input())\nnodes = list(map(int, input().split(\" \")))\nedges = [set() for _ in range(N)]\nfor _ in range(N-1):\n a, b = list(map(int, input().split(\" \")))\n edges[a-1].add(b-1)\n edges[b-1].add(a-1)\npath = [[] for _ in range(N)]\nvisited, tovisit = set(), [(0, 0)]\nwhile tovisit:...
{"inputs": [["5", "1 2 7 4 5", "1 2", "2 3", "2 4", "2 5", "7", "C 1 5", "F 1 5", "C 2 4", "C 1 2", "F 1 3", "F 3 4", "F 2 4"]], "outputs": [["1", "4", "2", "1", "6", "5", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
2,243
34443e8079fab856fd5d5cfb34a2c363
UNKNOWN
Chef Leonardo has a decimal integer $N$ and a non-zero decimal digit $d$. $N$ does not contain the digit zero; specifically, $N$ should always be treated as a decimal integer without leading zeroes. Chef likes $d$ and does not like any other digit, so he decided to change $N$. He may apply the following operation any n...
["for _ in range(int(input())):\n n,d=map(str,input().split())\n k=list(n)\n dd,c,n=d,0,len(n)\n for x in range(n):\n if int(k[n-x-1])>int(d):\n k.pop(n-x-1)\n c+=1 \n else:\n d=k[n-x-1]\n print(''.join(k)+c*dd)", "# cook your dish here\nfrom sys import stdin,stdout\n\nfor _ in range(int(input())):\n n,d=map(st...
{"inputs": [["3", "35 4", "42 4", "24 9"]], "outputs": [["34", "24", "24"]]}
INTERVIEW
PYTHON3
CODECHEF
9,879
791188a1c37a8bade00774c7596715db
UNKNOWN
Given an array A1,A2...AN, you have to print the size of the largest contiguous subarray such that GCD of all integers in that subarray is 1. Formally, For a subarray Ai,Ai+1...Aj where 1 ≤ i < j ≤ N to be valid: GCD(Ai,Ai+1...Aj) should be 1. You have to print the size of the largest valid subarray. If no valid suba...
["import math\nfor _ in range(int(input())):\n n=int(input())\n ar=[int(x) for x in input().split()]\n # dp=[1]*n\n f=0\n g=ar[0]\n for i in range(1,n):\n g=math.gcd(g,ar[i])\n if g==1:\n f=1\n print(n)\n break\n if f==0:\n print(-1)\n", "import math\ndef gcd(a,b):\n if b==0:\n return a\n return gcd(b,a%b)\nt...
{"inputs": [["2", "2", "7 2", "3", "2 2 4"]], "outputs": [["2", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
6,491
6db52717f63e3fb9b82c5d60ba6e80df
UNKNOWN
You are given an array A consisting of N integers. A group of disjoint subarrays in it will be a collection of subarrays of the array. Formally a group of subarrays consisting of K subarrays can be denoted by 2 * K indices, [i1, j1], [i2, j2] , ..., [iK, jK], such that i1 ≤ j1 < i2 ≤ j2 < ... < iK ≤ jK. For example, i...
["t=int(input())\nfor k in range(t):\n n=int(input())\n l=[int(i) for i in input().split()]\n m={}\n count=1\n for i in range(1,n):\n if l[i]==l[i-1]:\n count+=1\n else:\n \n if l[i-1] not in m:\n m[l[i-1]]=(count*(count+1))/2\n els...
{"inputs": [["3", "2", "3 4", "3", "1 2 2", "5", "1 1 2 2 2", "", ""]], "outputs": [["1", "3", "18"]]}
INTERVIEW
PYTHON3
CODECHEF
635
98362ac2f9185be80ef2816f87085240
UNKNOWN
Chef is playing a game on a sequence of $N$ positive integers, say $A_1, A_2, ... A_N$ The game is played as follows. - If all the numbers are equal, the game ends. - Otherwise - Select two numbers which are unequal - Subtract the smaller number from the larger number - Replace the larger number with the result from ab...
["# cook your dish here\nfrom sys import stdin\nimport functools\ndef gcd(a, b): \n if (a == 0): \n return b \n return gcd(b % a, a) \n \nMAX=10001\ndef func(ind, g, dp, n, a): \n if (ind == n): \n if (g == 1): \n return 1\n else: \n return 0\n if (dp[ind][g] != -1): \n return dp[ind][g] \n ans = (func(ind ...
{"inputs": [["3", "4", "2 3 5 7", "4", "3 4 8 16", "3", "6 10 15"]], "outputs": [["11", "7", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
12,112
487024452ff169ea9db62c2f38df6712
UNKNOWN
Anmol gained a lot of weight last semester. So this semester, he decided to run everyday. There is a very long straight road starting at his hostel. There are N poles on the road - P1, P2, P3,..., PN on the road. All the poles lie on the same side of his hostel. The distance between Pi and his hostel is Di. For 1 ≤ i, ...
["#code snippet reference:http://www.geeksforgeeks.org/searching-for-patterns-set\u00a0\u00a0\u00a0\u00a0-2-kmp-algorithm/\ndef KMPMatch(pattern, string):\n M = len(pattern)\n N = len(string)\n nonlocal ans\n\n lps = [0]*M\n j = 0 \n LPSCompute(pattern, M, lps)\n\n i = 0 \n while i < N:\n if pattern[j] == string[i]:\n...
{"inputs": [["3", "5 1", "1 5 10 12 14", "5", "5 2", "5 8 13 16 21", "3 5", "5 3", "2 6 8 11 16", "2 3 5"]], "outputs": [["1", "2", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
7,107
fc0ec349aa0ee9850dea3e85283ddb8d
UNKNOWN
Chef is a really nice and respectful person, in sharp contrast to his little brother, who is a very nasty and disrespectful person. Chef always sends messages to his friends in all small letters, whereas the little brother sends messages in all capital letters. You just received a message given by a string s. You don't...
["t=int(input())\ndef do():\n n,k=map(int,input().split())\n s=input()\n upper=0\n lower=0\n for i in s:\n if i.isupper():\n upper+=1\n else:\n lower+=1\n if lower>k and upper<=k:\n print('chef')\n elif(upper>k and lower<=k):\n print('brother')\n elif(upper<=k and lower<=k):\n print('both')\n else:\n print('n...
{"inputs": [["4", "5 1", "frauD", "5 1", "FRAUD", "4 4", "Life", "10 4", "sTRAWBerry"]], "outputs": [["chef", "brother", "both", "none"]]}
INTERVIEW
PYTHON3
CODECHEF
10,766
f79224608985608c7746f135af7e53d2
UNKNOWN
Alice likes prime numbers. According to Alice, only those strings are nice whose sum of character values at a prime position is prime. She has a string $S$. Now, she has to count the number of nice strings which come before string $S$( including $S$) in the dictionary and are of the same length as $S$. Strings are zer...
["import sys\r\nfrom collections import defaultdict\r\nfrom copy import copy\r\n\r\nMOD = 10**9 + 7\r\n\r\nR = lambda t = int: t(input())\r\nRL = lambda t = int: [t(x) for x in input().split()]\r\nRLL = lambda n, t = int: [RL(t) for _ in range(n)]\r\n\r\n# primes up to n\r\ndef primes(n):\r\n P = []\r\n n = int(n)\r\...
{"inputs": [["1", "abc"]], "outputs": [["10"]]}
INTERVIEW
PYTHON3
CODECHEF
1,145
972da25391d0ad2cd08e685bdf4745bf
UNKNOWN
Navnit is a college student and there are $N$ students in his college .Students are numbered from $1$ to $N$. You are given $M$ facts that "Student $A_i$ and $B_i$".The same fact can be given multiple times .If $A_i$ is a friend of $B_i$ ,then $B_i$ is also a friend of $A_i$ . If $A_i$ is a friend of $B_i$ and $B_i$ is...
["# cook your dish here\r\nfrom collections import defaultdict\r\nd=defaultdict(list)\r\ndef dfs(i):\r\n p=0\r\n nonlocal v\r\n e=[i]\r\n while(e!=[]):\r\n p+=1\r\n x=e.pop(0)\r\n v[x]=1\r\n for i in d[x]:\r\n if v[i]==-1:\r\n v[i]=1\r\n e...
{"inputs": [["5 3", "1 2", "3 4", "1 5"]], "outputs": [["6"]]}
INTERVIEW
PYTHON3
CODECHEF
779
440224781ceebcd81a827984b36da14e
UNKNOWN
A number K$K$ is said to be magical if it can be represented as a power of 2 only.That is K$K$=2x$2^{x}$ for some natural number x$x$. Given a string of digits S$S$ of length N$N$, Let P be a valid arrangement of S. By valid arrangement we mean that it should not have any leading zeroes. Find the sum of all such disti...
["from math import log2, ceil\r\nMOD = int(1e9 + 7)\r\nsrt = lambda s: ''.join(sorted(s))\r\nfor _ in range(int(input())):\r\n s = srt(input())\r\n res = -1\r\n for p in range(ceil(log2(int(s))), int(log2(int(s[::-1]))) + 1):\r\n if int(srt(str(pow(2, p)))) == int(s):\r\n if res == -1: res = ...
{"inputs": [["2", "35566", "31"]], "outputs": [["65536", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
1,430
94b1392882255070d6511ac81f10d316
UNKNOWN
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 ...
["# cook your dish here\ntry:\n for _ in range(int(input())):\n k = int(input())\n num = 1\n for i in range(1,k+1,1):\n for j in range(1,k+1,1):\n print(num*2,end=\"\")\n num = num +1\n print(\"\")\nexcept:\n pass", "t = int(input())\r\n\r\n...
{"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["2", "24", "68", "246", "81012", "141618", "2468", "10121416", "18202224", "26283032"]]}
INTERVIEW
PYTHON3
CODECHEF
5,502
d547bab1a5e0111c8a48667f097afb6b
UNKNOWN
You have been recently hired as a developer in CodeChef. Your first mission is to implement a feature that will determine the number of submissions that were judged late in a contest. There are $N$ submissions, numbered $1$ through $N$. For each valid $i$, the $i$-th submission was submitted at time $S_i$ and judged at...
["# cook your dish here\nfor t in range(int(input())):\n c=0\n for i in range(int(input())):\n s,j=list(map(int,input().split()))\n if (j-s)>5:\n c+=1 \n print(c)\n \n", "for _ in range(int(input())):\n n = int(input())\n\n cnt = 0\n for _ in range(n):\n s, j = map(int, input().split())\n\n if j - s > 5: cnt ...
{"inputs": [["1", "5", "1 3", "4 4", "4 10", "1 11", "2 7"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
4,401