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 |
|---|---|---|---|---|---|---|---|---|---|
c3a8d683660d87f662a06c367ea6e1b7 | UNKNOWN | Chef has an array A = (A1, A2, ..., AN), which has N integers in it initially. Chef found that for i ≥ 1, if Ai > 0, Ai+1 > 0, and Ai+2 exists, then he can decrease both Ai, and Ai+1 by one and increase Ai+2 by one. If Ai+2 doesn't exist, but Ai > 0, and Ai+1 > 0, then he can decrease both Ai, and Ai+1 (which will be t... | ["def fun(a,cur,n,cnt):\n if cur>=n-1:\n return\n for i in range(cur,n-1):\n if i<n-2:\n if a[i]>0 and a[i+1]>0:\n a[i]-=1\n a[i+1]-=1\n a[i+2]+=1\n cnt[0]=(cnt[0]+1)%1000000007\n fun(a,i,n,cnt)\n a[... | {"inputs": [["3", "3", "2 3 1", "2", "2 2", "3", "1 2 3", "", ""]], "outputs": [["9", "4", "9"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,887 | |
5074602fc583d164f453ba33d70e03e1 | UNKNOWN | Richik$Richik$ has just completed his engineering and has got a job in one of the firms at Sabrina$Sabrina$ which is ranked among the top seven islands in the world in terms of the pay scale.
Since Richik$Richik$ has to travel a lot to reach the firm, the owner assigns him a number X$X$, and asks him to come to work o... | ["t=int(input())\r\nfor i in range(t):\r\n x,n=[int(g) for g in input().split()]\r\n sal=0\r\n day=x\r\n while day<n:\r\n sal=sal+day\r\n day+=x\r\n print(sal)\r\n", "for _ in range(int(input())):\r\n\tl,r=map(int,input().split())\r\n\tr=r-1\r\n\tn=r//l\r\n\tsum_=n*(2*l+(n-1)*l)\r\... | {"inputs": [["1", "3 10"]], "outputs": [["18"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,489 | |
d8aa9f828b8a3aea5535fa6d3c92a3ac | UNKNOWN | You have found $M$ different types of jewels in a mine and each type of jewel is present in an infinite number.
There are $N$ different boxes located at position $(1 ,2 ,3 ,...N)$.
Each box can collect jewels up to a certain number ( box at position $i$ have $i$ different partitions and each partition can collect at mo... | ["t = int(input())\nwhile t != 0:\n M = 1000000007\n n, m = list(map(int, input().split())) \n ans = 1\n tt = n//2\n tt = tt * (tt + 1)\n \n ans = pow(m, tt, M)\n \n print(ans)\n t -= 1\n \n \n", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n nm = list(map(int,inpu... | {"inputs": [["2", "1 10", "5 2"]], "outputs": [["1", "64"]]} | INTERVIEW | PYTHON3 | CODECHEF | 7,925 | |
b3f85acc90dcb99bd69e65707481f0ff | UNKNOWN | Lets wish Horsbug98 on his birthday and jump right into the question.
In Chefland, $6$ new mobile brands have appeared each providing a range of smartphones. For simplicity let the brands be represented by numbers $1$ to $6$. All phones are sold at the superstore.
There are total $N$ smartphones. Let $P_i$ & $B_i$ be ... | ["import sys\r\nfrom collections import defaultdict\r\nfrom copy import copy\r\n\r\nR = lambda t = int: t(eval(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\ndef solve():\r\n N, Q = RL()\r\n P = RL()\r\n B = RL()\r\n phones = so... | {"inputs": [["4 2", "4 5 6 7", "1 2 3 4", "3 3", "1 2 3", "3 4", "4 5 6"]], "outputs": [["4", "-1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,506 | |
25adc821fb367e5e0a63a5753adec539 | UNKNOWN | Chef played an interesting game yesterday. This game is played with two variables $X$ and $Y$; initially, $X = Y = 0$. Chef may make an arbitrary number of moves (including zero). In each move, he must perform the following process:
- Choose any positive integer $P$ such that $P \cdot P > Y$.
- Change $X$ to $P$.
- Add... | ["from math import sqrt\n\nT = int(input())\nans = []\n\nfor _ in range(T):\n X = int(input())\n\n count = 0\n x = 0\n y = 0\n while(x<=X):\n p = int(sqrt(y))\n count += 1\n if(p*p>y):\n x = p\n y += p**2\n else:\n x = p+1\n y += (p+1)**2\n if(x<=X):\n ans.append(count)\n else:\n ans.append(count-1)\n\nfo... | {"inputs": [["3", "3", "8", "9"]], "outputs": [["3", "5", "6"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,837 | |
1e46ea42bb815d2decbcb2ffd0d7c6cc | UNKNOWN | The EEE classes are so boring that the students play games rather than paying attention during the lectures. Harsha and Dubey are playing one such game.
The game involves counting the number of anagramic pairs of a given string (you can read about anagrams from here). Right now Harsha is winning. Write a program to he... | ["def sort_str(s):\n o = []\n for c in s:\n o.append(c)\n o.sort()\n return \"\".join(o)\ndef find_ana(s):\n if len(s) <= 1:\n return 0\n h = {}\n c = 0\n for i in range(len(s)):\n for j in range(i+1, len(s)+1):\n t = sort_str(s[i:j])\n if t in h:\n ... | {"inputs": [["3", "rama", "abba", "abcd"]], "outputs": [["2", "4", "0"]]} | INTERVIEW | PYTHON3 | CODECHEF | 478 | |
a880f26667dee2eac7d8aae10b859fe6 | UNKNOWN | It's the annual military parade, and all the soldier snakes have arrived at the parade arena, But they aren't standing properly. The entire parade must be visible from the main podium, and all the snakes must be in a line. But the soldiers are lazy, and hence you must tell the soldiers to move to their new positions in... | ["t=int(input())\n \ndef vsense(val,a,l):\n sense=0\n ctr=a\n for c in range(n):\n if val[c]<=ctr:\n sense+=-1\n else:\n sense+=1\n ctr+=l\n return sense\n \nwhile t:\n n,l,a,b=list(map(int,input().split()))\n val=list(map(int,input().split()))\n val.sort()\n sense=0\n if b==a+n*l or vsense(val,a,l)<=0:\n loc=a... | {"inputs": [["2", "3 4 11 23", "10 11 30", "3 4 11 40", "10 11 30"]], "outputs": [["16", "16"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,815 | |
5160d01afeb8f8565d50dc8c3f0c9eb4 | UNKNOWN | Eugene loves sequences, especially arithmetic progressions. One day he was asked to solve a difficult problem.
If a sequence of numbers A1, A2, ... , AN form an arithmetic progression A, he was asked to calculate sum of F(Ai), for L ≤ i ≤ R.
F(X) is defined as:
If X < 10 then F(X) = X.
Else F(X) = F(sum_of_digits(X)... | ["\n\nimport fractions\nimport sys\n\nf = sys.stdin\n\nif len(sys.argv) > 1:\n f = open(sys.argv[1], \"rt\")\n\n\nsum_cache = {}\n\ndef sum_func(x):\n if x < 10:\n return x\n\n r = sum_cache.get(x)\n if r is not None:\n return r\n\n xx = 0\n while x > 0:\n xx += x % 10\n x ... | {"inputs": [["2", "1 1 1 3", "14 7 2 4", "", ""]], "outputs": [["6", "12"]]} | INTERVIEW | PYTHON3 | CODECHEF | 10,277 | |
3b6f9bc47edbe6a10b0f48f92c1fb697 | UNKNOWN | Tomya is a girl. She loves Chef Ciel very much.
Today, too, Tomya is going to Ciel's restaurant.
Of course, Tomya would like to go to Ciel's restaurant as soon as possible.
Therefore Tomya uses one of the shortest paths from Tomya's house to Ciel's restaurant.
On the other hand, Tomya is boring now to use the same pat... | ["t=eval(input())\ndef func(k,n,x,dist,graph):\n if k==n:\n x+=[dist[n]]\n return\n for i in range(1,n+1):\n if graph[k][i]!=0 and dist[i]==-1:\n dist[i]=dist[k]+graph[k][i]\n func(i,n,x,dist,graph)\n dist[i]=-1\n \nwhile t:\n graph=[[0 for i in range(11)]for j in range(11)]\n v,e=list(map(int,input().split(... | {"inputs": [["2", "3 3", "1 2 3", "2 3 6", "1 3 7", "3 3", "1 2 3", "2 3 6", "1 3 9"]], "outputs": [["1", "2"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,609 | |
90e452788cc8d1cf70b50bb1d383186b | UNKNOWN | It is well-known that the elephants are afraid of mouses. The Little Elephant from the Zoo of Lviv is not an exception.
The Little Elephant is on a board A of n rows and m columns (0-based numeration). At the beginning he is in cell with coordinates (0; 0) and he wants to go to cell with coordinates (n-1; m-1). From c... | ["from collections import defaultdict\nfrom itertools import product\n\ndef solve(mouse,n,m):\n \n # shadow matrix will contains the count of mice which affect (i,j) position\n # if there is a mice at position (i,j) then in shadow matrix it will affect \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0all four adjacent b... | {"inputs": [["2", "3 9", "001000001", "111111010", "100100100", "7 9", "010101110", "110110111", "010011111", "100100000", "000010100", "011011000", "000100101"]], "outputs": [["9", "10"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,113 | |
65c1d158e22563fe9ad76c99f3e15844 | UNKNOWN | One day, Chef found a cube which has each of its sides painted in some color out of black, blue, red, green, yellow and orange.
Now he asks you to check if he can choose three sides such that they are pairwise adjacent and painted in the same color.
-----Input-----
- The first line of the input contains an integer T d... | ["for _ in range(int(input())):\n l=list(map(str,input().split()))\n a=[(1,3,5),(1,3,6),(1,4,5),(1,4,6),(2,3,5),(2,3,6),(2,4,5),(2,4,6)]\n c=0\n for i in a:\n if len(set([l[i[0]-1],l[i[1]-1],l[i[2]-1]]))==1:\n c=1\n break\n if c==1:\n print(\"YES\")\n else:\n print(\"NO\")\n", "# cook your dish here\nfor _ in ra... | {"inputs": [["2", "blue yellow green orange black green", "green yellow green orange black green"]], "outputs": [["NO", "YES"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,807 | |
83c52927eb805c56f16cc06cee2b93c5 | UNKNOWN | Chef has $N$ axis-parallel rectangles in a 2D Cartesian coordinate system. These rectangles may intersect, but it is guaranteed that all their $4N$ vertices are pairwise distinct.
Unfortunately, Chef lost one vertex, and up until now, none of his fixes have worked (although putting an image of a point on a milk carton ... | ["for _ in range(int(input())):\n n=int(input())\n a=[]\n b=[]\n for i in range(4*n-1):\n c,d=list(map(int,input().split()))\n a.append(c)\n b.append(d)\n c1=0\n c2=0\n for i in a:\n c1^=i\n for i in b:\n c2^=i\n print(c1,c2)", "for _ in range(int(input())):\n n=int(input())\n n=n*4-1\n x=0\n y=0\n for z in range(... | {"inputs": [["1", "2", "1 1", "1 2", "4 6", "2 1", "9 6", "9 3", "4 3"]], "outputs": [["2 2"]]} | INTERVIEW | PYTHON3 | CODECHEF | 8,652 | |
28386b6b26a41a83e23101e6aaadd266 | UNKNOWN | Motu and Tomu are very good friends who are always looking for new games to play against each other and ways to win these games. One day, they decided to play a new type of game with the following rules:
- The game is played on a sequence $A_0, A_1, \dots, A_{N-1}$.
- The players alternate turns; Motu plays first, sinc... | ["for _ in range(int(input())):\n n, k = map(int, input().split())\n arr= list(map(int, input().split()))\n motu, tomu = [], []\n for i in range(n):\n if i%2 == 0:\n motu.append(arr[i])\n else:\n tomu.append((arr[i]))\n motu.sort(reverse=True)\n tomu.sort()\n for i in range(len(motu)):\n if len(tomu)-1<i:\n br... | {"inputs": [["2", "6 0", "1 1 1 1 1 1", "5 1", "2 4 6 3 4"]], "outputs": [["NO", "YES"]]} | INTERVIEW | PYTHON3 | CODECHEF | 9,155 | |
a02bc961ea557d2694348004a42d7fef | UNKNOWN | The Gray code (see wikipedia for more details) is a well-known concept.
One of its important properties is that every two adjacent numbers have exactly one different digit in their binary representation.
In this problem, we will give you n non-negative integers in a sequence A[1..n] (0<=A[i]<2^64), such that every two... | ["dic = {}\n#num = \"1\"\n#def tonum(num):\n# res=0\n# for i in range(len(num)):\n# res = 2*res + int(num[i])\n# return res\n\n#for i in range(64):\n# number = tonum(num)\n# dic[num] = []\n# num = num+\"0\"\n\nn = int(input())\nflag=0\nif n >= 68:\n inp = input()\n print(\"Yes\")\nelse:\n inp = [int(x... | {"inputs": [["5", "1 0 2 3 7"]], "outputs": [["Yes"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,490 | |
04c55fa57197aa1e9ef0d70479fe0f02 | UNKNOWN | The chef won a duet singing award at Techsurge & Mridang 2012. From that time he is obsessed with the number 2.
He just started calculating the powers of two. And adding the digits of the results.
But he got puzzled after a few calculations. So gave you the job to generate the solutions to 2^n and find their sum of d... | ["from operator import add\nfrom functools import reduce\n\nchoices=[]\n\nfor x in range(1800):\n num_str = list(map (int, str (2**x)))\n suma = reduce (add, num_str)\n choices.append(suma)\nN=int(input())\n\nfor x in range(N):\n t=int(input())\n print(choices[t])\n", "for _ in range(int(input())):\n i=int(input())\n a... | {"inputs": [["3", "5", "10", "4"]], "outputs": [["5", "7", "7"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,904 | |
6fda0027b77435c609442dd40be5ab1c | UNKNOWN | AND gates and OR gates are basic components used in building digital circuits. Both gates have two input lines and one output line. The output of an AND gate is 1 if both inputs are 1, otherwise the output is 0. The output of an OR gate is 1 if at least one input is 1, otherwise the output is 0.
You are given a digita... | ["# cook your dish here\nclass node:\n\tdef __init__(self,a,b=0,c=0):\n\t\tself.val=a\n\t\tself.a=b\n\t\tself.b=c\n\narr=[]\n\ndef finder(node,val):\n\tif(arr[node].val==0):\n\t\treturn val\n\telse:\n\t\ta=finder(arr[node].a,val)\n\t\tb=finder(arr[node].b,val)\n\t\tif(arr[node].val==1):\n\t\t\treturn a+b-a*b\n\t\telse:... | {"inputs": [["4", "", "1", "0", "", "3", "0", "0", "1 1 2", "", "3", "0", "0", "2 1 2", "", "5", "0", "0", "0", "2 1 2", "1 3 4", "", ""]], "outputs": [["0.50000", "0.29289", "0.70711", "0.40303"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,927 | |
9e037680569c88dcbf8f0e99576a71d3 | UNKNOWN | There are players standing in a row each player has a digit written on their T-Shirt (multiple players can have the same number written on their T-Shirt).
You have to select a group of players, note that players in this group should be standing in $\textbf{consecutive fashion}$. For example second player of chosen g... | ["import sys\n\ndef GRIG(L):\n\n LENT = len(L)\n MINT = 1\n GOT = 0\n\n DY = [ [{x: 0 for x in range(0, 10)}, 0, 0] ]\n\n for i in L:\n\n DY.append([{x: 0 for x in range(0, 10)}, 0, 0])\n GOT += 1\n\n for j in range(0, GOT):\n\n if DY[j][0][i] == 1:\n DY[j][... | {"inputs": [["1", "123343"]], "outputs": [["3"]]} | INTERVIEW | PYTHON3 | CODECHEF | 10,242 | |
a8cc545f3a2452be990ba727156d20bd | UNKNOWN | There is a new prodigy in town and he has challenged people to a game. They have to give him an integer N and he will immediately respond with a number which has more than N factors.
What the prodigy really does is to do some complex calculations in his head to find out the smallest integer with more than N factors. Ho... | ["divisors = [1 , 2 , 3 , 4 , 6 , 8 , 9 , 10 , 12 , 16 , 18 , 20 , 24 , 30 , 32 , 36 , 40 , 48 , 60 , 64 , 72 , 80 , 84 , 90 , 96 , 100 , 108 , 120 , 128 , 144 , 160 , 168 , 180 , 192 , 200 , 216 , 224 , 240 , 256 , 288 , 320 , 336 , 360 , 384 , 400 , 432 , 448 , 480 , 504 , 512 , 576 , 600 , 640 , 672 , 720 , 768 , 80... | {"inputs": [["3", "3", "5", "12345678"]], "outputs": [["win 6", "win 12", "lose"]]} | INTERVIEW | PYTHON3 | CODECHEF | 11,402 | |
4f798093bc395339474f3f28dac4ae19 | UNKNOWN | Given a number n. Find the last two digits of 5 ^ n ( 5 to the power of n ).
Remember that overflow can occur.
-----Input:-----
- N — the power in which you need to raise number 5.
-----Output:-----
Last two digits of 5^n.
-----Constraints-----
- $2 \leq N \leq 2.1018$
-----Sample Input:-----
2
-----Sample Output... | ["print(25)", "import sys\r\nimport math\r\nimport bisect\r\nfrom sys import stdin,stdout\r\nfrom math import gcd,floor,sqrt,log\r\nfrom collections import defaultdict as dd\r\nfrom bisect import bisect_left as bl,bisect_right as br\r\n\r\nsys.setrecursionlimit(100000000)\r\n\r\nii =lambda: int(input())\r\nsi =... | {"inputs": [["2"]], "outputs": [["25"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,892 | |
e5e7f95d5477e127c6e5fd23f2790b72 | UNKNOWN | You are given a set of n pens, each of them can be red, blue, green, orange, and violet in color. Count a minimum number of pens that should be taken out from the set so that any two neighboring pens have different colors. Pens are considered to be neighboring if there are no other pens between them.
-----Input:-----
... | ["t = int(input())\n\nfor _ in range(t):\n n = int(input())\n a = input().strip()\n prev = a[0]\n ans = -1\n for i in a:\n if prev == i:\n ans += 1\n prev = i\n print(ans)\n", "try:\r\n t=int(input())\r\n for _ in range(t):\r\n n=int(input())\r\n s=list(str... | {"inputs": [["2", "5", "RBBRG", "5", "RBGOV"]], "outputs": [["1", "0"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,214 | |
0c4254d08835724547a13d9e72fc39e8 | UNKNOWN | You are standing near a very strange machine. If you put C cents in the machine, the remaining money in your purse will transform in an unusual way. If you have A dollars and B cents remaining in your purse after depositing the C cents, then after the transformation you will have B dollars and A cents. You can repeat t... | ["# cook your dish here\r\nfor _ in range(int(input())):\r\n a,b,c=list(map(int, input().split()))\r\n p=a*100+b\r\n mx=p \r\n ans, cnt = 0, 0\r\n while True:\r\n cnt+=1 \r\n if p<c or cnt==10000:\r\n break\r\n \r\n else:\r\n p-=c \r\n a=p//100... | {"inputs": [["2", "9 77 69", "98 99 69", "", ""]], "outputs": [["4", "0"]]} | INTERVIEW | PYTHON3 | CODECHEF | 3,586 | |
ef840a93b67d299b769c86cc9c586731 | UNKNOWN | Chef likes to play with big numbers. Today, he has a big positive integer N. He can select any two digits from this number (the digits can be same but their positions should be different) and orders them in any one of the two possible ways. For each of these ways, he creates a two digit number from it (might contain le... | ["test=int(input())\nfor i in range(test):\n N=input()\n X=[]\n list2=[]\n for x in N:\n X.append(x)\n list1=[]\n list1=list(set(X))\n output=''\n for x in list1:\n for y in X:\n if int(x)>=6:\n n=int(x)*10+int(y)\n list2.append(n)\n for j in list1:\n if int(j)>=6:\n m=int(j)*10+int(j)\n list2.remove(m)\... | {"inputs": [["4", "65", "566", "11", "1623455078"]], "outputs": [["A", "AB", "ACDFGHIJKLNPQRSTUVW"]]} | INTERVIEW | PYTHON3 | CODECHEF | 8,798 | |
b3e93ec0d5b89ea6dcb56253c5c59d4c | 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\nt=int(input())\nfor _ in range(t):\n n = int(input())\n for i in range(n+1):\n b = n\n for space in range(n-i):\n print(\" \",end=\"\")\n for j in range(i+1):\n print(b,end=\"\")\n b-=1\n print()\n for l in range(n):\n ... | {"inputs": [["2", "2", "4"]], "outputs": [["2", "21", "210", "21", "2", "4", "43", "432", "4321", "43210", "4321", "432", "43", "4"]]} | INTERVIEW | PYTHON3 | CODECHEF | 11,065 | |
d94d511ffad30bb66fbf2a7e6a9f7b18 | UNKNOWN | The chef is having one array of natural numbers. Cheffina challenges chef that find the sum of weights all the natural numbers present in the array, but the main problem is that all numbers have not original weights. After every 6 natural numbers weight is set to 1 as weight increases by 1 after that. (i.e. weight of 1... | ["# cook your dish here\nt = int(input())\nwhile t:\n x = int(input())\n arr = [int(i) for i in input().split()]\n total = 0\n for i in arr:\n if i % 6 == 0:\n total += 6\n else:\n total += (i % 6)\n print(total)\n t -= 1", "import sys\ninput = lambda: sys.stdin.rea... | {"inputs": [["1", "6", "6 7 9 11 4 16"]], "outputs": [["23"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,262 | |
92bfb930312617f548a98fea279fd20a | UNKNOWN | "Don't Drink and Drive, but when you do, Better Call Saul."
Once Jesse and Walter were fighting over extra cash, and Saul decided to settle it with a game of stone piles whose winner gets the extra money. The game is described as follows :
There are N$N$ piles of stones with A$A$1$1$,$,$ A$A$2$2$,$,$ ...$...$ A$A$N$N$ ... | ["n=int(input())\nfor i in range(n):\n k,x=map(int,input().split())\n l=list(map(int,input().split()))\n f,e,o=0,0,0\n for i in l:\n if(i%2==0):\n e+=1\n else:\n o+=1\n if(o<=x//2):\n f=1\n elif(e<=x//2):\n if((k-x)%2!=0):\n f=0\n else:\n f=1\n else:\n if... | {"inputs": [["2", "5 3", "4 4 4 3 4", "7 4", "3 3 1 1 1 2 4"]], "outputs": [["Jesse", "Walter"]]} | INTERVIEW | PYTHON3 | CODECHEF | 2,289 | |
9bcee55fa68f3222331c9c0b954556ad | UNKNOWN | Chef loves to play with arrays by himself. Today, he has an array A consisting of N distinct integers. He wants to perform the following operation on his array A.
- Select a pair of adjacent integers and remove the larger one of these two. This decreases the array size by 1. Cost of this operation will be equal to the... | ["from math import *\nfor t in range(int(input())):\n n = int(input())\n numberlist = list(map(int,input().split()))\n numberlist.sort()\n print(numberlist[0]* ( len(numberlist) -1))", "t=int(input())\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n a.sort()\n m=a[0]\n ans=(len(a)-1)*m\n print(... | {"inputs": [["2", "2", "3 4", "3", "4 2 5"]], "outputs": [["3", "4"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,459 | |
b59c3628ee3fab97df6c5f2a9a07be33 | UNKNOWN | Chef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 5. If any of the permutations is divisible by 5 then print 1 else print 0.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single... | ["a = int(input())\r\nfor i in range(a):\r\n\tb = input()\r\n\tif '5' in b or '0' in b:\r\n\t\tprint(1)\r\n\t\tcontinue\r\n\tprint(0)", "t=int(input())\r\nwhile(t):\r\n n=input()\r\n if('0' in n or '5' in n):\r\n print('1')\r\n else:\r\n print('0')\r\n t=t-1", "t=int(input())\r\nfor t1 in rang... | {"inputs": [["2", "19", "385"]], "outputs": [["0", "1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 7,138 | |
e079259ab17935badb60e8199f0e96b0 | UNKNOWN | A Train started its journey at x=-infinity is travelling on the x-Coordinate Axis. Given n passengers and the coordinates $b_i$ and $d_i$ for each of the $ith$ passenger at which they board and leave from the train respectively. Due to current COVID-19 crisis, the train is monitored at each mile/coordinate. The infecti... | ["c=0\nfor i in range (int(input ())):\n\ta, b=map(int, input().split())\n\tc+=abs(a-b)+1\nprint(c%((10**9) +7)) ", "try:\r\n n=int(input())\r\n sm=0\r\n for i in range(n):\r\n a,b=map( int,input().split() )\r\n sm+=(abs(a-b)+1)\r\n print(sm%1000000007) \r\nexcept:\r\n pass", "def add(arr... | {"inputs": [["3", "0 2", "1 3", "-1 4"]], "outputs": [["12"]]} | INTERVIEW | PYTHON3 | CODECHEF | 9,330 | |
d08bd6d03dfc55835d039e020604e4f2 | 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 ... | ["n = int(input())\r\nl = [0] * n\r\nfor x in range(n):\r\n l[x] = int(input())\r\nfor i in range(n):\r\n z = 1\r\n for j in range(1,l[i]+1):\r\n for k in range(1,l[i]+1):\r\n print(z,end='')\r\n z += 2\r\n print()", "t = int(input())\r\n\r\nfor _ in range(t):\r\n k = int... | {"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["1", "13", "57", "135", "7911", "131517", "1357", "9111315", "17192123", "25272931"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,428 | |
c2c4cf46bfee01e995bd862dcba71613 | UNKNOWN | Walter White and Jesse Pinkman (a drug addict) both love to play with chemicals. One day they were playing with some chemicals to make an energy drink. Unknowingly they made a highly powerful drink. To test the drink on others also they called some of their friends and gave a drop of it to everyone. Now they all were f... | ["# cook your dish here\nl1=int(input())\nfor i in range(l1):\n x=int(input())\n y=list(map(int,input().split()))\n z=list(map(int,input().split()))\n if max(z)!=max(y):\n print('YES')\n else:\n print('NO')", "# cook your dish here\ntry:\n for _ in range(int(input())):\n n = int(i... | {"inputs": [["1", "5", "1 2 3 4 5", "2 7 8 9 9", ""]], "outputs": [["YES"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,833 | |
ab385edb360d3f8668e0ca416e7c8c09 | UNKNOWN | Chef received a permutation $P_1, P_2, \ldots, P_N$ and also an integer $D$ from his good friend Grux, because Grux was afraid he would forget them somewhere. However, since Grux was just playing with the permutation, it was all shuffled, and Chef only likes sorted permutations, so he decided to sort it by performing s... | ["import sys\nsys.setrecursionlimit(10000000)\ndef mergeSortInversions(arr):\n if len(arr) == 1:\n return arr, 0\n larr=len(arr)\n a = arr[:larr//2]\n b = arr[larr//2:]\n a, ai = mergeSortInversions(a)\n b, bi = mergeSortInversions(b)\n c = []\n i = 0\n j = 0\n inversions = 0 + ai + bi\n la=len(a)\n whil... | {"inputs": [["2", "5 2", "3 4 5 2 1", "5 2", "4 3 2 1 5"]], "outputs": [["3", "-1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 29,737 | |
6ca38be9754f58d3b65240fe5bb3f944 | UNKNOWN | Chef has recently learned about number bases and is becoming fascinated.
Chef learned that for bases greater than ten, new digit symbols need to be introduced, and that the convention is to use the first few letters of the English alphabet. For example, in base 16, the digits are 0123456789ABCDEF. Chef thought that thi... | ["# cook your dish here\ndef finder(n):\n cnt=0\n for i in range(2,n+1):\n a=n\n while a!=0:\n r=a%i\n a=a//i\n if r==1:\n cnt+=1\n return cnt\n\nt=int(input())\nfor _ in range(t):\n n=int(input())\n if n==0:\n print(0)\n elif n==1:\n ... | {"inputs": [["4", "6", "9", "11", "24"]], "outputs": [["4", "7", "8", "14"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,070 | |
8a86669623f418c9d026e343ced7e8e9 | UNKNOWN | For a permutation P = (p1, p2, ..., pN) of numbers [1, 2, ..., N], we define the function f(P) = max(p1, p2) + max(p2, p3) + ... + max(pN-1, pN).
You are given N and an integer K. Find and report a permutation P of [1, 2, ..., N] such that f(P) = K, if such a permutation exists.
Note f([1]) = 0.
-----Input-----
- The ... | ["# cook your dish here\nfor i in range(int(input())):\n n,k=[int(i) for i in input().split()]\n if(n%2==0):\n if(k<(n*(n+1))//2 - 1 or k>3*((n//2)**2) - 1):print(-1)\n elif(k==(n*(n+1))//2 - 1):\n for i in range(1,n+1):print(i,'',end='')\n print()\n else:\n k,count,p,l,x = k-(n*(n+1)... | {"inputs": [["3", "4 12", "2 2", "5 14"]], "outputs": [["-1", "1 2", "5 4 3 2 1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 2,018 | |
eb1553dc07e02fb53b40ca07933ce37b | UNKNOWN | Our chef has been assigned a task to make a necklace of length N, from gold, diamond and platinum.There is single kind of gold, two types of diamond and three types of platinum available.
A necklace can be represented as strings of the form (G)∗(D1|D2)∗(P1|P2|P3)∗$ (G)*(D1|D2)*(P1|P2|P3)* $ where (x|y) means we can use... | ["t=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n p=10**9+7\r\n a=(pow(3,n+1,p)-1)\r\n \r\n b=(pow(2,n+1,p)-1)\r\n \r\n print((((3*a)//2)%p-(2*(b))%p+p)%p)", "t=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n p=10**9+7\r\n a=(pow(3,n+1,p)-1)\r\n b=(pow(2,n+1,p)-1)\r\... | {"inputs": [["2", "1", "2"]], "outputs": [["6", "25"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,501 | |
4109aeb9bc16212f3957ce44e8499c30 | UNKNOWN | Chef likes to travel very much. He plans some travel routes and wants to know their lengths. He hired you to make these calculations. But be careful, some of the routes are incorrect. There may be some misspelling in city names or there will be no road between some two consecutive cities in the route. Also note that Ch... | ["import sys\n\ndef _r(*conv) :\n r = [conv[i](x) for i, x in enumerate(input().strip().split(' '))]\n return r[0] if len(r) == 1 else r\n\ndef _ra(conv) :\n return list(map(conv, input().strip().split(' ')))\n\ndef _rl() :\n return list(input().strip())\n\ndef _rs() :\n return input().strip()\n\ndef _a(k, *v) :\n retu... | {"inputs": [["5", "Donetsk Kiev New-York Miami Hollywood", "9", "Donetsk Kiev 560", "Kiev New-York 7507", "New-York Miami 1764", "Miami Hollywood 28", "Hollywood Miami 30", "Miami New-York 1764", "Kiev Donetsk 550", "Hollywood New-York 1736", "New-York Hollywood 1738", "13", "5 Donetsk Kiev New-York Miami Hollywood", "... | INTERVIEW | PYTHON3 | CODECHEF | 6,106 | |
2d0fac041858814f3d5f5debe10b29b7 | UNKNOWN | Given a number $n$, give the last digit of sum of all the prime numbers from 1 to $n$ inclusive.
-----Input:-----
- First line contains number of testcase $t$.
- Each testcase contains of a single line of input, number $n$.
-----Output:-----
Last digit of sum of every prime number till n.
-----Constraints-----
- $1... | ["# cook your dish here\nimport math\nN = 10**6\nsum_arr = [0] * (N + 1) \ndef lprime():\n arr = [0] * (N + 1) \n arr[0] = 1\n arr[1] = 1\n for i in range(2, math.ceil(math.sqrt(N) + 1)): \n if arr[i] == 0: \n for j in range(i * i, N + 1, i): \n arr[j] = 1\n \n curr_... | {"inputs": [["1", "10"]], "outputs": [["7"]]} | INTERVIEW | PYTHON3 | CODECHEF | 13,246 | |
f31b8180819c85caa6fe6dc72782608f | UNKNOWN | People in Karunanagar are infected with Coronavirus. To understand the spread of disease and help contain it as early as possible, Chef wants to analyze the situation in the town. Therefore, he does the following:
- Chef represents the population of Karunanagar as a binary string of length $N$ standing in a line number... | ["# cook your dish here\nT = int(input())\n\nfor i in range(T):\n N,data,D,People = int(input()),list(map(int,list(input()))),int(input()),list(map(int,input().split()))\n \n data.insert(0,\"|\"),data.append(\"|\")\n infected = []\n for i in range(1,N+1):\n if(data[i]==1):\n infected.ap... | {"inputs": [["2", "9", "000010000", "3", "2 5 8", "5", "00001", "1", "5"]], "outputs": [["6", "1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 31,762 | |
c46d66cad349d17f67f190ca46f94b31 | UNKNOWN | Chef wants to organize a contest. Predicting difficulty levels of the problems can be a daunting task. Chef wants his contests to be balanced in terms of difficulty levels of the problems.
Assume a contest had total P participants. A problem that was solved by at least half of the participants (i.e. P / 2 (integer divi... | ["t = int(input())\nfor z in range(t) :\n n,p = [int(x) for x in input().split()]\n a = [int(x) for x in input().split()] \n c = [x for x in a if x >= p//2]\n h = [x for x in a if x <= p//10]\n if len(c)==1 and len(h)==2 :\n print(\"yes\")\n else:\n print(\"no\")", "t = int(input())\nfor z in range(t) :\n n,p = [int(... | {"inputs": [["6", "3 100", "10 1 100", "3 100", "11 1 100", "3 100", "10 1 10", "3 100", "10 1 50", "4 100", "50 50 50 50", "4 100", "1 1 1 1"]], "outputs": [["yes", "no", "no", "yes", "no", "no"]]} | INTERVIEW | PYTHON3 | CODECHEF | 8,182 | |
4e21c25680604638761a00cbb10cb62e | UNKNOWN | You are teaching students to generate strings consisting of unique lowercase latin characters (a-z). You give an example reference string $s$ to the students.
You notice that your students just copy paste the reference string instead of creating their own string. So, you tweak the requirements for strings submitted by ... | ["for _ in range(int(input())):\n s,k=map(str,input().split())\n k=int(k)\n n=\"NOPE\"\n al=[0]*26\n for ele in s:\n al[ord(ele)-ord('a')]=1\n l=len(s)\n ans=[]\n # print(al)\n for i in range(26):\n if len(ans)==l:\n break\n elif al[i]==1 and k>0:\n k-=1\n ans.append(chr(i+ord('a')))\n elif al[i]==0:\n ans.... | {"inputs": [["4", "helowrd 0", "background 0", "abcdefghijklmnopqrstuvwxyz 0", "b 1"]], "outputs": [["abcfgij", "efhijlmpqs", "NOPE", "a"]]} | INTERVIEW | PYTHON3 | CODECHEF | 10,047 | |
7a9f4d1d6caf95ef5cb8a9f703371cd6 | UNKNOWN | Little chef has just been introduced to the world of numbers! While experimenting with addition and multiplication operations, the little chef came up with the following problem:
Given an array A of non-negative integers, how many pairs of indices i and j exist such that A[i]*A[j] > A[i]+A[j] where i < j .
Now bei... | ["# cook your dish here\nt = int(input())\n\nres = []\nfor i in range(t):\n n = int(input())\n arr = [int(i) for i in input().split()]\n \n num_2 = 0\n num = 0\n \n for j in range(len(arr)):\n if arr[j] == 2:\n num_2 += 1\n \n if arr[j] > 2:\n num += 1\n \n res.append(num_2 * num + (num * (num - 1)) // 2)\n \... | {"inputs": [["2", "3", "3 4 5", "4", "1 1 1 1"]], "outputs": [["3", "0"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,360 | |
a74f625eff8285706c45933f17498f7d | UNKNOWN | The chef was chatting with his friend who was a mathematician.
Chef said "Hi !".
His friend replied that '!' is the symbol of factorial.
Chef had never heard about it and he asked more about it. Then his friend taught him how to calculate the factorial of a number.
Chef loved that But as always he got tired after ca... | ["factorials=[1]\n\nfor x in range(1,201):\n factorials.append(factorials[x-1]*x)\n \nx=int(input())\n\nfor x in range(x):\n n=int(input())\n print(factorials[n])", "for _ in range(int(input())):\n t=int(input())\n x=1\n for i in range(2,t+1):\n x*=i\n \n print(x)", "T=eval(input())\nT=int(T)\nwhile T:\n n=eval(input... | {"inputs": [["3", "5", "4", "6"]], "outputs": [["120", "24", "720"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,679 | |
d10f66c3ad212e78334d6c17d3866c65 | UNKNOWN | Chef Zidane likes the number 9. He has a number N, and he wants to turn it into a multiple of 9. He cannot add or remove digits, and he can only change one digit at a time. The only allowed operation is to increment or decrement a digit by one, and doing this takes exactly one second. Note that he cannot increase a dig... | ["s=int(input())\nwhile(s>0):\n s-=1\n a=input()\n c=0\n for x in a:\n c+=int(x)\n if(c<9 and len(a)!=1):\n print(9-c%9)\n else:\n print(min(9-c%9,c%9))\n", "s=int(input())\nwhile(s>0):\n s-=1\n a=input()\n c=0\n for x in a:\n c+=int(x)\n if(c<9 and len(a)!=1):\n print(9-c%9)\n else:\n print(min(9-c%9,c%9))\n", "... | {"inputs": [["4", "1989", "86236", "90210", "99999999999999999999999999999999999999988"]], "outputs": [["0", "2", "3", "2"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,439 | |
3fb798182fede481e13f7d3e54aa06e5 | UNKNOWN | Vasya likes the number $239$. Therefore, he considers a number pretty if its last digit is $2$, $3$ or $9$.
Vasya wants to watch the numbers between $L$ and $R$ (both inclusive), so he asked you to determine how many pretty numbers are in this range. Can you help him?
-----Input-----
- The first line of the input con... | ["# cook your dish here\nt=int(input())\nfor _ in range(t):\n n,m = map(int,input().split())\n count=0\n for i in range(n,m+1):\n p=str(i)\n if p[-1]=='2' or p[-1]=='3' or p[-1]=='9':\n count+=1\n print(count)", "# cook your dish here\nt=int(input())\nfor i in range(t):\n l,r=list(map(int,input().split()))\n ans=0\... | {"inputs": [["2", "1 10", "11 33"]], "outputs": [["3", "8"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,859 | |
3f9623836b1e99c7889bc5b5e6c5891d | UNKNOWN | Lavanya and Nikhil have K months of holidays ahead of them, and they want to go on exactly K road trips, one a month. They have a map of the various cities in the world with the roads that connect them. There are N cities, numbered from 1 to N. We say that you can reach city B from city A if there is a sequence of road... | ["def merge(intervals,start,mid,end):\n al = mid-start+1\n bl = end-mid\n \n A = intervals[start:mid+1]\n B = intervals[mid+1:end+1]\n \n p=0;q=0;k=start;\n while(p<al and q<bl):\n if(A[p]<B[q]):\n intervals[k] = A[p]\n k+=1;p+=1;\n else:\n intervals[k] = B[q]\n k+=1;q+=1;\n \n while(p<al):\n intervals[k] = ... | {"inputs": [["3", "10 10 3", "1 3", "3 5", "5 1", "1 6", "6 2", "5 6", "2 5", "7 10", "4 7", "10 9", "20 0 15 20 25 30 30 150 35 20", "10 10 2", "1 3", "3 5", "5 1", "1 6", "6 2", "5 6", "2 5", "7 10", "4 7", "10 9", "20 0 15 20 25 30 30 150 35 20", "10 10 5", "1 3", "3 5", "5 1", "1 6", "6 2", "5 6", "2 5", "7 10", "4... | INTERVIEW | PYTHON3 | CODECHEF | 23,417 | |
a7f53750abb4e2dd03550f11c70455e1 | UNKNOWN | You have been appointed as the designer for your school's computer network.
In total, there are N computers in the class, and M computer-to-computer connections need to be made. Also, there are three mandatory conditions the design should fulfill.
The first requirement is that any computer in the network should be able... | ["\n\nimport fractions\nimport sys\n\nf = sys.stdin\n\nif len(sys.argv) > 1:\n f = open(sys.argv[1], \"rt\")\n\n\ndef calc(N, M):\n if M != N:\n return [(-1, -1)]\n r = [(i+1, ((i+1) % N)+1) for i in range(N)]\n return r\n\nT = int(f.readline().strip())\n\nfor case_id in range(1, T+1):\n N, M = list(map(int, f.readlin... | {"inputs": [["2", "10 1", "5 5"]], "outputs": [["-1 -1", "1 2", "2 3", "3 4", "4 5", "5 1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 794 | |
470150c75369692c34f87d7c3967744b | UNKNOWN | An area named Renus, is divided into $(N \times M)$ cells. According to archaeological survey the area contains huge amount of treasure. Some cells out of $(N \times M)$ cells contain treasure. But problem is, you can't go to every cell as some of the cells are blocked.
For every $a_{ij}$ cell($1 \leq i \leq N$,$1 \l... | ["t=int(input())\nfor _ in range(t):\n n,m=[int(x) for x in input().split()]\n mat=[]\n ans=[]\n for i in range(n+2):\n l=[]\n p=[]\n for j in range(m+2):\n l.append(0)\n p.append(1000000000)\n mat.append(l)\n ans.append(p)\n y=int(input())\n for i in range(y):\n a,b=[int(x) for x in input().split()]\n mat[a... | {"inputs": [["1", "3 3", "2", "1 1", "1 3", "2", "2 1", "2 2"]], "outputs": [["0 1 0", "X X 1", "4 3 2"]]} | INTERVIEW | PYTHON3 | CODECHEF | 3,181 | |
5d7b90caf219b230bfaa741a92781d97 | UNKNOWN | The chef was playing with numbers and he found that natural number N can be obtained by sum various unique natural numbers, For challenging himself chef wrote one problem statement, which he decided to solve in future.
Problem statement: N can be obtained as the sum of Kth power of integers in multiple ways, find total... | ["for _ in range(int(input())):\n x,n = map(int,input().split())\n reach = [0]*(x+1)\n reach[0] = 1\n i=1\n while i**n<=x:\n j = 1\n while j+i**n<=x:\n j+=1\n j-=1\n while j>=0:\n if reach[j]>0:\n reach[j+i**n]+=reach[j]\n j-=1\n... | {"inputs": [["2", "4 1", "38 2"]], "outputs": [["2", "1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 750 | |
731161549b35908ec23ecfac97473410 | UNKNOWN | Mohit's girlfriend is playing a game with Nicky. The description of the game is as follows:
- Initially on a table Player 1 will put N gem-stones.
- Players will play alternatively, turn by turn.
- At each move a player can take at most M gem-stones (at least 1 gem-stone must be taken) from the available gem-stones on ... | ["r=[0,1,1,2,1,4,2,6,1,8,4]\n\nn,m=[int(x) for x in input().split()]\nif m==1:\n while n%2!=1:\n n=n/2\n if n==1:\n print(1)\n else: \n print(n-1) \nelif (n+1)/2<m:\n print(m)\nelse:\n print(n-m)\n\n \n", "\nn,m=[int(x) for x in input().split()]\nif m==1:\n while n%2!=1:\n n=n/2\n if n==1:\n print(1)\n else: ... | {"inputs": [["4 2"]], "outputs": [["2"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,596 | |
364ab3240aeb6f50178200cced3e8d87 | UNKNOWN | The Head Chef is receiving a lot of orders for cooking the best of the problems lately. For this, he organized an hiring event to hire some talented Chefs. He gave the following problem to test the skills of the participating Chefs. Can you solve this problem and be eligible for getting hired by Head Chef.
A non-negat... | ["def base5(n):\n if n == 0: return\n for x in base5(n // 5): yield x\n yield n % 5\n\ndef seq(n):\n return int(''.join(str(2 * x) for x in base5(n)) or '0')\n\nfor i in range(eval(input())):\n k=eval(input())\n while(i<k):\n i=i+1\n print(seq(i-1))\n", "a=list()\nl=list()\nc=0\nt=eval(input... | {"inputs": [["2", "2", "5", "", ""]], "outputs": [["2", "8"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,074 | |
98e2ddde9e8e18f2ea4d1b775f5cf4cf | UNKNOWN | Chef's younger brother is in town. He's a big football fan and has a very important match to watch tonight. But the Chef wants to watch the season finale of MasterChef which will be aired at the same time. Now they don't want to fight over it like they used to when they were little kids. They want to decide it in a fai... | ["res=\"\"\nfor _ in range(int(input())):\n ans=0\n c=int(input())\n for i in range(c):\n n,m=list(map(int,input().split( )))\n ans^=(n+m-2)%3\n if ans:\n res+=\"MasterChef\\n\"\n else:\n res+=\"Football\\n\"\nprint(res)\n \n \n", "for _ in range(int(input())):\n ans=0\n c=int(input())\n for i in range(c):\n n,m... | {"inputs": [["1", "1", "2 2"]], "outputs": [["MasterChef"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,070 | |
f5d3b83dd8dd43b09d4c725569252de5 | UNKNOWN | Chef likes problems related to learning new languages. He only knows first N letters of English alphabet. Also he explores all M-letter words formed by the characters he knows. Define cost for a given M-letter word S, cost(S) = P1, S1+P2, S2+...+PM, SM, where Pi, j is i, jth entry of matrix P. Sort all the words by des... | ["def dfs(ind,m,n,k):\n if(ind == m):\n return [\"\"]\n else:\n temp = dfs(ind+1,m,n,k)\n ans = []\n if(len(temp)<k):\n for i in temp:\n for j in range(97,97+n):\n ans += [chr(j)+i]\n else:\n for i in temp:\n ans += [\"z\"+i]\n return ans\nn,m,k = list(map(int,input().split()))\np = []\nmr= []\nfor _... | {"inputs": [["2 5 17", "7 9", "13 18", "10 12", "4 18", "3 9"]], "outputs": [["aaaba"]]} | INTERVIEW | PYTHON3 | CODECHEF | 2,260 | |
071de1ceb67d6533fab1ca936b11ace3 | UNKNOWN | There is a universal library, where there is a big waiting room with seating capacity for maximum $m$ people, each of whom completes reading $n$ books sequentially. Reading each book requires one unit of time.
Unfortunately, reading service is provided sequentially. After all of the $m$ people enter the library, the e... | ["while(True):\n \n n, m, x = map(int, input().split())\n\n if(n==0 and m==0 and x==0): \n break\n \n \n money=0\n for i in range(n):\n \n money=money + (x+m*i)//n \n print(money) ", "# cook your dish here\nfrom math import gcd\ndef abc(n, a, d):return n*(2*a + (n-1) * d)//2\nwhile True:\n n, m, x = map(int, input... | {"inputs": [["1 100 9", "11 2 10", "12 2 11", "0 0 0"]], "outputs": [["9", "15", "16"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,258 | |
249be4878ad74942ead079f24b79785c | UNKNOWN | Once again, we have a lot of requests from coders for a challenging problem on geometry. Geometry expert Nitin is thinking about a problem with parabolas, icosahedrons, crescents and trapezoids, but for now, to encourage beginners, he chooses to work with circles and rectangles.
You are given two sequences $A_1, A_2, \... | ["for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n b=list(map(int,input().split()))\n a.sort()\n b.sort()\n s=0\n for i in range(n):\n s+=min(a[i],b[i])\n print(s)", "for t in range(int(input())):\n n = int(input())\n A = sorted(list(map(int, input().split())))\n B = sorted(list(map(... | {"inputs": [["2", "4", "8 8 10 12", "15 20 3 5", "3", "20 20 20", "10 10 10"]], "outputs": [["30", "30"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,832 | |
6d8d18bd9aac0b5b40a2ccac06fc1766 | UNKNOWN | Get excited, folks, because it is time for the final match of Codechef Premier League (CPL)!
Mike and Tracy also want to watch the grand finale, but unfortunately, they could not get tickets to the match. However, Mike is not someone who gives up so easily — he has a plan to watch the match.
The field where the match i... | ["import sys\nsys.setrecursionlimit(100000)\n\nmemo = {}\ndef recurse(arr, T1, T2, k, i):\n if T1 >= k and T2 >= k:\n return i\n\n if i >= len(arr):\n return float('inf')\n\n if (T1, T2) in memo:\n return memo[(T1, T2)]\n\n t1 = recurse(arr, T1 + arr[i], T2, k, i+1)\n t2 = recurse(arr, T1, T2 + arr[i], k, i+1) \n\n ... | {"inputs": [["2", "8 38", "7 8 19 7 8 7 10 20", "4 5", "2 10 4 9"]], "outputs": [["7", "2"]]} | INTERVIEW | PYTHON3 | CODECHEF | 8,499 | |
17a897f88b068af887aa8790f29166a8 | UNKNOWN | You are given a set $S$ and $Q$ queries. Initially, $S$ is empty. In each query:
- You are given a positive integer $X$.
- You should insert $X$ into $S$.
- For each $y \in S$ before this query such that $y \neq X$, you should also insert $y \oplus X$ into $S$ ($\oplus$ denotes the XOR operation).
- Then, you should fi... | ["# fast io\nimport sys\ndef fop(s): sys.stdout.write(str(s)+'\\n')\ndef fip(): return sys.stdin.readline()\nfintinp = lambda : int(fip()) \ndef flistinp(func= int): return list(map(func,fip().split())) \ndef fnsepline(n,func=str): return [func(fip()) for _ in range(n)]\n#-------------------code------------------------... | {"inputs": [["1", "3", "4", "2", "7"]], "outputs": [["0 1", "1 2", "3 4"]]} | INTERVIEW | PYTHON3 | CODECHEF | 13,422 | |
bf9a259c566bc672cef4daf6569e0ee2 | UNKNOWN | Given an integer $x$, find two non-negative integers $a$ and $b$ such that $(a \wedge b) + (a \vee b) = x$, where $\wedge$ is the bitwise AND operation and $\vee$ is the bitwise OR operation.
-----Input-----
- The first line of the input contains a single integer $T$ denoting the number of test cases. The description ... | ["# cook your dish here\nn=int(input())\nfor _ in range(n):\n a=int(input())\n if(a%2==0):\n f=(a//2)-1\n s=a-f\n else:\n f=(a//2)\n s=a-f\n print(f,s)"] | {"inputs": [["2", "1", "8"]], "outputs": [["0 1", "5 3"]]} | INTERVIEW | PYTHON3 | CODECHEF | 157 | |
46a82e80ba3ed5ea7e23a72b9aeb1415 | UNKNOWN | There is a haunted town called HauntedLand. The structure of HauntedLand can be thought of as a grid of size n * m. There is a house in each cell of the grid. Some people have fled from their houses because they were haunted. '.' represents a haunted house whereas '*' represents a house in which people are living.
One... | ["import math\n\n\nt = int(input().strip())\n\nfor _ in range(t):\n n, m = list(map(int, input().strip().split()))\n a = []\n v = [-1] * 4\n\n for i in range(n):\n a.append(input().strip())\n\n for i, ai in enumerate(a):\n if ai.find('*') > -1:\n v[2] = i\n break\n\n if v[2] == -1:\n print(0)\n else:\n\n for i,... | {"inputs": [["2", "2 2", "*.", "..", "3 4", ".*..", "***.", ".*.."]], "outputs": [["1", "2"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,981 | |
852d298a28bba55be5c885776c91c69b | 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().strip())):\n n = int(input().strip())\n lst = []\n for i in range(n):\n lst.append(i+1)\n lst.append(1)\n #print(lst)\n for i in range(n):\n print(''.join(str(e) for e in lst))\n for x in range(n):\n lst[x * 2 + 1] += 1\n", "# cook your ... | {"inputs": [["3", "2", "3", "4"]], "outputs": [["1121", "1222", "112131", "122232", "132333", "11213141", "12223242", "13233343", "14243444"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,291 | |
b4cce6e55828ee759caa5ed264085c9d | UNKNOWN | N Soldiers are lined up for a memory test. They are numbered from 0 to N-1 from left to right.
In the test, there are M rounds. In each round, Captain selects one position. Soldier at that position will be numbered 0. All the soldiers to the right of selected position will be numbered one greater than the soldier to ... | ["test = int(input())\nfor _ in range(test):\n n, m = map(int, input().split())\n indexArray = list(map(int, input().split()))\n mini = min(indexArray)\n maxi = max(indexArray)\n result = n*[0]\n for i in range(n):\n result[i] = max(maxi - i, i - mini)\n print(result[i], end=\" \")\n print()", "test = int(input())\nf... | {"inputs": [["2", "4 1", "1", "6 2", "2 3"]], "outputs": [["1 0 1 2", "3 2 1 1 2 3"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,726 | |
f6ce779538fe835fdc054abe6000dc01 | UNKNOWN | Chef Tobby is trying to run a code given to him by Bhuvan for an experiment they want to include in the manuscript to be submitted to a conference. The deadline to submit the manuscript is within a couple of hours and Chef Tobby needs to finish the experiments before then.
The code given by Bhuvan is the following whic... | ["from bisect import *\nfor x in range(eval(input())):\n n,k = list(map(int,input().split()))\n arr = list(map(int,input().split()))\n arr.sort()\n t = 1\n result = 0\n y = 0\n while y < n:\n if arr[y]<t:\n y += 1\n elif arr[y]==t:\n t = t*2\n y += 1\n else:\n result += 1\n t = t*2\n \n while t < 2**(k):\n... | {"inputs": [["- 1", "1", "2 2", "3 1"]], "outputs": [["1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 2,590 | |
e30630d58bbf5dff7b4baf7050caf6ce | UNKNOWN | Chef recently opened a big e-commerce website where her recipes can be bought online. It's Chef's birthday month and so she has decided to organize a big sale in which grand discounts will be provided.
In this sale, suppose a recipe should have a discount of x percent and its original price (before the sale) is p. Stat... | ["for i in range(int(input())):\n n=int(input())\n s=0\n for i in range(n):\n a,b,c=map(int,input().split())\n d=(c/100)*a\n e=a+d\n f=e-((c/100)*e)\n g=a-f\n h=b*g\n s=s+h\n print(s)", "for i in range(int(input())):\n n=int(input())\n s=0\n for i in range(n):\n a,b,c=list(map(int,input().split()))\n d=(c/100)... | {"inputs": [["2", "2", "100 5 10", "100 1 50", "3", "10 10 0", "79 79 79", "100 1 100"]], "outputs": [["30.000000000", "3995.0081000"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,653 | |
924265496027162fdb299f6b6e2cbd4a | UNKNOWN | A plot of land can be described by $M x N$ dots such that horizontal and vertical distance between any two dots is 10m.
Mr. Wolf would like to build a house in the land such that all four sides of the house are equal. Help Mr. Wolf to find the total number of unique positions where houses can be built. Two positions ar... | ["# cook your dish here\nfrom sys import stdin,stdout,setrecursionlimit\nfrom math import ceil\n\nmod = 1000000007\nt = int(stdin.readline())\nfor _ in range(t):\n m,n = list(map(int,input().split()))\n if m < n:\n m,n = n,m\n\n y = n-1\n s1 = ((y*(y+1)) //2)%mod\n s2 = ((y*(y+1)*(2*y+1)) //6)%mod... | {"inputs": [["4", "2 4", "3 4", "4 4", "1000 500"]], "outputs": [["3", "10", "20", "624937395"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,186 | |
470ce3f53720f92cf1f8eb70ca46102d | UNKNOWN | Chef hates unoptimized codes and people who write such codes. One fine day he decided to look through the kitchen's codebase and found a function whose pseudo-code is given here:
input: integer N, list X[1, 2, ..., N], list Y[1, 2, ..., N]
output: integer res
function:
set res = 0;
for i := 1 to N do
for j := 1 to ... | ["# cook your dish here\nfor _ in range(int(input())):\n d=dict()\n ls=[]\n for i in range(int(input())):\n ls=list(map(int,input().split()))\n if ls[0] in d:\n d[ls[0]]=max(ls[1],d[ls[0]])\n else:\n d[ls[0]]=ls[1]\n # print(d)\n if len(d)<3:\n print(0)\n else:\n kd=list(d.values())\n kd.sort()\n # print(kd)... | {"inputs": [["2", "3", "1 3", "3 1", "1 2", "5", "1 3", "2 4", "1 2", "3 2", "3 4"]], "outputs": [["0", "11"]]} | INTERVIEW | PYTHON3 | CODECHEF | 8,071 | |
db0d595ba9b0057fefb974c3f9517ead | UNKNOWN | Emily and Mia are friends. Emily got Mia’s essay paper, but since she is a prankster, she decided to meddle with the words present in the paper. She changes all the words in the paper into palindromes. To do this, she follows two rules:
- In one operation she can only reduce the value of an alphabet by 1, i.e. she ca... | ["t=int(input())\r\nfor _ in range(t):\r\n xyz = input().strip()\r\n \r\n string = 0\r\n\r\n for i in range(len(xyz)//2):\r\n string = string + (abs(ord(xyz[i])-ord(xyz[len(xyz)-i-1])))\r\n \r\n print(string)", "# cook your dish here\nnumbers = int(input())\nfor x in range(numbers):\n ... | {"inputs": [["4", "abc", "abcba", "abcd", "cba"]], "outputs": [["2", "0", "4", "2"]]} | INTERVIEW | PYTHON3 | CODECHEF | 10,309 | |
fd42e0f59c78c72302bea6bb6f580692 | UNKNOWN | Chef likes all arrays equally. But he likes some arrays more equally than others. In particular, he loves Rainbow Arrays.
An array is Rainbow if it has the following structure:
- First a1 elements equal 1.
- Next a2 elements equal 2.
- Next a3 elements equal 3.
- Next a4 elements equal 4.
- Next a5 elements equal ... | ["t=int(input())\nx=[1,2,3,4,5,6,7]\nfor i in range(t):\n N=int(input())\n a=list(map(int,input().split())) \n rev=a[::-1] \n dup=set(a) \n if rev== a and list(dup) ==x: \n print(\"yes\")\n else:\n print(\"no\")", "# cook your dish here\nt=int(input())\nx=[1,2,3,4,5,6,7]\nfor i in range(t):\n N=int(input())\n a=li... | {"inputs": [["3", "19", "1 2 3 4 4 5 6 6 6 7 6 6 6 5 4 4 3 2 1", "14", "1 2 3 4 5 6 7 6 5 4 3 2 1 1", "13", "1 2 3 4 5 6 8 6 5 4 3 2 1"]], "outputs": [["yes", "no", "no"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,989 | |
291c08fd547b59f782a9e8236bc1a3d4 | UNKNOWN | You are given positive integers $L$ and $R$. You have to find the sum
S=∑i=LR(L∧(L+1)∧…∧i),S=∑i=LR(L∧(L+1)∧…∧i),S = \sum_{i=L}^R \left(L \wedge (L+1) \wedge \ldots \wedge i\right) \,,
where $\wedge$ denotes the bitwise AND operation. Since the sum could be large, compute it modulo $10^9+7$.
-----Input-----
- The first... | ["l= []\nfor i in range(62):\n l.append(2**i)\nT = int(input())\n\nflag = 0\nfor t in range(T):\n L,R = [int(i) for i in input().split()]\n bL = bin(L)\n lL = len(bL)-2\n index = 1\n ans = 0\n temp = 0\n \n while(index<=lL):\n temp = L%l[index]\n if temp>=l[index-1]:\n if(l[index]-temp<=R-L+1):\n ans= (ans +(l[i... | {"inputs": [["2", "1 4", "4 10"]], "outputs": [["1", "16"]]} | INTERVIEW | PYTHON3 | CODECHEF | 8,978 | |
d0203c07399375cac83c714472ce0739 | UNKNOWN | Chef likes prime numbers. However, there is one thing he loves even more. Of course, it's semi-primes! A semi-prime number is an integer which can be expressed as a product of two distinct primes. For example, $15 = 3 \cdot 5$ is a semi-prime number, but $1$, $9 = 3 \cdot 3$ and $5$ are not.
Chef is wondering how to ch... | ["# cook your dish here\r\nimport sys\r\nn = 201\r\nv = [0 for i in range(n + 1)] \r\n\r\ndef gen():\r\n for i in range(1, n + 1): \r\n v[i] = i \r\n \r\n countDivision = [0 for i in range(n + 1)] \r\n \r\n for i in range(n + 1): \r\n countDivision[i] = 2\r\n \r\n for i in range(2, n ... | {"inputs": [["3", "30", "45", "62", ""]], "outputs": [["YES", "YES", "NO"]]} | INTERVIEW | PYTHON3 | CODECHEF | 19,754 | |
0c6d7d5b16df0fc7ef217f4cb5f25f3d | UNKNOWN | Coach Khaled is a swag teacher in HIT (Hag Institute of Technology). However, he has some obsession problems.
Recently, coach Khaled was teaching a course in building 8G networks using TV antennas and programming them with assembly. There are $N$ students (numbered $1$ through $N$) in his class; for some reason, this n... | ["# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n k = n//4\n # a,b,c = map(int,input().split())\n a = sorted(map(int,input().split()))\n a60 = (a[k-1],a[k])\n a75 = (a[2*k-1],a[2*k])\n a90 = (a[3*k-1],a[3*k])\n if a60[0]==a60[1] or a75[0]==a75[1] or a90[0]==a90[1] :\n print(-1)\n else :\n pr... | {"inputs": [["6", "4", "90 25 60 75", "8", "27 29 92 92 67 67 85 92", "4", "0 1 2 3", "4", "100 100 100 100", "4", "30 30 40 50", "4", "30 40 40 50"]], "outputs": [["60 75 90", "-1", "1 2 3", "-1", "-1", "-1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,725 | |
654f637dffffed401d567237bdbbea00 | UNKNOWN | Chef is learning linear algebra. Recently, he learnt that for a square matrix $M$, $\mathop{\rm trace}(M)$ is defined as the sum of all elements on the main diagonal of $M$ (an element lies on the main diagonal if its row index and column index are equal).
Now, Chef wants to solve some excercises related to this new qu... | ["# cook your dish here\nT=int(input())\nfor k in range(0,T):\n N=int(input())\n matrix=[]\n for i in range(0,N):\n a=list(map(int, input().split()))\n matrix.append(a)\n max_trace = []\n for i in range(0,N):\n trace1=0\n trace2=0\n for j in range(0,i+1):\n trace1+=matrix[j][N+j-i-1]\n trace2+=matrix[N+j-i-1][... | {"inputs": [["1", "3", "1 2 5", "6 3 4", "2 7 1"]], "outputs": [["13"]]} | INTERVIEW | PYTHON3 | CODECHEF | 8,834 | |
d71755ba2b9d0c82307cb30c27404308 | UNKNOWN | Wet Shark once had 2 sequences:
{a_n}= {a_1, a_2, a_3, ... , a_(109)}
{b_n} = {b_1, b_2, b_3, ... , b_(109)}
However, he only kept one element from each sequence. Luckily, both the elements that Wet Shark kept have the same index in Wet Shark's sequences: that is, he took a_i and b_i for some 1 ≤ i ≤ 109.
Right a... | ["import math\r\n\r\ndef main():\r\n #print(\"enter i, k, s\")\r\n IN = '11 6 5'\r\n z = IN.split()\r\n z = input().split()\r\n i = int(z[0])\r\n k = int(z[1])\r\n s = int(z[2])\r\n\r\n #print(\"enter a_i and b_i\")\r\n IN = '4 5'\r\n z = IN.split()\r\n z = input().split()\r\n a_i = int(z[0])\r\n b_i = int... | {"inputs": [["1 1 5", "4 5"]], "outputs": [["0.28125"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,941 | |
413995e6848aee78fde4e37f09be8bed | UNKNOWN | You are given a string $s$. And you have a function $f(x)$ defined as:
f(x) = 1, if $x$ is a vowel
f(x) = 0, if $x$ is a constant
Your task is to apply the above function on all the characters in the string s and convert
the obtained binary string in decimal number $M$.
Since the number $M$ can be very large, compute... | ["t=int(input())\nMOD=(10**9)+7\nl=['a','e','i','o','u']\nfor i in range(t):\n s=input()\n k=[]\n for j in s:\n if j in l:\n k.append(1)\n else:\n k.append(0)\n r=bin(int(''.join(map(str, k)), 2) << 1)\n print((int(r,2)//2)%MOD)\n", "for _ in range(int(input())):\n s=input()\n ss=list(s)\n for n, i in enumerate(s... | {"inputs": [["1", "hello"]], "outputs": [["9"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,590 | |
7017fe4d70c7330ae8a09270b2a24587 | UNKNOWN | Chef Shifu wanted to celebrate the success of his new restaurant with all his employees. He was willing to host a party and he had decided the location of the party as well. However, Chef Shifu was a shy person and wanted to communicate with the least possible employees to inform them about the party, and that these em... | ["t=int(input())\nfor _ in range(t):\n n,m=map(int,input().split())\n mat=[0 for i in range(n)]\n #mat=[[0 for i in range(n)] for j in range(n)]\n for i in range(m):\n u,v=map(int,input().split())\n u,v=(u-1),(v-1)\n mat[u]|=(1<<v)\n mat[v]|=(1<<u)\n for i in range(n):\n mat[i]|=(1<<i... | {"inputs": [["2", "3 3", "1 2", "2 3", "1 3", "4 3", "1 2", "2 3", "3 4"]], "outputs": [["1", "2"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,197 | |
d24c8ef29f393722f5ac0c179a72c75d | UNKNOWN | So the Chef has become health conscious and is now lifting weights at the gym. But its his first time so the trainer gives him a simple job to do.
He has been given a weight lifting rod and N heavy weights, each weighing 20, 21, .... , 2n-1. He has to stick each of the "N" weights on the rod, one after another, in su... | ["t = int(input())\n\nwhile(t>0):\n \n n=int(input())\n if(n<=0):\n print(0)\n \n fact=1\n start=1\n for i in range(1,n+1):\n fact*=start\n start+=2\n print(fact)\n \n t=t-1\n", "#!/usr/bin/env python\n\n'''\nfrom sys import stderr\n\ndef f(maxG, remaining):\n #stderr.write('%s %s\\n' % (maxG, remaining))\n if... | {"inputs": [["3", "2", "5", "18"]], "outputs": [["3", "945", "221643095476699771875"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,527 | |
63768d1b1caaf4df9f1d9f0689f2dd61 | UNKNOWN | Write a program to obtain a number $(N)$ from the user and display whether the number is a one digit number, 2 digit number, 3 digit number or more than 3 digit number
-----Input:-----
- First line will contain the number $N$,
-----Output:-----
Print "1" if N is a 1 digit number.
Print "2" if N is a 2 digit number.
P... | ["# cook your dish here\nx=input ()\ny=len (x)\nif y==1:\n print('1')\nelif y==2:\n print('2')\nelif y==3:\n print('3')\nelif y>3:\n print('More than 3 digits')", "# cook your dish here\nn = input()\nl = len(n)\n\nif l==1:\n print(1)\nelif l==2:\n print(2)\nelif l==3:\n print(3)\nelse:\n print(\"More than 3 digits\")",... | {"inputs": [["9"]], "outputs": [["1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 3,366 | |
bb844c57ee2d4c162045ce14ab509b27 | UNKNOWN | Did you hear about the Nibiru collision ? It is a supposed disastrous encounter between the earth and a large planetary object. Astronomers reject this idea. But why listen to other people's beliefs and opinions. We are coders above all, so what better way than to verify it by a small code. The earth and N asteroids ar... | ["#-*- coding:utf-8 -*-\n\nimport sys\n\n\n# class Point:\n# def __init__(self, x, y):\n# self.x = x\n# self.y = y\n\n# def mul(self, k):\n# return Point(k * self.x, k * self.y)\n\n# def __add__(self, other):\n# return Point(self.x + other.x, self.y + other.y)\n\n# def __... | {"inputs": [["3", "0 0 R", "2", "1 -2 U", "2 2 D", "1 1 U", "1", "1 0 U", "0 0 R", "1", "3 0 L"]], "outputs": [["2.0", "SAFE", "1.5"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,113 | |
75530d3c0bbb7b5c9afbb98371ac0e3b | UNKNOWN | You are given a grid of size N x M consisting of '.' (empty), 'W' (white) or 'B' (black) cells. We follow the convention that the top left corner is the position (1,1) and bottom right corner is (N,M).
From every '.' cell (i, j), a ray is shot towards the right. If the ray reaches a 'B' cell, it loses it's strength fu... | ["# cook your dish here\nfrom operator import itemgetter\ninp=list(map(int, input().split()))\nn, m, w, b = inp[:4]\nstops=[]\nfor i in range(w):\n stops.append((inp[4+2*i]-1,inp[5+2*i]-1,'w'))\nfor i in range(b):\n stops.append((inp[4+2*w+2*i]-1,inp[5+2*w+2*i]-1,'b'))\nstops.sort(key=itemgetter(1))\nstops.sort(key=ite... | {"inputs": [["4 4 5 2 1 3 2 1 3 2 3 3 4 3 1 4 2 3"]], "outputs": [["22"]]} | INTERVIEW | PYTHON3 | CODECHEF | 17,019 | |
b03b3c3efff975e7e653ace8a5c0c383 | UNKNOWN | Chef and his friend Miron were getting bored and decided to play a game.
Miron thinks of a sequence of N integers (A1, A2, …., AN) and gives Chef a matrix B, where Bi,j = |Ai - Aj|. He further tells Chef that A1 = 0. The game is for Chef to guess the sequence that Miron thought of.
But Miron is an adversarial playe... | ["def update_B(B, query):\n p, R = query\n for i in range(len(R)):\n B[p][i] = R[i]\n B[i][p] = R[i]\n\ndef get_A(B):\n N = len(B)\n A = [0] * N\n i = 0\n for j in range(N):\n if B[0][j] != 0:\n i = j\n A[i] = -B[0][i]\n break\n\n for j in range(i + 1, N):\n if abs(A[i] - B[0][j]) == B[i][j]:\n A[j] = B[0][... | {"inputs": [["3 2", "0 1 2", "1 0 1", "2 1 0", "1", "0 4 3", "2", "4 0 7"]], "outputs": [["0 -1 -2", "0 -4 -3", "0 -4 3"]]} | INTERVIEW | PYTHON3 | CODECHEF | 814 | |
396bf82a0b3998bfb9fd90f674a20da0 | UNKNOWN | "Say my Name".
Todd Alquist is being taught the process of cooking methamphetamine, but to see whether he's really capable of learning it, Walt gives him a problem to solve. Since he can't solve it, he asks you for help.
You are given a tree with $N$ vertices (numbered $1$ through $N$), rooted at the vertex $1$. There ... | ["# cook your dish here\nimport sys,collections\ninput=sys.stdin.readline\ndef main():\n T=int(input())\n for _ in range(T):\n N,K=map(int,input().split())\n Tree={}\n for j in range(N):\n Tree[j]=[]\n \n for i in range(N-1):\n u,v=map(int,input().split())\n Tree[u-1].append(v-1)\n Tree[v-1].append(u-1)\n... | {"inputs": [["1", "6 85", "1 2", "2 3", "2 4", "4 5", "3 6", "3 5 4 7 1 9"]], "outputs": [["YES"]]} | INTERVIEW | PYTHON3 | CODECHEF | 11,516 | |
c55680a7477eed26f2a0799849f6367b | UNKNOWN | In the year 4242, the language Haskell has evolved so much that it has become an AI. It can solve very challenging problems, in very little time. Humanity is worried that Haskell will take over the world. All hopes remain tied to the Competitive Programming community as they are the expert in shaving milliseconds off c... | ["mod=10**9+7\ndef fibonacci(n):\n if n < 0:\n raise ValueError(\"Negative arguments not implemented\")\n return (_fib(n)[0]%mod + mod)%mod;\ndef _fib(n):\n if n == 0:\n return (0, 1)\n else:\n a, b = _fib(n // 2)\n c = (a * (b * 2 - a))%mod\n d = (a * a + b * b)%mod\n if n % 2 == 0:\n return (c, d)\n else:\n ... | {"inputs": [["1", "1 1"]], "outputs": [["1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 729 | |
0e3f5ac50abe9aed4bd87bfa2a066aa5 | UNKNOWN | In Byteland there are N cities, numbered 1 through N. Some pairs of cities are connected by bi-directional roads in such a way that starting from any one city you can visit all other cities either directly or indirectly.
Chef is currently at city A and wants to visit all other cities in Byteland. Chef can only move ac... | ["import sys\nsys.setrecursionlimit(10**8)\n\nMOD = 10**9+7\n\nfac = [0]*(10**5+1)\ndef pre() :\n fac[0] = 1\n for i in range(1,10**5+1) :\n fac[i] = fac[i-1]*i\n fac[i] = fac[i]%MOD\n\ndef dfs(gp , vertex , visited , deg , ans) :\n visited[vertex] = 1\n stack = []\n stack.append(vertex)\n while len(stack)>0 :\n ver... | {"inputs": [["2", "3", "1 2", "1 3", "1", "5", "1 2", "1 3", "2 4", "2 5", "1"]], "outputs": [["2", "4"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,997 | |
f644e48f31f85568e511b60446551618 | UNKNOWN | Chef has just started Programming, he is in first year of Engineering. Chef is reading about Relational Operators.
Relational Operators are operators which check relatioship between two values. Given two numerical values A and B you need to help chef in finding the relationship between them that is,
- First one is ... | ["# cook your dish here\nfor _ in range(int(input())):\n x, y= map(int, input().split())\n if x<y:\n print('<')\n elif x>y:\n print('>')\n else:\n print('=')", "t=int(input())\nfor i in range(t):\n a,b=list(map(int,input().split()))\n if a>b:\n print(\">\")\n elif b>a:\n... | {"inputs": [["3", "10 20", "20 10", "10 10"]], "outputs": [["<", ">", "="]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,103 | |
4859347f68d0cc2455d9e0d2b2dcaa40 | UNKNOWN | Batman is about to face Superman so he decides to prepare for the battle by upgrading his Batmobile. He manufactures multiple duplicates of his standard Batmobile each tweaked in a different way such that the maximum speed of each is never less than that of the standard model.
After carrying out this process, he wishes... | ["t = int(input())\nwhile(t):\n n = int(input())\n ar = list(map(int,input().strip().split(\" \")))\n print(len([x for x in ar[1:len(ar)] if ar[0]<x]))\n t-=1\n", "t=eval(input())\nwhile t>0:\n n=eval(input())\n input_arr=input().split(' ')\n counter=0\n for i in range(1,n+1):\n if(int(input_arr[0])<int(input_arr[i]))... | {"inputs": [["2", "4", "1 2 3 4 5", "5", "1 10 100 1000 10000 100000"]], "outputs": [["4", "5"]]} | INTERVIEW | PYTHON3 | CODECHEF | 3,983 | |
ce923f2ee25f45b43bebd47e94e0393f | UNKNOWN | Chef has $N$ dishes of different types arranged in a row: $A_1, A_2, \ldots, A_N$, where $A_i$ denotes the type of the $i^{th}$ dish. He wants to choose as many dishes as possible from the given list but while satisfying two conditions:
- He can choose only one type of dish.
- No two chosen dishes should be adjacen... | ["t=int(input())\nf=0\ny=0\nfor _ in range(t):\n n=int(input())\n seq=[int(x) for x in input().split()]\n prev=seq[0]\n for i in range(1,len(seq)):\n if prev==seq[i]:\n seq[i]=0\n prev=seq[i] \n ans=0\n anss=0\n for el in seq:\n if el!=0:\n c=seq.count(el)\n if ans<c:\n ans=c\n \n anss=el\n elif ans... | {"inputs": [["3", "5", "1 2 2 1 2", "6", "1 1 1 1 1 1", "8", "1 2 2 2 3 4 2 1"]], "outputs": [["1", "1", "2"]]} | INTERVIEW | PYTHON3 | CODECHEF | 9,892 | |
f1381659b73a7999d0bdb093c98807d1 | UNKNOWN | Sunita has lots of tasks pending and she has no time to complete. She needs your help and wants you complete the task.
You are given a list of integers and two values $N$ and $K$ $-$ the size of array of integers and the numbers of partitions to be made respectively.
You have to partition the list of integers without ... | ["from sys import stdin,stdout\r\nfrom math import gcd\r\nfor _ in range(int(stdin.readline())):\r\n # n=int(stdin.readline()) k-pieces\r\n n,k=list(map(int,stdin.readline().split()))\r\n a=list(map(int,stdin.readline().split()))\r\n gr=[[0 for _ in range(n)]for _ in range(n)];ans=0;k-=1\r\n for sz in ra... | {"inputs": [["1", "4 2", "5 6 3 2"]], "outputs": [["6"]]} | INTERVIEW | PYTHON3 | CODECHEF | 873 | |
36fca690a74ed3b9bcadad5dfc48c63f | UNKNOWN | The chef has a number N, Cheffina challenges chef to form the largest number X from the digits of N.
-----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 l... | ["# cook your dish here\nn=int(input())\nl=[]\nfor i in range(n):\n a=int(input())\n l.append(a)\nfor i in l:\n b = list(map(int, str(i)))\n b.sort(reverse=True)\n s = [str(i) for i in b]\n r = int(\"\".join(s))\n print(r)", "# cook your dish here\nresult=[]\nfor i in range(int(input())):\n m=in... | {"inputs": [["2", "2", "212"]], "outputs": [["2", "221"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,152 | |
af36556f841ba6cbe19d7c159c8a7558 | UNKNOWN | The Chef has bought $N$ boxes of Tiles. The number of tiles present in $i^{th}$ box is $i$ ($i $ varies from $1$ to $N$) . The Chef has two houses with $N$ rooms each, whose floors is a square with area $(i*i)$ ,i varies from $(1....N)$. He want to distribute equal number of tiles from $i^{th}$ box to any... | ["from sys import stdin\r\n\r\nfor _ in range(int(stdin.readline())):\r\n n = int(stdin.readline())\r\n n //= 2\r\n k = 2 * int(n**0.5)\r\n print(k)\r\n", "# cook your dish here\nfrom math import sqrt\ndef solve(N):\n\n return int(sqrt(N/2)) * 2\n\n\nt = int(input())\n\nfor i in range(t):\n N = int(in... | {"inputs": [["1", "16"]], "outputs": [["4"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,473 | |
b4ba8713de9d9dfd35f2f44c616012b7 | UNKNOWN | After the death of their mother, Alphonse and Edward now live with Pinako and Winry.
Pinako is worried about their obsession with Alchemy, and that they don't give attention to their studies.
So to improve their mathematical solving ability, every day she gives a mathematical problem to solve. They can go out to pract... | ["# cook your dish here\nmod = 10**9 + 7\nfor i in range(int(input())):\n n,k,m = tuple(map(int, input().split()))\n a = list(map(int, input().split()))\n ans = [0 for i in range(k+1)]\n ans[0] = 1\n curr_ending = 1\n for i in range(n):\n mod_a = a[i]%m\n start = curr_ending - (curr_ending%m -... | {"inputs": [["1", "12 4 3", "4 5 6 7 1 4 6 9 0 0 10 2"]], "outputs": [["8"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,176 | |
9ab869724b27a250f95cf477239f8311 | UNKNOWN | It is an interesting exercise to write a program to print out all permutations of $1, 2, …, n$. However, since there are $6227020800$ permutations of $1, 2, …, 13$, it is unlikely that we would ever run this program on an input of size more than $10$.
However, here is another interesting problem whose solution can also... | ["import sys\n# import math as mt\n# from collections import Counter\n# from itertools import permutations\n# from functools import reduce\n# from heapq import nsmallest, nlargest, heapify, heappop, heappush, heapreplace\n\ndef get_inpt(): return sys.stdin.readline().strip()\ndef get_int(): return int(sys.stdin.readlin... | {"inputs": [["3 2", "3 1 2", "2 3 1", ""]], "outputs": [["3 2 1", "3 1 2 "]]} | INTERVIEW | PYTHON3 | CODECHEF | 3,212 | |
dc032012560522d213c01d0df384ed15 | UNKNOWN | Due to the COVID pandemic, there has been an increase in the number of cases if a hospital. The management has decided to clear a large square area for the patients and arrange for beds. But the beds can't be too near to each other.
The area is of dimension $N$ x $N$
The whole area is already divided into blocks. $1$ m... | ["res = []\nfor _ in range(int(input())):\n lst = []\n flag = 0\n n = int(input())\n for i in range(n):\n lst.append(list(map(int, input().split())))\n for i in lst:\n for j in range(n-1):\n if i[j] == i[j+1] == 1:\n res.append(\"UNSAFE\")\n flag = 1\n break\n if flag != 0:\n break\n for i in range(n-1)... | {"inputs": [["2", "4", "1 0 1 0", "0 0 0 1", "0 1 0 0", "1 0 0 1", "4", "1 0 1 0", "0 0 0 0", "1 0 1 1", "0 1 0 0"]], "outputs": [["SAFE", "UNSAFE"]]} | INTERVIEW | PYTHON3 | CODECHEF | 10,658 | |
63a42a72176c9c847e80a08bba22f942 | UNKNOWN | You are given a string S constisting of uppercase Latin letters. Is it possible to reorder the characters in this string to get a string with prefix "LTIME" and suffix "EMITL"?
We remind you that a prefix of a string is any substring which contains its first character, while a suffix of a string is substring containing... | ["# cook your dish here\nfrom collections import Counter\nfor i in range(int(input())):\n s=input().upper()\n res=Counter(s)\n if res[\"L\"]>=2 and res[\"T\"]>=2 and res[\"I\"]>=2 and res[\"M\"]>=2 :\n if len(s)==9:\n if res[\"E\"] >=1 :\n print(\"YES\")\n else:\n print(\"NO\")\n elif len(s)>9:\n if res[\... | {"inputs": [["3", "LTIMEAZAZAITLME", "LLLTTTIIIMMMEEEAHA", "LTIMEM"]], "outputs": [["YES", "YES", "NO"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,650 | |
33f08add2bda9d4ee862c3426fd3882d | UNKNOWN | As we all know, F.C. Barcelona is the best soccer team of our era! Their entangling and mesmerizing game style usually translates into very high ball possession, consecutive counter-attack plays and goals. Lots of goals, thanks to the natural talent of their attacker and best player in history, Lionel Andres Messi.
How... | ["T = int(input())\nfor _ in range(T):\n p,n=map(int,input().split())\n mod = 1000000007\n if p == 2:\n print(n)\n else:\n f=n\n t=n\n for i in range(p-2):\n f=(f%mod*n)%mod\n a=(f-t+mod)%mod\n t=a\n print(a)", "T = int(input())\nfor _ in range(T):\n p,n=map(int,input().split())\n mod = 1000000007\n if p == ... | {"inputs": [["2", "2 4", "4 2"]], "outputs": [["4", "6"]]} | INTERVIEW | PYTHON3 | CODECHEF | 2,519 | |
9a827e8975afc46d44a19861700a8ae3 | UNKNOWN | Raj is suffering from shot term memory loss so he is unable to remember his laptop password but he has a list of some string and the only thing that he remember about his password is alphanumeric and also that all the characters are unique.
Given a list of strings, your task is to find a valid password.
-----Input--... | ["import collections\n\nwhile True:\n d = input().strip()\n myCounter = collections.Counter(d)\n flag = 1\n\n for x in list(myCounter.keys()):\n if myCounter[x] > 1:\n flag = 0\n break\n\n isAlp = sum([myCounter[x] for x in list(myCounter.keys()) if x.isalnum()])\n\n if flag and isAlp:\n print(\"Valid\")\n break... | {"inputs": [["absdbads", "asdjenfef", "tyerbet", "abc564"]], "outputs": [["Invalid", "Invalid", "Invalid", "Valid"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,329 | |
42415e4bc191b27623827cbaba9a4b10 | 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())):\r\n n = int(input())\r\n s = [str(i) for i in range(n,0,-1)]\r\n for i in range(n):\r\n print('*'*i+''.join(s))\r\n del(s[0])", "for i in range(int(input())):\n p=int(input())\n for i in range(p):\n for k in range(i):\n print(\"*\", end=\"\"... | {"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["1", "21", "*1", "321", "*21", "**1", "4321", "*321", "**21", "***1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 6,575 | |
071ba062410b491df4cd3d3589c47e27 | UNKNOWN | Bohan loves milk tea so much and he drinks one cup of milk tea every day. The local shop sells milk tea in two sizes: a Medium cup for $3 and a Large cup for $4. For every cup of milk tea purchased Bohan receives a promotional stamp. Bohan may redeem 6 stamps for a free drink of milk tea regardless of the size. No stam... | ["t = int(input())\nfor tc in range(t):\n seq = input()\n dollar = 0\n stamp = 0\n for ct in seq:\n if stamp >= 6:\n stamp -= 6\n continue\n elif ct == 'M':\n dollar += 3\n elif ct == 'L':\n dollar += 4\n stamp += 1\n print(dollar)\n\n\n", "t=int(input())\nwhile t>0:\n t-=1\n s=input()\n val=0\n ctr=0\n for... | {"inputs": [["3", "MLM", "MMLLMMLL", "MMMMMMML"]], "outputs": [["10", "24", "22"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,345 | |
aa4736a10b9a11e4622baebde19a762c | UNKNOWN | You are given two positive integers $N$ and $K$, where $K \le N$. Find a sequence $A_1, A_2, \ldots, A_N$ such that:
- for each valid $i$, $A_i$ is either $i$ or $-i$
- there are exactly $K$ values of $i$ such that $1 \le i \le N$ and $A_1 + A_2 + \ldots + A_i > 0$
If there are multiple solutions, you may print any one... | ["test=int(input())\nfor i in range(test):\n n,k=map(int,input().split())\n x=n-k\n for j in range(1,n+1):\n if(j%2==0 and x>0):\n print(-j,end=' ')\n x-=1\n elif(k<=0):\n print(-j,end=' ')\n else:\n print(j,end=' ')\n k-=1\n print()", "# cook your dish here\nimport math\n\ntry:\n tc = int(input())\n for _... | {"inputs": [["1", "3 3"]], "outputs": [["1 2 3"]]} | INTERVIEW | PYTHON3 | CODECHEF | 12,792 | |
62d909ae977df52c3e8722b0d26d6611 | UNKNOWN | Chef recently saw the movie Matrix. He loved the movie overall but he didn't agree with some things in it. Particularly he didn't agree with the bald boy when he declared - There is no spoon. Being a chef, he understands the importance of the spoon and realizes that the universe can't survive without it. Furthermore, h... | ["import sys\n\nspoon = [ \"SPOON\", \"spoon\" ]\n\ndef main():\n try:\n tc=int(input())\n while tc>0:\n tc=tc-1\n [r,c] = input().split()\n r=int(r)\n c=int(c)\n k=0\n flag=0\n matrix=[0]*r\n i=0\n while i<r:\n matrix[i]=input()\n i=i+1\n \n #Check row wise\n for m in matrix:\n for s... | {"inputs": [["3", "3 6", "abDefb", "bSpoon", "NIKHil", "6 6", "aaaaaa", "ssssss", "xuisdP", "oooooo", "ioowoo", "bdylan", "6 5", "bdfhj", "cacac", "opqrs", "ddddd", "india", "yucky"]], "outputs": [["There is a spoon!", "There is a spoon!", "There is indeed no spoon!"]]} | INTERVIEW | PYTHON3 | CODECHEF | 7,694 | |
5be84740443f3dd7e1be019783672bd4 | UNKNOWN | The Little Elephant from the Zoo of Lviv has an array A that consists of N positive integers. Let A[i] be the i-th number in this array (i = 1, 2, ..., N).
Find the minimal number x > 1 such that x is a divisor of all integers from array A. More formally, this x should satisfy the following relations:
A[1] mod x = 0,... | ["from math import sqrt,gcd\n\nfor _ in range(int(input())):\n n=int(input())\n ar=[int(x) for x in input().split()]\n g=ar[0]\n for i in range(1,n):\n g=gcd(g,ar[i])\n \n f=g\n for i in range(2,int(sqrt(g))+1):\n if g%i==0:\n f=i\n break\n if g!=1:\n p... | {"inputs": [["2", "3", "2 4 8", "3", "4 7 5", "", ""]], "outputs": [["2", "-1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 12,706 | |
242ae0f2ce85745865987e2a5231a96a | UNKNOWN | Devu and Churu love to play games a lot. Today, they have an array A consisting of N positive integers. First they listed all N × (N+1) / 2 non-empty continuous subarrays of the array A on a piece of paper and then replaced all the subarrays on the paper with the maximum element present in the respective subarray.
Devu... | ["def left_span(arr,n):\n ans=[0]\n span=[0]\n for i in range(1,n):\n \n while span and arr[i]>arr[span[-1]]:\n span.pop()\n \n if not span:\n ans.append(0)\n \n else:\n ans.append(span[-1]+1)\n span.append(i)\n return ans\n\ndef right_span(arr,n):\n ans=[n+1]\n span=[n-1]\n for i in range(n-2,-1,-1):\n ... | {"inputs": [["3 5", "1 2 3", "> 1 D", "< 2 C", "= 3 D", "> 4 C", "< 5 D"]], "outputs": [["DCDDC"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,534 | |
26300c05ffe55054f20d6e0634cbe5c8 | UNKNOWN | -----
RANJANA QUIZ
-----
Prof. Ranjana decided to conduct a quiz in her class. She divided all the students of her
class into groups of three. Consider that no student was left out after the division. She gave
different sets of questions to every group. A set is said to be unique if there is no other team that
receive... | ["n=int(input())\nl=[]\ncount=0\nwhile n:\n n-=1\n a,b,c=sorted(map(int,input().split()))\n if (a,b,c) in l:\n count-=1\n else:\n l.append((a,b,c))\n count+=1\nprint(count)", "try:\n s=[]\n for i in range(int(input())):\n n=list(map(int,input().split()))\n n.sort()\n... | {"inputs": [["5", "6 5 4", "2 3 7", "4 6 5", "7 2 3", "5 3 1"]], "outputs": [["1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 7,955 | |
cad133c54f90c3f8df35e1e019c37c09 | UNKNOWN | You are given a weighted undirected graph consisting of n$n$ nodes and m$m$ edges. The nodes are numbered from 1$1$ to n$n$. The graph does not contain any multiple edges or self loops.
A walk W$W$ on the graph is a sequence of vertices (with repetitions of vertices and edges allowed) such that every adjacent pair of v... | ["# cook your dish here\nfrom collections import defaultdict\n\nclass sol():\n def __init__(self,n,edges):\n self.n = n\n self.edges = edges\n self.graph = self.create_graph()\n self.precompute()\n \n def create_graph(self):\n graph = defaultdict(list)\n for e in s... | {"inputs": [["3 3", "1 2 1", "2 3 2", "3 1 3", "3", "1", "2", "3"]], "outputs": [["2", "10", "36"]]} | INTERVIEW | PYTHON3 | CODECHEF | 13,277 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.