problem_id int64 0 5k | question stringlengths 50 14k | solutions stringlengths 12 764k | test_cases stringlengths 2 23.6M | difficulty stringclasses 3
values | starter_code stringlengths 0 952 |
|---|---|---|---|---|---|
700 | Now-a-days, Manish is becoming famous for bank robbery in the country because of his cleverness, he never robs own his own.He has four workers A , B, C, and D , all working under him.All of the four take some amount for that. There are total N banks in the country and Manish wants to rob all the banks with minimum
am... | ["for t in range(int(input())):\n n = int(input())\n l = []\n m = []\n x = list(map(int,input().split()))\n l.append(x)\n m.append(list(x))\n for i in range(1,n):\n x = list(map(int,input().split()))\n l.append(x)\n temp = []\n for i in range(4):\n temp.append (x[i]+min(m[-1][:i]+m[-1][i+1:]))\n m.append(temp)\n... | [{"input": ["1", "3", "4 7 2 9", "5 6 4 7", "2 6 4 3"], "output": ["10"]}] | interview | |
701 | You are given a sequence of N$N$ powers of an integer k$k$; let's denote the i$i$-th of these powers by kAi$k^{A_i}$. You should partition this sequence into two non-empty contiguous subsequences; each element of the original sequence should appear in exactly one of these subsequences. In addition, the product of (the ... | ["# cook your dish here\ndef main():\n for _ in range(int(input())):\n N, k = [int(x) for x in input().split()]\n Powers = [k ** int(x) for x in input().split()]\n \n s1, s2 = 0, sum(Powers)\n \n ans = (0, None)\n \n i = 0\n while i < N - 1:\n s1 += Powers[i]\n s2 -= Powers[i]\n ... | [{"input": ["1", "5 2", "1 1 3 3 5"], "output": ["4"]}] | interview | |
702 | This is a peculiar functioning setup.
Two Tanks are separated from each other by a wall .There is a pipe in the wall which connects both tanks which allows flow of water between them . Due to this ,there is change in temperature of both tanks , every minute temperature of Tank with larger temperature among two decrea... | ["for i in range(int(input())):\n m,tc,th=map(int,input().split())\n x=(th-tc)\n if x%3!=0:\n print(\"Yes\")\n else:\n if (x//3)<=m:\n print(\"No\")\n else:\n print(\"Yes\")", "T = int(input())\nfor _ in range(T):\n m, Tc, Th = list(map(int, input().split()))\n if (Th - Tc) % 3 != 0:\n print(\"Yes\")\n else:\n ... | [{"input": ["2", "4 5 10", "2 2 5"], "output": ["Yes", "No"]}] | interview | |
703 | Chef gives an integer $K$ in the input. If the given number is beautiful binary number, print it, Else find its previous beautiful binary number. A beautiful binary number is a number whose binary representation does not contain any consecutive 1s.
Note: 1 is also a beautiful binary number.
-----Input:-----
- First-l... | ["pref = []\r\n\r\nfor i in range(10 ** 5 + 10):\r\n b = bin(i)[2:]\r\n if not any(b[j] == b[j+1] == '1' for j in range(len(b) - 1)):\r\n pref.append(i)\r\n else:\r\n pref.append(pref[-1])\r\n\r\nfor i in range(int(input())):\r\n print(pref[int(input())])\r\n"] | [{"input": ["3", "3", "6", "8"], "output": ["2", "5", "8"]}] | interview | |
704 | Eugene has to do his homework. But today, he is feeling very lazy and wants to you do his homework. His homework has the following given maths problem.
You are given three integers: A, N, M. You write the number A appended to itself N times in a row. Let's call the resulting big number X. For example, if A = 120, N = 3... | ["# cook your dish here\nfor _ in range(int(input())):\n a,n,m = map(int,input().split(' '))\n s = len(str(a))\n #print(s)\n c = 10**s - 1\n w = c*m\n b = pow(10,n*s,w)-1\n d = b//c\n ans = (d%m)*(a%m)\n print(ans%m) ", "for _ in range(int(input())):\r\n a,n,m = map(int,input().split(' ')... | [{"input": ["2", "12 2 17", "523 3 11", "", ""], "output": ["5", "6"]}] | interview | |
705 | A city of dimension N x N is constructed with grid of lanes. These lanes are fenced by government so that no one can cross any grid diagonally. Although a train
line runs diagonally from (0,0) to (N,N).
Our chef has a weird kind of phobia and is very afraid to cross the railway line. He is at point (0,0) and wants to ... | ["ar = []\nar.append(1)\nfor i in range(1, 31):\n ar.append(ar[i-1]*(4*i-2)/(i+1))\nt = int(input())\nwhile(t>0):\n n = int(input())\n if(n==0):\n print(0)\n else:\n print(ar[n]*2)\n t=t-1\n"] | [{"input": ["2", "2", "5"], "output": ["4", "84"]}] | interview | |
706 | Chef has $N$ small boxes arranged on a line from $1$ to $N$. For each valid $i$, the weight of the $i$-th box is $W_i$. Chef wants to bring them to his home, which is at the position $0$. He can hold any number of boxes at the same time; however, the total weight of the boxes he's holding must not exceed K at any time,... | ["t=int(input())\nfor i in range(t):\n x,y=0,0\n n,m=list(map(int,input().split()))\n l=list(map(int,input().split()))\n if(max(l)>m):\n print(-1)\n else:\n for i in range(len(l)):\n y+=l[i]\n if(y>m):\n y=l[i]\n x+=1\n if(y>0):\n x+=1\n print(x)\n", "# cook your dish here\nfor __ in range(int(input()))... | [{"input": ["4", "1 1", "2", "2 4", "1 1", "3 6", "3 4 2", "3 6", "3 4 3"], "output": ["-1", "1", "2", "3"]}] | interview | |
707 | In 17th century our Chef was a Wizard. He asked his small son "Anshu" to bring him the secret of the Magical Mountain. The boy after travelling a lot reached the Mountain.
The description of the Mountain was as follows:
- Mountain contains N magical stones. Each of them has a unique number.
- Mountain was divided into... | ["for t in range(eval(input())):\n \n n = eval(input())\n \n a = [ [] for i in range(n+1) ]\n \n for i in range(n-1):\n x,y = list(map( int, input().split() ))\n a[x].append(y)\n a[y].append(x)\n \n vis = [0] * (n+1)\n vis[1] = 1\n\n ans = [1]\n\n t1 = [1]\n t2 = []\n \n while len(t1) > 0 :\n ... | [{"input": ["1", "5", "1 2", "1 3", "2 4", "2 5"], "output": ["1 2 3 4 5"]}] | interview | |
708 | You are given a square matrix $M$ with $N$ rows (numbered $1$ through $N$) and $N$ columns (numbered $1$ through $N$). Initially, all the elements of this matrix are equal to $A$. The matrix is broken down in $N$ steps (numbered $1$ through $N$); note that during this process, some elements of the matrix are simply mar... | ["# cook your dish here\nfor _ in range(int(input())):\n n,k = list(map(int,input().split()))\n mod = 10**9+7\n s=0\n for i in range(1,n+1):\n p = pow(k,(2*i)-1,mod)\n # print(p)\n s=(s+p)%mod\n # print(k)\n k = (p*k)%mod\n print(s)\n\n", "# cook your dish here\nfor _ in range(int(input())):\n n,k = list(map(int,i... | [{"input": ["1", "3 2"], "output": ["511620149"]}] | interview | |
709 | $Gogi$, $Tapu$ and $Sonu$ are the elite members of $Tapu$ $Sena$. $Gogi$ is always stoned and asks absurd questions, But this time he asked a question which seems to be very serious and interesting. $Tapu$ wants to solve this question to impress $Sonu$. He gave an array of length N to $Tapu$, $Tapu$ can perform the fo... | ["# cook your dish here\ntry:\n t = int(input())\n for _ in range(t):\n n = int(input())\n a = list(map(int, input().split()))\n gcd = max(a[0], a[-1])\n \n print(gcd)\nexcept EOFError:pass", "t=int(input())\r\nfor i in range(t):\r\n n = int(input())\r\n a=[int(x) for x in... | [{"input": ["1", "1", "2"], "output": ["2"]}] | interview | |
710 | Blob is a computer science student. He recently got an internship from Chef's enterprise. Along with the programming he has various other skills too like graphic designing, digital marketing and social media management. Looking at his skills Chef has provided him different tasks A[1…N] which have their own scores. Blog... | ["def maxval(arr):\n fn = [float('-inf')]*(len(arr)+1)\n sn = [float('-inf')]*len(arr)\n tn = [float('-inf')]*(len(arr)-1)\n fon = [float('-inf')]*(len(arr)-2)\n for i in reversed(list(range(len(arr)))):\n fn[i] = max(fn[i + 1], arr[i])\n for i in reversed(list(range(len(arr) - 1))):\n s... | [{"input": ["6", "3 9 10 1 30 40"], "output": ["46"]}] | interview | |
711 | The notorious hacker group "Sed" managed to obtain a string $S$ from their secret sources. The string contains only lowercase English letters along with the character '?'.
A substring of $S$ is a contiguous subsequence of that string. For example, the string "chef" is a substring of the string "codechef", but the strin... | ["def convertToParitys(s):\r\n \"\"\"\r\n This converts the string s to an int, which is a bitMap of the parity of each letter\r\n odd ? = first bit set\r\n odd a = second bit set\r\n odd b = third bit set \r\n etc\r\n \"\"\"\r\n keys = '?abcdefghijklmnopqrstuvwxyz'\r\n paritys = {c:0 for c i... | [{"input": ["5", "aa?", "a???", "????", "asfhaslskfak", "af??avvnfed?fav?faf????", ""], "output": ["2", "6", "4", "2", "27"]}] | interview | |
712 | Chef got into a fight with the evil Dr Doof. Dr Doof has decided to destroy all even numbers from the universe using his Evil-Destroy-inator. Chef has $N$ integers with him. To stop Doof, Chef has to find an odd number which is an integer multiple of all $N$ numbers that he has with him. Find if it is possible for Chef... | ["def gcd(a,b):\n if b==0: return a\n return gcd(b,a%b)\n\nfor _ in range(int(input())):\n n = int(input())\n arr = list(map(int,input().split()))\n value = arr[0]\n if n!=1:\n for i in arr[1:]:\n value = value*i//gcd(value, i)\n if value%2==0:\n print(\"NO\")\n else:\n print(\"YES\")", "# cook your dish here\nt=i... | [{"input": ["2", "5", "1 2 5 4 3", "1", "7"], "output": ["NO", "YES"]}] | interview | |
713 | Chef has a sequence of $N$ integers, $A_1, A_2, ... , A_N$. He likes this sequence if it contains a subsequence of $M$ integers, $B_1, B_2, ... , B_M$ within it.
A subsequence is a sequence that can be derived from another sequence by deleting some or no elements without changing the order of the remaining elements.
Y... | ["t=int(input())\ni=0\nwhile i<t:\n n=int(input())\n A=[]\n A=input().split()\n m=int(input())\n B=[]\n B=input().split()\n j=0\n a=-1\n while j<m:\n c=1\n if B[j] in A:\n b=A.index(B[j])\n A.remove(B[j])\n if b>=a:\n a=b\n c=1\n else:\n c=0\n break\n else:\n c=0\n break\n j+=1\n if c==1:\n ... | [{"input": ["3", "6", "1 2 3 4 5 6", "3", "2 3 4", "6", "22 5 6 33 1 4", "2", "4 15", "4", "1 3 4 2", "2", "1 2"], "output": ["Yes", "No", "Yes"]}] | interview | |
714 | It's John's birthday; he has brought some candies in distribute among N of his friends. Being a good friend, he decided to distribute all of his candies equally among his friend and he don't want to keep any for himself. He left the task of distributing candies up to his friends, but his friends haven't done a great jo... | ["# cook your dish here\nimport math\nfor t in range(int(input())):\n n=int(input())\n a=[int(i) for i in input().split()]\n div=sum(a)/n\n div=math.ceil(div)\n count=div*n-sum(a)\n for i in a:\n if i>div:\n count+=i-div\n print(count)", "# cook your dish here\nimport math\nt =i... | [{"input": ["3", "4", "7 8 6 4", "6", "7 3 10 2 3 8", "1", "10"], "output": ["4", "10", "0"]}] | interview | |
715 | Recently Rocky had participated in coding competition and he is sharing one of the problem with you which he was unable to solve. Help Rocky in solving the problem.
Suppose the alphabets are arranged in a row starting with index 0$0$ from AtoZ$A to Z$.
If in a coded language A=27$A=27$ and AND=65$AND=65$.
Help Rocky t... | ["# cook your dish here\ns = input().strip()\nstart_w = 27\nw_dict = {}\nwords = [\"A\", \"B\", \"C\", \"D\", \"E\", \"F\", \"G\", \"H\", \"I\", \"J\", \"K\", \"L\", \"M\", \"N\", \"O\", \"P\", \"Q\", \"R\", \"S\", \"T\", \"U\", \"V\", \"W\", \"X\", \"Y\", \"Z\"]\nfor word in words:\n w_dict[word] = start_w\n sta... | [{"input": ["A", "AND"], "output": ["27", "65"]}] | interview | |
716 | Chef has created a special dividing machine that supports the below given operations on an array of positive integers.
There are two operations that Chef implemented on the machine.
Type 0 Operation
Update(L,R):
for i = L to R:
a[i] = a[i] / LeastPrimeDivisor(a[i])
Type 1 Operation
Get(L,R):
result = 1
for i = ... | ["import math\nn=1001\na=[True]*n\nl=[]\nfor i in range(2,33):\n if(a[i]):\n for j in range(i*i,n,i):\n a[j]=False\nfor pr in range(2,1001):\n if(a[pr]):\n l.append(pr)\nt=int(input())\nfor j in range(t):\n n,m=list(map(int,input().strip().split()))\n arr=[int(num) for num in input().strip().split()]\n Matrix =[]\n... | [{"input": ["2", "6 7", "2 5 8 10 3 44", "1 2 6", "0 2 3", "1 2 6", "0 4 6", "1 1 6", "0 1 6", "1 4 6", "2 2", "1 3", "0 2 2", "1 1 2"], "output": ["5 3 5 11", "1"]}] | interview | |
717 | Today is rose day, batch mates of Kabir and Tara decided to celebrate this day by exchanging roses with each other.
Note:$Note:$ exchanging means both the boy and the girl will give rose to each other.
In the class there are B$B$ boys and G$G$ girls.
Exchange of rose will take place if and only if at least one of th... | ["for i in range(int(input())):\n print(2*(sum(list(map(int, input().split())))-1))", "# cook your dish here\nt=int(input())\nwhile(t>0):\n b,g=input().split()\n b=int(b)\n g=int(g)\n ans=(abs(b+g)-1)*2\n print(ans)\n \n t=t-1", "nn=int(input())\nfor i in range(nn):\n l=list(map(int,input().s... | [{"input": ["1", "2 3"], "output": ["8"]}] | interview | |
718 | 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... | ["import sys\ninput = lambda: sys.stdin.readline().rstrip(\"\\r\\n\")\ninp = lambda: list(map(int,sys.stdin.readline().rstrip(\"\\r\\n\").split()))\n#_______________________________________________________________________________\u00a0\u00a0\u00a0\u00a0_______________________\n# from math import *\n# from bisect import... | [{"input": ["4", "1", "2", "3", "4"], "output": ["0", "0", "1 1", "0", "1 1", "2 3 5", "0", "1 1", "2 3 5", "8 13 21 34"]}] | interview | |
719 | -----Problem-----
Suppose there is a circle. There are N Juice shops on that circle. Juice shops are numbered 0 to N-1 (both inclusive). You have two pieces of information corresponding to each of the juice shop:
(1) the amount of Juice that a particular Juice shop can provide and
(2) the distance from that juice sho... | ["import re,sys\ndef isCirlePossible(juices,distances):\n if juices == [] or distances == []:\n return -1;\n total_juice_consumed = 0\n juice_consumed = 0\n start=0\n for i in range(0,len(juices)):\n diff = juices[i] - distances[i]\n if juice_consumed >= 0:\n juice_consumed += diff\n else:\n juice_consumed = di... | [{"input": ["3", "1 5", "10 3", "3 4"], "output": ["1"]}] | interview | |
720 | All strings in Chefland are beautiful because they are binary strings (a binary string contains only characters '0' and '1'). The beauty of a binary string $S$ is defined as the number of pairs $(i, j)$ ($1 \le i \le j \le |S|$) such that the substring $S_i, S_{i+1}, \ldots, S_j$ is special.
For a binary string $U$, le... | ["t = int(input())\nfor _ in range(t):\n s = input()\n pref = [0]*len(s)\n if s[0]==\"1\":\n pref[0]+=1\n for i in range(1,len(s)):\n if s[i]==\"1\":\n pref[i]+=1\n pref[i]=pref[i]+pref[i-1]\n k=1\n cnt=0\n while (k+k*k)<=len(s):\n r = k+k*k\n i=r-1\n while i<len(s):\n if (i-r)>=0:\n if pref[i]-pref[i-r]==... | [{"input": ["2", "010001", "10"], "output": ["4", "1"]}] | interview | |
721 | Do you know that The Chef has a special interest in palindromes? Yes he does! Almost all of the dishes in his restaurant is named by a palindrome strings. The problem is that a name of a dish should not be too long, so The Chef has only limited choices when naming a new dish.
For the given positive integer N, your tas... | ["# cook your dish here\ndef permutation(n,p):\n r=26\n if n==1:\n return 26\n elif n==2:\n return 52\n elif n==3:\n return 728\n else:\n if n%2==0:\n return ((2*(bin_expo(r,((n//2)+1),p)-r)*bin_expo(25,1000000005,p)))%p\n else:\n n=n+1\n ... | [{"input": ["5", "1", "2", "3", "4", "100", "", ""], "output": ["26", "52", "728", "1404", "508533804"]}] | interview | |
722 | The kingdom of the snakes is an NxN grid. Their most-valued possession is a huge collection of poison, which is stored in the central KxK grid. It is guaranteed that both N and K are odd. What we mean by 'central' is this: suppose in the NxN grid, (i, j) refers to the cell in the i-th row and j-th column and (1,1) refe... | ["'''input\n2\n7 3 5\n5 2 5 2\n2 4 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n7 3 7\n1 1 6 1\n1 2 3 2\n5 2 5 2\n2 6 2 6\n6 2 6 4\n5 6 5 7\n7 1 7 4\n'''\n\nfor _ in range(int(input())):\n n, k, m = list(map(int, input().split()))\n row_s = []\n col_s = []\n for _ in range(m):\n h_x, h_y, t_x, t_y = list(map(int, input().split()))... | [{"input": ["2", "7 3 7", "1 1 6 1", "1 2 3 2", "5 2 5 2", "2 4 2 6", "6 2 6 4", "5 6 5 7", "7 1 7 4", "7 3 7", "1 1 6 1", "1 2 3 2", "5 2 5 2", "2 6 2 6", "6 2 6 4", "5 6 5 7", "7 1 7 4"], "output": ["3", "-1"]}] | interview | |
723 | In this problem, you will be given a polynomial, you have to print what it becomes after differentiation.
Following are the rules for differentiation:
- For a polynomial f(x), its differentiation is defined as f'(x).
- If a is a constant, then differentiation of af(x) is af'(x).
- If f(x) = h(x) + g(x) , then f'(x) = ... | ["def ans(l):\n s = \"\"\n i = 0\n while (i < len(l)):\n temp = l[i]\n k = temp[1]\n if (k != 0):\n s += str(temp[0]) + \"x^\" + str(k)\n else:\n s += str(temp[0])\n i += 1\n if (i < len(l)):\n s += \" + \"\n if (len(s) > 0):\n return s\n else:\n return \"0\"\n \ntest = int(input())\nwhile (test != 0):\n ... | [{"input": ["2", "1", "1 2", "3", "1 3", "1 1", "1 0"], "output": ["2x^1", "3x^2 + 1"]}] | interview | |
724 | Petya is preparing a problem for a local contest in his school. The problem is to find a longest increasing subsequence in a given permutation. A permutation of size n$n$ is a sequence of n$n$ numbers a1,…,an$a_1, \ldots, a_n$ such that every number from 1$1$ to n$n$ occurs in the sequence exactly once. An increasing s... | ["# cook your dish here\nfor _ in range(int(input())):\n n,k = [int(c) for c in input().split()]\n a = [int(c) for c in input().split()]\n ls = a\n if n==1:\n print(\"YES\")\n print(1)\n continue\n if k==1:\n print(\"NO\")\n continue\n \n if k==2 and n>2:\n ... | [{"input": ["2", "3 2", "1 2", "2 1", "1"], "output": ["YES", "2 3 1", "NO"]}] | interview | |
725 | The Little Elephant and his friends from the Zoo of Lviv were returning from the party. But suddenly they were stopped by the policeman Big Hippo, who wanted to make an alcohol test for elephants.
There were N elephants ordered from the left to the right in a row and numbered from 0 to N-1. Let R[i] to be the result of... | ["def magic():\n def check(art,k,m):\n n=len(art)\n for i in range(n-k+1):\n maxi=0\n maxi=max(art[i:i+k])\n\n total=0\n total=art[i:i+k].count(maxi)\n\n if total>=m:\n return False\n\n return True\n \n\n\n for _ in range(eval(input())):\n n,k,m=list(map(int,input().split()))\n arr=list(map(int,input... | [{"input": ["4", "5 3 2", "1 3 1 2 1", "5 3 3", "7 7 7 7 7", "5 3 3", "7 7 7 8 8", "4 3 1", "1 3 1 2"], "output": ["0", "1", "1", "-1"]}] | interview | |
726 | Today, Chef decided to cook some delicious meals from the ingredients in his kitchen. There are $N$ ingredients, represented by strings $S_1, S_2, \ldots, S_N$. Chef took all the ingredients, put them into a cauldron and mixed them up.
In the cauldron, the letters of the strings representing the ingredients completely ... | ["# cook your dish here\nt=int(input())\nwhile t>0:\n n=int(input())\n li=[]\n c,o,d,e,h,f=0,0,0,0,0,0\n for i in range(0,n):\n s=input()\n \n for i in range(len(s)):\n if s[i]=='c':\n c=c+1\n elif s[i]=='o':\n o=o+1\n elif s[i]=='d':\n d=d+1\n elif s[i]=='e':\n e=e+1\n elif s[i]=='h':\n h=h... | [{"input": ["3", "6", "cplusplus", "oscar", "deck", "fee", "hat", "near", "5", "code", "hacker", "chef", "chaby", "dumbofe", "5", "codechef", "chefcode", "fehcedoc", "cceeohfd", "codechef"], "output": ["1", "2", "5"]}] | interview | |
727 | To protect people from evil,
a long and tall wall was constructed a few years ago.
But just a wall is not safe, there should also be soldiers on it,
always keeping vigil.
The wall is very long and connects the left and the right towers.
There are exactly N spots (numbered 1 to N) on the wall for soldiers.
The Kth... | ["D=[0]*31\nD[1]=2\nD[2]=5\n\nfor i in range(3,31):\n best=10**10\n for p in range(1,i+1):\n best=min(best,D[p-1]+D[i-p]+i+1)\n D[i]=best\n\nt=int(input())\nfor i in range(t):\n n,m=list(map(int,input().split()))\n maxi=(n+2)*(n+1)/2-1\n mini=D[n]\n if mini<=m<=maxi: print(0)\n elif m<mini: print(-1)\n else: print(m-m... | [{"input": ["4", "3 8", "3 9", "2 4", "5 25"], "output": ["0", "0", "-1", "5"]}] | interview | |
728 | Given a square matrix of size N×N, calculate the absolute difference between the sums of its diagonals.
-----Input-----
The first line contains a single integer N. The next N lines denote the matrix's rows, with each line containing N space-separated integers describing the columns.
-----Output-----
Print the absolu... | ["def diagonal_difference(matrix):\n l = sum(matrix[i][i] for i in range(N))\n r = sum(matrix[i][N-i-1] for i in range(N))\n return abs(l - r)\n\nmatrix = []\nN = eval(input())\nfor _ in range(N):\n matrix.append(list(map(int, input().split())))\n\nprint(diagonal_difference(matrix))"] | [{"input": ["3", "11 2 4", "4 5 6", "10 8 -12"], "output": ["15"]}] | interview | |
729 | You are given a matrix of integers $A$ with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$). Each element of this matrix is either $0$ or $1$.
A move consists of the following steps:
- Choose two different rows $r_1$ and $r_2$ or two different columns $c_1$ and $c_2$.
- Apply the bitwise ... | ["t=int(input())\nfor _ in range(t):\n n,m=map(int,input().split())\n d={}\n e={}\n l=[]\n for i in range(n):\n d[i]=0\n for i in range(m):\n e[i]=0\n for i in range(n):\n l.append(input())\n for i in range(n):\n for j in range(m):\n if l[i][j]=='1':\n d[i]=1\n e[j]=1\n #ans=[]\n if sum(d.values())+sum(e.va... | [{"input": ["1", "3 3", "010", "000", "001"], "output": ["1 0 1", "2 1 1", "1 1 0"]}] | interview | |
730 | Every Friday Chef and his N - 1 friends go for a party. At these parties, they play board games. This Friday, they are playing a game named "Boats! Boats! Boats!". In this game players have to transport cookies between Venice and Constantinople. Each player has a personal storage. The players are numbered from 1 to N, ... | ["# cook your code here\nfor _ in range(eval(input())):\n n=eval(input())\n ind=0\n m=-1\n \n for i in range(n):\n \n l=[int(x) for x in input().split()]\n sc=l[0]\n for j in range(1,len(l)):\n sc+=int(l[j]>=4)+int(l[j]>=5)+2*int(l[j]>=6)\n if sc==m:\n ind=-2\n if sc>m :\n m=sc\n ind=i+1\n \n \n if (in... | [{"input": ["3", "2", "6 1 2 3 4 5 6", "9 3 3 3 4 4 4 5 5 5", "2", "5 2 3 4 5 6", "7 1 1 2 2 3 3 4", "3", "4 1 1 2 3", "4 1 2 2 3", "4 1 2 3 3"], "output": ["chef", "2", "tie"]}] | interview | |
731 | -----Indian National Olympiad in Informatics 2014-----
Nikhil’s slogan has won the contest conducted by Drongo Airlines and he is entitled to a free ticket between any two destinations served by the airline. All cities served by Drongo Airlines can be reached from each other by some sequence of connecting flights. Nikh... | ["c,f=list(map(int,input().split()))\r\nl=[[1000001 for i in range(c)] for j in range(c)] \r\nwhile f:\r\n x,y,cost=list(map(int,input().split()))\r\n l[x-1][y-1]=cost\r\n l[y-1][x-1]=cost\r\n f-=1 \r\nfor i in range(c):\r\n l[i][i]=0\r\nfor k in range(c): \r\n for x in range(c):\r\n for y in ... | [{"input": ["4 5", "1 2 10", "1 3 24", "2 3 2", "2 4 15", "3 4 7"], "output": ["19", "Note : Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your final submission. A program with extraneous output will be treated as in... | interview | |
732 | Alice and Bob are walking on an infinite straight street. Initially, both are at the position $X=0$ and they start walking in the direction of increasing $X$. After $N$ seconds, they stop. Let's denote Alice's speed and Bob's speed during the $i$-th of these seconds by $A_i$ and $B_i$ respectively.
Sometimes, Alice and... | ["# cook your dish here\nfor tc in range(int(input())):\n \n n = int(input())\n \n li1 = list(map(int,input().split(' ')))\n li2 = list(map(int,input().split(' ')))\n walk = 0\n sum1 = 0 \n sum2 = 0\n for i in range(n):\n if li1[i] == li2[i] and sum1 == sum2:\n walk += li1[i]\n sum1 += li1[i]\n sum2 += li2[i]\n pr... | [{"input": ["3", "4", "1 3 3 4", "1 2 4 4", "2", "2 3", "3 2", "2", "3 3", "3 3"], "output": ["5", "0", "6"]}] | interview | |
733 | Given a string consisting of only lowercase English alphabets, your task is to find the smallest palindromic substring.
In case there are multiple palindromic substrings of the same length present, print the lexicographically smallest substring.
Formally, a substring is a contiguous sequence of characters within a str... | ["# cook your dish here\nT = int(input())\nfor t in range(T):\n N = int(input())\n s = sorted(list(str(input())))\n print(s[0])", "for t in range(int(input())):\n n=int(input())\n s=sorted(list(str(input())))\n print(s[0])", "T = int(input())\nfor t in range(T):\n N = int(input())\n s = sorted(list(str(input())... | [{"input": ["2", "2", "zy", "1", "cd"], "output": ["y", "c"]}] | interview | |
734 | Chef has $N$ markers. There is a cap on each marker. For each valid $i$, the $i$-th marker has colour $a_i$. Initially, for each valid $i$, the colour of the cap on the $i$-th marker is also $a_i$.
Chef wants to rearrange the caps in such a way that no marker has the same colour as its cap. (Obviously, each marker must... | ["# cook your dish here\nfrom collections import Counter,defaultdict\n\nfor i in range(int(input())):\n n=int(input())\n arr=list(map(int,input().split()))\n coun=Counter(arr)\n check=True\n\n for j in coun:\n if coun[j]>n//2:\n print(\"No\")\n check=False\n break\n\n\n\n\n if check==True:\n print(\"Yes\")\n n... | [{"input": ["2", "9", "1 1 1 2 2 2 3 3 3", "2", "1 1"], "output": ["Yes", "2 2 2 3 3 3 1 1 1", "No"]}] | interview | |
735 | Harish has decided to go to Arya's hotel this morning. We all know he is crazy for masala dosas. And as usual he is always hungry. He decided to order all the masala dosas at once. But then he realised that he did not have enough money to buy all of them. So he decided to share the amount with his friend Ozil. But both... | ["for _ in range(eval(input())):\n n=eval(input())\n if n%2:\n print('NO')\n else:\n print('YES') ", "tc=int(input())\nfor case in range(tc):\n n=int(input())\n if n%4==0:\n print(\"YES\")\n else:\n print(\"NO\")\n", "t = eval(input())\nwhile t:\n t=~(-t)\n n = eval(input())\n print(\"NO\" if (n==2 or n%2!=0) else ... | [{"input": ["2", "16", "27"], "output": ["YES", "NO"]}] | interview | |
736 | Gargi is thinking of a solution to a problem. Meanwhile, her friend asks her to solve another problem. Since Gargi is busy in her own problem, she seeks your help to solve the new problem.
You are given a string S containing characters a-z (lower case letters) only. You need to change the string to a new string consis... | ["t = int(input())\nfor i in range(t):\n s = input().rstrip()\n sumv = 0\n for j in range(len(s)):\n sumv += ord(s[j])\n minv = 10 ** 8;\n for i in range(ord('a'), ord('z') + 1):\n val = abs(sumv - i * len(s))\n if minv > val:\n minv = val\n print(minv)", "for t in range(int(input())):\n s = input()\n a = [0]*26\n... | [{"input": ["1", "abba"], "output": ["2"]}] | interview | |
737 | Rodriguez is a happy and content farmer. He has got a square field of side length $x$. Miguel, his son has himself grown into a man and his father wants to gift him something out of which he can make a living. So he gift's his son a square piece of land cut out from a corner of his field of side length $ y (y < x) $ le... | ["from math import sqrt\ndef isPrime(n):\n for i in range(2, int(sqrt(n))+1):\n if(n%i==0): return True\n return False\nans = []\nfor _ in range(int(input())):\n x, y = map(int, input().split())\n ans.append('NO' if(isPrime(x**2-y**2)) else 'YES')\nprint('\\n'.join(ans))"] | [{"input": ["2", "7 5", "6 5"], "output": ["YES", "NO"]}] | interview | |
738 | Calculate the power of an army of numbers from 1 to $N$, both included.
-----Input:-----
- First line will contain a single integer $N$.
-----Output:-----
For each testcase, output in a single line containing the answer.
-----Constraints-----
- $1 \leq N \leq 5000$
-----Sample Input:-----
24
-----Sample Output:---... | ["# cook your dish here\n# cook your dish here\n#powerful numbers\nn = int(input())\nplist = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, ... | [{"input": ["24"], "output": ["5"]}] | interview | |
739 | Mr. X stays in a mansion whose door opens in the North. He travels every morning to meet his friend Ms. Y walking a predefined path.
To cut the distance short, one day he decides to construct a skywalk from his place to his friend’s place. Help him to find the shortest distance between the two residences.
-----Input... | ["#!/usr/bin/env python\n\nfrom math import sqrt\n\ndef process(S):\n P = [0,0,'S']\n for i in S:\n if i == 'L':\n if P[-1] == 'N': P[-1] = 'W'\n elif P[-1] == 'S': P[-1] = 'E'\n elif P[-1] == 'E': P[-1] = 'N'\n elif P[-1] == 'W': P[-1] = 'S'\n elif i == 'R':\n if P[-1] == 'N': P[-1] = 'E'\n elif P[-1] ==... | [{"input": ["1", "2 L 2 R 2 L 1"], "output": ["5.0NW"]}] | interview | |
740 | There is a field with plants — a grid with $N$ rows (numbered $1$ through $N$) and $M$ columns (numbered $1$ through $M$); out of its $NM$ cells, $K$ cells contain plants, while the rest contain weeds. Two cells are adjacent if they have a common side.
You want to build fences in the field in such a way that the follow... | ["t=int(input())\nwhile(t):\n t-=1\n d={}\n n,m,k=[int(x) for x in list(input().split())]\n sum=0\n while(k):\n k-=1\n x,y=[int(x) for x in list(input().split())]\n a=[-1,1,0,0]\n b=[0,0,-1,1]\n for i in range(4):\n if((x+a[i],y+b[i]) in d):\n sum-=1\n else:\n sum+=1\n d[(x,y)]=1\n print(sum)", "# cook ... | [{"input": ["2", "4 4 9", "1 4", "2 1", "2 2", "2 3", "3 1", "3 3", "4 1", "4 2", "4 3", "4 4 1", "1 1"], "output": ["20", "4"]}] | interview | |
741 | Given a positive integer K > 2, with prime
factorization:
K = p1^a1 * p2^a2 ... * pn^an
Compute the following:
S = a1*p1 + a2*p2 ... + an*pn.
-----Input-----
A list of <100 integers, one on each line,
all less than $2*10^{18}$.
-----Output-----
For each integer compute the super factor
sum and output it on a singl... | ["import random\nimport os\nyash=(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317,331,337,347,349,353,359,367,373,379,383,389,397,401... | [{"input": ["6", "7"], "output": ["5", "7"]}] | interview | |
742 | Rakesh has built a model rocket and wants to test how stable it is. He usually uses a magic box which runs some tests on the rocket and tells if it is stable or not, but his friend broke it by trying to find out how stable he is (very delicate magic indeed). The box only gives a polynomial equation now which can help R... | ["import random\n\ndef sign(i):\n if i>0:\n return 1\n elif i<=0:\n return 0\nbleh = []\nfor _ in range(int(input())):\n p = list(map(int,input().rstrip().split()))\n max_rows = len(p)\n if all([x==0 for x in p]):\n print(1)\n continue\n if max_rows <= 1:\n bleh.appe... | [{"input": ["1", "10 12 4 5 3"], "output": ["0"]}] | interview | |
743 | Yesterday, Chef found $K$ empty boxes in the cooler and decided to fill them with apples. He ordered $N$ apples, where $N$ is a multiple of $K$. Now, he just needs to hire someone who will distribute the apples into the boxes with professional passion.
Only two candidates passed all the interviews for the box filling ... | ["# cook your dish here\nt=int(input())\nfor i in range(t,0,-1):\n x,y=map(int,input().split())\n k=x//y\n \n if k%y==0:\n print(\"NO\")\n else:\n print(\"YES\")", "# cook your dish here\nt = int(input())\nfor _ in range(t):\n n,k = map(int,input().split())\n if(n%(k*k)==0):\n print(\"NO\")\n else:\n print(\"YES\")... | [{"input": ["3", "5 1", "4 2", "10 10"], "output": ["NO", "NO", "YES"]}] | interview | |
744 | The chef is trying to solve some pattern problems, Chef wants your help to code it. Chef has one number K (odd) to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single li... | ["t=int(input())\nfor _ in range(t):\n n=int(input())\n l1=[]\n if n==1:\n print('*')\n elif n==3:\n print('*')\n print('**')\n print('*')\n else:\n s1=\"\"\n n1=n//2\n n1+=1 \n for i in range(1,n1+1):\n s1=\"\"\n if i==1:\n ... | [{"input": ["4", "1", "3", "5", "7"], "output": ["*", "*", "**", "*", "*", "**", "* *", "**", "*", "*", "**", "* *", "* *", "* *", "**", "*"]}] | interview | |
745 | You want to build a temple for snakes. The temple will be built on a mountain range, which can be thought of as n blocks, where height of i-th block is given by hi. The temple will be made on a consecutive section of the blocks and its height should start from 1 and increase by exactly 1 each time till some height and ... | ["# cook your dish here\n\nt = int(input())\nwhile t:\n t -= 1\n n = int(input())\n arr = list(map(int, input().split()))\n sumi = sum(arr)\n prev = 1\n for i in range(n):\n arr[i] = min(arr[i], prev)\n prev = arr[i] + 1\n prev = 1\n for i in range(n - 1, -1, -1):\n arr[i] = min(arr[i], prev)\n prev = arr[i] + 1\n ... | [{"input": ["3", "3", "1 2 1", "4", "1 1 2 1", "5", "1 2 6 2 1"], "output": ["0", "1", "3"]}] | interview | |
746 | Given a complete binary tree with the height of H, we index the nodes respectively top-down and left-right from 1. The i-th node stores a positive integer Vi. Define Pi as follows: Pi=Vi if the i-th node is a leaf, otherwise Pi=max(Vi*PL, Vi*PR), where L and R are the indices of the left and right children of i, respec... | ["def treeProduct(num, h, root, ch):\n if ch >= h:\n return num[root]\n\n left = (root * 2) + 1\n right = (root * 2) + 2\n\n ret1 = treeProduct(num, h, left, ch + 1)\n ret2 = treeProduct(num, h, right, ch + 1)\n\n return num[root] * max(ret1, ret2)\n\ndef main():\n n = int(input())\n while n!=0:\n line = str(input())... | [{"input": ["2", "1 2 3", "3", "3 1 5 2 6 4 7", "0"], "output": ["3", "105"]}] | interview | |
747 | Chef received a new sequence $A_1, A_2, \ldots, A_N$. He does not like arbitrarily ordered sequences, so he wants to permute the elements of $A$ in such a way that it would satisfy the following condition: there is an integer $p$ ($1 \le p \le N$) such that the first $p$ elements of the new (permuted) sequence are stri... | ["for _ in range(int(input())):\n n = int(input())\n\n arr= list(map(int,input().split()))\n arr.sort()\n d={}\n for i in arr:\n if i not in d:\n d[i]=1\n else:\n d[i]+=1\n \n flag = True\n for i in d:\n if d[i]>2:\n flag=False\n break\n \n \n\n if arr.count(max(arr))!=1:\n flag=False\n \n \n if flag==Tru... | [{"input": ["5", "4", "1 3 2 4", "4", "1 3 2 4", "6", "1 10 10 10 20 15", "5", "1 1 2 2 3", "4", "1 2 3 3"], "output": ["YES", "1 2 3 4", "YES", "4 3 2 1", "NO", "YES", "1 2 3 2 1", "NO"]}] | interview | |
748 | Chef has a cubic die with 6 faces kept on an infinite plane. Each face has a distinct integer in the range [1,6] written on it, but the exact arrangement of the numbers on the faces of the die is unknown to Chef. Curiosity gets the better of Chef and he wants to find out o(1), o(2), ..., o(6), where o(i) is the number... | ["from itertools import permutations\n\ndef solve(n,a):\n ans=[]\n \n for des in desire:\n check=1\n for i in range(n-1):\n \n if (a[i]==a[i+1]):\n return [-1]\n if a[i+1]==des[a[i]-1]:\n check=0\n break\n if check:\n ans=des\n break\n if ans:\n return ans\n return [-1]\n \n\nper=permutations([... | [{"input": ["4", "9", "1 3 4 6 1 3 4 6 1", "10", "1 2 1 3 1 4 1 5 1 6", "6", "1 2 3 4 5 6", "4", "1 3 3 1"], "output": ["2 1 6 5 4 3", "-1", "4 5 6 1 2 3", "-1"]}] | interview | |
749 | The Government of Siruseri is no different from any other when it comes to being "capital-centric" in its policies. Recently the government decided to set up a nationwide fiber-optic network to take Siruseri into the digital age. And as usual, this decision was implemented in a capital centric manner --- from each city... | ["n=int(input())\r\nl=[]\r\nfor i in range(n):\r\n\tl.append([int(x) for x in input().split()])\r\nd=[10**9]*(n)\r\nq=set([int(x) for x in range(1,n)])\r\nd[1]=0\r\n#print(q)\r\ndef extract():\r\n\tmini=10**9\r\n\to=0\r\n\tfor i in range(1,len(d)):\r\n\t\tif d[i]<mini and i in q:\r\n\t\t\tmini=d[i]\r\n\t\t\to=i\r\n\tq.... | [{"input": ["4", "0 7 8 10", "7 0 4 5", "8 4 0 6", "10 5 6 0"], "output": ["9"]}] | interview | |
750 | Some programming contest problems are really tricky: not only do they
require a different output format from what you might have expected, but
also the sample output does not show the difference. For an example,
let us look at permutations.
A permutation of the integers 1 to n is an
ordering of
these integers. So the ... | ["def invper(ar):\n ar1=[0]*(len(ar))\n for i in range(len(ar)):\n ar1[ar[i]-1]=i+1\n return ar1\nt=int(input())\n\nwhile(t!=0):\n ar=list(map(int,input().split()))\n ar1=invper(ar)\n if(ar==ar1):\n print(\"ambiguous\")\n else:\n print(\"not ambiguous\")\n t = int(input())\n", "while int(input()) != 0:\n l = list(ma... | [{"input": ["4", "1 4 3 2", "5", "2 3 4 5 1", "1", "1", "0"], "output": ["ambiguous", "not ambiguous", "ambiguous"]}] | interview | |
751 | There are n villages in a Chefland. Some of the villages have electricity facilities, other doesn't. You can consider the villages arranged in line in the order 1 to n from left to right. i-th of village can be considered at xi coordinates.
Chef decided that electricity should be provided to all the villages. So, he d... | ["for _ in range(int(input())):\n n=int(input())\n s=list(input())\n coord=list(map(int,input().split()))\n p=0\n i=0\n h=[]\n for i in range(0,n):\n if s[i]=='1':\n h.append(i)\n if h[0]!=0:\n p=p+coord[h[0]]-coord[0]\n if h[len(h)-1]!=n-1:\n p=p+coord[n-1]-coord[h[len(h)-1]]\n for j in range(0,len(h)-1):\n if h... | [{"input": ["2", "2", "01", "1 2", "3", "100", "1 5 6"], "output": ["1", "5"]}] | interview | |
752 | Many internet protocols these days include the option of associating a
media type with the content being sent.
The type is usually inferred from the file extension.
You are to write a program that facilitates the lookup of media types for
a number of files.
You will be given a table of media type associations that asso... | ["# cook your dish here\nn,m=list(map(int,input().split()))\na={}\nfor i in range(n):\n x,y=input().split()\n a[x]=y\nfor i in range(m):\n c=input().strip()\n if '.' not in c:\n print(\"unknown\")\n else:\n h=c.split('.')[-1]\n if h in a:\n print(a[h])\n else:\n print('unknown')\n \n \n", "# cook your dish her... | [{"input": ["5 6", "html text/html", "htm text/html", "png image/png", "svg image/svg+xml", "txt text/plain", "index.html", "this.file.has.lots.of.dots.txt", "nodotsatall", "virus.exe", "dont.let.the.png.fool.you", "case.matters.TXT"], "output": ["text/html", "text/plain", "unknown", "unknown", "unknown", "unknown"]}] | interview | |
753 | It's autumn now, the time of the leaf fall.
Sergey likes to collect fallen leaves in autumn. In his city, he can find fallen leaves of maple, oak and poplar. These leaves can be of three different colors: green, yellow or red.
Sergey has collected some leaves of each type and color. Now he wants to create the biggest n... | ["for t in range(int(input())):\r\n\tl1=list(map(int,input().split()))\r\n\tl2=list(map(int,input().split()))\r\n\tl3=list(map(int,input().split()))\r\n\tmax=0\r\n\tg=l1[0]+l2[0]+l3[0]\r\n\ty=l1[1]+l2[1]+l3[1]\r\n\tr=l1[2]+l2[2]+l3[2]\r\n\tif g%2==0:\r\n\t\tg-=1\r\n\tif y%2==0:\r\n\t\ty-=1\r\n\tif r%2==0:\r\n\t\tr-=1\r... | [{"input": ["1", "1 2 3", "3 2 1", "1 3 4"], "output": ["7"]}] | interview | |
754 | Chef has a number N, Cheffina challenges the chef to check the divisibility of all the permutation of N by 2. If any of the permutations is divisible by 2 then print 1 else print 0.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single... | ["# cook your dish here\nfor i in range(int(input())):\n n = int(input())\n flag = 0\n while(n>0):\n if((n%10)%2 == 0):\n flag = 1\n break\n n = n//10\n if(flag == 0):\n print(0)\n else:\n print(1)", "testcases=int(input())\r\nfor i in range(testcases):\r... | [{"input": ["2", "19", "385"], "output": ["0", "1"]}] | interview | |
755 | Akshay is interested in mathematics, one day he came across a problem of modulus operator.He has a list of M integers say arr[M] and has to find all integers K such that :
- K > 1
- arr[1]%K = arr[2]%K = arr[3]%K = … = arr[M]%K where '%' is a modulus operator.
Help Akshay to find all such K's.
-----Input:-----
- Firs... | ["l = []\nfor _ in range(int(input())):\n l.append(int(input()))\nfor i in range(2,max(l)):\n r = [x%i for x in l]\n if len(set([x%i for x in l])) == 1:\n print(i, end = ' ')\n", "def find_gcd(x, y): \r\n\t\r\n\twhile(y): \r\n\t\tx, y = y, x % y \r\n\t\r\n\treturn x \r\n\t\t\r\ndef print_factors(x):\r\n... | [{"input": ["3", "38", "6", "34"], "output": ["2 4"]}] | interview | |
756 | Farmer Feb has three fields with potatoes planted in them. He harvested x potatoes from the first field, y potatoes from the second field and is yet to harvest potatoes from the third field. Feb is very superstitious and believes that if the sum of potatoes he harvests from the three fields is a prime number (http://en... | ["# cook your dish here\nimport math\ntry:\n def prime(n):\n for i in range(2, int(math.sqrt(n)) + 1):\n if n % i == 0:\n return False\n return True\n \n for t in range(int(input())):\n x, y = list(map(int, input().split()))\n s = x + y \n i = s\n while(1):\n if prime(s + 1):\n ans = s + 1\n break... | [{"input": ["2", "1 3", "4 3"], "output": ["1", "4"]}] | interview | |
757 | Saket loves to play with strings. One day , while he was having fun with Cyclic Permutations of available strings to him, he observed that despite being scarce in numbers Vowels were really clingy.Being clingy means for almost every given string, there was a Cyclic Permutation in which atleast two vowels were together.... | ["for t in range(int(input())):\r\n\tn=int(input())\r\n\ts=input().strip()\r\n\tc=0\r\n\tflag=0\r\n\tfor i in range(n):\r\n\t\tif (s[i]==\"A\" or s[i]==\"E\" or s[i]==\"I\" or s[i]==\"O\" or s[i]==\"U\") and (s[i-1]==\"A\" or s[i-1]==\"E\" or s[i-1]==\"I\" or s[i-1]==\"O\" or s[i-1]==\"U\") :\r\n\t\t\tflag=1\r\n\tif fl... | [{"input": ["2", "5", "AUXFC", "6", "XBCDEF"], "output": ["Yes", "No"]}] | interview | |
758 | Everyone loves short problem statements.
Given a function $ f(x) $ find its minimum value over the range $ 0 < x < π/2$
$
f(x) = ( x^2 + b*x + c ) / sin( x )
$
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single line of input, two re... | ["import sys\nimport math\ninput=sys.stdin.readline\ndef binary(l,r,co,b,c):\n x=(l+r)/2\n #print(x)\n val1=(2*x+b)*math.sin(x)\n val2=(x**2+b*x+c)*math.cos(x)\n x=(l+r)/2\n val=val1-val2\n if(abs(val)<.0000001 or co==150):\n return (l+r)/2\n if(val<0):\n return binary((l+r)/2,r,co+1,b,c)\n else:\n return binary(l,(... | [{"input": ["1", "2 2"], "output": ["5.8831725615"]}] | interview | |
759 | Tara was completing an Algorithms assignment and got stuck on a question. She thought of who can help her, and got reminded of Kabir who has good problem solving skills. The question is:
Given N$N$ the number of elements in the sequence A1$A_1$,A2$A_2$ … An$A_n$. Find out the prime factor which occurred maximum number ... | ["# cook your dish here\nstore=[0]*(10**5+1)\ndef sieve():\n\tfor i in range(2,10**5+1):\n\t\tif(store[i]==0):\n\t\t\tstore[i]=1\n\t\t\tfor j in range(i,10**5+1,i):\n\t\t\t\tstore[j]=i\nsieve()\n# print(store)\nfor _ in range(int(input())):\n\t\n\tn=int(input())\n\tli=[int(x) for x in input().split()]\n\n\tdp=[0]*(10**... | [{"input": ["1", "7", "3 2 15 6 8 5 10"], "output": ["5"]}] | interview | |
760 | Sereja has a string A consisting of n lower case English letters.
Sereja calls two strings X and Y each of length n similar if they can be made equal by applying the following operation at most once in each of them.
- Chose any two position i, j in the string (i can be equal to j too). Swap the characters at positio... | ["import math\ndef egcd(a, b):\n if a == 0:\n return (b, 0, 1)\n else:\n g, y, x = egcd(b % a, a)\n return (g, x - (b // a) * y, y)\n\ndef modin(a, m):\n g, x, y = egcd(a, m)\n return x % m\n# def gcdexten(a,b,x,y):\n# \tif a == 0:\n# \t\tx = 0\n# \t\ty = 1\n# \t\treturn b\n# \tx1 = y1 ... | [{"input": ["2", "z", "abcd", "", ""], "output": ["0", "144"]}] | interview | |
761 | Chef spent N days working really hard! He planned loads of tasks: as many as Ai tasks to do on the ith day! Chef's work was brutal, so he only managed to finish Bi tasks on the ith day.
The good news is that Chef has a Time Machine!
The Time Machine has K white buttons and M black buttons. Each button has a positive i... | ["t=int(input())\n\ndef diffe(a,b):\n return int(a-b)\n\nwhile t :\n t=t-1\n \n lia=[]\n lib=[]\n lik=[]\n lim=[]\n liab=[]\n likm=[]\n n,k,m=list(map(int,input().split()))\n \n \n lia=list(map(int,input().split()))\n lib=list(map(int,input().split()))\n lik=list(map(int,input().split()))\n lim=list(map(int,input().spl... | [{"input": ["1", "4 2 2", "5 7 6 1", "3 3 1 1", "6 3", "1 4"], "output": ["3"]}] | interview | |
762 | The chef is trying to decode some pattern problems, Chef wants your help to code it. Chef has one number K to form a new pattern. Help the chef to code this pattern problem.
-----Input:-----
- First-line will contain $T$, the number of test cases. Then the test cases follow.
- Each test case contains a single line of... | ["t=int(input())\nwhile(t):\n n=int(input())\n cnt=1;\n for i in range(n):\n s=\"\"\n for j in range(n):\n s=s+str(bin(cnt))[2:][: : -1]+\" \"\n cnt=cnt+1\n print(s)\n \n t=t-1", "# cook your dish here\nfor _ in range(int(input())):\n n = int(input())... | [{"input": ["4", "1", "2", "3", "4"], "output": ["1", "1 01", "11 001", "1 01 11", "001 101 011", "111 0001 1001", "1 01 11 001", "101 011 111 0001", "1001 0101 1101 0011", "1011 0111 1111 00001"]}] | interview | |
763 | You are given two binary strings $S$ and $P$, each with length $N$. A binary string contains only characters '0' and '1'. For each valid $i$, let's denote the $i$-th character of $S$ by $S_i$.
You have to convert the string $S$ into $P$ using zero or more operations. In one operation, you should choose two indices $i$ ... | ["\ndef solve(s, p):\n diffs = 0\n for x, y in zip(s, p):\n if x == y:\n continue\n if x == '0':\n if diffs < 1:\n return \"No\"\n diffs -= 1\n else:\n diffs += 1\n return \"Yes\" if diffs == 0 else \"No\"\n\nfor _ in range(int(input())):\n l = int(input())\n s = input().strip()\n p = input().strip()\n pr... | [{"input": ["3", "2", "00", "00", "3", "101", "010", "4", "0110", "0011"], "output": ["Yes", "No", "Yes"]}] | interview | |
764 | Chef has just found a recipe book, where every dish consists of exactly four ingredients.
He is going to choose some two dishes and prepare them for dinner.
Of course, he likes diversity and wants to know whether the two dishes are similar.
Two dishes are called similar if at least half of their ingredients are the sam... | ["# cook your dish here\nt=int(input())\ni=0\nwhile i<t:\n a=[]\n a=input().split()\n b=[]\n b=input().split()\n j=0\n c=0\n while j<4:\n if a[j] in b:\n c+=1\n j+=1\n if c>=2:\n print(\"similar\")\n else:\n print(\"dissimilar\")\n i+=1", "# cook your dish here\nn=int(input())\nl=[]\nfor i in range(0,n):\n s1=lis... | [{"input": ["5", "eggs sugar flour salt", "sugar eggs milk flour", "aa ab ac ad", "ac ad ae af", "cookies sugar grass lemon", "lemon meat chili wood", "one two three four", "one two three four", "gibberish jibberish lalalalala popopopopo", "jibberisz gibberisz popopopopu lalalalalu"], "output": ["similar", "similar", "... | interview | |
765 | Chef likes to travel a lot. Every day Chef tries to visit as much cities as possible. Recently he had a quite a few trips of great Chefland for learning various recipes. Chefland had N cities numbered from 1 to N. People in Chefland are very friendly, friendliness of i-th city is given by Fi.
Before starting of each t... | ["n=int(input())\na=list(map(int,input().split()))\nq=int(input())\nwhile q>0:\n i=1\n tot=a[0]\n b=list(map(int,input().split()))\n if b[0]==1:\n #p,f=map(int,raw_input().split())\n a[b[1]-1]=b[2]\n else:\n #r=int(raw_input())\n tot=a[0]\n while 1+i*b[1]<=n:\n tot=tot*a[i*b[1]]\n i=i+1\n m=(str)(tot)\n tot=... | [{"input": ["5", "1 2 3 4 5", "3", "2 1", "1 3 10", "2 2"], "output": ["1 120", "5 50"]}] | interview | |
766 | Chef has an array of N natural numbers. Cheffina challenges the chef to choose the two numbers from the array and following the condition as the area of the rectangle formed from the two numbers is maximum. Cheffina also asks the chef to choose two numbers different from the previous two to form the rectangle with a mi... | ["import sys\r\nimport math\r\nimport bisect\r\nfrom sys import stdin,stdout\r\nfrom math import gcd,floor,sqrt,log\r\nfrom collections import defaultdict as dd\r\nfrom bisect import bisect_left as bl,bisect_right as br\r\n\r\nsys.setrecursionlimit(100000000)\r\n\r\nii =lambda: int(input())\r\nsi =lambda: input... | [{"input": ["1", "5", "4 2 1 5 3"], "output": ["20 2"]}] | interview | |
767 | Indian National Olympiad in Informatics 2012
The Republic of Tutaria is celebrating its 37th year of independence. To mark the occasion, the nation is organising a contest where all its N citizens take part. The event has three tracks, a COBOL programming competition, pole vault, and a doughnut-eating competition. Each... | ["# cook your dish here\nwhile True:\n try:\n n=int(input())\n lis=[]\n for i in range(n):\n k=list(map(int,input().split()))\n k.append(k[1]+k[2])\n lis.append(k)\n \n #print(lis)\n p=sorted(lis,key=lambda x:x[3],reverse=True)\n #prin... | [{"input": ["and output corresponding to the example above.", "Sample input", "3", "18 7 6", "23 10 27", "20 9 14", "Sample output", "74", "Note: Your program should not print anything other than what is specified in the output format. Please remove all diagnostic print statements before making your final submission. ... | interview | |
768 | The MEX of a set of integers is defined as the smallest non-negative integer that does not belong to this set. For example, $\mathrm{MEX}(\{0,2,3\}) = 1$ and $\mathrm{MEX}(\{1,3\}) = 0$.
Chef has a tree with $N$ nodes (numbered $1$ through $N$). The tree is rooted at node $1$. Chef wants to assign a non-negative intege... | ["# cook your dish here\n# cook your dish here\nfrom math import log2;\nimport sys;\n\nsys.setrecursionlimit(10 ** 7)\nfrom collections import defaultdict\n\ninf = float(\"inf\")\ndef find_height(node):\n nodes[node]=1\n for i in graph[node]:\n nodes[node]+=find_height(i)\n return nodes[node]\ndef find_... | [{"input": ["2", "3", "1 1", "5", "1 1 2 2", ""], "output": ["4", "9"]}] | interview | |
769 | Pushkar is very good in Number Theory. He takes two numbers $A\ and\ B$ and declares them a Pushkar Pair. Pushkar Pair has a property that $A$ has a $Modular\ Inverse$ modulo $B$.
He asks you to tell him the largest number $L$ that divides both of them.
-----Input:-----
- First line will contain $T$, number of tes... | ["import math\nfor i in range(int(input())):\n a,b = map(int,input().split())\n print(math.gcd(a,b))", "# cook your dish here\nt=int(input())\ndef gcd(a,b):\n big=max(a,b)\n small=min(a,b)\n while small:\n big,small=small,big%small\n return(big)\nfor __ in range(t):\n a,b=list(map(int, input(). split(\" \")))\n print(... | [{"input": ["1", "3 4"], "output": ["1"]}] | interview | |
770 | You are given an array $a$ of length $n$. A subsequence of this array is valid, if it satisfies these two conditions:
- There shouldn't be any two even numbers within a distance of $K$, both which have been chosen in the subsequence. i.e. there shouldn't be two indices $i, j$ such that $a_i$ and $a_j$ are even, $|i - j... | ["import sys\nimport math\n\ndef main(arr,k):\n \n \n x=[]\n y=[]\n \n \n \n for e in arr:\n if e%2==0:\n x.append(e)\n y.append(0)\n else:\n x.append(0)\n y.append(e)\n \n a=[0]*n\n b=[0]*n\n a[0]=x[0]\n b[0]=y[0]\n for i in range(1,n):\n \n if i<k:\n a[i]=max(x[i],a[i-1])\n b[i]=max(y[i],b[i-1])\n ... | [{"input": ["3", "1 1", "3", "2 1", "2 2", "5 2", "1 2 3 4 6"], "output": ["3", "2", "11"]}] | interview | |
771 | Sultan, the freestyle wrestler, you all know him. He broke multiple records in the history of all wrestling leagues. Now 20 years have passed, Sultan has grown old. He has two sons, he wants them to be like him. Sultan being orthodox goes to his astrologer, where he is told that his sons shall be invincible like him.
... | ["from operator import itemgetter\nt=int(input())\nfor i in range(t):\n n=int(input())\n m,f=list(map(int,input().split()))\n x=list(map(int,input().split()))\n my,fy=0,0\n check=[0]*n\n #print check\n for j in range(n):\n if x[j]>0 and x[j]%m==0 and check[j]==0:\n check[j]=1\n my+=1\n #print check\n for j in rang... | [{"input": ["2", "7", "2 3", "4 5 7 8 9 10 14", "6", "5 7", "1 2 8 9 10 11"], "output": ["Yes", "Multan", "No"]}] | interview | |
772 | You are given a binary string S of N bits. The bits in the string are indexed starting from 1. S[i] denotes the ith bit of S.
Let's say that a sequence i1, i2, …, iK(1 ≤ K; 1 ≤ i1 < i2 < … < iK ≤ N) produces a palindrome when applied to S, if the string S[i1] S[i2] … S[ik] is a palindrome (that is, reads the same back... | ["\n\n\ndef powerset(s):\n n = len(s)\n masks = [1 << j for j in range(n)]\n for i in range(2**n):\n yield [j + 1 for j in range(n) if (masks[j] & i)]\n\n\ndef is_power2(num):\n return num != 0 and ((num & (num - 1)) == 0)\n\n\ndef special(l):\n n = len(l)\n for i in range(n):\n lis = [i... | [{"input": ["2", "11010", "101001011", "", ""], "output": ["9", "18"]}] | interview | |
773 | A permutation of length n is an array of size n consisting of n distinct integers in the range [1, n]. For example, (3, 2, 4, 1) is a permutation of length 4, but (3, 3, 1, 4) and (2, 3, 4, 5) are not, as (3, 3, 1, 4) contains duplicate elements, and (2, 3, 4, 5) contains elements not in range [1,4].
A permutation p of... | ["tests = int(input())\r\nfor t in range(tests):\r\n n = int(input())\r\n permut='2'\r\n permut_list=[]\r\n if n%2==0:\r\n for i in range(2, n+1):\r\n if i%2==1:\r\n permut=permut+' '+str(i+1)\r\n else:\r\n permut=permut+' '+str(i-1)\r\n print(permut)\r\n pass\r\n elif n==1:\r\n ... | [{"input": ["4", "2", "3", "5", "6", "", ""], "output": ["2 1", "2 3 1", "2 1 4 5 3", "2 1 4 3 6 5"]}] | interview | |
774 | Nobody knows, but $N$ frogs live in Chef's garden.
Now they are siting on the X-axis and want to speak to each other. One frog can send a message to another one if the distance between them is less or equal to $K$.
Chef knows all $P$ pairs of frogs, which want to send messages. Help him to define can they or not!
Note ... | ["# cook your dish here\nn, k, p = [int(i) for i in input().split()]\nn_sep = list(map(int, input().split()))\ncount = 0\nsep_sort = sorted(n_sep)\nhashing = {sep_sort[0]: 0}\n\nfor j in range(1, n):\n if (abs(sep_sort[j] - sep_sort[j - 1]) > k):\n count += 1\n hashing[sep_sort[j]] = count\n#print(hashing)\nfor i in r... | [{"input": ["5 3 3", "0 3 8 5 12", "1 2", "1 3", "2 5"], "output": ["Yes", "Yes", "No"]}] | interview | |
775 | After six days, professor GukiZ decided to give more candies to his students. Like last time, he has $N$ students, numbered $1$ through $N$. Let's denote the number of candies GukiZ gave to the $i$-th student by $p_i$. As GukiZ has a lot of students, he does not remember all the exact numbers of candies he gave to the ... | ["try:\n# https://www.codechef.com/LTIME63B/problems/GHMC\n# Finally.... I properly understood what needs to be done.\n\n def ctlt(arr, val):\n # find number of values in sorted arr < val\n if arr[0] >= val: return 0\n lo = 0\n hi = len(arr)\n while hi-lo > 1:\n md = (hi... | [{"input": ["2", "4 3 5 3", "2 1 5", "3 2 8 2", "3 8"], "output": ["12", "-1"]}] | interview | |
776 | You are given an integer $D$. Find an integer sequence $A_1, A_2, \ldots, A_N$ such that the following conditions are satisfied:
- $1 \le N \le 10^5$
- $1 \le A_i \le 10^5$ for each valid $i$
- $\sum_{i=1}^N \sum_{j=i}^N \left( \mathrm{min}(A_i, A_{i+1}, \ldots, A_j) - \mathrm{GCD}(A_i, A_{i+1}, \ldots, A_j) \right) = ... | ["# cook your dish here\nt=int(input())\nfor i in range(t):\n D=int(input())\n P=10**5-2\n ans=[]\n if(D==0):\n ans.append(1)\n while(D>0):\n P=min(P,D)\n ans.append(P+2);\n ans.append(P+1);\n ans.append(1);\n D=D-P;\n print(len(ans))\n print(*ans,sep=\" \",end=\"\\n\")\n \n \n \n ", "for _ in range(int(input... | [{"input": ["4", "2", "5", "200", "13"], "output": ["3", "3 3 2", "5", "2 8 5 1 10", "7", "12 10 15 11 19 13 15", "4", "5 4 4 10"]}] | interview | |
777 | Pankaj likes to eat Ice cream when he is working late into the night. Today has been yet another long day for Pankaj. So, he wants to eat ice cream now. He opens the fridge and sees that he has 2 types of containers holding the ice cream.
The first container is a cone with radius r1 and height h1. There is also a hemis... | ["import math\nt=eval(input())\nwhile t:\n t=t-1\n r1,h1,r2,h2=list(map(float,input().split()))\n vol1=(math.pi*r1*r1*h1)/3 + (2*math.pi*r1*r1*r1)/3\n vol2=math.pi*r2*r2*h2\n print(\"%.8f %.8f\" % (vol1,vol2))\n\n", "import math\ninputs = eval(input())\nfor i in range(inputs):\n\tinpu = input().split()\n... | [{"input": ["2", "1.00 1.00 1.00 1.00", "3.02 7.23 5.20 6.00", "", ""], "output": ["3.141592654 3.141592654", "126.739919445 509.691992118"]}] | interview | |
778 | Given an Integer N, write a program to reverse it.
-----Input-----
The first line contains an integer T, total number of testcases. Then follow T lines, each line contains an integer N.
-----Output-----
For each test case, display the reverse of the given number N, in a new line.
-----Constraints-----
- 1 ≤ T ≤ 10... | ["# cook your dish here\nx=int(input())\nfor i in range(x):\n s=input()\n print(int(s[::-1]))\n", "# cook your dish here\nn=int(input())\na=[]\nfor i in range (0,n):\n no=int(input())\n a.append(no)\nfor i in range (0,n):\n c=0\n s=0\n while (a[i]!=0):\n c=a[i]%10\n s=s*10+c\n ... | [{"input": ["4", "12345", "31203", "2123", "2300"], "output": ["54321", "30213", "3212", "32"]}] | interview | |
779 | Tanish is the president of the chemistry club at his school. He considers everyone who doesn't like chemistry as his enemy. After years of research, he has invented a lethal poison, which he named success. Now Tanish plans to kill all his enemies with his success. Success is extremely deadly and is untraceable in small... | ["t=int(input())\nfor i in range(t):\n n=int(input())\n N=list(map(int,input().split()))\n N.sort()\n \n k=n-1\n ave=N[k]\n for j in range(n-1):\n ave=(ave+N[k-1])/2\n k=k-1\n \n print(ave)", "test=int(input())\nfor i in range(test):\n N=int(input())\n n=input()\n a=list(n.split(' '))\n for k in range(N):\n a[k]=in... | [{"input": ["2", "2", "9 3", "3", "3 2 9"], "output": ["6.00000000", "4.00000000"]}] | interview | |
780 | "Ring Ring!!"
Sherlock's phone suddenly started ringing. And it was none other than Jim Moriarty..
"Long time no see ! You miss me right ? Anyway we'll talk about it later . Let me first tell you something. Dr.Watson is with me . And you've got only one chance to save him . Here's your challenge:.
Given a number N an... | ["import sys\nuser_input = sys.stdin.readline().split()\n\nT = int(user_input[0])\n\nfor j in range(T) :\n\n var = sys.stdin.readline().split()\n N = int(var[0])\n M = int(var[1])\n\n if (N%M)%2 :\n print(\"ODD\")\n else :\n print(\"EVEN\")", "t = int(input())\nfor i in range(0,t):\n n,m = list(map(int,input().split(... | [{"input": ["2", "4 4", "6 5"], "output": ["EVEN", "ODD"]}] | interview | |
781 | Xorgon is an extremely delicious treat formed by the sequence $S$ of binary integers $s_1, s_2,..,s_N$. A really interesting property found in a Xorgon is that the xor of all elements in any contiguous subsequence of length $K$ in $S$ will result in $1$.
Chef has been asked to prepare a Xorgon. However, he has at hi... | ["# cook your dish here\nfrom sys import stdin,stdout\n\na0=0\na1=1\nn,k=stdin.readline().strip().split(' ')\nn,k=int(n),int(k)\n\narr=list(map(int,stdin.readline().strip().split(' ')))\n\n\n\ndef solve(n,k,arr):\n sol=[]\n\n l=0;u=k;\n\n\n while l!=u:\n sol.append(arr[l:min(len(arr),u)])\n l=min(l+k,len(arr))\n ... | [{"input": ["7 5", "1 0 0 1 1 1 1"], "output": ["1"]}] | interview | |
782 | Naman owns a very famous Ice Cream parlour in Pune. He has a wide range of flavours with different pricing.
Every flavour costs ₹ X per gram and quantity of each flavour in the parlour is indefinite. Now, Naman has
received an order for a party wherein he is asked to prepare each Ice Cream with N number of flavours... | ["test = int(input())\nfor i in range(test):\n flavor = int(input())\n rate = input()\n gaf = input()\n gaf = gaf.split()\n gaf = [int(x) for x in gaf]\n rate = rate.split()\n rate = [int(x) for x in rate]\n rate.sort()\n c = gaf[0] - gaf[1]\n sum = rate[0]*c\n t = True\n if gaf[0] < gaf[1]:\n t = False\n j = 0\n whil... | [{"input": ["2", "5", "4 6 8 1 10", "10 3", "2", "1 2", "1 2"], "output": ["18", "Not Possible"]}] | interview | |
783 | You are given two points $P$ and $Q$ and an opaque sphere in a three-dimensional space. The point $P$ is not moving, while $Q$ is moving in a straight line with constant velocity. You are also given a direction vector $d$ with the following meaning: the position of $Q$ at time $t$ is $Q(t) = Q(0) + d \cdot t$, where $Q... | ["# cook your dish here\nepi=10**-2\ndef vision(t):\n a1=x0+(dx*t)-x1\n a2=y0+(dy*t)-y1\n a3=z0+(dz*t)-z1\n b=4*((a1*d1)+(a2*d2)+(a3*d3))*((a1*d1)+(a2*d2)+(a3*d3))\n a=4*((a1*a1)+(a2*a2)+(a3*a3))\n value=(b-(a*c))\n return value\nxrange=range\nfor _ in range(int(input())):\n x1,y1,z1,x0,y0,z0,dx,dy,dz,cx,cy,cz,r=list(m... | [{"input": ["1", "3 0 0 -10 -10 0 0 10 0 0 -3 0 3"], "output": ["1.0000000000"]}] | interview | |
784 | Spring is interesting season of year. Chef is thinking about different things, but last time he thinks about interesting game - "Strange Matrix".
Chef has a matrix that consists of n rows, each contains m elements. Initially, the element aij of matrix equals j. (1 ≤ i ≤ n, 1 ≤ j ≤ m).
Then p times some element aij is... | ["import sys\nimport os\nimport random\nimport math\n#nonlocal defs\nn, m, p = list(map(int, input().split()))\narr = [dict() for _ in range(n)]\nfor _ in range(p):\n i,j = list(map(int,input().split()))\n i -= 1\n j -= 1\n if j not in arr[i]:\n arr[i][j] = j+1\n else:\n arr[i][j] += 1\n\ndef chefbm(arr,i):\n for (e,... | [{"input": ["4 4 6", "2 2", "3 2", "3 2", "4 3", "4 4", "4 3"], "output": ["3", "3", "-1", "4"]}] | interview | |
785 | One of Chef's friends offered him a deal: during $D$ days, they are going to exchange money. For each $i$ ($1 \le i \le D$), on the $i$-th day, Chef's friend would give Chef $A$ rupees, while Chef would give his friend $2^{i-1}$ rupees ($1$ rupee on day $1$, $2$ rupees on day $2$, $4$ rupees on day $3$, and so on). Che... | ["# cook your dish here\na = int(input())\nfor i in range(a):\n b = int(input())\n li = []\n if b == 2:\n print(2,1)\n elif b == 3:\n print(3,2)\n elif b == 4:\n print(4,2)\n else:\n for t in range(b+1):\n if ((b*t)+1-(2**t))<0:\n li.append(t-1)\n break\n for o in range(b+1):\n if b<=2**(o):\n li.appe... | [{"input": ["4", "5", "8", "9", "1000000000"], "output": ["4 3", "5 3", "5 4", "35 30"]}] | interview | |
786 | The chef was not happy with the binary number system, so he designed a new machine which is having 6 different states, i.e. in binary there is a total of 2 states as 0 and 1. Now, the chef is confused about how to correlate this machine to get an interaction with Integer numbers, when N(Integer number) is provided to t... | ["from sys import stdin, stdout\r\n#from math import gcd as g\r\n#a,b = map(int, stdin.readline().split())\r\n#l1 = list(map(int, stdin.readline().split()))\r\nl = [1,6,7]\r\nc = 1\r\nfor x in range(3,100001):\r\n if x%2==1:\r\n a = l[c]*6\r\n l.append(a)\r\n else:\r\n l.append(a+1)\r\n ... | [{"input": ["2", "3", "5"], "output": ["7", "37"]}] | interview | |
787 | Limak is a little polar bear.
He is playing a video game and he needs your help.
There is a row with N cells, each either empty or occupied by a soldier, denoted by '0' and '1' respectively.
The goal of the game is to move all soldiers to the right (they should occupy some number of rightmost cells).
The only possible ... | ["for _ in range(int(input())):\n l=list(map(int,input().strip()))\n for j in range(len(l)-1,-1,-1):\n if l[j]==1:\n l.pop()\n else:\n break\n if l.count(1):\n time,prev,z,c=0,0,0,0\n for j in range(len(l)-1,-1,-1):\n if l[j]==0:\n z+=1\n continue\n if prev!=z:\n prev=z\n c+=1\n time+=c+z\n\n ... | [{"input": ["4", "10100", "1100001", "000000000111", "001110100011010"], "output": ["8", "10", "0", "48"]}] | interview | |
788 | If Give an integer N . Write a program to obtain the sum of the first and last digits of this number.
-----Input-----
The first line contains an integer T, the total number of test cases. Then follow T lines, each line contains an integer N.
-----Output-----
For each test case, display the sum of first and last dig... | ["n = int(input())\nfor i in range(n):\n s = input()\n l = len(s)\n n1 = int(s[0])\n n2 = int(s[l-1])\n print(n1+n2)\n", "try:\n # cook your dish here\n for _ in range(int(input())):\n s=str(input())\n print(int(s[0])+int(s[-1]))\nexcept:\n pass", "# cook your dish here\nfor _ in r... | [{"input": ["3", "1234", "124894", "242323"], "output": ["5", "5", "5"]}] | interview | |
789 | Rani is teaching Raju maths via a game called N-Cube, which involves three sections involving N.
Rani gives Raju a number N, and Raju makes a list of Nth powers of integers in increasing order (1^N, 2^N, 3^N.. so on). This teaches him exponentiation.
Then Raju performs the following subtraction game N times : Take al... | ["tc=int(input())\nfor case in range(tc):\n m,r=list(map(int,input().split()))\n n=m**(r-1)\n a=[i**n for i in range(1,2*n+1)]\n tmp=2*n-1\n for i in range(n):\n for j in range(tmp-i):\n a[j]=a[j+1]-a[j]\n print((a[n-1]/m)%1000000007)\n"] | [{"input": ["1", "2 2"], "output": ["1"]}] | interview | |
790 | Bob has n heap(s) of gravel (initially there are exactly c piece(s) in each). He wants to do m operation(s) with that heaps, each maybe:
- adding pieces of gravel onto the heaps from u to v, exactly k pieces for each,
- or querying "how many pieces of gravel are there in the heap p now?".
-----Request-----
Help Bob d... | ["N,M,C = list(map(int, input().split()))\ntree = [0] * (N+1)\n\ndef add(u,k):\n while u < len(tree):\n tree[u] += k \n u += u&-u\n\ndef query(k):\n ans = 0\n while k:\n ans += tree[k]\n k -= k&-k\n\n return ans\n\ndef solve():\n for _ in range(M):\n op = input().split()\n if op[0] == 'Q':\n print(query(int(op[... | [{"input": ["7 5 0", "Q 7", "S 1 7 1", "Q 3", "S 1 3 1", "Q 3"], "output": ["0", "1", "2", "Limitations", "0<n\u226410 6", "0<m\u2264250 000", "0<u\u2264v\u2264n", "0\u2264c,k\u226410 9", "0<p\u2264n"]}] | interview | |
791 | Chef's dog Snuffles has so many things to play with! This time around, Snuffles has an array A containing N integers: A1, A2, ..., AN.
Bad news: Snuffles only loves to play with an array in which all the elements are equal.
Good news: We have a mover of size D. !
A mover of size D is a tool which helps to change array... | ["tc=int(input())\nfor case in range(tc):\n n,d=list(map(int,input().split()))\n a=list(map(int,input().split()))\n sm=sum(a)\n f=True\n if sm%n==0:\n avg=sm/n\n for i in range(d):\n tmp_sm=0\n tmp_n=0\n for j in range(i,n,d):\n tmp_sm=tmp_sm+a[j]\n tmp_n+=1\n if tmp_sm%tmp_n==0:\n if avg!=tmp_sm/tmp... | [{"input": ["3", "5 2", "1 4 5 2 3", "3 1", "1 4 1", "4 2", "3 4 3 5"], "output": ["3", "2", "-1"]}] | interview | |
792 | Dustin, is the head of an Intelligence agency. He wants to send a secret message S$S$ to his colleague.The message is a single word consisting of only lowercase english letters but he decides to encrypt the message for security reasons. He makes a string M$M$ of length N$N$, such that after deleting a substring of non-... | ["# cook your dish here\nt = int(input())\n\nfor _ in range(t):\n\n n,s = input().split()\n\n N = int(n) \n r = N - len(s)\n\n count = 0\n\n if N>len(s):\n\n count = pow(26, r-1,(10**9+7))\n count*= (26+25*len(s))\n\n count = count%(10**9 + 7)\n print(count)\n\n", "# cook your dish here\nt... | [{"input": ["2", "3 a", "3 ab"], "output": ["1326", "76"]}] | interview | |
793 | As lockdown is going on so no is allowed to go outside , so Chef has come with an innovative idea for food home delivery using drone. But there is an issue with it , the drone can move forward or backward a fix number of steps $x$ .
All the houses and chef restaurant are all in a straight line . Homes which need deli... | ["# cook your dish here\nimport math\ntry:\n n,d=map( int,input().split() )\n a=list(map(int,input().split()))\n a.sort()\n z=abs(a[0]-d)\n for j in range(n):\n x=abs(a[j]-d)\n z=math.gcd(x,z)\n print(z) \n \n \nexcept:\n pass", "# cook your dish here\nn,r=map(int,input()... | [{"input": ["3 1", "3 5 11"], "output": ["2"]}] | interview | |
794 | One day, Tanya was studying graph theory. She is very inquisitive, so the following problem soon came to her mind.
Find the number of undirected unweighted connected simple graphs with $N$ vertices (numbered $1$ through $N$) and $M$ edges, such that for each $i$ ($2 \le i \le N$), the shortest path from vertex $1$ to v... | ["def multiple_input(): return map(int, input().split())\n\n\ndef list_input(): return list(map(int, input().split()))\n\n\nmod = int(1e9) + 7\nfor _ in range(int(input())):\n n, m = multiple_input()\n a = list_input()\n a.sort()\n max_level = a[-1] + 1\n levels = [0] * max_level\n levels[0] = 1\n for i in a:\n levels... | [{"input": ["3", "4 3", "1 2 1", "4 6", "1 2 1", "3 2", "2 2"], "output": ["2", "0", "0"]}] | interview | |
795 | In a cricket game, an over is a set of six valid deliveries of balls performed by one player ― the bowler for this over.
Consider a cricket game with a series of $N$ overs (numbered $1$ through $N$) played by $K$ players (numbered $1$ through $K$). Each player may be the bowler for at most $L$ overs in total, but the s... | ["t=int(input())\nfor i in range(t):\n n,k,l=map(int,input().split())\n if k*l<n:\n print(-1)\n elif (k==1 and n>1):\n print(-1)\n else:\n for j in range(n):\n print((j%k)+1,end=' ')\n print()", "t=int(input())\nfor i in range(t):\n n,k,l=map(int,input().split())\n if k*l<n:\n print(-1)\n elif (k==1 and n>1):\n ... | [{"input": ["2", "4 3 2", "5 4 1"], "output": ["1 2 3 2", "-1"]}] | interview | |
796 | There's an array A consisting of N non-zero integers A1..N. A subarray of A is called alternating if any two adjacent elements in it have different signs (i.e. one of them should be negative and the other should be positive).
For each x from 1 to N, compute the length of the longest alternating subarray that starts at... | ["test=int(input())\nfor i in range(test):\n n=int(input())\n a=list(map(int,input().split()))\n b=[0]*(n+2)\n b[n-1]=1\n for i in range(n-2,-1,-1):\n if(a[i]*a[i+1]<0):\n b[i]=b[i+1]+1\n else:\n b[i]=1\n for i in range(n):\n print(b[i], end=' ')\n print() ", "def f(x,y):\n if x<0 and y>0:\n return 1\n elif x>0... | [{"input": ["3", "4", "1 2 3 4", "4", "1 -5 1 -5", "6", "-5 -1 -1 2 -2 -3"], "output": ["1 1 1 1", "4 3 2 1", "1 1 3 2 1 1"]}] | interview | |
797 | Chef is a very experienced and well-known cook. He has participated in many cooking competitions in the past — so many that he does not even remember them all.
One of these competitions lasted for a certain number of days. The first day of the competition was day $S$ of the week (i.e. Monday, Tuesday etc.) and the last... | ["# cook your dish here\nd=[\"saturday\",\"sunday\",\"monday\",\"tuesday\",\"wednesday\",\"thursday\",\"friday\"]\nt=int(input())\nfor i in range(t):\n s,e,l,r=map(str,input().split())\n l,r=int(l),int(r)\n v=(d.index(e)-d.index(s)+8)%7\n c=r+1\n for i in range(l,r+1):\n if i%7==v:\n c=i\n break\n if c>r:\n print... | [{"input": ["3", "saturday sunday 2 4", "monday wednesday 1 20", "saturday sunday 3 5"], "output": ["2", "many", "impossible"]}] | interview | |
798 | Zonal Computing Olympiad 2013, 10 Nov 2012
Little Red Riding Hood is carrying a basket with berries through the forest to her grandmother's house. The forest is arranged in the form of a square N × N grid of cells. The top left corner cell, where Little Red Riding Hood starts her journey, is numbered (1,1) and the b... | ["# cook your dish here\nimport sys \ndef dist(a,b):\n return abs(a[0]-b[0])+abs(a[1]-b[1])\nn, m = map(int, input().split())\nmatrix=[]\nid_matrix=[[0 for i in range(n)] for i in range(n)]\nfor _ in range(n):\n matrix.append(list(map(int, input().split())))\ncharms=[]\nfor _ in range(m):\n x,y,lungh = map(int... | [{"input": ["5 3", "3 3 2 4 3 ", "2 1 -1 -2 2 ", "-1 2 4 3 -3 ", "-2 2 3 2 1 ", "3 -1 2 -1 2 ", "1 2 2", "4 5 2", "4 2 1", ""], "output": ["YES", "19"]}] | interview | |
799 | One upon a time there were three best friends Abhinav, Harsh, and Akash decided to form a
team and take part in ICPC from KIIT. Participants are usually offered several problems during
the programming contest. Long before the start, the friends decided that they will implement a
problem if at least two of them are s... | ["# cook your dish here\nn = int(input())\ncount = 0\nfor _ in range(n):\n L = list(map(int, input().split()))\n if (L.count(1)>=2):\n count+=1\n \nprint(count)\n", "count = 0\nfor _ in range(int(input())):\n view = list(map(int , input().split()))\n if(sum(view) > 1): count += 1\nprint(count)", "# cook your dish here... | [{"input": ["3", "1 1 0", "1 1 1", "1 0 0"], "output": ["2"]}] | interview |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.