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
8e64cd52cacb00d45a47c25883ba88c6
UNKNOWN
Amit is going on a date and he wants to gift his date an array of positive numbers. But he is running short on money. He already has an array of numbers in design. Cost of an array of numbers is the sum of elements in it. But he wants to minimize the cost of making it. So he does the following number of operations one...
["for _ in range(int(input())):\r\n n=int(input())\r\n l=list(map(int,input().split()))\r\n su=l[0]\r\n for i in range(1,n):\r\n su^=l[i]\r\n print(su)", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n n = int(input())\n a = list(map(int,input().split()))\n x = 0\n for i...
{"inputs": [["3", "5", "8 4 1 5 0", "5", "1 2 4 0 8", "2", "10 10"]], "outputs": [["8", "15", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
7,462
41f517608c8e1154daa3de678a12b50b
UNKNOWN
We all know Gru loves Agnes very much. One day Agnes asked Gru to answer some of her queries. She lined up $N$ minions in a straight line from $1$ to $N$. You are given an array $A$ which contains the height of minions. Agnes will ask him several queries. In each query, Gru has to tell whether the bitwise AND of $A[L...
["# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=[int(x) for x in input().split()]\n sum=0\n for i in range(n):\n if a[i]%2==0:\n sum+=1\n a[i]=sum \n q=int(input())\n while q:\n l,r=map(int,input().split())\n if l!=1:\n c=a[r-1]-a[l-2]\n else:\n c=a[r-1] \n if c==0:\n print(\"O...
{"inputs": [["1", "5", "1 3 2 4 5", "3", "1 2", "1 5", "3 4"]], "outputs": [["ODD", "EVEN", "EVEN"]]}
INTERVIEW
PYTHON3
CODECHEF
10,204
dad96ca38a493b4eae76182861093577
UNKNOWN
Motu wants to learn Cricket from a coach, but firstly coach wants to test his IQ level, so he gave Motu $1$ $Red$ $ball$ and $1$ $Black$ $ball$ , and asked him to buy other $x – 1$ red balls and other $y – 1$ black balls from the market. But he put some conditions on buying balls, that if he has $R$ red and $B$ black b...
["T=int(input())\nwhile T:\n x,y=map(int,input().split())\n while(y): \n x, y = y, x % y\n if x==1:\n print(\"YES\")\n else:\n print(\"NO\")\n T-=1", "import math\nT=int(input())\nwhile T:\n\ta,b=map(int,input().split())\n\tif math.gcd(a,b)==1:\n\t\tprint(\"YES\")\n\telse:\n\t\tprint...
{"inputs": [["2", "1 2", "2 3"]], "outputs": [["YES", "YES"]]}
INTERVIEW
PYTHON3
CODECHEF
7,747
d008aedc507844a61970c098b47c4ed7
UNKNOWN
The Little Elephant from the Zoo of Lviv is going to the Birthday Party of the Big Hippo tomorrow. Now he wants to prepare a gift for the Big Hippo. He has N balloons, numbered from 1 to N. The i-th balloon has the color Ci and it costs Pi dollars. The gift for the Big Hippo will be any subset (chosen randomly, possi...
["# cook your dish here\nfor _ in range(int(input())):\n n,m = list(map(int,input().split()))\n colors = [0]*41; cost = [0]*41\n color = 0\n for i in range(n):\n cc,pp = list(map(int,input().split()))\n colors[cc] += 1\n cost[cc] += pp\n for i in colors:\n if i>0: color += 1\n...
{"inputs": [["2", "2 2", "1 4", "2 7", "2 1", "1 4", "2 7"]], "outputs": [["11.000000000", "7.333333333"]]}
INTERVIEW
PYTHON3
CODECHEF
853
b9b5403c33798d5cad118b05567df28b
UNKNOWN
You are given $n$ intervals on the $X$ axis. Each interval $i$ is specified by its ends $[L_i, R_i]$. You want to color each interval either blue or yellow. After coloring all the intervals, the $X$ axis will will have $4$ colors: - White, the part of $X$ axis contained in no interval - Blue, the part of $X$ axis conta...
["for _ in range(int(input())):\n n = int(input())\n ls = []\n rs = []\n lrs = []\n\n for i in range(n):\n l, r = map(int, input().split())\n ls.append(l)\n rs.append(r)\n lrs.append((l, r, i))\n\n lrs.sort()\n\n c = 0\n maxi = -1\n\n res = [-1] * n\n for l, r, i in lrs:\n if ls[i] > maxi:\n maxi = rs[i]\n res...
{"inputs": [["1", "3", "3 7", "2 5", "6 9"]], "outputs": [["100"]]}
INTERVIEW
PYTHON3
CODECHEF
2,102
655d103d4efc50a04abe4f07e6270592
UNKNOWN
Doubleville, a small town in Texas, was attacked by the aliens. They have abducted some of the residents and taken them to the a spaceship orbiting around earth. After some (quite unpleasant) human experiments, the aliens cloned the victims, and released multiple copies of them back in Doubleville. So now it might happ...
["def main():\n while True:\n [n, m] = [int(i) for i in input().split()]\n if n == m and n == 0:\n break\n cache = {}\n for i in range(n):\n dna = input().rstrip('\\n')\n if dna in cac...
{"inputs": [["9 6", "AAAAAA", "ACACAC", "GTTTTG", "ACACAC", "GTTTTG", "ACACAC", "ACACAC", "TCCCCC", "TCCCCC", "0 0", "", ""]], "outputs": [["1", "2", "0", "1", "0", "0", "0", "0", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
750
58c2132a315889e6fc4cd9d3d80a87b3
UNKNOWN
Chef likes problems which using some math. Now he asks you to solve next one. You have 4 integers, Chef wondering is there non-empty subset which has sum equals 0. -----Input----- The first line of input contains T - number of test cases. Each of the next T lines containing four pairwise distinct integer numbers - a,...
["# cook your dish here\n\n# cook your dish here\n\n \n\nt = int(input())\nwhile t:\n t-=1\n c=0\n ar=[int(i) for i in input().strip().split()]\n for i in range(1,16):\n b=bin(i)[2:].zfill(4)\n s=0\n for i in range(4):\n if b[i]=='1':\n s+=ar[i]\n \n if(s==0):\n c=1\n break\n \n print(\"Yes\" if c==1 else...
{"inputs": [["3", "1 2 0 3", "1 2 4 -1", "1 2 3 4"]], "outputs": [["Yes", "Yes", "No"]]}
INTERVIEW
PYTHON3
CODECHEF
7,591
62a202535ca0711210c52558f8dd2879
UNKNOWN
Corruption is on the rise in the country of Freedonia, Gru's home. Gru wants to end this for good and for that he needs the help of his beloved minions. This corruption network can be represented in the form of a tree having N$N$ nodes and N−1$N-1$ edges. The nodes are numbered from 1$1$ to N$N$, and the tree is rooted...
["from sys import stdin,stdout\r\ninput=stdin.readline\r\nn=int(input())\r\na=[[] for i in range(n)]\r\nfor i in range(n-1):\r\n u,v=map(int,input().split())\r\n a[u-1].append(v-1)\r\n a[v-1].append(u-1)\r\nb=[0]*n\r\nvis=[0]*n\r\nst=[(0,0)]\r\nvis[0]=1\r\npa=[0]*n\r\nwhile st:\r\n x,y=st.pop()\r\n b[x]=...
{"inputs": [["7", "1 2", "1 3", "2 4", "2 5", "3 6", "3 7"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
7,785
805c01765752cf8cc16807417a0bb5ed
UNKNOWN
Our Chef is doing what he is best at, COOKING A BARBECUE for his guests. He has invited all of us, and taking the help of his apprentice to smoke the barbecues. The chef has got BBQ sticks, each can take N fillings, and he presents N distinctly filled sticks in front his guests forming a N*N matrix But here is the pr...
["testcase = int(input())\nfor case in range(testcase):\n n = int(input())\n print(2**(n-2)+1)\n print('\\n') ", "# Author: Karlheinz Jung\n# Compiler: Python @ ideone.com\n# Computer: Rabbit 286\n# Contest: ALGOTHIKA 2012\n# Problem: Barbeque sticks (ALGBBQ)\n\nN=eval(input())\nfor t in range(N):\n print(2**(eval(inpu...
{"inputs": [["1", "4"]], "outputs": [["5"]]}
INTERVIEW
PYTHON3
CODECHEF
2,065
8418b298f31cca3cd2e77f1fd75bdf63
UNKNOWN
Let's consider a rectangular table R consisting of N rows and M columns. Rows are enumerated from 1 to N from top to bottom. Columns are enumerated from 1 to M from left to right. Each element of R is a non-negative integer. R is called steady if the sum of elements in the ith row is not less then the sum of elements ...
["# This is not my code, it's Snehasish Karmakar's. Refer to http://www.codechef\u00a0\u00a0\u00a0\u00a0.com/viewsolution/7153774\n# for original version.\n# Submitting it to try and work out if it can be sped up.\n\ndef compute_nCr(n,r) :\n C[0][0]=1\n for i in range(1,n+1) :\n# print \"i\",i\n C[i][0]=1\n fo...
{"inputs": [["3", "1 1", "2 2", "2 3"]], "outputs": [["2", "25", "273"]]}
INTERVIEW
PYTHON3
CODECHEF
2,449
b7cd22b3e4e187954b4d2f51abd89316
UNKNOWN
Limak has a string S, that consists of N lowercase English letters. Limak then created a new string by repeating S exactly K times. For example, for S = "abcb" and K = 2, he would get "abcbabcb". Your task is to count the number of subsequences "ab" (not necessarily consecutive) in the new string. In other words, find ...
["try:\r\n t=int(input())\r\n for i in range(t):\r\n n,k=map(int,input().split())\r\n s=input()\r\n l=[-1]*len(s)\r\n numb=s.count('b')\r\n x=numb\r\n for j in range(len(s)):\r\n if(s[j]=='a'):\r\n l[j]=numb\r\n if(s[j]=='b'):\r\n ...
{"inputs": [["3", "4 2", "abcb", "7 1", "aayzbaa", "12 80123123", "abzbabzbazab", "", ""]], "outputs": [["6", "2", "64197148392731290"]]}
INTERVIEW
PYTHON3
CODECHEF
10,353
67a0f194555547d081b16b5ac2868fe4
UNKNOWN
Chef lives in a big apartment in Chefland. The apartment charges maintenance fees that he is supposed to pay monthly on time. But Chef is a lazy person and sometimes misses the deadlines. The apartment charges 1000 Rs per month as maintenance fees. Also, they also charge a one-time fine of 100 Rs for each of the late p...
["for i in range(int(input())):\n a=int(input())\n b=input().split()\n if '0' in b:\n print(100*(a-b.index('0'))+b.count('0')*1000)\n else:\n print(0)\n", "for i in range(int(input())):\r\n x=int(input())\r\n y=input().split()\r\n if '0' in y:\r\n print(100*(x-y.index('0'))+y.count('0')*...
{"inputs": [["4", "2", "1 1", "2", "0 0", "3", "0 1 0", "2", "0 1", "", ""]], "outputs": [["0", "2200", "2300", "1200"]]}
INTERVIEW
PYTHON3
CODECHEF
6,080
9ad89a9e9cd58c7878d1838585c8ff3b
UNKNOWN
Zonal Computing Olympiad 2013, 10 Nov 2012 N teams participate in a league cricket tournament on Mars, where each pair of distinct teams plays each other exactly once. Thus, there are a total of (N × (N-1))/2 matches. An expert has assigned a strength to each team, a positive integer. Strangely, the Martian crowds love...
["# cook your dish here\n# cook your dish here\nfrom itertools import combinations\nn = int(input())\nt = list(combinations(list(map(int, input().split())), 2))\nar = 0\nfor i in t:\n ar += abs(i[0] - i[1])\nprint(ar)", "# cook your dish here\nn=int(input())\nstrength=list(map(int,input().split()))\nrevenue=0\nfor i...
{"inputs": [["4", "3 10 3 5", "Sample output", "23", "Test data", "In all subtasks, the strength of each team is an integer between 1 and 1,000 inclusive.", "Subtask 1 (30 marks) : 2 \u2264 N \u2264 1,000.", "Subtask 2 (70 marks) : 2 \u2264 N \u2264 200,000.", "Live evaluation data", "Subtask 1 : Testcases 0,1,2....
INTERVIEW
PYTHON3
CODECHEF
6,355
06a0355ed33e37794a637cb06b9dd285
UNKNOWN
Vivek was quite bored with the lockdown, so he came up with an interesting task. He successfully completed this task and now, he would like you to solve it. You are given two strings $A$ and $B$, each with length $N$. Let's index the characters in each string from $0$ ― for each $i$ ($0 \le i < N$), the $i+1$-th charac...
["for _ in range(int(input())):\n n=int(input())\n a=input()\n b=input()\n l=[]\n flag=0\n for i in range(n):\n if b[i]!=a[i]:\n if b[i] in a and b[i]<a[i]:\n l.append(b[i])\n else:\n flag=1\n break\n if flag==1:\n print(-1)\n else:\n if l==[]:\n print(0)\n else:\n l = sorted(list(set(l)), reverse ...
{"inputs": [["3", "5", "abcab", "aabab", "3", "aaa", "aab", "2", "de", "cd"]], "outputs": [["2", "3 1 2 4", "3 0 1 3", "-1", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
19,482
8f3ad41a654dbaa132ea5c944e3ff513
UNKNOWN
Bear Limak has a sequence of N non-negative integers A1, A2, ..., AN. He defines the score of a segment (consecutive subsequence) as its sum of elements modulo P (not necessarily prime). Find the maximum score of a non-empty segment, and also find the number of segments with this maximum score. -----Input----- First l...
["for _ in range(int(input())):\n n,m=input().split()\n n,m=int(n),int(m)\n x=y=c=0\n l=list(map(int,input().split()))\n for i in range(n):\n for j in range(i,n):\n x=x+l[j]\n if (x%m)>y:\n y=x%m\n c=1\n elif y==(x%m):\n c+=1\n x = 0\n print(y,c)\n\n", "for _ in range(int(input())):\n n,p=map(int,input...
{"inputs": [["4", "2 3", "1 2", "3 5", "2 4 3", "3 100", "1 3 5", "4 3", "1 2 3 4"]], "outputs": [["2 1", "4 2", "9 1", "2 2"]]}
INTERVIEW
PYTHON3
CODECHEF
1,283
d9c7db8f9889e5a7a4bc0bf4e4578759
UNKNOWN
Chef has a sequence $A_1, A_2, \ldots, A_N$. This sequence has exactly $2^N$ subsequences. Chef considers a subsequence of $A$ interesting if its size is exactly $K$ and the sum of all its elements is minimum possible, i.e. there is no subsequence with size $K$ which has a smaller sum. Help Chef find the number of inte...
["def fact(n):\n if n<2:\n return 1\n return n * fact(n-1)\n \ndef ncr(n, r):\n return fact(n)// (fact(r)*fact(n-r))\n \nt=int(input())\n\nfor _ in range(t):\n n, k = list(map(int, input().split()))\n a = list(map(int, input().split()))\n a.sort()\n count_z = a.count(a[k-1])\n count_z_seq = a[:k].count(a[k-1])\n \n pr...
{"inputs": [["1", "4 2", "1 2 3 4"]], "outputs": [["1"]]}
INTERVIEW
PYTHON3
CODECHEF
8,270
da8ab24da2a99f4a32d97936ec890069
UNKNOWN
Galileo's latest project involves determining the density of stars in certain regions of the sky. For this purpose he started looking for datasets online, and discovered a dataset on Newton's blog. Newton had decomposed the night sky into a Voronoi tessellation with the generators arranged in a grid. He has stored the ...
["import sys\n\ndef main():\n s=sys.stdin.readline\n n, m = list(map(int, s().split()))\n nums={}\n for i in range(1, n+1):\n nums[i]=list(map(int, s().split()))\n cases=int(s())\n for case in range(cases):\n px, py, qx, qy = list(map(int, s().split()))\n ans=[]\n for i in range(px, qx+1):\n for j in range(py-1, ...
{"inputs": [["3 3", "10 10 10", "10 10 10", "10 10 10", "4", "1 1 1 1", "1 1 3 3", "2 1 3 3", "3 1 3 3"]], "outputs": [["10", "90", "60", "30"]]}
INTERVIEW
PYTHON3
CODECHEF
1,633
def5e134aff7a921cc1728fab8fa6eaf
UNKNOWN
Striver$Striver$ wants to strive hard in order to reach his goals, hence asks his mentor to give him a question for which he has to strive hard. The mentor gives Striver$Striver$ a N$N$ X N$N$ matrix consisting of lowercase characters (′a′$'a'$ to ′z′$'z'$) and Q$Q$ queries. Every query consists of X$X$ and Y$Y$. From...
["a=int(input())\r\nfor _ in range(a):\r\n c,d=list(map(int,input().split()))\r\n crr=[[[0,0] for i in range(c+1)] for j in range(c+1)]\r\n trr=[]\r\n for i in range(c):\r\n kk=list(input().split())\r\n trr.append(kk)\r\n for i in range(1,c+1):\r\n for j in range(1,c+1):\r\n ...
{"inputs": [["1", "3 2", "a b a", "a c d", "b a b", "1 3", "3 3"]], "outputs": [["1", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
3,442
c2fbb34ee1d420f86627704e1d3cfff8
UNKNOWN
Chef is stuck in a two dimensional maze having N rows and M columns. He needs to get out of the maze as soon as possible and arrive at the kitchen in order to serve his hungry customers. But, he can get out of the maze only if he is able to successfully find any magical path in the given maze. A path is defined as mag...
["t = eval(input())\nfor _ in range(t):\n n, m = list(map(int, input().split()))\n if n*m == 2:\n print('Yes')\n elif (n*m)%2 == 0 and m != 1 and n != 1:\n print('Yes')\n else:\n print('No')", "t=int(input())\nfor _ in range(t):\n n,m=input().strip().split()\n if (n=='1' and m=='2') or (n=='2' and m=='1'):\n print(...
{"inputs": [["1", "2 2"]], "outputs": [["Yes"]]}
INTERVIEW
PYTHON3
CODECHEF
6,310
830114ee9c4884240160ac61463302ed
UNKNOWN
Little Egor is a huge movie fan. He likes watching different kinds of movies: from drama movies to comedy movies, from teen movies to horror movies. He is planning to visit cinema this weekend, but he's not sure which movie he should watch. There are n movies to watch during this weekend. Each movie can be characterize...
["def bestMovie():\n tests=int(input())\n for t in range(tests):\n n = int(input())\n L = list(map(int, input().split()))\n R = list(map(int, input().split()))\n maxIndex = -1\n maxValue = 0\n for i in range(n):\n prod = L[i]*R[i]\n if maxValue < prod:\n maxValue = prod\n maxIndex = i\n elif maxValue ...
{"inputs": [["2", "2", "1 2", "2 1", "4", "2 1 4 1", "2 4 1 4"]], "outputs": [["1", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
8,162
77a95c5a2505b9267d028a33d5d5fbc3
UNKNOWN
Find sum of all the numbers that are multiples of 10 and are less than or equal to a given number "N". (quotes for clarity and be careful of integer overflow) -----Input----- Input will start with an integer T the count of test cases, each case will have an integer N. -----Output----- Output each values, on a newline...
["for t in range(eval(input())):\n n=eval(input())\n n-=n%10\n n/=10\n print(n*(n+1)/2*10)", "def tenn():\n t=eval(input())\n for i in range(t):\n a=eval(input())\n r=a/10\n t=(r*(r+1))/2\n print(t*10)\ntenn()\n", "t = int(input())\nl = list()\n\nfor i in range(t):\n n = int(input()) / 10\n l.append(n)\n \nfor n in...
{"inputs": [["1", "10"]], "outputs": [["10"]]}
INTERVIEW
PYTHON3
CODECHEF
589
485168bede73448727f9fc9db39205bb
UNKNOWN
Chef and his girlfriend are going to have a promenade. They are walking along the straight road which consists of segments placed one by one. Before walking Chef and his girlfriend stay at the beginning of the first segment, they want to achieve the end of the last segment. There are few problems: - At the beginnin...
["T = int(input())\nfor i in range(T):\n x = int(input())\n l= [int(x) for x in input().split()]\n t=[]\n for i in range(len(l)):\n t.append(l[i]+i) \n print(max(t))", "# cook your dish here\nt=int(input())\nwhile t:\n t=t-1\n n = int(input())\n l = list(map(int,input().split()))\n l.reverse()\n c = 0\n for i in range...
{"inputs": [["2", "5", "6 5 4 3 2", "5", "3 4 3 1 1"]], "outputs": [["6", "5"]]}
INTERVIEW
PYTHON3
CODECHEF
5,129
cbb23b951d0873f927cbfde03854127e
UNKNOWN
Dhiraj loves Chocolates.He loves chocolates so much that he can eat up to $1000$ chocolates a day. But his mom is fed up by this habit of him and decides to take things in her hand. Its diwali Season and Dhiraj has got a lot of boxes of chocolates and Dhiraj's mom is afraid that dhiraj might eat all boxes of chocolates...
["def isSubsetSum(arr, n, sum): \n subset = [ [False for j in range(sum + 1)] for i in range(3) ] \n for i in range(n + 1): \n for j in range(sum + 1): \n if (j == 0):subset[i % 2][j] = True\n elif (i == 0):subset[i % 2][j] = False\n elif (arr[i - 1] <= j):subset[i % 2][...
{"inputs": [["2", "20", "5", "8 7 2 10 5", "11", "4", "6 8 2 10"]], "outputs": [["1", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
3,321
787a0123d8b523fecfb9a36a7d22b9b7
UNKNOWN
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K(odd) to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single lin...
["def func(num):\r\n for i in range(num):\r\n if i < num//2 + 1:\r\n print(' '*i, end='')\r\n print('*')\r\n else:\r\n print(' '*(num-i-1), end='')\r\n print('*')\r\n\r\n\r\n\r\nfor _ in range(int(input())):\r\n num = int(input())\r\n func(num)\r\n", "#...
{"inputs": [["4", "1", "3", "5", "7"]], "outputs": [["*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*", "*"]]}
INTERVIEW
PYTHON3
CODECHEF
12,072
fbb5e7a2c7489af423034163d9f35578
UNKNOWN
The Petrozavodsk camp takes place in about one month. Jafar wants to participate in the camp, but guess what? His coach is Yalalovichik. Yalalovichik is a legendary coach, famous in the history of competitive programming. However, he is only willing to send to the camp students who solve really hard problems on Timus. ...
["M = 10 ** 9 + 7\nfor _ in range(int(input())):\n s,p,m,r = list(map(int, input())),0,1,0\n for d in reversed(s):\n p += d * m\n m = m * 10 % M\n for d in s:\n r = (r * m + p) % M\n p = (p * 10 - (m - 1) * d) % M\n print(r)", "M = 10 ** 9 + 7\n\nt = int(input())\nfor _ in range(...
{"inputs": [["1", "123", ""]], "outputs": [["123231312"]]}
INTERVIEW
PYTHON3
CODECHEF
10,181
d540cd2e0574fd840b4e10dc80afe98c
UNKNOWN
The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of ...
["t=int(input())\r\nfor _ in range(t):\r\n n=int(input())\r\n b=1\r\n if n%2:\r\n c=n-2\r\n for j in range(n//2):\r\n print(\" \"*j+str(b) +\" \"*c+ str(b))\r\n b+=1\r\n c-=2\r\n print(\" \"*(n//2)+str(b)+\" \"*(n//2))\r\n b+=1\r\n c=1\r\n ...
{"inputs": [["3", "5", "3", "4"]], "outputs": [["1 1", "2 2", "3", "4 4", "5 5", "1 1", "2", "3 3", "1 1", "22", "33", "4 4"]]}
INTERVIEW
PYTHON3
CODECHEF
3,183
70efd00c04dd28ac3bdbcc379724c170
UNKNOWN
You are given N integer sequences A1, A2, ..., AN. Each of these sequences contains N elements. You should pick N elements, one from each sequence; let's denote the element picked from sequence Ai by Ei. For each i (2 ≤ i ≤ N), Ei should be strictly greater than Ei-1. Compute the maximum possible value of E1 + E2 + ......
["t=int(input())\nfor _ in range(t):\n n=int(input())\n \n grid=[]\n for _ in range(n):\n temp=[]\n temp=list(map(int,input().strip().split()))\n temp.sort()\n grid.append(temp)\n \n \n curr=max(grid[n-1])\n total=curr\n for i in range(n-2,0-1,-1):\n flag=0\n for j in range(n-1,0-1,-1):\n if grid[i][j]<curr:\n...
{"inputs": [["1", "3", "1 2 3", "4 5 6", "7 8 9"]], "outputs": [["18"]]}
INTERVIEW
PYTHON3
CODECHEF
10,927
3761f15f8b3bbedcfa20b75b64373d6b
UNKNOWN
Little kids, Jack and Evan like playing their favorite game Glass-and-Stone. Today they want to play something new and came across Twitter on their father's laptop. They saw it for the first time but were already getting bored to see a bunch of sentences having at most 140 characters each. The only thing they liked to...
["def getInput():\n N_k = input().split()\n N =int(N_k[0])\n k =int(N_k[1])\n list = []\n output = []\n count = 0\n for i in range(0,k):\n val = input()\n if(val!=\"CLOSEALL\"):\n val=val.split()\n val = int (val[1])\n if val not in list:\n count= count +1\n list.append(val)\n else:\n list.remove(val...
{"inputs": [["3 6", "CLICK 1", "CLICK 2", "CLICK 3", "CLICK 2", "CLOSEALL", "CLICK 1"]], "outputs": [["1", "2", "3", "2", "0", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
5,258
e7963f87973a48667a35e37a39993b8a
UNKNOWN
Give me Biscuit Sunny wants to make slices of biscuit of size c * d into identical pieces. but each piece is a square having maximum possible side length with no left over piece of biscuit. Input Format The first line contains an integer N. N lines follow. Each line contains two space separated integers c and d. ...
["def __gcd(a, b): \n \n # Everything divides 0 \n if (a == 0 or b == 0): \n return 0; \n \n # base case \n if (a == b): \n return a; \n \n # a is greater \n if (a > b): \n return __gcd(a - b, b); \n return __gcd(a, b - a); \n \n# Function to find \n# number of squares \ndef NumberOfSquares(x, y): \n \n # Here i...
{"inputs": [["2", "2 2", "6 9"]], "outputs": [["1", "6"]]}
INTERVIEW
PYTHON3
CODECHEF
2,908
ac0642309b5d7cee1c7409fa67384ec6
UNKNOWN
-----Problem Statement----- Harry Potter has one biscuit and zero rupee in his pocket. He will perform the following operations exactly $K$ times in total, in the order he likes: - Hit his pocket, which magically increases the number of biscuits by one. - Exchange $A$ biscuits to $1$ rupee. - Exchange $1$ rupee to $B$ ...
["K,A,B = map(int,input().split())\r\n \r\nif A + 2 > B:\r\n print(K + 1)\r\n return\r\n \r\nstart = A - 1\r\nK -= start\r\nans = K//2 * (B-A) + K%2 + start + 1\r\nprint(ans)", "import sys\r\n# sys.stdin = open('input.txt', 'r') \r\n# sys.stdout = open('output.txt', 'w')\r\n \r\nimport math\r\nimport collections\...
{"inputs": [["4 2 6"]], "outputs": [["7"]]}
INTERVIEW
PYTHON3
CODECHEF
3,530
942afeabd5cc6895883b23fa4c6cbc27
UNKNOWN
Did you know that the people of America eat around 100 acres of pizza per day ? Having read this fact on internet, two chefs from the Elephant city, Arjuna and Bhima are set to make pizza popular in India. They organized a social awareness camp, where N people ( other than these two ) sit around a large pizza. To make ...
["a= [0, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 0, 5, 2, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 2, 7, 4, 0, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 2, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1, 1, 2, 0, 3, 1, 1, 0, 3, 3, 2, 2, 4, 4, 5, 5, 9, 3, 3, 0, 1, 1, 3, 0, 2, 1, 1, 0, 4, 5, 3, 7, 4, 8, 1,...
{"inputs": [["4", "2", "4", "5", "6"]], "outputs": [["Arjuna", "Arjuna", "Bhima", "Arjuna"]]}
INTERVIEW
PYTHON3
CODECHEF
60,263
ef4437abaac45933c57aa080079e5cfe
UNKNOWN
Coach Moony wants the best team to represent their college in ICPC. He has $N$ students standing in a circle with certain rating $X_i$ on a competitive coding platform. It is an established fact that any coder with more rating on the platform is a better coder. Moony wants to send his best $3$ coders based upon ...
["# cook your dish here\r\n#Moony and ICPC team\r\nT = int(input())\r\n\r\nfor i in range(T):\r\n N,data = int(input()),list(map(int,input().split()))\r\n if(N==3):\r\n print(sum(data))\r\n else:\r\n best = data[0]+data[1]+data[2]\r\n overall = best\r\n k=len(data)\r\n for i ...
{"inputs": [["1", "7", "10 40 30 30 20 0 0"]], "outputs": [["100"]]}
INTERVIEW
PYTHON3
CODECHEF
11,320
7e86e5ab4764b6bfffba41cd95c22c7a
UNKNOWN
We all know how great ABD aka AB-DE-VILLIERS is. However his team mates were jealous of him and posed a problem for him to solve.The problem description is as follows : Given an array of integers,find the length of the largest subarray(contiguous) of the given array with the maximum possible GCD (Greatest Common Divis...
["n=eval(input())\na=list(map(int,input().split()))\nc=m=0\nmaxi=max(a)\nfor i in range(n):\n if a[i]==maxi:\n c+=1\n m=max(c,m)\n else:\n c=0\nprint(m) ", "from fractions import gcd as G\nn=eval(input())\nflag=1\narr=list(map(int,input().split()))\na=max(arr)\nbest = 0\nI_I = 0\nwhile I_I<n:\n if arr[I_I]==a:\n k=...
{"inputs": [["4", "2 4 8 3"]], "outputs": [["1"]]}
INTERVIEW
PYTHON3
CODECHEF
662
d2eb45ecb073cd7819dfd49aa68052f8
UNKNOWN
Chef has a sequence of positive integers $A_1, A_2, \ldots, A_N$. He wants to split this sequence into two non-empty (not necessarily contiguous) subsequences $B$ and $C$ such that $\mathrm{GCD}\,(B) + \mathrm{GCD}\,(C)$ is maximum possible. Help him find this maximum value. Note: The greatest common divisor (GCD) of a...
["from math import gcd\r\n\r\n__author__ = 'Prateek'\r\n\r\n\r\ndef test():\r\n n = int(input())\r\n a = list(map(int, input().split()))\r\n a = list(set(a))\r\n n = len(a)\r\n if len(a) == 1:\r\n print(2 * a[0])\r\n return\r\n g1 = [0 for i in range(n)]\r\n g2 = [0 for i in range(n)]...
{"inputs": [["1 ", "4 ", "4 4 7 6 ", ""]], "outputs": [["9"]]}
INTERVIEW
PYTHON3
CODECHEF
15,890
81685b240bcc8a42c8ee869a228d1a20
UNKNOWN
Mr. X has come up with a new string compression algorithm. Consider a string of length N which contains up to K distinct characters. The compression algorithm works as follows: Replace each maximal contiguous substring containing only one distinct character (repeated an arbitrary number of times) and replace it by 2 va...
["for _ in range(int(input())):\n\tn,k=map(int,input().split())\n\tprint(((2*n*(k-1))+2)/k)", "for _ in range(int(input())):\r\n\tn,k=map(int,input().split())\r\n\ta=((2*n*(k-1))+2)/k\r\n\tprint(a)", "# cook your dish here\nfor _ in range(int(input())):\n n,k=map(int,input().split())\n print(2+(n-1)*((2)-(2/k)))"...
{"inputs": [["2", "3 1", "3 2", ""]], "outputs": [["2.0", "4.0"]]}
INTERVIEW
PYTHON3
CODECHEF
3,052
0b2164057f21667cb7c6264222b1e497
UNKNOWN
The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case contains a single line of...
["t=int(input())\nfor t in range(t):\n n=int(input())\n for i in range(0,n):\n for j in range(0,n):\n if i%2==0:\n if j%2==0:\n print(0,end=\"\")\n else:\n print(1,end=\"\")\n else:\n if j%2==0:\n ...
{"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["0", "01", "10", "010", "101", "010", "0101", "1010", "0101", "1010"]]}
INTERVIEW
PYTHON3
CODECHEF
8,759
c94a2bc775c62c31f3551a40404ac058
UNKNOWN
The new Formula 1 season is about to begin and Chef has got the chance to work with the Formula 1 technical team. Recently, the pre-season testing ended and the technical team found out that their timing system for qualifying was a little bit buggy. So, they asked Chef to fix it before the season begins. His task i...
["# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n if n<101:\n l1=[]\n l2=[]\n d=dict()\n for i in range(1,2*n+1):\n if i%2==0:\n l1.append(int(input()))\n else:\n l2.append(str(input()))\n r1=[]\n for i in l1:\n r1.append(i)\n l1.sort()\n ind=[]\n for i in l1:\n a=r1....
{"inputs": [["2", "3", "Hamilton", "75000", "Vettel", "76000", "Bottas", "75500", "2", "Leclerc", "666666", "Verstappen", "666777"]], "outputs": [["Hamilton", "Bottas", "Vettel", "Leclerc", "Verstappen"]]}
INTERVIEW
PYTHON3
CODECHEF
8,328
d4c4dd76660e8737adc215bbe1c8f920
UNKNOWN
A beautiful sequence is defined as a sequence that do not have any repeating elements in it. You will be given any random sequence of integers, and you have to tell whether it is a beautiful sequence or not. -----Input:----- - The first line of the input contains a single integer $T$. $T$ denoting the number of test ...
["# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int,input().split()))\n l = []\n for i in range(0, len(arr)): \n for j in range(i+1, len(arr)): \n if(arr[i] == arr[j]): \n l.append(arr[j])\n if (len(l) ==0):\n print...
{"inputs": [["2", "4", "1 2 3 4", "6", "1 2 3 5 1 4"]], "outputs": [["prekrasnyy", "ne krasivo"]]}
INTERVIEW
PYTHON3
CODECHEF
7,279
727edbd932363b1971b48239441d9fd9
UNKNOWN
Accepts a string from the user and print the reverse string as the output without using any built-in function. -----Input:----- Each testcase contains of a single line of input, a string. -----Output:----- For each testcase, output in a single line answer, the reverse string. -----Sample Input:----- 1 Tracy -----Sa...
["oo = int(input())\r\nfor i in range(oo):\r\n\tval = input()\r\n\tprint(val[::-1])", "for _ in range(int(input())):\n s=input()\n print(s[::-1])", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n a=input()\n for i in range(len(a)-1,-1,-1):print(a[i],end=\"\")\n print()\n ", "t=int(input()...
{"inputs": [["1", "Tracy"]], "outputs": [["ycarT"]]}
INTERVIEW
PYTHON3
CODECHEF
3,035
3f774ffb7889a8ae54faef841302330f
UNKNOWN
You are given a dataset consisting of $N$ items. Each item is a pair of a word and a boolean denoting whether the given word is a spam word or not. We want to use this dataset for training our latest machine learning model. Thus we want to choose some subset of this dataset as training dataset. We want to make sure tha...
["t = int(input())\n\nfor _ in range(t):\n n = int(input())\n \n a = {}\n \n for i in range(n):\n l = input()\n \n if l not in a:\n a[l] = 1\n else:\n a[l] += 1\n \n done = []\n ans = 0\n \n for i in a:\n if a[i] != 0:\n t...
{"inputs": [["3", "3", "abc 0", "abc 1", "efg 1", "7", "fck 1", "fck 0", "fck 1", "body 0", "body 0", "body 0", "ram 0", "5", "vv 1", "vv 0", "vv 0", "vv 1", "vv 1", ""]], "outputs": [["2", "6", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
12,509
c8a9546abf82450031e1c5c4e4bc5629
UNKNOWN
Problem description. Dominic Toretto has taken his crew to compete in this years' Race Wars, a crew-on-crew tournament in which each member of one crew competes with a member of the other crew in a quarter mile drag race. Each win counts as one point for the winning crew. Draws and loses are awarded zero points. In the...
["testcases = int(input())\n\nfor i in range(testcases):\n n = int(input())\n my = list(map(int,input().split()))\n opp = list(map(int,input().split()))\n \n my.sort(reverse = True)\n opp.sort(reverse = True)\n \n j = 0\n k = 0\n while(k < n):\n if(my[j] > opp[k]):\n j += 1\n k += 1\n\n print(j)"]
{"inputs": [["1", "3", "5 4 1", "5 4 1"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
302
ba809166d7596ff13ae6fc6acd07618b
UNKNOWN
For Diwali, Chef arranges all $K$ laddus in a row in his sweet shop. Whenever a customer comes to buy laddus, chef follows a rule that each customer must buy all laddus on odd position. After the selection of the laddu, a new row is formed, and again out of these only laddus on odd position are selected. This continues...
["# cook your dish here\nt=int(input())\nwhile t>0:\n n=int(input())\n if n==1:\n print(1)\n else:\n c,num=1,2\n while num<n:\n num*=2\n if num==n:\n print(num)\n else:\n print(num//2)\n t-=1", "# cook your dish here\nfrom math import log\n...
{"inputs": [["3", "1", "5", "8"]], "outputs": [["1", "4", "8"]]}
INTERVIEW
PYTHON3
CODECHEF
835
86917a228f8206c9a464c2a65f7de0fa
UNKNOWN
Voritex a big data scientist collected huge amount of big data having structure of two rows and n columns. Voritex is storing all the valid data for manipulations and pressing invalid command when data not satisfying the constraints. Voritex likes brute force method and he calls it as BT, he decided to run newly create...
["import math\r\nimport os\r\nimport random\r\nimport re\r\nimport sys\r\n\r\n\r\nr = 100000\r\nprev = 1\r\ns = set()\r\nfor i in range(1, r+1):\r\n now = i ^ prev\r\n s.add(now)\r\n prev = now\r\ns = list(s)\r\nt = int(input())\r\nwhile t > 0:\r\n t -= 1\r\n n, k = list(map(int, input().split()))\r\n\r\...
{"inputs": [["2", "4 2", "5 5"]], "outputs": [["2", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
573
b6f78cc4f53bd528ad130c8198f0732a
UNKNOWN
Minion Chef likes to eat bananas a lot. There are N piles of bananas in front of Chef; for each i (1 ≤ i ≤ N), the i-th pile contains Ai bananas. Chef's mother wants her to eat the bananas and be healthy. She has gone to the office right now and will come back in H hours. Chef would like to make sure that she can finis...
["# cook your dish here\nimport math\nT = int(input())\nfor _ in range(T):\n N, H = map(int, input().split())\n A = list(map(int, input().split()))\n low, high = 1, max(A)\n while low != high:\n time = 0\n mid = (low + high) // 2\n for i in range(N):\n time += math.ceil(A[i] / mid)\n \n if time <= H :\n high =...
{"inputs": [["3", "3 3", "1 2 3", "3 4", "1 2 3", "4 5", "4 3 2 7"]], "outputs": [["3", "2", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
8,766
8b00724eea0797b38ee5d73fe3a1fdbd
UNKNOWN
Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := fn-1 + fn-2 (n>=3) Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a,b]. -----Input----- The input contains several test cases. Each test case consists of two non-negative integer numbers a and b. Input is te...
["#!/usr/bin/env python\n\nF = [1,1]\ndef fibo():\n for i in range(500):\n F.append(F[-2] + F[-1])\n\ndef main():\n fibo()\n #print len(str(F[-1]))\n #print len(str(10**100))\n while True:\n try:\n A, B = list(map(int, input().strip().split()[:2]))\n if A == 0 and B == 0: break\n print(len([x for x in F if x >=...
{"inputs": [["10 100", "1234567890 9876543210", "0 0"]], "outputs": [["5", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
373
a34494ef0f4cd78243fa4cdaf51a38dd
UNKNOWN
As we all know, Dhoni loves drinking milk. Once he and Sir Jadeja were invited in the inauguration of a Dairy company in Ranchi. The company had arranged n jars of milk from various breeds of cows , jar number i containing a[i] litres of milk. Since Dhoni loves driking milk more than Sir Jadeja, so Kohli sugges...
["cases = int(input())\n\nfor case in range(cases):\n N, M, K = [int(i) for i in input().split()]\n A = [int(i) for i in input().split()]\n jad = 0\n P = M*K\n\n for milk in A:\n if(milk>P):\n jad += milk-P\n else:\n jad += milk%K\n\n print(jad%1000000007)\n", "import sys\n\nMOD = 10**9+7\nfor __ in range(eval(in...
{"inputs": [["1", "3 3 3", "15 8 10"]], "outputs": [["9"]]}
INTERVIEW
PYTHON3
CODECHEF
586
75025e1525376500d97055836b8c29e6
UNKNOWN
The government has invited bids from contractors to run canteens at all railway stations. Contractors will be allowed to bid for the catering contract at more than one station. However, to avoid monopolistic price-fixing, the government has declared that no contractor may bid for a pair of neighbouring stations. The ra...
["n=int(input())\r\nl=[]\r\ndp=[]\r\nd={}\r\nfor i in range(n):\r\n\tl.append(int(input()))\r\n\td[i]=[]\r\n\tdp.append([0,0])\r\n\r\nfor i in range(n-1):\r\n\ta,b=list(map(int,input().split()))\r\n\td[a-1].append(b-1)\r\n\td[b-1].append(a-1)\r\n#print(l)\r\n#print(d)\r\n\r\ndef dfs(ch,pa,visited):\r\n\tdp[ch][1]=l[ch]...
{"inputs": [["6", "10", "20", "25", "40", "30", "30", "4 5", "1 3", "3 4", "2 3", "6 4"]], "outputs": [["90"]]}
INTERVIEW
PYTHON3
CODECHEF
713
a3bd98dbd875c2cfe626567a8b0e8769
UNKNOWN
These days, chef is very much interested in Mathematics. He has started attending Recitations too! His hunger for problems is increasing day by day! Today, chef was a given a crumpled maths problem, which he is stuck with . He needs your help to do it Here's what his teacher said: "Find sum of all numbers till N, do no...
["testCases = int(input())\nfor c in range(testCases):\n n, k = list(map(int, input().split()))\n sum = 0\n i = 0\n power = 1\n while i <= n:\n if k**power == i:\n power += 1\n else:\n sum += i\n i +=1 \n answer = \"Case #\" + str(c + 1) + \": \" + str(sum)\n print(answer)", "for j in range(int(input())):\n n,k ...
{"inputs": [["2", "10 3", "20 2"]], "outputs": [["Case #1: 43", "Case #2: 180"]]}
INTERVIEW
PYTHON3
CODECHEF
452
d42a67b7565a11209b4b2cf505478c5c
UNKNOWN
Given N, count how many permutations of [1, 2, 3, ..., N] satisfy the following property. Let P1, P2, ..., PN denote the permutation. The property we want to satisfy is that there exists an i between 2 and n-1 (inclusive) such that - Pj > Pj + 1 ∀ i ≤ j ≤ N - 1. - Pj > Pj - 1 ∀ 2 ≤ j ≤ i. -----Input----- Fir...
["try:\n \n for _ in range(int(input())):\n n = int(input())\n print(0) if(n==1) else print(pow(2,n-1,10**9+7)-2) \nexcept EOFError:\n pass\n\n ", "for _ in range(int(input())):\n n = int(input())\n print(0) if(n==1) else print(pow(2,n-1,10**9+7)-2) ", "for _ in range(int(input())):\n n = int(input())\n if(n==1):\n ...
{"inputs": [["2", "2", "3"]], "outputs": [["0", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
634
0f0a087f30bfdcdbeea58cd49e2abe91
UNKNOWN
There are n chef's in Chefland. There is a festival in Chefland in which each chef is asked to vote a person as his best friend. Obviously, a person can't vote himself as his best friend. Note that the best friend relationship is not necessarily bi-directional, i.e. it might be possible that x is best friend of y, but...
["t=int(input())\nfor _ in range(t):\n n=int(input())\n l=list(map(int,input().split()))\n if sum(l)!=n or max(l)==n:\n print('-1')\n else:\n d=dict()\n ans=[-1]*n\n for i in range(0,n):\n d[i]=1\n for i in range(n):\n if l[i]!=0:\n count=l[i]\n for k,v in list(d.items()):\n if count>0 and v==1 and i...
{"inputs": [["3", "3", "1 1 1", "3", "3 0 0", "3", "2 2 0"]], "outputs": [["2 3 1", "-1", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
2,148
5b8a8ce17b6613ef30639ffe6f0aa0f0
UNKNOWN
For her next karate demonstration, Ada will break some bricks. Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are W1,W2,W3. Ada's strength is S. Whenever she hits a stack of bricks, consider the largest k≥0 such that the sum of widths of the topmost k bricks does not exceed ...
["T = int(input())\nfor _ in range(T):\n W = list(map(int, input().strip().split()))\n S = W[0]\n W = W[1:]\n W = W[::-1]\n i = 0\n c = 0\n flag = 0\n while (len(W) != 0 or flag != 1) and i<len(W):\n k = i\n su = 0\n while su <= S and k<len(W)-1:\n su += W[k]\n k += 1\n if su-W[k-1]<=S:\n c += 1\n else:\n ...
{"inputs": [["3", "3 1 2 2", "2 1 1 1", "3 2 2 1"]], "outputs": [["2", "2", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
8,652
7102782a6af5f65c54487d5cca054bf3
UNKNOWN
"It does not matter how slowly you go as long as you do not stop." - Confucius You are given an array $A_1, A_2, \ldots, A_N$ and an integer $K$. For each subarray $S = [A_l, A_{l+1}, \ldots, A_r]$ ($1 \le l \le r \le N$): - Let's define an array $B$ as $S$ concatenated with itself $m$ times, where $m$ is the smallest ...
["from bisect import insort\nfrom math import ceil\nfor _ in range(int(input())):\n n,k=list(map(int,input().split( )))\n array=list(map(int,input().split( )))\n ans=0\n index=[]\n for i in range(1,n+1):\n index.append(ceil(k/(ceil(k/i))))\n for i in range(n):\n count=[0]*(2001)\n temp=[]\n for j in range(i,n):\n ...
{"inputs": [["1", "3 3", "1 2 3"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
12,300
86a22eb1170e2eca30e1ff956b348959
UNKNOWN
The entire network is under the inspection and direct control of the Decepticons. They have learned our language through the World Wide Web and can easily understand the messages which are being sent. Sam is trying to send the information to Autobots to locate “ALL SPARK” which is the only source of energy that can be ...
["x = input()\ny = input()\nz = x.find(y)\nif z == -1 :\n print('N')\nelse :\n print('Y')", "m=input().strip().lower()\ns=input().strip().lower()\n\nif m.find(s)==-1:\n print('N')\nelse:\n print('Y')", "import sys\n\ndef main():\n s = sys.stdin.readline\n a = s().strip()\n b = s().strip()\n if b in a:\n print(\"Y\")\n...
{"inputs": [["techtrishna online event", "onlin"]], "outputs": [["Y"]]}
INTERVIEW
PYTHON3
CODECHEF
402
a0ffdf19f5203d07a9733e88f709e2eb
UNKNOWN
We say that a binary string (a string containing only characters '0' and '1') is pure if it does not contain either of the strings "0101" or "1010" as a subsequence. Recall that string T is a subsequence of string S if we can delete some of the letters of S (possibly none) such that the resulting string will become T. ...
["# cook your dish here\nimport math;\nfrom math import gcd,sqrt,floor,factorial,ceil\nfrom bisect import bisect_left,bisect_right\nimport bisect;\nimport sys;\nfrom sys import stdin,stdout\nimport os\nsys.setrecursionlimit(pow(10,7))\nimport collections\nfrom collections import defaultdict,Counter\nfrom statistics imp...
{"inputs": [["4", "010111101", "1011100001011101", "0110", "111111"]], "outputs": [["2", "3", "0", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
9,350
7a1859a78939463dce6db2bac58ee1a3
UNKNOWN
You are given a grid with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). Initially, each cell of this grid is either empty, contains an ant or an anteater. Each ant is moving in a fixed direction: up, down, left or right. The anteaters do not move. The movement of ants happens in discre...
["import sys\r\n\r\nt = int(input())\r\n# print(t)\r\nfor _ in range(t):\r\n\tn,m = map(int,input().split());\r\n\ts = [];\r\n\tfor i in range(n):\r\n\t\ts.append(input())\r\n\tans = []\r\n\tfor i in range(n):\r\n\t\tans.append([])\r\n\t\tfor j in range(m):\r\n\t\t\tans[i].append([])\r\n\tfor i in range(n):\r\n\t\tfor ...
{"inputs": [["10", "3 3", "R--", "---", "--U", "1 4", "R--R", "2 2", "--", "--", "1 4", "R--L", "1 4", "-R-L", "1 4", "-R#L", "3 3", "R-D", "-#-", "R-U", "3 3", "R-D", "---", "R#U", "3 3", "-D-", "R-L", "-U-", "1 7", "RLLLLLL", ""]], "outputs": [["1", "0", "0", "0", "1", "0", "3", "2", "6", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
62,412
d96a9f635f3230d00c0996abd18704a5
UNKNOWN
Appy and Chef are participating in a contest. There are $N$ problems in this contest; each problem has a unique problem code between $1$ and $N$ inclusive. Appy and Chef decided to split the problems to solve between them ― Appy should solve the problems whose problem codes are divisible by $A$ but not divisible by $B$...
["for t in range(int(input())):\n n, a , b , k = map(int,input().split())\n solvedbychef = 0\n solvedbyappy = 0\n for i in range(n+1):\n if i % a == 0 and i % b == 0 :\n continue\n elif i%a == 0 :\n solvedbyappy+=1\n elif i%b == 0:\n solvedbychef+=1\n totalsolved = solvedbychef + solvedbyappy\n if totalsolved>...
{"inputs": [["1", "6 2 3 3"]], "outputs": [["Win"]]}
INTERVIEW
PYTHON3
CODECHEF
8,309
d7b872be45cadd1d5462d15d03c0d72e
UNKNOWN
The following graph G is called a Petersen graph and its vertices have been numbered from 0 to 9. Some letters have also been assigned to vertices of G, as can be seen from the following picture: Let's consider a walk W in graph G, which consists of L vertices W1, W2, ..., WL, such that Wi is connected with Wi + 1 f...
["let_to_num = {'A':[0,5], 'B':[1,6], 'C':[2,7], 'D':[3,8], 'E':[4,9]}\n\nnum_to_let = {0:'A', 1:'B', 2:'C', 3:'D', 4:'E',\n 5:'A', 6:'B', 7:'C', 8:'D', 9:'E'}\n\nconnections = {0:(1,4,5), 1:(0,2,6), 2:(1,3,7), 3:(2,4,8), 4:(0,3,9), 5:(0,7,8),\n 6:(1,8,9), 7:(2,5,9), 8:(3,5,6), 9:(4,6,7)}\n\n...
{"inputs": [["2", "AAB", "AABE", "", ""]], "outputs": [["501", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
4,215
f64832239aa8beda708c755a3efa3363
UNKNOWN
ZCO is approaching, and you want to be well prepared! There are $N$ topics to cover and the $i^{th}$ topic takes $H_i$ hours to prepare (where $1 \le i \le N$). You have only $M$ days left to prepare, and you want to utilise this time wisely. You know that you can't spend more than $S$ hours in a day preparing, as yo...
["import math\nT=int(input())\nfor i in range(T):\n N,M,S=input().split()\n N=int(N)\n M=int(M)\n S=int(S)\n ls=list(map(int,input().split()))\n maxx=max(ls)\n if S<17 and maxx<=50:\n ls.sort()\n total_sum = M * S\n count = 0\n sum = 0\n for i in ls:\n if i / S > 2:\n continue\n else:\n sum = sum + math....
{"inputs": [["2", "5 4 10", "10 24 30 19 40", "5 4 16", "7 16 35 10 15"]], "outputs": [["2", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
9,202
9d416b79883a5888309ba2c50e6dc3b2
UNKNOWN
Vanja and Miksi really like games. After playing one game for a long time, they decided to invent another game! In this game, they have a sequence $A_1, A_2, \dots, A_N$ and two numbers $Z_1$ and $Z_2$. The rules of the game are as follows: - The players take turns alternately, starting with Vanja. - There is an intege...
["import sys\nfrom collections import defaultdict as dd\nfrom collections import deque\nfrom fractions import Fraction as f\nfrom copy import *\nfrom bisect import * \nfrom heapq import *\nfrom math import *\nfrom itertools import permutations \n \ndef eprint(*args):\n print(*args, file=sys.stderr)\nzz=1\n \n#sys.setre...
{"inputs": [["3", "2 6 4", "-4 10", "1 1 -1", "2", "2 0 7", "3 4"]], "outputs": [["1", "0", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
9,360
52c47012190da3f8d2a1bc262d358cec
UNKNOWN
Rachel has some candies and she decided to distribute them among $N$ kids. The ith kid receives $A_i$ candies. The kids are happy iff the difference between the highest and lowest number of candies received is less than $X$. Find out if the children are happy or not. -----Input:----- - First line will contain $T$, num...
["t=int(input())\r\n\r\nfor t1 in range(t):\r\n\tn,x=map(int,input().split())\r\n\ta=list(map(int,input().split()))\r\n\t\r\n\tmx=max(a)\r\n\tmn=min(a)\r\n\t\r\n\tif (mx-mn<x):\r\n\t\tprint(\"YES\")\r\n\telse:\r\n\t\tprint(\"NO\")", "for i in range(int(input())):\r\n n, x = list(map(int, input().split()))\r\n a =...
{"inputs": [["2", "5 6", "3 5 6 8 1", "3 10", "5 2 9"]], "outputs": [["NO", "YES"]]}
INTERVIEW
PYTHON3
CODECHEF
7,260
1a931c888de1da1088480396a270a3a5
UNKNOWN
A policeman wants to catch a thief. Both the policeman and the thief can only move on a line on integer coordinates between $0$ and $N$ (inclusive). Initially, the policeman is at a coordinate $x$ and the thief is at a coordinate $y$. During each second, each of them must move to the left or right (not necessarily both...
["t = int(input())\nfor _ in range(t):\n x, y, k, n = [int(x) for x in input().split()]\n k = k*2\n temp = abs(x-y)\n if(temp%k == 0):\n print(\"Yes\")\n else:\n print(\"No\")\n", "t = int(input())\n\nfor _ in range(t):\n x, y, k, n = [int(x) for x in input().split()]\n k = k*2\n temp = abs(x-y)\n if(temp%k == 0):\n ...
{"inputs": [["5", "0 1 1 1", "1 4 1 5", "4 2 1 7", "3 7 2 10", "8 2 3 15"]], "outputs": [["No", "No", "Yes", "Yes", "Yes"]]}
INTERVIEW
PYTHON3
CODECHEF
5,249
fe39fc583e47d11eeaebdc823465a443
UNKNOWN
There is a big staircase with $N$ steps (numbered $1$ through $N$) in ChefLand. Let's denote the height of the top of step $i$ by $h_i$. Chef Ada is currently under the staircase at height $0$ and she wants to reach the top of the staircase (the top of the last step). However, she can only jump from height $h_i$ to the...
["# cook your dish here\n\nimport numpy as np\n \n\ndef minstairs(n,k):\n stairsHeight=[]\n stairs=0\n current = 0\n stairsHeight=list(map(int, input().split()))\n stairsHeight=np.array(stairsHeight)\n curr=0\n for i in range(n):\n if stairsHeight[i]-curr<=k:\n curr=stairsHeight[i]\n else:\n if (stairsHeight[i]-c...
{"inputs": [["1", "4 3", "2 4 8 16"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
7,054
3de34409c413b0379eb5c4b06480cb04
UNKNOWN
There are $X$ people participating in a quiz competition and their IDs have been numbered from $1$ to $X$ (both inclusive). Beth needs to form a team among these $X$ participants. She has been given an integer $Y$. She can choose participants whose ID numbers are divisible by $Y$. Now that the team is formed, Beth wan...
["for _ in range(int(input())):\r\n x, y = map(int, input().split())\r\n ans = 0\r\n for i in range(y, x+1, y):\r\n if i%y == 0:\r\n ans += i%10\r\n print(ans)", "lt = [[0, 0, 0, 0, 0, 0, 0, 0, 0 ,0],\n [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],\n [2, 4, 6, 8, 0, 2, 4, 6, 8, 0],\n [3, 6, ...
{"inputs": [["2", "10 3", "15 5"]], "outputs": [["18", "10"]]}
INTERVIEW
PYTHON3
CODECHEF
9,207
194cee621d87b2ef3c01cc8e81a290b6
UNKNOWN
Tracy loves Donuts. She purchased a lots of Donuts for her birthday party. She learnt to calculate the area of the circle a few days back and she is fascinated to know the area of the donuts as well !! Help her finding the area of the Donuts….. -----Input:----- - First line will contain, number of testcases. Then the ...
["oo = int(input())\r\nfor i in range(oo):\r\n\tval = int(input())\r\n\tprint((val**2)*3.14)", "for _ in range(int(input())):\n n=int(input())\n print((n*n)*3.14)", "# cook your dish here\nimport math\nfor _ in range(int(input())):\n r=int(input())\n if r>=1 and r<=20:\n print(3.14*(r**2))", "# cook ...
{"inputs": [["2", "5", "12"]], "outputs": [["78.5", "452.16"]]}
INTERVIEW
PYTHON3
CODECHEF
2,510
6d625fc00525283e8ddb454963082a3e
UNKNOWN
Given an array $A_1, A_2, ..., A_N$, count the number of subarrays of array $A$ which are non-decreasing. A subarray $A[i, j]$, where $1 ≤ i ≤ j ≤ N$ is a sequence of integers $A_i, A_i+1, ..., A_j$. A subarray $A[i, j]$ is non-decreasing if $A_i ≤ A_i+1 ≤ A_i+2 ≤ ... ≤ A_j$. You have to count the total number of such...
["# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n ar=list(map(int,input().split()))\n tot=0\n st=0\n for j in range(1,n):\n if(ar[j-1]>ar[j]):\n si=j-st\n c=(si*(si+1))//2\n tot+=c\n st=j\n si=n-st\n c=(si*(si+1))//2\n tot+=c\n print(tot)\n", "# cook your dish here\nfor _ in range ...
{"inputs": [["2", "4", "1 4 2 3", "1", "5"]], "outputs": [["6", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
4,937
1f6662d8b25e115d0d9bcad31c772276
UNKNOWN
As we all know, Chef is cooking string for long days, his new discovery on string is the longest common pattern length. The longest common pattern length between two strings is the maximum number of characters that both strings have in common. Characters are case sensitive, that is, lower case and upper case characters...
["from collections import Counter\r\ndef solve(A,B):\r\n a = Counter(A)\r\n b = Counter(B)\r\n ans = 0\r\n for i in a:\r\n if i in b:\r\n ans += min(a[i],b[i])\r\n \r\n return ans\r\n \r\n \r\nt = int(input())\r\n\r\nfor _ in range(t):\r\n A = input()\r\n B = input...
{"inputs": [["4", "abcd", "xyz", "abcd", "bcda", "aabc", "acaa", "Codechef", "elfedcc", "", ""]], "outputs": [["0", "4", "3", "5"]]}
INTERVIEW
PYTHON3
CODECHEF
8,871
4aaa23baed2907aba3b4cef8614b4f35
UNKNOWN
It's year 2018 and it's Christmas time! Before going for vacations, students of Hogwarts School of Witchcraft and Wizardry had their end semester exams. $N$ students attended the semester exam. Once the exam was over, their results were displayed as either "Pass" or "Fail" behind their magic jacket which they wore. A s...
["for _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n s = set(a)\n\n if n == 1 or len(s) > 2:\n print(-1)\n continue\n\n if len(s) == 1:\n x = s.pop()\n\n if x == 0:\n print(n)\n elif x == n-1:\n print(0)\n else:\n print(-1)\n\n continue\n\n x, y = sorted(s)\n xc, yc = ...
{"inputs": [["1", "4", "3 2 2 2"]], "outputs": [["1"]]}
INTERVIEW
PYTHON3
CODECHEF
9,547
c3870ea9d09ca6d8b313cc011376c888
UNKNOWN
Write a program that reads two numbers $X$ and $K$. The program first finds the factors of $X$ and then gives the sum of $K$th power of every factor. The program also finds the factor of $k$ and outputs the sum of $X$ times of every factor. -----Input:----- - First line will contain $T$, number of testcases. Then the...
["try:\r\n for _ in range(int(input())):\r\n s,s1=0,0\r\n x,k=[int(i) for i in input().split()]\r\n for i in range(2,x+1):\r\n if(x%i==0):\r\n s=s+i**k\r\n for i in range(2,k+1):\r\n if(k%i==0):\r\n s1+=i*x\r\n print(s,s1)\r\nexce...
{"inputs": [["1", "8 6"]], "outputs": [["266304 88"]]}
INTERVIEW
PYTHON3
CODECHEF
9,082
55e7d0ce71236d0b756936db77f952d6
UNKNOWN
Chef solved so many hard questions, now he wants to solve some easy problems for refreshment. Chef asks Cheffina for the new question. Cheffina challenges the chef to print the total number of 0's in the binary representation of N(natural number). -----Input:----- - First-line will contain $T$, the number of test case...
["from sys import stdin, stdout\r\ninput = stdin.readline\r\nfrom collections import defaultdict as dd\r\nimport math\r\ndef geti(): return list(map(int, input().strip().split()))\r\ndef getl(): return list(map(int, input().strip().split()))\r\ndef gets(): return input()\r\ndef geta(): return int(input())\r\ndef print_...
{"inputs": [["2", "2", "4"]], "outputs": [["1", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
1,268
85467ba9075152fb0d3ba3efc6b5dc57
UNKNOWN
Chef is playing a game with his childhood friend. He gave his friend a list of N numbers named $a_1, a_2 .... a_N$ (Note: All numbers are unique). Adjust the numbers in the following order: $(i)$ swap every alternate number with it's succeeding number (If N is odd, do not swap the last number i.e. $a_N$ ). $(ii)$ add ...
["for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n x=int(input())\n for _ in range(1,n,2):\n a[_],a[_-1]=a[_-1],a[_]\n for _ in range(n):\n a[_]+=(a[_]%3)\n # a=a[::-1]\n # a.sort()\n # if x>a[-1]:\n # print(-1)\n # continue\n l,h...
{"inputs": [["1", "10", "5 15 1 66 55 32 40 22 34 11", "38"]], "outputs": [["35 41"]]}
INTERVIEW
PYTHON3
CODECHEF
11,648
84d8a4004c03c22bbd8f6789f5b23df3
UNKNOWN
Arya and Aryan live in a country called Nadaca. Nadaca consists of $N$ cities numbered $1$ through $N$, which are connected by some bidirectional roads. Each road has a positive (not necessarily integer) length. Arya lives in city $1$ and Aryan lives in city $N$. Arya claims that for each city $v$, the shortest path fr...
["# cook your dish here\n# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int, input().split()))\n b=list(map(int, input().split()))\n\n if a[0]!=0 or b[-1]!=0 or a[-1]!=b[0]:\n print('No')\n \n else:\n ab=b[0]\n flag=0\n for i in range(1, n-1):\n if a[i]==0 or b[i]==0:\n pri...
{"inputs": [["2", "3", "0 1 1", "1 1 0", "3", "0 1 5", "5 1 0"]], "outputs": [["Yes", "No"]]}
INTERVIEW
PYTHON3
CODECHEF
9,856
7e9d1ebda2f4c8f47f40ccee0eb72aef
UNKNOWN
Cherry has a string S$S$ consisting of lowercase English letters. Using this string, he formed a pyramid of infinite length with certain rules: - N$N$-th row of pyramid contains N$N$ characters. - Each row of pyramid begins with the first character of the string. - The subsequent characters of the row are appended to t...
["def search(arr, lenl, val):\r\n s = 0\r\n l = lenl - 1\r\n\r\n total = 0\r\n\r\n while (s <= l):\r\n m = int((s + l) / 2)\r\n\r\n if (arr[m] <= val):\r\n total = m + 1\r\n s = m + 1\r\n\r\n else:\r\n l = m - 1\r\n\r\n return total\r\n\r\n\r\ndef kmp...
{"inputs": [["codechef", "chefcode", "3", "4", "12", "1455"]], "outputs": [["0", "1", "181"]]}
INTERVIEW
PYTHON3
CODECHEF
7,794
c269466d62007cd058ab61d9651e76f5
UNKNOWN
Chef is a brilliant university student that does not attend lectures because he believes that they are boring and coding is life! However, his university follows certain rules and regulations, and a student may only take an exam for a course if he has attended at least 75% of lectures for this course. Since you are Che...
["# cook your dish here\ndef ceil(num):\n if num%1==0:\n return int(num//1)\n else:\n return int((num//1)+1)\n \nfor _ in range(int(input())):\n n=int(input())\n s=input()\n p=0\n a=[]\n for i in range(n):\n if s[i]==\"P\":\n p=p+1\n req=ceil(0.75*n)\n requirement=req-p\n for i in range(2,n-2):\n if s[i]==\"A\":\...
{"inputs": [["1", "9", "PAAPPAPPP"]], "outputs": [["1"]]}
INTERVIEW
PYTHON3
CODECHEF
1,329
54a0a06ca2ad4efd52d534162bdf48ae
UNKNOWN
Snakeland is a well organised city. The houses of the city are organised in an orderly rectangular fashion with dimensions 2 * n, i.e. there are total two rows and n columns. The house in the i-th row and j-th column is also said to be the house at coordinates (i, j). Some of the houses are occupied by snakes, while th...
["# cook your dish here\nt=int(input())\nwhile t:\n n=int(input())\n r1=input()\n r2=input()\n r1count=0\n r2count=0\n count=0\n for i in range(n):\n if(r1[i]==\"*\"):\n r1count+=1\n if(r2[i]==\"*\"):\n r2count+=1\n if(r1count>0) and (r2count>0):\n count=1\n r1count=0\n r2count=0\n i=0\n while(i<n):\n if(r...
{"inputs": [["3", "2", "**", "**", "3", "***", "*..", "3", "*..", ".*."]], "outputs": [["2", "3", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
623
20f5d3a8f884b5d0edfd998d246045c5
UNKNOWN
Andrii is good in Math, but not in Programming. He is asking you to solve following problem: Given an integer number N and two sets of integer A and B. Let set A contain all numbers from 1 to N and set B contain all numbers from N + 1 to 2N. Multiset C contains all sums a + b such that a belongs to A and b belongs to B...
["# cook your dish here\nimport math;\nfrom math import gcd,sqrt,floor,factorial,ceil\nfrom bisect import bisect_left,bisect_right\nimport bisect;\nimport sys;\nfrom sys import stdin,stdout\nimport os\nsys.setrecursionlimit(pow(10,7))\nimport collections\nfrom collections import defaultdict,Counter\nfrom statistics imp...
{"inputs": [["3 5", "6", "2", "9", "7", "5", ""]], "outputs": [["2", "0", "1", "3", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
5,896
f1e0fd2219aa3432da1286f20defa005
UNKNOWN
There are $N$ cells numbered 1,2,….., N, and every cell has some positive value. you will be given an array $A_1$,$A_2$,…,$A_N$ where $A_i$ is the value of $ith$ cell and an integer $K$. There is a monkey who wants to reach the $right$ side of the last ($Nth$) cell, initially, the monkey was left side of the first ($1s...
["from sys import setrecursionlimit\r\nsetrecursionlimit(10 * 9)\r\n\r\ndef solve(i):\r\n if i + k >= n:\r\n return 1\r\n\r\n if i in dp:\r\n return dp[i]\r\n\r\n mini = float('inf')\r\n for j in range(i+1, min(n, i+k+1)):\r\n if i == -1 or a[i] == a[j]:\r\n mini = min(mini, ...
{"inputs": [["1", "2 2", "3 4"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
8,267
82ae0f03da3911df040390854bf7b06e
UNKNOWN
Given an array of size N$N$ and two integers K$K$ and S$S$, the special sum of a subarray is defined as follows: (Sum of all elements of the subarray) * (K$K$ - p$p$ * S$S$) Where p$p$ = number of distinct prime factors of “product of all elements of the subarray”. Find the maximum special sum by considering all non...
["# cook your dish here\nfrom math import floor, sqrt\ntry:long\nexcept NameError:long = int \ndef fac(n):\n step,maxq,d = lambda x: 1 + (x<<2) - ((x>>1)<<1),long(floor(sqrt(n))),1\n q = n % 2 == 0 and 2 or 3 \n while q <= maxq and n % q != 0:\n q = step(d)\n d += 1\n return q <= maxq and [q] + fac(...
{"inputs": [["4 10 2", "14 2 7 15"]], "outputs": [["138", "Sample"]]}
INTERVIEW
PYTHON3
CODECHEF
4,955
a57f5ff7127a978191f4e05ffa06bb1a
UNKNOWN
Chef recently developed an affinity for undirected graphs. He likes pairs of graphs that are similar in structure. However, Chef discovered that when the vertices of a graph are reorganized, it's often the case that the resulting graph, although still structurally similar to the original, can look completely different....
["import random\nt=int(input())\nfor testCase in range(t):\n\tn=int(input())\n\tarray1=[]\n\tarray2=[]\n\tarray=[]\n\tfor i in range(n) :\n\t\tarray1.append(list(map(int,input().split())))\n\tfor i in range(n) :\n\t\tarray2.append(list(map(int,input().split())))\n\tfor i in range(n) :\n\t\tarray.append(i)\n#\tprint arr...
{"inputs": [["2", "3", "0 1 0", "1 0 0", "0 0 0", "0 0 1", "0 0 1", "1 1 0", "4", "0 0 1 0", "0 0 0 0", "1 0 0 1", "0 0 1 0", "0 0 1 1", "0 0 0 0", "1 0 0 0", "1 0 0 0", ""]], "outputs": [["1 2 3", "1 2 3", "1 4 2 3", "2 4 1 3"]]}
INTERVIEW
PYTHON3
CODECHEF
19,753
ddb7b04be70c3150f08997240e3ea789
UNKNOWN
Zonal Computing Olympiad 2012, 26 Nov 2011 It's dinner time in Castle Camelot, and the fearsome Knights of the Round Table are clamouring for dessert. You, the chef, are in a soup. There are N knights, including King Arthur, each with a different preference for dessert, but you cannot afford to make desserts for all ...
["n=int(input())\r\nar=list(map(int,input().split()))\r\ndp=[0]*n \r\ndp[0]=ar[0]\r\ndp[1]=ar[1]\r\nfor i in range(2,n):\r\n dp[i]=min(dp[i-2],dp[i-1])+ar[i]\r\n \r\nar.reverse()\r\n#print(ar)\r\ndp1=[0]*n \r\ndp1[0]=ar[0]\r\ndp1[1]=ar[1]\r\nfor i in range(2,n):\r\n dp1[i]=min(dp1[i-2],dp1[i-1])+ar[i]\r\nprint...
{"inputs": [["5", "1 2 1 2 2"]], "outputs": [["4"]]}
INTERVIEW
PYTHON3
CODECHEF
10,378
488bb6845cc7a1b4669b8c072bab04f9
UNKNOWN
-----Problem Statement----- Chef has a sequence of N segments: [L1, R1], [L2, R2], ..., [LN, RN]. He wants to transform the first segment to the last one (with index N). His plan is to do this big deal with a number of transformations: firstly he will transform the first segment to the second one, then to the third on...
["for tc in range(int(input())):\n N = int(input())\n a, b = list(map(int, input().split()))\n pr = []\n\n # 'L' is lexicographically lower than 'R'.\n # so, we should first try to apply L+ or L-\n # if we can't then only we'll try to apply R+ or R-\n\n for i in range(N - 1):\n l, r = list(map(int, input().split()))\n...
{"inputs": [["4", "3", "-1 0", "0 1", "3 5", "1", "0 1", "3", "-2 -1", "-2 -1", "-2 0", "4", "4 6", "3 5", "-1 1", "1 2"]], "outputs": [["9", "R+L+R+L+R+L+R+L+R+", "0", "1", "R+", "13", "L-R-L-L-L-L-R-R-R-R-L+R+L+"]]}
INTERVIEW
PYTHON3
CODECHEF
851
6446fd0e490eca0ff3d037cf2aa2ed25
UNKNOWN
Chef had an array A with length N, but some of its elements got lost. Now, each element of this array is either unknown (denoted by -1) or a positive integer not exceeding K. Chef decided to restore the array A by replacing each unknown element by a positive integer not exceeding K. However, Chef has M restrictions tha...
["# cook your dish here\n# cook your dish here\nMOD = 10 ** 9 + 7\n \nfor t in range(int(input())):\n N, M, K = map(int, input().split())\n A = list(map(int, input().split()))\n I, D = [0] * (N + 2), [0] * (N + 2)\n for i in range(M):\n x, L, R = input().split()\n L, R = int(L), int(R)\n ...
{"inputs": [["3", "4 2 10", "2 3 5 4", "I 1 2", "D 3 4", "5 2 10", "-1 -1 -1 -1 -1", "I 1 3", "D 3 5", "6 2 2", "-1 -1 -1 -1 -1 -1", "I 1 4", "D 4 6"]], "outputs": [["1", "8", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
3,256
9c138bd7cdbea27578033c7a5229ac71
UNKNOWN
Note : This question carries $150$ $points$ There is an outcry in Middle Earth, as the greatest war between Orgs of Dark Lord Sauron and Frodo Baggins is about to begin. To end the war, Frodo decides to destroy the ring in the volcano of Mordor. There are many ships that lead Frodo to Mordor, and he is confused about w...
["# cook your dish here\nfrom math import pow\nt = int(input())\nfor _ in range(t):\n m,n = map(int,input().rstrip().split())\n cnt = len(str(n))\n x = pow(10,cnt)\n if n == x-1:\n print(m*cnt,m)\n else:\n print(m*(cnt-1),m)", "# cook your dish here\r\ndef sol(z):\r\n r=len(str(z))\r\n ...
{"inputs": [["1", "1 9"]], "outputs": [["1 1"]]}
INTERVIEW
PYTHON3
CODECHEF
8,130
cbadd373b4b3ededb179e1798135840d
UNKNOWN
Chef wants to teach a lesson of sharing to the students. There are $N$ students (numbered from $1$ to $N$ from left to right) who are asked to stand in a row. Initially Chef gave $A$$i$ candies to the $i$$th$ child. In one operation any child can give any number of candies to the child standing to his immediate left (i...
["from math import ceil\n\nfor _ in range(int(input())):\n n = int(input())\n arr = [int(x) for x in input().split()]\n sarr = sum(arr)\n mavg = sarr/n\n while n>1:\n sarr -= arr.pop()\n n-=1\n mavg = max(mavg, sarr/n)\n print(int(ceil(mavg)))", "import math\nT=int(input())\n\nfor _ in range(T):\n N=int(input())\n A...
{"inputs": [["2", "5", "1 2 3 4 5", "5", "5 4 3 2 1"]], "outputs": [["3", "5"]]}
INTERVIEW
PYTHON3
CODECHEF
1,092
a52c56d9644f1553d35b696bb6e1d733
UNKNOWN
On her way to ChefLand, Marichka noticed $10^K$ road signs (numbered $0$ through $10^K - 1$). For each valid $i$, the sign with number $i$ had the integer $i$ written on one side and $10^K-i-1$ written on the other side. Now, Marichka is wondering — how many road signs have exactly two distinct decimal digits written o...
["import math\r\nt=int(input())\r\nfor i in range(t):\r\n k=int(input())\r\n res=((pow(2,k,1000000007))*5)%1000000007\r\n print(res)", "import math\r\nt=int(input())\r\nfor i in range(t):\r\n k=int(input())\r\n res=((pow(2,k,1000000007))*5)\r\n print(res)", "t=int(input())\r\nfor i in range(t):\r\n ...
{"inputs": [["1", "1", ""]], "outputs": [["10"]]}
INTERVIEW
PYTHON3
CODECHEF
7,563
d589fd59a8c7f71b4f9f1776b3a9e625
UNKNOWN
Sereja have array A' that contain N integers. Now Sereja want to permute elements of the array, he want to use some permutation p, such that A[i] = A'[p[i]], where A - new array. Lets function f(A,i) = S - A[i] - A[i +1] - ... - A[j], where j is the maximum possible index, such that A[i] + A[i + 1] + ... + A[j] <= S,...
["# Md. Khairullah Gaurab\n# SUST, CSE, 20th Batch\n# gaurab.cse.sust@gmail.com\n\n\ntest = int(input());\n\nfor i in range(test):\n N, S, K = list(map(int,input().split()));\n lis = list(map(int,input().split()));\n ans = [i+1 for i in range(N)] ;\n ans.sort(reverse=True);\n for j in range(N):\n ...
{"inputs": [["2", "3 2 4", "3 4 1", "4 4 1", "1 1 1 1", "", ""]], "outputs": [["2 1 3", "4 3 2 1"]]}
INTERVIEW
PYTHON3
CODECHEF
8,668
67282879282ddbe5cc4610e2a8bb1431
UNKNOWN
Tweedle-Dee and Tweedle-Dum are playing a fierce match of binary Nim. This novel game is played with $N$ stacks, each of them containing only $1$-s and $0$-s. Just like in normal Nim, Tweedle-Dee and Tweedle-Dum alternate turns; in their turn, a player must choose one non-empty stack and remove a positive number of ele...
["for u in range(int(input())):\n p=input().split()\n n=int(p[0])\n s=p[1]\n x,y=0,0\n for i in range(n):\n l=input()\n if(l[0]=='1'):\n y+=l.count('1')\n else:\n x+=l.count('0')\n if(x<y):\n print(\"Dum\")\n elif(y<x):\n print(\"Dee\")\n else:\n if(s=='Dee'):\n print(\"Dum\")\n else:\n print(\"Dee\")\n"...
{"inputs": [["2", "2 Dee", "101", "010", "2 Dum", "101", "010"]], "outputs": [["Dum", "Dee"]]}
INTERVIEW
PYTHON3
CODECHEF
9,226
7fb0a361ae071d38c927d13b04ab3e59
UNKNOWN
Kabir likes Tara's smile and wants to look at her smile. They are sitting in the class and you are friends with Kabir. You have to place a mirror (point size) in the front wall of the class so that Kabir can have a glimpse of Tara's smile. Consider the front wall as x-axis . You are given the coordinates of position ...
["# cook your dish here\ntry:\n t = int(input())\n for _ in range(t):\n p = [int(x) for x in input().split()]\n q = [int(x) for x in input().split()]\n \n q[1] *= -1\n m = (q[1]-p[1])/(q[0]-p[0])\n c = p[1] - m*p[0]\n \n print(\"{:.2f}\".format(-c/m))\nexcep...
{"inputs": [["1", "1 1", "4 4"]], "outputs": [["1.60"]]}
INTERVIEW
PYTHON3
CODECHEF
2,157
77aa46f530dba877ab930ced30cbac11
UNKNOWN
The most dangerous cyborg Jenish is finally entrapped on a narrow bridge over a valley. The bridge is $N$ meters long. For convenience, position $i$ represents a portion of bridge between whose left border is at distance $i-1$ meters from left end and right border is at distance $i$ meters from left end. There are $N$...
["# cook your dish here\nimport bisect\nfor _ in range(int(input())):\n \n n,x=list(map(int,input().split()))\n \n l=list(map(int,input().split()))\n battery=[]\n \n power=0\n i=0\n t=(n+1)//2\n while power<x and i<t:\n \n if i==n-i-1:\n temp=[-1,l[i]]\n else:\n temp=sorted([ l[i], l[n-i-1] ])\n \n power+=temp...
{"inputs": [["3", "4 8", "5 1 4 2", "3 4", "3 1 2", "2 7", "5 5"]], "outputs": [["YES", "YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
9,632
873f4d513741735d227571e2d6247f73
UNKNOWN
Once upon a time, a king and a few of his soldiers were caught by an enemy king in a war. He puts them in a circle. The first man in the circle has to kill the second man, the third man has to kill the fourth, fifth man to kill the sixth and so on. When the circle is completed, the remaining people have to form a ci...
["n=int(input())\narr=[]\nfor i in range(1,n+1):\n arr.append(i)\nc=0\ni=0\nf=0;\nwhile(c<n-1):\n if(arr[i%n]!=-1 and f):\n arr[i%n]=-1\n c=c+1\n f=0\n if(arr[i%n]!=-1):\n f=1\n i=i+1\n\nfor i in range(0,n):\n if(arr[i]!=-1):\n ans=arr[i]\n break;\nprint(ans) \n", "import sys\nn = int(sys.stdin.readline())\nans=0...
{"inputs": [["9"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
429
4c99d889e2644a0544e50fc00eba07b8
UNKNOWN
Chef has come to a 2 dimensional garden in which there are N points. Each point has coordinates (x, y), where x can either be 1 or 2 or 3. Chef will now choose every triplet of these N points and make a triangle from it. You need to tell the sum of areas of all the triangles the Chef makes. Note that some of the triple...
["# cook your dish here\n# Author: Dancing Monkey | Created: 09.DEC.2018\n\n\nimport bisect\nfor _ in range(int(input())):\n n = int(input())\n x1 , x2, x3 = [], [], []\n for i in range(n):\n x, y = list(map(int, input().split()))\n\n if x == 1: x1.append(y)\n if x == 2: x2.append(y)\n if x == 3: x3.append(y)\n\n x...
{"inputs": [["2", "3", "1 1", "2 1", "3 3", "4", "1 1", "2 2", "2 1", "3 3"]], "outputs": [["1.0", "2.0"]]}
INTERVIEW
PYTHON3
CODECHEF
2,255
abc7fdaacb5421aaf1cf86f5de687534
UNKNOWN
The annual snake festival is upon us, and all the snakes of the kingdom have gathered to participate in the procession. Chef has been tasked with reporting on the procession, and for this he decides to first keep track of all the snakes. When he sees a snake first, it'll be its Head, and hence he will mark a 'H'. The s...
["# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n s=input().strip()\n c=0\n for i in range(len(s)):\n if s[i]=='.':\n continue\n if s[i]=='H':\n c+=1\n if s[i]=='T':\n c-=1\n if c>1:\n break\n if c<0:\n break\n if c==0:\n print('Valid')\n else:\n print('Invalid')", "for i i...
{"inputs": [["6", "18", "..H..T...HTH....T.", "3", "...", "10", "H..H..T..T", "2", "HT", "11", ".T...H..H.T", "7", "H..T..H"]], "outputs": [["Valid", "Valid", "Invalid", "Valid", "Invalid", "Invalid"]]}
INTERVIEW
PYTHON3
CODECHEF
9,073
f7843030194b449584d77a0f41fe2f52
UNKNOWN
Chef belongs to a very rich family which owns many gold mines. Today, he brought N gold coins and decided to form a triangle using these coins. Isn't it strange? Chef has a unusual way of forming a triangle using gold coins, which is described as follows: - He puts 1 coin in the 1st row. - then puts 2 coins in the 2nd ...
["t = eval(input())\n\ndef moneda(m):\n h = 1\n triange = []\n while m >= h:\n triange.append(h)\n m -= h \n h += 1\n return len(triange)\n\ntriangulo = []\nfor i in range(t):\n n = eval(input())\n triangulo.append(n)\n\nfor i in triangulo:\n print(moneda(i))\n", "t = eval(input())\n\ndef moneda(m):\n h = 1\n triang...
{"inputs": [["3", "3", "5", "7"]], "outputs": [["2", "2", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
4,318
45cfdb1ad95a91b65232d92d63447c9c
UNKNOWN
-----Problem Statement----- A classroom has several students, half of whom are boys and half of whom are girls. You need to arrange all of them in a line for the morning assembly such that the following conditions are satisfied: - The students must be in order of non-decreasing height. - Two boys or two girls must not ...
["for u in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n d=list(map(int,input().split()))\n ka=[]\n k=[]\n l.sort()\n d.sort()\n for i in range(n):\n ka.append(d[i])\n ka.append(l[i])\n for i in range(n):\n k.append(l[i])\n k.append(d[i...
{"inputs": [["1", "2", "1 3", "2 4"]], "outputs": [["YES"]]}
INTERVIEW
PYTHON3
CODECHEF
19,250
d62ddbf9d95942a32edb32f26f1d35e4
UNKNOWN
Recently, Chef got obsessed with piano. He is a just a rookie in this stuff and can not move his fingers from one key to other fast enough. He discovered that the best way to train finger speed is to play scales. There are different kinds of scales which are divided on the basis of their interval patterns. For instanc...
["t =int(input())\r\nfor i in range(t):\r\n C=[ord(x)-ord('R') for x in list(input())]\r\n N=int(input())\r\n L=sum(C)\r\n r=1\r\n c=0\r\n while(r*L<N*12):\r\n c+=N*12-r*L\r\n r+=1\r\n print(c)\r\n\r\n\r\n\r\n\r\n\r\n\r\n"]
{"inputs": [["2 ", "TTTT", "1", "TTSTTTS", "3", "", ""]], "outputs": [["4", "36"]]}
INTERVIEW
PYTHON3
CODECHEF
258
98ee87ca6512f58c9f696891633a651b
UNKNOWN
The Golomb sequence $G_1, G_2, \ldots$ is a non-decreasing integer sequence such that for each positive integer $n$, $G_n$ is the number of occurrences of $n$ in this sequence. The first few elements of $G$ are $[1, 2, 2, 3, 3, 4, 4, 4, 5, \ldots]$. Do you know the recurrence relation for the Golomb sequence? It is $G_...
["def find_upper_bound(arr,key):\n low,high = 0,len(arr)-1\n while low<=high:\n mid = (low+high)//2 \n if arr[mid]==key:return mid\n elif arr[mid]>key and mid-1>=0 and arr[mid-1]<key:return mid \n elif arr[mid]>key:high = mid - 1 \n else:low = mid + 1 \n return mid \ndef get_query(l):\n nonlocal prefix_storer,bin_...
{"inputs": [["3", "1 5", "2 4", "100 100"]], "outputs": [["27", "17", "441"]]}
INTERVIEW
PYTHON3
CODECHEF
8,581
69bf4a364d98fc85371a76c2177cd12b
UNKNOWN
k kids seem to have visited your home for the festival. It seems like the kids had all been fighting with each other, so you decided to keep them as far as possible from each other. You had placed n chairs on the positive number line, each at position x i , 1 ≤ i ≤ n. You can make the kids sit in any of the chairs. Now...
["#dt = {} for i in x: dt[i] = dt.get(i,0)+1\r\nimport sys;input = sys.stdin.readline\r\ninp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]\r\n\r\ndef check(mid):\r\n pos = x[0]\r\n ct = 1\r\n for i in range(1,n):\r\n if x[i]-pos >= mid:\r\n pos = x[i]\r\n ct +...
{"inputs": [["1", "2 2", "1 2"]], "outputs": [["1", "Constraints", "2 \u2264 n \u2264 100000", "0 \u2264 xi \u2264 10 9", "k \u2264 n"]]}
INTERVIEW
PYTHON3
CODECHEF
762
3278178bc3d2b5ef4742a7f1626789ec
UNKNOWN
Salmon runs a fish delivery company in Fish City. Fish City has $N$ vertical roads numbered $1, 2, ..., N$ from left to right, each spaced 1 unit apart; similarly, there are $M$ horizontal roads numbered $1, 2, ..., M$ from bottom to top, each spaced 1 unit apart. We will denote the intersection between the $x$-th vert...
["n,m,k=map(int, input().split())\na = []\ncheck = [0]*m\nwhile k!= 0:\n x1,y1,x2,y2 =map(int,input().split())\n a.append([x1,y1,x2,y2])\n check[y1-1] += 1\n check[y2-1] += 1\n k-= 1\nmaxi = check.index(max(check))+1\nsum = 0\nk = 0\nfor i in range(len(a)):\n x1,y1,x2,y2 = a[i]\n if (y1 > maxi and y2 > maxi) or (y1<max...
{"inputs": [["5 4 3", "2 3 4 1", "1 4 5 2", "3 3 5 3"]], "outputs": [["16"]]}
INTERVIEW
PYTHON3
CODECHEF
17,525
3a683ebbec8353139958e9f1a4a08b48
UNKNOWN
There is a building with $N$ floors (numbered $1$ through $N$ from bottom to top); on each floor, there are $M$ windows (numbered $1$ through $M$ from left to right). Let's denote the $j$-th window on the $i$-th floor by $(i, j)$. All windows in the building need to be cleaned one by one in a specific order. You are gi...
["try:\r\n t = int(input())\r\n while(t > 0):\r\n t -= 1\r\n n,m = list(map(int,input().split()))\r\n a = [list(map(int,input().split())) for _ in range(n)]\r\n dp = [[0 for _ in range(m)] for _ in range(n)]\r\n ans = [['0' for _ in range(m)] for _ in range(n)]\r\n for i ...
{"inputs": [["1", "3 4", "1 3 7 10", "9 2 4 11", "8 12 5 6 ", ""]], "outputs": [["1111", "1001", "0100"]]}
INTERVIEW
PYTHON3
CODECHEF
16,979
3ed4f4c49726df1cdb497967a3db49c2
UNKNOWN
Devu has n weird friends. Its his birthday today, so they thought that this is the best occasion for testing their friendship with him. They put up conditions before Devu that they will break the friendship unless he gives them a grand party on their chosen day. Formally, ith friend will break his friendship if he does...
["# cook your dish here\ntest = int(input())\n\nfor _ in range(0,test):\n n = int(input())\n lister = set(map(int,input().split()))\n print(len(lister))", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n s=set(l)\n l1=list(s)\n print(len(l1))", "# cook your dis...
{"inputs": [["2", "2", "3 2", "2", "1 1"]], "outputs": [["2", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
3,966
66126f5911ae98a89f6f94f8ef06e9af
UNKNOWN
Chef was bored staying at home in the lockdown. He wanted to go out for a change. Chef and Chefu are fond of eating Cakes,so they decided to go the Cake shop where cakes of all possible price are available . They decided to purchase cakes of equal price and each of them will pay for their cakes. Chef only has coins of ...
["# cook your dish here\nimport math\nT=int(input())\nfor i in range(T):\n a=list(map(int,input().split()))\n n=a[0]\n m=a[1]\n print(m*n//math.gcd(m,n))", "def compute_gcd(x, y):\r\n\r\n while(y):\r\n x, y = y, x % y\r\n return x\r\n\r\n# This function computes LCM\r\ndef compute_lcm(x, y):\r\n ...
{"inputs": [["1", "2 3"]], "outputs": [["6"]]}
INTERVIEW
PYTHON3
CODECHEF
5,951