problem_id int64 0 5k | question stringlengths 50 14k | solutions stringlengths 12 1.21M | input_output stringlengths 0 23.6M | difficulty stringclasses 3
values | url stringlengths 36 108 | starter_code stringlengths 0 1.4k |
|---|---|---|---|---|---|---|
1,000 | The activity of a panipuri seller is "making a panipuri and putting it on the palte of his customer".
$N$ customers are eating panipuri, Given an array $A$ of length $N$, $i^{th}$ customer takes $A_i$ seconds to eat a panipuri.
The Speed of Panipuri seller refers to the number of customers served per second. D... | ["# cook your dish here\nfrom math import ceil\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n ans=ceil(n/min(a))\n print(int(ans))", "from math import *\nfor i in range(int(input())):\n n=int(input())\n arr=[int(i) for i in input().split()]\n print(ceil(n/min(a... | {"inputs": [["2", "4", "2 4 6 3", "5", "2 3 4 6 5"]], "outputs": [["2", "3"]]} | interview | https://www.codechef.com/ECPG2020/problems/ECPC10B | |
1,001 | Chef wants to buy a new phone, but he is not willing to spend a lot of money. Instead, he checks the price of his chosen model everyday and waits for the price to drop to an acceptable value. So far, he has observed the price for $N$ days (numbere $1$ through $N$); for each valid $i$, the price on the $i$-th day was $P... | ["for _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n g=1\n for j in range(1,n):\n if j-5<0:\n mi=min(a[0:j])\n #print(a[0:j])\n if mi>a[j]:\n g=g+1\n else:\n mi=min(a[j-5:j])\n #print(a[j-5:j])\n if mi>a[j]:\n g=g+1\n print(g)\n", "# cook your dish here\nt = int(inpu... | {"inputs": [["1", "7", "375 750 723 662 647 656 619"]], "outputs": [["2"]]} | interview | https://www.codechef.com/problems/S10E | |
1,002 | Chef works in a similar way to a travelling salesman ― he always travels to new cities in order to sell his delicious dishes.
Today, Chef is planning to visit $N$ cities (numbered $1$ through $N$). There is a direct way to travel between each pair of cities. Each city has a specific temperature; let's denote the temper... | ["# cook your dish here\ndef solution(b,n1,d):\n first=b[0]\n b.sort()\n for j in range(n1-1):\n if(a[j+1]-a[j]>d):\n return \"NO\"\n for j in range(n1):\n if(b[j]==first):\n pos=j\n if(pos==0 or pos==n1-1):\n return \"YES\"\n rec=1\n for j in range(pos-1,n1-2):\n if(a[j+2]-a[j]>d):\n rec=0\n break\n if(... | {"inputs": [["2", "5 3", "3 2 1 4 5", "5 4", "10 1 3 2 9"]], "outputs": [["YES", "NO"]]} | interview | https://www.codechef.com/problems/TRVLCHEF | |
1,003 | In the world of DragonBool there are fierce warriors called Soints. Also there are even fiercer warriors called Sofloats – the mortal enemies of Soints.
The power of each warrior is determined by the amount of chakra he possesses which is some positive integer. Warriors with zero level of chakra are dead warriors :) W... | ["t=eval(input())\nfor i in range(0,t):\n x=input()\n nm=x.split(' ')\n nm[0]=int(nm[0])\n nm[1]=int(nm[1])\n csoint=[]\n lsoint=[]\n csofloat=[]\n lsofloat=[]\n for j in range(0,nm[0]):\n a=input()\n b=a.split(' ')\n b[0]=int(b[0])\n b[1]=int(b[1])\n csoint... | {"inputs": [["2", "2 3", "10 1", "20 2", "5 2", "5 2", "18 1", "5 5", "73 87", "69 13", "36 36", "77 46", "43 93", "49 46", "74 93", "78 87", "99 13", "59 36", "", ""]], "outputs": [["8", "89"]]} | interview | https://www.codechef.com/OCT12/problems/DRGNBOOL | |
1,004 | A group of rebels travelling on a square hoverboard is ambushed by Imperial Stormtroopers.Their big hoverboard is an easy target, so they decide to split the board into smaller square hoverboards so that they can bolt away easily.But they should also make sure they don't get too spread out.Help the rebels split the cra... | ["a=int(input())\nif(a%2==0):\n print(\"4\")\n print(a/2,a/2,a/2,a/2)\nelse:\n print(\"6\")\n print((a-1)/2,(a-1)/2,(a-1)/2,(a-1)/2,(a-1)/2,(a+1)/2)"] | {"inputs": [["3"]], "outputs": [["6", "1 1 1 1 1 2"]]} | interview | https://www.codechef.com/SOPC2015/problems/SOPC1505 | |
1,005 | Takaki Tono is a Computer Programmer in Tokyo. His boss at work shows him an online puzzle, which if solved would earn the solver a full expense paid trip to Los Angeles, California. Takaki really wants to solve this, as the love of his life, Akari, lives in Los Angeles and he hasn't met her since four years. Upon read... | ["MAXX = 10**9+1\nN = eval(input())\nnodes = list(map(int, input().split(\" \")))\nedges = [set() for _ in range(N)]\nfor _ in range(N-1):\n a, b = list(map(int, input().split(\" \")))\n edges[a-1].add(b-1)\n edges[b-1].add(a-1)\npath = [[] for _ in range(N)]\nvisited, tovisit = set(), [(0, 0)]\nwhile tovisit:... | {"inputs": [["5", "1 2 7 4 5", "1 2", "2 3", "2 4", "2 5", "7", "C 1 5", "F 1 5", "C 2 4", "C 1 2", "F 1 3", "F 3 4", "F 2 4"]], "outputs": [["1", "4", "2", "1", "6", "5", "2"]]} | interview | https://www.codechef.com/LTIME38/problems/CLOSEFAR | |
1,006 | Chef Leonardo has a decimal integer $N$ and a non-zero decimal digit $d$. $N$ does not contain the digit zero; specifically, $N$ should always be treated as a decimal integer without leading zeroes.
Chef likes $d$ and does not like any other digit, so he decided to change $N$. He may apply the following operation any n... | ["for _ in range(int(input())):\n n,d=map(str,input().split())\n k=list(n)\n dd,c,n=d,0,len(n)\n for x in range(n):\n if int(k[n-x-1])>int(d):\n k.pop(n-x-1)\n c+=1 \n else:\n d=k[n-x-1]\n print(''.join(k)+c*dd)", "# cook your dish here\nfrom sys import stdin,stdout\n\nfor _ in range(int(input())):\n n,d=map(st... | {"inputs": [["3", "35 4", "42 4", "24 9"]], "outputs": [["34", "24", "24"]]} | interview | https://www.codechef.com/problems/CHDIGER | |
1,007 | Given an array A1,A2...AN, you have to print the size of the largest contiguous subarray such that
GCD of all integers in that subarray is 1.
Formally,
For a subarray Ai,Ai+1...Aj where 1 ≤ i < j ≤ N to be valid: GCD(Ai,Ai+1...Aj) should be 1. You have to print the size of the largest valid subarray.
If no valid suba... | ["import math\nfor _ in range(int(input())):\n n=int(input())\n ar=[int(x) for x in input().split()]\n # dp=[1]*n\n f=0\n g=ar[0]\n for i in range(1,n):\n g=math.gcd(g,ar[i])\n if g==1:\n f=1\n print(n)\n break\n if f==0:\n print(-1)\n", "import math\ndef gcd(a,b):\n if b==0:\n return a\n return gcd(b,a%b)\nt... | {"inputs": [["2", "2", "7 2", "3", "2 2 4"]], "outputs": [["2", "-1"]]} | interview | https://www.codechef.com/problems/SUBGCD | |
1,008 | You are given an array A consisting of N integers. A group of disjoint subarrays in it will be a collection of subarrays of the array. Formally a group of subarrays consisting of K subarrays can be denoted by 2 * K indices, [i1, j1], [i2, j2] , ..., [iK, jK], such that i1 ≤ j1 < i2 ≤ j2 < ... < iK ≤ jK.
For example, i... | ["t=int(input())\nfor k in range(t):\n n=int(input())\n l=[int(i) for i in input().split()]\n m={}\n count=1\n for i in range(1,n):\n if l[i]==l[i-1]:\n count+=1\n else:\n \n if l[i-1] not in m:\n m[l[i-1]]=(count*(count+1))/2\n els... | {"inputs": [["3", "2", "3 4", "3", "1 2 2", "5", "1 1 2 2 2", "", ""]], "outputs": [["1", "3", "18"]]} | interview | https://www.codechef.com/problems/MXSUBARR | |
1,009 | Chef is playing a game on a sequence of $N$ positive integers, say $A_1, A_2, ... A_N$ The game is played as follows.
- If all the numbers are equal, the game ends.
- Otherwise
- Select two numbers which are unequal
- Subtract the smaller number from the larger number
- Replace the larger number with the result from ab... | ["# cook your dish here\nfrom sys import stdin\nimport functools\ndef gcd(a, b): \n if (a == 0): \n return b \n return gcd(b % a, a) \n \nMAX=10001\ndef func(ind, g, dp, n, a): \n if (ind == n): \n if (g == 1): \n return 1\n else: \n return 0\n if (dp[ind][g] != -1): \n return dp[ind][g] \n ans = (func(ind ... | {"inputs": [["3", "4", "2 3 5 7", "4", "3 4 8 16", "3", "6 10 15"]], "outputs": [["11", "7", "1"]]} | interview | https://www.codechef.com/problems/AMSGAME2 | |
1,010 | Anmol gained a lot of weight last semester. So this semester, he decided to run everyday. There is a very long straight road starting at his hostel. There are N poles on the road - P1, P2, P3,..., PN on the road. All the poles lie on the same side of his hostel. The distance between Pi and his hostel is Di.
For 1 ≤ i, ... | ["#code snippet reference:http://www.geeksforgeeks.org/searching-for-patterns-set\u00a0\u00a0\u00a0\u00a0-2-kmp-algorithm/\ndef KMPMatch(pattern, string):\n M = len(pattern)\n N = len(string)\n nonlocal ans\n\n lps = [0]*M\n j = 0 \n LPSCompute(pattern, M, lps)\n\n i = 0 \n while i < N:\n if pattern[j] == string[i]:\n... | {"inputs": [["3", "5 1", "1 5 10 12 14", "5", "5 2", "5 8 13 16 21", "3 5", "5 3", "2 6 8 11 16", "2 3 5"]], "outputs": [["1", "2", "1"]]} | interview | https://www.codechef.com/LOCAPR16/problems/RUNNING | |
1,011 | Chef is a really nice and respectful person, in sharp contrast to his little brother, who is a very nasty and disrespectful person. Chef always sends messages to his friends in all small letters, whereas the little brother sends messages in all capital letters.
You just received a message given by a string s. You don't... | ["t=int(input())\ndef do():\n n,k=map(int,input().split())\n s=input()\n upper=0\n lower=0\n for i in s:\n if i.isupper():\n upper+=1\n else:\n lower+=1\n if lower>k and upper<=k:\n print('chef')\n elif(upper>k and lower<=k):\n print('brother')\n elif(upper<=k and lower<=k):\n print('both')\n else:\n print('n... | {"inputs": [["4", "5 1", "frauD", "5 1", "FRAUD", "4 4", "Life", "10 4", "sTRAWBerry"]], "outputs": [["chef", "brother", "both", "none"]]} | interview | https://www.codechef.com/problems/GOODBAD | |
1,012 | Alice likes prime numbers. According to Alice, only those strings are nice whose sum of character values at a prime position is prime. She has a string $S$. Now, she has to count the number of nice strings which come before string $S$( including $S$) in the dictionary and are of the same length as $S$.
Strings are zer... | ["import sys\r\nfrom collections import defaultdict\r\nfrom copy import copy\r\n\r\nMOD = 10**9 + 7\r\n\r\nR = lambda t = int: t(input())\r\nRL = lambda t = int: [t(x) for x in input().split()]\r\nRLL = lambda n, t = int: [RL(t) for _ in range(n)]\r\n\r\n# primes up to n\r\ndef primes(n):\r\n P = []\r\n n = int(n)\r\... | {"inputs": [["1", "abc"]], "outputs": [["10"]]} | interview | https://www.codechef.com/ENJU2020/problems/ECJN207 | |
1,013 | Navnit is a college student and there are $N$ students in his college .Students are numbered from $1$ to $N$.
You are given $M$ facts that "Student $A_i$ and $B_i$".The same fact can be given multiple times .If $A_i$ is a friend of $B_i$ ,then $B_i$ is also a friend of $A_i$ . If $A_i$ is a friend of $B_i$ and $B_i$ is... | ["# cook your dish here\r\nfrom collections import defaultdict\r\nd=defaultdict(list)\r\ndef dfs(i):\r\n p=0\r\n nonlocal v\r\n e=[i]\r\n while(e!=[]):\r\n p+=1\r\n x=e.pop(0)\r\n v[x]=1\r\n for i in d[x]:\r\n if v[i]==-1:\r\n v[i]=1\r\n e... | {"inputs": [["5 3", "1 2", "3 4", "1 5"]], "outputs": [["6"]]} | interview | https://www.codechef.com/INDC2021/problems/NAV28 | |
1,014 | A number K$K$ is said to be magical if it can be represented as a power of 2 only.That is K$K$=2x$2^{x}$ for some natural number x$x$.
Given a string of digits S$S$ of length N$N$, Let P be a valid arrangement of S.
By valid arrangement we mean that it should not have any leading zeroes.
Find the sum of all such disti... | ["from math import log2, ceil\r\nMOD = int(1e9 + 7)\r\nsrt = lambda s: ''.join(sorted(s))\r\nfor _ in range(int(input())):\r\n s = srt(input())\r\n res = -1\r\n for p in range(ceil(log2(int(s))), int(log2(int(s[::-1]))) + 1):\r\n if int(srt(str(pow(2, p)))) == int(s):\r\n if res == -1: res = ... | {"inputs": [["2", "35566", "31"]], "outputs": [["65536", "-1"]]} | interview | https://www.codechef.com/ALQU2018/problems/POWTWO | |
1,015 | The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single line of ... | ["# cook your dish here\ntry:\n for _ in range(int(input())):\n k = int(input())\n num = 1\n for i in range(1,k+1,1):\n for j in range(1,k+1,1):\n print(num*2,end=\"\")\n num = num +1\n print(\"\")\nexcept:\n pass", "t = int(input())\r\n\r\n... | {"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["2", "24", "68", "246", "81012", "141618", "2468", "10121416", "18202224", "26283032"]]} | interview | https://www.codechef.com/PTRN2021/problems/ITGUY50 | |
1,016 | You have been recently hired as a developer in CodeChef. Your first mission is to implement a feature that will determine the number of submissions that were judged late in a contest.
There are $N$ submissions, numbered $1$ through $N$. For each valid $i$, the $i$-th submission was submitted at time $S_i$ and judged at... | ["# cook your dish here\nfor t in range(int(input())):\n c=0\n for i in range(int(input())):\n s,j=list(map(int,input().split()))\n if (j-s)>5:\n c+=1 \n print(c)\n \n", "for _ in range(int(input())):\n n = int(input())\n\n cnt = 0\n for _ in range(n):\n s, j = map(int, input().split())\n\n if j - s > 5: cnt ... | {"inputs": [["1", "5", "1 3", "4 4", "4 10", "1 11", "2 7"]], "outputs": [["2"]]} | interview | https://www.codechef.com/problems/JDELAY | |
1,017 | Chef recently started working at ABC corporation. Let's number weekdays (Monday through Friday) by integers $1$ through $5$. For each valid $i$, the number of hours Chef spent working at the office on weekday $i$ was $A_i$.
Unfortunately, due to the COVID-19 pandemic, Chef started working from home and his productivity... | ["# cook your dish here\nfor t in range(int(input())):\n a1,a2,a3,a4,a5,p=[int(x)for x in input().rstrip().split()]\n if (a1+a2+a3+a4+a5)*p >120:\n print(\"Yes\")\n else:\n print(\"No\")\n", "for i in range(int(input())):\n n=[int(x) for x in input().split()]\n t=n[-1]\n n=n[:-1]\n a=0\n for i in n:\n a+=i*t\n if a>... | {"inputs": [["2", "14 10 12 6 18 2", "10 10 10 10 10 3"]], "outputs": [["No", "Yes"]]} | interview | https://www.codechef.com/problems/LOSTWKND | |
1,018 | Chef has a garden with $N$ plants arranged in a line in decreasing order of height. Initially the height of the plants are $A_1, A_2, ..., A_N$.
The plants are growing, after each hour the height of the $i$-th plant increases by $i$ millimeters. Find the minimum number of integer hours that Chef must wait to have two p... | ["\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int, input().split()))\n hrs = arr[0] - arr[1]\n\n for i in range(1, n-1):\n if hrs > arr[i] - arr[i+1]:\n hrs = arr[i] - arr[i+1]\n\n print(hrs)", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n a = list(map(int,input()... | {"inputs": [["1", "3", "8 4 2"]], "outputs": [["2"]]} | interview | https://www.codechef.com/problems/INFTINCR | |
1,019 | The snakes want to build a temple for Lord Cobra. There are multiple strips of land that they are looking at, but not all of them are suitable. They need the strip of land to resemble a coiled Cobra. You need to find out which strips do so.
Formally, every strip of land, has a length. Suppose the length of the i-th str... | ["# cook your dish here\nfor i in range(int(input())):\n N=int(input())\n L=list(map(int,input().split()))\n l,h=0,N-1 \n flag=1\n if L[l]!=1 and L[h]!=1:\n flag=0\n else:\n while(l<h):\n if (L[l]!=L[h]) or (L[l+1]-L[l]!=1 and L[h-1]-L[h]!=1):\n flag=0\n break\n l+=1 \n h-=1\n if flag:\n print(\"yes\")\n... | {"inputs": [["7", "5", "1 2 3 2 1", "7", "2 3 4 5 4 3 2", "5", "1 2 3 4 3", "5", "1 3 5 3 1", "7", "1 2 3 4 3 2 1", "4", "1 2 3 2", "4", "1 2 2 1"]], "outputs": [["yes", "no", "no", "no", "yes", "no", "no"]]} | interview | https://www.codechef.com/problems/TEMPLELA | |
1,020 | Vanja and Miksi have already finished everything for this year at their university, so they decided to spend their free time playing a game with a binary sequence $A_1, A_2, \dots, A_N$ (i.e. a sequence containing only integers $0$ and $1$).
At the beginning of the game, Vanja and Miksi write down the expression $* A_1... | ["# cook your dish here\nfor _ in range(int(input())):\n n,k=list(map(int,input().split()))\n a=list(map(int,input().split()))\n m=0\n for i in range(n):\n if i%2==0:\n if m<0:\n m-=a[i]\n else:\n m+=a[i]\n else:\n if m<0:\n m+=a[i]\n else:\n m-=a[i]\n if abs(m)>=k:\n print(1)\n else:\n print(2)... | {"inputs": [["2", "2 1", "1 0", "3 5", "0 1 0"]], "outputs": [["1", "2"]]} | interview | https://www.codechef.com/problems/MIXGA | |
1,021 | The chef likes to play with numbers. He takes some integer number x, writes it down on his iPad, and then performs with it n−1 operations of the two kinds:
- divide the number x by 3 (x must be divisible by 3);
- multiply the number x by 2.
After each iteration, Chef writes down the result on his iPad and replaces x wi... | ["class Node:\r\n def __init__(self,x):\r\n self.x=x\r\n self.next=None\r\n self.prev=None\r\n self.flag=True\r\n\r\nfor t in range(1):\r\n n=int(input())\r\n arr=list(map(int,input().split()))\r\n for i in range(n):\r\n arr[i]=Node(arr[i])\r\n for i in arr:\r\n ... | {"inputs": [["6", "4 8 6 3 12 9"]], "outputs": [["9 3 6 12 4 8"]]} | interview | https://www.codechef.com/BRBG2020/problems/THTOG | |
1,022 | There are $N$ cities on a circle, numbered $1$ through $N$. For each $i$ ($1 \le i \le N-1$), cities $i$ and $i+1$ are directly connected by a bidirectional road with length $A_i$, and cities $N$ and $1$ are also directly connected by a bidirectional road with length $A_N$. However, we do not know the lengths of some r... | ["# cook your dish here\n# cook your dish here\nimport math\ntest=int(input())\nfor _ in range(test):\n n=int(input())\n l=list(map(int,input().split()))\n f=0\n for i in range(math.ceil(n//2)):\n if n%2==1:\n f=1\n break\n else:\n if l[i]!=l[i+n//2]:\n if min(l[i],l[i+n//2])==-1:\n l[i]=max(l[i],l[i+n//... | {"inputs": [["4", "4", "1 1 1 1", "4", "1 1 1 2", "4", "1 -1 -1 4", "4", "1 -1 2 -1"]], "outputs": [["YES", "1 1 1 1", "NO", "YES", "1 4 1 4", "NO"]]} | interview | https://www.codechef.com/problems/OPPOSITE | |
1,023 | 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 _ in range(int(input())):\n n = int(input())\n count = 1\n l = 3*(n-1)\n i = 0\n if n==1:\n print(1)\n continue\n while count<=l-n:\n for j in range(i+1):\n if j==i:\n print(count)\n count += 1\n elif... | {"inputs": [["5", "1", "2", "3", "4", "5"]], "outputs": [["1", "1", "23", "1", "23", "456", "1", "23", "4 5", "6789", "1", "23", "4 5", "6 7", "89101112"]]} | interview | https://www.codechef.com/PSTR2020/problems/ITGUY05 | |
1,024 | Note : This question carries $100$ $points$
CodeLand is celebrating a festival by baking cakes! In order to avoid wastage, families follow a unique way of distributing cakes.
For $T$ families in the locality, $i$-th family (1 <= $i$ <= $T$) has $N$ members. They baked $S$ slices of cakes. The smallest member of the fam... | ["# cook your dish here\nextra, less = 0,0\nfor _ in range(int(input())):\n sli,mem,sma,luc = list(map(int, input().split()))\n total = sma\n t = sma\n while mem > 1:\n t *= luc\n total += t\n mem -= 1\n if total <= sli:\n extra += sli-total\n print('POSSIBLE',sli-total... | {"inputs": [["5", "100 4 2 2", "100 4 3 2", "100 4 3 3", "200 4 4 2", "10 3 2 2"]], "outputs": [["POSSIBLE 70", "POSSIBLE 55", "IMPOSSIBLE 20", "POSSIBLE 140", "IMPOSSIBLE 4", "POSSIBLE"]]} | interview | https://www.codechef.com/PCO12020/problems/MORECAKE | |
1,025 | You are given a tree rooted at node $1$ with $N$ vertices. The $i$$th$ vertex initially has value $A_i (1 \leq i \leq N)$. You are also given $Q$ queries.
In each query you are given a vertex $V$. Let $S = \{ S_1 , S_2 , ... S_x \} $ denote the set of vertices such that $S_i$ is in the subtree of $V$, distance betwee... | ["from collections import defaultdict as dd,deque as dq\ndef opbfs(u,vis,ll,parr):\n q=dq([(u,0)])\n uu=u\n su=0\n while q:\n \n u,lol=q.pop()\n par=parr[u]\n if(lol%2==0):\n vis[u]=1\n su+=ll[u-1]\n ll[u-1]=0\n for j in d[u]:\n if(j!=par):\n q.appendleft((j,lol+1))\n ll[uu-1]=su\ndef bfs(height,d,parr)... | {"inputs": [["1", "4 3", "6 2 7 3", "1 2", "2 3", "3 4", "3", "2", "1"]], "outputs": [["13 5 0 0"]]} | interview | https://www.codechef.com/problems/CENS20F | |
1,026 | This is probably the simplest problem ever. You just need to count the number of ordered triples of different numbers (X1, X2, X3), where Xi could be any positive integer from 1 to Ni, inclusive (i = 1, 2, 3).
No, wait. I forgot to mention that numbers N1, N2, N3 could be up to 1018. Well, in any case it is still quite... | ["d=1000000007\nfor _ in range(int(input())):\n l=sorted(list(map(int,input().split())))\n ans=(l[0]%d)*((l[1]-1)%d)*((l[2]-2)%d)\n print(ans%d)", "# cook your dish here\nfor _ in range(int(input())):\n a=[int(x) for x in input().split()]\n a.sort()\n m=(10**9+7)\n print((a[0]*(a[1]-1)*(a[2]-2))%m)", "for _ in range(in... | {"inputs": [["5", "3 3 3", "2 4 2", "1 2 3", "25 12 2012", "1 1 2013"]], "outputs": [["6", "4", "1", "578880", "0"]]} | interview | https://www.codechef.com/problems/THREEDIF | |
1,027 | Chef recently learned about concept of periodicity of strings. A string is said to have a period P, if P divides N and for each i, the i-th of character of the string is same as i-Pth character (provided it exists), e.g. "abab" has a period P = 2, It also has a period of P = 4, but it doesn't have a period of 1 or 3.
C... | ["T=int(input())\nfor i in range(T):\n n,m=list(map(int,input().split()))\n if(m<=2):\n print(\"impossible\")\n else:\n l=[0]*m\n\n if(m%2==0):\n a=m//2\n else:\n a=(m//2)+1\n for j in range(a):\n if(j%2==0):\n l[j]=\"a\"\n l[m-j-1]=\"a\"\n \n else:\n l[... | {"inputs": [["5", "3 1", "2 2", "3 3", "4 4", "6 3"]], "outputs": [["impossible", "impossible", "aba", "abba", "abaaba"]]} | interview | https://www.codechef.com/problems/PERPALIN | |
1,028 | Chef has some numbers. His girlfriend Chefina feels good when chef gives her a particular pattern number also called as Armstrong number.
Armstrong number is a number whose sum of its all individual digit raise to the power of the number of digit in that number is equal to that number itself
eg.. 153 = 1^3 + 5^3 + 3^3 ... | ["def power(x, y):\n\tif y == 0:\n\t\treturn 1\n\tif y % 2 == 0:\n\t\treturn power(x, y // 2) * power(x, y // 2)\n\n\treturn x * power(x, y // 2) * power(x, y // 2)\n\n\n# Function to calculate order of the number\ndef order(x):\n\t# Variable to store of the number\n\tn = 0\n\twhile (x != 0):\n\t\tn = n + 1\n\t\tx = x ... | {"inputs": [["3", "153", "11", "1634"]], "outputs": [["FEELS GOOD", "FEELS BAD", "FEELS GOOD"]]} | interview | https://www.codechef.com/SPTC2020/problems/CPCEJC5 | |
1,029 | After a long and successful day of preparing food for the banquet, it is time to clean up. There is a list of n jobs to do before the kitchen can be closed for the night. These jobs are indexed from 1 to n.
Most of the cooks have already left and only the Chef and his assistant are left to clean up. Thankfully, some o... | ["T = int(input())\nfor _ in range(T):\n n,m = map(int,input().split())\n completed = list(map(int,input().split()))\n jobs = []\n for i in range(1,n+1):\n if i not in completed:\n jobs.append(i)\n jobs.sort()\n chef = []\n ass = []\n for i in range(len(jobs)):\n if i%2==0:\n chef.append(str(jobs[i]))\n else:\n ... | {"inputs": [["3", "6 3", "2 4 1", "3 2", "3 2", "8 2", "3 8"]], "outputs": [["3 6", "5", "1", "1 4 6", "2 5 7"]]} | interview | https://www.codechef.com/problems/CLEANUP | |
1,030 | Let's consider a rooted binary tree with the following properties:
- The number of nodes and edges in the tree is infinite
- The tree root is labeled by $1$
- A node labeled by $v$ has two children: $2 \cdot v$ (the left child of $v$), and $2 \cdot v + 1$ (the right child of $v$).
Here is an image of the first several ... | ["t = int(input())\nwhile(t>0):\n t-=1;\n n,l,r = list(map(int,input().split()));\n a = bin(l)[2:];\n b = bin(r)[2:];\n # find matching\n z = 0;\n l = min(len(a),len(b));\n for i in range(l):\n if a[i]==b[i]:\n z+=1;\n else:\n break;\n\n #find base string\n a = a[z:]\n b = b[z:]\n if(len(a)==0 and len(b)==0):\n ... | {"inputs": [["3", "11 9 11", "10 2 2", "8 1 8"]], "outputs": [["2", "10", "1"]]} | interview | https://www.codechef.com/COOK69/problems/BINTREEQ | |
1,031 | Chef taught his brother Chefu about right angled triangle and its properties. Chefu says that he has understood everything about right angled triangles. Chef wants to check learning of his brother by asking the following question "Can you find a right angled triangle whose length of hypotenuse is H and its area is S?"... | ["import math\nt = eval(input())\nwhile(t > 0):\n h,s = input().split()\n h = int(h)\n s = int(s)\n if(((h*h*h*h) - (16*s*s)) < 0):\n print(\"-1\")\n else:\n B = (math.sqrt((h*h) + math.sqrt((h*h*h*h) - (16*s*s))))/math.sqrt(2)\n P = (2*s)/B\n if(B > P):\n print('{0:.6f}'.format(P),'{0:.6f}'.format(B),'{0:.6f}'.f... | {"inputs": [["4", "5 6", "6 10", "258303 89837245228", "616153 77878145466"]], "outputs": [["3.00000 4.00000 5.00000", "-1", "-1", "285168.817674 546189.769984 616153.000000"]]} | interview | https://www.codechef.com/COOK71/problems/RIGHTTRI | |
1,032 | Help Saurabh with his Chemistry Assignment.
Saurabh has been given a chemistry assignment by Ruby Mam. Though the assignment is simple but
Saurabh has to watch India vs Pakistan Match and he has no time to do the assignment by himself.
So Saurabh wants you to do his assignment so that he doesn’t get scolded by Ruby ... | ["a = [1]\nM = 10**6 + 3\nfor ii in range(1, 1000005):\n a.append((a[-1]*ii)%M)\nfor __ in range(eval(input())):\n n, x = list(map(int, input().split()))\n if n>=M: print(0)\n else: print((a[n]*x)%M)\n", "# your code goes here\nmod=1000003\nfact=[0]*mod\nfact[0]=1\nfor i in range(1,mod):\n fact[i]=(fact[i-1]*i)%mod\nt=... | {"inputs": [["2", "1 2", "2 1"]], "outputs": [["2", "2"]]} | interview | https://www.codechef.com/REC2016/problems/RECIICHA | |
1,033 | Given the values at the leaf nodes of a complete binary tree. The total number of nodes in the binary tree, is also given. Sum of the values at both the children of a node is equal to the value of the node itself. You can add any value or subtract any value from a node. Print the minimum change(difference made) in the ... | ["print(0)"] | {"inputs": [["1:", "Input:", "1", "50"]], "outputs": [["0"]]} | interview | https://www.codechef.com/KM252020/problems/KM25P5C | |
1,034 | A manufacturing project consists of exactly $K$ tasks. The board overviewing the project wants to hire $K$ teams of workers — one for each task. All teams begin working simultaneously.
Obviously, there must be at least one person in each team. For a team of $A$ workers, it takes exactly $A$ days to complete the task th... | ["from math import log2;\nimport bisect;\nfrom bisect import bisect_left,bisect_right\nimport sys;\nfrom math import gcd,sqrt\nsys.setrecursionlimit(10**7)\nfrom collections import defaultdict\ninf=float(\"inf\")\n# n=int(input())\n# n,m=map(int,input().split())\n# l=list(map(int,input().split()))\ndef get_factors(x):\... | {"inputs": [["2", "2 3", "2 6"]], "outputs": [["4", "5"]]} | interview | https://www.codechef.com/problems/HIRINGWO | |
1,035 | Mathison and Chef are playing a new teleportation game. This game is played on a $R \times C$ board where each cell $(i, j)$ contains some value $V_{i, j}$. The purpose of this game is to collect a number of values by teleporting from one cell to another. A teleportation can be performed using a tel-pair.
A player is g... | ["# cook your dish here\nfrom collections import namedtuple\n\nCurrentPosition = namedtuple('current_position', 'points, cell, pairs')\n\nT = int(input())\nfor _ in range(T):\n R, C, N = map(int, input().split())\n Sx, Sy = map(int, input().split())\n tx = map(int, input().split())\n ty = map(int, input().s... | {"inputs": [["3", "5 5 2", "2 2", "1 2", "2 1", "10 11 62 14 15", "57 23 34 75 21", "17 12 14 11 53", "84 61 24 85 22", "43 89 14 15 43", "3 3 2", "0 0", "1 1", "1 1", "9 8 7", "5 6 4", "1 3 2", "2 2 1", "1 1", "2", "2", "5 6", "8 3"]], "outputs": [["188", "24", "3"]]} | interview | https://www.codechef.com/problems/MATTEG | |
1,036 | Consider a 2d-grid. That is, each cell is identified by (i,j). You have received reports of two snake-sightings on this grid. You want to check whether they could be partial sightings of the same snake or not.
Each of the snake sightings correspond to a straight, axis-parallel line segment in the grid, and the starting... | ["# cook your dish here\nt=int(input())\nfor _ in range(t):\n x1,y1,x2,y2=map(int,input().split())\n x3,y3,x4,y4=map(int,input().split())\n if (x1==x3 and y1==y3)or(x2==x4 and y2==y4):\n print(\"yes\")\n elif (x1==x4 and y1==y4)or(x2==x3 and y2==y3):\n print(\"yes\")\n else:\n if(y1==y2)and(y1==y3)and(y1==y4):\n a... | {"inputs": [["4", "2 1 8 1", "11 1 7 1", "2 1 8 1", "11 1 9 1", "2 1 8 1", "3 1 3 -2", "2 1 8 1", "2 1 2 -2"]], "outputs": [["yes", "no", "no", "yes"]]} | interview | https://www.codechef.com/problems/SAMESNAK | |
1,037 | Ada is playing pawn chess with Suzumo.
Pawn chess is played on a long board with N$N$ squares in one row. Initially, some of the squares contain pawns.
Note that the colours of the squares and pawns do not matter in this game, but otherwise, the standard chess rules apply:
- no two pawns can occupy the same square at t... | ["for _ in range(int(input())):\n s = input().strip()\n a = []\n last = 0\n for i in range(len(s)):\n if s[i] == 'P':\n a.append(i - last)\n last = i + 1\n x = 0\n a = a[::-1]\n for v in a[::2]:\n x ^= v % 3\n print('Yes' if x else 'No')"] | {"inputs": [["1", "..P.P"]], "outputs": [["Yes"]]} | interview | https://www.codechef.com/problems/ADAPWNS | |
1,038 | Two's company, three's a crowd!
It's been one year since Chef met his brother. Last year, his younger brother came to visit him during this time of the year. This year, the Chef is planning to go visit his brother. Chef's brother has planned to throw a "Welcome Party" for him. He wants to invite people from his neighbo... | ["MOD = int(1e9+7)\n\ndef mult(a, b):\n rsp = [[0, 0, 0],\n [0, 0, 0],\n [0, 0, 0]]\n\n for i in range(3):\n for j in range(3):\n for k in range(3):\n rsp[i][j] += a[i][k] * b[k][j]\n rsp[i][j] %= MOD\n\n return rsp\n\nident = [[1, 0, 0],\n [0, 1, 0],\n [0, 0, 1]]\nm = [[1, 1, 0],\n [1, 0, 1],\n [1, ... | {"inputs": [["2", "3", "4"]], "outputs": [["1", "3"]]} | interview | https://www.codechef.com/problems/CROWD | |
1,039 | “I am not in danger, Skyler. I am the danger. A guy opens his door and gets shot, and you think that of me? No! I am the one who knocks!”
Skyler fears Walter and ponders escaping to Colorado. Walter wants to clean his lab as soon as possible and then go back home to his wife.
In order clean his lab, he has to achieve ... | ["t=int(input())\nfor i in range(t):\n ans=0\n x,y=list(map(int,input().split()))\n if y>x:\n if (y-x)%4==0:ans=3\n elif (y-x)%2==0: ans=2\n else: ans=1\n if y<x:\n if (y-x)%2==0:ans=1\n else: ans=2\n print(ans)\n", "# cook your dish here\nfor _ in range(int(input())):\n x,y = map(int,input().split())\n if x == y:... | {"inputs": [["3", "0 5", "4 -5", "0 10000001"]], "outputs": [["1", "2", "1"]]} | interview | https://www.codechef.com/problems/EOOPR | |
1,040 | A string with length $L$ is called rich if $L \ge 3$ and there is a character which occurs in this string strictly more than $L/2$ times.
You are given a string $S$ and you should answer $Q$ queries on this string. In each query, you are given a substring $S_L, S_{L+1}, \ldots, S_R$. Consider all substrings of this sub... | ["t=int(input())\n\nfor _ in range(t):\n n,q=map(int,input().split())\n s=input()\n l=[0]*(n-1)\n for i in range(n-2):\n a,b,c=s[i],s[i+1],s[i+2]\n if len(set([a,b,c]))<3:\n l[i]=l[i-1]+1\n else:\n l[i]=l[i-1]\n \n for i in range(q):\n left,right=map(int,input().split())\n left-=1\n right-=1\n if right-lef... | {"inputs": [["1", "10 2", "helloworld", "1 3", "1 10"]], "outputs": [["NO", "YES"]]} | interview | https://www.codechef.com/problems/RICHSTR | |
1,041 | Ripul was skilled in the art of lapidary. He used to collect stones and convert it into decorative items for sale. There were n stone shops. Each shop was having one exclusive stone of value s[i] , where 1<=i<=n. If number of stones collected are more than 1, then total value will be product of values of all the ston... | ["# cook your dish here\nfor u in range(int(input())):\n n=int(input())\n l=list(map(int,input().split()))\n d=[]\n dd=[]\n s=1\n for i in range(n-1):\n s=l[i]\n d.append(s)\n dd.append([i,i])\n for j in range(i+1,n):\n s=s*l[j]\n d.append(s)\n dd.append([i,j])\n d.append(l[n-1])\n dd.append([n-1,n-1])\n k=le... | {"inputs": [["1", "3", "1 2 3"]], "outputs": [["6 1 2"]]} | interview | https://www.codechef.com/COH12020/problems/RIPUGEMS | |
1,042 | Chef wants to gift pairs to his friends this new year. But his friends like good pairs
only.
A pair (a , b) is called a good pair if 1 <= a < b <= N such that GCD(a*b , P) = 1.
Since Chef is busy in preparation for the party, he wants your help to find all the
good pairs.
—————————————————————————————————————
INPUT
• T... | ["# cook your dish here\n \ndef G(x, y): \n while(y): \n x, y = y, x % y \n return x \n# t=int(input())\n# l=list(map(int,input().split()))\nfor _ in range(int(input())):\n n,p=map(int,input().split())\n\n c=0\n for i in range(1,n+1):\n if G(i,p)==1:\n c+=1\n ans=c*(c-1)//2\n ... | {"inputs": [["2", "2 3", "3 3", "\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014\u2014"]], "outputs": [["1", "1"]]} | interview | https://www.codechef.com/NITJ2021/problems/CIN004 | |
1,043 | Forgotten languages (also known as extinct languages) are languages that are no longer in use. Such languages were, probably, widely used before and no one could have ever imagined that they will become extinct at some point. Unfortunately, that is what happened to them. On the happy side of things, a language may be d... | ["test_case = int(input())\nfor w in range(test_case):\n n, k = map(int,input().split())\n l = list(map(str,input().split()))\n ans = []\n for q in range(k):\n l2 = list(map(str,input().split()))\n ans.extend(l2[1:])\n for i in l:\n if i in ans:\n print('YES',end=' ')\n else:\n print('NO',end=' ')\n print()# co... | {"inputs": [["2", "3 2", "piygu ezyfo rzotm", "1 piygu", "6 tefwz tefwz piygu ezyfo tefwz piygu", "4 1", "kssdy tjzhy ljzym kegqz", "4 kegqz kegqz kegqz vxvyj"]], "outputs": [["YES YES NO", "NO NO NO YES"]]} | interview | https://www.codechef.com/problems/FRGTNLNG | |
1,044 | You're given an integer N. Write a program to calculate the sum of all the digits of N.
-----Input-----
The first line contains an integer T, the total number of testcases. Then follow T lines, each line contains an integer N.
-----Output-----
For each test case, calculate the sum of digits of N, and display it in... | ["# cook your dish here\nnumber = int(input())\nfor i in range(number):\n a = list(input())\n for k in range(len(a)):\n a[k] = eval(a[k])\n print(sum(a))", "T=int(input())\nwhile(T!=0):\n t=int(input())\n sum=0\n while(t!=0):\n a=t%10\n sum=sum+a\n t=t//10\n print(sum)\n... | {"inputs": [["3", "12345", "31203", "2123"]], "outputs": [["15", "9", "8"]]} | interview | https://www.codechef.com/problems/FLOW006 | |
1,045 | You are given Name of chef's friend and using chef's new method of calculating value of string , chef have to find the value of all the names. Since chef is busy , he asked you to do the work from him .
The method is a function $f(x)$ as follows -
-
$f(x)$ = $1$ , if $x$ is a consonent
-
$f(x)$ = $0$ , if $x$ is a v... | ["\n\nvow = ['a', 'e', 'i','o', 'u']\nfor _ in range(int(input())):\n name = str(input())\n tmp = ''\n for i in range(len(name)):\n if name[i] not in vow and name[i].isalpha():\n tmp+='1'\n elif name[i] in vow and name[i].isalpha():\n tmp+='0'\n \n print( int(tmp, 2)% (10**9 + 7))", "# cook your dish here\nt = i... | {"inputs": [["1", "codechef"]], "outputs": [["173"]]} | interview | https://www.codechef.com/LDT42020/problems/NAMEVAL | |
1,046 | Bears love candies and games involving eating them. Limak and Bob play the following game. Limak eats 1 candy, then Bob eats 2 candies, then Limak eats 3 candies, then Bob eats 4 candies, and so on. Once someone can't eat what he is supposed to eat, he loses.
Limak can eat at most A candies in total (otherwise he would... | ["for t in range(int(input())):\n limakMax, bobMax = list(map(int, input().split()))\n limakEat = 0; bobEat = 0\n eating = 1\n while limakEat <= limakMax or bobEat <= bobMax:\n\n if eating % 2 != 0 and limakEat <= limakMax:\n limakEat += eating\n eating += 1\n if limakEat > limakMax:\n print(\"Bob\")\n bre... | {"inputs": [["10", "3 2", "4 2", "1 1", "1 2", "1 3", "9 3", "9 11", "9 12", "9 1000", "8 11"]], "outputs": [["Bob", "Limak", "Limak", "Bob", "Bob", "Limak", "Limak", "Bob", "Bob", "Bob"]]} | interview | https://www.codechef.com/problems/CANDY123 | |
1,047 | Chef bought a huge (effectively infinite) planar island and built $N$ restaurants (numbered $1$ through $N$) on it. For each valid $i$, the Cartesian coordinates of restaurant $i$ are $(X_i, Y_i)$.
Now, Chef wants to build $N-1$ straight narrow roads (line segments) on the island. The roads may have arbitrary lengths; ... | ["import sys\n\ndef input(): return sys.stdin.readline().strip()\ndef iinput(): return int(input())\ndef rinput(): return list(map(int, sys.stdin.readline().strip().split())) \ndef get_list(): return list(map(int, sys.stdin.readline().strip().split()))\n\n\nt=iinput()\n\nfor _ in range(t):\n n=iinput()\n p=[]\n ... | {"inputs": [["2", "3", "0 0", "0 1", "0 -1", "3", "0 1", "1 0", "-1 0"]], "outputs": [["0.5", "0"]]} | interview | https://www.codechef.com/problems/WTBTR | |
1,048 | There are three squares, each with side length a placed on the x-axis. The coordinates of centers of these squares are (x1, a/2), (x2, a/2) and (x3, a/2) respectively. All of them are placed with one of their sides resting on the x-axis.
You are allowed to move the centers of each of these squares along the x-axis (eit... | ["t=int(input())\nfor i in range(t):\n a,k=list(map(int,input().split()))\n x1,x2,x3=list(map(int,input().split()))\n big=max(x1,x2,x3)\n small=min(x1,x2,x3)\n q=big-small-2*k\n \n if q>=a:\n print(0)\n elif -1*q>=0:\n print(a*a)\n else:\n print(a*(a-q))\n", "t=int(input())\nfor i in range(t):\n a,k=list(map(int,inp... | {"inputs": [["3", "1 0", "1 2 3", "1 1", "1 2 3", "1 1", "1 4 6"]], "outputs": [["0.000000", "1.0000", "0.0"]]} | interview | https://www.codechef.com/problems/TALESQUA | |
1,049 | -----
ARRAY AND DISTINCT ELEMENTS
-----
Chef is multitalented but he mistakenly took part in 2 contest which will take place
at the same time. So while chef is busy at one cooking contest, he wants you to
take part in coding contest. Chef wants u to solve this program for him.
You have been given an array of size ... | ["#\n\nfor _ in range(int(input())):\n n,k = list(map(int,input().split()))\n arr = list(map(int,input().split()))\n s=set(arr)\n t1=len(s)\n max=-1\n for i in range(n-k+1):\n temp=set(arr[i:i+k])\n #print(temp,i,k+i+1)\n t=len(temp)\n if t1 == t:\n if max<sum(arr[i:k+i]):\n max=sum(arr[i:k+i])\n print(max)\n"... | {"inputs": [["1", "10 6", "8 8 3 5 3 8 5 7 7 7"]], "outputs": [["37"]]} | interview | https://www.codechef.com/APO12020/problems/APOC2_02 | |
1,050 | Lira is now very keen on compiler development. :)
She knows that one of the most important components of a compiler, is its parser.
A parser is, in simple terms, a software component that processes text, and checks it's semantic correctness, or, if you prefer, if the text is properly built.
As an example, in declaring... | ["# cook your dish here\nt=int(input())\nfor j in range(t):\n s=input()\n st=[]\n ans=0\n\n for i in range(len(s)):\n \n if(s[i]=='>'):\n if(len(st)!=0 and st[-1]=='<'):\n st.pop()\n if(len(st)==0):\n ans=i+1\n else:\n ... | {"inputs": [["3", "<<>>", "><", "<>>>", ""]], "outputs": [["4", "0", "2"]]} | interview | https://www.codechef.com/problems/COMPILER | |
1,051 | The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single line of ... | ["# cook your dish here\nt=int(input())\nfor i in range(0,t):\n my_ip = int(input().strip())\n for xyz in range(my_ip+1):\n for abc in range(0,xyz+1):\n if abc == xyz:\n print(xyz,end=\"\")\n else:\n print('*',end=\"\")\n\n print()", "# cook your d... | {"inputs": [["3", "2", "3", "4", ""]], "outputs": [["0", "*1", "**2", "0", "*1", "**2", "***3", "0", "*1", "**2", "***3", "****4"]]} | interview | https://www.codechef.com/PTRN2020/problems/ITGUY38 | |
1,052 | You are given positive integers $N$ and $D$. You may perform operations of the following two types:
- add $D$ to $N$, i.e. change $N$ to $N+D$
- change $N$ to $\mathop{\mathrm{digitsum}}(N)$
Here, $\mathop{\mathrm{digitsum}}(x)$ is the sum of decimal digits of $x$. For example, $\mathop{\mathrm{digitsum}}(123)=1+2+3=6$... | ["from collections import deque \r\nT=int(input())\r\ndef break_down(num):\r\n count=0\r\n while(len(num)!=1):\r\n temp=0\r\n for i in range(0,len(num)):\r\n temp=temp+int(num[i])\r\n num=str(temp)\r\n count=count+1\r\n return (int(num),count)\r\ndef digit_sum(num):\r\n ... | {"inputs": [["3", "2 1", "9 3", "11 13", ""]], "outputs": [["1 9", "3 2", "1 4"]]} | interview | https://www.codechef.com/problems/MINDSUM | |
1,053 | Chef has a binary array in an unsorted manner. Cheffina challenges chef to find the transition point in the sorted (ascending) binary array. Here indexing is starting from 0.
Note: Transition point always exists.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- E... | ["# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n A=list(map(int,input().split()))\n A.sort()\n for i in range(len(A)):\n if A[i]==1:\n print(i)\n break", "for x in range(int(input())):\n n = int(input())\n S = list(map(int,input().split()))\n in... | {"inputs": [["1", "5", "0 1 0 0 1", ""]], "outputs": [["3"]]} | interview | https://www.codechef.com/PSTR2020/problems/ANITGUY5 | |
1,054 | Chef likes strings a lot but he likes palindromic strings even more. Today he found an old string s in his garage. The string is so old that some of its characters have faded and are unidentifiable now. Faded characters in the string are represented by '.' whereas other characters are lower case Latin alphabets i.e ['a... | ["test=int(input())\nfor i in range(test):\n s=input()\n b=len(s)\n list1=[]\n for j in range(len(s)):\n if s[j]=='.':\n list1.append(j)\n for i in list1:\n if b-i-1 in list1 :\n if i!=b-i-1 and ((s[i] and s[b-i-1]) != 'a' ):\n s=s[:i]+'a'+s[i+1:b-i-1]+'... | {"inputs": [["3", "a.ba", "cb.bc", "a.b"]], "outputs": [["abba", "cbabc", "-1"]]} | interview | https://www.codechef.com/problems/LEXOPAL | |
1,055 | Chef is planning a huge party for all of you and has ordered M pizzas. He wants to invite as many people to the party. However, he knows that everyone will have exactly one slice of a pizza (regardless of the size) and he wants to make sure that he has enough pizza slices.
Chef is very lazy and will only make a total ... | ["# cook your dish here\r\nm,n=[int(i) for i in input().split()]\r\narr=list(map(int,input().split()))\r\narr=sorted(arr,reverse=True)\r\nans=0\r\nw=0\r\nq=m\r\nfor m in range(q):\r\n if(arr[m]>n):\r\n w=1\r\n break \r\n ans+=1+(arr[m]*(arr[m]+1))//2\r\n n-=arr[m]\r\n\r\nif(n==0):\r\n print(an... | {"inputs": [["5 10", "1 2 3 4 5", ""]], "outputs": [["31"]]} | interview | https://www.codechef.com/problems/PIZPAR | |
1,056 | Write a program to check whether a triangle is valid or not, when the three angles of the triangle are the inputs. A triangle is valid if the sum of all the three angles is equal to 180 degrees.
-----Input-----
The first line contains an integer T, the total number of testcases. Then T lines follow, each line contain... | ["n=int(input())\nfor i in range(n):\n a,b,c=map(int,input().split())\n if a>0 and b>0 and c>0 and a+b+c==180:\n print(\"YES\")\n else:\n print(\"NO\")", "for _ in range (int(input())):\n a,b,c = map(int,input().split())\n if a+b+c==180:\n print(\"YES\")\n else:\n print(\"N... | {"inputs": [["3 ", "40 40 100", "45 45 90", "180 1 1", ""]], "outputs": [["YES", "YES", "NO"]]} | interview | https://www.codechef.com/problems/FLOW013 | |
1,057 | Alice is a very brilliant student. He considers '4' and '7' as Magic numbers. The numbers containing only magic numbers are also magical. Given a magic number N ,he wants to know what could be the next magical number greater than the given number.
-----Input-----
First line of input contains number of test cases T. F... | ["import math\n\ndef magic(a,digits):\n m=a%10\n if(m==4):\n return a+3\n elif(m==7):\n p=list(str(a))\n #print p\n for i in range(digits-1,-1,-1):\n #print p[i]\n if (p[i]=='4'):\n #print 'four'\n p[i]='7'\n p = ''.... | {"inputs": [["2", "4", "47", "", ""]], "outputs": [["7", "74"]]} | interview | https://www.codechef.com/ALKH2012/problems/NMAGIC | |
1,058 | There is a popular apps named “Exbook” like “Facebook”. To sign up in this app , You have to make a strong password with more than 3 digits and less than 10 digits . But I am a pro hacker and so I make a Exbook hacking site . You need to login in this site to hack exbook account and then you will get a portal. You can ... | ["# cook your dish here\nt=int(input())\nfor i in range(0,t):\n p=input()\n l=list(p)\n for j in range(0,len(l)):\n l[j]=int(l[j])\n l[j]=l[j]-2\n for j in range(0,len(l)):\n l[j]=str(l[j])\n q=''.join(l)\n print(q)", "t=int(input())\nfor i in range(t):\n n=input()\n l=len(n... | {"inputs": [["2", "3527", "47269"]], "outputs": [["1305", "25047"]]} | interview | https://www.codechef.com/ABCC2020/problems/PASSHACK | |
1,059 | You have an array A of size N containing only positive numbers. You have to output the maximum possible value of A[i]%A[j] where 1<=i,j<=N.
-----Input-----
The first line of each test case contains a single integer N denoting the size of the array. The next N lines contains integers A1, A2, ..., AN denoting the numbe... | ["n = int(input())\na = []\nfor i in range(n):\n a.append(int(input()))\nm1 = 0\nm2 = 0\nfor e in a:\n if (e > m1):\n m2 = m1\n m1 = e\n elif (e > m2 and e != m1):\n m2 = e\nans = 0\nfor e in a:\n temp = m1%e\n if (temp>ans):\n ans = temp\nprint(max(m2%m1,ans))", "__author__ = 'Hacktivist'\n\nfrom sys import stdin\... | {"inputs": [["2", "1", "2"]], "outputs": [["1"]]} | interview | https://www.codechef.com/LOCMAR16/problems/MOD | |
1,060 | Chef and Abhishek both are fighting for the post of Chairperson to be part of ACE committee and are trying their best. To select only one student their teacher gave them a binary string (string consisting of only 0's and 1's) and asked them to find number of sub-strings present in the given string that satisfy the foll... | ["def countSubstr(str, n, x, y): \r\n \r\n tot_count = 0\r\n \r\n count_x = 0\r\n \r\n for i in range(n): \r\n if str[i] == x: \r\n count_x += 1\r\n if str[i] == y: \r\n tot_count += count_x \r\n return tot_count \r\n \r\nt=int(input())\r\nfor _ in range(t):\r\n n... | {"inputs": [["1", "4", "1010"]], "outputs": [["4"]]} | interview | https://www.codechef.com/CEFT2020/problems/QFUN | |
1,061 | Chef is playing with an expression which consists of integer operands and the following binary
Bitwise operators - AND, OR and XOR. He is trying to figure out that what could be the Maximum possible answer of the expression, given that he can perform the operation in any order i.e not necessarily follow the rule of Pr... | ["# cook your dish here\ndef value(a, b, c):\n if(c == '&'):\n return a&b\n elif(c == '^'):\n return a^b\n elif(c == '|'):\n return a|b\n\ndef break_rules(n, operator):\n if(len(n) == 1):\n return n\n elif(len(n) == 2):\n return [value(n[0], n[1], operator[0])]\n els... | {"inputs": [["2", "3^40|10^2", "92^95|56&2&3"]], "outputs": [["43", "95"]]} | interview | https://www.codechef.com/problems/BIT2C | |
1,062 | Ho, Ho, Ho!
It's Christmas time and our friendly grandpa Santa Claus is busy distributing gifts to all the nice children. With the rising population, Santa's workload every year gets increased and he seeks your help to wrap the gifts with fancy wrapping papers while he gets them distributed.
Everything was going great... | ["# cook your dish here\ndef read_i_l(l=False):\n m = list(map(int, input().strip().split(\" \")))\n if l:\n return list(m)\n else:\n return m\ndef i():\n return int(input().strip())\nT = i()\nL = []\n\"\"\"for current in range(T):\n line = \"\"\n for i in range(current):\n line+=... | {"inputs": [["4"]], "outputs": [["4 4 4 4 4 4 4", "4 3 3 3 3 3 4", "4 3 2 2 2 3 4", "4 3 2 1 2 3 4", "4 3 2 2 2 3 4", "4 3 3 3 3 3 4", "4 4 4 4 4 4 4"]]} | interview | https://www.codechef.com/NQST2020/problems/ICEWRAP | |
1,063 | Write a program to find the remainder when an integer A is divided by an integer B.
-----Input-----
The first line contains an integer T, the total number of test cases. Then T lines follow, each line contains two Integers A and B.
-----Output-----
For each test case, find the remainder when A is divided by B, and... | ["number = int(input())\nfor i in range(number):\n x = list(map(int, input().split(' ')))\n print(x[0]%x[1])", "t = int(input())\n\nfor x in range(0, t):\n a, b = input().split()\n rem = int(a) % int(b)\n print(int(rem), \"\\n\")", "t = int(input())\n\nfor x in range(0, t):\n a, b = input().split()\n ... | {"inputs": [["3", "1 2", "100 200", "40 15"]], "outputs": [["1", "100", "10"]]} | interview | https://www.codechef.com/problems/FLOW002 | |
1,064 | Chef Ciel wants to put a fancy neon signboard over the entrance of her restaurant. She has not enough money to buy the new one so she bought some old neon signboard through the internet. Ciel was quite disappointed when she received her order - some of its letters were broken. But she realized that this is even better ... | ["from math import gcd\nimport sys\ninput=lambda : sys.stdin.readline().strip()\nc=lambda x: 10**9 if(x==\"?\") else int(x)\ndef main():\n for _ in range(int(input())):\n s=list(input())[::-1]\n l=['F','E','H','C']\n i=0\n while(i<len(s)):\n if(i+3<len(s)):\n f=True\n for j in range(i,i+4):\n if(l[j-i]=... | {"inputs": [["5", "????CIELIS???E?", "????CIELISOUR???F", "T?KEITE?SY", "????????", "???C???"]], "outputs": [["CHEFCIELISACHEF", "CHEFCIELISOURCHEF", "TAKEITEASY", "CHEFCHEF", "AAACHEF"]]} | interview | https://www.codechef.com/problems/MANYCHEF | |
1,065 | Chefland is a grid with N$N$ rows and M$M$ columns. Each cell of this grid is either empty or contains a house. The distance between a pair of houses is the Manhattan distance between the cells containing them.
For each d$d$ between 1$1$ and N+M−2$N+M-2$ inclusive, Chef wants to calculate the number of unordered pairs ... | ["# cook your dish here\nfor a in range(int(input())):\n N,M=map(int,input().split())\n b=[]\n for o in range(N):\n b.append(input())\n c=[]\n for d in b:\n f=[]\n for e in range(len(d)):\n if d[e]=='1':\n f.append(e)\n c.append(f)\n i=[]\n for g in range(len(c)):\n f... | {"inputs": [["1", "3 4", "0011", "0000", "0100"]], "outputs": [["1 0 1 1 0"]]} | interview | https://www.codechef.com/problems/AVGMAT | |
1,066 | -----
CHEF N TIMINGS
-----
One day chef was working with some random numbers. Then he found something
interesting. He observed that no 240, 567, 9999 and 122 and called these numbers
nice as the digits in numbers are in increasing order. Also he called 434, 452, 900
are not nice as digits are in decreasing order
N... | ["for _ in range(int(input())):\n n=input().rstrip()\n n=[ele for ele in n]\n l=len(n)\n m=10**18+8\n ini=1\n for i in range(l-1,-1,-1):\n if int(n[i])<=m:\n if ini==1:\n m=int(n[i])\n else:\n m=max(m,n[i])\n else:\n m=int(n[i])-1\n n[i]=str(m)\n for j in range(l-1,i,-1):\n n[j]='9'\n \n i=0\n wh... | {"inputs": [["1", "132"]], "outputs": [["129"]]} | interview | https://www.codechef.com/APO12020/problems/APOC2_04 | |
1,067 | Chef has a strip of length $N$ units and he wants to tile it using $4$ kind of tiles
-A Red tile of $2$ unit length
-A Red tile of $1$ unit length
-A Blue tile of $2$ unit length
-A Blue tile of $1$ unit length
Chef is having an infinite supply of each of these tiles. He wants to find out the number of ways in w... | ["# Fibonacci Series using \r\n# Optimized Method \r\n\r\n# function that returns nth \r\n# Fibonacci number\r\nMOD = 1000000007\r\ndef fib(n):\r\n F = [[2, 2],\r\n [1, 0]]\r\n power(F, n - 1)\r\n ans = [6, 2]\r\n return (F[0][0] * 6 + F[0][1] * 2) % MOD\r\n # return F[0][0]\r\n\r\n\r\ndef multip... | {"inputs": [["1", "2"]], "outputs": [["6"]]} | interview | https://www.codechef.com/COG2020/problems/COG2004 | |
1,068 | Ada's classroom contains $N \cdot M$ tables distributed in a grid with $N$ rows and $M$ columns. Each table is occupied by exactly one student.
Before starting the class, the teacher decided to shuffle the students a bit. After the shuffling, each table should be occupied by exactly one student again. In addition, each... | ["# cook your dish here\nt=int(input())\nfor _ in range(t):\n N, M=map(int,input().split())\n if(N%2==0 or M%2==0):\n print(\"YES\")\n else:\n print(\"NO\")", "# cook your dish here\nt=int(input())\nfor _ in range(t):\n N, M=map(int,input().split())\n if(N%2==0 or M%2==0):\n print(\"YES\")\n else:\n print(\"NO\")",... | {"inputs": [["2", "3 3", "4 4"]], "outputs": [["NO", "YES"]]} | interview | https://www.codechef.com/problems/ADASCOOL | |
1,069 | Shivam is the youngest programmer in the world, he is just 12 years old. Shivam is learning programming and today he is writing his first program.
Program is very simple, Given two integers A and B, write a program to add these two numbers.
-----Input-----
The first line contains an integer T, the total number of t... | ["#Note that it's python3 Code. Here, we are using input() instead of raw_input().\n#You can check on your local machine the version of python by typing \"python --version\" in the terminal.\n\n#Read the number of test cases.\nT = int(input())\nfor tc in range(T):\n\t# Read integers a and b.\n\t(a, b) = list(map(int, i... | {"inputs": [["3", "1 2", "100 200", "10 40"]], "outputs": [["3", "300", "50"]]} | interview | https://www.codechef.com/problems/FLOW001 | |
1,070 | and Bengali as well.
There are N$N$ cats (numbered 1$1$ through N$N$) and M$M$ rats (numbered 1$1$ through M$M$) on a line. Each cat and each rat wants to move from some point to some (possibly the same) point on this line. Naturally, the cats also want to eat the rats when they get a chance. Both the cats and the rats... | ["# cook your dish here\n# cook your dish here\nclass Animal:\n def __init__(self):\n start, end, starting_time = map(int, input().split())\n \n self.ending_time = starting_time + abs(start - end)\n self.velocity = 1 if end >= start else -1 \n \n self.eaten_by = -1, 10 ** 10... | {"inputs": [["2", "8 7", "2 5 1", "1 4 1", "9 14 10", "20 7 9", "102 99 1", "199 202 1", "302 299 3", "399 402 3", "6 3 1", "10 15 10", "100 101 1", "201 200 1", "300 301 5", "401 400 5", "1000 1010 1020", "8 8", "2 8 2", "12 18 2", "22 28 4", "32 38 4", "48 42 2", "58 52 3", "68 62 1", "78 72 3", "3 6 3", "13 19 3", "... | interview | https://www.codechef.com/problems/CATSRATS | |
1,071 | Bob just learned about bitwise operators. Since Alice is an expert, she decided to play a game, she will give a number $x$ to Bob and will ask some questions:
There will be 4 different kinds of queries:-
-
Alice gives an integer $i$ and Bob has to report the status of the $i^{th}$ bit in $x$, the answer is $"ON"$ if i... | ["# cook your dish here\nt=int(input())\nwhile t>0:\n n,q=list(map(int,input().split()))\n blst=[0]\n for i in range(1,65):\n blst.append(0)\n i=1\n while n>0:\n if n%2:\n blst[i]=1\n n//=2\n i+=1\n while q>0:\n n=int(input())\n if n==1:\n ... | {"inputs": [["1", "2 2", "2", "1", "1", "1"]], "outputs": [["ON"]]} | interview | https://www.codechef.com/ENDE2020/problems/ENCDEC03 | |
1,072 | Problem description.
Winston and Royce love sharing memes with each other. They express the amount of seconds they laughed ar a meme as the number of ‘XD’ subsequences in their messages. Being optimization freaks, they wanted to find the string with minimum possible length and having exactly the given number of ‘XD’ su... | ["t=int(input())\nfor i in range(t):\n n=int(input())\n r=int(n**(.5))\n d=n-r*r\n m=d%r\n print('X'*m+'D'*(m>0)+'X'*(r-m)+'D'*(r+d//r))\n", "from math import sqrt\n\ndef solve():\n n = int(input())\n \n k = int(sqrt(n))\n \n y = n - k * k\n \n z = y % k\n \n if z > 0:\n print('X'*z+'D'+'X'*(k - z)+'D'*(k+y//k))\n els... | {"inputs": [["1", "9"]], "outputs": [["XXXDDD"]]} | interview | https://www.codechef.com/problems/XDS | |
1,073 | You are given two integers $N$ and $M$. Find the number of sequences $A_1, A_2, \ldots, A_N$, where each element is an integer between $1$ and $M$ (inclusive) and no three consecutive elements are equal. Since this number could be very large, compute it modulo $10^9+7$.
-----Input-----
- The first line of the input co... | ["import sys\ndef fin(): return sys.stdin.readline().strip()\ndef fout(s, end=\"\\n\"): sys.stdout.write(str(s)+end)\n\nMOD = pow(10, 9)+7\nt = int(input())\nwhile t>0:\n t -= 1\n n, m = list(map(int, fin().split()))\n if n == 1:\n print(m%MOD)\n continue\n dp1 = m*(m-1)\n dp2 = m\n for i in range(3, n+1):\n temp = ... | {"inputs": [["2", "2 2", "3 4"]], "outputs": [["4", "60"]]} | interview | https://www.codechef.com/problems/CARR | |
1,074 | Chef is making Window frames for his new office, for this he has n wooden Logs whose lengths are l1, l2, … ln respectively. Chef Doesn’t want to break any logs or Stick 2 or more logs together.
To make a h × w Window Frame, he needs two Logs with lengths equal h and two with length .
The Chef wants as much sunlight ... | ["# cook your dish here\nt=int(input())\nj=0\nwhile j<t:\n n=int(input())\n lst=list(map(int,input().split()))\n s=set()\n d=list()\n for i in lst:\n if i in s:\n s.remove(i)\n d.append(i)\n else:\n s.add(i)\n x=len(d)\n if x%2==0:\n print(x//2)... | {"inputs": [["2", "4", "1 2 1 2", "8", "1 2 1 3 4 1 5 6"]], "outputs": [["1", "0"]]} | interview | https://www.codechef.com/NITJ2021/problems/CIN005 | |
1,075 | Henry and Derek are waiting on a room, eager to join the Snackdown 2016 Qualifier Round. They decide to pass the time by playing a game.
In this game's setup, they write N positive integers on a blackboard. Then the players take turns, starting with Henry. In a turn, a player selects one of the integers, divides it b... | ["gb = [0, 1, 2, 2, 3, 3]\nga = [0 for x in range(70)]\ngag = [0 for x in range(70)]\nga[0] = 1\ngag[0] = 0\n\nfor i in range(1, 70):\n if i % 4 == 0:\n ga[i] = 1.5 * ga[i-1]\n gag[i] = 0\n else:\n ga[i] = 2 * ga[i-1]\n gag[i] = gag[i-1] + 1\n\n\ndef g(n):\n if n < 6:\n return gb[n]\n else:\n x = n / 6\n a = 0\n... | {"inputs": [["2", "2", "3 4", "3", "1 3 5"]], "outputs": [["Henry", "Derek"]]} | interview | https://www.codechef.com/SNCKQL16/problems/FDIVGAME | |
1,076 | You are given an unweighted tree with N$N$ nodes (numbered 1$1$ through N$N$). Let's denote the distance between any two nodes p$p$ and q$q$ by d(p,q)$d(p, q)$.
You should answer Q$Q$ queries. In each query, you are given parameters a$a$, da$d_a$, b$b$, db$d_b$, and you should find a node x$x$ such that d(x,a)=da$d(x, ... | ["# cook your dish here\nclass TestCase:\n def __init__(self):\n [self.node_count, self.query_count] = read_line()\n \n def fill_nodes(self):\n self.nodes = {n+1: [] for n in range(self.node_count)}\n for i in range(self.node_count -1):\n new_node_1, new_node_2 = read_line()... | {"inputs": [["1", "5 3", "1 2", "2 3", "3 4", "3 5", "2 1 4 1", "2 2 4 2", "1 1 2 1"]], "outputs": [["3", "5", "-1"]]} | interview | https://www.codechef.com/problems/DDQUERY | |
1,077 | Chef recently printed directions from his home to a hot new restaurant across the town, but forgot to print the directions to get back home. Help Chef to transform the directions to get home from the restaurant.
A set of directions consists of several instructions. The first instruction is of the form "Begin on XXX", i... | ["t = int(input())\n\nfor i in range(t):\n n = int(input())\n dir = []\n \n for j in range(n):\n dir.append(input().strip().split())\n \n for j in range(n-1):\n if dir[j+1][0] == 'Right':\n dir[j][0] = 'Left'\n else:\n dir[j][0] = 'Right'\n\n dir[n-1][0] = '... | {"inputs": [["2", "4", "Begin on Road A", "Right on Road B", "Right on Road C", "Left on Road D", "6", "Begin on Old Madras Road", "Left on Domlur Flyover", "Left on 100 Feet Road", "Right on Sarjapur Road", "Right on Hosur Road", "Right on Ganapathi Temple Road", ""]], "outputs": [["Begin on Road D", "Right on Road C"... | interview | https://www.codechef.com/COOK29/problems/DIRECTI | |
1,078 | 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 $W_1, W_2, W_3$.
Ada's strength is $S$. Whenever she hits a stack of bricks, consider the largest $k \ge 0$ such that the sum of widths of the topmost $k$ bricks... | ["t=int(input())\nfor i in range(t):\n n,w1,w2,w3=map(int,input().split())\n if n>=w1+w2+w3:\n print(1)\n elif n>=w1+w2 or n>=w2+w3:\n print(2)\n else:\n print(3)", "t=int(input())\nfor i in range(t):\n n,w1,w2,w3=map(int,input().split())\n if n>=w1+w2+w3:\n print(1)\n elif n>=w1+w2 or n>=w2+w3:\n print(2)\n else:... | {"inputs": [["3", "3 1 2 2", "2 1 1 1", "3 2 2 1"]], "outputs": [["2", "2", "2"]]} | interview | https://www.codechef.com/problems/BRKBKS | |
1,079 | Kostya likes the number 4 much. Of course! This number has such a lot of properties, like:
- Four is the smallest composite number;
- It is also the smallest Smith number;
- The smallest non-cyclic group has four elements;
- Four is the maximal degree of the equation that can be solved in radicals;
- There is four-col... | ["# cook your dish here\nx=int(input())\nfor i in range(x):\n h=input()\n print(h.count('4'))\n", "t = int(input())\nfor i in range(t):\n v = input()\n l = len(v)\n d =\"4\"\n c = 0\n for i in range(l):\n if(v[i] == d):\n c+=1\n print(c) \n \n \n", "# cook your dish he... | {"inputs": [["5", "447474", "228", "6664", "40", "81"]], "outputs": [["4", "0", "1", "1", "0"]]} | interview | https://www.codechef.com/problems/LUCKFOUR | |
1,080 | Every day, Mike goes to his job by a bus, where he buys a ticket. On the ticket, there is a letter-code that can be represented as a string of upper-case Latin letters.
Mike believes that the day will be successful in case exactly two different letters in the code alternate. Otherwise, he believes that the day will be... | ["def res(s):\n if len(s) == 2:\n if s[0] == s[1]:\n print(\"NO\")\n else:\n print(\"YES\")\n\n elif s[0] != s[1]:\n counte = 0\n for i in range(2, len(s)):\n if i % 2 == 0:\n if s[i] != s[0]:\n counte = 1\n break\n else:\n if s[i] != s[1]:\n counte = 1\n break\n\n if counte == 0:\n ... | {"inputs": [["2", "ABABAB", "ABC"]], "outputs": [["YES", "NO"]]} | interview | https://www.codechef.com/problems/TICKETS5 | |
1,081 | A spy needs your help to encrypt a 5 letter message.
To encrypt the message the following steps are need to be done:
1)Each letter of the message will be converted to it's equivalent number (i.e A=0, B=1,..Z=25)
2)98, 57, 31, 45, 46 are the 5 numbers in the key.
3)Add the equivalent number of the first letter of the ... | ["# cook your dish here\nimport string \nfrom collections import OrderedDict\nfrom itertools import zip_longest\ndic = OrderedDict(zip(string.ascii_uppercase, range(0, 26)))\nkeys = [98, 57, 31, 45, 46]\nt = int(input()) # number of test cases\ns1 = []\nfor i in range(t):\n s = input()\n for i in s:\n if i in dic.... | {"inputs": [["2", "HELLO", "HELL"]], "outputs": [["BJQEI", "BJQE"]]} | interview | https://www.codechef.com/STRG2020/problems/ENCYP | |
1,082 | $Jaggu$ monkey a friend of $Choota$ $Bheem$ a great warrior of $Dholakpur$. He gets everything he wants. Being a friend of $Choota$ $Bheem$ he never has to struggle for anything, because of this he is in a great debt of $Choota$ $Bheem$, he really wants to pay his debt off.
Finally the time has come to pay his debt off... | ["counter = -1\r\ndef flattree(node):\r\n nonlocal counter\r\n if visited[node]==1:\r\n return\r\n else:\r\n visited[node]=1\r\n counter += 1\r\n i_c[node] = counter\r\n\r\n flat_tree[counter] = swt[node]\r\n\r\n for i in graph[node]:\r\n if visited[i]==0:\r... | {"inputs": [["10", "10 12 6 8 1 19 0 5 13 17", "1 2", "1 3", "1 4", "3 10", "4 8", "8 9", "4 5", "5 7", "5 6", "3", "1 1", "2 3 20", "1 8"]], "outputs": [["10", "23"]]} | interview | https://www.codechef.com/COFY2020/problems/GKSMNHM | |
1,083 | Probably everyone has experienced an awkward situation due to shared armrests between seats in cinemas. A highly accomplished cinema manager named "Chef" decided to solve this problem.
When a customer wants to buy a ticket, the clerk at the ticket window asks the visitor if they need the armrests, and if so, which of ... | ["for i in range(eval(input())):\n n,m,z,l,r,b = list(map(int, input().split()))\n rows=n\n columns=m\n hand_rest=n*(m+1)\n if(m%2==0):\n hand_rest -=max(0,n-l-r)\n if(l+r+(2*b)<=hand_rest):\n # print \"kanu\"\n print(min(n*m,l+r+z+b))\n else:\n temp=l+r+(hand_rest-l-r)/2\n # print \"parth\"\n print(min(n*m,temp+... | {"inputs": [["2", "2 2 3 2 1 1", "3 3 1 2 0 9"]], "outputs": [["4", "8"]]} | interview | https://www.codechef.com/DEC15/problems/CHCINEMA | |
1,084 | You are given a binary string S. You need to transform this string into another string of equal length consisting only of zeros, with the minimum number of operations.
A single operation consists of taking some prefix of the string S and flipping all its values. That is, change all the 0s in this prefix to 1s, and all ... | ["# cook your dish here\ns=input()\ns1=s[::-1]\narr=[]\ncnt=0\nfor i in range(len(s1)):\n arr.append(s1[i])\nfor i in range(len(arr)):\n if(arr[i]==\"1\"):\n for j in range(i,len(arr)):\n if(arr[j]==\"1\"):\n arr[j]=\"0\"\n else:\n arr[j]=\"1\"\n cnt+=1\nprint(cnt)", "# cook your dish here\ndef rev(s):\n s1... | {"inputs": [["01001001"]], "outputs": [["6"]]} | interview | https://www.codechef.com/problems/PREFINVS | |
1,085 | -----Problem-----
Once THANMAY met PK who is from a different planet visiting earth. THANMAY was very fascinate to learn PK's language. The language contains only lowercase English letters and is based on a simple logic that only certain characters can follow a particular character.
Now he is interested in cal... | ["d = {}\nfor i in range(26):\n char = chr(i+ord('a'))\n d[char] = []\nfor i in range(26):\n char = chr(i+ord('a'))\n temp = list(map(int,input().strip().split()))\n for j in range(26):\n if (temp[j] == 1):\n follow= chr(j+ord('a'))\n d[follow].append(char)\n \ndef f(char,i,n,count):\n if (i==n):\n return count... | {"inputs": [["0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0", "0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0... | interview | https://www.codechef.com/COMN2016/problems/THANPK | |
1,086 | Let's define the niceness of a sequence of positive integers X1,X2,…,XN$X_1, X_2, \dots, X_N$ as the sum of greatest common divisors of all pairs of its elements, i.e.
N∑i=1N∑j=i+1gcd(Xi,Xj).∑i=1N∑j=i+1Ngcd(Xi,Xj).\sum_{i=1}^N \sum_{j=i+1}^N \mathrm{gcd}(X_i, X_j)\;.
For example, the niceness of the sequence [1,2,2]$[1... | ["# cook your dish here\nmod = 10**9 + 7\nfrom math import gcd\ndef fac50():\n f = [0]*51\n f[0] ,f[1] = 1,1\n for i in range(1,51):f[i] = (f[i-1]*i)%mod\n return f\ndef gcd110():\n gc = [[0]*111 for i in range(111)]\n for i in range(111):\n for j in range(111):gc[i][j] = gcd(i,j)\n return g... | {"inputs": [["3", "3 3", "1 1 -1", "4 8", "1 -1 -1 3", "3 10", "-1 -1 -1", ""]], "outputs": [["3", "23", "150"]]} | interview | https://www.codechef.com/problems/NICARRAY | |
1,087 | You are given an unweighted, undirected graph. Write a program to check if it's a tree topology.
-----Input-----
The first line of the input file contains two integers N and M --- number of nodes and number of edges in the graph (0 < N <= 10000, 0 <= M <= 20000). Next M lines contain M edges of that graph --- Each li... | ["#!/usr/bin/env python\n\ndef iscycle(E, v, EXPLORED_NODES, EXPLORED_EDGES):\n EXPLORED_NODES.add(v)\n r = False\n for e in [x for x in E if v in x]:\n if e in EXPLORED_EDGES: continue\n if e[0] == v: w = e[1]\n else: w = e[0]\n if w in EXPLORED_NODES:\n return True\n else:\n EXPLORED_EDGES.add(e)\n ... | {"inputs": [["3 2", "1 2", "2 3"]], "outputs": [["YES"]]} | interview | https://www.codechef.com/PRFT2012/problems/PD31 | |
1,088 | Two cheeky thieves (Chef being one of them, the more talented one of course) have came across each other in the underground vault of the State Bank of Churuland. They are shocked! Indeed, neither expect to meet a colleague in such a place with the same intentions to carry away all the money collected during Churufest 2... | ["t=int(input())\nwhile(t):\n s=input().split()\n m=int(s[0])\n p=float(s[1])\n if(m%2==0):\n r=(1-p**m)/(p+1)\n else:\n r=(1+p**m)/(p+1)\n print(1000000000*r,1000000000*(1-r))\n t-=1", "for _ in range(int(input())):\n m, p = map(float, input().split())\n ans = 10**9 * (1 - (-p)**m) / (1 + p)\n print(ans,10**9-ans)",... | {"inputs": [["2", "1 0.5", "2 0.5"]], "outputs": [["1000000000.0 0.0", "500000000.0 500000000.0"]]} | interview | https://www.codechef.com/problems/BANROB | |
1,089 | The garden has a tree with too many leaves on it and gardner wants to cut the unwanted leaves. This is a rooted tree, where a node $v$ is called parent of another node $u$, if there exists a directed edge from $v$ to $u$. Leaf node is a node with no outgoing edges.
Gardner cuts the tree in a peculiar way:
- For each pa... | ["def dfs(node):\n nonlocal adj,leaf\n val=0\n flag=0\n for i in adj[node]:\n x= dfs(i)\n val+=x\n if x==0:\n flag=1\n leaf+=val-val%3\n if val%3==0 and flag==0:\n return 1\n else:\n return 0\nfor _ in range(int(input())):\n n=int(input())\n adj=[[] for i in range(n+2)]\n arr=[int(i) for i in input().split()]\n ... | {"inputs": [["1", "13", "1 1 1 1 1 4 3 4 4 3 4 3"]], "outputs": [["4"]]} | interview | https://www.codechef.com/ECPG2020/problems/ECPC10D | |
1,090 | You are given a sequence of n integers a1, a2, ..., an and an integer d.
Find the length of the shortest non-empty contiguous subsequence with sum of elements at least d. Formally, you should find the smallest positive integer k with the following property: there is an integer s (1 ≤ s ≤ N-k+1) such that as + as+1 + ..... | ["# cook your dish here\n\nimport collections\n\ndef shortestSubarray(A, K):\n \n \n N = len(A)\n P = [0]\n\n for x in A:\n P.append(P[-1] + x)\n\n #Want smallest y-x with Py - Px >= K\n ans = N+1 # N+1 is impossible\n monoq = collections.deque() #opt(y) candidates, represented as indices \u00a0\u00a0\u00a0\u... | {"inputs": [["2", "5 5", "1 2 3 1 -5", "5 1", "1 2 3 1 -5"]], "outputs": [["2", "1"]]} | interview | https://www.codechef.com/problems/MINSUBAR | |
1,091 | Rupsa really loves triangles. One day she came across an equilateral triangle having length of each side as an integer N. She started wondering if it was possible to transform the triangle keeping two sides fixed and alter the third side such that it still remains a triangle, but the altered side will have its length a... | ["# cook your dish here\nimport math\ndef isPos(num):\n if num%2==0:\n for i in range(num,2*num,1):\n if ((num**2)-((i/2)**2))**(1/2)==int(((num**2)-((i/2)**2))**(1/2)):\n return 'YES'\n return 'NO'\n else:\n for i in range(num+1,2*num,1):\n if ((num**2)-((i/2)**2))**(1/2)==int(((num**2)-((i/2)**2))**(1/2)):\... | {"inputs": [["2", "5", "3"]], "outputs": [["YES", "NO"]]} | interview | https://www.codechef.com/problems/ADTRI | |
1,092 | The faculty of application management and consulting services (FAMCS) of the Berland State University (BSU) has always been popular among Berland's enrollees. This year, N students attended the entrance exams, but no more than K will enter the university. In order to decide who are these students, there are series of e... | ["# cook your dish here\nt=int(input())\nfor i in range(t):\n (n,k,e,m)=tuple(map(int,input().split()))\n scores=[]\n for j in range(n-1):\n scores.append(sum(list(map(int,input().split()))))\n scores.sort(reverse=True);\n bsc=scores[k-1];\n msc=sum(list(map(int,input().split())))\n mini=bsc-msc+1\n if(mini<0):\n pri... | {"inputs": [["1", "4 2 3 10", "7 7 7", "4 6 10", "7 10 9", "9 9"]], "outputs": [["4"]]} | interview | https://www.codechef.com/problems/ENTEXAM | |
1,093 | Chef likes toys. His favourite toy is an array of length N. This array contains only integers. He plays with this array every day. His favourite game with this array is Segment Multiplication. In this game, the second player tells the left and right side of a segment and some modulo. The first player should find the mu... | ["# # # # n = int(input())\r\n# # # # arr = list(map(int , input().split()))\r\n# # # # for _ in range(int(input())):\r\n# # # # \tl,r,mod = map(int , input().split())\r\n# # # # \tpro = 1\r\n# # # # \tfor i in range(l - 1,r):\r\n# # # # \t\tpro *= arr[i]\r\n# # # # \tprint(pro % mod) #sample testcases passed #TLE\r\n#... | {"inputs": [["5", "1 2 3 4 5", "4", "1 2 3", "2 3 4", "1 1 1", "1 5 1000000000"]], "outputs": [["2", "2", "0", "120"]]} | interview | https://www.codechef.com/problems/CHMOD | |
1,094 | Two words rhyme if their last 3 letters are a match. Given N words, print the test case number (of the format Case : num) followed by the rhyming words in separate line adjacent to each other.
The output can be in anyorder.
-----Input-----
First line contains the number of test case T
The next line contains the numb... | ["t = int(input())\nfor i in range(t):\n n = int(input())\n suffixes = {}\n xx = input().split()\n for x in range(n):\n try:\n a = suffixes[xx[x][-3:]]\n except Exception as e:\n a = []\n a.append(xx[x])\n\n suffixes.update({xx[x][-3:]: a})\n\n print(\"Case : %d\" % (i + 1))\n for a in sorted(suffixes):\n prin... | {"inputs": [["3", "3", "nope qwerty hope", "5", "brain drain request grain nest", "4", "these words dont rhyme"]], "outputs": [["Case : 1", "hope nope", "qwerty", "Case : 2", "brain drain grain", "nest request", "Case : 3", "these", "dont", "words", "rhyme"]]} | interview | https://www.codechef.com/COWA2016/problems/CWAM1502 | |
1,095 | Indraneel has to sort the books in his library. His library has one long shelf. His books are numbered $1$ through $N$ and he wants to rearrange the books so that they appear in the sequence $1,2, ..., N$.
He intends to do this by a sequence of moves. In each move he can pick up any book from the shelf and insert it at... | ["n=int(input())\narr=[int(x) for x in input().split()]\nl=[1]*n\nif sorted(arr)==arr:\n print('0')\nelse:\n for i in range(0,len(arr)):\n for j in range(i):\n if arr[i]>=arr[j] and l[i]<l[j]+1:\n l[i]=l[j]+1\n print(n-max(l))", "n=int(input())\narr=[int(x) for x in input().spl... | {"inputs": [["5", "2 1 4 5 3"]], "outputs": [["2"]]} | interview | https://www.codechef.com/IARCSJUD/problems/BOOKSORT | |
1,096 | Zonal Computing Olympiad 2012, 26 Nov 2011
The year is 2102 and today is the day of ZCO. This year there are N contests and the starting and ending times of each contest is known to you. You have to participate in exactly one of these contests. Different contests may overlap. The duration of different contests might b... | ["import sys\nn, x, y = input().split(' ')\nn = int(n)\nx = int(x)\ny = int(y)\ncontests = {}\n\nfor i in range(n):\n s, e = input().split(' ')\n s = int(s)\n e = int(e)\n contests[(s, e)] = abs(s-e)\n\nv_time = input().split(' ')\nw_time = input().split(' ')\n\nv_time, w_time = list(map(int, v_time)), list(map(int, w_... | {"inputs": [["3 4 2", "15 21", "5 10", "7 25", "4 14 25 2", "13 21"]], "outputs": [["8"]]} | interview | https://www.codechef.com/ZCOPRAC/problems/ZCO12002 | |
1,097 | Sinchan and his friends loves to eat. They have a 2D rectangular cake which they want to share. Sinchan is very kind and offers his friends to eat the cake first, all friends goes one by one to eat the cake. Each friend will cut cake into two parts. First part of the cake will be largest possible square from the cake, ... | ["testcases=int(input())\nresults=[]\nfor i in range(0,testcases):\n friends=int(input())\n l,b=list(map(int,input().split()))\n over=False\n if b>l:\n temp=b\n b=l\n l=temp\n for counter in range(0,friends):\n if l==b:\n over=True\n break\n elif l>b:\n l=l-b\n if b>l:\n temp=b\n b=l\n l=temp\n ... | {"inputs": [["3", "2", "5 3", "4", "4 8", "1", "1 2"]], "outputs": [["Yes 2", "No", "Yes 1"]]} | interview | https://www.codechef.com/CDGO2016/problems/CDGO1601 | |
1,098 | Chef and Roma are playing a game. Rules of the game are quite simple.
Initially there are N piles of stones on the table.
In each turn, a player can choose one pile and remove it from the table.
Each player want to maximize the total number of stones removed by him.
Chef takes the first turn.
Please tell Chef the max... | ["# cook your dish here\nfor i in range(int(input())):\n n = int(input())\n l = list(map(int,input().split()))\n s = 0\n l.sort(reverse = True)\n for i in range(0,n,2):\n s = s+l[i]\n print(s)\n", "# cook your dish here\ntest_case = int(input())\nwhile test_case :\n n = int(input())\n array = list(map(int, input().str... | {"inputs": [["2", "3", "1 2 3", "3", "1 2 1"]], "outputs": [["4", "3"]]} | interview | https://www.codechef.com/problems/CHEFA | |
1,099 | Did you know that there are over 40,000 varieties of Rice in the world ? There are so many dishes that can be prepared with Rice too. A famous chef from Mumbai, Tid Gusto prepared a new dish and named it 'Tid Rice'. He posted the recipe in his newly designed blog for community voting, where a user can plus (+) or minus... | ["import sys\n\ndef f(p):\n votes = {}\n for x in range(p):\n str = sys.stdin.readline()\n t = str.split()\n votes[t[0]] = t[1]\n\n ans = 0\n for per in votes:\n if votes[per] == \"+\":\n ans= ans+1\n else:\n ans = ans-1\n\n return ans\n\nx = sys.stdin.readline()\nfor t in range(int(x)):\n... | {"inputs": [["3", "4", "tilak +", "tilak +", "tilak -", "tilak +", "3", "ratna +", "shashi -", "ratna -", "3", "bhavani -", "bhavani +", "bhavani -"]], "outputs": [["1", "-2", "-1"]]} | interview | https://www.codechef.com/COOK10/problems/TIDRICE |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.