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
7c38d67ff32f8cbb391f43bac7e568db
UNKNOWN
There are $M$ levels for a building numbered from $1$ to $M$ from top to bottom, each level having $N$ parking spots numbered from $1$ to $N$ from left to right. Some spots might have a car while other may be empty, the information of which is given in form of two dimensional character array $C$ ($C_{i, j}$ denote park...
["from sys import stdin\n\nfor _ in range(int(stdin.readline())):\n m, n = list(map(int, stdin.readline().split()))\n final = []\n arr = []\n val = 0\n extra = 0\n for j in range(m):\n ans = list(map(str, stdin.readline().split()))\n if ans.count('N') == n:\n val += 1\n else:\n if val%2 == 0:\n arr.append(ans...
{"inputs": [["2", "4 5", "N P N N P", "N N P N N", "N P N N N", "P N N N N", "3 3", "N P P", "P P P", "P P N"]], "outputs": [["10", "6"]]}
INTERVIEW
PYTHON3
CODECHEF
17,560
e4749d4506883129b4689f2968b92741
UNKNOWN
We all know that Share market is place where drastic change occurs within moments. So we have one Stockholder, Isabella, who wants to maximize her profit by selling her shares. She has $N$ shares of a Doofenshmirtz Corporation which is represented by $N$ different lines where each line contains two space separated inte...
["def CeilIndex(A, l, r, key): \n \n while (r - l > 1): \n \n m = l + (r - l)//2\n if (A[m] >= key): \n r = m \n else: \n l = m \n return r \n \ndef LongestIncreasingSubsequenceLength(A, size): \n \n # Add boundary case, \n # when array size is one \n \n...
{"inputs": [["1", "4", "1 2", "4 3", "3 5", "2 4"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
4,094
b3703902df886fa9555545ce7f5d9a87
UNKNOWN
Dexter, being irritated by DD, gave her a lucrative game to play to keep her busy. There are $N$ bags numbered $1$ to $N$. The $i_{th}$ bag contains $A_i$ coins. The bags are placed in a circular order such that the $N_{th}$ bag is adjacent to the $1^{st}$ bag. DD can select $K$ consecutive adjacent bags and take all ...
["t=int(input())\nfor i in range(t):\n n,k=list(map(int,input().split(\" \")))\n arr=list(map(int,input().strip().split(\" \")))[:n]\n def maxCircularSum(arr, n, k):\n if (n < k):\n print(\"Invalid\");\n return;\n\n sum = 0;\n start = 0;\n end = k - 1;\n\n ...
{"inputs": [["1", "5 3", "8 6 9 4 10"]], "outputs": [["24"]]}
INTERVIEW
PYTHON3
CODECHEF
11,649
6d47cb4940c5baaf4c70526875c44ee9
UNKNOWN
In a regular table tennis match, the player who serves changes every time after 2 points are scored, regardless of which players scored them. Chef and Cook are playing a different match — they decided that the player who serves would change every time after $K$ points are scored instead (again regardless of which playe...
["n=int(input())\nfor i in range(n):\n l=list(map(int,input().split()))\n k=l[0]+l[1]\n k=k%(2*l[2])\n \n if k>=0 and k<l[2]:\n print(\"CHEF\")\n else:\n print(\"COOK\")\n", "t=int(input())\nwhile t>0:\n p1,p2,k=map(int,input().split())\n s=(p1+p2)//k\n if s%2==0:\n print(\"CHEF\")\n else:\n print(\"COOK\...
{"inputs": [["3", "1 3 2", "0 3 2", "34 55 2"]], "outputs": [["CHEF", "COOK", "CHEF"]]}
INTERVIEW
PYTHON3
CODECHEF
4,547
513da0d36cf28a85348412f47b88b6d0
UNKNOWN
Find the length of the longest contiguous segment in an array, in which if a given element $K$ is inserted, $K$ becomes the second largest element of that subarray. -----Input:----- - The first line will contain $T$, number of test cases. Then the test cases follow. - The first line of each test case contains two int...
["for _ in range(int(input())):\n n,k=list(map(int,input().split()))\n a=list(map(int,input().split()))\n def check(mid):\n d,left={},0\n for i in range(mid):\n if a[i]>k:\n if a[i] not in d: \n d[a[i]]=1\n else: \n d[a[i]]+=1\n if len(d)==1:\n return True\n for i in range(mid,n):\n if a[left]>k...
{"inputs": [["2", "5 3", "2 4 2 4 2", "8 5", "9 3 5 7 8 11 17 2"]], "outputs": [["5", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
9,246
10844794469488fbf329b238f9cd849a
UNKNOWN
Given n words w[1..n], which originate from the same stem (e.g. grace, graceful, disgraceful, gracefully), we are interested in the original stem. To simplify the problem, we define the stem as the longest consecutive substring that occurs in all the n words. If there are ties, we will choose the smallest one in the al...
["t = eval(input())\nfor _ in range(t):\n n = eval(input())\n a = input().strip().split()\n cb, cs = 0, \"\"\n for i in range(len(a[0])):\n for j in range(i+1,len(a[0])+1):\n al = True\n s = a[0][i:j]\n for k in a[1:]:\n if s not in k:\n al = False\n break\n if al:\n if j-i>=cb:\n cb = max(cb...
{"inputs": [["1", "4", "grace graceful disgraceful gracefully"]], "outputs": [["grace"]]}
INTERVIEW
PYTHON3
CODECHEF
9,391
a3307aa60c3fd0599051564240d071cb
UNKNOWN
Chef has a rectangular piece of paper. He puts it on a big board in such a way that two sides of the paper are horizontal and two are vertical, and then he performs a sequence of $N$ operations. You are given a string $S$ with length $N$; for each valid $i$, the $i$-th character of $S$ determines the type of the $i$-th...
["# cook your dish here folding paper\nfrom collections import Counter\ndef li():return [int(i) for i in input().rstrip('\\n').split()]\ndef st():return input().rstrip('\\n')\ndef val():return int(input().rstrip('\\n'))\ndef dist(a,b):return ((a[0]-b[0])**2+(a[1]-b[1])**2)**0.5\nfor _ in range(val()):\n n,m,w,h=li()\n ...
{"inputs": [["2", "6 2 10 10", "ULRDDL", "4 4", "5 5", "4 2 10 10", "RUDL", "1 1", "9 9"]], "outputs": [["1.41421356237", "2.00000000000"]]}
INTERVIEW
PYTHON3
CODECHEF
2,800
d212da460853134b0d986b8c87abab5c
UNKNOWN
Given the list of numbers, you are to sort them in non decreasing order. -----Input----- t – the number of numbers in list, then t lines follow [t <= 10^6]. Each line contains one integer: N [0 <= N <= 10^6] -----Output----- Output given numbers in non decreasing order. -----Example----- Input: 5 5 3 6 7 1 Output...
["t = int(input())\nlist_to_tri = []\nfor i in range(t):\n list_to_tri.append(int(input()))\nlist_to_tri.sort()\nfor i in list_to_tri:\n print(i)\n", "# cook your dish here\nn=int(input())\nlst = []\nfor i in range(n):\n i=int(input())\n lst.append(i)\n\nlst.sort()\nfor i in range(n):\n print(lst[i])\n",...
{"inputs": [["5", "5", "3", "6", "7", "1"]], "outputs": [["1", "3", "5", "6", "7"]]}
INTERVIEW
PYTHON3
CODECHEF
3,620
2730e39f7b0cba74924418025b83fbda
UNKNOWN
Once, a genius guy Cristo visited NASA where he met many scientists. A young intern Mark at NASA asked Cristo to observe the strange behaviour of two independent particles (say Alpha and Beta) moving in the free space.Cristo was astonished to see the movement of Alpha and Beta. However, he formulated a procedure to e...
["for _ in range(eval(input())):\n n=eval(input())\n mod=1000000007\n f1,f2=[0]*101000,[0]*101000\n f1[1]=0\n f1[2]=2\n f1[3]=3\n f2[1]=1\n f2[2]=1\n f2[3]=2;\n for i in range(4,100001):\n f1[i]=f1[i-1]%mod+f1[i-2]%mod+f1[i-3]%mod\n f2[i]=f2[i-1]%mod+f2[i-2]%mod+f2[i-3]%mod\n print(f1[n]%mod,f2[n]%mod) ", "MOD = 10**...
{"inputs": [["2", "1", "2"]], "outputs": [["0 1", "2 1"]]}
INTERVIEW
PYTHON3
CODECHEF
2,463
088fc29627c4b80420e1bf33488f5198
UNKNOWN
Shaun is very much interested in Subarrays. Shaun wants to count the number of subarrays in his chosen array with sum being a multiple of $10^9$. Since, Shaun is interested in huge numbers.He chose his array such that it contains only $10^8$ and $9*10^8$ as its elements. Help shaun to count the number of required subar...
["def subCount(arr, n, k):\r\n\r\n mod = []\r\n for i in range(k + 1):\r\n mod.append(0)\r\n\r\n\r\n cumSum = 0\r\n for i in range(n):\r\n cumSum = cumSum + arr[i]\r\n\r\n # as the sum can be negative,\r\n # taking modulo twice\r\n mod[((cumSum % k) + k) % k] = mod[((cumSu...
{"inputs": [["2", "3", "100000000 900000000 100000000", "1", "900000000"]], "outputs": [["2", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
15,150
e8ce9a6dd50e421186739e29b65803d2
UNKNOWN
The Chef has prepared the appetizers in the shapes of letters to spell a special message for the guests. There are n appetizers numbered from 0 to n-1 such that if the appetizers are arrayed in this order, they will display the message. The Chef plans to display them in this order on a table that can be viewed by all g...
["t=int(input())\ndef reversebinary(bits,n):\n bStr=''\n for i in range(bits):\n if n>0:\n bStr=bStr+str(n%2)\n else:\n bStr=bStr+'0'\n n=n>>1\n return int(bStr,2)\n \nfor i in range(t):\n k,msg=input().split()\n k=int(k)\n newmsg=[]\n for j in msg:...
{"inputs": [["2", "2 chef", "4 enjoyourapplepie", "", ""]], "outputs": [["cehf", "eayejpuinpopolre"]]}
INTERVIEW
PYTHON3
CODECHEF
468
b4e84f0750fd281148e527ab77cbd2d7
UNKNOWN
Bharat was given a problem to solve, by his brother, Lord Ram. The problem was like, given integers, $N$ and $K$, Bharat has to find the number (possibilities) of non-increasing arrays of length $K$, where each element of the array is between $1$ and $N$ (both inclusive). He was confused, regarding this problem. So, he...
["import math\np=7+10**9\nn,k=list(map(int,input().split()))\nc=math.factorial(n+k-1)//((math.factorial(k))*(math.factorial(n-1)))\nprint(c%p)\n", "from math import *\n \n# Function to find the nCr \ndef printNcR(n, r): \n \n # p holds the value of n*(n-1)*(n-2)..., \n # k holds the value of r*(r-1)... \n p = 1\n k = 1...
{"inputs": [["2 5"]], "outputs": [["6"]]}
INTERVIEW
PYTHON3
CODECHEF
3,970
4c941c7475502ca97b844fa319e185da
UNKNOWN
Chef and his best friend Aleksa are into mathematical games these days. Today, they have some ( ≥ 0 ) black cells represented as B, and a white cell represented as W, lying randomly in a straight line. They have decided to play with these cells. In a move, a player chooses some ( > 0 ) black cells lying on any one side...
["t =int(input()) #no. of test cases\nwhile t>0:\n t=t-1\n str=input()\n size=len(str)\n pos=str.find('W')\n left=pos\n right=size-pos-1\n arr = [[0 for i in range(right+1)] for j in range(left+1)]\n #arr[i,j] = 1 if with i black cells on left and j on right 1st player can \u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00...
{"inputs": [["3", "W", "BW", "BWBB"]], "outputs": [["Chef", "Aleksa", "Aleksa"]]}
INTERVIEW
PYTHON3
CODECHEF
4,471
6424a20f7641f5222969d31a28190e0e
UNKNOWN
Naturally, the magical girl is very good at performing magic. She recently met her master wizard Devu, who gifted her R potions of red liquid, B potions of blue liquid, and G potions of green liquid. - The red liquid potions have liquid amounts given by r[1], ..., r[R] liters. - The green liquid potions have liqu...
["import sys\nimport math\nimport heapq\ndef half(n):\n return n//2\ndef main(arr,m):\n a,b,c=arr\n \n while m!=0:\n \n \n \n s=max(a,b,c)\n \n if s==a:\n a=half(a)\n elif s==b:\n b=half(b)\n else:\n c=half(c)\n m-=1\n return max(a,b,c)\n \n \n \n \n \n\nfor i in range(int(input())):\n r,g,b,m=list(map...
{"inputs": [["3", "1 1 1 1", "1", "2", "3", "1 1 1 1", "2", "4", "6", "3 2 2 2", "1 2 3", "2 4", "6 8"]], "outputs": [["2", "4", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
9,334
7ecf4e6eb54476dbe78961aafd716816
UNKNOWN
Cersei wants to be the queen of seven kingdoms. For this to happen, she needs to address the soldiers in her army. There are n$n$ soldiers in her army (numbered 1$1$ through n$n$). Cersei passes on the message to the first soldier (soldier 1). This message needs to reach every soldier in the army. For this, the sol...
["dt, a = None, None\ndef dfs(z):\n r = [{}, {}];ln = len(dt[z])\n if ln == 0:r[0][0] = 0;r[1][1 << a[z]] = 1\n elif ln == 1:\n l = dfs(dt[z][0]);r[0] = l[1]\n for m in l[0]: r[1][(1 << a[z]) | m] = min(r[1][(1 << a[z]) | m], l[0][m] + 1) if (1 << a[z]) | m in r[1] else l[0][m] + 1\n ...
{"inputs": [["1", "5 4 3", "1 1 2 2 3", "1 2", "1 3", "2 4", "2 5"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
39,702
84bdc0aa3dc54825216bdea38fa9f38e
UNKNOWN
In Ciel's restaurant, a waiter is training. Since the waiter isn't good at arithmetic, sometimes he gives guests wrong change. Ciel gives him a simple problem. What is A-B (A minus B) ? Surprisingly, his answer is wrong. To be more precise, his answer has exactly one wrong digit. Can you imagine this? Can you make the...
["a, b = [int(x) for x in input().split()]\nr = list(str(a-b))\nif r[0] == \"1\":\n r[0] = \"2\"\nelse:\n r[0]=\"1\"\nprint(\"\".join(r))\n"]
{"inputs": [["5858 1234"]], "outputs": [["1624", "Output details", "The correct answer of 5858-1234 is 4624.", "So, for instance, 2624, 4324, 4623, 4604 and 4629 will be accepted, but 0624, 624, 5858, 4624 and 04624 will be rejected.", "Notes", "The problem setter is also not good at arithmetic."]]}
INTERVIEW
PYTHON3
CODECHEF
141
cbbe5bbf3ba75c270cec21dcb6d7b32f
UNKNOWN
Sheldon is a little geek living in Texas. While his friends like to play outside, little Sheldon likes to play around with ICs and lasers in his house. He decides to build N clap activated toggle machines each with one power inlet and one outlet. Each machine works when its power source inlet is receiving power. When t...
["n=int(input())\nwhile n>0:\n i=1\n a,b=(int(i) for i in input().split())\n if (b+1)%(i<<a)==0:\n print(\"ON\")\n else:\n print(\"OFF\")\n n=n-1\n", "for _ in range(int(input())):\n n,k=input().split()\n n=int(n)\n k=int(k)\n \n p=2**n-1\n \n if p==k:\n print('ON')\n elif p<k:\n if (k-p)%(2**n)==0:\n print('ON')...
{"inputs": [["4", "4 0", "4 47", "1 0", "1 1"]], "outputs": [["OFF", "ON", "OFF", "ON"]]}
INTERVIEW
PYTHON3
CODECHEF
890
81a853ae965491962baa08e9b817db75
UNKNOWN
Well known investigative reporter Kim "Sherlock'' Bumjun needs your help! Today, his mission is to sabotage the operations of the evil JSA. If the JSA is allowed to succeed, they will use the combined power of the WQS binary search and the UFDS to take over the world! But Kim doesn't know where the base is located. He ...
["n=int(input())\ndef do():\n t=int(input())\n x=[]\n for i in range(t):\n x.append(int(input()))\n print(max(x))\n return\nfor i in range(n):\n do()", "t=int(input())\ndef do():\n n=int(input())\n a=[]\n for i in range(n):\n a.append(int(input()))\n print(max(a))\n return\nfor i in range(t):\n do()", "# cook your di...
{"inputs": [["1", "5", "4", "7", "6", "3", "1"]], "outputs": [["7"]]}
INTERVIEW
PYTHON3
CODECHEF
3,838
d5bd90e50993fb162f19fd92ec476905
UNKNOWN
Lyra Belacqua is a very gifted girl. She is one of a very small set of people capable of reading an alethiometer, more commonly known as The Golden Compass. It has one specific use: to tell the truth. The name in fact, is derived from "Aletheia" meaning truth, and "-ometer", meaning "measuring device". The alethiomete...
["string=input()\nmax_no=0\nfor i in range(len(string)):\n var_occur=0\n check_no=str()\n j=i\n while(j<len(string) and var_occur<2 ):\n if(string[j].isalpha()):\n if(var_occur==0):\n check_no+='9'\n var_occur+=1\n else:\n var_occur+=1\n else:\n check_no+=string[j]\n j+=1\n #print(check_no)\n max_no=m...
{"inputs": [["06454", "Input2:", "C0D3C43F"]], "outputs": [["6454", "Output2:", "3943"]]}
INTERVIEW
PYTHON3
CODECHEF
787
ee812514a7fd654c3ab608f72dd800b1
UNKNOWN
Chef is given a sequence of prime numbers $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. A subsequence of $A$ is good if it does not contain any two identical numbers; in particular, the empty sequence is good. Chef has to find the number of good subsequences which contain at most $K$ numbers. S...
["# cook your dish here\nfrom collections import Counter\ndef solve(arr, n, k):\n ans = 0\n dict1 = {}\n mod = 1000000007\n \n for i in range(n):\n if arr[i] in dict1:\n dict1[arr[i]] += 1 \n else:\n dict1[arr[i]] = 1\n l1 = [0]+list(dict1.keys())\n v = min(k, len(l1))\n dp = [[0 for _ in range(v+1)]for _ in rang...
{"inputs": [["5 3", "2 2 3 3 5"]], "outputs": [["18"]]}
INTERVIEW
PYTHON3
CODECHEF
15,434
22101cecdf1125793ce529c08fe79149
UNKNOWN
In this problem you are given a sequence of $N$ positive integers $S[1],S[2],\dots,S[N]$. In addition you are given an integer $T$, and your aim is to find the number of quadruples $(i,j,k,l)$, such that $1 \le i < j < k < l \le N$, and $S[i] + S[j] + S[k] + S[l] = T$. That is, the number of ways of picking four numb...
["# cook your dish here\nfrom itertools import combinations\na = list(map(int, input().split()))\nn = a[0]\nt = a[1]\nq = list(combinations(a[2:], 4))\ntotal = 0\nfor i in q:\n if sum(i) == t:\n total += 1\nprint(total)\n", "from itertools import combinations\ndef rSubset(arr, r): \n return list(combinati...
{"inputs": [["6 20 3 1 1 2 5 10"]], "outputs": [["1"]]}
INTERVIEW
PYTHON3
CODECHEF
16,855
b7e17b5f5c7e16ef716280928fffa00b
UNKNOWN
A balanced parenthesis string is defined as follows: - The empty string is balanced - If P is balanced, (P) is also - If P and Q are balanced, PQ is also balanced You are given two even integers n$n$ and k$k$. Find any balanced paranthesis string of length n$n$ that doesn't contain a balanced substring of length k$k$,...
["import sys\n\n\ndef input():\n return sys.stdin.readline().strip()\n\n\nfor i in range(int(input())):\n n, k = map(int, input().split())\n arr = []\n if k == 2 or k == 4 or n % 2 != 0 or n == k:\n arr.append('-1')\n elif k % 2 != 0:\n for i in range(int(n / 2)):\n arr.append('(...
{"inputs": [["2", "4 2", "8 6"]], "outputs": [["-1", "(())(())"]]}
INTERVIEW
PYTHON3
CODECHEF
5,390
c49aa2066e37a63e2cc2ab30f02e7233
UNKNOWN
You will be given m strings. For each of those strings, you need to count the total number of appearances of that string as substrings in all possible strings of length n containing only lower case English letters. A string may appear in a string multiple times. Also, these appearances may overlap. All these must be ...
["for _ in range(int(input())):\r\n n,m=map(int,input().split())\r\n print(\"Case \"+str(_+1)+\":\")\r\n for i in range(m):\r\n s=input()\r\n ls=len(s)\r\n if ls>n:\r\n print(\"0\")\r\n else:\r\n k=(n-ls+1)\r\n print((k*pow(26,n-ls,1000000007))%10000...
{"inputs": [["3", "2 1", "aa", "2 1", "d", "12 3", "cdmn", "qweewef", "qs", "", ""]], "outputs": [["Case 1:", "1", "Case 2:", "52", "Case 3:", "443568031", "71288256", "41317270"]]}
INTERVIEW
PYTHON3
CODECHEF
4,302
0ac94bbebf68c152fc4f4f859c43b964
UNKNOWN
For a string $S$ let the unique set of characters that occur in it one or more times be $C$. Consider a permutation of the elements of $C$ as $(c_1, c_2, c_3 ... )$. Let $f(c)$ be the number of times $c$ occurs in $S$. If any such permutation of the elements of $C$ satisfies $f(c_i) = f(c_{i-1}) + f(c_{i-2})$ for all $...
["# cook your dish here\nt=int(input())\nfor _ in range(t):\n st=input()\n s=set(st)\n a=[]\n f1=f2=0\n for i in s:\n a.append(st.count(i))\n a.sort()\n if len(a)>=3:\n for i in range(2,len(a)):\n if a[i]!=a[i-1]+a[i-2]:\n f1=1\n break\n x=a[0]\n a[0]=a[1]\n a[1]=x\n for i in range(2,len(a)):\n if a[i]!...
{"inputs": [["3", "aaaabccc", "aabbcc", "ppppmmnnoooopp"]], "outputs": [["Dynamic", "Not", "Dynamic"]]}
INTERVIEW
PYTHON3
CODECHEF
7,334
f6f4aef6bd1fabe6a1d5963dfda933f3
UNKNOWN
Chef made two laddus with sweetness X and Y respectively. Cheffina comes and sees the chef created two laddus with different sweetness (might be same). Cheffina has the magical power to make the sweetness of laddus equal. Cheffina requires 1 unit of power to increase the sweetness of laddu by its original value i.e. 1 ...
["def gcd(a,b):\r\n\tif b==0:return a\r\n\telse:return gcd(b,a%b)\r\ndef lcm(a,b):\r\n\tm=a*b\r\n\tg=gcd(a,b)\r\n\treturn int(m/g)\r\nfor _ in range(int(input())):\r\n\tx,y=[int(x) for x in input().split()]\r\n\tl=lcm(x,y)\r\n\ts=int(l/x)\r\n\tt=int(l/y)\r\n\tprint(s+t-2)", "for i in range(int(input())):\r\n def gcd...
{"inputs": [["2", "2 2", "4 6"]], "outputs": [["0", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
10,008
bed419fdbae2c9cf050273bc5f5ef7e4
UNKNOWN
A key feature of the Siruseri railway network is that it has exactly one route between any pair of stations. The government has chosen three contractors to run the canteens at the stations on the railway network. To ensure that there are no disputes between the contractors it has been decided that if two stations, say ...
["n=int(input())\r\ncost=[]\r\nd={}\r\nval_desc=[0]*n\r\nvisited=set()\r\nvisited.add(0)\r\ndfstack=[]\r\ndesc = [[False for i in range(n)] for i in range(n)]\r\nfor i in range(n):\r\n\tcost.append(int(input()))\r\n\td[i]=[]\r\n\r\nfor i in range(n-1):\r\n\tj,k=list(map(int,input().split()))\r\n\td[j-1].append(k-1)\r\n...
{"inputs": [["6", "10", "20", "25", "40", "30", "30", "4 5", "1 3", "3 4", "2 3", "6 4"]], "outputs": [["70"]]}
INTERVIEW
PYTHON3
CODECHEF
2,334
883e5d70091cb97b3f69691a3c68a1cd
UNKNOWN
Chef is the leader of Chef's Earth Defense Organization, and his mission is to counter aliens which are threatening the earth. According to information gathered by the organization, there are $N$ alien spaceships (numbered $1$ through $N$) planning to invade the earth. The $i$-th spaceship will appear on the radar at t...
["# cook your dish here\ndef isValid(mid):\n time = 0.0\n for i in range(n):\n if time < c[i]:\n time = c[i]\n time += mid # cannon cooling\n elif time >= c[i] and time <= c[i] + d:\n time += mid # cannon cooling\n else:\n return False\n return True\n\nt = int(input())\nwhile t != 0:\n n, d = list(map(int, i...
{"inputs": [["2", "3 2", "3 2 3", "2 1", "5 6"]], "outputs": [["1.5000000000", "2.0000000000"]]}
INTERVIEW
PYTHON3
CODECHEF
14,870
249c36dc1ef824037968ab4406466220
UNKNOWN
Ted$Ted$ loves prime numbers. One day he is playing a game called legendary$legendary$ with his girlfriend Robin$Robin$. Ted$Ted$ writes a number N$N$ on a table and the number is in the form of : N = P1A1 * P2A2 * ……….. * PnAn Ted$Ted$ asks Robin$Robin$ to find the sum of all the numbers which are less than or equal ...
["\r\n\r\nd = 10**9 + 7\r\n\r\nt = int(input())\r\nwhile t:\r\n t-=1\r\n n =int(input())\r\n p =list(map(int, input().strip().split()))\r\n a =list(map(int, input().strip().split()))\r\n b =list(map(int, input().strip().split()))\r\n ans = 1\r\n for i in range(n):\r\n c = a[i] - b[i] + 1\r\n...
{"inputs": [["1", "3", "2 3 5", "2 1 2", "1 1 1"]], "outputs": [["540"]]}
INTERVIEW
PYTHON3
CODECHEF
479
a3aa674e09a72b98879700ecc79d39e3
UNKNOWN
There are $N$ friends in a group. Each of them have $A_{i}$ candies. Can they share all of these candies among themselves such that each one of them have equal no. of candies. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - First line of each testcase contains of a si...
["# cook your dish here\n\nfor _ in range(int(input())):\n friends = int(input())\n candies = list(map(int,input().split()))\n if (sum(candies) % friends == 0):\n print(\"Yes\")\n else:\n print(\"No\")", "t=input()\nfor i in range(int(t)):\n n=int(input())\n l=list(map(int,input().split()))\n if(sum(l)%n==0): print(\...
{"inputs": [["1", "3", "1 2 3"]], "outputs": [["Yes"]]}
INTERVIEW
PYTHON3
CODECHEF
4,541
17a04d89eabe9202452b9b495474c787
UNKNOWN
Chef has $K$ chocolates and he wants to distribute them to $N$ people (numbered $1$ through $N$). These people are standing in a line in such a way that for each $i$ ($1 \le i \le N-1$), person $i$ and person $i+1$ are adjacent. First, consider some way to distribute chocolates such that for each valid $i$, the number ...
["t = int(input())\nfor _ in range(t):\n n = int(input())\n k = int(input())\n num = int(k/n)\n x = max(n*(1+num) - k, 0)\n diff = abs(x - (n-x))\n if diff == 0:\n number = 2*x - 1\n else:\n number = min(x, n-x)*2\n print(number)", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n n = int(input())\n k = ...
{"inputs": [["1", "3", "2"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
6,501
b2e84ceb4f0b0716ff8d919b3fe96c38
UNKNOWN
Given a string $s$. You can perform the following operation on given string any number of time. Delete two successive elements of the string if they are same. After performing the above operation you have to return the least possible length of the string. -----Input:----- - First line will contain $T$, number of testc...
["from sys import stdin,stdout\nimport math,bisect\nfrom datetime import date\nfrom collections import Counter,deque,defaultdict\nL=lambda:list(map(int, stdin.readline().strip().split()))\nM=lambda:list(map(int, stdin.readline().strip().split()))\nI=lambda:int(stdin.readline().strip())\nS=lambda:stdin.readline().strip(...
{"inputs": [["3", "abccd", "abbac", "aaaa"]], "outputs": [["3", "1", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
1,064
0e2b600ac2903f5d91cd31b4d141d041
UNKNOWN
Ashley wrote a random number generator code. Due to some reasons, the code only generates random positive integers which are not evenly divisible by 10. She gives $N$ and $S$ as input to the random number generator. The code generates a random number with number of digits equal to $N$ and sum of digits equal to $S$. Th...
["\"\"\"\n Author : thekushalghosh\n Team : CodeDiggers\n\"\"\"\nimport sys,math\ninput = sys.stdin.readline\n############ ---- USER DEFINED INPUT FUNCTIONS ---- ############\ndef inp():\n return(int(input()))\ndef inlt():\n return(list(map(int,input().split())))\ndef insr():\n s = input()\n return(...
{"inputs": [["2", "1 5", "2 2"]], "outputs": [["5", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
1,287
0b1f0483f8587923f6893ab93f1379b0
UNKNOWN
Chef is going to organize a hill jumping competition and he is going to be one of the judges in it. In this competition there are N hills in a row, and the initial height of i-th hill is Ai. Participants are required to demonstrate their jumping skills by doing what the judges tell them. Judges will give each participa...
["n,q=list(map(int,input().split()))\nfinal=[]\nheight=list(map(int,input().split()))\nfor k in range(0,q):\n b=input().split()\n if int(b[0])==1:\n step=int(b[1])-1\n for k in range(0,int(b[2])):\n temp = 0\n j=1\n while j in range(1,101) and temp==0 and step+j<n:\n if height[step+j]>height[step]:\n ste...
{"inputs": [["5 3", "1 2 3 4 5", "1 1 2", "2 3 4 -1", "1 1 2"]], "outputs": [["3", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
16,571
181a408bdd065a09e93ebd3a72a4da57
UNKNOWN
Mandarin chinese , Russian and Vietnamese as well. You are given a grid with $n$ rows and $m$ columns. Each cell of this grid can either be empty or it contains one particle. It can never contain more than one particle. Let's denote the cell in the $i$-th row and $j$-th column by $(i, j)$, with the top left corner bein...
["def main():\n for _ in range(int(input())):\n rows,column = map(int,input().split())\n arr = []\n for i in range(rows):\n arr.append(list(input()))\n string = input()\n last = string[-1]\n operation = Find(string,last)\n for i in string[0]+operation:\n if i == \"L\":\n arr = Left(arr)\n if i == \"R\":...
{"inputs": [["3", "4 4", "1010", "0010", "1001", "0100", "LRDU", "4 3", "000", "010", "001", "101", "LRL", "3 2", "01", "10", "00", "D"]], "outputs": [["0011", "0011", "0001", "0001", "000", "100", "100", "110", "00", "00", "11"]]}
INTERVIEW
PYTHON3
CODECHEF
7,012
9b912aef4d85ccd128f6bbbe2302a2e9
UNKNOWN
Chef is the event manager of his college. He has been assigned the task to manage the upcoming tech fest. There are $K$ rooms where the event can take place, and at a particular time only one event can be organized in a room for a particular time interval. Each event coordinator has their strictly preferred room $P_i$,...
["import sys\r\n# import math\r\nfrom math import gcd\r\n# import re\r\n# from heapq import *\r\n# from collections import defaultdict as dd\r\n# from collections import OrderedDict as odict\r\n# from collections import Counter as cc\r\n# from collections import deque\r\n# sys.setrecursionlimit(10**5)#thsis is must\r\n...
{"inputs": [["1", "4 2", "1 10 1", "10 20 2", "15 50 2", "20 30 2"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
7,276
367e974dbc9c3752d3198f9ceee3684c
UNKNOWN
In these quarantine days, Chef and Chefina are getting bored. So, Chef came up with a game for her. He gets a pack of cards with numbers written on them. Chef then asks her to remove cards from the pack in the following manner: Chefina can choose any 3 cards at a time, having unique values, and remove the smallest and ...
["# cook your dish here\ntry:\n for i in range(int(input())):\n n=int(input())\n l=[int(j) for j in input().split()][:n]\n d={}\n for j in l:\n d[j]=d.get(j,0)+1\n a=len(d)\n c=0\n for j in list(d.keys()):\n while(d[j]>=3):\n d[j]=(d[j]//3)+(d[j]%3)\n if(d[j]==2):\n c=c+1\n if(c&1):\n s=0\n for ...
{"inputs": [["2", "5", "1 2 2 3 5", "9", "1 2 2 3 3 5 8 8 9"]], "outputs": [["3", "5"]]}
INTERVIEW
PYTHON3
CODECHEF
5,245
06beccf27f29e9180b6bfac904318127
UNKNOWN
Shubham recently learned the lexicographical order in strings. Now, he has two strings s1 and s2 of the equal size and Shubham wants to compare those two strings lexicographically. Help Shubham with the strings comparison. Note: Letters are case insensitive. -----Input----- First line contains a integer T de...
["t=eval(input())\nwhile t:\n t=t-1\n s1=input().lower()\n s2=input().lower()\n res=\"equal\"\n for i in range(len(s1)):\n if(s1[i]!=s2[i]):\n \n res=\"first\" if s1[i]<s2[i] else \"second\"\n break\n print(res)\n", "import sys\n\nfor __ in range(eval(input())) :\n a , b = input().lower() , input().lower()\n if ...
{"inputs": [["2", "abc", "acb", "AB", "ba"]], "outputs": [["first", "first"]]}
INTERVIEW
PYTHON3
CODECHEF
2,170
d0a5abdaeb6d23b012d4cf2cbbfb1eae
UNKNOWN
You have a laser with P amount of energy in it. You are playing a game where you have to use the laser to destroy some crystals, each with some health of their own. Initially, you have 0 points. Each crystal has an associated health. The health of the ith crystal is given by health[i]. You can perform one of the two ac...
["def game(n,l,p):\n if(len(l)==0):\n return 0\n l.sort()\n if(len(l)>=1 and p<l[0]):\n return 0\n l.sort()\n c=0\n \n \n ma=set()\n ma.add(0)\n while(len(l)):\n if(p>=l[0]):\n p-=l[0]\n \n c+=1\n ma.add(c)\n l=l[1...
{"inputs": [["1", "200", "100"]], "outputs": [["0"]]}
INTERVIEW
PYTHON3
CODECHEF
9,246
263731cbaf494eb12dc6cdf0f6884f49
UNKNOWN
Three numbers A, B and C are the inputs. Write a program to find second largest among them. -----Input----- The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains three integers A, B and C. -----Output----- For each test case, display the second largest among A...
["# cook your dish here\nx=int(input())\nfor i in range(x):\n s=list(map(int,input().split()))\n s.sort()\n print(s[1])\n \n \n", "for i in range(int(input())):\r\n a=list(map(int, input().split()))\r\n a.sort()\r\n print(a[1])", "n= int(input())\nfor i in range(n):\n a,b,c= list(map(int,inpu...
{"inputs": [["3", "120 11 400", "10213 312 10", "10 3 450"]], "outputs": [["120", "312", "10"]]}
INTERVIEW
PYTHON3
CODECHEF
5,357
7839c12ac105eb08da1304c584f1e30d
UNKNOWN
Chef had a sequence of positive integers with length $N + K$. He managed to calculate the arithmetic average of all elements of this sequence (let's denote it by $V$), but then, his little brother deleted $K$ elements from it. All deleted elements had the same value. Chef still knows the remaining $N$ elements — a sequ...
["def __starting_point():\n t=int(input())\n for _ in range(t):\n n,k,v=map(int,input().split())\n li=list(map(int,input().split()))\n sumn=0\n for i in range(n):\n sumn=sumn+li[i]\n sumk=v*(n+k)-sumn\n e=int(sumk/k)\n r=sumk%k\n if e<=0:\n print(-1)\n elif r!=0:\n print(-1)\n else:\n print(e)\n__star...
{"inputs": [["3", "3 3 4", "2 7 3", "3 1 4", "7 6 5", "3 3 4", "2 8 3"]], "outputs": [["4", "-1", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
6,150
dd0e92ccd029b6c89b8a53627662e4a8
UNKNOWN
Write a program to obtain a number $N$ and increment its value by 1 if the number is divisible by 4 $otherwise$ decrement its value by 1. -----Input:----- - First line will contain a number $N$. -----Output:----- Output a single line, the new value of the number. -----Constraints----- - $0 \leq N \leq 1000$ -----Sa...
["# cook your dish here\nn = int(input())\nif(n%4==0):\n print(n+1)\nelse:\n print(n-1)", "n=int(input())\nif n%4==0:\n n+=1\nelse:\n n-=1\nprint(n)", "# cook your dish h\nn = int(input())\nif n%4==0:\n print(n+1)\nelse:\n print(n-1)", "# cook your dish h\nn = int(input())\nif n%4==0:\n print(n+1)\...
{"inputs": [["5"]], "outputs": [["4"]]}
INTERVIEW
PYTHON3
CODECHEF
2,205
48f86daf89cf7750b3550e779aaa903a
UNKNOWN
You will be given a two-dimensional array with row consisting values 0 or 1. A move consists of choosing any column or row, and toggling all the 0’s as 1’s and 1’s as 0’s. After making the required moves, every row represents a binary number and the score of the matrix will be sum of all the numbers represented as ...
["def matrixScore(A):\r\n \"\"\"\r\n :type A: List[List[int]]\r\n :rtype: int\r\n \"\"\"\r\n m,n = len(A),len(A[0])\r\n # \u884c\u53d8\u6362\r\n for i in range(m):\r\n if A[i][0] == 1: continue\r\n for j in range(n):\r\n A[i][j] = 1 -...
{"inputs": [["3 4", "0 0 1 1", "1 0 1 0", "1 1 0 0"]], "outputs": [["39"]]}
INTERVIEW
PYTHON3
CODECHEF
7,341
28bd59a096ce015799d8912966c6f844
UNKNOWN
A sequence of integers ($a_1, a_2, \ldots, a_k$) is said to be UpDown, if these inequalities hold true: - $a_1 \le a_2$ - $a_2 \ge a_3$ - $a_3 \le a_4$ and so on. That is, every even-indexed element should be at least as large as its adjacent elements. And every odd-indexed element should be at most as large as its adj...
["# cook your dish here\nt=int(input())\nfor _ in range(t):\n n=int(input())\n array=list(map(int, input().split()))\n list_sub=[]\n idx=0\n counter=0\n for i in range(n-1):\n if counter%2==0 and array[i]<=array[i+1]:\n counter+=1 \n elif counter%2==1 and array[i]>=array[i+1]:...
{"inputs": [["2", "7", "100 1 10 3 20 25 24", "5", "3 3 2 4 1"]], "outputs": [["7", "6"]]}
INTERVIEW
PYTHON3
CODECHEF
24,155
fe66e61ed3a0fb280e83f920e8d39de6
UNKNOWN
Binod is a youtuber and he is busy in the fame of social media so he asked you to help him solve a problem. You have been given an array of $positive$ $integers$ $a_{1},a_{2},a_{3},...,a_{i},...,a_{n}$ of size n.You have to find the smallest length of the subarray such that the length of the subarray must be $strictly$...
["#binarr\r\ndef binarr(a, k, s):\r\n a.sort(reverse=True)\r\n arr = [0]*k\r\n for i in range(k):\r\n arr[i] = a[i]\r\n if sum(arr) <= s:\r\n return binarr(a, k+1, s)\r\n return len(arr)\r\n\r\ntry:\r\n n, k, s = list(map(int, input().split()))\r\n a = list(map(int, input().split()))\...
{"inputs": [["1:", "5 1 5", "1 2 3 4 5"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
882
da9479e0c5ee81cf219c30d6ce2de326
UNKNOWN
The chef was busy in solving algebra, he found some interesting results, that there are many numbers which can be formed by the sum of the factorial of the digits, he wrote all those interesting numbers in the diary(in increasing order) and went to sleep. Cheffina came and stole his diary, in morning chef found that hi...
["t = int(input())\nfor i in range(t):\n n = int(input())\n if n == 1 or n == 2 or n == 145 or n == 40585:\n print(1)\n else:\n print(0)\n", "from collections import Counter\r\nimport string\r\nimport math\r\nimport sys\r\n# sys.setrecursionlimit(10**6) \r\ndef isprime(x): \r\n \r\n # che...
{"inputs": [["2", "2", "10"]], "outputs": [["1", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
3,014
a754cba7331fbf4e37df8b37b623776e
UNKNOWN
Raju has created a program to find the square root of a number. But his program can store only integers. Being a newbie, he didn't know about rounding the numbers. Hence his program returns the absolute value of the result if possible. For example, sqrt(3) = 1.73205080757……. His program will return 1 Given a number $N$...
["try:\n from math import sqrt\n t,x=list(map(int,input().split()))\n for _ in range(t):\n n=int(input())\n if(n<0):\n print(\"no\")\n else:\n diff=(x/100)*n\n ans=int(sqrt(n))\n ans1=ans**2\n if(n-ans1<=diff):\n print(\"yes\")\n else:\n print(\"no\")\nexcept:\n pass\n", "import math \nt,x=map(int,...
{"inputs": [["2 20", "5", "3"]], "outputs": [["yes", "no"]]}
INTERVIEW
PYTHON3
CODECHEF
6,640
b6dfe41dec421b6d157a7b330a341cbc
UNKNOWN
Kabir wants to impress Tara by showing her his problem solving skills. He has decided to give the correct answer to the next question which will be asked by his Algorithms teacher. The question asked is: Find the sum of alternate consecutive d$d$ odd numbers from the range L$L$ to R$R$ inclusive. if d$d$ is 3 and L$L$ ...
["# cook your dish here\nfor t in range(int(input().strip())):\n d = int(input().strip())\n L, R = map(int, input().strip().split(\" \"))\n if L % 2 == 0:\n L += 1\n sum = (((((R - L + 2)//2)//d)+1)//2) - 1\n sum = (sum * 2 * d * (sum + 1) * d) + (sum+1) *d * (L + d -1)\n print(sum%1000000007)"...
{"inputs": [["1", "3", "10 33"]], "outputs": [["114"]]}
INTERVIEW
PYTHON3
CODECHEF
1,267
51eb1a3a05f25cc01e3da8f7dd261862
UNKNOWN
You are given a string $S$ and an integer $L$. A operation is described as :- "You are allowed to pick any substring from first $L$ charcaters of $S$, and place it at the end of the string $S$. A string $A$ is a substring of an string $B$ if $A$ can be obtained from $B$ by deletion of several (possibly, zero or all) c...
["def least_rotation(S: str) -> int:\r\n \"\"\"Booth's algorithm.\"\"\"\r\n f = [-1] * len(S) # Failure function\r\n k = 0 # Least rotation of string found so far\r\n for j in range(1, len(S)):\r\n sj = S[j]\r\n i = f[j - k - 1]\r\n while i != -1 and sj != S[k + i + 1]:\r\n ...
{"inputs": [["2", "1 rga", "2 cab"]], "outputs": [["arg", "abc"]]}
INTERVIEW
PYTHON3
CODECHEF
6,974
b64204109c638a9e118da10265b27619
UNKNOWN
This year $p$ footballers and $q$ cricketers have been invited to participate in IPL (Indian Programming League) as guests. You have to accommodate them in $r$ rooms such that- - No room may remain empty. - A room may contain either only footballers or only cricketers, not both. - No cricketers are allowed to stay alon...
["# cook your dish here\nMOD = 998244353\n\nfball = [ [0]*101 for _ in range(101) ]\n\ncric = [ [0]*101 for _ in range(101) ] \n\n\n\ndef calSNum(n, r):\n if n == r or r == 1:\n fball[r][n] = 1\n return\n if n > 0 and r > 0 and n > r:\n fball[r][n] = (fball[r-1][n-1]%MOD + (r*fball[r][n-1])%MOD )%MOD\n return\n fba...
{"inputs": [["4", "2 1 4", "2 4 4", "2 5 4", "2 8 4"]], "outputs": [["0", "3", "10", "609"]]}
INTERVIEW
PYTHON3
CODECHEF
8,544
20405650bb8da9e9610a0a882b293013
UNKNOWN
Chef organised a chess tournament, which spanned over $M$ months. There were $N$ players, and player $i$ was rated $R_i$ before the start of the tournament. To see the progress of the players, he noted their rating changes at the end of each month. After the tournament, FIDE asked Chef to find the number of players who...
["# cook your dish here\nt=int(input())\nfor _ in range(t):\n n,m=list(map(int,input().split()))\n r=list(map(int,input().split()))\n rating=[[r[i]]*(m) for i in range(n)]\n ranking=[[0]*m for i in range(n)]\n for i in range(n):\n diff=list(map(int,input().split()))\n for j in range(m):\n rating[i][j]+=diff[j]\n ...
{"inputs": [["2", "3 3", "2500 2500 2520", "10 -5 -20", "10 15 20", "-15 17 13", "2 3", "2125 2098", "-20 10 -10", "10 10 -20"]], "outputs": [["2", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
21,988
a1151ddfb661e722413a027d3ba8cd23
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\n\nt = int(input())\n\nfor _ in range(t):\n s = ''\n n = int(input())\n if n==1:\n print(1)\n continue\n for i in range(1, n+1):\n s = s + str(i)\n print(s)\n \n p = 1\n for i in range(n-1):\n s = ''\n for j in range(n):\n s =...
{"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["1", "12", "34", "123", "456", "789", "1234", "5678", "9101112", "13141516"]]}
INTERVIEW
PYTHON3
CODECHEF
6,251
c6fe1f8015e860dbcfb72c8e9da68491
UNKNOWN
Diana is planning to make a very long journey. Her journey consists of $N$ bus routes, numbered from $1 to N$ in the order she must take them. The buses themselves are very fast but do not run often. The $i-th$ bus route only runs every $Xi$ days. More specifically, she can only take the $i-th$ bus on day $Xi, 2Xi, 3X...
["t = int(input())\r\nfor _ in range(t):\r\n nd = list(map(int, input().split()))\r\n n = nd[0]\r\n d = nd[1]\r\n cutOff = []\r\n x = d\r\n buses = list(map(int, input().split()))\r\n for i in range(len(buses)-1,-1,-1):\r\n x = x - x%buses[i]\r\n print(x)\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r...
{"inputs": [["3", "3 10", "3 7 2", "4 100", "11 10 5 50", "1 1", "1"]], "outputs": [["6", "99", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
6,975
280bfd6883fb5ebcb4c2c05dde00863d
UNKNOWN
You are given an array A with size N (indexed from 0) and an integer K. Let's define another array B with size N · K as the array that's formed by concatenating K copies of array A. For example, if A = {1, 2} and K = 3, then B = {1, 2, 1, 2, 1, 2}. You have to find the maximum subarray sum of the array B. Fomally, you ...
["def max_sum(arr):\n # Finds the maximum sum of sub-arrays of arr\n max_till_now = -1000000 #minimum possible number \n current_sum = 0\n for i in range(len(arr)):\n if current_sum < 0:\n # If sum of previous elements is negative, then ignore them. Start fresh\n # with `current...
{"inputs": [["2", "2 3", "1 2", "3 2", "1 -2 1", "", ""]], "outputs": [["9", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
22,314
84ea416af4fe1b547a3c36a2785a6167
UNKNOWN
Nadaca is a country with N$N$ cities. These cities are numbered 1$1$ through N$N$ and connected by M$M$ bidirectional roads. Each city can be reached from every other city using these roads. Initially, Ryan is in city 1$1$. At each of the following K$K$ seconds, he may move from his current city to an adjacent city (a ...
["T = int(input())\nfor _ in range(T):\n N, M, K = [int(x) for x in input().split()]\n UV = [[int(x) for x in input().split()] for _ in range(M)]\n Q = int(input())\n AB = [[int(x) for x in input().split()] for _ in range(Q)]\n \n X = [[i] for i in range(N)]\n for u, v in UV:\n X[u - 1] += [v - 1]...
{"inputs": [["3", "4 3 3", "1 2", "1 3", "1 4", "0", "4 3 3", "1 2", "1 3", "1 4", "1", "2 2", "4 3 3", "1 2", "1 3", "1 4", "1", "2 1"]], "outputs": [["28", "4", "6"]]}
INTERVIEW
PYTHON3
CODECHEF
695
4c6b5f2b5669a9db874e2388e37b24f3
UNKNOWN
Sereja has an array A of N positive integers : A[1], A[2], A[3], ... , A[N]. In a single operation on the array, he performs the following two steps : - Pick two indices i, j s.t. A[i] > A[j] - A[i] -= A[j] Sereja can apply these operations any number of times (possibly zero), such that the sum of resulting eleme...
["def gcd(a,b):\n if b==0:\n return a\n else:\n return gcd(b,a%b)\n \ndef main():\n t=int(input())\n while t!=0:\n t=t-1\n n=int(input())\n if n==1:\n print(input())\n else:\n a=list(map(int,input().split(\" \")))\n p=a[0]\n for i in range(1,n):\n p=gcd(p,a[i])\n if p==1:\n break\n print(n*p)\...
{"inputs": [["2", "1", "1", "3", "2 4 6"]], "outputs": [["1", "6"]]}
INTERVIEW
PYTHON3
CODECHEF
4,437
95970ee45ecd31ccff1c1bf2d7585b77
UNKNOWN
Chef is going to start playing Fantasy Football League (FFL) this season. In FFL, each team consists of exactly $15$ players: $2$ goalkeepers, $5$ defenders, $5$ midfielders and $3$ forwards. Chef has already bought $13$ players; he is only missing one defender and one forward. There are $N$ available players (numbered...
["for i in range(int(input())):\n n,s =map(int,input().split())\n l1=list(map(int,input().split()))\n l2=list(map(int,input().split()))\n m=[]\n n=[]\n for i in range(len(l1)):\n if l2[i]==0:\n m.append(l1[i])\n else:\n n.append(l1[i])\n if len(m)>0 and len(n)>0:\n if 100-s>=(min(m)+min(n)):\n print(\"yes\")\n...
{"inputs": [["2", "4 90", "3 8 6 5", "0 1 1 0", "4 90", "5 7 6 5", "0 1 1 0"]], "outputs": [["yes", "no"]]}
INTERVIEW
PYTHON3
CODECHEF
9,907
4836988a54b09999918765b13d85e3fc
UNKNOWN
In my town ,there live a coder named Chef . He is a cool programmer . One day , he participate in a programming contest ,the contest give him only one problem . If he can’t solve the problem ,the problem setter will kill him . But the round allow you to help Chef. Can you save the life of Chef from problem setter ? :p ...
["# cook your dish here\nfrom math import sqrt\nfor i in range(int(input())):\n x1,y1,x2,y2=list(map(float,input().split()))\n m=(y2-y1)/(x2-x1)\n c=y2-m*x2\n print('Test case : ',i+1)\n q=int(input())\n for i in range(q):\n x3,y3=list(map(float,input().split()))\n if(y3-m*x3-c==0):\n print(\"YES\")\n else:\n d=...
{"inputs": [["2", "3 5 6 5", "2", "4 5", "6 8", "3 4 7 10", "1", "7 4"]], "outputs": [["Test case : 1", "YES", "NO", "3.000000", "Test case : 2", "NO", "3.328201"]]}
INTERVIEW
PYTHON3
CODECHEF
3,158
3cfe9b9b228a598c5b33e8cc8aceb763
UNKNOWN
Its Christmas time and Santa has started his ride to deliver gifts to children waiting for him in a 1-dimentional city. All houses in this city are on a number line numbered as 1, 2, 3… and so on. Santa wants to deliver to houses from n to m, but he found that all the kids living at positions that are divisible by a, a...
["from math import gcd\r\nfrom math import ceil\r\nfrom itertools import combinations as c\r\nt=int(input())\r\nfor _ in range(t):\r\n n,m,a,d=list(map(int,input().split()))\r\n \r\n l=[]\r\n for i in range(5):\r\n l.append(a+i*d)\r\n ans=m-n+1\r\n for i in range(1,6):\r\n x=list(c(l,i))...
{"inputs": [["1", "2 20 2 1"]], "outputs": [["5"]]}
INTERVIEW
PYTHON3
CODECHEF
618
9732572ab97e395d6423676a86951c0a
UNKNOWN
Chef bought an electronic board and pen. He wants to use them to record his clients' signatures. The board is a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$) of pixels. Initially, all pixels are white. A client uses the electronic pen to sign on the board; whenever the pen tou...
["import numpy as np\nfor _ in range(int(input())):\n ans = np.float('inf')\n n, m = (int(x) for x in input().split())\n sig = np.zeros((n,m))\n img = np.zeros((3*n,3*m))\n for row in range(n):\n sig[row,:] = np.array([int(x) for x in input()])\n for row in range(n):\n img[row+n,m:2*m] = np.array([int(x) for x in inp...
{"inputs": [["5", "3 3", "100", "010", "000", "000", "010", "001", "4 4", "0000", "0110", "0000", "0011", "1100", "0000", "1100", "0000", "3 3", "100", "000", "001", "000", "010", "000", "3 3", "000", "010", "000", "100", "000", "001", "3 3", "111", "000", "000", "001", "001", "001"]], "outputs": [["0", "2", "1", "0", ...
INTERVIEW
PYTHON3
CODECHEF
1,347
2abc4ce3c377f2fba2619bbad2a00c9e
UNKNOWN
A permutation $p_1,p_2...p_N$ of $\{1, 2, ..., N\}$ is beautiful if $p_i \& p_{i+1}$ is greater than 0 for every $1 \leq i < N$ . You are given an integer $N$, and your task is toconstruct a beautiful permutation of length $N$ or determine that it's impossible. Note that $a \& b$ denotes the bitwise AND of $a$ and $b$....
["import math\ndef ispoweroftwo(y):\n return math.ceil(math.log(y,2))==math.floor(math.log(y,2))\nt=int(input())\nfor i in range(t):\n n=int(input())\n \n a=[]\n if(ispoweroftwo(n) and n!=1):\n print(-1,end=\" \")\n if(n==1):\n print(1)\n \n if(n>=3 and not(ispoweroftwo(n))):\n a.append(2)\n a.append(3)\n a.append...
{"inputs": [["3", "4", "3", "5"]], "outputs": [["-1", "1 3 2", "2 3 1 5 4"]]}
INTERVIEW
PYTHON3
CODECHEF
10,799
2deaee0348e18c0ad9c76e68070c045a
UNKNOWN
There is an event in DUCS where boys get a chance to show off their skills to impress girls. The boy who impresses the maximum number of girls will be honoured with the title “Charming Boy of the year”. There are $N$ girls in the department. Each girl gives the name of a boy who impressed her the most. You need to find...
["from collections import Counter\r\n\r\nfor _ in range(int(input())):\r\n n=int(input())\r\n l=[i for i in input().split()]\r\n ll=[]\r\n c=Counter(l)\r\n cc=[]\r\n m=0\r\n for l,count in c.most_common(len(l)-1):\r\n if m==0:\r\n ll.append(l)\r\n cc.append(count)\r\n ...
{"inputs": [["2", "10", "john berry berry thomas thomas john john berry thomas john", "4", "ramesh suresh suresh ramesh"]], "outputs": [["john", "ramesh"]]}
INTERVIEW
PYTHON3
CODECHEF
14,503
13d7a677521786c53a954b648a1118d7
UNKNOWN
Computation of the date either previous or forthcoming dates is quiet easy. But it is quiet difficult to calculate the day from a particular given date. You are required to find a day from a particular date given to you. -----Input----- It consists of a single line entry consisting of date in format dd mm yyyy. i.e. ...
["import sys\nimport datetime\na,b,c = list(map(int,sys.stdin.readline().split()))\nd = datetime.date(c,b,a)\nprint(d.strftime(\"%A\"))", "import sys\nfrom datetime import date\na,b,c = list(map(int,sys.stdin.readline().split()))\nd = date(c,b,a)\nprint(d.strftime(\"%A\"))", "import sys\nfrom datetime import date\na,b,...
{"inputs": [["14 3 2012"]], "outputs": [["Wednesday"]]}
INTERVIEW
PYTHON3
CODECHEF
969
809aca7397fbe8370849064559c5f6f4
UNKNOWN
Snackdown 2019 is coming! People have started to spread the word and tell other people about the contest. There are $N$ people numbered $1$ through $N$. Initially, only person $1$ knows about Snackdown. On each day, everyone who already knows about Snackdown tells other people about it. For each valid $i$, person $i$ c...
["# cook your dish here\ntest_case = int(input())\nwhile test_case :\n n_people = int(input())\n array = list(map(int, input().strip().split()))\n sums =[0 for i in range(n_people)]\n \n sums[0] = array[0]\n \n for i in range(1, n_people) :\n sums[i] = sums[i-1] + array[i]\n \n # print(sums)\n\n k = 1 \n count = 0\n ...
{"inputs": [["2", "7", "2 1 1 5 5 5 5", "5", "5 1 3 2 1"]], "outputs": [["2", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
6,983
faabaf1f1aada4ba4719cc9dbfa26c4e
UNKNOWN
Harry is a bright student. To prepare thoroughly for exams, he completes all the exercises in his book! Now that the exams are approaching fast, he is doing book exercises day and night. He writes down and keeps updating the remaining number of exercises on the back cover of each book. Harry has a lot of books messed o...
["t=eval(input())\n \na=[]\nb=[]\n \ntop=-1\n \nfor __ in range(0,t):\n \n x=input().split()\n \n if(x[0]!=\"-1\" and x[0]!=\"0\"):\n \n add=int(x[0])\n \n if top!=-1 and add>a[top][0] :\n \n b[top]+=1\n \n else:\n a.append((add,x[1]))\n \n b.append(0)\n top+=1\n \n \n elif (x[0]==\"-1\"):\n...
{"inputs": [["6", "9 english", "6 mathematics", "8 geography", "-1", "3 graphics", "-1"]], "outputs": [["1 mathematics", "0 graphics"]]}
INTERVIEW
PYTHON3
CODECHEF
9,864
7b20cd02b312a2328d5c68991420e156
UNKNOWN
You are given two integer sequences $A_1, A_2, \ldots, A_N$ and $B_1, B_2, \ldots, B_M$. For any two sequences $U_1, U_2, \ldots, U_p$ and $V_1, V_2, \ldots, V_q$, we define Score(U,V)=∑i=1p∑j=1qUi⋅Vj.Score(U,V)=∑i=1p∑j=1qUi⋅Vj.Score(U, V) = \sum_{i=1}^p \sum_{j=1}^q U_i \cdot V_j \,. You should process $Q$ queries of...
["t = int(input())\nl,r,x = 0,0,0\nans = []\nfor i in range(t):\n (n,m) = tuple(map(int,input().split()))\n a = list(map(int,input().split()))\n b = list(map(int,input().split()))\n suma = sum(a)\n sumb = sum(b)\n q = int(input())\n for j in range(q):\n l1 = list(map(int,input().split()))\n if l1[0] == 1:\n l = l1[...
{"inputs": [["1", "3 4", "2 -1 5", "3 3 2 4", "6", "3", "1 2 3 -2", "3", "1 1 3 1", "2 2 4 2", "3"]], "outputs": [["72", "24", "90"]]}
INTERVIEW
PYTHON3
CODECHEF
4,428
aa685e3b12e8b58a9b74fb3856f17e8b
UNKNOWN
You are playing following game: given an array A of N natural numbers. All numbers in the array A are at most M. On every turn you may pick any two different elements Ai and Aj (i≠j), such that Ai, Aj ≤ M, and add K to both. The game ends when you are not able to continue. That is, when there is no pair (i,j) left such...
["\nfrom math import ceil\nfrom bisect import bisect_right as b_r\nfrom bisect import bisect_left as b_l\nar = list(map(int , input().split()))\na = [int(ceil((ar[1]-int(x)+1)/ar[2])) for x in input().split()]\ns = sum(a)\nar[1] = max(a)\nm = ar[1] - (s-ar[1])%2\nmi = s%2 \nprint(int( (m-mi)//2 +1)%(10**9+7))\n\n"]
{"inputs": [["3 3 2", "1 2 3"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
316
bd2abe2dedac629a6b68271fb8ccbdca
UNKNOWN
Rohit collects coins: he has exactly one coin for every year from 1 to n. Naturally, Rohit keeps all the coins in his collection in the order in which they were released. Once Rohit's younger brother made a change — he took all the coins whose release year dated from l to r inclusively and put them in the reverse order...
["n=int(input())\na=list(map(int,input().split()))\n\nl,r=-1,-1\nfor i in range(n):\n if a[i]!=i+1:\n l=i\n break\n\nfor i in range(n-1,-1,-1):\n if a[i]!=i+1:\n r=i\n break\n\nj=r+1\n\nfor i in range(l,r+1):\n if a[i]==j:\n j-=1\n continue\n else:\n print(0,...
{"inputs": [["8", "1 6 5 4 3 2 7 8"]], "outputs": [["2 6"]]}
INTERVIEW
PYTHON3
CODECHEF
11,979
1dc885c61236de65227e01eeec9f7fb0
UNKNOWN
-----Problem Statement----- Write a program that accepts a number, n, and outputs the same. -----Input----- The only line contains a single integer. -----Output----- Output the answer in a single line. -----Constraints----- - 0 ≤ n ≤ 105 -----Sample Input----- 123 -----Sample Output----- 123
["# cook your dish here\na = int(input())\nprint(a)", "# cook your dish here\nnum = int(input())\nprint(num)", "# cook your dish here\nnum = int(input())\nprint(num)", "a=int(input(\"\"))\nprint(a)", "a=int(input())\nprint(a)", "from sys import *\n\n\ndef main():\n nombre = stdin.readline().strip()\n stdout.write...
{"inputs": [["123"]], "outputs": [["123"]]}
INTERVIEW
PYTHON3
CODECHEF
1,194
7764d606b8e627290e2890304c1efaa4
UNKNOWN
Congratulations !!! You have successfully completed the heist by looting all the gifts in Santa's locker. Now it's time to decide who gets to take all the gifts, you or the Grinch, there will be no splitting. So you and Grinch decide to play a game. To start the game, an Integer N will be given. The game is played in t...
["# cook your dish here\nimport math \n \n# Function to find the Largest \n# Odd Divisor Game to check \n# which player wins \ndef findWinner(n, k): \n \n cnt = 0; \n \n # Check if n == 1 then \n # player 2 will win \n if (n == 1): \n print(\"Grinch\"); \n \n # Check if n == 2 or ...
{"inputs": [["7", "1", "2", "3", "4", "5", "6", "12"]], "outputs": [["Grinch", "Me", "Me", "Grinch", "Me", "Grinch", "Me"]]}
INTERVIEW
PYTHON3
CODECHEF
12,817
5f376e35a1e29c3eb354821851ab5325
UNKNOWN
You are given an axis-aligned rectangle in a 2D Cartesian plane. The bottom left corner of this rectangle has coordinates (0,0)$(0, 0)$ and the top right corner has coordinates (N−1,N−1)$(N-1, N-1)$. You are also given K$K$ light sources; each light source is a point inside or on the perimeter of the rectangle. For eac...
["# https://www.codechef.com/problems/RECTLIT\r\n\r\ndef assess(sq,points):\r\n EWct = 0\r\n NSct = 0\r\n for a,b in points:\r\n EW = (a == 0 or a == sq)\r\n NS = (b == 0 or b == sq)\r\n if EW and NS:\r\n return 'yes'\r\n EWct += EW\r\n NSct += NS\r\n if NSct + ...
{"inputs": [["2", "2 10", "0 0", "1 0", "2 10", "1 2", "1 1"]], "outputs": [["yes", "no"]]}
INTERVIEW
PYTHON3
CODECHEF
3,529
232d4c4658c3f5d4cb12d6548636dead
UNKNOWN
Chef has been working in a restaurant which has N floors. He wants to minimize the time it takes him to go from the N-th floor to ground floor. He can either take the elevator or the stairs. The stairs are at an angle of 45 degrees and Chef's velocity is V1 m/s when taking the stairs down. The elevator on the other ...
["n=int(input())\nl=[]\nfor i in range(0,n):\n a,b,c=map(int,input().split())\n n1=(2**0.5)*(a/b)\n n2=2*(a/c)\n if n1>n2:\n l.append(\"Elevator\")\n else:\n l.append(\"Stairs\")\nfor i in l:\n print(i)", "n=int(input())\nl=[]\nfor i in range(0,n):\n a,b,c=list(map(int,input().split()))\n n1=(2**0.5)*(a/b)\n n2=2*(a/...
{"inputs": [["3", "5 10 15", "2 10 14", "7 14 10"]], "outputs": [["Elevator", "Stairs", "Stairs"]]}
INTERVIEW
PYTHON3
CODECHEF
5,820
550a75ca0971313346de7415f7f4b90f
UNKNOWN
The Little Elephant likes permutations. This time he has a permutation A[1], A[2], ..., A[N] of numbers 1, 2, ..., N. He calls a permutation A good, if the number of its inversions is equal to the number of its local inversions. The number of inversions is equal to the number of pairs of integers (i; j) such that 1 ≤ ...
["from sys import stdin\nt = int(stdin.readline())\n\ndef count(n, arr):\n loc = 0\n glob = 0\n for i in range(n-1):\n if arr[i] > arr[i+1]:\n loc += 1\n for i in range(n-1):\n for j in range(i+1, n):\n if glob > loc:\n return 0\n if arr[i] > arr[j]:\n glob += 1;\n if glob == loc:\n return 1\n return 0\n...
{"inputs": [["4", "1", "1", "2", "2 1", "3", "3 2 1", "4", "1 3 2 4"]], "outputs": [["YES", "YES", "NO", "YES"]]}
INTERVIEW
PYTHON3
CODECHEF
1,017
1779ea4d9e06cc1f00d0d676c03d7d21
UNKNOWN
You are given a string s of length 8 consisting solely of '0's and '1's. Assume that the characters of the string are written in a circular fashion. You need to find the number of 0-1 or 1-0 transitions that one has to make while making a single traversal over the string. ie. start from any character and go circularly ...
["n = int(input())\n# this code only for 8 bits string and it isn't possible to more than 8 bits of \u00a0\u00a0\u00a0\u00a0string \n\n# for i in range(n):\n# s = input()\n# subString1, subString2 = s[:4], s[4:]\n# rev = subString2[::-1]\n# print( 'uniform' if(subString1 == rev) else 'non-uniform'...
{"inputs": [["4", "00000000", "10101010", "10000001", "10010011"]], "outputs": [["uniform", "non-uniform", "uniform", "non-uniform"]]}
INTERVIEW
PYTHON3
CODECHEF
5,873
f23192a8436f9d9e66b0c7b03eb32cbf
UNKNOWN
In africa jungle , there were zebra's who liked to spit. There owner watched them for whole day and noted in his sheet where each zebra spitted. Now he's in a confusion and wants to know if in the jungle there are two zebra's which spitted at each other. Help him solve this task. If the zebra is present in position a s...
["# cook your dish here\nt=int(input())\ni=0\na=0\nd=dict()\nwhile i<t:\n l=input().split()\n d[int(l[0])]=int(l[0])+int(l[1])\n i+=1\nfor k in d:\n if d[k] in d:\n if d[d[k]]==k:\n a=1\n break\nif a==1:\n print(\"YES\")\nelse:\n print(\"NO\")", "# cook your dish here\nt=i...
{"inputs": [["2", "0 1", "1 -1"]], "outputs": [["YES"]]}
INTERVIEW
PYTHON3
CODECHEF
9,332
d73ae96f241699d50e9eb0de1bb90760
UNKNOWN
You are a king and you are at war. If the enemy breaks through your frontline you lose. Enemy can break the line only if the sum of morale of any $K$ continuous soldiers is strictly less than $M$. So, you being a motivational orator decides to boost their morale by giving a speech. On hearing it morale of a soldier mul...
["n,k,m = map(int,input().split())\nar = list(map(int,input().split()))\nfsum = [ar[0]]\nfor i in range(1,n):\n fsum.append(fsum[i-1]+ar[i])\ni = k\n#print(fsum)\nc = 0\nwhile i <= n:\n if i == k:\n s = fsum[i-1]\n else:\n s = fsum[i-1]-fsum[i-k-1]\n if s == 0:\n c = -1\n break\n...
{"inputs": [["6 2 5", "1 1 1 1 1 1"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
3,245
9371ce348e7419e45dbb4927632ba1c8
UNKNOWN
You are given a sequence $A_1, A_2, \ldots, A_N$. For each valid $i$, the star value of the element $A_i$ is the number of valid indices $j < i$ such that $A_j$ is divisible by $A_i$. Chef is a curious person, so he wants to know the maximum star value in the given sequence. Help him find it. -----Input----- - The fir...
["T = int(input())\nfor _ in range(T):\n n = int(input())\n arr = list(map(int, input().split()))\n a = [0 for _ in range(max(arr)+1)]\n star_val = []\n for i in range(len(arr)):\n j = 1\n val = 0\n while j*arr[i] <= len(a):\n val += a[j*arr[i]-1]\n j += 1\n star_val.append(val)\n a[arr[i]-1] += 1\n print(max(...
{"inputs": [["1", "7", "8 1 28 4 2 6 7"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
7,790
eb4551ca59fc0d63af1e9453068731dc
UNKNOWN
There is crazy man named P29892P. He always tries to do crazy things as he thinks. One day he invented a machine and named it as ANGEN. The ANGEN is used to perform range operations. The range operation means performing operations on range values from {L..R}. At any time it performs operations on values in between L to...
["VQ = \"UAMmSs\"\nn = int(input())\na = list(map(int, input().split()))\nfor _ in range(int(input())):\n q, x, y = input().split()\n if q not in VQ:\n print(\"!!!\")\n continue\n if q == \"U\":\n a[int(x) - 1] = int(y)\n continue\n l = int(x) - 1\n r = int(y)\n if q == \"A\":\n print(sum(a[l:r]))\n continue\n if...
{"inputs": [["6", "1 2 5 3 10 6", "6", "A 1 5", "M 1 3", "m 5 6", "s 3 6", "U 1 7", "S 1 2"]], "outputs": [["21", "5", "6", "5", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
7,699
fe8ff5fda6eab48edcb70523e86050e5
UNKNOWN
Write a program to find the factorial value of any number entered by the user. -----Input----- The first line contains an integer T, the total number of testcases. Then T lines follow, each line contains an integer N. -----Output----- For each test case, display the factorial of the given number N in a new line. -...
["# cook your dish here\nx=int(input())\nfor i in range(x):\n s=int(input())\n fact=1\n for i in range(1,s+1):\n fact=fact*i\n print(fact)\n", "# cook your dish here\nfor _ in range(int(input())):\n n= int(input())\n fact=1\n if n==0:\n pass\n else:\n for i in range(1, n+1):...
{"inputs": [["3", "3", "4", "5"]], "outputs": [["6", "24", "120"]]}
INTERVIEW
PYTHON3
CODECHEF
4,041
554f5550ae91d0bced4eae5da2bbf8d5
UNKNOWN
The MarkiT online virtual market startup wants to organize its grand opening in NIT Patna. but they want maximum crowd for their inauguration. So the manager told this to Praveen a student in NITP who suggested them: The first-year students come to campus every x hour, Second-year students come to campus every y hou...
["import math\ndef fun(num1,num2):\n if num1>num2:\n a=num1\n b=num2\n else:\n a=num2\n b=num1\n rem=a%b\n while(rem!=0):\n a=b\n b=rem\n rem=a%b\n gcd=b\n return (int((num1*num2)/gcd))\n \nfor _ in range (int(input())):\n hours=int(input())*24\n x,y,z=list(map(int,input().split()))\n lcm=x\n lcm=fun(x,y)\n lcm...
{"inputs": [["1", "10", "8 10 6"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
9,030
c98a76e9ba053ba37e44844dbf3224fc
UNKNOWN
You are given three non-negative integers $X$, $Y$ and $N$. Find the number of integers $Z$ such that $0 \le Z \le N$ and $(X \oplus Z) < (Y \oplus Z)$, where $\oplus$ denotes the bitwise XOR operation. -----Input----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The d...
["# cook your dish here\ntc=int(input())\nfor j in range(tc):\n ip=list(map(int,input().rstrip().split()))\n x=ip[0]\n y=ip[1]\n n=ip[2]\n cnt=0\n if(x==y):\n print('0')\n continue\n ln=bin(x).replace(\"0b\", \"\") \n rn=bin(y).replace(\"0b\", \"\") \n ll=len(ln)\n rl=len(rn)\n #print(ln)\n #print(rn)\n if(ll==len(rn...
{"inputs": [["3", "1 2 10", "2 1 10", "0 0 7"]], "outputs": [["6", "5", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
11,604
421a4146102526ca4644db0d4f88e685
UNKNOWN
You are given a permutation of natural integers from 1 to N, inclusive. Initially, the permutation is 1, 2, 3, ..., N. You are also given M pairs of integers, where the i-th is (Li Ri). In a single turn you can choose any of these pairs (let's say with the index j) and arbitrarily shuffle the elements of our permutatio...
["t=int(input())\nfor _ in range(t):\n n,m=list(map(int,input().split()))\n l=list(map(int,input().split()))\n k=[]\n for i in range(m):\n a,b=list(map(int,input().split()))\n k.append([a,b])\n k.sort()\n c=[]\n flag=1\n x=k[0][0]\n y=k[0][1]\n \n for i in k[1:]:\n if i[0]<=y:\n y=max(y,i[1])\n else:\n c.append...
{"inputs": [["2", "7 4", "3 1 2 4 5 7 6", "1 2", "4 4", "6 7", "2 3", "4 2", "2 1 3 4", "2 4", "2 3"]], "outputs": [["Possible", "Impossible"]]}
INTERVIEW
PYTHON3
CODECHEF
636
fea7769db896f25b4b949b95dba4ae18
UNKNOWN
In Programmers Army Land, people have started preparation as sports day is scheduled next week. You are given a task to form 1 team of $k$ consecutive players, from a list of sports player whose powers are given to you. You want your team to win this championship, so you have to chose your $k$ team players optimally i....
["# cook your dish here\ndef func(arr, k):\n sumi = 0\n for j in range(k):\n sumi += arr[j]\n maxi = sumi\n for i in range(k,len(arr)):\n sumi -= arr[i - k]\n sumi += arr[i]\n maxi = max(maxi,sumi)\n return maxi\nfor _ in range(int(input())):\n n, k = map(int,input().split(...
{"inputs": [["1", "5 3", "1 2 3 4 5"]], "outputs": [["12"]]}
INTERVIEW
PYTHON3
CODECHEF
10,137
5835903ed7c9044b86891c8f9c1939a3
UNKNOWN
For years you have been working hard in Santa's factory to manufacture gifts for kids in substandard work environments with no pay. You have finally managed to escape the factory and now you seek revenge. You are planning a heist with the Grinch to steal all the gifts which are locked in a safe. Since you have worked i...
["import math\nt = int(input())\n \ndef phi(n):\n\tres = n\n\ti = 2\n\twhile i*i<=n:\n\t\tif n%i==0:\n\t\t\tres/=i\n\t\t\tres*=(i-1)\n \n\t\t\twhile n%i==0:\n\t\t\t\tn/=i\n\t\ti+=1\n\t\n\tif n>1:\n\t\tres/=n\n\t\tres*=(n-1)\n \n\treturn int(res)\n \nwhile t:\n\ta,m = list(map(int,input().split()))\n\tg = math.gcd(a,m)\...
{"inputs": [["3", "4 9", "5 10", "42 9999999967"]], "outputs": [["6", "1", "9999999966"]]}
INTERVIEW
PYTHON3
CODECHEF
351
e008443214cd3d6fd75a230d22f9ec59
UNKNOWN
Chef wants to host some Division-3 contests. Chef has $N$ setters who are busy creating new problems for him. The $i^{th}$ setter has made $A_i$ problems where $1 \leq i \leq N$. A Division-3 contest should have exactly $K$ problems. Chef wants to plan for the next $D$ days using the problems that they have current...
["for T in range(int (eval(input()))):\n N,K,D=list(map(int,input().split()))\n A=list(map(int,input().split()))\n P=sum(A)//K \n print(min(P,D))\n", "# cook your dish here\n#Hello\nr=int(input())\nwhile r>0:\n n,k,d=map(int,input().split())\n l=list(map(int,input().split()))[0:n]\n sum=0\n for x in range(n):\n sum=su...
{"inputs": [["5", "1 5 31", "4", "1 10 3", "23", "2 5 7", "20 36", "2 5 10", "19 2", "3 3 300", "1 1 1"]], "outputs": [["0", "2", "7", "4", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
5,891
40cf725773f26ba957175b5246966562
UNKNOWN
Now-a-days, Manish is becoming famous for bank robbery in the country because of his cleverness, he never robs own his own.He has four workers A , B, C, and D , all working under him.All of the four take some amount for that. There are total N banks in the country and Manish wants to rob all the banks with minimum am...
["for t in range(int(input())):\n n = int(input())\n l = []\n m = []\n x = list(map(int,input().split()))\n l.append(x)\n m.append(list(x))\n for i in range(1,n):\n x = list(map(int,input().split()))\n l.append(x)\n temp = []\n for i in range(4):\n temp.append (x[i]+min(m[-1][:i]+m[-1][i+1:]))\n m.append(temp)\n...
{"inputs": [["1", "3", "4 7 2 9", "5 6 4 7", "2 6 4 3"]], "outputs": [["10"]]}
INTERVIEW
PYTHON3
CODECHEF
702
51a1c549401ce0abf22a0d99bd086b87
UNKNOWN
You are given a sequence of N$N$ powers of an integer k$k$; let's denote the i$i$-th of these powers by kAi$k^{A_i}$. You should partition this sequence into two non-empty contiguous subsequences; each element of the original sequence should appear in exactly one of these subsequences. In addition, the product of (the ...
["# cook your dish here\ndef main():\n for _ in range(int(input())):\n N, k = [int(x) for x in input().split()]\n Powers = [k ** int(x) for x in input().split()]\n \n s1, s2 = 0, sum(Powers)\n \n ans = (0, None)\n \n i = 0\n while i < N - 1:\n s1 += Powers[i]\n s2 -= Powers[i]\n ...
{"inputs": [["1", "5 2", "1 1 3 3 5"]], "outputs": [["4"]]}
INTERVIEW
PYTHON3
CODECHEF
5,274
622bf30a5a865f1efc17f9271edaa9b8
UNKNOWN
This is a peculiar functioning setup. Two Tanks are separated from each other by a wall .There is a pipe in the wall which connects both tanks which allows flow of water between them . Due to this ,there is change in temperature of both tanks , every minute temperature of Tank with larger temperature among two decrea...
["for i in range(int(input())):\n m,tc,th=map(int,input().split())\n x=(th-tc)\n if x%3!=0:\n print(\"Yes\")\n else:\n if (x//3)<=m:\n print(\"No\")\n else:\n print(\"Yes\")", "T = int(input())\nfor _ in range(T):\n m, Tc, Th = list(map(int, input().split()))\n if (Th - Tc) % 3 != 0:\n print(\"Yes\")\n else:\n ...
{"inputs": [["2", "4 5 10", "2 2 5"]], "outputs": [["Yes", "No"]]}
INTERVIEW
PYTHON3
CODECHEF
6,269
a59b59fe41503a068654b901ca3d1b28
UNKNOWN
Chef gives an integer $K$ in the input. If the given number is beautiful binary number, print it, Else find its previous beautiful binary number. A beautiful binary number is a number whose binary representation does not contain any consecutive 1s. Note: 1 is also a beautiful binary number. -----Input:----- - First-l...
["pref = []\r\n\r\nfor i in range(10 ** 5 + 10):\r\n b = bin(i)[2:]\r\n if not any(b[j] == b[j+1] == '1' for j in range(len(b) - 1)):\r\n pref.append(i)\r\n else:\r\n pref.append(pref[-1])\r\n\r\nfor i in range(int(input())):\r\n print(pref[int(input())])\r\n"]
{"inputs": [["3", "3", "6", "8"]], "outputs": [["2", "5", "8"]]}
INTERVIEW
PYTHON3
CODECHEF
287
7db4dc17303920c2a140751f03459d9e
UNKNOWN
Eugene has to do his homework. But today, he is feeling very lazy and wants to you do his homework. His homework has the following given maths problem. You are given three integers: A, N, M. You write the number A appended to itself N times in a row. Let's call the resulting big number X. For example, if A = 120, N = 3...
["# cook your dish here\nfor _ in range(int(input())):\n a,n,m = map(int,input().split(' '))\n s = len(str(a))\n #print(s)\n c = 10**s - 1\n w = c*m\n b = pow(10,n*s,w)-1\n d = b//c\n ans = (d%m)*(a%m)\n print(ans%m) ", "for _ in range(int(input())):\r\n a,n,m = map(int,input().split(' ')...
{"inputs": [["2", "12 2 17", "523 3 11", "", ""]], "outputs": [["5", "6"]]}
INTERVIEW
PYTHON3
CODECHEF
5,957
88fceef0b9f6e82f45d4cd7f1b8c10f9
UNKNOWN
A city of dimension N x N is constructed with grid of lanes. These lanes are fenced by government so that no one can cross any grid diagonally. Although a train line runs diagonally from (0,0) to (N,N). Our chef has a weird kind of phobia and is very afraid to cross the railway line. He is at point (0,0) and wants to ...
["ar = []\nar.append(1)\nfor i in range(1, 31):\n ar.append(ar[i-1]*(4*i-2)/(i+1))\nt = int(input())\nwhile(t>0):\n n = int(input())\n if(n==0):\n print(0)\n else:\n print(ar[n]*2)\n t=t-1\n"]
{"inputs": [["2", "2", "5"]], "outputs": [["4", "84"]]}
INTERVIEW
PYTHON3
CODECHEF
194
ee03f39abbd6d8e06ec4188a686ab0ab
UNKNOWN
Chef has $N$ small boxes arranged on a line from $1$ to $N$. For each valid $i$, the weight of the $i$-th box is $W_i$. Chef wants to bring them to his home, which is at the position $0$. He can hold any number of boxes at the same time; however, the total weight of the boxes he's holding must not exceed K at any time,...
["t=int(input())\nfor i in range(t):\n x,y=0,0\n n,m=list(map(int,input().split()))\n l=list(map(int,input().split()))\n if(max(l)>m):\n print(-1)\n else:\n for i in range(len(l)):\n y+=l[i]\n if(y>m):\n y=l[i]\n x+=1\n if(y>0):\n x+=1\n print(x)\n", "# cook your dish here\nfor __ in range(int(input()))...
{"inputs": [["4", "1 1", "2", "2 4", "1 1", "3 6", "3 4 2", "3 6", "3 4 3"]], "outputs": [["-1", "1", "2", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
7,309
12f32b75973b841ebb4a448fe10807ce
UNKNOWN
In 17th century our Chef was a Wizard. He asked his small son "Anshu" to bring him the secret of the Magical Mountain. The boy after travelling a lot reached the Mountain. The description of the Mountain was as follows: - Mountain contains N magical stones. Each of them has a unique number. - Mountain was divided into...
["for t in range(eval(input())):\n \n n = eval(input())\n \n a = [ [] for i in range(n+1) ]\n \n for i in range(n-1):\n x,y = list(map( int, input().split() ))\n a[x].append(y)\n a[y].append(x)\n \n vis = [0] * (n+1)\n vis[1] = 1\n\n ans = [1]\n\n t1 = [1]\n t2 = []\n \n while len(t1) > 0 :\n ...
{"inputs": [["1", "5", "1 2", "1 3", "2 4", "2 5"]], "outputs": [["1 2 3 4 5"]]}
INTERVIEW
PYTHON3
CODECHEF
650
f8e1abb698fa766ebd133d1b84dd5956
UNKNOWN
You are given a square matrix $M$ with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). Initially, all the elements of this matrix are equal to $A$. The matrix is broken down in $N$ steps (numbered $1$ through $N$); note that during this process, some elements of the matrix are simply mar...
["# cook your dish here\nfor _ in range(int(input())):\n n,k = list(map(int,input().split()))\n mod = 10**9+7\n s=0\n for i in range(1,n+1):\n p = pow(k,(2*i)-1,mod)\n # print(p)\n s=(s+p)%mod\n # print(k)\n k = (p*k)%mod\n print(s)\n\n", "# cook your dish here\nfor _ in range(int(input())):\n n,k = list(map(int,i...
{"inputs": [["1", "3 2"]], "outputs": [["511620149"]]}
INTERVIEW
PYTHON3
CODECHEF
6,860
a2ac2a1ed9c01eacbc0815542f43a4a0
UNKNOWN
$Gogi$, $Tapu$ and $Sonu$ are the elite members of $Tapu$ $Sena$. $Gogi$ is always stoned and asks absurd questions, But this time he asked a question which seems to be very serious and interesting. $Tapu$ wants to solve this question to impress $Sonu$. He gave an array of length N to $Tapu$, $Tapu$ can perform the fo...
["# cook your dish here\ntry:\n t = int(input())\n for _ in range(t):\n n = int(input())\n a = list(map(int, input().split()))\n gcd = max(a[0], a[-1])\n \n print(gcd)\nexcept EOFError:pass", "t=int(input())\r\nfor i in range(t):\r\n n = int(input())\r\n a=[int(x) for x in...
{"inputs": [["1", "1", "2"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
7,214
3d1416bcb9f9c8f28b7fb3876afb5535
UNKNOWN
Blob is a computer science student. He recently got an internship from Chef's enterprise. Along with the programming he has various other skills too like graphic designing, digital marketing and social media management. Looking at his skills Chef has provided him different tasks A[1…N] which have their own scores. Blog...
["def maxval(arr):\n fn = [float('-inf')]*(len(arr)+1)\n sn = [float('-inf')]*len(arr)\n tn = [float('-inf')]*(len(arr)-1)\n fon = [float('-inf')]*(len(arr)-2)\n for i in reversed(list(range(len(arr)))):\n fn[i] = max(fn[i + 1], arr[i])\n for i in reversed(list(range(len(arr) - 1))):\n s...
{"inputs": [["6", "3 9 10 1 30 40"]], "outputs": [["46"]]}
INTERVIEW
PYTHON3
CODECHEF
678
493c8097b5a38754958820dd8b240d54
UNKNOWN
The notorious hacker group "Sed" managed to obtain a string $S$ from their secret sources. The string contains only lowercase English letters along with the character '?'. A substring of $S$ is a contiguous subsequence of that string. For example, the string "chef" is a substring of the string "codechef", but the strin...
["def convertToParitys(s):\r\n \"\"\"\r\n This converts the string s to an int, which is a bitMap of the parity of each letter\r\n odd ? = first bit set\r\n odd a = second bit set\r\n odd b = third bit set \r\n etc\r\n \"\"\"\r\n keys = '?abcdefghijklmnopqrstuvwxyz'\r\n paritys = {c:0 for c i...
{"inputs": [["5", "aa?", "a???", "????", "asfhaslskfak", "af??avvnfed?fav?faf????", ""]], "outputs": [["2", "6", "4", "2", "27"]]}
INTERVIEW
PYTHON3
CODECHEF
14,251
13a21d4c62a490e9135495084cab7d84
UNKNOWN
Chef got into a fight with the evil Dr Doof. Dr Doof has decided to destroy all even numbers from the universe using his Evil-Destroy-inator. Chef has $N$ integers with him. To stop Doof, Chef has to find an odd number which is an integer multiple of all $N$ numbers that he has with him. Find if it is possible for Chef...
["def gcd(a,b):\n if b==0: return a\n return gcd(b,a%b)\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int,input().split()))\n value = arr[0]\n if n!=1:\n for i in arr[1:]:\n value = value*i//gcd(value, i)\n if value%2==0:\n print(\"NO\")\n else:\n print(\"YES\")", "# cook your dish here\nt=i...
{"inputs": [["2", "5", "1 2 5 4 3", "1", "7"]], "outputs": [["NO", "YES"]]}
INTERVIEW
PYTHON3
CODECHEF
5,416
94aa019f27a67e91aaf9d2bb8fc00332
UNKNOWN
Chef has a sequence of $N$ integers, $A_1, A_2, ... , A_N$. He likes this sequence if it contains a subsequence of $M$ integers, $B_1, B_2, ... , B_M$ within it. A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements. Y...
["t=int(input())\ni=0\nwhile i<t:\n n=int(input())\n A=[]\n A=input().split()\n m=int(input())\n B=[]\n B=input().split()\n j=0\n a=-1\n while j<m:\n c=1\n if B[j] in A:\n b=A.index(B[j])\n A.remove(B[j])\n if b>=a:\n a=b\n c=1\n else:\n c=0\n break\n else:\n c=0\n break\n j+=1\n if c==1:\n ...
{"inputs": [["3", "6", "1 2 3 4 5 6", "3", "2 3 4", "6", "22 5 6 33 1 4", "2", "4 15", "4", "1 3 4 2", "2", "1 2"]], "outputs": [["Yes", "No", "Yes"]]}
INTERVIEW
PYTHON3
CODECHEF
7,776
875faa381b4df1742be9664a786f0273
UNKNOWN
It's John's birthday; he has brought some candies in distribute among N of his friends. Being a good friend, he decided to distribute all of his candies equally among his friend and he don't want to keep any for himself. He left the task of distributing candies up to his friends, but his friends haven't done a great jo...
["# cook your dish here\nimport math\nfor t in range(int(input())):\n n=int(input())\n a=[int(i) for i in input().split()]\n div=sum(a)/n\n div=math.ceil(div)\n count=div*n-sum(a)\n for i in a:\n if i>div:\n count+=i-div\n print(count)", "# cook your dish here\nimport math\nt =i...
{"inputs": [["3", "4", "7 8 6 4", "6", "7 3 10 2 3 8", "1", "10"]], "outputs": [["4", "10", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
7,932
6ed0978e06515586f9ec17424f886f27
UNKNOWN
Recently Rocky had participated in coding competition and he is sharing one of the problem with you which he was unable to solve. Help Rocky in solving the problem. Suppose the alphabets are arranged in a row starting with index 0$0$ from AtoZ$A to Z$. If in a coded language A=27$A=27$ and AND=65$AND=65$. Help Rocky t...
["# cook your dish here\ns = input().strip()\nstart_w = 27\nw_dict = {}\nwords = [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\"]\nfor word in words:\n w_dict[word] = start_w\n sta...
{"inputs": [["A", "AND"]], "outputs": [["27", "65"]]}
INTERVIEW
PYTHON3
CODECHEF
5,288