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
f39e919597e397681bb961672e4542e6
UNKNOWN
Almir had a small sequence $A_1, A_2, \ldots, A_N$. He decided to make $K$ copies of this sequence and concatenate them, forming a sequence $X_1, X_2, \ldots, X_{NK}$; for each valid $i$ and $j$ ($0 \le j < K$), $X_{j \cdot N + i} = A_i$. For example, if $A = (1, 2, 3)$ and $K = 4$, the final sequence is $X = (1, 2, 3,...
["# cook your dish here\ndef count(k,n,m):\n sum1=(m*(m+1))//2\n sum2=(m*(m-1))//2\n ct=0\n for i in range(n):\n for j in range(n):\n if i<j and k[i]>k[j]:\n ct+=sum1\n elif j<i and k[i]>k[j]:\n ct+=sum2\n return ct\n\ntest=int(input())\nfor _ in...
{"inputs": [["2", "3 3", "2 1 3", "4 100", "99 2 1000 24", ""]], "outputs": [["12", "30000"]]}
INTERVIEW
PYTHON3
CODECHEF
12,758
69a52b017f9ef99f9140db9b27a850ac
UNKNOWN
Indian National Olympiad in Informatics 2015 A string is any nonempty sequence of 0s and 1s. Examples of strings are 00, 101, 111000, 1, 0, 01. The length of a string is the number of symbols in it. For example, the length of 111000 is 6. If u and v are strings, then uv is the string obtained by concatenating u and v. ...
["# cook your dish here\r\ndef offset(l, flag):\r\n x = 0\r\n # print(l)\r\n for i in range(1, len(l)):\r\n temp = []\r\n for j in range(i):\r\n v = getbig(l[i], l[j], fs)\r\n if v > 1:\r\n temp.append(v)\r\n if flag:\r\n x +=...
{"inputs": [["3 176"]], "outputs": [["6"]]}
INTERVIEW
PYTHON3
CODECHEF
15,055
b1c857fa02977c0552a3dc516d7d50bf
UNKNOWN
Finally, the pandemic is over in ChefLand, and the chef is visiting the school again. Chef likes to climb the stairs of his school's floor by skipping one step, sometimes chef climbs the stairs one by one. Simply, the chef can take one or 2 steps in one upward movement. There are N stairs between ground and next floor....
["for _ in range(int(input())):\n N=int(input())\n if N%2==0:\n print(N//2+1)\n else:\n print((N-1)//2+1)", "# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n print((n//2)+1)", "# cook your dish here\nfor t in range(int(input())):\n n = int(input())\n print(int(n...
{"inputs": [["1", "3"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
768
25fa88a3996bbd4c6bbb4555d24f5d62
UNKNOWN
Indian National Olympiad in Informatics 2016 There are k types of brackets each with its own opening bracket and closing bracket. We assume that the first pair is denoted by the numbers 1 and k+1, the second by 2 and k+2 and so on. Thus the opening brackets are denoted by 1,2,.., k, and the corresponding closing brack...
["# cook your dish here\r\nimport bisect\r\nn, k1, *l = map(int, input().split())\r\nv_l, b_l = l[:n], l[n:]\r\n\r\nb_inv = {key:[] for key in range(2*k1)}\r\nfor i in range(n):\r\n b_l[i] -= 1\r\n b_inv[b_l[i]].append(i)\r\n\r\ndp = [[0 for _ in range(n)] for _ in range(n)]\r\nfor k in range(1, n):\r\n for j ...
{"inputs": [["6 3 4 5 -2 1 1 6 1 3 4 2 5 6"]], "outputs": [["13"]]}
INTERVIEW
PYTHON3
CODECHEF
31,739
088c6f856fd7cd6d13ccea67ae630919
UNKNOWN
Write a program that takes in a letterclass ID of a ship and display the equivalent string class description of the given ID. Use the table below. Class ID Ship ClassB or bBattleShipC or cCruiserD or dDestroyerF or fFrigate -----Input----- The first line contains an integer T, the total number of testcases. Then T l...
["# cook your dish here\nt=int(input())\nfor i in range(t):\n n=input()\n if(n=='b' or n=='B'):\n print('BattleShip')\n elif(n=='c' or n=='C'):\n print('Cruiser')\n elif(n=='d' or n=='D'):\n print('Destroyer')\n else:\n print('Frigate')", "for _ in range(int(input())):\n p=...
{"inputs": [["3", "B", "c", "D"]], "outputs": [["BattleShip", "Cruiser", "Destroyer"]]}
INTERVIEW
PYTHON3
CODECHEF
7,161
345904291e0f2f68608866e1b22ec387
UNKNOWN
Nature photographing may be fun for tourists, but it is one of the most complicated things for photographers. To capture all the facets of a bird, you might need more than one cameras. You recently encountered such a situation. There are $n$ photographers, so there are $n$ cameras in a line on the x-axis. All the camer...
["from math import *\r\nfrom collections import *\r\nimport sys\r\ninput=sys.stdin.readline\r\nt=int(input())\r\nwhile(t):\r\n t-=1\r\n n=int(input())\r\n a=list(map(int,input().split()))\r\n p,q=map(int,input().split())\r\n s=0\r\n a.sort()\r\n for i in range(n//2):\r\n x=a[i]\r\n x1...
{"inputs": [["2", "2", "0 1", "0 1", "2", "0 1", "100 1", ""]], "outputs": [["0.785398163397", "0.000100999899"]]}
INTERVIEW
PYTHON3
CODECHEF
16,651
34af6b3ddf701cf4352e90de94842a31
UNKNOWN
Three Best Friends $AMAN$ , $AKBAR$ , $ANTHONY$ are planning to go to “GOA” , but just like every other goa trip plan there is a problem to their plan too. Their parents will only give permission if they can solve this problem for them They are a given a number N and they have to calculate the total number of triplets...
["import sys\r\ndef get_array(): return list(map(int , sys.stdin.readline().strip().split()))\r\ndef get_ints(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef input(): return sys.stdin.readline().strip()\r\nimport sys\r\nsys.setrecursionlimit(10**9)\r\nfrom math import sqrt,ceil,floor\r\nn=int(inpu...
{"inputs": [["3"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
1,129
11f736cf93352e54ffc606a124301fd9
UNKNOWN
Maheshmati and Sangu are playing a game. First, Maheshmati gives Sangu a sequence of $N$ distinct integers $a_1, a_2, \dots, a_N$ (not necessarily sorted) and an integer $K$. Sangu has to create all subsequences of this sequence with length $K$. For each subsequence, he has to write down the product of $K-2$ integers: ...
["f = 5003*[0]\nmodn = 1000000007\n\n\ndef qPow(a, b):\n nonlocal modn\n res = 1\n while b > 0:\n if (b & 1) == 1:\n res = res * a % modn\n a = a * a % modn\n b = b >> 1\n return res\n\n\ndef getF():\n nonlocal f\n f[0] = 1\n for i in range(1, 5001):\n f[i] = f[i-1] * i\n\n\ndef __starting_point():\n getF()\n T =...
{"inputs": [["1", "4 3", "1 2 3 4"]], "outputs": [["36"]]}
INTERVIEW
PYTHON3
CODECHEF
11,058
c9afd6a7eb3626d1cb4bc489bbb65c69
UNKNOWN
There are total $N$ cars in a sequence with $ith$ car being assigned with an alphabet equivalent to the $ith$ alphabet of string $S$ . Chef has been assigned a task to calculate the total number of cars with alphabet having a unique even value in the given range X to Y (both inclusive) . The value of an alphabet is sim...
["arr = list(input())\r\nn = len(arr)\r\nans = list()\r\n#for i in arr:\r\n #ans.append(ord(i)-96)\r\nli = ['b','d','f','h','j','l','n','p','r','t','v','x','z']\r\ns = set(arr)\r\ntemp = s.intersection(li)\r\nfor _ in range(int(input())):\r\n x,y = list(map(int,input().split()))\r\n li = list(temp)\r\n #s =...
{"inputs": [["bbccdd", "5", "1 2", "3 4", "5 6", "1 6", "2 5"]], "outputs": [["1", "0", "1", "2", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
7,366
641cad3585b966480a714cbe24852b98
UNKNOWN
You are given three numbers $a$, $b$, $c$ . Write a program to determine the largest number that is less than or equal to $c$ and leaves a remainder $b$ when divided by $a$. -----Input:----- - First line will contain $T$, number of testcases. Then the testcases follow. - Each testcase contains a single line of input, ...
["# cook your dish here\nfor t in range(int(input())):\n a,b,c=map(int,input().split())\n p=(c//a)*a+b\n if p<=c:\n print(p)\n else:\n print(((c//a)-1)*a+b)", "try:\r\n for _ in range(int(input())):\r\n a,b,c=[int(i) for i in input().split()]\r\n r=c%a\r\n if(r>b):\r\n ...
{"inputs": [["1", "7 2 10"]], "outputs": [["9"]]}
INTERVIEW
PYTHON3
CODECHEF
5,258
19f7e653c49205d19730fdcaf165f311
UNKNOWN
Aureole the Techno-cultural fest of JEC thought of conducting a workshop on big data, as the topic is hot everyone wants to take part but due to limited seats in the Jashan Auditorium there is a selection criteria, a problem is given. the problem states a string is to be compressed when two or more consecutive characte...
["#include<sdg.h>\nfor _ in range(int(input())):\n s=input()\n n=len(s)\n if n==1:\n if s[0].isalpha(): print(\"-32\")\n else: print(0)\n else:\n num,ch=0,0\n p,q=0,0\n c=1\n x=s[0]\n ans=\"\"\n for i in range(1,n):\n if s[i-1]==s[i]:\n ...
{"inputs": [["1", "aaabb"]], "outputs": [["-40"]]}
INTERVIEW
PYTHON3
CODECHEF
14,656
d3f47586aa3538d20c1e09441c85e61f
UNKNOWN
Given an Array of length $N$ containing elements $Ai$ ( i = 1 to n ) . You have to handle $Q$ queries on this array . Each Query is of two types k=(1 or 2). Type 1:- $k$ $l$ $r$ in which you have to tell whether the product of numbers in range l to r results in a perfect square or not. if product of numbers in range...
["def update(index, value, bi_tree):\n while index < len(bi_tree):\n bi_tree[index] += value\n index += index & -index\n\n\ndef get_sum(index, bi_tree):\n ans = 0\n while index > 0:\n ans += bi_tree[index]\n index -= index & -index\n\n return ans\n\n\ndef get_range_sum(left, right, bi_tree):\n ans = get_sum(right, ...
{"inputs": [["4", "2 2 3 4", "4", "1 1 2", "1 3 4", "2 3 3", "1 1 4"]], "outputs": [["YES", "NO", "YES"]]}
INTERVIEW
PYTHON3
CODECHEF
1,131
1a606a3bc75555fbc61de8d1722960d9
UNKNOWN
Recently in JEC ants have become huge, the Principal is on a journey to snipe them !! Principal has limited $N$ practice Bullets to practice so that he can be sure to kill ants. - The Practice ground has max length $L$. - There is a Limit X such that if the bullet is fired beyond this, it will destroy and it wont be of...
["# cook your dish here\n\nfrom sys import stdin,stdout\nfrom collections import deque,defaultdict\nfrom math import ceil,floor,inf,sqrt,factorial,gcd,log\nfrom copy import deepcopy\nii1=lambda:int(stdin.readline().strip())\nis1=lambda:stdin.readline().strip()\niia=lambda:list(map(int,stdin.readline().strip().split()))...
{"inputs": [["2", "1 10", "2 10"]], "outputs": [["10", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
6,204
836aacd6d510158ba409a322b600d612
UNKNOWN
Given an integer N. Integers A and B are chosen randomly in the range [1..N]. Calculate the probability that the Greatest Common Divisor(GCD) of A and B equals to B. -----Input----- The first line of the input contains an integer T denoting the number of test cases. The description of T test cases follows. Each test c...
["import math\nfor _ in range(int(input())):\n n=int(input())\n s=int(math.sqrt(n))\n ans=0\n for i in range(1,s+1):\n ans+=(n//i)\n ans=ans*2-(s*s)\n g=math.gcd(n*n,ans)\n print(str(ans//g)+\"/\"+str(n*n//g)) ", "from collections import defaultdict\nimport sys\nimport math as m\nimport random as rd\nimport bisect as ...
{"inputs": [["3", "1", "2", "3"]], "outputs": [["1/1", "3/4", "5/9"]]}
INTERVIEW
PYTHON3
CODECHEF
2,592
c8022aff577fb955ddb73dccbae51d31
UNKNOWN
The median of a sequence is the element in the middle of the sequence after it is sorted. For a sequence with even size, the median is the average of the two middle elements of the sequence after sorting. For example, for a sequence $A = [1, 3, 3, 5, 4, 7, 11]$, the median is equal to $4$, and for $A = [2, 3, 4, 5]$, t...
["# cook your dish here\n# cook your dish here\nimport numpy as np\nimport sys\n\ndef findSeq(n, s, k, m, M):\n midInd = n // 2\n seqs = []\n for ind in range(midInd + 2, midInd - 3, -1):\n if ind >= n or ind < 0:\n continue \n seq = genBestSeq(n, ind, m, M, s)\n if seq is n...
{"inputs": [["2", "3 6 1 1 5", "4 4 2 1 3", ""]], "outputs": [["1 1 4", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
19,124
e4307da7b5ae872452ed840363efbba5
UNKNOWN
Shashank is playing a game with his friends. There are n sticks located in a row at points $a_1,a_2, ...,a_n$. Each stick has a height- $h_i$. A person can chop a stick down, after which it takes over one of the regions [$a_i$ - $h_i$, $a_i$] or [$a_i$, $a_i$ + $h_i$]. The stick that is not chopped remains at the point...
["# cook your dish here\nn=int(input())\ncounts=dict()\nz=0\nupper=None\nfor i in range(0,n):\n a,h= [int(num) for num in input().split()]\n counts[a]=h\nfor key,count in counts.items():\n c=0\n x=key-count\n y=key+count\n c1=0\n c2=0\n for j in counts.keys():\n if j==key:\n continue\n else:\n if x<=j<=key:\n ...
{"inputs": [["5", "1 2", "2 1", "5 10", "10 9", "19 1", "Sample Input 2:", "5", "1 2", "2 1", "5 10", "10 9", "20 1"]], "outputs": [["3", "Sample Output 2:", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
16,547
cfbc27c1b216dda6841e6eaa7a6b914e
UNKNOWN
To help Lavanya learn all about binary numbers and binary sequences, her father has bought her a collection of square tiles, each of which has either a 0 or a 1 written on it. Her brother Nikhil has played a rather nasty prank. He has glued together pairs of tiles with 0 written on them. Lavanya now has square tiles wi...
["n=int(input())\nmodulo=15746\nnum=[1,1]\nfor i in range(2,n+1):\n num.append((num[i-1]+num[i-2])%modulo)\nprint(num[n])", "def EXEC(n):\r\n if n < 3: return n\r\n else:\r\n x, y = 1, 2\r\n for _ in range(2, n):\r\n z = (x + y) % 15746\r\n x, y = y, z\r\n return y % ...
{"inputs": [["4"]], "outputs": [["5"]]}
INTERVIEW
PYTHON3
CODECHEF
2,329
9aa1ff9c7a9b31c162bca56de8c5374d
UNKNOWN
The chef is playing a game of long distance. Chef has a number K and he wants to find the longest distance between the index of the first and the last occurrence of K in a given array of N numbers. -----Input:----- - First-line will contain $T$, the number of test cases. Then the test cases follow. - Each test case c...
["# cook your dish here\nfor _ in range(int(input())):\n m,n=list(map(int,input().split()))\n a=[int(i) for i in input().split()]\n l=-1\n for i in range(n-1,-1,-1):\n if a[i]==m:\n l=i\n break\n f=-1\n for i in range(0,n):\n if a[i]==m:\n f=i\n ...
{"inputs": [["2", "2 6", "2 3 4 2 1 6", "4 6", "2 3 4 2 1 6"]], "outputs": [["3", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
3,482
6b94b63ef40ecd0ba43a3634abedbef4
UNKNOWN
Vasya's older brother, Petya, attends an algorithm course in his school. Today he learned about matchings in graphs. Formally, a set of edges in a graph is called a matching if no pair of distinct edges in the set shares a common endpoint. Petya instantly came up with an inverse concept, an antimatching. In an antimatc...
["def detect_triangle(adj): \n for x in range(len(adj)):\n for y in adj[x]:\n if not set(adj[x]).isdisjoint(adj[y]):\n return True\n\n \nfor _ in range(int(input())):\n n,m=list(map(int,input().split()))\n graph=[[] for i in range(n)]\n for i in range(m):\n u,v=list(map(int,input().split(...
{"inputs": [["3", "3 3", "1 2", "1 3", "2 3", "4 2", "1 2", "3 4", "5 0"]], "outputs": [["3", "1", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
2,979
454db7c33a5976ae5fde2997905fe196
UNKNOWN
Chef got in the trouble! He is the king of Chefland and Chessland. There is one queen in Chefland and one queen in Chessland and they both want a relationship with him. Chef is standing before a difficult choice… Chessland may be considered a chessboard with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered...
["def C(n):\n return n*(n-1)//2\n\n\ndef sol():\n equal, mini = False, min(N,M)\n total_ways = 2*C(N * M)\n if N==M:\n equal = True\n ways = 0\n if not equal:\n ways = (N*C(M)+M*C(N))\n diag = 0\n for i in range(2, mini+1):\n diag += 2*C(i)\n for i in range(mini+1,max(N,M)):\n diag += C(mini)\n diag *= 2\n w...
{"inputs": [["2", "3 3 2 2", "4 4 2 3"]], "outputs": [["24", "94"]]}
INTERVIEW
PYTHON3
CODECHEF
3,259
26ac5951eecc0558de4dbf241c860a0b
UNKNOWN
2021 was approaching and the world was about to end. So 2 gods Saurabhx and Saurabhy (from Celesta) created the Cyberverse. But this time disappointed with humans both the gods decided not to have humans in this world. So they created a world of cyborgs. A world without humans. Isn’t it interesting? So let us dive into...
["# cook your dish here\nt=int(input())\nfor i in range(t):\n (n,k)=tuple(map(int,input().split()))\n print(k//n)", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n n,k=map(int,input().split())\n print(k//n)", "# cook your dish here\nt=int(input())\nfor i in range(0,t):\n s=input().split(\" \")\n k=list(map...
{"inputs": [["1", "5 8"]], "outputs": [["1"]]}
INTERVIEW
PYTHON3
CODECHEF
3,126
23dc1dec94f19037b403ceeccd854435
UNKNOWN
Zonal Computing Olympiad 2015, 29 Nov 2014 We say that two integers x and y have a variation of at least K, if |x − y| ≥ K (the absolute value of their difference is at least K). Given a sequence of N integers a1,a2,...,aN and K, the total variation count is the number of pairs of elements in the sequence with variati...
["n,k=[int(x) for x in input().split()]\r\na=[int(x) for x in input().split()]\r\nans=0\r\nfor i in range(n-1):\r\n for j in range(i+1,n):\r\n if(abs(a[i]-a[j])>=k):\r\n ans+=1\r\nprint(ans)\r\n", "n,k=map(int,input().split())\na=list(map(int,input().split()))\na.sort()\ni=0\ns=0\nfor j in range(0,...
{"inputs": [["3 1", "3 1 3"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
7,653
67cbc96175663aca8abc7d6e914c2567
UNKNOWN
Sebi goes to school daily with his father. They cross a big highway in the car to reach to the school. Sebi sits in front seat beside his father at driving seat. To kill boredom, they play a game of guessing speed of other cars on the highway. Sebi makes a guess of other car's speed being SG kph, his father FG kph. T...
["# cook your dish here\nn=int(input())\nfor i in range(n):\n S, SG, FG, D, T = map(int, input().split())\n speed = (D*180)/T + S\n if abs(SG-speed) == abs(FG-speed):\n print('DRAW')\n elif abs(SG-speed) > abs(FG-speed):\n print('FATHER')\n else:\n print('SEBI')", "# cook your dish h...
{"inputs": [["2", "100 180 200 20 60", "130 131 132 1 72", "", ""]], "outputs": [["SEBI", "FATHER"]]}
INTERVIEW
PYTHON3
CODECHEF
6,493
a0e68d2a4270bebd628b25054d93ba11
UNKNOWN
Bob has got some injury in his leg and due to this he can take exactly M steps in one move. Bob enters a square field of size NxN. The field is only having one gate(for both entrance and exit) at its one of the corners. Bob started walking along the perimeter of square field.(remember Bob can only take exactly M steps...
["# By Prathmesh Maurya\nt=eval(input())\nwhile(t!=0):\n t-=1\n n=eval(input())\n if n%2 == 0:\n print(n*4)\n elif n%4==3:\n print(n)\n else:\n print(n*2)\n", "t = eval(input())\n\ndef gcd(a, b):\n while b:\n t = a % b\n a, b = b, t\n return a\n\nfor i in range(t):\n n = eval(input())\n m = n + 1\n k = n * 4\n g =...
{"inputs": [["2", "1", "2"]], "outputs": [["2", "8"]]}
INTERVIEW
PYTHON3
CODECHEF
2,208
79fc705bad4eb37d5b0bbeae2253e897
UNKNOWN
Chef has a sequence of positive integers $A_1, A_2, \ldots, A_N$. He wants to choose some elements of this sequence (possibly none or all of them) and compute their MEX, i.e. the smallest positive integer which does not occur among the chosen elements. For example, the MEX of $[1, 2, 4]$ is $3$. Help Chef find the larg...
[" \r\nfor __ in range(int(input())):\r\n n,m=map(int,input().split())\r\n arr=list(map(int,input().split()))\r\n s=set(arr)\r\n mex=-1\r\n ele=1\r\n for i in range(1,n+1):\r\n if i not in s:\r\n mex = i\r\n break\r\n if m>mex:\r\n print(-1)\r\n elif m==mex...
{"inputs": [["1", "3 3", "1 2 4", ""]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
12,855
7d28e5a350f25edfafdfb80aaf9506ca
UNKNOWN
"Humankind cannot gain anything without first giving something in return. To obtain, something of equal value must be lost. That is alchemy's first law of Equivalent Exchange. In those days, we really believed that to be the world's one, and only truth." -- Alphonse Elric Now, here we have an equivalent exchange law fo...
["for i in range(int(input())):\n n = int(input())\n c = list(map(int, input().split()))\n d = {}\n d[0] = -1\n parity = 0\n ans = 0\n for i in range(n):\n parity ^= 1 << (c[i]-1)\n for t in range(30):\n x = parity^(1<<t)\n if(x in d.keys()):\n ans = max(ans, i - d[x])\n ...
{"inputs": [["4", "14", "5 4 2 2 3 2 1 3 2 7 4 9 9 9", "3", "1 2 1", "3", "1 1 1", "5", "1 2 3 4 1"]], "outputs": [["3", "1", "1", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
4,804
6b94b3c2b2458a87514acddd02824c41
UNKNOWN
Chef has just finished the construction of his new garden. He has sown the garden with patches of the most beautiful carpet grass he could find. He has filled it with patches of different color and now he wants to evaluate how elegant his garden is. Chef's garden looks like a rectangular grid of cells with N rows and M...
["# cook your dish here\nimport sys\nimport math\n\ndef main(grid):\n ans=0\n for i in range(len(grid)):\n for j in range(len(grid[0])):\n first_point=grid[i][j]\n for k in range(j+1,len(grid[0])):\n second_point=grid[i][k]\n if first_point==second_point:...
{"inputs": [["3", "2 2", "aa", "aA", "3 3", "aba", "bab", "aba", "4 4", "aabb", "aabb", "bbaa", "bbaa", "", ""]], "outputs": [["0", "1", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
3,920
b344bd988548869907ab14c12fce8409
UNKNOWN
Ram and Shyam are playing a game of Truth and Dare. In this game, Shyam will ask Ram to perform tasks of two types: - Truth task: Ram has to truthfully answer a question. - Dare task: Ram has to perform a given task. Each task is described by an integer. (If a truth task and a dare task are described by the same intege...
["# cook your dish here\nfor _ in range(int(input())):\n tr=int(input())\n trl=list(map(int,input().split()))\n dr = int(input())\n drl = list(map(int, input().split()))\n ts = int(input())\n tsl = list(map(int, input().split()))\n ds = int(input())\n dsl = list(map(int, input().split()))\n f...
{"inputs": [["4", "2", "1 2", "3", "1 3 2", "1", "2", "2", "3 2", "2", "1 2", "3", "1 3 2", "1", "2", "3", "3 2 4", "3", "3 2 5", "2", "2 100", "1", "2", "1", "100", "2", "1 2", "3", "1 3 2", "1", "2", "3", "3 2 2", ""]], "outputs": [["yes", "no", "yes", "yes"]]}
INTERVIEW
PYTHON3
CODECHEF
16,163
d0ee3a020d4f9cfd829227d9d715914d
UNKNOWN
An encoder encodes the first $16$ lowercase English letters using $4$ bits each. The first bit (from the left) of the code is $0$ if the letter lies among the first $8$ letters, else it is $1$, signifying that it lies among the last $8$ letters. The second bit of the code is $0$ if the letter lies among the first $4$ l...
["# cook your dish here\ndef decode(L,S):\n str_2=\"\"\n lst=[]\n for i in range(L//4):\n str_1 = \"abcdefghijklmnop\"\n S_1=S[(i*4):(4*(i+1))]\n for j in range(4):\n if(S_1[j]==\"1\"):\n str_1=str_1[len(str_1)//2:len(str_1)]\n else:\n str_1 = str_1[0:len(str_1) // 2]\n str_2=str_2+str_1\n print(str_2)\n\...
{"inputs": [["3", "4", "0000", "8", "00001111", "4", "1001"]], "outputs": [["a", "ap", "j"]]}
INTERVIEW
PYTHON3
CODECHEF
7,990
a61e80a517cd34f4039cc226ab665a4c
UNKNOWN
Chef wants to serve mankind by making people immortal by preparing a dish, a dish of life - a dish with the best taste in the universe, one with the smell and splash of fresh water flowing down the springs of the mountain, one with the smell of the best lily flowers of the garden, one that has contained the very essenc...
["for _ in range(int(input())):\n n,k = list(map(int,input().split()))\n array = []\n tot = []\n for _ in range(n):\n temp = list(map(int,input().split()))\n aa = temp[0]\n del(temp[0])\n temp.sort()\n temp.insert(0,aa)\n array.append(temp)\n dic = {}\n array.sort(reverse=True)\n for i in array:\n del(i[0])\n fo...
{"inputs": [["3", "3 4", "3 1 2 3", "2 1 3", "2 1 2", "2 3", "3 1 2 3", "2 1 3", "2 3", "2 1 2", "2 1 3"]], "outputs": [["sad", "some", "all"]]}
INTERVIEW
PYTHON3
CODECHEF
3,038
4c0bad2dd8066126e6c1bfa51b338e4a
UNKNOWN
Motu and Patlu are playing with a Magical Ball. Patlu find some interesting pattern in the motion of the ball that ball always bounce back from the ground after travelling a linear distance whose value is some power of $2$. Patlu gave Motu total distance $D$ travelled by the ball and ask him to calculate the minimum nu...
["# cook your dish here\r\ntest=int(input())\r\nfor _ in range(test):\r\n n=int(input())\r\n n=list(bin(n))\r\n ans=n.count('1')\r\n print(ans-1)", "# cook your dish here\nt=int(input())\nfor i in range(t):\n n=int(input())\n binary=bin(n)\n setb=[ones for ones in binary[2:] if ones=='1']\n prin...
{"inputs": [["1", "13"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
6,800
99f24491321b5bb9201a0b9178a2aaf5
UNKNOWN
Two players are playing a game. The game is played on a sequence of positive integer pairs. The players make their moves alternatively. During his move the player chooses a pair and decreases the larger integer in the pair by a positive multiple of the smaller integer in the pair in such a way that both integers in the...
["import sys\n\nt = int(input())\n\ndef g(a,b):\n if (a > b):\n tmp = a\n a = b\n b = tmp\n if (b == a):\n return 0\n if (b % a == 0):\n return int(b/a)-1\n r = g(b%a,a)\n q = int(b/a)\n if (r >= q):\n return q-1\n else:\n return q\n\ndef mex(x):\n n = len(list(x.keys()))\n for i in range(n):\n if (i not in x):...
{"inputs": [["3", "1", "2 3", "2", "4 5", "5 6", "2", "2 3", "3 5"]], "outputs": [["NO", "NO", "YES"]]}
INTERVIEW
PYTHON3
CODECHEF
898
54f17b59bcf1c8cd30aa3aafea7f711c
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\nfor i in range(int(input())):\n n=int(input())\n p=1\n l=n-1\n for j in range(n):\n for k in range(l):\n print(\" \",end='')\n for k in range(p):\n print(\"*\",end='')\n print()\n for k in range(l):\n print(\" \",end='')\n...
{"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["*", "*", "*", "*", "***", "***", "*", "*", "***", "***", "*****", "*****", "*", "*", "***", "***", "*****", "*****", "*******", "*******"]]}
INTERVIEW
PYTHON3
CODECHEF
2,859
39c7d2800107f6fa85602aa4eacf88ee
UNKNOWN
In a fictitious city of CODASLAM there were many skyscrapers. The mayor of the city decided to make the city beautiful and for this he decided to arrange the skyscrapers in descending order of their height, and the order must be strictly decreasing but he also didn’t want to waste much money so he decided to get the mi...
["import sys\n \nnum=int(sys.stdin.readline())\ns=sys.stdin.readline().split()\nsky=list(map(int,s))\nsky.reverse()\ncuts=0\nchange=0\nt=False\ni=1\n \nwhile i<len(sky):\n if sky[i]<=sky[i-1]:\n for j in range(i-1,-1,-1):\n \n if sky[j]<=sky[i]-(i-j):\n break\n else:\n change+=sky[j]-(sky[i]-(i-j))\n \n...
{"inputs": [["5", "1 2 3 4 5"]], "outputs": [["8", "By:", "Chintan,Asad,Ashayam,Akanksha"]]}
INTERVIEW
PYTHON3
CODECHEF
1,678
b6d90b2a4da50323edca7ee16e6e0292
UNKNOWN
There is Chef and Chef’s Crush who are playing a game of numbers. Chef’s crush has a number $A$ and Chef has a number $B$. Now, Chef wants Chef’s crush to win the game always, since she is his crush. The game ends when the greatest value of A^B is reached after performing some number of operations (possibly zero), Wh...
["\ndef main():\n t = int(input())\n while (t):\n m, n = map(int, input().split())\n a , b= bin(m)[2:],bin(n)[2:]\n #print(a,b)\n max = m^n\n if len(a)>len(b):\n diff =len(a)-len(b)\n b= (\"0\"*diff)+b\n #print(b)\n elif len(a)<len(b):\n diff =len(b)-len(a)\n a= (\"0\"*diff)+a\n #print(a)\n ll = len(...
{"inputs": [["1", "4 5"]], "outputs": [["2 7"]]}
INTERVIEW
PYTHON3
CODECHEF
9,336
bf5a235dcc984bd82ebdbc1593200db3
UNKNOWN
Chef Tobby is playing a rapid fire with Bhuvan. He gives Bhuvan a string S and each time, Bhuvan has to guess whether there exists 2 equal subsequences in the string or not. Bhuvan got a perfect score in the game with Chef Tobby. However, Chef Tobby has now asked Bhuvan to write a program that will do this automaticall...
["t = int(input())\n\nfor _ in range(t):\n s = [x for x in input()]\n \n freq = {}\n \n for i in s:\n if i in freq:\n freq[i] += 1\n else:\n freq[i] = 1\n \n flag = 0\n \n for keys, values in freq.items():\n if(values >= 2):\n flag = 1\n break\n \n if(flag == 0):\n print(\"no\")\n else:\n print(\"yes\")", ...
{"inputs": [["4", "likecs", "venivedivici", "bhuvan", "codechef"]], "outputs": [["no", "yes", "no", "yes"]]}
INTERVIEW
PYTHON3
CODECHEF
4,747
5bd2bfec4904a2b8ea43afc9c2738c38
UNKNOWN
Chef has gone shopping with his 5-year old son. They have bought N items so far. The items are numbered from 1 to N, and the item i weighs Wi grams. Chef's son insists on helping his father in carrying the items. He wants his dad to give him a few items. Chef does not want to burden his son. But he won't stop botherin...
["def main():\n T = int(input())\n for t in range(T):\n N,K = map(int, input().split())\n W = list(map(int, input().split()))\n W.sort()\n if 2*K > N:\n K = N - K\n kid = sum(W[:K])\n dad = sum(W[K:])\n\n diff = dad - kid\n\n print(diff)\n\n\ndef __starting_point():\n main()\n__starting_point()", "# cook your...
{"inputs": [["2", "5 2", "8 4 5 2 10", "8 3", "1 1 1 1 1 1 1 1"]], "outputs": [["17", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
7,851
47ddd45f6b2ea7dde6f22e3e8c026bc8
UNKNOWN
Consider the following operations on a triple of integers. In one operation, you should: - Choose an integer $d$ and an arithmetic operation ― either addition or multiplication. - Choose a subset of elements of the triple. - Apply the arithmetic operation to each of the chosen elements, i.e. either add $d$ to each of t...
["def eq_solve(v0, v1, u0, u1):\r\n den = u0 - v0\r\n num = u1 - v1\r\n if den != 0:\r\n return num / den\r\n return 1\r\n \r\ndef solve(p, q, r, a, b, c, rs):\r\n if p == a and q == b and r == c:\r\n return rs\r\n if rs >= 2:\r\n return 3\r\n res = 3\r\n adds = [a - p, b - ...
{"inputs": [["2", "3 5 7", "6 5 10", "8 6 3", "9 7 8", ""]], "outputs": [["1", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
76,040
c404e8295424718589824a366f309b2d
UNKNOWN
Johnny was asked by his math teacher to compute nn (n to the power of n, where n is an integer), and has to read his answer out loud. This is a bit of a tiring task, since the result is probably an extremely large number, and would certainly keep Johnny occupied for a while if he were to do it honestly. But Johnny know...
["from math import log10\nfrom decimal import Decimal\ndef solve(n,k):\n \n mod=10**k\n x=Decimal(n)\n y=x*(x.log10())%1\n p=str(pow(10,y))\n c=0\n first=''\n for v in p:\n if c==k:\n break\n if v==\".\":\n continue\n first+=v\n c+=1\n last=str(pow(n,n,mod)).zfill(k)\n return (first,last)\nqueries=[]\nfor _ in ...
{"inputs": [["2", "4 2", "9 3"]], "outputs": [["25 56", "387 489"]]}
INTERVIEW
PYTHON3
CODECHEF
1,431
a495a766fca0036b79970bdb23d92a20
UNKNOWN
Sherlock Holmes has decided to start a new academy to some of the young lads. He has conducted several tests and finally selected N equally brilliant students.Now he don't know whether to train all the N students or not. Now since Holmes was in a confusion, Watson came up with an idea. He wanted to test the obedience...
["t = eval(input())\n\nfor i in range(t):\n n = eval(input())\n a = list(map(int, input().split()))\n cnt = 2\n cnt1 = 2\n ll = len(a)\n if ll < 3:\n cnt1 = ll\n else:\n for j in range(2,ll):\n if a[j-1] + a[j-2] == a[j]:\n cnt += 1\n cnt1 = max(cnt1, cnt)\n else:\n cnt1 = max(cnt1, cnt)\n cnt = 2\n p...
{"inputs": [["2", "5", "2 3 5 1 2", "3", "1 2 3"]], "outputs": [["3", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
5,372
9819135bcc160f88bbdb6b9b3b911343
UNKNOWN
A robot is initially at $(0,0)$ on the cartesian plane. It can move in 4 directions - up, down, left, right denoted by letter u, d, l, r respectively. More formally: - if the position of robot is $(x,y)$ then u makes it $(x,y+1)$ - if the position of robot is $(x,y)$ then l makes it $(x-1,y)$ - if the position of robot...
["\r\n\r\nz = int(input())\r\ni = 0\r\nwhile i < z:\r\n n = int(input())\r\n p = int(n**(0.5))\r\n if p*(p+1) < n:\r\n p += 1\r\n # print(\"P\", p)\r\n x, y = 0, 0\r\n q = 0\r\n flag = True\r\n if p*(p+1) == n:\r\n # print(\"Even steps, nice\")\r\n q = p\r\n else:\r\n # remaining steps\r\n q = p...
{"inputs": [["5", "1", "2", "3", "50", "12233443"]], "outputs": [["0 1", "-1 1", "-1 0", "2 4", "-1749 812"]]}
INTERVIEW
PYTHON3
CODECHEF
1,059
617e1ce131107df64e986e5b416c2542
UNKNOWN
Prof. Sergio Marquina is a mathematics teacher at the University of Spain. Whenever he comes across any good question(with complexity k), he gives that question to students within roll number range i and j. At the start of the semester he assigns a score of 10 to every student in his class if a student submits a questi...
["# cook your dish here\nfor t in range(int(input())):\n n,m=[int(x)for x in input().rstrip().split()]\n s=[]\n for p in range(n):\n s.append(10)\n for c in range(m):\n i,j,k=[int(x)for x in input().rstrip().split()]\n for q in range(i-1,j):\n s[q]=s[q]*k\n print(sum(s)//n)\n \n \n \n \n", "# cook your dish here...
{"inputs": [["1", "5 3", "1 3 5", "2 5 2", "3 4 7"]], "outputs": [["202"]]}
INTERVIEW
PYTHON3
CODECHEF
1,143
ac119ec051aa3127c6800c0c22749de1
UNKNOWN
The city of Siruseri is impeccably planned. The city is divided into a rectangular array of cells with $M$ rows and $N$ columns. Each cell has a metro station. There is one train running left to right and back along each row, and one running top to bottom and back along each column. Each trains starts at some time $T$ ...
["from queue import PriorityQueue\r\nm,n=list(map(int,input().split()))\r\nrr=[]\r\ncc=[]\r\nspeed={'S':3,'O':2,'F':1}\r\nvisited=set()\r\ndp=[]\r\n\r\ndef qwerty(cur,x,y,f):\r\n\tif f==0:\r\n\t\tgg=rr[x][1]+y*rr[x][0]\r\n\t\twhile gg<cur:\r\n\t\t\tgg+=(2*(n-1))*rr[x][0]\r\n\t\treturn gg-cur+rr[x][0]\r\n\telif f==1:\r\...
{"inputs": [["3 4", "F 3", "S 2", "O 2", "S 1", "F 2", "O 2", "F 4", "2 3 8 1 1"]], "outputs": [["15"]]}
INTERVIEW
PYTHON3
CODECHEF
1,773
af41cfba1f416652da63fc5fee733663
UNKNOWN
Taxis of Kharagpur are famous for making sharp turns. You are given the coordinates where a particular taxi was on a 2-D planes at N different moments: (x1, y1), (x2, y2), ..., (xN, yN). In between these coordinates, the taxi moves on a straight line. A turn at the i-th (2 ≤ i ≤ N-1) coordinate is said to be a sharp tu...
["import math\nimport copy\ntry:\n import psyco\n psyco.full()\nexcept ImportError:\n pass\n \ndef isSharp(ang):\n return ang > math.pi/4 + 0.00001\n \ndef unitVector(p2, p1):\n d0 = p2[0] - p1[0]\n d1 = p2[1] - p1[1]\n d = math.sqrt(d0*d0 + d1*d1)\n if d != 0:\n return [d0/d, d1/d]\n return [0, 0]\n \ndef compVectors...
{"inputs": [["5", "3", "0 0", "1 1", "2 1", "3", "0 0", "1 0", "6 1", "3", "0 0", "1 0", "1 1", "4", "0 0", "1 0", "1 1", "6 1", "6", "0 0", "1 0", "1 1", "2 1", "2 2", "3 2"]], "outputs": [["yes yes", "yes yes", "no yes", "no yes", "no no"]]}
INTERVIEW
PYTHON3
CODECHEF
4,768
166496f202e1cd356c806b5fe522e98a
UNKNOWN
Chef is the judge of a competition. There are two players participating in this competition — Alice and Bob. The competition consists of N races. For each i (1 ≤ i ≤ N), Alice finished the i-th race in Ai minutes, while Bob finished it in Bi minutes. The player with the smallest sum of finish times wins. If this total ...
["# cook your dish here\nfor i in range(int(input())):\n N=int(input())\n ALICE=list(map(int,input().split()))\n BOB=list(map(int,input().split()))\n ALICE[ALICE.index(max(ALICE))]=0\n BOB[BOB.index(max(BOB))]=0\n if sum(ALICE)<sum(BOB):\n print(\"Alice\")\n elif sum(BOB)<sum(ALICE):\n print(\"Bob\")\n else:\n print...
{"inputs": [["3", "5", "3 1 3 3 4", "1 6 2 5 3", "5", "1 6 2 5 3", "3 1 3 3 4", "3", "4 1 3", "2 2 7"]], "outputs": [["Alice", "Bob", "Draw"]]}
INTERVIEW
PYTHON3
CODECHEF
7,423
3d3ba4481811be4d1731687cd7822945
UNKNOWN
This time minions are celebrating Diwali Festival. There are N minions in total. Each of them owns a house. On this Festival, Each of them wants to decorate their house. But none of them have enough money to do that. One of the minion, Kevin, requested Gru for money. Gru agreed for money distribution but he will be giv...
["def find_combinations(list, sum):\n if not list:\n if sum == 0:\n return [[]]\n return []\n return find_combinations(list[1:], sum) + \\\n [[list[0]] + tail for tail in\n find_combinations(list[1:], sum - list[0])]\nfor tc in range(int(input())):\n n,k=list(map(int,input().split()))\n a=list(map(int,input().sp...
{"inputs": [["2", "4 9", "5 2 2 4", "4 9", "5 2 18 3"]], "outputs": [["YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
852
7965989be01f11173998a6fa29278af5
UNKNOWN
Chef loves to play chess, so he bought a new chessboard with width M$M$ and height N$N$ recently. Chef considers a chessboard correct if its width (number of columns) is equal to its height (number of rows) and each cell has no side-adjacent cell of the same color (this is the so-called "chess order" which you can see ...
["# cook your dish here\nn,m=map(int,input().split())\nL=[]\nfor i in range(n):\n s=input()\n L.append(s)\n\ncost=[]\nh2=[0]*(m+1)\ncost.append(h2)\nfor i in range(n):\n h=[0]\n for j in range(m):\n if(L[i][j]=='0' and (i+j)%2!=0):\n h.append(1)\n elif(L[i][j]=='1' and (i+j)%2==0):\...
{"inputs": [["8 8", "00101010", "00010101", "10101010", "01010101", "10101010", "01010101", "10101010", "01010101", "4", "1 2 0 1001"]], "outputs": [["7", "8", "6", "8"]]}
INTERVIEW
PYTHON3
CODECHEF
13,773
ead56553e782574f944a71d31392cbff
UNKNOWN
The land of Programmers Army is surrounded by many islands. A unique number is associated with each island. The king of the islands is a very generous person, he donates a certain amount of gold coins to travelers for visiting each island that they visited to. Now, you are appointed as a traveler, who will travel to al...
["# cook your dish here\nfor i in range(int(input())):\n N = int(input())\n l = list(map(int, input().split()))\n for j in range(int(input())):\n q1, q2 = map(int, input().split())\n temp = l[q1 - 1 : q2]\n print(sum(temp))", "# cook your dish here\nfor _ in range(int(input())):\n n...
{"inputs": [["1", "4", "10 2 5 50", "2", "1 3", "2 4"]], "outputs": [["17", "57"]]}
INTERVIEW
PYTHON3
CODECHEF
8,813
5120d67b7482c0ad0edced8aa1c128bb
UNKNOWN
-----Coal Company ----- The Tunisian Coal Mining company uses a train to ferry out coal blocks from its coal mines. The train has N containers numbered from 1 to N which need to be filled with blocks of coal. Assume there are infinite coal blocks. The containers are arranged in increasing order of capacity, and the i...
["for _ in range(int(input())):\n n,k=list(map(int,input().split()))\n c=list(map(int,input().split()))\n count=1\n for i in range(n):\n if i+1<n:\n if c[i]-c[i+1]>=k or c[i+1]-c[i]>=k:\n continue\n else:\n count+=1\n c[i],c[i+1]=c[i+1],c[i]\n print(count)\n \n"]
{"inputs": [["2", "3 2", "5 4 7", "5 1", "5 3 4 5 6"]], "outputs": [["2", "1"]]}
INTERVIEW
PYTHON3
CODECHEF
280
be0a5dae02f65c3e2c573cafe5a2c8a0
UNKNOWN
"If you didn't copy assignments during your engineering course, did you even do engineering?" There are $Q$ students in Chef's class. Chef's teacher has given the students a simple assignment: Write a function that takes as arguments an array $A$ containing only unique elements and a number $X$ guaranteed to be present...
["def f(a,y,index,sorted_pos):\n #print(a,y,index,sorted_pos)\n n=len(a)\n low=0\n high=n-1\n L,R=0,0\n l,r=0,0\n while(low<=high):\n mid=(low+high)//2\n #print(low,high,mid)\n if(a[mid]== y):\n break\n elif(mid > index[y]):\n high=mid-1\n L+=1\n #print(\"L\")\n if(a[mid] <y):\n l+=1\n #print(\" l \...
{"inputs": [["1", "7 7", "3 1 6 7 2 5 4", "1", "2", "3", "4", "5", "6", "7"]], "outputs": [["0", "1", "1", "2", "1", "0", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
17,582
324c5dc9f871558c7c56fdbf119caa88
UNKNOWN
Chef likes strings a lot but he likes palindromic strings more. Today, Chef has two strings A and B, each consisting of lower case alphabets. Chef is eager to know whether it is possible to choose some non empty strings s1 and s2 where s1 is a substring of A, s2 is a substring of B such that s1 + s2 is a palindromic s...
["t=int(input())\nfor _ in range (t):\n str1=input()\n str2=input()\n res='No'\n for i in str1:\n if i in str2:\n res='Yes'\n break\n print(res)\n", "for _ in range(int(input())):\n str1=input()\n str2=input()\n res='No'\n for i in str1:\n if i in str2:\n res='Yes'\n break\n print(res)", "# cook your dish her...
{"inputs": [["3", "abc", "abc", "a", "b", "abba", "baab"]], "outputs": [["Yes", "No", "Yes"]]}
INTERVIEW
PYTHON3
CODECHEF
4,997
b1b31108634cb7d856da67c6bb1034eb
UNKNOWN
Chef's new hobby is painting, but he learned the fact that it's not easy to paint 2D pictures in a hard way, after wasting a lot of canvas paper, paint and of course time. From now on, he decided to paint 1D pictures only. Chef's canvas is N millimeters long and is initially all white. For simplicity, colors will be re...
["# cook your dish here\nimport sys\nimport math\n\ndef main(arr):\n for i in range(1,len(arr)-1):\n if arr[i]==arr[i-1] and arr[i]==arr[i+1]:\n return \"Yes\"\n return \"No\"\n\ntest=int(input())\nfor _ in range(test):\n b=int(input())\n arr=list(map(int,input().split()))\n print(main(...
{"inputs": [["3", "4", "1 5 5 5", "4", "1 1 1 5", "3", "5 5 2", ""]], "outputs": [["Yes", "Yes", "No"]]}
INTERVIEW
PYTHON3
CODECHEF
9,088
5e824983f5b38933f880032b91f0aa21
UNKNOWN
Kefaa has developed a novel decomposition of a tree. He claims that this decomposition solves many difficult problems related to trees. However, he doesn't know how to find it quickly, so he asks you to help him. You are given a tree with $N$ vertices numbered $1$ through $N$. Let's denote an edge between vertices $u$ ...
["\ntest=int(input())\nfor t in range(test):\n n= int(input())\n\n adj=[[] for i in range(n+1)]\n\n for _ in range(n-1):\n a,b=list(map(int,input().split()))\n adj[a].append(b)\n adj[b].append(a)\n \n\n #print(adj)\n root=1\n q,s=[root],set([root])\n\n for x in q:\n adj[x]= [p for p in adj[x] if p not in s]\n q.ex...
{"inputs": [["2", "4", "1 2", "1 3", "1 4", "7", "1 2", "2 3", "1 4", "4 5", "1 6", "6 7"]], "outputs": [["YES", "1 2 3 4", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
1,995
a4ec6d67dbaa0d7f760ef923d0d264c0
UNKNOWN
Sandu, a teacher in Chefland introduced his students to a new sequence i.e. 0,1,0,1,2,0,1,2,3,0,1,2,3,4........ The Sequence starts from 0 and increases by one till $i$(initially i equals to 1), then repeat itself with $i$ changed to $i+1$ Students being curious about the sequence asks the Nth element of the sequence. ...
["from math import sqrt\n\nfor _ in range(int(input())):\n n = int(input())\n\n x = int(sqrt(2 * n))\n\n while x * (x+1) // 2 <= n:\n x += 1\n\n while x * (x+1) // 2 > n:\n x -= 1\n\n n -= x * (x+1) // 2\n\n print(n)\n", "\"\"\"\nProblem Statement: https://www.codechef.com/ENCD2020/problems/ECAPR203\nAuthor: striker\...
{"inputs": [["5", "8", "9", "20", "32", "109"]], "outputs": [["2", "3", "5", "4", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
5,760
3b7da0e21b175c0af906905896fe99ce
UNKNOWN
Ayu loves distinct letter sequences ,a distinct letter sequence is defined by a sequence of small case english alphabets such that no character appears more then once. But however there are two phrases that she doesn't like these phrases are "kar" and "shi" and she is given a sequence of distinct characters and she won...
["# cook your dish here\r\nfrom collections import deque, defaultdict\r\nfrom math import sqrt, ceil,factorial\r\nimport sys\r\nimport copy\r\ndef get_array(): return list(map(int, sys.stdin.readline().strip().split()))\r\ndef get_ints(): return map(int, sys.stdin.readline().strip().split())\r\ndef input(): return sys....
{"inputs": [["2", "karp", "abcd"]], "outputs": [["22", "24"]]}
INTERVIEW
PYTHON3
CODECHEF
1,497
a7ac4c70101c38241936f15fbeac854c
UNKNOWN
The chef has a recipe he wishes to use for his guests, but the recipe will make far more food than he can serve to the guests. The chef therefore would like to make a reduced version of the recipe which has the same ratios of ingredients, but makes less food. The chef, however, does not like fractions. The original rec...
["#! /usr/bin/env python\n\nfrom sys import stdin\nfrom functools import reduce\n\ndef gcd(a,b):\n\twhile b!=0:\n\t\ta,b=b,a%b\n\treturn a\n\t\ndef gcdl(l):\n\treturn reduce(gcd, l[1:],l[0])\n\ndef __starting_point():\n\tT=int(stdin.readline())\n\tfor case in range(T):\n\t\tnumbers=list(map(int, stdin.readline().split(...
{"inputs": [["3", "2 4 4", "3 2 3 4", "4 3 15 9 6", ""]], "outputs": [["1 1", "2 3 4", "1 5 3 2"]]}
INTERVIEW
PYTHON3
CODECHEF
464
9bcbd573b0904e482a7a7eb8f18b2a16
UNKNOWN
Today is Chef's birthday. His mom has surprised him with truly fruity gifts: 2 fruit baskets. The first basket contains N apples, and the second one contains M oranges. Chef likes apples and oranges very much but he likes them equally, and therefore, wants to have the minimum possible difference between the number of a...
["for _ in range(int(input())):\n a,o,g=map(int,input().split())\n while g>0:\n if a<o:\n a+=1\n g-=1\n elif o<a:\n o+=1\n g-=1\n else:\n break\n print(abs(a-o))", "# cook your dish here\ntest_case = int(input())\nfor i in range(test_case):\n apple ,orange ,coin = map(int,input().split())\n k = abs(apple -...
{"inputs": [["3", "3 4 1", "5 2 1", "3 4 3"]], "outputs": [["0", "2", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
4,658
23280361291787657f4a9124a344f7c5
UNKNOWN
After acquiring an extraordinary amount of knowledge through programming contests, Malvika decided to harness her expertise to train the next generation of Indian programmers. So, she decided to hold a programming camp. In the camp, she held a discussion session for n members (n-1 students, and herself). They are sitti...
["for _ in range(int(input())):\n n,m=map(int, input().split())\n if n==1:\n print(0)\n elif n==2:\n print(m)\n else:\n print(m*2+n-3)", "# cook your dish here\nfor i in range(int(input())):\n n,m=list(map(int,input().split()))\n if(n==1):\n print(0)\n continue\n if(n==2):\n print(m)\n continue\n ans=(n-1)+2*(m-...
{"inputs": [["2", "2 1", "3 2"]], "outputs": [["1", "4"]]}
INTERVIEW
PYTHON3
CODECHEF
951
5d47b3882a803cac37f16067d7ef17c2
UNKNOWN
Find out the maximum sub-array of non negative numbers from an array. The sub-array should be continuous. That is, a sub-array created by choosing the second and fourth element and skipping the third element is invalid. Maximum sub-array is defined in terms of the sum of the elements in the sub-array. Sub-array A is...
["for t in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n s=0\n l=[]\n for i in range(n):\n if (a[i]<0):\n e=i\n ss=sum(a[s:e])\n l.append((ss,e-s,n-s))\n s=i+1\n e=n\n ss=sum(a[s:e])\n l.append((ss,e-s,n-s))\n x=max(l)\n s=n-x[2]\n e=x[1]+s\n for i in range(s,e):\n print(a[i], end...
{"inputs": [["1", "6", "1 2 5 -7 2 3"]], "outputs": [["1 2 5"]]}
INTERVIEW
PYTHON3
CODECHEF
341
57e690aa51999fd187b4c3e834b4bf88
UNKNOWN
Chef found a strange string yesterday - a string of signs s, where each sign is either a '<', '=' or a '>'. Let N be the length of this string. Chef wants to insert N + 1 positive integers into this sequence and make it valid. A valid sequence is a sequence where every sign is preceded and followed by an integer, and t...
["for _ in range(int(input())):\n st=input().replace(\"=\",\"\")\n if not len(st):print(1)\n else:\n cu=mx=1\n for j in range(1,len(st)):\n if st[j]==st[j-1]:cu+=1\n else:mx=max(mx,cu);cu=1\n print(max(mx+1,cu+1))\n", "r=int(input())\nfor z in range(r):\n s=input()\n s=s.replace('=','')\n l=list(s)\n final=0\n a...
{"inputs": [["4", "<<<", "<><", "<=>", "<=<"]], "outputs": [["4", "2", "2", "3"]]}
INTERVIEW
PYTHON3
CODECHEF
7,711
f45801f89c02c42f37a9ab3f5f8a1e47
UNKNOWN
You came across this story while reading a book. Long a ago when the modern entertainment systems did not exist people used to go to watch plays in theaters, where people would perform live in front of an audience. There was a beautiful actress who had a disability she could not pronounce the character $'r'$. To win he...
["for _ in range(int(input())):\r\n S = input()\r\n n = len(S)\r\n a = n - S.count('a')\r\n print(2 ** n - 2 ** a)", "for _ in range(int(input())):\n s=input()\n n=len(s)\n c=s.count('a')\n l=n-c\n print(pow(2,n)-pow(2,l))\n\n", "for _ in range(int(input())):\n s=input()\n n=len(s)\n ...
{"inputs": [["2", "abc", "aba"]], "outputs": [["4", "6"]]}
INTERVIEW
PYTHON3
CODECHEF
4,133
69c84e3586a6ca4d1eeb928675793992
UNKNOWN
Not everyone probably knows that Chef has younder brother Jeff. Currently Jeff learns to read. He knows some subset of the letter of Latin alphabet. In order to help Jeff to study, Chef gave him a book with the text consisting of N words. Jeff can read a word iff it consists only of the letters he knows. Now Chef is cu...
["knows=input()\nn=eval(input())\nwhile n!=0:\n n=n-1\n word=input()\n for x in word:\n ctr=0\n for y in knows:\n if x==y:ctr=ctr+1;break\n if ctr==0:print('No');break\n else: print('Yes')", "import collections\n\ndef alphabet():\n s = input()\n d = collections.defaultdict(lambda : 0)\n for i in s:\n d[i]+=1\n n ...
{"inputs": [["act", "2", "cat", "dog"]], "outputs": [["Yes", "No"]]}
INTERVIEW
PYTHON3
CODECHEF
4,775
ca1e568c157042d2a67c91b764d9aa3b
UNKNOWN
Chef has a calculator which has two screens and two buttons. Initially, each screen shows the number zero. Pressing the first button increments the number on the first screen by 1, and each click of the first button consumes 1 unit of energy. Pressing the second button increases the number on the second screen by the n...
["# cook your dish here\nfor i in range(int(input())):\n n,b=map(int,input().split())\n ans=round(n/(2*b))*(n-b*round((n/(2*b))));\n print(ans)", "import math\nn=int(input())\nfor i in range(n):\n a,b=list(map(int,input().split()))\n if a>b:\n a1=math.ceil(a/(2*b))\n b1=a-a1*b\n a2=math.floor(a/(2*b))\n b2=a-a2*b\n...
{"inputs": [["3", "10 2", "8 5", "6 1"]], "outputs": [["12", "3", "9"]]}
INTERVIEW
PYTHON3
CODECHEF
4,129
2dab08a1c24aa8d9e1ff58ee2e34672e
UNKNOWN
Chef has a circular sequence $A$ of $N$ non-negative integers $A_1, A_2, \ldots, A_N$ where $A_i$ and $A_{i+1}$ are considered adjacent, and elements $A_1$ and $A_N$ are considered adjacent. An operation on position $p$ in array $A$ is defined as replacing $A_p$ by the bitwise OR of elements adjacent to $A_p$. Formally...
["t=int(input())\ndef check():\n pref = [0]*n\n pref[0]=a[0]\n suff = [0]*n\n suff[-1]=a[-1]\n for i in range (1,n):\n pref[i] = pref[i-1]|a[i]\n suff[n-i-1] = suff[n-i]|a[n-i-1]\n if suff[1]==k:\n return 0\n elif pref[n-2]==k:\n return n-1\n else:\n for i in r...
{"inputs": [["5", "3 6", "2 1 6", "3 6", "2 1 5", "3 7", "2 4 6", "3 7", "1 2 4", "3 7", "1 2 6"]], "outputs": [["2 1 3", "-1", "-1", "-1", "2 3 1"]]}
INTERVIEW
PYTHON3
CODECHEF
9,092
a2bebfb98e48b43da636716f639f8ebb
UNKNOWN
The chef is trying to decode 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 li...
["from sys import stdin, stdout\nfrom math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log\nfrom collections import defaultdict as dd, deque\nfrom heapq import merge, heapify, heappop, heappush, nsmallest\nfrom bisect import bisect_left as bl, bisect_right as br, bisect\nmod = pow(10, 9) + 7\nmod2 = 998244353\...
{"inputs": [["4", "1", "3", "5", "7"]], "outputs": [["1", "111", "111", "111", "11111", "11 11", "1 1 1", "11 11", "11111", "1111111", "11 11", "1 1 1 1", "1 1 1", "1 1 1 1", "11 11", "1111111"]]}
INTERVIEW
PYTHON3
CODECHEF
1,659
f080afea8556628d4020028dbcc3f4ea
UNKNOWN
Humpy, the little elephant, has his birthday coming up. He invited all his cousins but doesn’t know how many of them are really coming as some of them are having exams coming up. He will only get to know how many of them are coming on the day of his birthday. He ordered sugarcane for his party, of length L. Humpy’s m...
["# your code goes here\nfrom sys import stdin, stdout\nn = int(stdin.readline())\nwhile n:\n n -= 1\n k, l, e = map(int, stdin.readline().strip().split(' '))\n a = map(int, stdin.readline().strip().split(' '))\n x = float(l) / float(e + sum(a))\n if x - int(x):\n stdout.write(\"NO\\n\")\n else:\n stdout.write(\"YES\...
{"inputs": [["2", "4 10 2", "2 2 3 1", "4 12 3", "6 5 7 3"]], "outputs": [["YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
1,543
c4d22849b389c122b9e18922a0e73e36
UNKNOWN
You may have tried your level best to help Chef but Dr Doof has managed to come up with his masterplan in the meantime. Sadly, you have to help Chef once again. Dr Doof has designed a parenthesis-inator. It throws a stream of $N$ brackets at the target, $1$ bracket per second. The brackets can either be opening or clos...
["import sys\nimport bisect as bi\nimport math\nfrom collections import defaultdict as dd\ninput=sys.stdin.readline\n##sys.setrecursionlimit(10**7)\ndef cin():\n return list(map(int,sin().split()))\ndef ain(): \n return list(map(int,sin().split()))\ndef sin():\n return input()\ndef inin():\n retu...
{"inputs": [["1", ")())((()", "3", "1 7 6"]], "outputs": [["3", "8", "-1"]]}
INTERVIEW
PYTHON3
CODECHEF
15,263
af35cb3838b6eea0e5cb36e65afbd8ca
UNKNOWN
Let's call a sequence good if the sum of all its elements is $0$. You have a sequence of integers $A_1, A_2, \ldots, A_N$. You may perform any number of operations on this sequence (including zero). In one operation, you should choose a valid index $i$ and decrease $A_i$ by $i$. Can you make the sequence good using the...
["n=int(input())\nfor i in range(n):\n t=int(input())\n m=list(map(int,input().split()))\n p,q=0,0\n if t==1:\n if m[0]>=0:\n print('YES')\n else:\n print('NO')\n else:\n for i in m:\n if i<0:\n q+=i\n else:\n p+=i\n if p>=abs(q):\n print('YES')\n else:\n print('NO')", "n=int(input())\nfor i in r...
{"inputs": [["2", "1", "-1", "2", "1 2"]], "outputs": [["NO", "YES"]]}
INTERVIEW
PYTHON3
CODECHEF
5,076
585653a9fbeb1b2e061848a5dd1313ea
UNKNOWN
Given a binary string $S$ consisting of only 1’s and 0’s where 1 represents a Square and 0 represents a Circle. The diameter of the circle and the side of the square must be any integer (obviously > 0) . You will have to perfectly inscribe (as shown in the example below) the respective geometric figure at $S$$i+1$ insi...
["for z in range(int(input())):\n s = input()\n n = len(s)\n i = 0\n while i<n and s[i]=='1':\n i+=1\n if i==0:\n print(0)\n else:\n k = 0\n while i<n and s[i]=='0':\n i+=1\n k+=1\n print(k)\n", "# cook your dish h\nfor _ in range(int(input())):...
{"inputs": [["3", "1110", "0010", "1001000"]], "outputs": [["1", "0", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
9,714
6093fad81f2e546a0906dd9f99db8951
UNKNOWN
You are an evil sorcerer at a round table with $N$ sorcerers (including yourself). You can cast $M$ spells which have distinct powers $p_1, p_2, \ldots, p_M$. You may perform the following operation any number of times (possibly zero): - Assign a living sorcerer to each positive integer cyclically to your left starting...
["import functools\n\ndef gcd(x,y):\n if(y == 0):\n return x\n return gcd(y, x%y)\n\nfor _ in range(int(input())):\n n, m= map(int, input().split())\n p = list(map(int, input().split()))\n \n ans = functools.reduce(lambda x,y: gcd(x, y), p)\n \n if(ans <= n):\n print(n-ans)\n else:\n f = [1]\n for k in range(ans//2...
{"inputs": [["5", "4 1", "5", "6 2", "2 4", "1 4", "7 16 8 29", "1000000000 1", "998244353", "1 1", "20201220"]], "outputs": [["3", "4", "0", "1755647", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
10,367
06f3361a9dbf31ef051dff02d723e0f4
UNKNOWN
Teacher Sungjae wanted to hold a programming competition for his students where every participant need to be included into team. The participants submitted their team names before the deadline. After the competition ran for half an hour, (It is assured that each registered team will submit absolutely once within half ...
["# cook your dish here\nfor t in range(int(input())):\n n,k=map(int,input().split())\n a=[]\n sr=[]\n for i in range(k):\n x,y=input().split()\n y=int(y)\n a.append([10**10-y,x])\n sr.append(sorted(x))\n for i in range(n-k):\n x,y=input().split()\n y=int(y)\n ...
{"inputs": [["1", "10 5", "amigoes 1", "bannermen 1", "monarchy 4", "outliers 5", "iniciador 10", "aegimos 2", "iiiacdnor 1", "eilorstu 1", "gimosae 3", "mnachroy 7"]], "outputs": [["iniciador 11", "monarchy 11", "amigoes 6", "outliers 6", "bannermen 1"]]}
INTERVIEW
PYTHON3
CODECHEF
2,279
9f4763a03b342044e3b743dc7708e7b9
UNKNOWN
On a planet called RUIZ LAND, which is ruled by the queen, Erika Ruiz. Each person on that planet has a strength value (strength value >0). That planet has a special rule made by the queen that a boy and a girl will form a couple if their Hate value is a prime number where $Hate$ is given by the formula:- Hate = (boy's...
["n=int(input())\r\na=list(map(int,input().split()))\r\nc=[]\r\nfor i in range(len(a)):\r\n if a[i]==2:\r\n c.append(1)\r\n else:\r\n c.append(a[i]^2)\r\nprint(*c)", "import copy\r\nn=int(input())\r\na=list(map(int,input().split()))\r\nc=[]\r\nfor i in range(len(a)):\r\n if a[i]==2:\r\n c....
{"inputs": [["2", "10 16"]], "outputs": [["8 18"]]}
INTERVIEW
PYTHON3
CODECHEF
9,827
0d6aea4a28a26aba598a2238227743d4
UNKNOWN
Vasya has ordered a pizza delivery. The pizza can be considered a perfect circle. There were $n$ premade cuts in the pizza when it was delivered. Each cut is a straight segment connecting the center of the pizza with its boundary. Let $O$ be the center of the pizza, $P_i$ be the endpoint of the $i$-th cut lying on the ...
["def gcd(a, b):\n if a == 0:\n return b\n return(gcd(b % a, a))\n\nt = int(input())\nfor T in range(t):\n n = int(input())\n l = [int(x) for x in input().split()]\n\n ang = []\n for i in range(1, n):\n ang.append(l[i] - l[i - 1])\n ang.append(360 - (l[-1] - l[0]))\n ang.sort()\n if ang == ang[::-1]:\n print(0)\n c...
{"inputs": [["3", "4", "0 90 180 270", "2", "90 210", "2", "0 1"]], "outputs": [["0", "1", "358"]]}
INTERVIEW
PYTHON3
CODECHEF
10,414
3be38813c5dc7e9bd5454cd5ea0db4bd
UNKNOWN
Digory Kirke and Polly Plummer are two kids living next door to each other. The attics of the two houses are connected to each other through a passage. Digory's Uncle Andrew has been secretly doing strange things in the attic of his house, and he always ensures that the room is locked. Being curious, Digory suspects th...
["# cook your dish here\nfor i in range(int(input())):\n s = input()\n m = 0\n p = 0\n d = 0\n l = []\n for i in range(len(s)):\n if(s[i] == \".\"):\n m = m+1\n elif(s[i] == \"#\"):\n l.append(m)\n m=0\n for i in range(len(l)):\n if(l[i]>p):\n p = l[i]\n d = d+1\n print(d)\n \n \n \n \n", "t=int(inpu...
{"inputs": [["4", "####", "##.#..#", "##..#.#", "##.#....#"]], "outputs": [["0", "2", "1", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
7,659
dd3809d100b7d788c6742ccc9accff17
UNKNOWN
Chef has an array A consisting of N integers (1-based indexing). He asks you to perform the following operation M times: for i = 2 to N: Ai = Ai + Ai-1 Your task is to find the xth element of the array (i.e., Ax) after performing the above operation M times. As the answer could be large, please output it modulo 10...
["for _ in range(int(input())):\n n,x,m = map(int,input().split())\n a = list(map(int,input().split()))\n for _ in range(m):\n for i in range(1,n):\n a[i] = a[i] + a[i-1]\n print(a[x-1]%(10**9+7))", "def modInverse(a, m) : \n m0 = m \n y = 0\n x = 1\n\n if (m == 1) : \n return 0\n\n while (a > 1) : \n q = a // m \...
{"inputs": [["2", "3 2 3", "1 2 3", "3 3 3", "1 2 3"]], "outputs": [["5", "15"]]}
INTERVIEW
PYTHON3
CODECHEF
11,218
87792cc2d9ac30d55afcb4bcfc8334f2
UNKNOWN
Ganesh lives in Gopalmath. He is looking for Jojo. So he decides to collect Aadhar Card Information of all the citizens of India from UIDAI. Someone told Ganesh that the sum of all the digits of Jojo’s Aadhar number is divisible by 10 and it is greater than zero. After finding all Aadhar numbers which are divisible by ...
["for _ in range(int(input())):\n N = input()\n num = list(N)\n s=0\n for n in num:\n if n.isnumeric():\n s+=int(n)\n #print(s)\n x=(10-s%10)%10\n print(int(N)*10+int(x))", "# cook your dish here\ndef s(n):\n sn=str(n)\n r=0\n for i in sn:\n r+=int(i)\n return r\n \nfor _ in range(int(input())):\n n=int(input())\n...
{"inputs": [["1", "3"]], "outputs": [["37"]]}
INTERVIEW
PYTHON3
CODECHEF
516
4741ee3d6cfa2b9534e08c2ef3a383db
UNKNOWN
Teddy and Tracy like to play a game based on strings. The game is as follows. Initially, Tracy writes a long random string on a whiteboard. Then, each player starting with Teddy makes turn alternately. Each turn, the player must erase a contiguous substring that exists in the dictionary. The dictionary consists of N wo...
["import sys\n\ndef mex(S,W,C,start,end):\n \"\"\"Returns Nim-number of S[start:end]\"\"\"\n key=(start,end)\n try:\n return C[key]\n except KeyError:\n pass\n A=set()\n for s in range(start,end):\n for e in range(start+1,end+1):\n if S[s:e] not in W: continue\n ...
{"inputs": [["3", "codechef", "2", "code", "chef", "foo", "1", "bar", "mississippi", "4", "ssissi", "mippi", "mi", "ppi", "", ""]], "outputs": [["Tracy", "Tracy", "Teddy"]]}
INTERVIEW
PYTHON3
CODECHEF
2,986
efc82c6919ecc32866243fb1a55e2470
UNKNOWN
Mathison recently inherited an ancient papyrus that contained some text. Unfortunately, the text was not a pangram. Now, Mathison has a particular liking for holoalphabetic strings and the text bothers him. The good news is that Mathison can buy letters from the local store in order to turn his text into a pangram. Ho...
["# cook your dish here\n# cook your dish here\nfor i in range(int(input())):\n a=list(map(int,input().split()))\n x=input()\n t=0\n for i in range(ord('a'),ord('z')+1):\n if chr(i) not in x:\n t+=a[i-97]\n print(t)", "t=int(input())\nx='abcdefghijklmnopqrstuvwxyz'\nfor i in range(t):\n a=0\n b=input().split()\n c=i...
{"inputs": [["2", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26", "abcdefghijklmopqrstuvwz", "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26", "thequickbrownfoxjumpsoverthelazydog"]], "outputs": [["63", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
4,331
5b559147634fc5b25854fd1a6ec99e28
UNKNOWN
You are given a sequence of integers $A_1,A_2,…,A_N$ and a magical non-zero integer $x$ You have to select a subsegment of sequence A (possibly empty), and replace the elements in that subsegment after dividing them by x. Formally, replace any one subsegment $A_l, A_{l+1}, ..., A_r$ with $A_l/x, A_{l+1}/x, ..., A_r/x$ ...
["def solve(a,n):\n max1=curr=a[0]\n for i in range(1,n):\n curr=max(a[i],curr+a[i])\n max1=max(max1,curr)\n return max1\n \nn,k = list(map(int,input().split()))\na = list(map(int,input().split()))\nprint(sum(a)-solve(a,n)+solve(a,n)/k)\n", "# cook your dish here\ndef atharva(a:list,n:int): \n msf = mh = a[0]\n for i...
{"inputs": [["3 2", "1 -2 3"]], "outputs": [["0.5"]]}
INTERVIEW
PYTHON3
CODECHEF
6,071
083f112be5923fa90736ee3b5f37cf76
UNKNOWN
You are given a string $S$. Find the number of ways to choose an unordered pair of non-overlapping non-empty substrings of this string (let's denote them by $s_1$ and $s_2$ in such a way that $s_2$ starts after $s_1$ ends) such that their concatenation $s_1 + s_2$ is a palindrome. Two pairs $(s_1, s_2)$ and $(s_1', s_2...
["def binarySearch(arr, l, r, x):\n mid=0\n while l <= r: \n mid = l + (r - l)//2; \n if arr[mid] == x: \n return mid+1 \n elif arr[mid] < x: \n l = mid + 1\n else: \n r = mid - 1\n if mid!=len(arr):\n if arr[mid]<x:\n return mid+1\n return mid\ns=input()\nstrt=[]\nend=[]\nplc=[]\nlandr=[]\nl2r=[]\nlr=[]\n...
{"inputs": [["abba"]], "outputs": [["7"]]}
INTERVIEW
PYTHON3
CODECHEF
4,367
cd3ca4fc18a421c0037cdc03e29f0b7d
UNKNOWN
Chef is playing a game on the non-negative x-axis. It takes him $1$ second to reach from $i^{th}$ position to $(i-1)^{th}$ position or $(i+1)^{th}$ position. The chef never goes to the negative x-axis. Also, Chef doesn't stop at any moment of time. The movement of chef can be described as follows. - At the start he is ...
["import sys\nfrom random import choice,randint\ninp=sys.stdin.readline\nout=sys.stdout.write\nflsh=sys.stdout.flush\n \nsys.setrecursionlimit(10**9)\ninf = 10**20\neps = 1.0 / 10**10\nmod = 10**9+7\ndd = [(-1,0),(0,1),(1,0),(0,-1)]\nddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]\n \ndef MI(): return map...
{"inputs": [["5", "0 1", "1 1", "2 1", "1 3", "4 6"]], "outputs": [["0", "1", "4", "5", "46"]]}
INTERVIEW
PYTHON3
CODECHEF
13,497
0232f2731d017d78d773236f6488dcf7
UNKNOWN
Chef Ada is building a new restaurant in the following way: - First, $N$ points $X_1, X_2, \ldots, X_N$ are chosen on the $x$-axis. - Then, $N$ columns (numbered $1$ through $N$) are made. For simplicity, the columns are represented as vertical segments; for each valid $i$, the height of the $i$-th segment is $H_i$. - ...
["# cook your dish here\nt = int(input())\nfor _ in range(t):\n n = int(input())\n a = []\n b = []\n for i in range(n):\n x,y = list(map(int, input().split()))\n a.append(x)\n b.append(y)\n b.sort()\n xcor = []\n xcor.append(a[1]-a[0])\n xcor.append(a[n-1]-a[n-2])\n for i in range(1,n-1):\n xcor.append(a[i+1]-a[i-1...
{"inputs": [["1", "5", "1 1", "2 2", "3 3", "4 4", "5 5"]], "outputs": [["27"]]}
INTERVIEW
PYTHON3
CODECHEF
11,372
08882683f53f827e144260f1e16a4b60
UNKNOWN
Roman has no idea, why this problem is called Stone. He also has no idea on how to solve the followong problem: given array of N integers A and a number K. During a turn the maximal value over all Ai is chosen, let's call it MAX. Then Ai = MAX - Ai is done for every 1 <= i <= N. Help Roman to find out how will the arr...
["n, k = list(map(int, input().split()))\nA = list(map(int, input().split()))\nmaximum = max(A)\nminimum = min(A)\nif k == 0:\n for i in A:\n print(i, end=' ')\nelif k&1:\n for i in A:\n print(maximum - i, end=' ')\nelse:\n for i in A:\n print(i - minimum, end=' ')\n", "n,k = input().split()\nn=int(n)\nk=int(k)\na=l...
{"inputs": [["4 1", "5 -1 7 0"]], "outputs": [["2 8 0 7"]]}
INTERVIEW
PYTHON3
CODECHEF
6,630
f2a9ee7b72b2c9803330cad5083c53dc
UNKNOWN
Chef just got a box of chocolates as his birthday gift. The box contains $N$ chocolates in a row (numbered $1$ through $N$), where $N$ is even. For each valid $i$, the $i$-th chocolate has a sweetness value $W_i$. Chef wants to eat all the chocolates in the first half of the box and leave all chocolates in the second h...
["from collections import deque\nt=int(input())\n\nfor i in range(t):\n n=int(input())\n N=[i for i in range(1, n+1)]\n w=list(map(int, input().split()))\n max_sweetness=max(w)\n sizes=[]\n cnt=0\n for i in range(n):\n if w[i]!=max_sweetness:\n cnt+= 1 \n else:\n sizes.append(cnt)\n cnt=0\n \n if cnt!=0:\n siz...
{"inputs": [["2", "6", "1 1 2 1 1 1", "6", "1 1 2 1 1 2"]], "outputs": [["3", "0"]]}
INTERVIEW
PYTHON3
CODECHEF
9,051
af41fe00d667c136d17c5def6f06ecca
UNKNOWN
The Fibonacci sequence $F_0, F_1, \ldots$ is a special infinite sequence of non-negative integers, where $F_0 = 0$, $F_1 = 1$ and for each integer $n \ge 2$, $F_n = F_{n-1} + F_{n-2}$. Consider the sequence $D$ of the last decimal digits of the first $N$ Fibonacci numbers, i.e. $D = (F_0 \% 10, F_1 \% 10, \ldots, F_{N-...
["import math\n\nt = int(input())\n\na = [-1, 0, 1]\n\nfor i in range(58):\n temp = a[-1] + a[-2]\n temp = temp%10\n a.append(temp)\n \nfor _ in range(t):\n n = int(input())\n \n temp = len(bin(n)) - 3\n temp = 2**temp\n temp = temp%60\n \n print(a[temp])", "import math\n\ndef logBase2(n):\n res = 0\n fact = 1\n while(...
{"inputs": [["1", "9"]], "outputs": [["3"]]}
INTERVIEW
PYTHON3
CODECHEF
8,291
a806d32dcd45e159492f3e8aa2aa1a1b
UNKNOWN
The bustling town of Siruseri has just one sports stadium. There are a number of schools, colleges, sports associations, etc. that use this stadium as the venue for their sports events. Anyone interested in using the stadium has to apply to the Manager of the stadium indicating both the starting date (a positive intege...
["# cook your dish here\nn=(int(input()))\nx=[]\nfor _ in range(n):\n a,b=map(int,input().split())\n a=[a,a+b]\n x.append(a)\nx = sorted(x, key= lambda i:i[1])\ny=-1\nc=0\nfor i in range(len(x)):\n if x[i][0]>y:\n c+=1\n y=x[i][1]\nprint(c)", "# cook your dish here\nn=(int(input()))\nx=[]\nfor...
{"inputs": [["4", "2 5", "9 7", "15 6", "9 3", "Sample output:", "3"]], "outputs": [[]]}
INTERVIEW
PYTHON3
CODECHEF
1,271
2a330741cbcf50a6fa4d57b4b357f486
UNKNOWN
Chef Loves to listen to remix songs, but currently he had already finished the entire playlist of remix songs. As Chef is smart, so he thought let's make my own remix songs of the original songs. Chef is not having much knowledge of making remix songs, so he came up with the simple technique in which he will pick the w...
["m= 9999999\r\nword=''\r\np= ''\r\ntry:\r\n s=input().split()\r\n for i in s:\r\n if(len(i) <= m):\r\n m = len(i)\r\n word = i\r\n p = word\r\n for i in s:\r\n p+= (' '+i+' '+ word)\r\n \r\n print(p)\r\n\r\n \r\nexcept E...
{"inputs": [["Mai Hu Jiyaan"]], "outputs": [["Hu Mai Hu Hu Hu Jiyaan Hu"]]}
INTERVIEW
PYTHON3
CODECHEF
6,989
aa809cabe3ad0e94e59046e553e31359
UNKNOWN
----- Statement ----- You need to find a string which has exactly K positions in it such that the character at that position comes alphabetically later than the character immediately after it. If there are many such strings, print the one which has the shortest length. If there is still a tie, print the string which c...
["for i in range(int(input())):\n N = int(input())\n s = 'zyxwvutsrqponmlkjihgfedcba'\n r = ''\n while True:\n r = s[-N-1:] + r \n if N < 26:\n break\n N -= 25\n print(r)", "s='abcdefghijklmnopqrstuvwxyz'\nfor u in range(int(input())):\n n=int(input())\n r=''\n while(1):\n r=s[n::-1]+r\n if(n<26):\n break\n n...
{"inputs": [["2", "1", "2"]], "outputs": [["ba", "cba"]]}
INTERVIEW
PYTHON3
CODECHEF
5,132
08e7a923bf9b2b12686e47484de04b2b
UNKNOWN
You are given a grid with $R$ rows (numbered $1$ through $R$) and $C$ columns (numbered $1$ through $C$). A cell in row $r$ and column $c$ is denoted by $(r, c)$. Two cells in the grid are adjacent if they have a common side. For each valid $i$ and $j$, there is a value $a_{i, j}$ written in cell $a_{i, j}$. A cell in ...
["for _ in range(int(input())):\n r,c = map(int,input().split())\n l = []\n for k in range(r):\n a = list(map(int,input().split()))\n l.append(a)\n ans = \"Stable\" \n for i in range(r):\n for j in range(c):\n p = l[i][j]\n count=0\n if i-1>=0 and j>=0:\n count+=1 \n if i>=0 and j-1>=0:\n count+=1 \n ...
{"inputs": [["2", "3 3", "1 2 1", "2 3 2", "1 2 1", "3 4", "0 0 0 0", "0 0 0 0", "0 0 4 0"]], "outputs": [["Stable", "Unstable"]]}
INTERVIEW
PYTHON3
CODECHEF
5,204
613f634fa50b1a659f5185accf6f2fa0
UNKNOWN
There is a rectangular grid of cells consisting of n rows and m columns. You will place a robot on one of the grid cells and provide it with a command string s, consisting of characters ‘L’, ‘R’, ‘U’, ‘D’. After being placed, the robot will follow the instructions of the command string, where 'L' corresponds moving to ...
["# cook your dish here\ntest=int(input())\nfor _ in range(test):\n b=list(map(int,str(input()).split(' ')))\n c=str(input())\n li1=[0]\n li2=[0]\n for i1 in range(len(c)):\n if c[i1]=='R':\n li1.append(li1[len(li1)-1]+1)\n elif c[i1]=='L':\n li1.append(li1[len(li1)-1]-1)\n elif c[i1]=='U':\n li2.append(li2[le...
{"inputs": [["5", "1 1", "R", "2 3", "LLRU", "3 2", "LLRU", "4 3", "ULURUDRDLD", "3 6", "RURUR"]], "outputs": [["unsafe", "safe", "unsafe", "safe", "safe"]]}
INTERVIEW
PYTHON3
CODECHEF
9,048
fd93760d21214e26a0b9e8d4c121db51
UNKNOWN
Consider the infinite x$x$ axis. There are N$N$ impacts on this X-axis at integral points (X1$X_1$,X2$X_2$,....XN$X_N$) (all distinct) . An impact at a point X$X$i propagates such that at a point X$X$0, the effect of the impact is K|Xi−X0|$K^{|X_i - X_0|}$. Given the point X0$X_0$, N$N$ and K$K$. Assume the total impa...
["# cook your dish here\nT = int(input())\nfor i in range(T):\n l = list(map(int, input().split()))\n n, k, m, x = l[0], l[1], l[2], l[3]\n if k == 1:\n if n == m:\n print(\"yes\")\n else:\n print(\"no\")\n elif m % k > 1:\n print(\"no\")\n elif k == 2:\n ...
{"inputs": [["2", "4 3 10 10", "2 3 10 10"]], "outputs": [["no", "yes"]]}
INTERVIEW
PYTHON3
CODECHEF
12,492
c69353d45f3a19ed29ab4afa788da335
UNKNOWN
You are given a sequence $A_1, A_2, \ldots, A_N$. You have to split the array into maximum number of non-empty subarrays such that the gcd of elements of each subarray is equal to 1. -----Input:----- - The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ t...
["'''input\n2\n3\n2 2 3\n4\n2 3 3 2\n'''\nimport math\n\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int, input().split()))\n count = 0\n i = 0\n while i < len(a):\n if a[i] == 1:\n count += 1\n i += 1\n continue\n curr_gcd = a[i]\n while i < len(a) and curr_gcd != 1:\n curr_gcd = math.gc...
{"inputs": [["2", "3", "2 2 3", "4", "2 3 3 2"]], "outputs": [["1", "2"]]}
INTERVIEW
PYTHON3
CODECHEF
1,473
be16604c0f234ad6e2bce7e8afe36203
UNKNOWN
Abhi Ram analyses london stock exchange and invests in a software company C-.gate . He wants to sell his shares after 5 weeks. Given the investment m, increase or decrease of share prices of 5 weeks(+/- pi) , help him to calculate his net profit or loss percentage(n%) of his investment to establish his own company KM...
["for i in range(int(input())):\n\t n = int(input())\n\t P = list(map(float, input().split()))\n\t pr = 1\n\t for p in P:\n\t\t a = 100+p\n\t\t pr = (pr*a)/100\n\t pr = (pr-1)*100\n\t x = 6-len(str(int(abs(pr))))\n \t if (x==1):\n \t \t if (pr==0):\n \t \t \tprint(0)\n\t\t elif (pr>0):\n\t\t \tprint(\"+\"+str(\...
{"inputs": [["2", "10000", "+5 -3 -2 +10 +15", "6256250", "-24 +22 +4 -16 +20"]], "outputs": [["+26.2634", "-2.79977"]]}
INTERVIEW
PYTHON3
CODECHEF
1,315
fcb93f3bafdb1974f72977bfdf9f22c9
UNKNOWN
Chef published a blog post, and is now receiving many queries about it. On day $i$, he receives $Q_i$ queries. But Chef can answer at most $k$ queries in a single day. Chef always answers the maximum number of questions that he can on any given day (note however that this cannot be more than $k$). The remaining questi...
["# cook your dish here\n\nt=int(input())\nwhile(t):\n t=t-1\n n,k=list(map(int,input().split()))\n q=list(map(int,input().split()))\n days,rem=0,0\n for i in range(n):\n rem+=q[i]\n if(rem>=k):\n rem-=k\n else:\n days=i+1\n break\n days+=1\n if(rem>=k):\n days+=(rem//k)+1\n print(days)\n", "# cook your dish...
{"inputs": [["2", "6 5", "10 5 5 3 2 1", "1 1", "100"]], "outputs": [["6", "101"]]}
INTERVIEW
PYTHON3
CODECHEF
7,311
941fecd17affbeed734ce75b4fd48c1c
UNKNOWN
Due to the COVID pandemic, people have been advised to stay at least $6$ feet away from any other person. Now, people are lining up in a queue at the local shop and it is your duty to check whether they are all following this advice. There are a total of $N$ spots (numbered $1$ through $N$) where people can stand in fr...
["# cook your dish here\nt=int(input())\nwhile t>0:\n n=int(input())\n l=list(map(int,input().split()))\n l1=[]\n c=1\n for i in range(len(l)):\n if l[i]==1:\n l1.append(i)\n for j in range(len(l1)-1):\n if l1[j+1]-l1[j]<6:\n c=0\n break\n if c:\n ...
{"inputs": [["3", "3", "1 0 1", "7", "1 0 0 0 0 0 1", "11", "0 1 0 0 0 0 0 1 0 0 1", ""]], "outputs": [["NO", "YES", "NO"]]}
INTERVIEW
PYTHON3
CODECHEF
10,968
ae2b1dac138d29ab2cc8609982ad248a
UNKNOWN
"What do you know about happiness?" — Yoda Chef is happy only if three conditions hold: - Chef finished cooking a delicious meal - Chef got AC for a programming problem with an almost correct code - Chef got a new problem with a sequence of integers Today, all three conditions are satisfied. Chef would like you to fee...
["# cook your dish here\n\nt=int(input())\n\nfor i in range(t):\n n=int(input())\n a=list(map(int,input().split()))\n d={}\n for i in range(n):\n if a[i]-1 not in d:\n d[a[i]-1]=[i]\n else:\n d[a[i]-1].append(i)\n ans=False\n d1={}\n \n for i in d:\n if ans==True:\n break\n for j in d:\n if i!=j:\n if a[...
{"inputs": [["4", "4", "1 1 2 3", "4", "2 1 3 3", "5", "5 4 4 3 1", "5", "3 2 1 1 4"]], "outputs": [["Truly Happy", "Poor Chef", "Poor Chef", "Truly Happy"]]}
INTERVIEW
PYTHON3
CODECHEF
9,820
df7d25501a1e69a3946ebf9fd10c648f
UNKNOWN
Lots of geeky customers visit our chef's restaurant everyday. So, when asked to fill the feedback form, these customers represent the feedback using a binary string (i.e a string that contains only characters '0' and '1'. Now since chef is not that great in deciphering binary strings, he has decided the following cri...
["# cook your dish here\nt=int(input())\nfor i in range(t):\n s=input()\n fl=-1\n n=len(s)\n for i in range(n-2):\n if(s[i:i+3]==\"010\" or s[i:i+3]==\"101\"):\n fl=0\n print(\"Good\")\n break\n\n if(fl==-1):\n print(\"Bad\")\n", "# cook your dish here\nt=int(input())\nfor i in range(t):\n s=input()\n fl=-1\n n...
{"inputs": [["2", "11111110", "10101010101010"]], "outputs": [["Bad", "Good"]]}
INTERVIEW
PYTHON3
CODECHEF
4,808
1c4a1077793786c810bfcb74feb802fc
UNKNOWN
-----Problem----- Nikki's latest work is writing a story of letters. However, she finds writing story so boring that, after working for three hours, she realized that all she has written are M long words consisting entirely of letters A and B. Having accepted that she will never finish the story in time, Nikki has ...
["def check(s):\n arr=[s[0]]\n l=len(s)\n f1=0\n for i in range(1,l):\n if arr==[]: arr.append(s[i])\n elif arr[-1]!=s[i]:arr.append(s[i])\n else: del arr[-1]\n if arr==[]: return True\n else: return False\n \ncount = 0\nfor t in range(eval(input())):\n s=input().strip()\n if check(s): count+=1\nprint(count)", "coun...
{"inputs": [["3", "ABAB", "AABB", "ABBA"]], "outputs": [["2"]]}
INTERVIEW
PYTHON3
CODECHEF
534
055a58070b55400df17380a944630cfa
UNKNOWN
Chef would like go shopping to buy ingredients for his special dish. The local grocery store has some special discount offers. If you want to buy some set of ingredients you will pay for all ingredients except the cheapest one. Chef would like to spend as little money as possible. You have to help him. :) The store is...
["from itertools import permutations as p\ndef disc(a,b):\n for ai in a:\n for bi in b:\n if ai==bi:\n return False\n return True\n\nfor i in range(eval(input())):\n n = eval(input())\n arr = list(map(int,input().split()))\n perms = list(p(arr))\n m = eval(input())\n offer = {}\n for i in range(m):\n dup = list(...
{"inputs": [["1", "4", "1 2 3 4", "3", "2 1 2", "2 3 4", "3 1 2 3"]], "outputs": [["6"]]}
INTERVIEW
PYTHON3
CODECHEF
3,826
8a12d8c60725598209d8d7d89f50da1e
UNKNOWN
Nexus 4.O is going to be organized by ASME, GLA University. Shubhanshu, Head of Finance Team is working for it. He has $N$ number of bills of different values as $a$$1$,$ a$$2$, $a$$3$…$a$$n$. He is interested in a game in which one has to do the addition of the bills. But due to privacy concerns, he cannot share the d...
["\nt=int(input())\nfor i in range(t):\n l=list(map(int,input().split(' ')))\n a=l[0]\n b=l[1]\n \n l1=list(map(int,input().split(' ')))\n for i in range(b):\n l2=list(map(int,input().split(' ')))\n a1=l2[0]\n b1=l2[1]\n su=0\n for j in range(a1-1,b1):\n su=(su+l1[j])%1000000000\n print(su) ", "\nt=int(input())...
{"inputs": [["1", "8 3", "1 2 3 4 5 6 7 8", "2 3", "1 6", "5 8"]], "outputs": [["5", "21", "26"]]}
INTERVIEW
PYTHON3
CODECHEF
5,951