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 |
|---|---|---|---|---|---|---|---|---|---|
850751c1c91765c4a8b5feeb829f2e0b | UNKNOWN | 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 | PYTHON3 | CODECHEF | 4,744 | |
df836610bb55bc0374b6d6eb3f0903cc | UNKNOWN | 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 | PYTHON3 | CODECHEF | 4,361 | |
f238f104950d8a1b614939790f1ac318 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 8,680 | |
9f3aab2732dc646276baed9768718703 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 8,503 | |
7bec9922fb931374e3c733acabbcea36 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 5,525 | |
ac6958ffec6b8507cf57e493a863882f | UNKNOWN | 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 | PYTHON3 | CODECHEF | 14,016 | |
34ea69ce06611960c8b9960b2ca75e25 | 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 _ 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 | PYTHON3 | CODECHEF | 8,265 | |
b111777307e96562135e3429c9a07ad7 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 14,039 | |
81d6ff1d37c96a796cfe8f8cddb088d3 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 953 | |
47c8a11501f816b111eceacdfd65c675 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 3,758 | |
0119e9b8288b989b982f0cba6d7d8dbe | UNKNOWN | 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 | PYTHON3 | CODECHEF | 2,351 | |
9e702c9e6de83cd372d6eea9887d37b2 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 9,077 | |
62404f1e591b768914beb2c93d5df709 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 10,696 | |
957d32c40d2ef32aee67219b83e7ab23 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 554 | |
9809a24d89a41aafd34df7578345f051 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 8,148 | |
31191aeb11420d63b0b09151852bbc1d | UNKNOWN | 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 | PYTHON3 | CODECHEF | 492 | |
9f62f520e544114b9ed8a5970316d6a8 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 12 | |
533e4120f43accba48083ff40a5b379a | UNKNOWN | 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 | PYTHON3 | CODECHEF | 18,257 | |
c4c0b125e7e2afcf6645f8adaa83613c | UNKNOWN | 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 | PYTHON3 | CODECHEF | 1,720 | |
73f06c5dca1821be7db3d089a0f03c30 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 1,322 | |
18fadb0010f779744fb0dd464999f81f | UNKNOWN | 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 | PYTHON3 | CODECHEF | 281 | |
6e3b747a0aa7aa1b9b39c0b2474ccf50 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 784 | |
df98497388e7bf0efb49ca1514daa5ad | UNKNOWN | “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 | PYTHON3 | CODECHEF | 8,010 | |
7004c1d9dcf170258c7ddafe88bc2775 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 12,280 | |
2d4a1ca25c2e7d7247c7d5595ff7a2c9 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 1,873 | |
de4d08e2fe55e8f1a3124628e7ded945 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 335 | |
6aff4ec7147aa48d923bf3ccbefea31e | UNKNOWN | 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 | PYTHON3 | CODECHEF | 9,962 | |
d826e2b3b0c4fa81a538223ac24166ac | UNKNOWN | 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 | PYTHON3 | CODECHEF | 4,535 | |
61bc83fff885726bcfd4fa78f5831efd | UNKNOWN | 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 | PYTHON3 | CODECHEF | 4,293 | |
4a8e13d8686fbda363f5eeed9cf9014d | UNKNOWN | 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 | PYTHON3 | CODECHEF | 8,078 | |
235199b0e9b1c6a66851fa0b702709b7 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 12,955 | |
2374d3997cb1f14fd1282c6a283c949a | UNKNOWN | 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 | PYTHON3 | CODECHEF | 5,990 | |
050a6effc71b43175fa56db87f70c34e | UNKNOWN | -----
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 | PYTHON3 | CODECHEF | 9,266 | |
61d057efc3d0aa612681997658792557 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 9,746 | |
0080c125aa184e1776d901b4b6b7110b | UNKNOWN | The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single line of ... | ["# cook your dish here\nt=int(input())\nfor 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 | PYTHON3 | CODECHEF | 4,519 | |
14c4e72e8587aadc810aef3651b3248e | UNKNOWN | 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 | PYTHON3 | CODECHEF | 19,895 | |
9a25733138b5b3816bf44043fa11adb7 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 6,007 | |
87688431fd94b5c2040abc94581e2341 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 17,590 | |
2d6a1f619ade0ca5ea49c7f8d90aa993 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 2,526 | |
4eaa99e36453bf3bb850ccedf67e856a | UNKNOWN | 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 | PYTHON3 | CODECHEF | 4,497 | |
4543c55fca49941a987b45c15c6379eb | UNKNOWN | 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 | PYTHON3 | CODECHEF | 3,021 | |
a56dccfc7e7d7e5748d3d177a30dae2e | UNKNOWN | 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 | PYTHON3 | CODECHEF | 6,381 | |
63df4075710813e9b9622b71b4277cf3 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 1,949 | |
616bb89a22e0d90bc10fca826fd7d58a | UNKNOWN | 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 | PYTHON3 | CODECHEF | 9,962 | |
9545fc0a970ea188ddaae44a6d440967 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 15,805 | |
97fc5fd42341baf2e0c2650ab4397334 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 16,737 | |
1fe2185425127141b2cb8fdc0b41e2d9 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 3,024 | |
68180e9ff60e4f6f8fcb9f27d0415a9a | UNKNOWN | 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 | PYTHON3 | CODECHEF | 4,861 | |
f8886d269ab5b54a612ef45a8990d528 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 7,007 | |
43ce4a02554d8d0837cafa1654bdaed5 | UNKNOWN | -----
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 | PYTHON3 | CODECHEF | 6,912 | |
f6a244710e5f055a262ef8ab6c096af9 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 2,426 | |
930604e6855a914984026f05ebac4952 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 3,904 | |
9eaae41cbfc44551edfe21fe0799463e | UNKNOWN | 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 | PYTHON3 | CODECHEF | 6,310 | |
1563aafc21ba6ecd2234f2dd4065d3ce | UNKNOWN | 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 | PYTHON3 | CODECHEF | 7,115 | |
9967f79dbda0a1666c1eb63900d374e6 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 12,046 | |
c39aa0650aaa35941e8dc5fd73bd3249 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 1,420 | |
980770de4b9e8c1edb693e4b71ab6a07 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 6,597 | |
2168d04d2a6aca8c5e1edca1d0eee751 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 4,363 | |
902eabf02b10f653cbc63aa5beb0c804 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 1,966 | |
88d85c42ecfa683764c8e6734c1db217 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 29,535 | |
6a1822b9dab07393f517da0615e50351 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 16,435 | |
e194c38bfa5ed9fdc6ad8a08b4363282 | UNKNOWN | For her next karate demonstration, Ada will break some bricks.
Ada stacked three bricks on top of each other. Initially, their widths (from top to bottom) are $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 | PYTHON3 | CODECHEF | 6,403 | |
28ad298eaf07e60a9f23d0d2184d2ab9 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 4,130 | |
c98de1998ce052a924c520da2b924da8 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 8,591 | |
a583d3f582424217efa417281b2c1405 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 8,736 | |
f6d230c746462ee9f8821046d4a5791f | UNKNOWN | $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 | PYTHON3 | CODECHEF | 3,399 | |
5704bffcdfd0503fb37cd7abe6cafdcb | UNKNOWN | 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 | PYTHON3 | CODECHEF | 13,978 | |
d460c4e2384858e4a383ce940fef829f | UNKNOWN | 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 | PYTHON3 | CODECHEF | 2,851 | |
880705d91ed9417aa151f6450f6383f8 | UNKNOWN | -----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 | PYTHON3 | CODECHEF | 1,511 | |
86009db8d4bc8037d0158fa759a16eb4 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 7,638 | |
6e0b329e83200bfb26a5392227f96eae | UNKNOWN | 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 | PYTHON3 | CODECHEF | 1,726 | |
40574c47fea01673761de823d5531d15 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 511 | |
a5d37149ad53188d3ed2602fec9183f8 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 1,254 | |
e0bcc0a3c08f355bee8d4417169a0948 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 866 | |
5fca51d7d26d72731f2fbb5fd13f9acb | UNKNOWN | 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 | PYTHON3 | CODECHEF | 2,230 | |
3bb95ab5557d440d36c3f44fbfde4d79 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 8,449 | |
ef1d573c6fb038e8523c0a7165298926 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 6,308 | |
2a34c855f8d198d69e5a99e8a16d99ec | UNKNOWN | 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 | PYTHON3 | CODECHEF | 382 | |
d0c9251677ba9ea0f51f5787adb3246c | UNKNOWN | 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 | PYTHON3 | CODECHEF | 718 | |
68ab367651444d831a37bc3fb1b100c1 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 13,950 | |
74760f93ddc0b5174d1ace704ddd4556 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 2,464 | |
9197079e192343205cb3ebd87366d329 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 4,913 | |
68356f6ecf5a2d610e379f803e665694 | UNKNOWN | 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 | PYTHON3 | CODECHEF | 1,274 | |
b5a8110ac65fbd161d5b5b2a53c70448 | UNKNOWN | This question is similar to the $"Operation$ $on$ $a$ $Tuple"$ problem in this month's Long Challenge but with a slight variation.
Consider the following operations on a triple of integers. In one operation, you should:
- Choose a positive integer $d>0$ and an arithmetic operation - in this case, it will only be addi... | ["# cook your dish here\n\"\"\"\nInput:\nThe first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.\nThe first line of each test case contains three space-separated integers p, q and r.\nThe second line contains three space-separated integers a, b... | {"inputs": [["1", "2 2 1", "3 3 2"]], "outputs": [["3"]]} | INTERVIEW | PYTHON3 | CODECHEF | 8,579 | |
07997277b6f2c3122f0024fd77005838 | UNKNOWN | After failing to clear his school mathematics examination, infinitepro decided to prepare very hard for his upcoming re-exam, starting with the topic he is weakest at ― computational geometry.
Being an artist, infinitepro has C$C$ pencils (numbered 1$1$ through C$C$); each of them draws with one of C$C$ distinct colour... | ["from collections import Counter\r\nfrom math import factorial\r\ndef nc3(n):\r\n a=factorial(n)\r\n b=factorial(n-3)\r\n return ((a)/(b*6))\r\ndef rem(s,k):\r\n t=-1\r\n x=-1\r\n for i in range(len(s)):\r\n if s[i][0]>2 and s[i][1]<=k:\r\n if s[i][0]>3:\r\n ch=(nc3(s... | {"inputs": [["2", "7 2 13", "1 10 1", "1 14 2", "6 4 1", "2 2 1", "0 12 2", "2 11 2", "0 6 1", "8 10", "6 1 20", "1 5 1", "2 11 1", "4 0 1", "6 8 1", "0 11 1", "3 3 1", "9"]], "outputs": [["2", "4"]]} | INTERVIEW | PYTHON3 | CODECHEF | 48,724 | |
5ea889cae3bfb491085fc39105a8df3d | UNKNOWN | On Miu's smart phone, there is a search feature which lets her search for a contact name by typing digits on the keypad where each digit may correspond to any of the characters given below it. For example, to search for TOM, she can type 866 and for MAX she can type 629.
+------+-----+------+
| 1 | 2 | 3 |
| ... | ["for _ in range(int(input())):\n n=int(input())\n n1=0\n ans=1\n while(n>0):\n d=int(n % 10)\n if(d!=0):\n if(d!=9 and d!=7 and d!=1):\n n1=3\n elif(d==1):\n n1=1\n else:\n n1=4\n ans=(int(ans)*int(n1))% (1000000007)\n n/=10\n else:\n n/=10\n if(ans==1):\n print(\"0\")\n else:\n print(ans %(1... | {"inputs": [["2", "5", "72"]], "outputs": [["3", "12"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,844 | |
ab93883a29da74cac0a2d67c511e87bf | UNKNOWN | Leha is a bright mathematician. Today he is investigating whether an integer is divisible by some square number or not.
He has a positive integer X represented as a product of N integers a1, a2, .... aN. He has somehow figured out that there exists some integer P such that the number X is divisible by P2, but he is not... | ["import sys\nimport math\nr=int(input())\nfor v in range (0,r):\n n = int(input())\n x=1\n arr=list(map(int,input().strip().split(\" \")))\n for i in range (0,n):\n x=x*arr[i]\n \n for i in range (2,100000000):\n if(x%(pow(i,2))==0):\n ans1=i\n break\n \n \n print(ans1) \n", "import math\ndef forloop(list,list1... | {"inputs": [["1", "3", "21 11 6"]], "outputs": [["3"]]} | INTERVIEW | PYTHON3 | CODECHEF | 9,278 | |
c2b58859efe6dd5a35c77df831d8fa0a | UNKNOWN | Kabir Singh is playing a game on the non-negative side of x-axis. It takes him $1 second$ to reach from Pth position to (P−1)th position or (P+1)th position.
Kabir never goes to the negative side and also doesn't stop at any moment of time.
The movement can be defined as :
- At the beginning he is at $x=0$ , at tim... | ["# cook your dish here\nT=int(input())\nMOD=int(1e9+7)\nfor t in range(T):\n N,K=[int(a) for a in input().split()]\n M=K//2\n # ans= ((K%2)?( (N+M)*(N+M) + M ):( (N+M)*(N+M) - M) )\n ans=(N+M)*(N+M) -M\n if(K%2):\n ans+=2*M\n if(N==0):\n ans=K*(K-1)\n print(ans%MOD) ", "# cook your d... | {"inputs": [["4", "0 1", "1 1", "1 3", "4 6"]], "outputs": [["0", "1", "5", "46"]]} | INTERVIEW | PYTHON3 | CODECHEF | 12,888 | |
83965d177227288bcf879f0a41219335 | UNKNOWN | Chef Ada is preparing $N$ dishes (numbered $1$ through $N$). For each valid $i$, it takes $C_i$ minutes to prepare the $i$-th dish. The dishes can be prepared in any order.
Ada has a kitchen with two identical burners. For each valid $i$, to prepare the $i$-th dish, she puts it on one of the burners and after $C_i$ min... | ["for i in range(int(input())):\n n=int(input())\n c=[int(z) for z in input().split()]\n c.sort()\n c.reverse()\n b1,b2=0,0\n for i in range(n):\n if b1<b2:\n b1+=c[i]\n elif b2<b1:\n b2+=c[i]\n else:\n b1+=c[i]\n print(max(b1,b2))\n \n", "n=int(input())\nfor i in range(n):\n N=int(input())\n lst=list(map(in... | {"inputs": [["3", "3", "2 2 2", "3", "1 2 3", "4", "2 3 4 5"]], "outputs": [["4", "3", "7"]]} | INTERVIEW | PYTHON3 | CODECHEF | 7,782 | |
0d13820350e5a00218d41909e415f473 | UNKNOWN | A long way back I have taken $5000 from Golu when I used to live in Jodhpur. Now, time has passed and I am out of Jodhpur. While Golu still in Jodhpur, one day called me and asked about his money.
I thought of giving Golu a chance. I told him that he can still take his money back if he reaches my home anyhow just in 2 ... | ["'''Well I found the bug, but I don't understand why it was doing that. I mean, as\nfar as I can tell, it shouldn't be a bug!\nNote to self: deleting from (supposedly) local lists through recursion is dangerous!'''\n\nclass Group(object):\n def __init__(self,size,start,end,value):\n self.size = size\n ... | {"inputs": [["2", "5 5 4", "2 1 5 50", "1 2 4 20", "2 3 4 40", "2 4 5 50", "3 4 5 80", "10 10 5", "2 5 10 17300", "2 1 8 31300", "5 4 10 27600", "4 8 10 7000", "5 9 10 95900", "2 7 10 14000", "3 6 10 63800", "1 7 10 19300", "3 8 10 21400", "2 2 10 7000"]], "outputs": [["140", "127200", "By:", "Chintan, Asad, Ashayam, A... | INTERVIEW | PYTHON3 | CODECHEF | 1,944 | |
604e20f027baa2fa94aac42153865843 | UNKNOWN | Polo, the Penguin, likes numbers. He says that the goodness of a number is itself multiplied by the number of digits in it's decimal representation. For example, the goodness of the integer 474 is 474*3 = 1422.
Help him to count the sum of goodness of all integers from L to R, inclusive. Since the answer can be too lar... | ["# cook your dish here\nfrom sys import stdin\nfrom math import sqrt,ceil,log10\ndef get_sum(a,b,digits):\n sum=((b+a)*(b-a+1))//2\n return sum*digits\n\ndef solve():\n mod=10**9+7\n thehighlimiter={i: 10 ** i - 1 for i in range(12)}\n thelowlimiter={i: 10**i for i in range(12)}\n for _ in range(int(... | {"inputs": [["1", "9 12", "", ""]], "outputs": [["75"]]} | INTERVIEW | PYTHON3 | CODECHEF | 3,572 | |
d367ea749949b35eef2a0d50c5047405 | UNKNOWN | There were $N$ students (numbered $1$ through $N$) participating in the Indian Programming Camp (IPC) and they watched a total of $K$ lectures (numbered $1$ through $K$). For each student $i$ and each lecture $j$, the $i$-th student watched the $j$-th lecture for $T_{i, j}$ minutes.
Additionally, for each student $i$, ... | ["N,M,K=map(int,input().split())\nc=0\nfor i in range(N):\n T=list(map(int,input().split()))\n Q=T[-1]\n T.pop(-1)\n if Q<=10 and sum(T)>=M:\n c+=1\nprint(c)", "n,m,k=map(int,input().split())\na=0\nfor i in range(n):\n t=list(map(int,input().split()))\n q=t[-1]\n t.pop(-1)\n if q<=10 and sum(t)>=m:\n a+=1\nprint(a)",... | {"inputs": [["4 8 4", "1 2 1 2 5", "3 5 1 3 4", "1 2 4 5 11", "1 1 1 3 12"]], "outputs": [["1"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,515 | |
c3c5628657311497df467e1c866f5ef7 | UNKNOWN | Sumit and Dhiraj are roommates in a hostel of NIT Jamshedpur,One day after completing there boring assignments of Artificial Intelligence, they decided to play a game as it was dhiraj,s idea to play a game so he started explaining the rules of the game to sumit.
So the game was as follows-They randomly took a number N ... | ["import math\nfor t in range(int(input())):\n n = int(input())\n temp = math.sqrt(n)\n if (temp == int(temp)):\n print(\"YES\")\n else:\n print(\"NO\")", "t=int(input());\nfor i in range (0,t):\n c=0;\n n=int(input());\n for j in range (1,n+1):\n if(n%j==0):\n c=c+1;\n if(c%2==0):\n print(\"NO\\n\");\n else:\n ... | {"inputs": [["2", "4", "5"]], "outputs": [["YES", "NO"]]} | INTERVIEW | PYTHON3 | CODECHEF | 4,619 | |
7aa325701fab00159aecd916b5de553c | UNKNOWN | You are given an array of integers [A1,A2,…,AN]$[A_1, A_2, \ldots, A_N]$. Let's call adding an element to this array at any position (including the beginning and the end) or removing an arbitrary element from it a modification. It is not allowed to remove an element from the array if it is empty.
Find the minimum numbe... | ["# cook your dish here\nfor _ in range(int(input())):\n n=int(input());li=list(map(int,input().split()));dli=dict();modi=0\n for i in li:\n if i not in dli:dli[i]=1\n else:dli[i]+=1\n op=sorted(list(dli))\n if(len(dli)!=0):\n while 1:\n tmp=[]\n for i in op:\n if dli[i]==0:conti... | {"inputs": [["2", "5", "1 4 1 2 2", "4", "2 3 2 3"]], "outputs": [["1", "2"]]} | INTERVIEW | PYTHON3 | CODECHEF | 3,154 | |
7917359c4d92955930ff18508f6444aa | UNKNOWN | Using his tip-top physique, Kim has now climbed up the mountain where the base is located. Kim has found the door to the (supposedly) super secret base. Well, it is super secret, but obviously no match for Kim's talents.
The door is guarded by a row of $N$ buttons. Every button has a single number $A_i$ written on it.... | ["# cook your dish here\nfor _ in range(int(input())):\n n=int(input())\n a=list(map(int,input().split()))\n even=[]\n odd=[]\n for i in a:\n if(i & 1):\n even.append(i)\n else:\n odd.append(i)\n print(len(even)*len(odd))", "t=int(input()) \nfor kkk in range(t): \n n=int(input()) \n a=[int(x) for x in input ().sp... | {"inputs": [["3", "4", "3 5 3 4", "2", "5 7", "1", "4"]], "outputs": [["3", "0", "0"]]} | INTERVIEW | PYTHON3 | CODECHEF | 5,371 | |
0eaaf5363a50f639564dc5a5ba18af4c | UNKNOWN | The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single line of... | ["# cook your dish here\nfor _ in range(int(input())):\n n = int(input())\n m = n\n x= 1\n for i in range(n):\n for j in range(m):\n print(x, end = '')\n x += 1\n print()\n m -= 1", "# cook your dish here\n\nt=int(input())\nfor i in range(t):\n n=int(input())\n ... | {"inputs": [["4", "1", "2", "3", "4"]], "outputs": [["1", "12", "3", "123", "45", "6", "1234", "567", "89", "10"]]} | INTERVIEW | PYTHON3 | CODECHEF | 9,054 | |
84a85a35281b21e9e6cdb13ed2d511f6 | UNKNOWN | Given an array A of length N, your task is to find the element which repeats in A maximum number of times as well as the corresponding count. In case of ties, choose the smaller element first.
-----Input-----
First line of input contains an integer T, denoting the number of test cases. Then follows description of T ca... | ["t = input();\n\na = [0 for i in range(10001)]\n\ni = 0;\n\nwhile i < int(t):\n\n\tn = input();\n\n\tk = input();\n\n\tassert(len(k.split(' ')) == int(n));\n\n\tfor each in k.split(' '):\n\n\t\ta[int(each)] += 1;\n\n\n\tV = 0;\n\n\tC = a[V];\n\n\tfor j in range(10001):\n\n\t\tif C < a[j]:\n\n\t\t\tV = j;\n\n\t\t\tC = ... | {"inputs": [["2", "5", "1 2 3 2 5", "6", "1 2 2 1 1 2", "", ""]], "outputs": [["2 2", "1 3"]]} | INTERVIEW | PYTHON3 | CODECHEF | 12,153 | |
d97f33b8277fb15fbd11f99884f6d1df | UNKNOWN | Chefu is Chef's little brother, he is 12 years old and he is new to competitive programming.
Chefu is practicing very hard to become a very skilled competitive programmer and win gold medal in IOI.
Now Chefu is participating in a contest and the problem that he is trying to solve states:
Given an array A of N integers,... | ["T=int(input())\nfor i in range(T):\n N=int(input())\n A=list(map(int,input().split()))[:N]\n l=[]\n for j in range(len(A)):\n for k in range(j+1,len(A)):\n l.append(A[j]+A[k])\n print(l.count(max(l))/((N*(N-1))/2))", "for i in range(int(input())):\n n=int(input())\n t=list(map(int,input().split()))[:n]\n m=[]\n fo... | {"inputs": [["3", "4", "3 3 3 3", "6", "1 1 1 2 2 2", "4", "1 2 2 3"]], "outputs": [["1.00000000", "0.20000000", "0.33333333"]]} | INTERVIEW | PYTHON3 | CODECHEF | 7,732 | |
b2eec328328dd50ce1f309b987707f11 | UNKNOWN | You are given a tree with $N$ vertices (numbered $1$ through $N$) and a sequence of integers $A_1, A_2, \ldots, A_N$. You may choose an arbitrary permutation $p_1, p_2, \ldots, p_N$ of the integers $1$ through $N$. Then, for each vertex $i$, you should assign the value $A_{p_i}$ to this vertex.
The profit of a path bet... | ["T = int(input())\n\nM = 10 ** 9 + 7\n\nfor _ in range(T):\n N = int(input())\n\n A = list(map(int, input().split()))\n\n if N == 1:\n print(0)\n continue\n\n B = {}\n C = {}\n\n for i in range(N - 1):\n u, v = input().split()\n u = int(u) - 1\n v = int(v) - 1\n\n if u not in B:\n B[u] = []\n\n if v not in B:... | {"inputs": [["2", "4", "1 2 3 4", "1 2", "2 3", "2 4", "5", "1 2 3 4 5", "1 2", "2 3", "3 4", "4 5"]], "outputs": [["24", "15"]]} | INTERVIEW | PYTHON3 | CODECHEF | 1,714 | |
7ead6c8bc6a2462a38a59a17d4ac5dfa | UNKNOWN | -----Problem Statement-----
We have an integer sequence $A$, whose length is $N$.
Find the number of the non-empty contiguous subsequences of $A$ whose sum is $0$. Note that we are counting the ways to take out subsequences. That is, even if the contents of some two subsequences are the same, they are counted individua... | ["from collections import defaultdict \ndef findSubarraySum(arr, n, Sum): \n \n # Dictionary to store number of subarrays \n # starting from index zero having \n # particular value of sum. \n prevSum = defaultdict(lambda : 0) \n \n res = 0 \n \n # Sum of elements so far. \n currsum = 0 \n \n for i in range(0, n):... | {"inputs": [["6", "1 3 -4 2 2 -2"]], "outputs": [["3"]]} | INTERVIEW | PYTHON3 | CODECHEF | 10,731 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.